yaffsfs.c: Fix NULL dereference in yaffs_unmount2_reldev()
[yaffs2.git] / direct / test-framework / stress_tests / stress_tester / error_handler.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2018 Aleph One Ltd.
5  *
6  * Created by Timothy Manning <timothy@yaffs.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 /*
14  * error_handler.c contains code for checking yaffs function calls for errors.
15  */
16 #include "error_handler.h"
17 #include "shared.h"
18
19 typedef struct error_codes_template {
20   int code;
21   char * text;  
22 }error_entry;
23
24 const error_entry error_list[] = {
25         { ENOMEM , "ENOMEM" },
26         { EBUSY , "EBUSY"},
27         { ENODEV , "ENODEV"},
28         { EINVAL , "EINVAL"},
29         { EBADF , "EBADF"},
30         { EACCES , "EACCES"},
31         { EXDEV , "EXDEV" },
32         { ENOENT , "ENOENT"},
33         { ENOSPC , "ENOSPC"},
34         { ERANGE , "ERANGE"},
35         { ENODATA, "ENODATA"},
36         { ENOTEMPTY, "ENOTEMPTY"},
37         { ENAMETOOLONG,"ENAMETOOLONG"},
38         { ENOMEM , "ENOMEM"},
39         { EEXIST , "EEXIST"},
40         { ENOTDIR , "ENOTDIR"},
41         { EISDIR , "EISDIR"},
42         { 0, NULL }
43 };
44
45 char * error_to_str(int err)
46 {
47         error_entry const *e = error_list;
48         if (err < 0) 
49                 err = -err;
50         while(e->code && e->text){
51                 if(err == e->code)
52                         return e->text;
53                 e++;
54         }
55         return "Unknown error code";
56 }
57
58 void yaffs_check_for_errors(char output, buffer *message_buffer,char error_message[],char success_message[]){
59         int yaffs_error=-1;
60
61         if (output==-1)
62         {
63                 add_to_buffer(message_buffer, "\nerror##########",MESSAGE_LEVEL_ERROR,PRINT);
64                 add_to_buffer(message_buffer, error_message,MESSAGE_LEVEL_ERROR,PRINT);
65                 add_to_buffer(message_buffer, "error_code: ",MESSAGE_LEVEL_ERROR,NPRINT);
66                 yaffs_error=yaffs_get_error();
67                 append_int_to_buffer(message_buffer, yaffs_error,MESSAGE_LEVEL_ERROR,PRINT);
68
69                 add_to_buffer(message_buffer, error_to_str(yaffs_error),MESSAGE_LEVEL_ERROR,NPRINT);
70                 append_to_buffer(message_buffer, "\n\n",MESSAGE_LEVEL_ERROR,PRINT);     
71                 quit_program();
72                 //scanf("%c",dummy);    /*this line causes a segmentation fault. Need a better way of waiting for a key press*/
73                 //print_buffer(message_buffer,PRINT_ALL);
74                 
75         }
76         else{
77                 add_to_buffer(message_buffer, success_message,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
78         }               
79 }
80
81