btrfs-util: introduce btrfs_subvol_make_fd()

This commit is contained in:
Franck Bui 2018-04-27 17:04:47 +02:00
parent 1e9126316f
commit 62f9666ae0
2 changed files with 20 additions and 7 deletions

View File

@ -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) {

View File

@ -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);