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.
18 #include <sys/types.h>
28 struct inode_walk_struct {
35 unsigned int get_pathname_failed:1;
36 unsigned int check_dirent:1;
39 static int ncheck_proc(struct ext2_dir_entry *dirent,
40 int offset EXT2FS_ATTR((unused)),
41 int blocksize EXT2FS_ATTR((unused)),
42 char *buf EXT2FS_ATTR((unused)),
45 struct inode_walk_struct *iw = (struct inode_walk_struct *) private;
46 struct ext2_inode inode;
48 int filetype = dirent->name_len >> 8;
52 if (iw->position <= 2)
54 for (i=0; i < iw->num_inodes; i++) {
55 if (iw->iarray[i] == dirent->inode) {
56 if (!iw->parent && !iw->get_pathname_failed) {
57 retval = ext2fs_get_pathname(current_fs,
61 com_err("ncheck", retval,
62 "while calling ext2fs_get_pathname for inode #%u", iw->dir);
63 iw->get_pathname_failed = 1;
67 printf("%u\t%s/%.*s", iw->iarray[i],
69 (dirent->name_len & 0xFF), dirent->name);
71 printf("%u\t<%u>/%.*s", iw->iarray[i],
73 (dirent->name_len & 0xFF), dirent->name);
74 if (iw->check_dirent && filetype) {
75 if (!debugfs_read_inode(dirent->inode, &inode,
77 filetype != ext2_file_type(inode.i_mode)) {
78 printf(" <--- BAD FILETYPE");
90 void do_ncheck(int argc, char **argv)
92 struct inode_walk_struct iw;
94 ext2_inode_scan scan = 0;
96 struct ext2_inode inode;
103 while ((c = getopt (argc, argv, "c")) != EOF) {
117 com_err(argv[0], 0, "Usage: ncheck [-c] <inode number> ...");
120 if (check_fs_open(argv[0]))
123 iw.iarray = malloc(sizeof(ext2_ino_t) * argc);
125 com_err("ncheck", ENOMEM,
126 "while allocating inode number array");
129 memset(iw.iarray, 0, sizeof(ext2_ino_t) * argc);
131 for (i=0; i < argc; i++) {
132 iw.iarray[i] = strtol(argv[i], &tmp, 0);
134 com_err(argv[0], 0, "Bad inode - %s", argv[i]);
139 iw.num_inodes = iw.inodes_left = argc;
141 retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
143 com_err("ncheck", retval, "while opening inode scan");
148 retval = ext2fs_get_next_inode(scan, &ino, &inode);
149 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
151 com_err("ncheck", retval, "while starting inode scan");
155 printf("Inode\tPathname\n");
157 if (!inode.i_links_count)
160 * To handle filesystems touched by 0.3c extfs; can be
165 /* Ignore anything that isn't a directory */
166 if (!LINUX_S_ISDIR(inode.i_mode))
172 iw.get_pathname_failed = 0;
174 retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
176 ext2fs_free_mem(&iw.parent);
178 com_err("ncheck", retval,
179 "while calling ext2_dir_iterate");
183 if (iw.inodes_left == 0)
188 retval = ext2fs_get_next_inode(scan, &ino, &inode);
189 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
192 com_err("ncheck", retval,
193 "while doing inode scan");
201 ext2fs_close_inode_scan(scan);