]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/cowextsize.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
7 * If configure didn't find a struct fsxattr with fsx_cowextsize,
8 * disable the only other source (so far) of struct fsxattr. Thus,
9 * build with the internal definition of struct fsxattr, which has
12 #include "platform_defs.h"
19 static cmdinfo_t cowextsize_cmd
;
20 static long cowextsize
;
27 " report or modify preferred CoW extent size (in bytes) for the current path\n"
29 " -R -- recursively descend (useful when current path is a directory)\n"
30 " -D -- recursively descend, only modifying cowextsize on directories\n"
35 get_cowextsize(const char *path
, int fd
)
39 if ((xfsctl(path
, fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0) {
40 printf("%s: XFS_IOC_FSGETXATTR %s: %s\n",
41 progname
, path
, strerror(errno
));
44 printf("[%u] %s\n", fsx
.fsx_cowextsize
, path
);
49 set_cowextsize(const char *path
, int fd
, long extsz
)
54 if (fstat64(fd
, &stat
) < 0) {
58 if ((xfsctl(path
, fd
, FS_IOC_FSGETXATTR
, &fsx
)) < 0) {
59 printf("%s: XFS_IOC_FSGETXATTR %s: %s\n",
60 progname
, path
, strerror(errno
));
64 if (S_ISREG(stat
.st_mode
) || S_ISDIR(stat
.st_mode
)) {
65 fsx
.fsx_xflags
|= FS_XFLAG_COWEXTSIZE
;
67 printf(_("invalid target file type - file %s\n"), path
);
70 fsx
.fsx_cowextsize
= extsz
;
72 if ((xfsctl(path
, fd
, FS_IOC_FSSETXATTR
, &fsx
)) < 0) {
73 printf("%s: XFS_IOC_FSSETXATTR %s: %s\n",
74 progname
, path
, strerror(errno
));
82 get_cowextsize_callback(
84 const struct stat
*stat
,
90 if (recurse_dir
&& !S_ISDIR(stat
->st_mode
))
93 fd
= open(path
, O_RDONLY
);
95 fprintf(stderr
, _("%s: cannot open %s: %s\n"),
96 progname
, path
, strerror(errno
));
98 get_cowextsize(path
, fd
);
105 set_cowextsize_callback(
107 const struct stat
*stat
,
113 if (recurse_dir
&& !S_ISDIR(stat
->st_mode
))
116 fd
= open(path
, O_RDONLY
);
118 fprintf(stderr
, _("%s: cannot open %s: %s\n"),
119 progname
, path
, strerror(errno
));
121 set_cowextsize(path
, fd
, cowextsize
);
132 size_t blocksize
, sectsize
;
135 recurse_all
= recurse_dir
= 0;
136 init_cvtnum(&blocksize
, §size
);
137 while ((c
= getopt(argc
, argv
, "DR")) != EOF
) {
148 return command_usage(&cowextsize_cmd
);
153 cowextsize
= (long)cvtnum(blocksize
, sectsize
, argv
[optind
]);
154 if (cowextsize
< 0) {
155 printf(_("non-numeric cowextsize argument -- %s\n"),
163 if (recurse_all
|| recurse_dir
)
164 nftw(file
->name
, (cowextsize
>= 0) ?
165 set_cowextsize_callback
: get_cowextsize_callback
,
166 100, FTW_PHYS
| FTW_MOUNT
| FTW_DEPTH
);
167 else if (cowextsize
>= 0)
168 set_cowextsize(file
->name
, file
->fd
, cowextsize
);
170 get_cowextsize(file
->name
, file
->fd
);
175 cowextsize_init(void)
177 cowextsize_cmd
.name
= "cowextsize";
178 cowextsize_cmd
.cfunc
= cowextsize_f
;
179 cowextsize_cmd
.args
= _("[-D | -R] [cowextsize]");
180 cowextsize_cmd
.argmin
= 0;
181 cowextsize_cmd
.argmax
= -1;
182 cowextsize_cmd
.flags
= CMD_NOMAP_OK
;
183 cowextsize_cmd
.oneline
=
184 _("get/set preferred CoW extent size (in bytes) for the open file");
185 cowextsize_cmd
.help
= cowextsize_help
;
187 add_command(&cowextsize_cmd
);