yaffs More tests for quick tests.
[yaffs2.git] / direct / timothy_tests / quick_tests / test_yaffs_write_EFBIG.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 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 "test_yaffs_write_EFBIG.h"
15
16 static int handle=0;
17 static char *file_name = NULL;
18 int test_yaffs_write_EFBIG(void)
19 {
20         int output=0;
21         int error_code=0;
22         handle=test_yaffs_open();
23         int x=0;
24         
25         long int file_name_length=100000000000;
26
27         file_name = malloc(file_name_length);
28         if(!file_name){
29                 printf("unable to create file text\n");
30                 return -1;
31         }
32         
33         strcat(file_name,YAFFS_MOUNT_POINT);
34         for (x=strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
35                 file_name[x]='a';
36         }
37         file_name[file_name_length-2]='\0';
38
39
40
41         if (handle>=0){
42                 output= yaffs_write(handle, file_name, file_name_length-1);
43                 if (output<0){
44                         error_code=yaffs_get_error();
45                         //printf("EISDIR def %d, Error code %d\n", ENOTDIR,error_code);
46                         if (abs(error_code)==EINVAL){
47                                 return 1;
48                         } else {
49                                 printf("different error than expected\n");
50                                 return -1;
51                         }
52                 } else {
53                         printf("wrote a large amount of text to a file.(which is a bad thing)\n");
54                         return -1;
55                 }
56
57         } else {
58                 printf("error opening file\n");
59                 return -1;
60         }
61         
62 }
63
64 int test_yaffs_write_EFBIG_clean(void)
65 {
66         int output=1;
67         if(file_name){
68                 free(file_name);
69                 file_name = NULL;
70         }
71
72         if (handle>=0){ 
73                 output=yaffs_close(handle);
74         }
75
76         
77         output= test_yaffs_truncate_clean();    
78         if (output>=0){
79                 output=test_yaffs_write();
80                 if (output>=0){
81                         return 1;
82                 } else {
83                         printf("failed to write to file\n");
84                         return -1;
85                 }
86         } else {
87                 printf("failed to truncate file\n");
88                 return -1;
89         }
90
91 }