2014-12-12 05:15:58 +03:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd .
Copyright 2014 Lennart Poettering
systemd is free software ; you can redistribute it and / or modify it
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/>.
* * */
2014-12-25 05:19:19 +03:00
# include <fcntl.h>
2014-12-12 05:15:58 +03:00
# include "log.h"
# include "fileio.h"
2014-12-25 05:19:19 +03:00
# include "util.h"
# include "btrfs-util.h"
2014-12-12 05:15:58 +03:00
int main ( int argc , char * argv [ ] ) {
2015-04-06 11:57:17 +03:00
int r , fd ;
2014-12-25 05:19:19 +03:00
fd = open ( " / " , O_RDONLY | O_CLOEXEC | O_DIRECTORY ) ;
if ( fd < 0 )
log_error_errno ( errno , " Failed to open root directory: %m " ) ;
else {
2014-12-26 18:59:53 +03:00
BtrfsSubvolInfo info ;
2014-12-28 04:05:28 +03:00
BtrfsQuotaInfo quota ;
char ts [ FORMAT_TIMESTAMP_MAX ] , bs [ FORMAT_BYTES_MAX ] ;
2014-12-26 18:59:53 +03:00
2014-12-25 05:19:19 +03:00
r = btrfs_subvol_get_info_fd ( fd , & info ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to get subvolume info: %m " ) ;
else {
log_info ( " otime: %s " , format_timestamp ( ts , sizeof ( ts ) , info . otime ) ) ;
2014-12-26 18:59:53 +03:00
log_info ( " read-only (search): %s " , yes_no ( info . read_only ) ) ;
2014-12-25 05:19:19 +03:00
}
2014-12-28 04:05:28 +03:00
r = btrfs_subvol_get_quota_fd ( fd , & quota ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to get quota info: %m " ) ;
else {
2015-03-10 17:55:58 +03:00
log_info ( " referenced: %s " , strna ( format_bytes ( bs , sizeof ( bs ) , quota . referenced ) ) ) ;
2014-12-28 04:05:28 +03:00
log_info ( " exclusive: %s " , strna ( format_bytes ( bs , sizeof ( bs ) , quota . exclusive ) ) ) ;
2015-03-10 17:55:58 +03:00
log_info ( " referenced_max: %s " , strna ( format_bytes ( bs , sizeof ( bs ) , quota . referenced_max ) ) ) ;
2014-12-28 04:05:28 +03:00
log_info ( " exclusive_max: %s " , strna ( format_bytes ( bs , sizeof ( bs ) , quota . exclusive_max ) ) ) ;
}
2014-12-25 05:19:19 +03:00
r = btrfs_subvol_get_read_only_fd ( fd ) ;
2014-12-26 18:59:53 +03:00
if ( r < 0 )
log_error_errno ( r , " Failed to get read only flag: %m " ) ;
else
log_info ( " read-only (ioctl): %s " , yes_no ( r ) ) ;
2014-12-25 05:19:19 +03:00
2014-12-26 18:59:53 +03:00
safe_close ( fd ) ;
2014-12-25 05:19:19 +03:00
}
2014-12-12 05:15:58 +03:00
r = btrfs_subvol_make ( " /xxxtest " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make subvolume: %m " ) ;
r = write_string_file ( " /xxxtest/afile " , " ljsadhfljasdkfhlkjdsfha " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to write file: %m " ) ;
r = btrfs_subvol_snapshot ( " /xxxtest " , " /xxxtest2 " , false , false ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make snapshot: %m " ) ;
r = btrfs_subvol_snapshot ( " /xxxtest " , " /xxxtest3 " , true , false ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make snapshot: %m " ) ;
2015-04-06 11:57:17 +03:00
r = btrfs_subvol_remove ( " /xxxtest " , false ) ;
2014-12-12 05:15:58 +03:00
if ( r < 0 )
log_error_errno ( r , " Failed to remove subvolume: %m " ) ;
2015-04-06 11:57:17 +03:00
r = btrfs_subvol_remove ( " /xxxtest2 " , false ) ;
2014-12-12 05:15:58 +03:00
if ( r < 0 )
log_error_errno ( r , " Failed to remove subvolume: %m " ) ;
2015-04-06 11:57:17 +03:00
r = btrfs_subvol_remove ( " /xxxtest3 " , false ) ;
2014-12-12 05:15:58 +03:00
if ( r < 0 )
log_error_errno ( r , " Failed to remove subvolume: %m " ) ;
r = btrfs_subvol_snapshot ( " /etc " , " /etc2 " , true , true ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make snapshot: %m " ) ;
2015-04-06 11:57:17 +03:00
r = btrfs_subvol_remove ( " /etc2 " , false ) ;
2014-12-12 05:15:58 +03:00
if ( r < 0 )
log_error_errno ( r , " Failed to remove subvolume: %m " ) ;
2015-04-06 11:57:17 +03:00
r = btrfs_subvol_make ( " /xxxrectest " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make subvolume: %m " ) ;
r = btrfs_subvol_make ( " /xxxrectest/xxxrectest2 " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make subvolume: %m " ) ;
r = btrfs_subvol_make ( " /xxxrectest/xxxrectest3 " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make subvolume: %m " ) ;
r = btrfs_subvol_make ( " /xxxrectest/xxxrectest3/sub " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make subvolume: %m " ) ;
if ( mkdir ( " /xxxrectest/dir " , 0755 ) < 0 )
log_error_errno ( errno , " Failed to make directory: %m " ) ;
r = btrfs_subvol_make ( " /xxxrectest/dir/xxxrectest4 " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make subvolume: %m " ) ;
if ( mkdir ( " /xxxrectest/dir/xxxrectest4/dir " , 0755 ) < 0 )
log_error_errno ( errno , " Failed to make directory: %m " ) ;
r = btrfs_subvol_make ( " /xxxrectest/dir/xxxrectest4/dir/xxxrectest5 " ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to make subvolume: %m " ) ;
if ( mkdir ( " /xxxrectest/mnt " , 0755 ) < 0 )
log_error_errno ( errno , " Failed to make directory: %m " ) ;
r = btrfs_subvol_remove ( " /xxxrectest " , true ) ;
if ( r < 0 )
log_error_errno ( r , " Failed to recursively remove subvolume: %m " ) ;
2014-12-12 05:15:58 +03:00
return 0 ;
}