]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/mincore.c
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
25 static cmdinfo_t mincore_cmd
;
32 off64_t offset
, llength
;
34 size_t blocksize
, sectsize
;
36 void *current
, *previous
;
41 offset
= mapping
->offset
;
42 length
= mapping
->length
;
43 } else if (argc
== 3) {
44 init_cvtnum(&blocksize
, §size
);
45 offset
= cvtnum(blocksize
, sectsize
, argv
[1]);
47 printf(_("non-numeric offset argument -- %s\n"),
51 llength
= cvtnum(blocksize
, sectsize
, argv
[2]);
53 printf(_("non-numeric length argument -- %s\n"),
56 } else if (llength
> (size_t)llength
) {
57 printf(_("length argument too large -- %lld\n"),
61 length
= (size_t)llength
;
63 return command_usage(&mincore_cmd
);
66 start
= check_mapping_range(mapping
, offset
, length
, 1);
70 vec
= calloc(length
/pagesize
, sizeof(unsigned char));
76 if (mincore(start
, length
, vec
) < 0) {
84 for (i
= 0; i
< length
/pagesize
; i
++, current
+= pagesize
) {
86 if (!previous
) { /* print start address */
87 printf("0x%lx - ", (unsigned long)current
);
88 previous
= start
+ (i
* pagesize
);
90 } else if (previous
) { /* print end and page count */
91 printf(_("0x%lx %lu pages (%llu : %lu)\n"),
92 (unsigned long)current
,
93 (unsigned long)(current
- previous
) / pagesize
,
94 (unsigned long long)offset
+
95 (unsigned long long)(previous
- start
),
96 (unsigned long)(current
- previous
));
101 printf(_("0x%lx %lu pages (%llu : %lu)\n"),
102 (unsigned long)current
,
103 (unsigned long)(current
- previous
) / pagesize
,
104 (unsigned long long)offset
+
105 (unsigned long long)(previous
- start
),
106 (unsigned long)(current
- previous
));
115 mincore_cmd
.name
= "mincore";
116 mincore_cmd
.altname
= "mi";
117 mincore_cmd
.cfunc
= mincore_f
;
118 mincore_cmd
.argmin
= 0;
119 mincore_cmd
.argmax
= 2;
120 mincore_cmd
.flags
= CMD_NOFILE_OK
| CMD_FOREIGN_OK
;
121 mincore_cmd
.args
= _("[off len]");
122 mincore_cmd
.oneline
= _("find mapping pages that are memory resident");
124 add_command(&mincore_cmd
);