btrfs-util.c revision f2cbe59e113f08549949a76ac5b9b3972df4cc30
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#ifdef HAVE_LINUX_BTRFS_H
#endif
#include "missing.h"
#include "util.h"
#include "path-util.h"
#include "macro.h"
#include "strv.h"
#include "copy.h"
#include "btrfs-util.h"
static int validate_subvolume_name(const char *name) {
if (!filename_is_valid(name))
return -EINVAL;
return -E2BIG;
return 0;
}
int r, fd;
if (r < 0)
return r;
if (fd < 0)
return -errno;
return fd;
}
const char *fn;
int r;
r = validate_subvolume_name(fn);
if (r < 0)
return r;
return 0;
}
int btrfs_is_snapshot(int fd) {
return -errno;
return 0;
return -errno;
/* On btrfs subvolumes always have the inode 256 */
}
int btrfs_subvol_snapshot(const char *old_path, const char *new_path, bool read_only, bool fallback_copy) {
struct btrfs_ioctl_vol_args_v2 args = {
};
const char *subvolume;
int r;
if (old_fd < 0)
return -errno;
r = btrfs_is_snapshot(old_fd);
if (r < 0)
return r;
if (r == 0) {
if (fallback_copy) {
r = btrfs_subvol_make(new_path);
if (r < 0)
return r;
if (r < 0) {
return r;
}
if (read_only) {
r = btrfs_subvol_read_only(new_path, true);
if (r < 0) {
return r;
}
}
return 0;
}
return -EISDIR;
}
if (r < 0)
return r;
if (new_fd < 0)
return new_fd;
return -errno;
return 0;
}
int btrfs_subvol_make(const char *path) {
struct btrfs_ioctl_vol_args args = {};
const char *subvolume;
int r;
if (r < 0)
return r;
if (fd < 0)
return fd;
return -errno;
return 0;
}
int btrfs_subvol_remove(const char *path) {
struct btrfs_ioctl_vol_args args = {};
const char *subvolume;
int r;
if (r < 0)
return r;
if (fd < 0)
return fd;
return -errno;
return 0;
}
int btrfs_subvol_read_only(const char *path, bool b) {
if (fd < 0)
return -errno;
return -errno;
if (b)
else
return 0;
return -errno;
return 0;
}
int r;
if (r < 0)
return -errno;
return 0;
}
struct btrfs_ioctl_fs_info_args fsi = {};
if (fd < 0)
return -errno;
return -errno;
/* We won't do this for btrfs RAID */
return 0;
struct btrfs_ioctl_dev_info_args di = {
};
continue;
return -errno;
}
return -errno;
return -ENODEV;
return -ENODEV;
return 1;
}
return -ENODEV;
}