1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 Red Hat, Inc.
8 #include "libfrog/fsgeom.h"
12 #include "libfrog/paths.h"
15 static cmdinfo_t prealloc_cmd
;
18 * Control preallocation amounts.
25 struct xfs_fs_eofblocks eofb
= {0};
26 struct xfs_fsop_geom
*fsgeom
= &file
->xfd
.fsgeom
;
29 eofb
.eof_version
= XFS_EOFBLOCKS_VERSION
;
31 while ((c
= getopt(argc
, argv
, "g:m:p:su:")) != EOF
) {
34 eofb
.eof_flags
|= XFS_EOF_FLAGS_GID
;
35 eofb
.eof_gid
= cvt_u32(optarg
, 10);
37 return command_usage(&prealloc_cmd
);
40 eofb
.eof_flags
|= XFS_EOF_FLAGS_UID
;
41 eofb
.eof_uid
= cvt_u32(optarg
, 10);
43 return command_usage(&prealloc_cmd
);
46 eofb
.eof_flags
|= XFS_EOF_FLAGS_PRID
;
47 eofb
.eof_prid
= cvt_u32(optarg
, 10);
49 return command_usage(&prealloc_cmd
);
52 eofb
.eof_flags
|= XFS_EOF_FLAGS_SYNC
;
55 eofb
.eof_flags
|= XFS_EOF_FLAGS_MINFILESIZE
;
56 eofb
.eof_min_file_size
= cvtnum(fsgeom
->blocksize
,
57 fsgeom
->sectsize
, optarg
);
61 return command_usage(&prealloc_cmd
);
65 return command_usage(&prealloc_cmd
);
67 if (ioctl(file
->xfd
.fd
, XFS_IOC_FREE_EOFBLOCKS
, &eofb
) < 0) {
68 fprintf(stderr
, _("%s: XFS_IOC_FREE_EOFBLOCKS on %s: %s\n"),
69 progname
, file
->name
, strerror(errno
));
79 "Remove speculative preallocation\n"
81 " -g gid -- remove prealloc on files matching group <gid>\n"
82 " -m minlen -- only consider files larger than <minlen>\n"
83 " -p prid -- remove prealloc on files matching project <prid>\n"
84 " -s -- wait for removal to complete\n"
85 " -u uid -- remove prealloc on files matching user <uid>\n"
87 "If none of -u, -g, or -p are specified, this command acts on all files.\n"
88 "minlen can take units.\n"
96 prealloc_cmd
.name
= "prealloc";
97 prealloc_cmd
.altname
= "prealloc";
98 prealloc_cmd
.cfunc
= prealloc_f
;
99 prealloc_cmd
.argmin
= 1;
100 prealloc_cmd
.argmax
= -1;
101 prealloc_cmd
.args
= "[-s] [-u id] [-g id] [-p id] [-m minlen]";
102 prealloc_cmd
.flags
= CMD_FLAG_ONESHOT
;
103 prealloc_cmd
.oneline
= _("Remove speculative preallocation");
104 prealloc_cmd
.help
= prealloc_help
;
106 add_command(&prealloc_cmd
);