summaryrefslogtreecommitdiff
path: root/direct/timothy_tests/stress_tester/error_handler.c
blob: a9152f3a2dc1c7c301fe6e3db7b6934428fb479d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * YAFFS: Yet another FFS. A NAND-flash specific file system.
 *
 * Copyright (C) 2002-2011 Aleph One Ltd.
 *   for Toby Churchill Ltd and Brightstar Engineering
 *
 * Created by Timothy Manning <timothy@yaffs.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/*
 * error_handler.c contains code for checking yaffs function calls for errors.
 */
#include "error_handler.h"


typedef struct error_codes_template {
  int code;
  char * text;  
}error_entry;

const error_entry error_list[] = {
	{ ENOMEM , "ENOMEM" },
	{ EBUSY , "EBUSY"},
	{ ENODEV , "ENODEV"},
	{ EINVAL , "EINVAL"},
	{ EBADF , "EBADF"},
	{ EACCES , "EACCES"},
	{ EXDEV , "EXDEV" },
	{ ENOENT , "ENOENT"},
	{ ENOSPC , "ENOSPC"},
	{ ERANGE , "ERANGE"},
	{ ENODATA, "ENODATA"},
	{ ENOTEMPTY, "ENOTEMPTY"},
	{ ENAMETOOLONG,"ENAMETOOLONG"},
	{ ENOMEM , "ENOMEM"},
	{ EEXIST , "EEXIST"},
	{ ENOTDIR , "ENOTDIR"},
	{ EISDIR , "EISDIR"},
	{ 0, NULL }
};

const char * error_to_str(int err)
{
	error_entry *e = error_list;
	if (err < 0) 
		err = -err;
	while(e->code && e->text){
		if(err == e->code)
			return e->text;
		e++;
	}
	return "Unknown error code";
}

void yaffs_check_for_errors(char output, buffer *message_buffer,char error_message[],char success_message[]){
	char dummy[10];
	unsigned int x=0;
	int yaffs_error=-1;
	char error_found=0;
	if (output==-1)
	{
		add_to_buffer(message_buffer, "\nerror##########",MESSAGE_LEVEL_ERROR,PRINT);
		add_to_buffer(message_buffer, error_message,MESSAGE_LEVEL_ERROR,PRINT);
		add_to_buffer(message_buffer, "error_code: ",MESSAGE_LEVEL_ERROR,NPRINT);
		yaffs_error=yaffs_get_error();
		append_int_to_buffer(message_buffer, yaffs_error,MESSAGE_LEVEL_ERROR,PRINT);

		add_to_buffer(message_buffer, error_to_str(yaffs_error),MESSAGE_LEVEL_ERROR,NPRINT);
		append_to_buffer(message_buffer, "\n\n",MESSAGE_LEVEL_ERROR,PRINT);	
		quit_program();
		//scanf("%c",dummy);	/*this line causes a segmentation fault. Need a better way of waiting for a key press*/
		//print_buffer(message_buffer,PRINT_ALL);
		
	}
	else{
		add_to_buffer(message_buffer, success_message,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
	}		
}