[Libguestfs] [PATCH 2/4] New API: ntfsfix for fixing problems on NTFS.

Richard W.M. Jones rjones at redhat.com
Mon Feb 27 17:34:20 UTC 2012


From: "Richard W.M. Jones" <rjones at redhat.com>

Note this is not a "chkdsk" equivalent tool.
---
 daemon/ntfs.c                  |   29 +++++++++++++++++++++++++++++
 generator/generator_actions.ml |   16 ++++++++++++++++
 src/MAX_PROC_NR                |    2 +-
 3 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/daemon/ntfs.c b/daemon/ntfs.c
index e8be344..235ecbc 100644
--- a/daemon/ntfs.c
+++ b/daemon/ntfs.c
@@ -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;
+}
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 9baf081..9df9ea5 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -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
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index cd30709..ae4cf41 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-306
+307
-- 
1.7.9.1




More information about the Libguestfs mailing list