]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/mincore.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
13 static cmdinfo_t mincore_cmd
;
20 off64_t offset
, llength
;
22 size_t blocksize
, sectsize
;
24 void *current
, *previous
;
29 offset
= mapping
->offset
;
30 length
= mapping
->length
;
31 } else if (argc
== 3) {
32 init_cvtnum(&blocksize
, §size
);
33 offset
= cvtnum(blocksize
, sectsize
, argv
[1]);
35 printf(_("non-numeric offset argument -- %s\n"),
39 llength
= cvtnum(blocksize
, sectsize
, argv
[2]);
41 printf(_("non-numeric length argument -- %s\n"),
44 } else if (llength
> (size_t)llength
) {
45 printf(_("length argument too large -- %lld\n"),
49 length
= (size_t)llength
;
51 return command_usage(&mincore_cmd
);
54 start
= check_mapping_range(mapping
, offset
, length
, 1);
58 vec
= calloc(length
/pagesize
, sizeof(unsigned char));
64 if (mincore(start
, length
, vec
) < 0) {
72 for (i
= 0; i
< length
/pagesize
; i
++, current
+= pagesize
) {
74 if (!previous
) { /* print start address */
75 printf("0x%lx - ", (unsigned long)current
);
76 previous
= start
+ (i
* pagesize
);
78 } else if (previous
) { /* print end and page count */
79 printf(_("0x%lx %lu pages (%llu : %lu)\n"),
80 (unsigned long)current
,
81 (unsigned long)(current
- previous
) / pagesize
,
82 (unsigned long long)offset
+
83 (unsigned long long)(previous
- start
),
84 (unsigned long)(current
- previous
));
89 printf(_("0x%lx %lu pages (%llu : %lu)\n"),
90 (unsigned long)current
,
91 (unsigned long)(current
- previous
) / pagesize
,
92 (unsigned long long)offset
+
93 (unsigned long long)(previous
- start
),
94 (unsigned long)(current
- previous
));
103 mincore_cmd
.name
= "mincore";
104 mincore_cmd
.altname
= "mi";
105 mincore_cmd
.cfunc
= mincore_f
;
106 mincore_cmd
.argmin
= 0;
107 mincore_cmd
.argmax
= 2;
108 mincore_cmd
.flags
= CMD_NOFILE_OK
| CMD_FOREIGN_OK
;
109 mincore_cmd
.args
= _("[off len]");
110 mincore_cmd
.oneline
= _("find mapping pages that are memory resident");
112 add_command(&mincore_cmd
);