From 594c23aff0859d0934a14d7cbf8b62ff74dcb2b5 Mon Sep 17 00:00:00 2001 From: szaka Date: Mon, 7 Nov 2005 20:49:18 +0000 Subject: [PATCH] ntfsclone: check available free space on the destination --- ChangeLog | 2 ++ configure.ac | 5 +++-- ntfsprogs/ntfsclone.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d1efc22..d9437578 100644 --- a/ChangeLog +++ b/ChangeLog @@ -67,6 +67,8 @@ xx/xx/2005 - 1.12.2-WIP block devices, FIFOs and sockets) to layout.h. Teech ntfsmount to handle them. (Yura) - Fix allocated data size for resident attributes. (Yura) + - ntfsclone: check available free space on the destination before + starting to clone or restore. (Szaka) 10/10/2005 - 1.12.1 - Minor fix to location of mount.ntfs-fuse and mkfs.ntfs. diff --git a/configure.ac b/configure.ac index 03b85204..1754521f 100644 --- a/configure.ac +++ b/configure.ac @@ -311,8 +311,9 @@ AC_CHECK_HEADERS([ctype.h fcntl.h libintl.h limits.h locale.h mntent.h \ stddef.h stdint.h stdlib.h stdio.h stdarg.h string.h strings.h \ errno.h time.h unistd.h utime.h wchar.h getopt.h features.h endian.h \ byteswap.h sys/byteorder.h sys/endian.h sys/param.h sys/ioctl.h \ - sys/mount.h sys/stat.h sys/types.h sys/vfs.h linux/major.h linux/fd.h \ - linux/hdreg.h machine/endian.h gcrypt.h windows.h gnutls/pkcs12.h]) + sys/mount.h sys/stat.h sys/types.h sys/vfs.h sys/statvfs.h \ + linux/major.h linux/fd.h linux/hdreg.h machine/endian.h gcrypt.h \ + windows.h gnutls/pkcs12.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index b95c477b..c6ee044f 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -34,7 +34,10 @@ #include #endif #ifdef HAVE_SYS_VFS_H -# include +#include +#endif +#ifdef HAVE_SYS_STATVFS_H +#include #endif #ifdef HAVE_FCNTL_H #include @@ -1444,6 +1447,28 @@ static void ignore_bad_clusters(ntfs_walk_clusters_ctx *image) perr_exit("ntfs_inode_close failed for $BadClus"); } +static void check_dest_free_space(u64 src_bytes) +{ + u64 dest_bytes; + struct statvfs stvfs; + + if (opt.save_image || opt.metadata_only || opt.blkdev_out || opt.std_out) + return; + + if (fstatvfs(fd_out, &stvfs) == -1) { + Printf("WARNING: Unknown free space on the destination: %s\n", + strerror(errno)); + return; + } + + dest_bytes = stvfs.f_bsize * stvfs.f_bfree; + + if (dest_bytes < src_bytes) + err_exit("Destination has no enough free space: %llu MB < %llu" + " MB\n", rounded_up_division(dest_bytes, NTFS_MBYTE), + rounded_up_division(src_bytes, NTFS_MBYTE)); +} + int main(int argc, char **argv) { ntfs_walk_clusters_ctx image; @@ -1504,6 +1529,8 @@ int main(int argc, char **argv) compare_bitmaps(&lcn_bitmap); print_disk_usage(vol->cluster_size, vol->nr_clusters, image.inuse); + check_dest_free_space(vol->cluster_size * image.inuse); + ignore_bad_clusters(&image); if (opt.save_image)