]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/imap.c
fbc8e9e1b4605b0d588d0188563c3269a0a45638
[thirdparty/xfsprogs-dev.git] / io / imap.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2001-2003,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "command.h"
8 #include "input.h"
9 #include "init.h"
10 #include "io.h"
11
12 static cmdinfo_t imap_cmd;
13
14 static int
15 imap_f(int argc, char **argv)
16 {
17 int count;
18 int nent;
19 int i;
20 __u64 last = 0;
21 xfs_inogrp_t *t;
22 xfs_fsop_bulkreq_t bulkreq;
23
24 if (argc != 2)
25 nent = 1;
26 else
27 nent = atoi(argv[1]);
28
29 t = malloc(nent * sizeof(*t));
30 if (!t)
31 return 0;
32
33 bulkreq.lastip = &last;
34 bulkreq.icount = nent;
35 bulkreq.ubuffer = (void *)t;
36 bulkreq.ocount = &count;
37
38 while (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS, &bulkreq) == 0) {
39 if (count == 0)
40 goto out_free;
41 for (i = 0; i < count; i++) {
42 printf(_("ino %10llu count %2d mask %016llx\n"),
43 (unsigned long long)t[i].xi_startino,
44 t[i].xi_alloccount,
45 (unsigned long long)t[i].xi_allocmask);
46 }
47 }
48 perror("xfsctl(XFS_IOC_FSINUMBERS)");
49 exitcode = 1;
50 out_free:
51 free(t);
52 return 0;
53 }
54
55 void
56 imap_init(void)
57 {
58 imap_cmd.name = "imap";
59 imap_cmd.cfunc = imap_f;
60 imap_cmd.argmin = 0;
61 imap_cmd.argmax = 1;
62 imap_cmd.args = _("[nentries]");
63 imap_cmd.flags = CMD_NOMAP_OK | CMD_FLAG_ONESHOT;
64 imap_cmd.oneline = _("inode map for filesystem of current file");
65
66 if (expert)
67 add_command(&imap_cmd);
68 }