]>
Commit | Line | Data |
---|---|---|
d7c7c334 LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2014 Lennart Poettering | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. | |
20 | ***/ | |
21 | ||
10f9c755 | 22 | #include <fcntl.h> |
d7c7c334 LP |
23 | |
24 | #include "log.h" | |
d7c7c334 | 25 | #include "fileio.h" |
10f9c755 LP |
26 | #include "util.h" |
27 | #include "btrfs-util.h" | |
d7c7c334 LP |
28 | |
29 | int main(int argc, char *argv[]) { | |
30 | int r; | |
10f9c755 LP |
31 | int fd; |
32 | ||
33 | fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY); | |
34 | if (fd < 0) | |
35 | log_error_errno(errno, "Failed to open root directory: %m"); | |
36 | else { | |
c75f27ea | 37 | BtrfsSubvolInfo info; |
b6b18498 LP |
38 | BtrfsQuotaInfo quota; |
39 | char ts[FORMAT_TIMESTAMP_MAX], bs[FORMAT_BYTES_MAX]; | |
c75f27ea | 40 | |
10f9c755 LP |
41 | r = btrfs_subvol_get_info_fd(fd, &info); |
42 | if (r < 0) | |
43 | log_error_errno(r, "Failed to get subvolume info: %m"); | |
44 | else { | |
45 | log_info("otime: %s", format_timestamp(ts, sizeof(ts), info.otime)); | |
c75f27ea | 46 | log_info("read-only (search): %s", yes_no(info.read_only)); |
10f9c755 LP |
47 | } |
48 | ||
b6b18498 LP |
49 | r = btrfs_subvol_get_quota_fd(fd, "a); |
50 | if (r < 0) | |
51 | log_error_errno(r, "Failed to get quota info: %m"); | |
52 | else { | |
53 | log_info("referred: %s", strna(format_bytes(bs, sizeof(bs), quota.referred))); | |
54 | log_info("exclusive: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive))); | |
55 | log_info("referred_max: %s", strna(format_bytes(bs, sizeof(bs), quota.referred_max))); | |
56 | log_info("exclusive_max: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive_max))); | |
57 | } | |
58 | ||
10f9c755 | 59 | r = btrfs_subvol_get_read_only_fd(fd); |
c75f27ea LP |
60 | if (r < 0) |
61 | log_error_errno(r, "Failed to get read only flag: %m"); | |
62 | else | |
63 | log_info("read-only (ioctl): %s", yes_no(r)); | |
10f9c755 | 64 | |
c75f27ea | 65 | safe_close(fd); |
10f9c755 | 66 | } |
d7c7c334 LP |
67 | |
68 | r = btrfs_subvol_make("/xxxtest"); | |
69 | if (r < 0) | |
70 | log_error_errno(r, "Failed to make subvolume: %m"); | |
71 | ||
72 | r = write_string_file("/xxxtest/afile", "ljsadhfljasdkfhlkjdsfha"); | |
73 | if (r < 0) | |
74 | log_error_errno(r, "Failed to write file: %m"); | |
75 | ||
76 | r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest2", false, false); | |
77 | if (r < 0) | |
78 | log_error_errno(r, "Failed to make snapshot: %m"); | |
79 | ||
80 | r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest3", true, false); | |
81 | if (r < 0) | |
82 | log_error_errno(r, "Failed to make snapshot: %m"); | |
83 | ||
84 | r = btrfs_subvol_remove("/xxxtest"); | |
85 | if (r < 0) | |
86 | log_error_errno(r, "Failed to remove subvolume: %m"); | |
87 | ||
88 | r = btrfs_subvol_remove("/xxxtest2"); | |
89 | if (r < 0) | |
90 | log_error_errno(r, "Failed to remove subvolume: %m"); | |
91 | ||
92 | r = btrfs_subvol_remove("/xxxtest3"); | |
93 | if (r < 0) | |
94 | log_error_errno(r, "Failed to remove subvolume: %m"); | |
95 | ||
96 | r = btrfs_subvol_snapshot("/etc", "/etc2", true, true); | |
97 | if (r < 0) | |
98 | log_error_errno(r, "Failed to make snapshot: %m"); | |
99 | ||
100 | r = btrfs_subvol_remove("/etc2"); | |
101 | if (r < 0) | |
102 | log_error_errno(r, "Failed to remove subvolume: %m"); | |
103 | ||
104 | return 0; | |
105 | } |