}
#ifndef READ_ONLY
-/*
- * Given a mode, return the ext2 file type
- */
-static int ext2_file_type(unsigned int mode)
-{
- if (LINUX_S_ISREG(mode))
- return EXT2_FT_REG_FILE;
-
- if (LINUX_S_ISDIR(mode))
- return EXT2_FT_DIR;
-
- if (LINUX_S_ISCHR(mode))
- return EXT2_FT_CHRDEV;
-
- if (LINUX_S_ISBLK(mode))
- return EXT2_FT_BLKDEV;
-
- if (LINUX_S_ISLNK(mode))
- return EXT2_FT_SYMLINK;
-
- if (LINUX_S_ISFIFO(mode))
- return EXT2_FT_FIFO;
-
- if (LINUX_S_ISSOCK(mode))
- return EXT2_FT_SOCK;
-
- return 0;
-}
-
static void make_link(char *sourcename, char *destname)
{
ext2_ino_t ino;
#include <errno.h>
#endif
#include <sys/types.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
#include "debugfs.h"
int num_inodes;
int position;
char *parent;
- unsigned int get_pathname_failed;
+ unsigned int get_pathname_failed:1;
+ unsigned int check_dirent:1;
};
static int ncheck_proc(struct ext2_dir_entry *dirent,
void *private)
{
struct inode_walk_struct *iw = (struct inode_walk_struct *) private;
+ struct ext2_inode inode;
errcode_t retval;
+ int filetype = dirent->name_len >> 8;
int i;
iw->position++;
}
}
if (iw->parent)
- printf("%u\t%s/%.*s\n", iw->iarray[i],
+ printf("%u\t%s/%.*s", iw->iarray[i],
iw->parent,
(dirent->name_len & 0xFF), dirent->name);
else
- printf("%u\t<%u>/%.*s\n", iw->iarray[i],
+ printf("%u\t<%u>/%.*s", iw->iarray[i],
iw->dir,
(dirent->name_len & 0xFF), dirent->name);
+ if (iw->check_dirent && filetype) {
+ if (!debugfs_read_inode(dirent->inode, &inode,
+ "ncheck") &&
+ filetype != ext2_file_type(inode.i_mode)) {
+ printf(" <--- BAD FILETYLE");
+ }
+ }
+ putc('\n', stdout);
}
}
if (!iw->inodes_left)
void do_ncheck(int argc, char **argv)
{
struct inode_walk_struct iw;
- int i;
+ int c, i;
ext2_inode_scan scan = 0;
ext2_ino_t ino;
struct ext2_inode inode;
errcode_t retval;
char *tmp;
- if (argc < 2) {
- com_err(argv[0], 0, "Usage: ncheck <inode number> ...");
+ iw.check_dirent = 0;
+
+ reset_getopt();
+ while ((c = getopt (argc, argv, "c")) != EOF) {
+ switch (c) {
+ case 'c':
+ iw.check_dirent = 1;
+ break;
+ default:
+ goto print_usage;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc < 1) {
+ print_usage:
+ com_err(argv[0], 0, "Usage: ncheck [-c] <inode number> ...");
return;
}
if (check_fs_open(argv[0]))
iw.iarray = malloc(sizeof(ext2_ino_t) * argc);
if (!iw.iarray) {
com_err("ncheck", ENOMEM,
- "while allocating inode info array");
+ "while allocating inode number array");
return;
}
memset(iw.iarray, 0, sizeof(ext2_ino_t) * argc);
- for (i=1; i < argc; i++) {
- iw.iarray[i-1] = strtol(argv[i], &tmp, 0);
+ for (i=0; i < argc; i++) {
+ iw.iarray[i] = strtol(argv[i], &tmp, 0);
if (*tmp) {
com_err(argv[0], 0, "Bad inode - %s", argv[i]);
goto error_out;
}
}
- iw.num_inodes = iw.inodes_left = argc-1;
+ iw.num_inodes = iw.inodes_left = argc;
retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
if (retval) {
}
return 0;
}
+
+/*
+ * Given a mode, return the ext2 file type
+ */
+int ext2_file_type(unsigned int mode)
+{
+ if (LINUX_S_ISREG(mode))
+ return EXT2_FT_REG_FILE;
+
+ if (LINUX_S_ISDIR(mode))
+ return EXT2_FT_DIR;
+
+ if (LINUX_S_ISCHR(mode))
+ return EXT2_FT_CHRDEV;
+
+ if (LINUX_S_ISBLK(mode))
+ return EXT2_FT_BLKDEV;
+
+ if (LINUX_S_ISLNK(mode))
+ return EXT2_FT_SYMLINK;
+
+ if (LINUX_S_ISFIFO(mode))
+ return EXT2_FT_FIFO;
+
+ if (LINUX_S_ISSOCK(mode))
+ return EXT2_FT_SOCK;
+
+ return 0;
+}