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>
22 struct inode_walk_struct {
30 static int ncheck_proc(struct ext2_dir_entry *dirent,
31 int offset EXT2FS_ATTR((unused)),
32 int blocksize EXT2FS_ATTR((unused)),
33 char *buf EXT2FS_ATTR((unused)),
36 struct inode_walk_struct *iw = (struct inode_walk_struct *) private;
40 if (iw->position <= 2)
42 for (i=0; i < iw->num_inodes; i++) {
43 if (iw->iarray[i] == dirent->inode) {
44 printf("%u\t%s/%.*s\n", iw->iarray[i], iw->parent,
45 (dirent->name_len & 0xFF), dirent->name);
54 void do_ncheck(int argc, char **argv)
56 struct inode_walk_struct iw;
58 ext2_inode_scan scan = 0;
60 struct ext2_inode inode;
65 com_err(argv[0], 0, "Usage: ncheck <inode number> ...");
68 if (check_fs_open(argv[0]))
71 iw.iarray = malloc(sizeof(ext2_ino_t) * argc);
73 com_err("ncheck", ENOMEM,
74 "while allocating inode info array");
77 memset(iw.iarray, 0, sizeof(ext2_ino_t) * argc);
79 for (i=1; i < argc; i++) {
80 iw.iarray[i-1] = strtol(argv[i], &tmp, 0);
82 com_err(argv[0], 0, "Bad inode - %s", argv[i]);
87 iw.num_inodes = iw.inodes_left = argc-1;
89 retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
91 com_err("ncheck", retval, "while opening inode scan");
96 retval = ext2fs_get_next_inode(scan, &ino, &inode);
97 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
99 com_err("ncheck", retval, "while starting inode scan");
103 printf("Inode\tPathname\n");
105 if (!inode.i_links_count)
108 * To handle filesystems touched by 0.3c extfs; can be
113 /* Ignore anything that isn't a directory */
114 if (!LINUX_S_ISDIR(inode.i_mode))
119 retval = ext2fs_get_pathname(current_fs, ino, 0, &iw.parent);
121 com_err("ncheck", retval,
122 "while calling ext2fs_get_pathname");
126 retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
128 ext2fs_free_mem(&iw.parent);
130 com_err("ncheck", retval,
131 "while calling ext2_dir_iterate");
135 if (iw.inodes_left == 0)
140 retval = ext2fs_get_next_inode(scan, &ino, &inode);
141 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
144 com_err("ncheck", retval,
145 "while doing inode scan");
153 ext2fs_close_inode_scan(scan);