Hello Frans,
hello Andree,

Frans Pop wrote:
> On Tuesday 28 November 2006 13:08, Szakacsits Szabolcs wrote:
>> There are two NTFS during resizing. The original and the resized. When
>> the resizing is over then the latter is consistent and the old one is
>> irrelevant. ntfsresize doesn't work like the other utilities: mount,
>> modify, umount. It works like: mount and morph the original into a new
>> one.
> 
> I'm going to wait with further testing until you have sorted out this 
> difference of opinion.

Could you test the attached patches against ntfsprogs 1.13.1? It is my
attempt at a backport for the first patch from Anton which seems to
have agreement from Szaka.
ntfsprogs-1.13.1-rename-MS_.diff is just a rename orgy to make
 backporting easier and has to be applied first.
ntfsprogs-1.13.1-vistahotfix.diff is a stripped version of Anton's
 first patch.

Regards,
Carl-Daniel
diff -urN ntfsprogs-1.13.1-orig/include/ntfs/volume.h 
ntfsprogs-1.13.1/include/ntfs/volume.h
--- ntfsprogs-1.13.1-orig/include/ntfs/volume.h 2006-01-08 16:53:28.000000000 
+0100
+++ ntfsprogs-1.13.1/include/ntfs/volume.h      2006-11-28 19:39:22.000000000 
+0100
@@ -41,25 +41,6 @@
 #include <mntent.h>
 #endif
 
-/*
- * Under Cygwin, DJGPP and FreeBSD we do not have MS_RDONLY and MS_NOATIME,
- * so we define them ourselves.
- */
-#ifndef MS_RDONLY
-#define MS_RDONLY 1
-#endif
-/*
- * Solaris defines MS_RDONLY but not MS_NOATIME thus we need to carefully
- * define MS_NOATIME.
- */
-#ifndef MS_NOATIME
-#if (MS_RDONLY != 1)
-#      define MS_NOATIME 1
-#else
-#      define MS_NOATIME 2
-#endif
-#endif
-
 /* Forward declaration */
 typedef struct _ntfs_volume ntfs_volume;
 
@@ -69,6 +50,12 @@
 #include "inode.h"
 #include "attrib.h"
 
+enum {
+       NTFS_MNT_RDONLY         = 1,
+       NTFS_MNT_NOATIME        = 2,
+       NTFS_MNT_CASE_SENSITIVE = 4,
+};
+
 /**
  * enum ntfs_mount_flags -
  *
diff -urN ntfsprogs-1.13.1-orig/libntfs/gnome-vfs-method.c 
ntfsprogs-1.13.1/libntfs/gnome-vfs-method.c
--- ntfsprogs-1.13.1-orig/libntfs/gnome-vfs-method.c    2006-02-03 
23:19:19.000000000 +0100
+++ ntfsprogs-1.13.1/libntfs/gnome-vfs-method.c 2006-11-28 19:29:04.000000000 
+0100
@@ -162,7 +162,7 @@
                        return GNOME_VFS_ERROR_INVALID_URI;
                }
 
-               if (!(volume = ntfs_mount(uri->parent->text, MS_RDONLY))) {
+               if (!(volume = ntfs_mount(uri->parent->text, NTFS_MNT_RDONLY))) 
{
                        g_free(uri_parent_string);
                        return GNOME_VFS_ERROR_WRONG_FORMAT;
                }
diff -urN ntfsprogs-1.13.1-orig/libntfs/volume.c 
ntfsprogs-1.13.1/libntfs/volume.c
--- ntfsprogs-1.13.1-orig/libntfs/volume.c      2006-03-28 00:43:09.000000000 
+0200
+++ ntfsprogs-1.13.1/libntfs/volume.c   2006-11-28 19:29:48.000000000 +0100
@@ -429,9 +429,9 @@
        }
        ntfs_upcase_table_build(vol->upcase,
                        vol->upcase_len * sizeof(ntfschar));
-       if (flags & MS_RDONLY)
+       if (flags & NTFS_MNT_RDONLY)
                NVolSetReadOnly(vol);
-       if (flags & MS_NOATIME)
+       if (flags & NTFS_MNT_NOATIME)
                NVolSetNoATime(vol);
        ntfs_log_debug("Reading bootsector... ");
        if (dev->d_ops->open(dev, NVolReadOnly(vol) ? O_RDONLY: O_RDWR)) {
@@ -745,8 +745,8 @@
  * @flags is an optional second parameter. The same flags are used as for
  * the mount system call (man 2 mount). Currently only the following flags
  * are implemented:
- *     MS_RDONLY       - mount volume read-only
- *     MS_NOATIME      - do not update access time
+ *     NTFS_MNT_RDONLY - mount volume read-only
+ *     NTFS_MNT_NOATIME        - do not update access time
  *
  * The function opens the device @dev and verifies that it contains a valid
  * bootsector. Then, it allocates an ntfs_volume structure and initializes
@@ -1116,7 +1116,7 @@
         * Check for dirty logfile and hibernated Windows.
         * We care only about read-write mounts.
         */
-       if (!(flags & MS_RDONLY)) {
+       if (!(flags & NTFS_MNT_RDONLY)) {
                if (ntfs_volume_check_logfile(vol) < 0)
                        goto error_exit;
                if (ntfs_volume_check_hiberfile(vol) < 0)
@@ -1148,8 +1148,8 @@
  * @flags is an optional second parameter. The same flags are used as for
  * the mount system call (man 2 mount). Currently only the following flags
  * are implemented:
- *     MS_RDONLY       - mount volume read-only
- *     MS_NOATIME      - do not update access time
+ *     NTFS_MNT_RDONLY - mount volume read-only
+ *     NTFS_MNT_NOATIME        - do not update access time
  *
  * The function opens the device or file @name and verifies that it contains a
  * valid bootsector. Then, it allocates an ntfs_volume structure and 
initializes
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfscat.c 
ntfsprogs-1.13.1/ntfsprogs/ntfscat.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfscat.c   2006-04-05 14:43:07.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfscat.c        2006-11-28 19:29:04.000000000 
+0100
@@ -399,7 +399,7 @@
 
        utils_set_locale();
 
-       vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
+       vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY, opts.force);
        if (!vol) {
                ntfs_log_perror("ERROR: couldn't mount volume");
                return 1;
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsclone.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsclone.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsclone.c 2006-06-21 09:59:19.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsclone.c      2006-11-28 19:29:48.000000000 
+0100
@@ -1487,7 +1487,7 @@
 {
        s64 device_size;
 
-       mount_volume(MS_RDONLY);
+       mount_volume(NTFS_MNT_RDONLY);
 
        device_size = ntfs_device_size_get(vol->dev, 1);
        if (device_size <= 0)
@@ -1716,7 +1716,7 @@
        /* 'force' again mount for dirty volumes (e.g. after resize).
           FIXME: use mount flags to avoid potential side-effects in future */
        opt.force++;
-       mount_volume(MS_NOATIME);
+       mount_volume(NTFS_MNT_NOATIME);
 
        free(lcn_bitmap.bm);
        setup_lcn_bitmap();
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfscluster.c 
ntfsprogs-1.13.1/ntfsprogs/ntfscluster.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfscluster.c       2006-04-05 
14:43:07.000000000 +0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfscluster.c    2006-11-28 19:29:04.000000000 
+0100
@@ -492,7 +492,7 @@
 
        utils_set_locale();
 
-       vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
+       vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY, opts.force);
        if (!vol)
                return 1;
 
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfscmp.c 
ntfsprogs-1.13.1/ntfsprogs/ntfscmp.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfscmp.c   2006-04-05 14:43:07.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfscmp.c        2006-11-28 19:29:04.000000000 
+0100
@@ -829,7 +829,7 @@
                                 "You must 'umount' it first.\n", volume);
        }
 
-       vol = ntfs_mount(volume, MS_RDONLY);
+       vol = ntfs_mount(volume, NTFS_MNT_RDONLY);
        if (vol == NULL) {
 
                int err = errno;
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfscp.c 
ntfsprogs-1.13.1/ntfsprogs/ntfscp.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfscp.c    2006-04-05 14:43:07.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfscp.c 2006-11-28 19:29:04.000000000 +0100
@@ -312,7 +312,7 @@
        }
 
        if (opts.noaction)
-               flags = MS_RDONLY;
+               flags = NTFS_MNT_RDONLY;
 
        vol = utils_mount_volume(opts.device, flags, opts.force);
        if (!vol) {
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsdecrypt.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsdecrypt.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsdecrypt.c       2006-04-20 
00:03:58.000000000 +0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsdecrypt.c    2006-11-28 19:29:04.000000000 
+0100
@@ -1313,7 +1313,7 @@
                return 1;
        }
        /* Mount the ntfs volume. */
-       vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
+       vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY, opts.force);
        if (!vol) {
                ntfs_log_error("Failed to mount ntfs volume.  Aborting.\n");
                ntfs_rsa_private_key_release(rsa_key);
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsdump_logfile.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsdump_logfile.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsdump_logfile.c  2005-11-20 
15:15:33.000000000 +0100
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsdump_logfile.c       2006-11-28 
19:29:04.000000000 +0100
@@ -197,7 +197,7 @@
                ntfs_inode *ni;
                ntfs_attr *na;
 
-               vol = ntfs_mount(filename, MS_RDONLY);
+               vol = ntfs_mount(filename, NTFS_MNT_RDONLY);
                if (!vol)
                        log_err_exit(NULL, "Failed to mount %s: %s\n",
                                        filename, strerror(errno));
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsinfo.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsinfo.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsinfo.c  2006-05-20 23:27:15.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsinfo.c       2006-11-28 19:29:04.000000000 
+0100
@@ -1967,7 +1967,7 @@
 
        utils_set_locale();
 
-       vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
+       vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY, opts.force);
        if (!vol)
                return 1;
 
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfslabel.c 
ntfsprogs-1.13.1/ntfsprogs/ntfslabel.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfslabel.c 2006-04-05 14:43:07.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfslabel.c      2006-11-28 19:29:04.000000000 
+0100
@@ -394,7 +394,7 @@
        if (!opts.label)
                opts.noaction++;
 
-       vol = utils_mount_volume(opts.device, opts.noaction ? MS_RDONLY : 0,
+       vol = utils_mount_volume(opts.device, opts.noaction ? NTFS_MNT_RDONLY : 
0,
                        opts.force);
        if (!vol)
                return 1;
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsls.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsls.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsls.c    2006-04-05 14:43:07.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsls.c 2006-11-28 19:29:04.000000000 +0100
@@ -651,7 +651,7 @@
 
        utils_set_locale();
 
-       vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
+       vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY, opts.force);
        if (!vol) {
                // FIXME: Print error... (AIA)
                return 2;
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsmftalloc.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsmftalloc.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsmftalloc.c      2005-11-20 
15:15:33.000000000 +0100
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsmftalloc.c   2006-11-28 19:29:04.000000000 
+0100
@@ -313,7 +313,7 @@
        /* Mount the device. */
        if (opts.no_action) {
                ntfs_log_quiet("Running in READ-ONLY mode!\n");
-               ul = MS_RDONLY;
+               ul = NTFS_MNT_RDONLY;
        } else
                ul = 0;
        vol = ntfs_mount(dev_name, ul);
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsmount.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsmount.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsmount.c 2006-05-19 06:22:53.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsmount.c      2006-11-28 19:29:48.000000000 
+0100
@@ -1420,8 +1420,8 @@
 {
        ntfs_volume *vol;
 
-       vol = utils_mount_volume(device, ((ctx->ro) ? MS_RDONLY : 0) |
-                       ((ctx->noatime) ? MS_NOATIME : 0), ctx->force);
+       vol = utils_mount_volume(device, ((ctx->ro) ? NTFS_MNT_RDONLY : 0) |
+                       ((ctx->noatime) ? NTFS_MNT_NOATIME : 0), ctx->force);
        if (!vol) {
                ntfs_log_error("Mount failed.\n");
                return -1;
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsmove.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsmove.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsmove.c  2006-04-05 14:43:07.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsmove.c       2006-11-28 19:29:05.000000000 
+0100
@@ -873,7 +873,7 @@
        utils_set_locale();
 
        if (opts.noaction)
-               flags |= MS_RDONLY;
+               flags |= NTFS_MNT_RDONLY;
 
        vol = utils_mount_volume(opts.device, flags, opts.force);
        if (!vol) {
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsresize.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsresize.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsresize.c        2006-04-19 
00:03:09.000000000 +0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsresize.c     2006-11-28 19:29:48.000000000 
+0100
@@ -486,7 +486,7 @@
                        opt.info++;
                        break;
                case 'n':
-                       opt.ro_flag = MS_RDONLY;
+                       opt.ro_flag = NTFS_MNT_RDONLY;
                        break;
                case 'P':
                        opt.show_progress = 0;
@@ -522,7 +522,7 @@
                        err++;
                }
                if (opt.info) {
-                       opt.ro_flag = MS_RDONLY;
+                       opt.ro_flag = NTFS_MNT_RDONLY;
                        if (opt.bytes) {
                                printf(NERR_PREFIX "Options --info and --size "
                                        "can't be used together.\n");
@@ -2238,7 +2238,7 @@
                                 "You must 'umount' it first.\n", opt.volume);
        }
 
-       if (!(vol = ntfs_mount(opt.volume, opt.ro_flag | MS_NOATIME))) {
+       if (!(vol = ntfs_mount(opt.volume, opt.ro_flag | NTFS_MNT_NOATIME))) {
 
                int err = errno;
 
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsrm.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsrm.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsrm.c    2006-04-05 14:43:08.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsrm.c 2006-11-28 19:29:05.000000000 +0100
@@ -1027,7 +1027,7 @@
 #endif
 
        if (opts.noaction)
-               flags |= MS_RDONLY;
+               flags |= NTFS_MNT_RDONLY;
 
        //ntfs_log_set_levels (NTFS_LOG_LEVEL_DEBUG | NTFS_LOG_LEVEL_TRACE);
        //ntfs_log_set_levels (NTFS_LOG_LEVEL_DEBUG);
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfstruncate.c 
ntfsprogs-1.13.1/ntfsprogs/ntfstruncate.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfstruncate.c      2006-04-05 
04:45:56.000000000 +0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfstruncate.c   2006-11-28 19:29:05.000000000 
+0100
@@ -738,7 +738,7 @@
        /* Mount the device. */
        if (opts.no_action) {
                ntfs_log_quiet("Running in READ-ONLY mode!\n");
-               ul = MS_RDONLY;
+               ul = NTFS_MNT_RDONLY;
        } else
                ul = 0;
        vol = ntfs_mount(dev_name, ul);
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfsundelete.c 
ntfsprogs-1.13.1/ntfsprogs/ntfsundelete.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfsundelete.c      2006-04-05 
14:43:08.000000000 +0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfsundelete.c   2006-11-28 19:29:05.000000000 
+0100
@@ -2123,7 +2123,7 @@
 
        utils_set_locale();
 
-       vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
+       vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY, opts.force);
        if (!vol)
                return 1;
 
diff -urN ntfsprogs-1.13.1-orig/ntfsprogs/ntfswipe.c 
ntfsprogs-1.13.1/ntfsprogs/ntfswipe.c
--- ntfsprogs-1.13.1-orig/ntfsprogs/ntfswipe.c  2006-04-05 14:43:08.000000000 
+0200
+++ ntfsprogs-1.13.1/ntfsprogs/ntfswipe.c       2006-11-28 19:29:05.000000000 
+0100
@@ -1340,7 +1340,7 @@
                print_summary();
 
        if (opts.info || opts.noaction)
-               flags = MS_RDONLY;
+               flags = NTFS_MNT_RDONLY;
 
        vol = utils_mount_volume(opts.device, flags, opts.force);
        if (!vol)
Index: include/ntfs/volume.h
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/include/ntfs/volume.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- include/ntfs/volume.h       25 Nov 2006 17:37:37 -0000      1.26
+++ include/ntfs/volume.h       28 Nov 2006 10:09:57 -0000      1.27
@@ -54,6 +54,11 @@
        NTFS_MNT_RDONLY         = 1,
        NTFS_MNT_NOATIME        = 2,
        NTFS_MNT_CASE_SENSITIVE = 4,
+       NTFS_MNT_NOT_EXCLUSIVE  = 8,
+       NTFS_MNT_FORENSIC       = 16, /* Mount for forensic purposes, i.e. do
+                                        not do any writing at all during the
+                                        mount, i.e. no journal emptying, no
+                                        dirty bit setting, etc. */
 };
 
 /**
@@ -79,6 +83,10 @@
        NV_CaseSensitive,       /* 1: Volume is mounted case-sensitive. */
        NV_LogFileEmpty,        /* 1: $logFile journal is empty. */
        NV_NoATime,             /* 1: Do not update access time. */
+       NV_WasDirty,            /* 1: Volume was marked dirty before we mounted
+                                     it. */
+       NV_ForensicMount,       /* 1: Mount is forensic, i.e. no modifications
+                                     are to be done by mount/umount. */
 } ntfs_volume_state_bits;
 
 #define  test_nvol_flag(nv, flag)       test_bit(NV_##flag, (nv)->state)
@@ -101,6 +109,14 @@
 #define NVolSetNoATime(nv)               set_nvol_flag(nv, NoATime)
 #define NVolClearNoATime(nv)           clear_nvol_flag(nv, NoATime)
 
+#define NVolWasDirty(nv)                test_nvol_flag(nv, WasDirty)
+#define NVolSetWasDirty(nv)              set_nvol_flag(nv, WasDirty)
+#define NVolClearWasDirty(nv)          clear_nvol_flag(nv, WasDirty)
+
+#define NVolForensicMount(nv)           test_nvol_flag(nv, ForensicMount)
+#define NVolSetForensicMount(nv)         set_nvol_flag(nv, ForensicMount)
+#define NVolClearForensicMount(nv)     clear_nvol_flag(nv, ForensicMount)
+
 /*
  * NTFS version 1.1 and 1.2 are used by Windows NT4.
  * NTFS version 2.x is used by Windows 2000 Beta
Index: libntfs/volume.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/libntfs/volume.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- libntfs/volume.c    25 Nov 2006 21:35:39 -0000      1.81
+++ libntfs/volume.c    28 Nov 2006 10:09:57 -0000      1.82
@@ -88,6 +88,14 @@
  */
 static void __ntfs_volume_release(ntfs_volume *v)
 {
+       /*
+        * Clear the dirty bit if it was not set before we mounted and this is
+        * not a forensic mount.
+        */
+       if (!NVolReadOnly(v) && !NVolWasDirty(v) && !NVolForensicMount(v)) {
+               v->flags &= ~VOLUME_IS_DIRTY;
+               (void)ntfs_volume_write_flags(v, v->flags);
+       }
        if (v->lcnbmp_ni && NInoDirty(v->lcnbmp_ni))
                ntfs_inode_sync(v->lcnbmp_ni);
        if (v->vol_ni)
@@ -780,7 +788,9 @@
                ntfs_log_perror("Failed to startup volume");
                return NULL;
        }
-
+       /* Record whether this is a forensic mount. */
+       if (flags & NTFS_MNT_FORENSIC)
+               NVolSetForensicMount(vol);
        /* Load data from $MFT and $MFTMirr and compare the contents. */
        m = (u8*)malloc(vol->mftmirr_size << vol->mft_record_size_bits);
        m2 = (u8*)malloc(vol->mftmirr_size << vol->mft_record_size_bits);
@@ -997,9 +1007,14 @@
        /* Setup vol from the volume information attribute value. */
        vol->major_ver = vinf->major_ver;
        vol->minor_ver = vinf->minor_ver;
-       /* Do not use le16_to_cpu() macro here as our VOLUME_FLAGS are
-          defined using cpu_to_le16() macro and hence are consistent. */
+       /*
+        * Do not use le16_to_cpu() macro here as our VOLUME_FLAGS are defined
+        * using cpu_to_le16() macro and hence are consistent.
+        */
        vol->flags = vinf->flags;
+       /* Record whether the volume was dirty or not. */
+       if (vol->flags & VOLUME_IS_DIRTY)
+               NVolSetWasDirty(vol);
        /*
         * Reinitialize the search context for the $Volume/$VOLUME_NAME lookup.
         */
@@ -1115,12 +1130,26 @@
        /*
         * Check for dirty logfile and hibernated Windows.
         * We care only about read-write mounts.
+        *
+        * If all is ok, reset the logfile and set the dirty bit on the volume.
+        *
+        * But do not do that if this is a FORENSIC mount.
         */
        if (!(flags & NTFS_MNT_RDONLY)) {
                if (ntfs_volume_check_logfile(vol) < 0)
                        goto error_exit;
                if (ntfs_volume_check_hiberfile(vol) < 0)
                        goto error_exit;
+               if (!NVolForensicMount(vol)) {
+                       if (ntfs_logfile_reset(vol) < 0)
+                               goto error_exit;
+                       if (!NVolWasDirty(vol)) {
+                               vol->flags |= VOLUME_IS_DIRTY;
+                               if (ntfs_volume_write_flags(vol, vol->flags) <
+                                               0)
+                                       goto error_exit;
+                       }
+               }
        }
 
        return vol;
Index: ntfsprogs/ntfsclone.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfsclone.c,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- ntfsprogs/ntfsclone.c       12 Nov 2006 22:46:50 -0000      1.94
+++ ntfsprogs/ntfsclone.c       28 Nov 2006 10:09:57 -0000      1.95
@@ -1328,7 +1328,7 @@
                exit(1);
        }
 
-       if (vol->flags & VOLUME_IS_DIRTY)
+       if (NVolWasDirty(vol))
                if (opt.force-- <= 0)
                        err_exit(dirty_volume_msg, opt.volume);
 
Index: ntfsprogs/ntfscp.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfscp.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- ntfsprogs/ntfscp.c  12 Nov 2006 22:46:50 -0000      1.39
+++ ntfsprogs/ntfscp.c  28 Nov 2006 10:09:57 -0000      1.40
@@ -320,7 +320,7 @@
                return 1;
        }
 
-       if ((vol->flags & VOLUME_IS_DIRTY) && (!opts.force))
+       if (NVolWasDirty(vol) && !opts.force)
                goto umount;
 
        {
Index: ntfsprogs/ntfsdump_logfile.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfsdump_logfile.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- ntfsprogs/ntfsdump_logfile.c        12 Nov 2006 22:46:50 -0000      1.35
+++ ntfsprogs/ntfsdump_logfile.c        28 Nov 2006 10:09:57 -0000      1.36
@@ -197,7 +197,7 @@
                ntfs_inode *ni;
                ntfs_attr *na;
 
-               vol = ntfs_mount(filename, NTFS_MNT_RDONLY);
+               vol = ntfs_mount(filename, NTFS_MNT_RDONLY | NTFS_MNT_FORENSIC);
                if (!vol)
                        log_err_exit(NULL, "Failed to mount %s: %s\n",
                                        filename, strerror(errno));
Index: ntfsprogs/ntfsfix.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfsfix.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- ntfsprogs/ntfsfix.c 5 Apr 2006 12:43:07 -0000       1.33
+++ ntfsprogs/ntfsfix.c 28 Nov 2006 10:09:57 -0000      1.34
@@ -82,8 +82,6 @@
 static const char *EXEC_NAME = "ntfsfix";
 static const char *OK        = "OK\n";
 static const char *FAILED    = "FAILED\n";
-static BOOL vol_is_dirty     = FALSE;
-static BOOL journal_is_empty = FALSE;
 
 struct {
        char *volume;
@@ -247,9 +245,8 @@
 {
        u16 flags;
 
-       if (vol_is_dirty == TRUE)
+       if (NVolWasDirty(vol))
                return 0;
-
        ntfs_log_info("Setting required flags on partition... ");
        /*
         * Set chkdsk flag, i.e. mark the partition dirty so chkdsk will run
@@ -264,37 +261,9 @@
                ntfs_log_error("Error setting volume flags.\n");
                return -1;
        }
+       vol->flags = flags;
        ntfs_log_info(OK);
-       vol_is_dirty = TRUE;
-       return 0;
-}
-
-/**
- * set_dirty_flag_mount
- */
-static int set_dirty_flag_mount(ntfs_volume *vol)
-{
-       u16 flags;
-
-       if (vol_is_dirty == TRUE)
-               return 0;
-
-       ntfs_log_info("Setting required flags on partition... ");
-       /*
-        * Set chkdsk flag, i.e. mark the partition dirty so chkdsk will run
-        * and fix it for us.
-        */
-       flags = vol->flags | VOLUME_IS_DIRTY;
-       /* If NTFS volume version >= 2.0 then set mounted on NT4 flag. */
-       if (vol->major_ver >= 2)
-               flags |= VOLUME_MOUNTED_ON_NT4;
-       if (ntfs_volume_write_flags(vol, flags)) {
-               ntfs_log_info(FAILED);
-               ntfs_log_error("Error setting volume flags.\n");
-               return -1;
-       }
-       ntfs_log_info(OK);
-       vol_is_dirty = TRUE;
+       NVolSetWasDirty(vol);
        return 0;
 }
 
@@ -303,9 +272,8 @@
  */
 static int empty_journal(ntfs_volume *vol)
 {
-       if (journal_is_empty == TRUE)
+       if (NVolLogFileEmpty(vol))
                return 0;
-
        ntfs_log_info("Going to empty the journal ($LogFile)... ");
        if (ntfs_logfile_reset(vol)) {
                ntfs_log_info(FAILED);
@@ -313,7 +281,6 @@
                return -1;
        }
        ntfs_log_info(OK);
-       journal_is_empty = TRUE;
        return 0;
 }
 
@@ -475,13 +442,13 @@
 
        ntfs_log_info("Attempting to correct errors... ");
 
-       dev = ntfs_device_alloc(opt.volume, 0, &ntfs_device_default_io_ops, 
NULL);
+       dev = ntfs_device_alloc(opt.volume, 0, &ntfs_device_default_io_ops,
+                       NULL);
        if (!dev) {
                ntfs_log_info(FAILED);
                ntfs_log_perror("Failed to allocate device");
                return -1;
        }
-
        vol = ntfs_volume_startup(dev, 0);
        if (!vol) {
                ntfs_log_info(FAILED);
@@ -490,17 +457,12 @@
                ntfs_device_free(dev);
                return -1;
        }
-
        if (fix_mftmirr(vol) < 0)
                goto error_exit;
-
-       /* FIXME: Will this fail?  Probably... */
        if (set_dirty_flag(vol) < 0)
                goto error_exit;
-
        if (empty_journal(vol) < 0)
                goto error_exit;
-
        ret = 0;
 error_exit:
        /* ntfs_umount() will invoke ntfs_device_free() for us. */
@@ -550,7 +512,8 @@
                        exit(1);
                }
        }
-
+       /* So the unmount does not clear it again. */
+       NVolSetWasDirty(vol);
        /* 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);
@@ -558,22 +521,13 @@
                ntfs_log_error("Error: Unknown NTFS version.\n");
                goto error_exit;
        }
-
-       if (set_dirty_flag_mount(vol) < 0)
-               goto error_exit;
-
-       if (empty_journal(vol) < 0)
-               goto error_exit;
-
        if (vol->major_ver >= 3) {
-       /* FIXME: If on NTFS 3.0+, check for presence of the usn journal and
-          disable it (if present) as Win2k might be unhappy otherwise and Bad
-          Things(TM) could happen depending on what applications are actually
-          using it for. */
+               /*
+                * FIXME: If on NTFS 3.0+, check for presence of the usn
+                * journal and stamp it if present.
+                */
        }
-
-       /* FIXME: Should we be marking the quota out of date, too? */
-
+       /* FIXME: We should be marking the quota out of date, too. */
        /* That's all for now! */
        ntfs_log_info("NTFS partition %s was processed successfully.\n",
                        vol->dev->d_name);
Index: ntfsprogs/ntfsinfo.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfsinfo.c,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -r1.154 -r1.155
--- ntfsprogs/ntfsinfo.c        25 Nov 2006 18:38:47 -0000      1.154
+++ ntfsprogs/ntfsinfo.c        28 Nov 2006 10:09:57 -0000      1.155
@@ -1165,7 +1165,7 @@
                        runlist *rlc = rl;
                        printf("\tRunlist:\tVCN\t\tLCN\t\tLength\n");
                        while (rlc->length) {
-                               printf("\t\t\t%lld\t\t%lld\t\t%lld\n",
+                               printf("\t\t\t0x%llx\t\t0x%llx\t\t0x%llx\n",
                                        rlc->vcn, rlc->lcn, rlc->length);
                                rlc++;
                        }
Index: ntfsprogs/ntfsmove.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfsmove.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- ntfsprogs/ntfsmove.c        12 Nov 2006 22:46:50 -0000      1.24
+++ ntfsprogs/ntfsmove.c        28 Nov 2006 10:09:57 -0000      1.25
@@ -889,10 +889,7 @@
 
        count = move_file(vol, inode, opts.location, 0);
        if ((count > 0) && (!opts.nodirty)) {
-               if (ntfs_volume_write_flags(vol, vol->flags | VOLUME_IS_DIRTY) <
-                               0) {
-                       ntfs_log_error("Couldn't mark volume dirty\n");
-               }
+               NVolSetWasDirty(vol);
                ntfs_log_info("Relocated %lld bytes\n", count);
        }
        if (count >= 0)
Index: ntfsprogs/ntfsresize.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfsresize.c,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -r1.123 -r1.124
--- ntfsprogs/ntfsresize.c      12 Nov 2006 22:46:50 -0000      1.123
+++ ntfsprogs/ntfsresize.c      28 Nov 2006 10:09:57 -0000      1.124
@@ -2256,7 +2256,7 @@
                exit(1);
        }
 
-       if (vol->flags & VOLUME_IS_DIRTY)
+       if (NVolWasDirty(vol))
                if (opt.force-- <= 0)
                        err_exit("Volume is scheduled for check.\nRun chkdsk /f"
                                 " and please try again, or see option -f.\n");
@@ -2280,32 +2280,16 @@
 /**
  * prepare_volume_fixup
  *
- * Set the volume's dirty flag and wipe the filesystem journal.  When Windows
- * boots it will automatically run chkdsk to check for any problems.  If the
- * read-only command line option was given, this function will do nothing.
+ * Make sure the volume's dirty flag does not get cleared at umount time.  When
+ * Windows boots it will automatically run chkdsk to check for any problems.
+ * If the read-only command line option was given, this function will do
+ * nothing.
  */
 static void prepare_volume_fixup(ntfs_volume *vol)
 {
-       u16 flags;
-
-       flags = vol->flags | VOLUME_IS_DIRTY;
-       if (vol->major_ver >= 2)
-               flags |= VOLUME_MOUNTED_ON_NT4;
-
        printf("Schedule chkdsk for NTFS consistency check at Windows "
                "boot time ...\n");
-
-       if (ntfs_volume_write_flags(vol, flags))
-               perr_exit("Failed to set $Volume dirty");
-
-       if (vol->dev->d_ops->sync(vol->dev) == -1)
-               perr_exit("Failed to sync device");
-
-       printf("Resetting $LogFile ... (this might take a while)\n");
-
-       if (ntfs_logfile_reset(vol))
-               perr_exit("Failed to reset $LogFile");
-
+       NVolSetWasDirty(vol);
        if (vol->dev->d_ops->sync(vol->dev) == -1)
                perr_exit("Failed to sync device");
 }
Index: ntfsprogs/ntfswipe.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/ntfswipe.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- ntfsprogs/ntfswipe.c        12 Nov 2006 22:46:51 -0000      1.45
+++ ntfsprogs/ntfswipe.c        28 Nov 2006 10:09:57 -0000      1.46
@@ -1346,7 +1346,7 @@
        if (!vol)
                goto free;
 
-       if ((vol->flags & VOLUME_IS_DIRTY) && (!opts.force))
+       if (NVolWasDirty(vol) && !opts.force)
                goto umount;
 
        if (opts.info) {
Index: ntfsprogs/utils.c
===================================================================
RCS file: /cvs/linux-ntfs/ntfsprogs/ntfsprogs/utils.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- ntfsprogs/utils.c   25 Nov 2006 21:44:36 -0000      1.69
+++ ntfsprogs/utils.c   28 Nov 2006 10:09:57 -0000      1.70
@@ -196,7 +196,7 @@
                return NULL;
        }
 
-       if (vol->flags & VOLUME_IS_DIRTY) {
+       if (NVolWasDirty(vol)) {
                ntfs_log_warning("Volume is dirty.\n");
                if (!force) {
                        ntfs_log_error("Run chkdsk and try again, or use the "
                                        "force option.\n");

Reply via email to