From 5154256c62396c79d886ed26a4ab995203b6b4b8 Mon Sep 17 00:00:00 2001 From: "omakaista.fi!szaka" Date: Tue, 23 Mar 2004 02:00:56 +0000 Subject: [PATCH] - Check the mount state of the output device in ntfsclone. - Correct a too strong sanity check in ntfsclone that prevented cloning from larger device to a smaller one but the NTFS image could have fit fully. (Logical change 1.344) --- ntfsprogs/ntfsclone.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index 1f244f19..e95933d2 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -845,6 +845,23 @@ static void print_disk_usage(ntfs_walk_clusters_ctx *image) Printf("\n"); } +static void check_if_mounted(const char *device, unsigned long new_mntflag) +{ + unsigned long mntflag; + + if (ntfs_check_if_mounted(device, &mntflag)) + perr_exit("Failed to check '%s' mount state", device); + + if (mntflag & NTFS_MF_MOUNTED) { + if (!(mntflag & NTFS_MF_READONLY)) + err_exit("Device %s is mounted read-write. " + "You must 'umount' it first.\n", device); + if (!new_mntflag) + err_exit("Device %s is mounted. " + "You must 'umount' it first.\n", device); + } +} + /** * First perform some checks to determine if the volume is already mounted, or * is dirty (Windows wasn't shutdown properly). If everything is OK, then mount @@ -852,20 +869,8 @@ static void print_disk_usage(ntfs_walk_clusters_ctx *image) */ static void mount_volume(unsigned long new_mntflag) { - unsigned long mntflag; + check_if_mounted(opt.volume, new_mntflag); - if (ntfs_check_if_mounted(opt.volume, &mntflag)) - perr_exit("Failed to check '%s' mount state", opt.volume); - - if (mntflag & NTFS_MF_MOUNTED) { - if (!(mntflag & NTFS_MF_READONLY)) - err_exit("Device %s is mounted read-write. " - "You must 'umount' it first.\n", opt.volume); - if (!new_mntflag) - err_exit("Device %s is mounted. " - "You must 'umount' it first.\n", opt.volume); - } - if (!(vol = ntfs_mount(opt.volume, new_mntflag))) { int err = errno; @@ -1008,7 +1013,7 @@ int main(int argc, char **argv) } if ((fd_out = open(opt.output, flags, S_IRWXU)) == -1) - perr_exit("opening file '%s' failed", opt.output); + perr_exit("Opening file '%s' failed", opt.output); if (!opt.blkdev_out) { struct statfs stfs; @@ -1028,9 +1033,13 @@ int main(int argc, char **argv) opt.output); } else { s64 dest_size = device_size_get(fd_out); - if (dest_size < device_size) + s64 ntfs_size = vol->nr_clusters * vol->cluster_size; + ntfs_size += 512; /* add backup boot sector */ + if (dest_size < ntfs_size) err_exit("Output device size (%lld) is too small" - " to fit an NTFS clone\n", dest_size); + " to fit the NTFS image.\n", dest_size); + + check_if_mounted(opt.output, 0); } }