2 * ncheck.c --- given a list of inodes, generate a list of names
4 * Copyright (C) 1994 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
17 #include <sys/types.h>
27 struct inode_walk_struct {
28 struct inode_info *iarray;
35 static int ncheck_proc(struct ext2_dir_entry *dirent,
36 int offset EXT2FS_ATTR((unused)),
37 int blocksize EXT2FS_ATTR((unused)),
38 char *buf EXT2FS_ATTR((unused)),
41 struct inode_walk_struct *iw = (struct inode_walk_struct *) private;
45 if (iw->position <= 2)
47 for (i=0; i < iw->num_inodes; i++) {
48 if (iw->iarray[i].ino == dirent->inode) {
49 iw->iarray[i].parent = iw->parent;
59 void do_ncheck(int argc, char **argv)
61 struct inode_walk_struct iw;
62 struct inode_info *iinfo;
64 ext2_inode_scan scan = 0;
66 struct ext2_inode inode;
71 com_err(argv[0], 0, "Usage: ncheck <inode number> ...");
74 if (check_fs_open(argv[0]))
77 iw.iarray = malloc(sizeof(struct inode_info) * argc);
79 com_err("do_ncheck", ENOMEM,
80 "while allocating inode info array");
83 memset(iw.iarray, 0, sizeof(struct inode_info) * argc);
85 for (i=1; i < argc; i++) {
86 iw.iarray[i-1].ino = strtol(argv[i], &tmp, 0);
88 com_err(argv[0], 0, "Bad inode - %s", argv[i]);
93 iw.num_inodes = iw.inodes_left = argc-1;
95 retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
97 com_err("ncheck", retval, "while opening inode scan");
102 retval = ext2fs_get_next_inode(scan, &ino, &inode);
103 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
105 com_err("ncheck", retval, "while starting inode scan");
110 if (!inode.i_links_count)
113 * To handle filesystems touched by 0.3c extfs; can be
118 /* Ignore anything that isn't a directory */
119 if (!LINUX_S_ISDIR(inode.i_mode))
125 retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
128 com_err("ncheck", retval,
129 "while calling ext2_dir_iterate");
133 if (iw.inodes_left == 0)
138 retval = ext2fs_get_next_inode(scan, &ino, &inode);
139 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
142 com_err("ncheck", retval,
143 "while doing inode scan");
148 for (i=0, iinfo = iw.iarray; i < iw.num_inodes; i++, iinfo++) {
149 if (iinfo->parent == 0)
151 retval = ext2fs_get_pathname(current_fs, iinfo->parent,
152 iinfo->ino, &iinfo->pathname);
154 com_err("ncheck", retval,
155 "while resolving pathname for inode %d (%d)",
156 iinfo->parent, iinfo->ino);
159 printf("Inode\tPathname\n");
160 for (i=0, iinfo = iw.iarray; i < iw.num_inodes; i++, iinfo++) {
161 if (iinfo->parent == 0) {
162 printf("%u\t<inode not found>\n", iinfo->ino);
165 printf("%u\t%s\n", iinfo->ino, iinfo->pathname ?
166 iinfo->pathname : "<unknown pathname>");
168 free(iinfo->pathname);
174 ext2fs_close_inode_scan(scan);