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