1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include "btrfs-util.h"
30 int main(int argc, char *argv[]) {
34 fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
36 log_error_errno(errno, "Failed to open root directory: %m");
40 char ts[FORMAT_TIMESTAMP_MAX], bs[FORMAT_BYTES_MAX];
42 r = btrfs_subvol_get_info_fd(fd, &info);
44 log_error_errno(r, "Failed to get subvolume info: %m");
46 log_info("otime: %s", format_timestamp(ts, sizeof(ts), info.otime));
47 log_info("read-only (search): %s", yes_no(info.read_only));
50 r = btrfs_subvol_get_quota_fd(fd, "a);
52 log_error_errno(r, "Failed to get quota info: %m");
54 log_info("referred: %s", strna(format_bytes(bs, sizeof(bs), quota.referred)));
55 log_info("exclusive: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive)));
56 log_info("referred_max: %s", strna(format_bytes(bs, sizeof(bs), quota.referred_max)));
57 log_info("exclusive_max: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive_max)));
60 r = btrfs_subvol_get_read_only_fd(fd);
62 log_error_errno(r, "Failed to get read only flag: %m");
64 log_info("read-only (ioctl): %s", yes_no(r));
69 r = btrfs_subvol_make("/xxxtest");
71 log_error_errno(r, "Failed to make subvolume: %m");
73 r = write_string_file("/xxxtest/afile", "ljsadhfljasdkfhlkjdsfha");
75 log_error_errno(r, "Failed to write file: %m");
77 r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest2", false, false);
79 log_error_errno(r, "Failed to make snapshot: %m");
81 r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest3", true, false);
83 log_error_errno(r, "Failed to make snapshot: %m");
85 r = btrfs_subvol_remove("/xxxtest");
87 log_error_errno(r, "Failed to remove subvolume: %m");
89 r = btrfs_subvol_remove("/xxxtest2");
91 log_error_errno(r, "Failed to remove subvolume: %m");
93 r = btrfs_subvol_remove("/xxxtest3");
95 log_error_errno(r, "Failed to remove subvolume: %m");
97 r = btrfs_subvol_snapshot("/etc", "/etc2", true, true);
99 log_error_errno(r, "Failed to make snapshot: %m");
101 r = btrfs_subvol_remove("/etc2");
103 log_error_errno(r, "Failed to remove subvolume: %m");