2 * util.c --- utilities for the debugfs program
4 * Copyright (C) 1993, 1994 Theodore Ts'o. This file may be
5 * redistributed under the terms of the GNU Public License.
19 FILE *open_pager(void)
22 char *pager = getenv("PAGER");
24 signal(SIGPIPE, SIG_IGN);
28 outfile = popen(pager, "w");
35 void close_pager(FILE *stream)
37 if (stream && stream != stdout) fclose(stream);
41 * This routine is used whenever a command needs to turn a string into
44 ino_t string_to_inode(char *str)
47 int len = strlen(str);
52 * If the string is of the form <ino>, then treat it as an
55 if ((len > 2) && (str[0] == '<') && (str[len-1] == '>')) {
56 ino = strtoul(str+1, &end, 0);
61 retval = ext2fs_namei(current_fs, root, cwd, str, &ino);
63 com_err(str, retval, "");
70 * This routine returns 1 if the filesystem is not open, and prints an
71 * error message to that effect.
73 int check_fs_open(char *name)
76 com_err(name, 0, "Filesystem not open");
83 * This routine returns 1 if a filesystem is open, and prints an
84 * error message to that effect.
86 int check_fs_not_open(char *name)
90 "Filesystem %s is still open. Close it first.\n",
91 current_fs->device_name);
98 * This routine returns 1 if a filesystem is not opened read/write,
99 * and prints an error message to that effect.
101 int check_fs_read_write(char *name)
103 if (!(current_fs->flags & EXT2_FLAG_RW)) {
104 com_err(name, 0, "Filesystem opened read/only");
111 * This routine returns 1 if a filesystem is doesn't have its inode
112 * and block bitmaps loaded, and prints an error message to that
115 int check_fs_bitmaps(char *name)
117 if (!current_fs->block_map || !current_fs->inode_map) {
118 com_err(name, 0, "Filesystem bitmaps not loaded");
125 * This function takes a __u32 time value and converts it to a string,
128 char *time_to_string(__u32 cl)
130 time_t t = (time_t) cl;