]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/fadvise.c
61724b5ce246781aea06ed3897fb95bed5e0aad1
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <xfs/libxfs.h>
20 #include <xfs/command.h>
21 #include <xfs/input.h>
25 static cmdinfo_t fadvise_cmd
;
32 " advise the page cache about expected I/O patterns on the current file\n"
34 " Modifies kernel page cache behaviour when operating on the current file.\n"
35 " The range arguments are required by some advise commands ([*] below).\n"
36 " With no arguments, the POSIX_FADV_NORMAL advice is implied.\n"
37 " -d -- don't need these pages (POSIX_FADV_DONTNEED) [*]\n"
38 " -n -- data will be accessed once (POSIX_FADV_NOREUSE) [*]\n"
39 " -r -- expect random page references (POSIX_FADV_RANDOM)\n"
40 " -s -- expect sequential page references (POSIX_FADV_SEQUENTIAL)\n"
41 " -w -- will need these pages (POSIX_FADV_WILLNEED) [*]\n"
42 " Notes: these interfaces are not supported in Linux kernels before 2.6.\n"
43 " NORMAL sets the default readahead setting on the file.\n"
44 " RANDOM sets the readahead setting on the file to zero.\n"
45 " SEQUENTIAL sets double the default readahead setting on the file.\n"
46 " WILLNEED and NOREUSE are equivalent, and force the maximum readahead.\n"
57 int c
, range
= 0, advise
= POSIX_FADV_NORMAL
;
59 while ((c
= getopt(argc
, argv
, "dnrsw")) != EOF
) {
61 case 'd': /* Don't need these pages */
62 advise
= POSIX_FADV_DONTNEED
;
65 case 'n': /* Data will be accessed once */
66 advise
= POSIX_FADV_NOREUSE
;
69 case 'r': /* Expect random page references */
70 advise
= POSIX_FADV_RANDOM
;
73 case 's': /* Expect sequential page references */
74 advise
= POSIX_FADV_SEQUENTIAL
;
77 case 'w': /* Will need these pages */
78 advise
= POSIX_FADV_WILLNEED
;
82 return command_usage(&fadvise_cmd
);
86 size_t blocksize
, sectsize
;
88 if (optind
!= argc
- 2)
89 return command_usage(&fadvise_cmd
);
90 init_cvtnum(&blocksize
, §size
);
91 offset
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
93 printf(_("non-numeric offset argument -- %s\n"),
98 length
= cvtnum(blocksize
, sectsize
, argv
[optind
]);
100 printf(_("non-numeric length argument -- %s\n"),
104 } else if (optind
!= argc
) {
105 return command_usage(&fadvise_cmd
);
108 if (posix_fadvise64(file
->fd
, offset
, length
, advise
) < 0) {
118 fadvise_cmd
.name
= _("fadvise");
119 fadvise_cmd
.cfunc
= fadvise_f
;
120 fadvise_cmd
.argmin
= 0;
121 fadvise_cmd
.argmax
= -1;
122 fadvise_cmd
.flags
= CMD_NOMAP_OK
| CMD_FOREIGN_OK
;
123 fadvise_cmd
.args
= _("[-dnrsw] [off len]");
124 fadvise_cmd
.oneline
= _("advisory commands for sections of a file");
125 fadvise_cmd
.help
= fadvise_help
;
127 add_command(&fadvise_cmd
);