2820d680e893ef7733ac244a729807c25c641c94
[yaffs2.git] / direct / timothy_tests / mirror_tests / yaffs_test_write.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include "yaffs_test_write.h"
15
16 int yaffs_test_write(arg_temp *args_struct)
17 {
18         char path[200];
19         char message[200];
20         int output=0,output2=0;
21         int handle;
22         struct yaffs_stat yaffs_stat_struct;
23         join_paths(yaffs_struct.root_path,args_struct->string1, path );
24         sprintf(message,"trying to write to: %s\nwith mode set to %o \n",path,args_struct->char1);
25         print_message(3,message);
26         printf("mode S_IREAD %d S_IWRITE %d\n",(args_struct->char2 & S_IREAD),(args_struct->char2 & S_IWRITE));
27         handle=yaffs_open(path,((args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND))|O_RDWR),(args_struct->char2&(S_IREAD|S_IWRITE)));
28         printf("handle %d\n",handle);
29         if (handle<0){
30                 print_message(3,"failed to open a handle\n");
31                 return -1; //handle failed to open
32         }
33
34 /*      output=yaffs_fstat(handle,&yaffs_stat_struct);
35         if (output < 0){
36                 sprintf(message,"failed to stat the file\n");
37                 print_message(3,message);
38                 get_error_yaffs();
39         } else {
40                 sprintf(message,"stated the file\n");
41                 print_message(3,message);
42                 sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
43                 print_message(3,message);
44                 sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
45                 print_message(3,message);       
46         }
47
48         sprintf(message,"trying to write: %d bytes into the file\n",strlen(args_struct->string2));
49         print_message(3,message);
50 */      
51         output=yaffs_write(handle,&args_struct->string2,strlen(args_struct->string2));
52
53 /*      print_message(3,"\n wrote to the file\n");
54         output2=yaffs_fstat(handle,&yaffs_stat_struct);
55         if (output2 < 0){
56                 sprintf(message,"failed to stat the file\n");
57                 print_message(3,message);
58                 get_error_yaffs();
59         } else {
60                 sprintf(message,"stated the file\n");
61                 print_message(3,message);
62                 sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
63                 print_message(3,message);
64                 sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
65                 print_message(3,message);       
66         }
67 */      yaffs_close(handle);
68 /*      print_message(3,"\n closing the file\n");
69         output2=yaffs_stat(path,&yaffs_stat_struct);
70         if (output2 < 0){
71                 sprintf(message,"failed to stat the file\n");
72                 print_message(3,message);
73                 get_error_yaffs();
74         } else {
75                 sprintf(message,"stated the file\n");
76                 print_message(3,message);
77                 sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
78                 print_message(3,message);
79                 sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
80                 print_message(3,message);       
81         }
82 */
83
84         return output;
85 }