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>
21 struct inode_walk_struct {
29 static int ncheck_proc(struct ext2_dir_entry *dirent,
30 int offset EXT2FS_ATTR((unused)),
31 int blocksize EXT2FS_ATTR((unused)),
32 char *buf EXT2FS_ATTR((unused)),
35 struct inode_walk_struct *iw = (struct inode_walk_struct *) private;
39 if (iw->position <= 2)
41 for (i=0; i < iw->num_inodes; i++) {
42 if (iw->iarray[i] == dirent->inode) {
43 printf("%u\t%s/%.*s\n", iw->iarray[i], iw->parent,
44 (dirent->name_len & 0xFF), dirent->name);
53 void do_ncheck(int argc, char **argv)
55 struct inode_walk_struct iw;
57 ext2_inode_scan scan = 0;
59 struct ext2_inode inode;
64 com_err(argv[0], 0, "Usage: ncheck <inode number> ...");
67 if (check_fs_open(argv[0]))
70 iw.iarray = malloc(sizeof(ext2_ino_t) * argc);
72 com_err("ncheck", ENOMEM,
73 "while allocating inode info array");
76 memset(iw.iarray, 0, sizeof(ext2_ino_t) * argc);
78 for (i=1; i < argc; i++) {
79 iw.iarray[i-1] = strtol(argv[i], &tmp, 0);
81 com_err(argv[0], 0, "Bad inode - %s", argv[i]);
86 iw.num_inodes = iw.inodes_left = argc-1;
88 retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
90 com_err("ncheck", retval, "while opening inode scan");
95 retval = ext2fs_get_next_inode(scan, &ino, &inode);
96 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
98 com_err("ncheck", retval, "while starting inode scan");
102 printf("Inode\tPathname\n");
104 if (!inode.i_links_count)
107 * To handle filesystems touched by 0.3c extfs; can be
112 /* Ignore anything that isn't a directory */
113 if (!LINUX_S_ISDIR(inode.i_mode))
118 retval = ext2fs_get_pathname(current_fs, ino, 0, &iw.parent);
120 com_err("ncheck", retval,
121 "while calling ext2fs_get_pathname");
125 retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
127 ext2fs_free_mem(&iw.parent);
129 com_err("ncheck", retval,
130 "while calling ext2_dir_iterate");
134 if (iw.inodes_left == 0)
139 retval = ext2fs_get_next_inode(scan, &ino, &inode);
140 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
143 com_err("ncheck", retval,
144 "while doing inode scan");
152 ext2fs_close_inode_scan(scan);