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/>.
27 #include "btrfs-util.h"
29 int main(int argc
, char *argv
[]) {
32 fd
= open("/", O_RDONLY
|O_CLOEXEC
|O_DIRECTORY
);
34 log_error_errno(errno
, "Failed to open root directory: %m");
38 char ts
[FORMAT_TIMESTAMP_MAX
], bs
[FORMAT_BYTES_MAX
];
40 r
= btrfs_subvol_get_info_fd(fd
, &info
);
42 log_error_errno(r
, "Failed to get subvolume info: %m");
44 log_info("otime: %s", format_timestamp(ts
, sizeof(ts
), info
.otime
));
45 log_info("read-only (search): %s", yes_no(info
.read_only
));
48 r
= btrfs_subvol_get_quota_fd(fd
, "a
);
50 log_error_errno(r
, "Failed to get quota info: %m");
52 log_info("referenced: %s", strna(format_bytes(bs
, sizeof(bs
), quota
.referenced
)));
53 log_info("exclusive: %s", strna(format_bytes(bs
, sizeof(bs
), quota
.exclusive
)));
54 log_info("referenced_max: %s", strna(format_bytes(bs
, sizeof(bs
), quota
.referenced_max
)));
55 log_info("exclusive_max: %s", strna(format_bytes(bs
, sizeof(bs
), quota
.exclusive_max
)));
58 r
= btrfs_subvol_get_read_only_fd(fd
);
60 log_error_errno(r
, "Failed to get read only flag: %m");
62 log_info("read-only (ioctl): %s", yes_no(r
));
67 r
= btrfs_subvol_make("/xxxtest");
69 log_error_errno(r
, "Failed to make subvolume: %m");
71 r
= write_string_file("/xxxtest/afile", "ljsadhfljasdkfhlkjdsfha");
73 log_error_errno(r
, "Failed to write file: %m");
75 r
= btrfs_subvol_snapshot("/xxxtest", "/xxxtest2", 0);
77 log_error_errno(r
, "Failed to make snapshot: %m");
79 r
= btrfs_subvol_snapshot("/xxxtest", "/xxxtest3", BTRFS_SNAPSHOT_READ_ONLY
);
81 log_error_errno(r
, "Failed to make snapshot: %m");
83 r
= btrfs_subvol_remove("/xxxtest", false);
85 log_error_errno(r
, "Failed to remove subvolume: %m");
87 r
= btrfs_subvol_remove("/xxxtest2", false);
89 log_error_errno(r
, "Failed to remove subvolume: %m");
91 r
= btrfs_subvol_remove("/xxxtest3", false);
93 log_error_errno(r
, "Failed to remove subvolume: %m");
95 r
= btrfs_subvol_snapshot("/etc", "/etc2", BTRFS_SNAPSHOT_READ_ONLY
|BTRFS_SNAPSHOT_FALLBACK_COPY
);
97 log_error_errno(r
, "Failed to make snapshot: %m");
99 r
= btrfs_subvol_remove("/etc2", false);
101 log_error_errno(r
, "Failed to remove subvolume: %m");
103 r
= btrfs_subvol_make("/xxxrectest");
105 log_error_errno(r
, "Failed to make subvolume: %m");
107 r
= btrfs_subvol_make("/xxxrectest/xxxrectest2");
109 log_error_errno(r
, "Failed to make subvolume: %m");
111 r
= btrfs_subvol_make("/xxxrectest/xxxrectest3");
113 log_error_errno(r
, "Failed to make subvolume: %m");
115 r
= btrfs_subvol_make("/xxxrectest/xxxrectest3/sub");
117 log_error_errno(r
, "Failed to make subvolume: %m");
119 if (mkdir("/xxxrectest/dir", 0755) < 0)
120 log_error_errno(errno
, "Failed to make directory: %m");
122 r
= btrfs_subvol_make("/xxxrectest/dir/xxxrectest4");
124 log_error_errno(r
, "Failed to make subvolume: %m");
126 if (mkdir("/xxxrectest/dir/xxxrectest4/dir", 0755) < 0)
127 log_error_errno(errno
, "Failed to make directory: %m");
129 r
= btrfs_subvol_make("/xxxrectest/dir/xxxrectest4/dir/xxxrectest5");
131 log_error_errno(r
, "Failed to make subvolume: %m");
133 if (mkdir("/xxxrectest/mnt", 0755) < 0)
134 log_error_errno(errno
, "Failed to make directory: %m");
136 r
= btrfs_subvol_snapshot("/xxxrectest", "/xxxrectest2", BTRFS_SNAPSHOT_RECURSIVE
);
138 log_error_errno(r
, "Failed to snapshot subvolume: %m");
140 r
= btrfs_subvol_remove("/xxxrectest", true);
142 log_error_errno(r
, "Failed to recursively remove subvolume: %m");
144 r
= btrfs_subvol_remove("/xxxrectest2", true);
146 log_error_errno(r
, "Failed to recursively remove subvolume: %m");