Permalink
Browse files

btrfs-util: introduce btrfs_subvol_make_fd()

  • Loading branch information...
fbuihuu committed Apr 27, 2018
1 parent 1e91263 commit 62f9666ae03d3a2f0205ffa54eb4267faca43b74
Showing with 20 additions and 7 deletions.
  1. +19 −7 src/basic/btrfs-util.c
  2. +1 −0 src/basic/btrfs-util.h
@@ -116,8 +116,25 @@ int btrfs_is_subvol(const char *path) {
return btrfs_is_subvol_fd(fd);
}

int btrfs_subvol_make(const char *path) {
int btrfs_subvol_make_fd(int fd, const char *subvolume) {
struct btrfs_ioctl_vol_args args = {};
int r;

assert(subvolume);

r = validate_subvolume_name(subvolume);
if (r < 0)
return r;

strncpy(args.name, subvolume, sizeof(args.name)-1);

if (ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, &args) < 0)
return -errno;

return 0;
}

int btrfs_subvol_make(const char *path) {
_cleanup_close_ int fd = -1;
const char *subvolume;
int r;
@@ -132,12 +149,7 @@ int btrfs_subvol_make(const char *path) {
if (fd < 0)
return fd;

strncpy(args.name, subvolume, sizeof(args.name)-1);

if (ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, &args) < 0)
return -errno;

return 0;
return btrfs_subvol_make_fd(fd, subvolume);
}

int btrfs_subvol_set_read_only_fd(int fd, bool b) {
@@ -65,6 +65,7 @@ int btrfs_resize_loopback_fd(int fd, uint64_t size, bool grow_only);
int btrfs_resize_loopback(const char *path, uint64_t size, bool grow_only);

int btrfs_subvol_make(const char *path);
int btrfs_subvol_make_fd(int fd, const char *subvolume);

int btrfs_subvol_snapshot_fd(int old_fd, const char *new_path, BtrfsSnapshotFlags flags);
int btrfs_subvol_snapshot(const char *old_path, const char *new_path, BtrfsSnapshotFlags flags);

0 comments on commit 62f9666

Please sign in to comment.