d0df0703e552231ffe0fba44fd7196dbc6f50c60
[yaffs2.git] / direct / test-framework / timothy_tests / quick_tests / test_yaffs_fchmod_EROFS.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 "test_yaffs_fchmod_EROFS.h"
15 static int handle = -1;
16
17 int test_yaffs_fchmod_EROFS(void)
18 {
19         int error = 0;
20         int output = 0;
21         if (yaffs_close(yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE))==-1){
22                 print_message("failed to create file\n",1);
23                 return -1;
24         }
25         if (EROFS_setup() < 0 ){
26                 return -1;
27         }
28         handle = yaffs_open(FILE_PATH,O_CREAT  ,S_IREAD  );
29         if (handle<0){
30                 print_message("failed to open file\n",2);
31                 return -1;
32         }
33
34
35
36         output = yaffs_fchmod(handle,S_IREAD|S_IWRITE);
37
38         if (output<0){
39                 error=yaffs_get_error();
40                 if (abs(error)==EROFS){
41                         return 1;
42                 } else {
43                         print_message("different error than expected\n",2);
44                         return -1;
45                 }
46         } else {
47                 print_message("chmoded with EROFS (which is a bad thing)\n",2);
48                 return -1;
49         }
50
51
52 }
53
54 int test_yaffs_fchmod_EROFS_clean(void)
55 {
56         int output =-1;
57         if (handle >= 0) {
58                 output= yaffs_close(handle);
59         }
60         return (EROFS_clean() && output);
61 }