]>
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
19 #include <xfs/libxfs.h>
20 #include <xfs/command.h>
21 #include <xfs/input.h>
26 static cmdinfo_t mincore_cmd
;
35 size_t blocksize
, sectsize
;
37 void *current
, *previous
;
42 offset
= mapping
->offset
;
43 length
= mapping
->length
;
44 } else if (argc
== 3) {
45 init_cvtnum(&blocksize
, §size
);
46 offset
= cvtnum(blocksize
, sectsize
, argv
[1]);
48 printf(_("non-numeric offset argument -- %s\n"),
52 length
= cvtnum(blocksize
, sectsize
, argv
[2]);
54 printf(_("non-numeric length argument -- %s\n"),
59 return command_usage(&mincore_cmd
);
62 start
= check_mapping_range(mapping
, offset
, length
, 1);
66 vec
= calloc(length
/pagesize
, sizeof(unsigned char));
72 if (mincore(start
, length
, vec
) < 0) {
80 for (i
= 0; i
< length
/pagesize
; i
++, current
+= pagesize
) {
82 if (!previous
) { /* print start address */
83 printf("0x%lx - ", (unsigned long)current
);
84 previous
= start
+ (i
* pagesize
);
86 } else if (previous
) { /* print end and page count */
87 printf(_("0x%lx %lu pages (%llu : %lu)\n"),
88 (unsigned long)current
,
89 (unsigned long)(current
- previous
) / pagesize
,
90 (unsigned long long)offset
+
91 (unsigned long long)(previous
- start
),
92 (unsigned long)(current
- previous
));
97 printf(_("0x%lx %lu pages (%llu : %lu)\n"),
98 (unsigned long)current
,
99 (unsigned long)(current
- previous
) / pagesize
,
100 (unsigned long long)offset
+
101 (unsigned long long)(previous
- start
),
102 (unsigned long)(current
- previous
));
111 mincore_cmd
.name
= _("mincore");
112 mincore_cmd
.altname
= _("mi");
113 mincore_cmd
.cfunc
= mincore_f
;
114 mincore_cmd
.argmin
= 0;
115 mincore_cmd
.argmax
= 2;
116 mincore_cmd
.flags
= CMD_NOFILE_OK
| CMD_FOREIGN_OK
;
117 mincore_cmd
.args
= _("[off len]");
118 mincore_cmd
.oneline
= _("find mapping pages that are memory resident");
120 add_command(&mincore_cmd
);