From 1df34a605628f0a393ce5605e648b0203b9ca6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Fri, 4 Nov 2011 11:15:01 +0100 Subject: [PATCH] New : implemented an option -d to clear the dirty flag if ntfsfix is successful --- ntfsprogs/ntfsfix.8.in | 5 +++++ ntfsprogs/ntfsfix.c | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ntfsprogs/ntfsfix.8.in b/ntfsprogs/ntfsfix.8.in index 93687b4a..e6228514 100644 --- a/ntfsprogs/ntfsfix.8.in +++ b/ntfsprogs/ntfsfix.8.in @@ -41,6 +41,11 @@ Long named options can be abbreviated to any unique prefix of their name. Clear the list of bad sectors. This is useful after cloning an old disk with bad sectors to a new disk. .TP +\fB\-d\fR, \fB\-\-clear\-dirty\fR +Clear the volume dirty flag if the volume can be fixed and mounted. +If the option is not present or the volume cannot be fixed, the dirty +volume flag is set to request a volume checking at next mount. +.TP \fB\-h\fR, \fB\-\-help\fR Show a list of options with a brief description of each one. .TP diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index 828ee05b..fd46c5a0 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -97,6 +97,7 @@ static struct { char *volume; BOOL no_action; BOOL clear_bad_sectors; + BOOL clear_dirty; } opt; /* @@ -130,6 +131,7 @@ static void usage(void) " Attempt to fix an NTFS partition.\n" "\n" " -b, --clear-bad-sectors Clear the bad sector list\n" + " -d, --clear-dirty Clear the volume dirty flag\n" " -h, --help Display this help\n" " -n, --no-action Do not write anything\n" " -V, --version Display version information\n" @@ -164,11 +166,12 @@ static void version(void) static void parse_options(int argc, char **argv) { int c; - static const char *sopt = "-bhnV"; + static const char *sopt = "-bdhnV"; static const struct option lopt[] = { { "help", no_argument, NULL, 'h' }, { "no-action", no_argument, NULL, 'n' }, { "clear-bad-sectors", no_argument, NULL, 'b' }, + { "clear-dirty", no_argument, NULL, 'd' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; @@ -188,6 +191,9 @@ static void parse_options(int argc, char **argv) case 'b': opt.clear_bad_sectors = TRUE; break; + case 'd': + opt.clear_dirty = TRUE; + break; case 'n': opt.no_action = TRUE; break; @@ -1486,9 +1492,16 @@ int main(int argc, char **argv) * * 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)) { + * now set does not hold. So we need to set it if not already set. + * + * However clear the flag if requested to do so, at this stage + * mounting was successful. + */ + if (opt.clear_dirty) + vol->flags &= ~VOLUME_IS_DIRTY; + else + vol->flags |= VOLUME_IS_DIRTY; + if (!opt.no_action && ntfs_volume_write_flags(vol, vol->flags)) { ntfs_log_error("Error: Failed to set volume dirty flag (%d " "(%s))!\n", errno, strerror(errno)); }