Ticket #230: chmod_HPFS386.diff

File chmod_HPFS386.diff, 3.8 KB (added by dmik, 13 years ago)
  • b_fsFileModeSetFH.c

     
    124124            &&  pFH->pFsInfo
    125125            &&  pFH->pFsInfo->fUnixEAs)
    126126        {
     127            /*
     128             * Temporarily remove the FILE_READONLY bit because on some file
     129             * systems (e.g. HPFS386) setting EAs on a read-only file fails with
     130             * ERROR_ACCESS_DENIED.
     131             */
     132            BOOL fResetReadOnly = FALSE;
     133            if (fsts3.attrFile & FILE_READONLY)
     134            {
     135                fsts3.attrFile &= ~FILE_READONLY;
     136                rc = DosSetFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(fsts3));
     137                if (rc)
     138                {
     139                    FS_RESTORE();
     140                    rc = -__libc_native2errno(rc);
     141                    LIBCLOG_ERROR_RETURN_INT(rc);
     142                }
     143                fResetReadOnly = TRUE;
     144            }
     145
    127146            mode_t CurMode;
    128147            rc = __libc_back_fsUnixAttribsGetMode(fh, pFH->pszNativePath, &CurMode);
    129148            if (__predict_true(!rc))
     
    178197
    179198            if (__predict_false(rc != 0))
    180199            {
     200                /* Restore the FILE_READONLY bit. */
     201                if (fResetReadOnly)
     202                    fsts3.attrFile &= ~FILE_READONLY;
     203                DosSetFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(fsts3));
    181204                FS_RESTORE();
    182205                LIBCLOG_ERROR_RETURN_INT(rc);
    183206            }
  • b_fsNativeFileModeSet.c

     
    126126    }
    127127
    128128    /*
    129      * Update OS/2 attributes.
     129     * Update OS/2 attributes. Note that in fUnixEAs mode we temporarily remove
     130     * the FILE_READONLY bit because on some file systems (e.g. HPFS386) setting
     131     * EAs on a read-only file fails with ERROR_ACCESS_DENIED.
    130132     */
    131133#if OFF_MAX > LONG_MAX
    132134    if (fLarge)
    133135    {
    134         if (Mode & S_IWRITE)
     136        if (fUnixEAs)
    135137            info.fsts4L.attrFile &= ~FILE_READONLY;
    136138        else
    137             info.fsts4L.attrFile = FILE_READONLY;
     139        {
     140            if (Mode & S_IWRITE)
     141                info.fsts4L.attrFile &= ~FILE_READONLY;
     142            else
     143                info.fsts4L.attrFile |= FILE_READONLY;
     144        }
    138145        rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList), 0);
    139146    }
    140147    else
    141148#endif
    142149    {
    143         if (Mode & S_IWRITE)
     150        if (fUnixEAs)
    144151            info.fsts4.attrFile &= ~FILE_READONLY;
    145152        else
    146             info.fsts4.attrFile |= FILE_READONLY;
     153        {
     154            if (Mode & S_IWRITE)
     155                info.fsts4.attrFile &= ~FILE_READONLY;
     156            else
     157                info.fsts4.attrFile |= FILE_READONLY;
     158        }
    147159        rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList), 0);
    148160    }
    149161    if (__predict_false(rc != NO_ERROR))
     
    203215        else if (rc == -ENOTSUP)
    204216            rc = 0;
    205217
     218        /* Restore the FILE_READONLY bit. */
     219        if (!(Mode & S_IWRITE))
     220        {
     221#if OFF_MAX > LONG_MAX
     222            if (fLarge)
     223            {
     224                info.fsts4L.attrFile |= FILE_READONLY;
     225                DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList), 0);
     226            }
     227            else
     228#endif
     229            {
     230                info.fsts4.attrFile |= FILE_READONLY;
     231                DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList), 0);
     232            }
     233        }
     234
    206235        if (__predict_false(rc != 0))
    207236        {
    208237            FS_RESTORE();