yaffsfs.c: Fix NULL dereference in yaffs_unmount2_reldev()
[yaffs2.git] / direct / test-framework / unit_tests / quick_tests / test_yaffs_write_big_file.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 #include "test_yaffs_write_big_file.h"
14
15 static int handle=-1;
16 static char *file_name = NULL;
17 int test_yaffs_write_big_file(void)
18 {
19         int output=0;
20         int error_code=0;
21         handle=test_yaffs_open();
22         int x=0;
23         
24         int file_name_length=20000;
25         if (handle<0){
26                 printf("failed to open file\n");
27                 return -1;
28         }
29         output=yaffs_lseek(handle,0x7FFFFF00, SEEK_SET);
30         if (output<0){
31                 printf("failed to seek\n");
32                 return -1;
33         }
34         file_name = malloc(file_name_length);
35         if(!file_name){
36                 printf("unable to create file text\n");
37                 return -1;
38         }
39         
40         strcpy(file_name,YAFFS_MOUNT_POINT);
41         for (x=strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
42                 file_name[x]='a';
43         }
44         file_name[file_name_length-2]='\0';
45
46
47
48         if (handle>=0){
49                 output= yaffs_write(handle, file_name, file_name_length-1);
50                 if (output<0){
51                         error_code=yaffs_get_error();
52                         //printf("EISDIR def %d, Error code %d\n", ENOTDIR,error_code);
53                         if (abs(error_code)==EINVAL){
54                                 return 1;
55                         } else {
56                                 printf("different error than expected\n");
57                                 return -1;
58                         }
59                 } else {
60                         printf("wrote a large amount of text to a file.(which is a bad thing)\n");
61                         return -1;
62                 }
63
64         } else {
65                 printf("error opening file\n");
66                 return -1;
67         }
68         
69 }
70
71 int test_yaffs_write_big_file_clean(void)
72 {
73         int output=1;
74         if(file_name){
75                 free(file_name);
76                 file_name = NULL;
77         }
78
79         if (handle>=0){ 
80                 output=yaffs_close(handle);
81         }
82
83         
84         output= yaffs_truncate(FILE_PATH,FILE_SIZE );   
85         if (output>=0){
86                 output=test_yaffs_write();
87                 if (output>=0){
88                         return test_yaffs_write_clean();
89                 } else {
90                         printf("failed to write to file\n");
91                         return -1;
92                 }
93         } else {
94                 printf("failed to truncate file\n");
95                 return -1;
96         }
97
98 }