yaffs direct: Add EROFS error for hundling chmod on a read-only fs
[yaffs2.git] / direct / yaffsfs.c
index 203a034c739dfd4287459cb8402746a8b5efb6ee..7a05c2192b4b2fdae5e2f3cb27267d96f5711c7d 100644 (file)
@@ -1737,9 +1737,13 @@ int yaffs_access(const YCHAR *path, int amode)
 int yaffs_chmod(const YCHAR *path, mode_t mode)
 {
        struct yaffs_obj *obj;
-
        int retVal = -1;
 
+       if(mode & ~(0777)){
+               yaffsfs_SetError(-EINVAL);
+               return -1;
+       }
+
        yaffsfs_Lock();
 
        obj = yaffsfs_FindObject(NULL,path,0,1);
@@ -1747,7 +1751,7 @@ int yaffs_chmod(const YCHAR *path, mode_t mode)
        if(!obj)
                yaffsfs_SetError(-ENOENT);
        else if(obj->my_dev->read_only)
-               yaffsfs_SetError(-EINVAL);
+               yaffsfs_SetError(-EROFS);
        else
                retVal = yaffsfs_DoChMod(obj,mode);
 
@@ -1761,16 +1765,20 @@ int yaffs_chmod(const YCHAR *path, mode_t mode)
 int yaffs_fchmod(int fd, mode_t mode)
 {
        struct yaffs_obj *obj;
-
        int retVal = -1;
 
+       if(mode & ~(0777)){
+               yaffsfs_SetError(-EINVAL);
+               return -1;
+       }
+
        yaffsfs_Lock();
        obj = yaffsfs_GetHandleObject(fd);
 
        if(!obj)
-               yaffsfs_SetError(-ENOENT);
+               yaffsfs_SetError(-EBADF);
        else if(obj->my_dev->read_only)
-               yaffsfs_SetError(-EINVAL);
+               yaffsfs_SetError(-EROFS);
        else
                retVal = yaffsfs_DoChMod(obj,mode);