NEW API: add new api btrfs-fsck

Add the new API btrfs-fsck to check the btrfs filesystem.
Btrfs is currently under heavy development, and not suitable for
any uses other than benchmarking and review. But it'll be useful
in the near future.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
This commit is contained in:
Wanlong Gao
2012-05-15 22:29:19 +08:00
committed by Richard W.M. Jones
parent a84d02e8d8
commit b9331a2d73
5 changed files with 59 additions and 3 deletions

View File

@@ -619,3 +619,47 @@ do_btrfs_set_seeding (const char *device, int svalue)
free (err);
return 0;
}
/* Takes optional arguments, consult optargs_bitmask. */
int
do_btrfs_fsck (const char *device, int64_t superblock, int repair)
{
char *err;
int r;
size_t i = 0;
const size_t MAX_ARGS = 64;
const char *argv[MAX_ARGS];
char super_s[64];
ADD_ARG (argv, i, "btrfsck");
/* Optional arguments. */
if (optargs_bitmask & GUESTFS_BTRFS_FSCK_SUPERBLOCK_BITMASK) {
if (superblock < 0) {
reply_with_error ("super block offset must be >= 0");
return -1;
}
snprintf (super_s, sizeof super_s, "%" PRIi64, superblock);
ADD_ARG (argv, i, "--super");
ADD_ARG (argv, i, super_s);
}
if (!(optargs_bitmask & GUESTFS_BTRFS_FSCK_REPAIR_BITMASK))
repair = 0;
if (repair)
ADD_ARG (argv, i, "--repair");
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

@@ -7232,6 +7232,15 @@ If C<devices> is an empty list, this does nothing.");
Enable or disable the seeding feature of a device that contains
a btrfs filesystem.");
("btrfs_fsck", (RErr, [Device "device"], [OInt64 "superblock"; OBool "repair"]), 332, [Optional "btrfs"],
[InitPartition, IfAvailable "btrfs", TestRun (
[["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
["btrfs_fsck"; "/dev/sda1"; ""; ""]])],
"check a btrfs filesystem",
"\
Used to check a btrfs filesystem, C<device> is the device file where the
filesystem is stored.");
]
let all_functions = non_daemon_functions @ daemon_functions

View File

@@ -60,7 +60,8 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-ntfsfix.h \
include/guestfs-gobject/optargs-ntfsclone_out.h \
include/guestfs-gobject/optargs-mkfs_btrfs.h \
include/guestfs-gobject/optargs-set_e2attrs.h
include/guestfs-gobject/optargs-set_e2attrs.h \
include/guestfs-gobject/optargs-btrfs_fsck.h
guestfs_gobject_sources= \
src/session.c \
@@ -102,4 +103,5 @@ guestfs_gobject_sources= \
src/optargs-ntfsfix.c \
src/optargs-ntfsclone_out.c \
src/optargs-mkfs_btrfs.c \
src/optargs-set_e2attrs.c
src/optargs-set_e2attrs.c \
src/optargs-btrfs_fsck.c

View File

@@ -134,6 +134,7 @@ fuse/guestmount.c
gobject/src/optargs-add_domain.c
gobject/src/optargs-add_drive_opts.c
gobject/src/optargs-btrfs_filesystem_resize.c
gobject/src/optargs-btrfs_fsck.c
gobject/src/optargs-compress_device_out.c
gobject/src/optargs-compress_out.c
gobject/src/optargs-copy_device_to_device.c

View File

@@ -1 +1 @@
331
332