From 6b513b1c55f3d1242c9004f724cc99a727330340 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Thu, 2 Dec 2010 09:26:00 +0100 Subject: [PATCH] Replaced references to NVolSetWasDirty with appropriate substitutions. libntfs (unlike libntfs-3g) sets the volume dirty bit automatically on ntfs_mount (if not already set) and also automatically clears the volume dirty bit on ntfs_umount (if it was not already set before mount). The 'WasDirty' flag is set to indicate that the volume was already dirty when it was mounted, so setting it means bypassing the 'clear dirty flag' behaviour on unmount (it does not mean 'set dirty flag on unmount'). NVolSetWasDirty is accordingly replaced with the actions that were intended: - If the intention was to leave the dirty bit set on unmount, we explicitly set the bit if it is not already set. - If the intention was to simply update the 'WasDirty' bit to be consistent with earlier changes, we just comment out the statement. --- ntfsprogs/ntfsfix.c | 24 ++++++++++++++++++++++-- ntfsprogs/ntfsmove.c | 14 +++++++++++++- ntfsprogs/ntfsresize.c | 7 ++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index a0220e6f..c6ec628a 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -264,7 +264,14 @@ static int set_dirty_flag(ntfs_volume *vol) return -1; } vol->flags = flags; - NVolSetWasDirty(vol); + + /* Porting note: libntfs-3g does not have the 'WasDirty' flag/property, + * and never touches the 'dirty' bit except when explicitly told to do + * so. Since we just wrote the VOLUME_IS_DIRTY bit to disk, and + * vol->flags is up-to-date, we can just ignore the NVolSetWasDirty + * statement. */ + /* NVolSetWasDirty(vol); */ + ntfs_log_info(OK); return 0; } @@ -515,7 +522,20 @@ int main(int argc, char **argv) } } /* So the unmount does not clear it again. */ - NVolSetWasDirty(vol); + + /* Porting note: The WasDirty flag was set here to prevent ntfs_unmount + * from clearing the dirty bit (which might have been set in + * fix_mount()). So the intention is to leave the dirty bit set. + * + * libntfs-3g does not automatically set or clear dirty flags on + * mount/unmount, this means that the assumption that the dirty flag is + * now set does not hold. So we need to set it if not already set. */ + if(!(vol->flags & VOLUME_IS_DIRTY) && ntfs_volume_write_flags(vol, + vol->flags | VOLUME_IS_DIRTY)) { + ntfs_log_error("Error: Failed to set volume dirty flag (%d " + "(%s))!\n", errno, strerror(errno)); + } + /* Check NTFS version is ok for us (in $Volume) */ ntfs_log_info("NTFS volume version is %i.%i.\n", vol->major_ver, vol->minor_ver); diff --git a/ntfsprogs/ntfsmove.c b/ntfsprogs/ntfsmove.c index 13092701..6cfff46f 100644 --- a/ntfsprogs/ntfsmove.c +++ b/ntfsprogs/ntfsmove.c @@ -893,7 +893,19 @@ int main(int argc, char *argv[]) count = move_file(vol, inode, opts.location, 0); if ((count > 0) && (!opts.nodirty)) { - NVolSetWasDirty(vol); + + /* Porting note: libntfs-3g does not automatically set or clear + * dirty flags on mount/unmount. It always preserves them until + * they are explicitly changed with ntfs_volume_write_flags. + * This means that the dirty flag is possibly not set, but + * should be set. So we explicitly set it with a call to + * ntfs_volume_write_flags. */ + if(!(vol->flags & VOLUME_IS_DIRTY) && ntfs_volume_write_flags( + vol, vol->flags | VOLUME_IS_DIRTY)) { + ntfs_log_error("Error: Failed to set volume dirty " + "flag (%d (%s))!\n", errno, strerror(errno)); + } + ntfs_log_info("Relocated %lld bytes\n", count); } if (count >= 0) diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index 8f0d4e26..18dd6a45 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -2297,7 +2297,12 @@ static void prepare_volume_fixup(ntfs_volume *vol) vol->flags |= VOLUME_IS_DIRTY; if (ntfs_volume_write_flags(vol, vol->flags)) perr_exit("Failed to set the volume dirty"); - NVolSetWasDirty(vol); + + /* Porting note: This flag does not exist in libntfs-3g. The dirty flag + * is never modified by libntfs-3g on unmount and we set it above. We + * can safely comment out this statement. */ + /* NVolSetWasDirty(vol); */ + if (vol->dev->d_ops->sync(vol->dev) == -1) perr_exit("Failed to sync device"); printf("Resetting $LogFile ... (this might take a while)\n");