New API: ntfsfix for fixing problems on NTFS.

Note this is not a "chkdsk" equivalent tool.
This commit is contained in:
Richard W.M. Jones
2012-02-27 11:13:45 +00:00
parent 2e788ca45e
commit 51aa51884e
3 changed files with 46 additions and 1 deletions

View File

@@ -115,3 +115,32 @@ do_ntfsresize_size (const char *device, int64_t size)
optargs_bitmask = GUESTFS_NTFSRESIZE_OPTS_SIZE_BITMASK;
return do_ntfsresize_opts (device, size, 0);
}
/* Takes optional arguments, consult optargs_bitmask. */
int
do_ntfsfix (const char *device, int clearbadsectors)
{
const char *argv[MAX_ARGS];
size_t i = 0;
int r;
char *err;
ADD_ARG (argv, i, "ntfsfix");
if ((optargs_bitmask & GUESTFS_NTFSFIX_CLEARBADSECTORS_BITMASK) &&
clearbadsectors)
ADD_ARG (argv, i, "-b");
ADD_ARG (argv, i, device);
ADD_ARG (argv, i, NULL);
r = commandv (NULL, &err, argv);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
return -1;
}
free (err);
return 0;
}

View File

@@ -6666,6 +6666,22 @@ C<device>.
Compare with C<guestfs_zero> which zeroes the first few blocks of a
device.");
("ntfsfix", (RErr, [Device "device"], [OBool "clearbadsectors"]), 307, [Optional "ntfs3g"],
[InitPartition, IfAvailable "ntfs3g", TestRun (
[["mkfs"; "ntfs"; "/dev/sda1"];
["ntfsfix"; "/dev/sda1"; "false"]])],
"fix common errors and force Windows to check NTFS",
"\
This command repairs some fundamental NTFS inconsistencies,
resets the NTFS journal file, and schedules an NTFS consistency
check for the first boot into Windows.
This is I<not> an equivalent of Windows C<chkdsk>. It does I<not>
scan the filesystem for inconsistencies.
The optional C<clearbadsectors> flag clears the list of bad sectors.
This is useful after cloning a disk with bad sectors to a new disk.");
]
let all_functions = non_daemon_functions @ daemon_functions

View File

@@ -1 +1 @@
306
307