]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/cowextsize.c
2 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 * If configure didn't find a struct fsxattr with fsx_cowextsize,
22 * disable the only other source (so far) of struct fsxattr. Thus,
23 * build with the internal definition of struct fsxattr, which has
26 #include "platform_defs.h"
33 static cmdinfo_t cowextsize_cmd
;
34 static long cowextsize
;
41 " report or modify preferred CoW extent size (in bytes) for the current path\n"
43 " -R -- recursively descend (useful when current path is a directory)\n"
44 " -D -- recursively descend, only modifying cowextsize on directories\n"
49 get_cowextsize(const char *path
, int fd
)
53 if ((xfsctl(path
, fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0) {
54 printf("%s: XFS_IOC_FSGETXATTR %s: %s\n",
55 progname
, path
, strerror(errno
));
58 printf("[%u] %s\n", fsx
.fsx_cowextsize
, path
);
63 set_cowextsize(const char *path
, int fd
, long extsz
)
68 if (fstat64(fd
, &stat
) < 0) {
72 if ((xfsctl(path
, fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0) {
73 printf("%s: XFS_IOC_FSGETXATTR %s: %s\n",
74 progname
, path
, strerror(errno
));
78 if (S_ISREG(stat
.st_mode
) || S_ISDIR(stat
.st_mode
)) {
79 fsx
.fsx_xflags
|= FS_XFLAG_COWEXTSIZE
;
81 printf(_("invalid target file type - file %s\n"), path
);
84 fsx
.fsx_cowextsize
= extsz
;
86 if ((xfsctl(path
, fd
, FS_IOC_FSSETXATTR
, &fsx
)) < 0) {
87 printf("%s: XFS_IOC_FSSETXATTR %s: %s\n",
88 progname
, path
, strerror(errno
));
96 get_cowextsize_callback(
98 const struct stat
*stat
,
104 if (recurse_dir
&& !S_ISDIR(stat
->st_mode
))
107 fd
= open(path
, O_RDONLY
);
109 fprintf(stderr
, _("%s: cannot open %s: %s\n"),
110 progname
, path
, strerror(errno
));
112 get_cowextsize(path
, fd
);
119 set_cowextsize_callback(
121 const struct stat
*stat
,
127 if (recurse_dir
&& !S_ISDIR(stat
->st_mode
))
130 fd
= open(path
, O_RDONLY
);
132 fprintf(stderr
, _("%s: cannot open %s: %s\n"),
133 progname
, path
, strerror(errno
));
135 set_cowextsize(path
, fd
, cowextsize
);
146 size_t blocksize
, sectsize
;
149 recurse_all
= recurse_dir
= 0;
150 init_cvtnum(&blocksize
, §size
);
151 while ((c
= getopt(argc
, argv
, "DR")) != EOF
) {
162 return command_usage(&cowextsize_cmd
);
167 cowextsize
= (long)cvtnum(blocksize
, sectsize
, argv
[optind
]);
168 if (cowextsize
< 0) {
169 printf(_("non-numeric cowextsize argument -- %s\n"),
177 if (recurse_all
|| recurse_dir
)
178 nftw(file
->name
, (cowextsize
>= 0) ?
179 set_cowextsize_callback
: get_cowextsize_callback
,
180 100, FTW_PHYS
| FTW_MOUNT
| FTW_DEPTH
);
181 else if (cowextsize
>= 0)
182 set_cowextsize(file
->name
, file
->fd
, cowextsize
);
184 get_cowextsize(file
->name
, file
->fd
);
189 cowextsize_init(void)
191 cowextsize_cmd
.name
= "cowextsize";
192 cowextsize_cmd
.cfunc
= cowextsize_f
;
193 cowextsize_cmd
.args
= _("[-D | -R] [cowextsize]");
194 cowextsize_cmd
.argmin
= 0;
195 cowextsize_cmd
.argmax
= -1;
196 cowextsize_cmd
.flags
= CMD_NOMAP_OK
;
197 cowextsize_cmd
.oneline
=
198 _("get/set preferred CoW extent size (in bytes) for the open file");
199 cowextsize_cmd
.help
= cowextsize_help
;
201 add_command(&cowextsize_cmd
);