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