Have updated yaffs direct tests and added README files to the tests.
[yaffs2.git] / direct / timothy_tests / is_yaffs_working_tests / test_1_yaffs_mount.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
15 #include "yaffsfs.h"
16 #define YAFFS_MOUNT_POINT "/yaffs2/"
17 #define FILE_PATH "/yaffs2/foo.txt"
18
19 int random_seed;
20 int simulate_power_failure = 0;
21
22
23 int main()
24 {
25         int output = 0;
26         int output2 = 0;
27         yaffs_start_up();
28
29         printf("\n\n starting test\n");
30         yaffs_set_trace(0);
31         output = yaffs_mount(YAFFS_MOUNT_POINT);
32
33         if (output>=0){  
34                 printf("yaffs mounted: %s\n",YAFFS_MOUNT_POINT); 
35         } else {
36                 printf("error\n yaffs failed to mount: %s\nerror\n",YAFFS_MOUNT_POINT);
37                 return (0);
38         }
39         //now create a file.
40         output = yaffs_open(FILE_PATH,O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
41         if (output>=0){  
42                 printf("file created: %s\n",FILE_PATH); 
43         } else {
44                 printf("error\n yaffs failed to create the file: %s\nerror\n",FILE_PATH);
45                 return (0);
46         }
47         output2 = yaffs_close(output);
48         if (output2>=0){  
49                 printf("file closed: %s\n",FILE_PATH); 
50         } else {
51                 printf("error\n yaffs failed to close the file: %s\nerror\n",FILE_PATH);
52                 return (0);
53         }
54         //unmount and remount the mount point.
55         output = yaffs_unmount(YAFFS_MOUNT_POINT);
56         if (output>=0){  
57                 printf("yaffs unmounted: %s\n",YAFFS_MOUNT_POINT); 
58         } else {
59                 printf("error\n yaffs failed to unmount: %s\nerror\n",YAFFS_MOUNT_POINT);
60                 return (0);
61         }
62         output = yaffs_mount(YAFFS_MOUNT_POINT);
63         if (output>=0){  
64                 printf("yaffs mounted: %s\n",YAFFS_MOUNT_POINT); 
65         } else {
66                 printf("error\n yaffs failed to mount: %s\nerror\n",YAFFS_MOUNT_POINT);
67                 return (0);
68         }
69         //now open the existing file.
70         output = yaffs_open(FILE_PATH, O_RDWR, S_IREAD | S_IWRITE);
71         if (output>=0){  
72                 printf("file created: %s\n",FILE_PATH); 
73         } else {
74                 printf("error\n yaffs failed to create the file: %s\nerror\n",FILE_PATH);
75                 return (0);
76         }
77         //close the file.
78         output2 = yaffs_close(output);
79         if (output2>=0){  
80                 printf("file closed: %s\n",FILE_PATH); 
81         } else {
82                 printf("error\n yaffs failed to close the file: %s\nerror\n",FILE_PATH);
83                 return (0);
84         }
85
86         //unmount the mount point.
87         output = yaffs_unmount(YAFFS_MOUNT_POINT);
88         if (output>=0){  
89                 printf("yaffs unmounted: %s\n",YAFFS_MOUNT_POINT); 
90         } else {
91                 printf("error\n yaffs failed to unmount: %s\nerror\n",YAFFS_MOUNT_POINT);
92                 return (0);
93         }
94
95         printf("test passed. yay!\n");
96         
97 }