Opened 12 years ago

Closed 9 years ago

#205 closed defect (fixed)

coreutils chmod does not work on files without EA

Reported by: Yuri Dario Owned by: bird
Priority: normal Milestone: libc-0.6.5
Component: libc-backend Version: 0.6.2
Severity: normal Keywords: chmod MODE EA


The coreutils chmod.exe does not modify the mode attribute if MODE EA is not present in the file.

The attached patch fixes two problems in chmod():

1) libc_back_fsUnixAttribsGetMode returns -ENOTSUP when EA are not supported by file system and EA are not present on file. Probably the two error conditions should be split, but in this case we can go on even if EA are not supported, we will fail in the DosSetPathInfo? call.

2) the MODE field contains also the bits to specify the kind of handle (dir, file, socket, ...) and these bits are not initialized, so when MODE is read back it is reported as zero. This bit is handled inside the backend function, I don't know if it must be handled before reaching the final steps.

Index: src/lib/sys/b_fsNativeFileModeSet.c
--- src/lib/sys/b_fsNativeFileModeSet.c	(revision 3650)
+++ src/lib/sys/b_fsNativeFileModeSet.c	(working copy)
@@ -50,7 +50,7 @@
  * @returns 0 on success.
  * @returns Negative error code (errno.h) on failure.
- * @param   fh      Handle to file.
+ * @param   pszNativePath   Path to the file to change.
  * @param   Mode    The filemode.
 int __libc_back_fsNativeFileModeSet(const char *pszNativePath, mode_t Mode)
@@ -160,12 +160,25 @@
         mode_t CurMode;
         rc = __libc_back_fsUnixAttribsGetMode(-1, pszNativePath, &CurMode);
-        if (__predict_true(!rc))
+	// YD -ENOTSUP is returned if EA not supported or not present!
+	// in the latter case, we need to continue
+        if (__predict_true(!rc) || rc==-ENOTSUP)
             /* correct the passed in Mode mask. */
             Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */
             Mode |= CurMode & ~ALLPERMS;
+            ULONG fAttributtes = fLarge ? info.fsts4L.attrFile : info.fsts4.attrFile;
+            ULONG fAttributtes = info.fsts4.attrFile;
+            if (fAttributtes & FILE_DIRECTORY)
+                Mode |= S_IFDIR;
+            else
+                Mode |= S_IFREG;
             /* construct FEA2 stuff. */
             #pragma pack(1)

Change History (2)

comment:1 Changed 10 years ago by bird

Status: newassigned

comment:2 Changed 9 years ago by bird

Resolution: fixed
Status: assignedclosed

Implemented in r3777.

Note: See TracTickets for help on using tickets.