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