1N/A * ntfsclone - Part of the Linux-NTFS project. 1N/A * Copyright (c) 2003-2006 Szabolcs Szakacsits 1N/A * Copyright (c) 2004-2006 Anton Altaparmakov 1N/A * Special image format support copyright (c) 2004 Per Olofsson 1N/A * Clone NTFS data and/or metadata to a sparse file, image, device or stdout. 1N/A * This program is free software; you can redistribute it and/or modify 1N/A * it under the terms of the GNU General Public License as published by 1N/A * the Free Software Foundation; either version 2 of the License, or 1N/A * (at your option) any later version. 1N/A * FIXME: ntfsclone do bad things about endians handling. Fix it and remove 1N/A * this note and define. 1N/A"*************************************************************************\n" 1N/A"* WARNING: The disk has bad sector. This means physical damage on the *\n" 1N/A"* disk surface caused by deterioration, manufacturing faults or other *\n" 1N/A"* reason. The reliability of the disk may stay stable or degrade fast. *\n" 1N/A"* Use the --rescue option to efficiently save as much data as possible! *\n" 1N/A"*************************************************************************\n";
1N/A"Volume '%s' is scheduled for a check or it was shutdown \n" 1N/A"uncleanly. Please boot Windows or use the --force option to progress.\n";
1N/A/* This is the first endianness safe format version. */ 1N/A * Set the version to 10.0 to avoid colisions with old ntfsclone which 1N/A * stupidly used the volume version as the image version... )-: I hope NTFS 1N/A * never reaches version 10.0 and if it does one day I hope no-one is using 1N/A * such an old ntfsclone by then... 1N/A * NOTE: Only bump the minor version if the image format and header are still 1N/A * backwards compatible. Otherwise always bump the major version. If in 1N/A * doubt, bump the major version. 1N/A/* All values are in little endian. */ 1N/A " Efficiently clone NTFS to a sparse file, image, device or standard output.\n" 1N/A " -o, --output FILE Clone NTFS to the non-existent FILE\n" 1N/A " -O, --overwrite FILE Clone NTFS to FILE, overwriting if exists\n" 1N/A " -s, --save-image Save to the special image format\n" 1N/A " -r, --restore-image Restore from the special image format\n" 1N/A " --rescue Continue after disk read errors\n" 1N/A " -m, --metadata Clone *only* metadata (for NTFS experts)\n" 1N/A " --ignore-fs-check Ignore the filesystem check result\n" 1N/A " -f, --force Force to progress (DANGEROUS)\n" 1N/A " -h, --help Display this help\n" 1N/A " -d, --debug Show debug information\n" 1N/A " If FILE is '-' then send the image to the standard output. If SOURCE is '-'\n" 1N/A " and --restore-image is used then read the image from the standard input.\n" 1N/A static const char *
sopt =
"-dfhmo:O:rs";
1N/A case 1:
/* A non-option argument */ 1N/A err_exit(
"Restoring only metadata from an image is not " 1N/A err_exit(
"Cloning only metadata to stdout isn't supported!\n");
1N/A err_exit(
"Filesystem check can be ignored only for metadata " 1N/A err_exit(
"Saving and restoring an image at the same time " 1N/A "is not supported!\n");
1N/A "Use option --overwrite if you want to" 1N/A "block device isn't supported!\n");
1N/A /* FIXME: this is a workaround for losing debug info if stdout != stderr 1N/A and for the uncontrollable verbose messages in libntfs. Ughhh. */ 1N/A /* Redirect stderr to stdout, note fflush()es are essential! */ 1N/A perror(
"Failed to redirect stderr to stdout");
1N/A /* Don't save bad sectors (both $Bad and unnamed are ignored */ 1N/A /* Save at least the first 16 KiB of FILE_LogFile */ 1N/A Printf(
"WARNING: Can't read sector at %llu, lost data.\n",
1N/A /* vol is NULL if opt.restore_image is set */ 1N/A Printf(
"Apparently you tried to clone to a remote " 1N/A "Windows computer but they don't\nhave " 1N/A "efficient sparse file handling by default. " 1N/A "Please try a different method.\n");
1N/A#
endif /* !defined(__sun) */ 1N/A /* FIXME: this could give pretty suboptimal performance */ 1N/A /* FIXME: can fall into infinite loop if corrupted */ 1N/A * FIXME: no guarantee it's indeed /$Extend/$Quota:$Q. 1N/A * For now, as a minimal safeguard, we check only for 1N/A * quota version 2 ... 1N/A /* FIXME: ntfs_mapping_pairs_decompress should return error */ 1N/A "You didn't shutdown your Windows" 1N/A "properly?\n", (
unsigned long long)k);
1N/A "(0x%llx): %s cluster in $Bitmap\n",
1N/A (
long long)
cl, (
unsigned long long)
cl,
1N/A Printf(
"WARNING: The NTFS inconsistency was overruled " 1N/A "by the --ignore-fs-check option.\n");
1N/A err_exit(
"Filesystem check failed! Windows wasn't shutdown " 1N/A "properly or inconsistent\nfilesystem. Please run " 1N/A "chkdsk /f on Windows then reboot it TWICE.\n");
1N/A /* FIXME: broken MFTMirr update was fixed in libntfs, check if OK now */ 1N/A /* FIXME: broken MFTMirr update was fixed in libntfs, check if OK now */ 1N/A /* FIXME: Terrible kludge for libntfs not being able to return 1N/A a deleted MFT record as inode */ 1N/A /* FIXME: continue only if it make sense, e.g. 1N/A MFT record not in use based on $MFT bitmap */ 1N/A * $Bitmap can overlap the end of the volume. Any bits in this region 1N/A * must be set. This region also encompasses the backup boot sector. 1N/A * Allocate a block of memory with one bit for each cluster of the disk. 1N/A * All the bits are set to 0, except those representing the region beyond the 1N/A /* Determine lcn bitmap byte size and allocate it. */ 1N/A Printf(
"Offset to image data : %u (0x%x) bytes\n",
1N/A * First perform some checks to determine if the volume is already mounted, or 1N/A * is dirty (Windows wasn't shutdown properly). If everything is OK, then mount 1N/A * the volume (load the metadata into memory). 1N/A Printf(
"Apparently device '%s' doesn't have a " 1N/A "valid NTFS. Maybe you selected\nthe whole " 1N/A "disk instead of a partition (e.g. /dev/hda, " 1N/A "(0x%llx).\n", (
unsigned long long)
size,
1N/A * We couldn't figure it out by using a specialized ioctl, 1N/A * so do binary search to find the size of the device. 1N/A Printf(
"WARNING: Couldn't get filesystem type: " 1N/A Printf(
"WARNING: You're using PCFS, it does not support " 1N/A "sparse files so the next operation might take " 1N/A "a while. You should consider using the more " 1N/A "efficient --save-image option of ntfsclone. Use " 1N/A "the --restore-image option to restore the image.\n");
1N/A Printf(
"Destination filesystem type is %s\n",
1N/A Printf(
"Your system or the destination filesystem " 1N/A "doesn't support large files.\n");
1N/A#
else /* !defined(__sun) */ 1N/A Printf(
"WARNING: Couldn't get filesystem type: " 1N/A Printf(
"WARNING: You're using ReiserFS, it has very poor " 1N/A "performance creating\nlarge sparse files. The next " 1N/A "operation might take a very long time!\n" 1N/A "Creating sparse output file ...\n");
1N/A Printf(
"WARNING: You're using SMBFS and if the remote share " 1N/A "isn't Samba but a Windows\ncomputer then the clone " 1N/A "operation will be very inefficient and may fail!\n");
1N/A Printf(
"Destination filesystem type is 0x%lx.\n",
1N/A Printf(
"Your system or the destination filesystem " 1N/A "doesn't support large files.\n");
1N/A "version 2.4.25 and\n the 'lfs' option" 1N/A "\nfor smbmount to have large " 1N/A Printf(
"Apparently the destination filesystem doesn't " 1N/A "support sparse files.\nYou can overcome this " 1N/A "by using the more efficient --save-image " 1N/A "option\nof ntfsclone. Use the --restore-image " 1N/A "option to restore the image.\n");
1N/A#
endif /* defined(__sun) */ 1N/A err_exit(
"Input file is not an image! (invalid magic)\n");
1N/A Printf(
"Old image format detected. If the image was created " 1N/A "on a little endian architecture it will not " 1N/A "work. Use a more recent version of " 1N/A "ntfsclone to recreate the image.\n");
1N/A "version %d.%d. Please obtain a " 1N/A "newer version of ntfsclone.\n",
1N/A /* Read the image header data offset. */ 1N/A * Read any fields from the header that we have not read yet so 1N/A * that the input stream is positioned correctly. This means 1N/A * we can support future minor versions that just extend the 1N/A * header in a backwards compatible way. 1N/A err_exit(
"Current NTFS volume size is bigger than the device " 1N/A "size (%lld)!\nCorrupt partition table or incorrect " 1N/A err_exit(
"Output device is too small (%lld) to fit the " 1N/A * Find the $DATA attribute (with or without a name) for the given ntfs inode. 1N/A Printf(
"WARNING: The disk has %lld or more bad sectors" 1N/A * TODO: save_image needs a bit more space than src_bytes 1N/A * due to the free space encoding overhead. 1N/A Printf(
"WARNING: Unknown free space on the destination: %s\n",
1N/A /* If file is a FIFO then there is no point in checking the size. */ 1N/A err_exit(
"Destination doesn't have enough free space: " 1N/A "%llu MB < %llu MB\n",
1N/A /* print to stderr, stdout can be an NTFS image ... */ 1N/A // FIXME: This needs to be the cluster size... 1N/A /* device_size_get() might need to read() */ 1N/A /* FIXME: save backup boot sector */ 1N/A /* 'force' again mount for dirty volumes (e.g. after resize). 1N/A FIXME: use mount flags to avoid potential side-effects in future */