Date: Thu, 30 Apr 2020 04:00:53 +0000 (UTC) From: Xin LI <delphij@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360488 - stable/12/sbin/fsck_msdosfs Message-ID: <202004300400.03U40rbQ053254@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: delphij Date: Thu Apr 30 04:00:53 2020 New Revision: 360488 URL: https://svnweb.freebsd.org/changeset/base/360488 Log: MFC r360359: Fix a bug with dirty file system handling. Modified: stable/12/sbin/fsck_msdosfs/check.c stable/12/sbin/fsck_msdosfs/ext.h stable/12/sbin/fsck_msdosfs/fat.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sbin/fsck_msdosfs/check.c ============================================================================== --- stable/12/sbin/fsck_msdosfs/check.c Thu Apr 30 03:58:30 2020 (r360487) +++ stable/12/sbin/fsck_msdosfs/check.c Thu Apr 30 04:00:53 2020 (r360488) @@ -169,7 +169,7 @@ checkfilesys(const char *fname) if (mod & FSDIRTY) { pwarn("MARKING FILE SYSTEM CLEAN\n"); - mod |= writefat(fat); + mod |= cleardirty(fat); } else { pwarn("\n***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****\n"); mod |= FSERROR; /* file system not clean */ Modified: stable/12/sbin/fsck_msdosfs/ext.h ============================================================================== --- stable/12/sbin/fsck_msdosfs/ext.h Thu Apr 30 03:58:30 2020 (r360487) +++ stable/12/sbin/fsck_msdosfs/ext.h Thu Apr 30 04:00:53 2020 (r360488) @@ -90,6 +90,8 @@ int writefsinfo(int, struct bootblock *); /* Opaque type */ struct fat_descriptor; +int cleardirty(struct fat_descriptor *); + void fat_clear_cl_head(struct fat_descriptor *, cl_t); bool fat_is_cl_head(struct fat_descriptor *, cl_t); Modified: stable/12/sbin/fsck_msdosfs/fat.c ============================================================================== --- stable/12/sbin/fsck_msdosfs/fat.c Thu Apr 30 03:58:30 2020 (r360487) +++ stable/12/sbin/fsck_msdosfs/fat.c Thu Apr 30 04:00:53 2020 (r360488) @@ -578,7 +578,6 @@ valid_cl(struct fat_descriptor *fat, cl_t cl) * h = hard error flag (1 = ok; 0 = I/O error) * x = any value ok */ - int checkdirty(int fs, struct bootblock *boot) { @@ -636,6 +635,53 @@ checkdirty(int fs, struct bootblock *boot) if ((buffer[7] & 0x0c) == 0x0c) ret = 1; } + +err: + free(buffer); + return ret; +} + +int +cleardirty(struct fat_descriptor *fat) +{ + int fd, ret = FSERROR; + struct bootblock *boot; + u_char *buffer; + size_t len; + off_t off; + + boot = boot_of_(fat); + fd = fd_of_(fat); + + if (boot->ClustMask != CLUST16_MASK && boot->ClustMask != CLUST32_MASK) + return 0; + + off = boot->bpbResSectors; + off *= boot->bpbBytesPerSec; + + buffer = malloc(len = boot->bpbBytesPerSec); + if (buffer == NULL) { + perr("No memory for FAT sectors (%zu)", len); + return 1; + } + + if ((size_t)pread(fd, buffer, len, off) != len) { + perr("Unable to read FAT"); + goto err; + } + + if (boot->ClustMask == CLUST16_MASK) { + buffer[3] |= 0x80; + } else { + buffer[7] |= 0x08; + } + + if ((size_t)pwrite(fd, buffer, len, off) != len) { + perr("Unable to write FAT"); + goto err; + } + + ret = FSOK; err: free(buffer);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202004300400.03U40rbQ053254>