Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * debugfs.c --- a program which allows you to attach an ext2fs |
| 3 | * filesystem and play with it. |
| 4 | * |
| 5 | * Copyright (C) 1993 Theodore Ts'o. This file may be redistributed |
| 6 | * under the terms of the GNU Public License. |
| 7 | * |
| 8 | * Modifications by Robert Sanders <gt8134b@prism.gatech.edu> |
| 9 | */ |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <unistd.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <ctype.h> |
| 15 | #include <string.h> |
| 16 | #include <time.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 17 | #ifdef HAVE_GETOPT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 18 | #include <getopt.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 19 | #else |
| 20 | extern int optind; |
| 21 | extern char *optarg; |
| 22 | #endif |
| 23 | #ifdef HAVE_OPTRESET |
| 24 | extern int optreset; /* defined by BSD, but not others */ |
| 25 | #endif |
| 26 | #ifdef HAVE_ERRNO_H |
| 27 | #include <errno.h> |
| 28 | #endif |
| 29 | #include <fcntl.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
| 32 | |
| 33 | #include "et/com_err.h" |
| 34 | #include "ss/ss.h" |
| 35 | #include "debugfs.h" |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 36 | #include "uuid/uuid.h" |
Theodore Ts'o | f68aa41 | 1999-10-26 14:20:22 +0000 | [diff] [blame] | 37 | #include "e2p/e2p.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 38 | |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 39 | #include "../version.h" |
| 40 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 41 | extern ss_request_table debug_cmds; |
| 42 | |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 43 | ext2_filsys current_fs = NULL; |
| 44 | ext2_ino_t root, cwd; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 45 | |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 46 | static void open_filesystem(char *device, int open_flags, blk_t superblock, |
| 47 | blk_t blocksize, int catastrophic) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 48 | { |
| 49 | int retval; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 50 | |
| 51 | if (superblock != 0 && blocksize == 0) { |
| 52 | com_err(device, 0, "if you specify the superblock, you must also specify the block size"); |
| 53 | current_fs = NULL; |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | if (catastrophic && (open_flags & EXT2_FLAG_RW)) { |
| 58 | com_err(device, 0, |
| 59 | "opening read-only because of catastrophic mode"); |
| 60 | open_flags &= ~EXT2_FLAG_RW; |
| 61 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 62 | |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 63 | retval = ext2fs_open(device, open_flags, superblock, blocksize, |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 64 | unix_io_manager, ¤t_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 65 | if (retval) { |
| 66 | com_err(device, retval, "while opening filesystem"); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 67 | current_fs = NULL; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 68 | return; |
| 69 | } |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 70 | |
| 71 | if (catastrophic) |
| 72 | com_err(device, 0, "catastrophic mode - not reading inode or group bitmaps"); |
| 73 | else { |
| 74 | retval = ext2fs_read_inode_bitmap(current_fs); |
| 75 | if (retval) { |
| 76 | com_err(device, retval, "while reading inode bitmap"); |
| 77 | goto errout; |
| 78 | } |
| 79 | retval = ext2fs_read_block_bitmap(current_fs); |
| 80 | if (retval) { |
| 81 | com_err(device, retval, "while reading block bitmap"); |
| 82 | goto errout; |
| 83 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 84 | } |
| 85 | root = cwd = EXT2_ROOT_INO; |
| 86 | return; |
| 87 | |
| 88 | errout: |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 89 | retval = ext2fs_close(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 90 | if (retval) |
| 91 | com_err(device, retval, "while trying to close filesystem"); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 92 | current_fs = NULL; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void do_open_filesys(int argc, char **argv) |
| 96 | { |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 97 | const char *usage = "Usage: open [-s superblock] [-b blocksize] [-c] [-w] <device>"; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 98 | int c, err; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 99 | int catastrophic = 0; |
| 100 | blk_t superblock = 0; |
| 101 | blk_t blocksize = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 102 | int open_flags = 0; |
| 103 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 104 | optind = 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 105 | #ifdef HAVE_OPTRESET |
| 106 | optreset = 1; /* Makes BSD getopt happy */ |
| 107 | #endif |
Theodore Ts'o | 59cf7e0 | 2001-05-03 15:05:55 +0000 | [diff] [blame] | 108 | while ((c = getopt (argc, argv, "iwfcb:s:")) != EOF) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 109 | switch (c) { |
Theodore Ts'o | 59cf7e0 | 2001-05-03 15:05:55 +0000 | [diff] [blame] | 110 | case 'i': |
| 111 | open_flags |= EXT2_FLAG_IMAGE_FILE; |
| 112 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 113 | case 'w': |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 114 | open_flags |= EXT2_FLAG_RW; |
| 115 | break; |
| 116 | case 'f': |
| 117 | open_flags |= EXT2_FLAG_FORCE; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 118 | break; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 119 | case 'c': |
| 120 | catastrophic = 1; |
| 121 | break; |
| 122 | case 'b': |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 123 | blocksize = parse_ulong(optarg, argv[0], |
| 124 | "block size", &err); |
| 125 | if (err) |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 126 | return; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 127 | break; |
| 128 | case 's': |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 129 | superblock = parse_ulong(optarg, argv[0], |
| 130 | "superblock number", &err); |
| 131 | if (err) |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 132 | return; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 133 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 134 | default: |
| 135 | com_err(argv[0], 0, usage); |
| 136 | return; |
| 137 | } |
| 138 | } |
| 139 | if (optind != argc-1) { |
| 140 | com_err(argv[0], 0, usage); |
| 141 | return; |
| 142 | } |
| 143 | if (check_fs_not_open(argv[0])) |
| 144 | return; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 145 | open_filesystem(argv[optind], open_flags, |
| 146 | superblock, blocksize, catastrophic); |
| 147 | } |
| 148 | |
| 149 | void do_lcd(int argc, char **argv) |
| 150 | { |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 151 | if (common_args_process(argc, argv, 2, 2, "lcd", |
| 152 | "<native dir>", 0)) |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 153 | return; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 154 | |
| 155 | if (chdir(argv[1]) == -1) { |
| 156 | com_err(argv[0], errno, |
| 157 | "while trying to change native directory to %s", |
| 158 | argv[1]); |
| 159 | return; |
| 160 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 163 | static void close_filesystem(NOARGS) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 164 | { |
| 165 | int retval; |
| 166 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 167 | if (current_fs->flags & EXT2_FLAG_IB_DIRTY) { |
| 168 | retval = ext2fs_write_inode_bitmap(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 169 | if (retval) |
| 170 | com_err("ext2fs_write_inode_bitmap", retval, ""); |
| 171 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 172 | if (current_fs->flags & EXT2_FLAG_BB_DIRTY) { |
| 173 | retval = ext2fs_write_block_bitmap(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 174 | if (retval) |
| 175 | com_err("ext2fs_write_block_bitmap", retval, ""); |
| 176 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 177 | retval = ext2fs_close(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 178 | if (retval) |
| 179 | com_err("ext2fs_close", retval, ""); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 180 | current_fs = NULL; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
| 184 | void do_close_filesys(int argc, char **argv) |
| 185 | { |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 186 | if (common_args_process(argc, argv, 1, 1, "close_filesys", "", 0)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 187 | return; |
| 188 | close_filesystem(); |
| 189 | } |
| 190 | |
| 191 | void do_init_filesys(int argc, char **argv) |
| 192 | { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 193 | struct ext2_super_block param; |
| 194 | errcode_t retval; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 195 | int err; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 196 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 197 | if (common_args_process(argc, argv, 3, 3, "initialize", |
| 198 | "<device> <blocksize>", CHECK_FS_NOTOPEN)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 199 | return; |
| 200 | |
| 201 | memset(¶m, 0, sizeof(struct ext2_super_block)); |
Theodore Ts'o | b38cd28 | 2002-05-11 22:13:20 -0400 | [diff] [blame] | 202 | param.s_blocks_count = parse_ulong(argv[2], argv[0], |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 203 | "blocks count", &err); |
| 204 | if (err) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 205 | return; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 206 | retval = ext2fs_initialize(argv[1], 0, ¶m, |
| 207 | unix_io_manager, ¤t_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 208 | if (retval) { |
| 209 | com_err(argv[1], retval, "while initializing filesystem"); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 210 | current_fs = NULL; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 211 | return; |
| 212 | } |
| 213 | root = cwd = EXT2_ROOT_INO; |
| 214 | return; |
| 215 | } |
| 216 | |
Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 217 | static void print_features(struct ext2_super_block * s, FILE *f) |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 218 | { |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 219 | int i, j, printed=0; |
Theodore Ts'o | 092c3de | 2001-05-14 11:20:48 +0000 | [diff] [blame] | 220 | __u32 *mask = &s->s_feature_compat, m; |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 221 | |
Theodore Ts'o | 777ebb3 | 2001-05-13 02:45:15 +0000 | [diff] [blame] | 222 | fputs("Filesystem features:", f); |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 223 | for (i=0; i <3; i++,mask++) { |
| 224 | for (j=0,m=1; j < 32; j++, m<<=1) { |
| 225 | if (*mask & m) { |
| 226 | fprintf(f, " %s", e2p_feature2string(i, m)); |
| 227 | printed++; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | if (printed == 0) |
Theodore Ts'o | 777ebb3 | 2001-05-13 02:45:15 +0000 | [diff] [blame] | 232 | fputs("(none)", f); |
| 233 | fputs("\n", f); |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 236 | void do_show_super_stats(int argc, char *argv[]) |
| 237 | { |
| 238 | int i; |
| 239 | FILE *out; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 240 | struct ext2_group_desc *gdp; |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 241 | int c, header_only = 0; |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 242 | const char *usage = "Usage: show_super [-h]"; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 243 | |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 244 | optind = 0; |
| 245 | #ifdef HAVE_OPTRESET |
| 246 | optreset = 1; /* Makes BSD getopt happy */ |
| 247 | #endif |
| 248 | while ((c = getopt (argc, argv, "h")) != EOF) { |
| 249 | switch (c) { |
| 250 | case 'h': |
| 251 | header_only++; |
| 252 | break; |
| 253 | default: |
| 254 | com_err(argv[0], 0, usage); |
| 255 | return; |
| 256 | } |
| 257 | } |
| 258 | if (optind != argc) { |
| 259 | com_err(argv[0], 0, usage); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | if (check_fs_open(argv[0])) |
| 263 | return; |
| 264 | out = open_pager(); |
Theodore Ts'o | bd09eff | 2000-08-14 20:39:17 +0000 | [diff] [blame] | 265 | |
| 266 | list_super2(current_fs->super, out); |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 267 | |
| 268 | if (header_only) { |
| 269 | close_pager(out); |
| 270 | return; |
| 271 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 272 | |
| 273 | gdp = ¤t_fs->group_desc[0]; |
| 274 | for (i = 0; i < current_fs->group_desc_count; i++, gdp++) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 275 | fprintf(out, " Group %2d: block bitmap at %d, " |
| 276 | "inode bitmap at %d, " |
| 277 | "inode table at %d\n" |
Theodore Ts'o | b74d1d8 | 2001-01-12 17:23:52 +0000 | [diff] [blame] | 278 | " %d free %s, " |
| 279 | "%d free %s, " |
| 280 | "%d used %s\n", |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 281 | i, gdp->bg_block_bitmap, |
| 282 | gdp->bg_inode_bitmap, gdp->bg_inode_table, |
| 283 | gdp->bg_free_blocks_count, |
Theodore Ts'o | b74d1d8 | 2001-01-12 17:23:52 +0000 | [diff] [blame] | 284 | gdp->bg_free_blocks_count != 1 ? "blocks" : "block", |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 285 | gdp->bg_free_inodes_count, |
Theodore Ts'o | b74d1d8 | 2001-01-12 17:23:52 +0000 | [diff] [blame] | 286 | gdp->bg_free_inodes_count != 1 ? "inodes" : "inode", |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 287 | gdp->bg_used_dirs_count, |
Theodore Ts'o | b74d1d8 | 2001-01-12 17:23:52 +0000 | [diff] [blame] | 288 | gdp->bg_used_dirs_count != 1 ? "directories" |
| 289 | : "directory"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 290 | close_pager(out); |
| 291 | } |
| 292 | |
Theodore Ts'o | 4a31c48 | 1998-03-30 01:27:25 +0000 | [diff] [blame] | 293 | void do_dirty_filesys(int argc, char **argv) |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 294 | { |
| 295 | if (check_fs_open(argv[0])) |
| 296 | return; |
Theodore Ts'o | 601002b | 1999-10-26 02:06:39 +0000 | [diff] [blame] | 297 | if (check_fs_read_write(argv[0])) |
| 298 | return; |
| 299 | |
| 300 | if (argv[1] && !strcmp(argv[1], "-clean")) |
| 301 | current_fs->super->s_state |= EXT2_VALID_FS; |
| 302 | else |
| 303 | current_fs->super->s_state &= ~EXT2_VALID_FS; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 304 | ext2fs_mark_super_dirty(current_fs); |
| 305 | } |
| 306 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 307 | struct list_blocks_struct { |
Andreas Dilger | 89e25cf | 2001-11-08 17:56:12 -0700 | [diff] [blame] | 308 | FILE *f; |
| 309 | e2_blkcnt_t total; |
| 310 | blk_t first_block, last_block; |
| 311 | e2_blkcnt_t first_bcnt, last_bcnt; |
| 312 | e2_blkcnt_t first; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 313 | }; |
| 314 | |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 315 | static void finish_range(struct list_blocks_struct *lb) |
| 316 | { |
| 317 | if (lb->first_block == 0) |
| 318 | return; |
| 319 | if (lb->first) |
| 320 | lb->first = 0; |
| 321 | else |
Theodore Ts'o | 80bfaa3 | 2000-08-18 15:08:37 +0000 | [diff] [blame] | 322 | fprintf(lb->f, ", "); |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 323 | if (lb->first_block == lb->last_block) |
Theodore Ts'o | e898188 | 2001-11-30 11:51:30 +0100 | [diff] [blame] | 324 | fprintf(lb->f, "(%lld):%d", lb->first_bcnt, lb->first_block); |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 325 | else |
Theodore Ts'o | e898188 | 2001-11-30 11:51:30 +0100 | [diff] [blame] | 326 | fprintf(lb->f, "(%lld-%lld):%d-%d", lb->first_bcnt, |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 327 | lb->last_bcnt, lb->first_block, lb->last_block); |
| 328 | lb->first_block = 0; |
| 329 | } |
| 330 | |
Andreas Dilger | 89e25cf | 2001-11-08 17:56:12 -0700 | [diff] [blame] | 331 | static int list_blocks_proc(ext2_filsys fs, blk_t *blocknr, |
| 332 | e2_blkcnt_t blockcnt, blk_t ref_block, |
| 333 | int ref_offset, void *private) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 334 | { |
| 335 | struct list_blocks_struct *lb = (struct list_blocks_struct *) private; |
| 336 | |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 337 | lb->total++; |
| 338 | if (blockcnt >= 0) { |
| 339 | /* |
| 340 | * See if we can add on to the existing range (if it exists) |
| 341 | */ |
| 342 | if (lb->first_block && |
| 343 | (lb->last_block+1 == *blocknr) && |
| 344 | (lb->last_bcnt+1 == blockcnt)) { |
| 345 | lb->last_block = *blocknr; |
| 346 | lb->last_bcnt = blockcnt; |
| 347 | return 0; |
| 348 | } |
| 349 | /* |
| 350 | * Start a new range. |
| 351 | */ |
| 352 | finish_range(lb); |
| 353 | lb->first_block = lb->last_block = *blocknr; |
| 354 | lb->first_bcnt = lb->last_bcnt = blockcnt; |
| 355 | return 0; |
| 356 | } |
| 357 | /* |
| 358 | * Not a normal block. Always force a new range. |
| 359 | */ |
| 360 | finish_range(lb); |
| 361 | if (lb->first) |
| 362 | lb->first = 0; |
Theodore Ts'o | a5eef73 | 2000-08-14 15:47:15 +0000 | [diff] [blame] | 363 | else |
Theodore Ts'o | 2c4a540 | 2000-08-19 17:33:28 +0000 | [diff] [blame] | 364 | fprintf(lb->f, ", "); |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 365 | if (blockcnt == -1) |
| 366 | fprintf(lb->f, "(IND):%d", *blocknr); |
| 367 | else if (blockcnt == -2) |
| 368 | fprintf(lb->f, "(DIND):%d", *blocknr); |
| 369 | else if (blockcnt == -3) |
| 370 | fprintf(lb->f, "(TIND):%d", *blocknr); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | |
Theodore Ts'o | 5e4f070 | 2001-06-01 15:36:05 +0000 | [diff] [blame] | 375 | static void dump_blocks(FILE *f, const char *prefix, ext2_ino_t inode) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 376 | { |
| 377 | struct list_blocks_struct lb; |
| 378 | |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 379 | fprintf(f, "%sBLOCKS:\n%s", prefix, prefix); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 380 | lb.total = 0; |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 381 | lb.first_block = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 382 | lb.f = f; |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 383 | lb.first = 1; |
Andreas Dilger | 89e25cf | 2001-11-08 17:56:12 -0700 | [diff] [blame] | 384 | ext2fs_block_iterate2(current_fs, inode, 0, NULL, |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 385 | list_blocks_proc, (void *)&lb); |
Theodore Ts'o | 0a3db93 | 2000-08-14 17:06:05 +0000 | [diff] [blame] | 386 | finish_range(&lb); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 387 | if (lb.total) |
Theodore Ts'o | e898188 | 2001-11-30 11:51:30 +0100 | [diff] [blame] | 388 | fprintf(f, "\n%sTOTAL: %lld\n", prefix, lb.total); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 389 | fprintf(f,"\n"); |
| 390 | } |
| 391 | |
| 392 | |
Theodore Ts'o | 5e4f070 | 2001-06-01 15:36:05 +0000 | [diff] [blame] | 393 | void internal_dump_inode(FILE *out, const char *prefix, |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 394 | ext2_ino_t inode_num, struct ext2_inode *inode, |
| 395 | int do_dump_blocks) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 396 | { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 397 | const char *i_type; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 398 | char frag, fsize; |
| 399 | int os = current_fs->super->s_creator_os; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 400 | |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 401 | if (LINUX_S_ISDIR(inode->i_mode)) i_type = "directory"; |
| 402 | else if (LINUX_S_ISREG(inode->i_mode)) i_type = "regular"; |
| 403 | else if (LINUX_S_ISLNK(inode->i_mode)) i_type = "symlink"; |
| 404 | else if (LINUX_S_ISBLK(inode->i_mode)) i_type = "block special"; |
| 405 | else if (LINUX_S_ISCHR(inode->i_mode)) i_type = "character special"; |
| 406 | else if (LINUX_S_ISFIFO(inode->i_mode)) i_type = "FIFO"; |
| 407 | else if (LINUX_S_ISSOCK(inode->i_mode)) i_type = "socket"; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 408 | else i_type = "bad type"; |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 409 | fprintf(out, "%sInode: %u Type: %s ", prefix, inode_num, i_type); |
| 410 | fprintf(out, "%sMode: %04o Flags: 0x%x Generation: %u\n", |
| 411 | prefix, |
| 412 | inode->i_mode & 0777, inode->i_flags, inode->i_generation); |
| 413 | fprintf(out, "%sUser: %5d Group: %5d Size: ", |
| 414 | prefix, inode->i_uid, inode->i_gid); |
Andreas Dilger | 1a6bb62 | 2001-11-08 17:52:26 -0700 | [diff] [blame] | 415 | if (LINUX_S_ISREG(inode->i_mode)) { |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 416 | __u64 i_size = (inode->i_size | |
| 417 | ((unsigned long long)inode->i_size_high << 32)); |
Andreas Dilger | 1a6bb62 | 2001-11-08 17:52:26 -0700 | [diff] [blame] | 418 | |
Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 419 | fprintf(out, "%lld\n", i_size); |
Andreas Dilger | 1a6bb62 | 2001-11-08 17:52:26 -0700 | [diff] [blame] | 420 | } else |
| 421 | fprintf(out, "%d\n", inode->i_size); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 422 | if (current_fs->super->s_creator_os == EXT2_OS_HURD) |
Theodore Ts'o | 62c06f7 | 1997-04-29 14:34:47 +0000 | [diff] [blame] | 423 | fprintf(out, |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 424 | "%sFile ACL: %d Directory ACL: %d Translator: %d\n", |
| 425 | prefix, |
| 426 | inode->i_file_acl, LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0, |
| 427 | inode->osd1.hurd1.h_i_translator); |
Theodore Ts'o | 62c06f7 | 1997-04-29 14:34:47 +0000 | [diff] [blame] | 428 | else |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 429 | fprintf(out, "%sFile ACL: %d Directory ACL: %d\n", |
| 430 | prefix, |
| 431 | inode->i_file_acl, LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0); |
| 432 | fprintf(out, "%sLinks: %d Blockcount: %d\n", |
| 433 | prefix, inode->i_links_count, inode->i_blocks); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 434 | switch (os) { |
| 435 | case EXT2_OS_LINUX: |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 436 | frag = inode->osd2.linux2.l_i_frag; |
| 437 | fsize = inode->osd2.linux2.l_i_fsize; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 438 | break; |
| 439 | case EXT2_OS_HURD: |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 440 | frag = inode->osd2.hurd2.h_i_frag; |
| 441 | fsize = inode->osd2.hurd2.h_i_fsize; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 442 | break; |
| 443 | case EXT2_OS_MASIX: |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 444 | frag = inode->osd2.masix2.m_i_frag; |
| 445 | fsize = inode->osd2.masix2.m_i_fsize; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 446 | break; |
| 447 | default: |
| 448 | frag = fsize = 0; |
| 449 | } |
Theodore Ts'o | da81e3f | 2001-03-29 20:49:58 +0000 | [diff] [blame] | 450 | fprintf(out, "%sFragment: Address: %d Number: %d Size: %d\n", |
| 451 | prefix, inode->i_faddr, frag, fsize); |
| 452 | fprintf(out, "%sctime: 0x%08x -- %s", prefix, inode->i_ctime, |
| 453 | time_to_string(inode->i_ctime)); |
| 454 | fprintf(out, "%satime: 0x%08x -- %s", prefix, inode->i_atime, |
| 455 | time_to_string(inode->i_atime)); |
| 456 | fprintf(out, "%smtime: 0x%08x -- %s", prefix, inode->i_mtime, |
| 457 | time_to_string(inode->i_mtime)); |
| 458 | if (inode->i_dtime) |
| 459 | fprintf(out, "%sdtime: 0x%08x -- %s", prefix, inode->i_dtime, |
| 460 | time_to_string(inode->i_dtime)); |
| 461 | if (LINUX_S_ISLNK(inode->i_mode) && inode->i_blocks == 0) |
| 462 | fprintf(out, "%sFast_link_dest: %.*s\n", prefix, |
| 463 | (int) inode->i_size, (char *)inode->i_block); |
| 464 | else if (do_dump_blocks) |
| 465 | dump_blocks(out, prefix, inode_num); |
| 466 | } |
| 467 | |
| 468 | static void dump_inode(ext2_ino_t inode_num, struct ext2_inode inode) |
| 469 | { |
| 470 | FILE *out; |
| 471 | |
| 472 | out = open_pager(); |
| 473 | internal_dump_inode(out, "", inode_num, &inode, 1); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 474 | close_pager(out); |
| 475 | } |
| 476 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 477 | void do_stat(int argc, char *argv[]) |
| 478 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 479 | ext2_ino_t inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 480 | struct ext2_inode inode_buf; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 481 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 482 | if (common_inode_args_process(argc, argv, &inode, 0)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 483 | return; |
| 484 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 485 | if (debugfs_read_inode(inode, &inode_buf, argv[0])) |
| 486 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 487 | |
| 488 | dump_inode(inode,inode_buf); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | void do_chroot(int argc, char *argv[]) |
| 493 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 494 | ext2_ino_t inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 495 | int retval; |
| 496 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 497 | if (common_inode_args_process(argc, argv, &inode, 0)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 498 | return; |
| 499 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 500 | retval = ext2fs_check_directory(current_fs, inode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 501 | if (retval) { |
| 502 | com_err(argv[1], retval, ""); |
| 503 | return; |
| 504 | } |
| 505 | root = inode; |
| 506 | } |
| 507 | |
| 508 | void do_clri(int argc, char *argv[]) |
| 509 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 510 | ext2_ino_t inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 511 | struct ext2_inode inode_buf; |
| 512 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 513 | if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 514 | return; |
| 515 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 516 | if (debugfs_read_inode(inode, &inode_buf, argv[0])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 517 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 518 | memset(&inode_buf, 0, sizeof(inode_buf)); |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 519 | if (debugfs_write_inode(inode, &inode_buf, argv[0])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 520 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | void do_freei(int argc, char *argv[]) |
| 524 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 525 | ext2_ino_t inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 526 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 527 | if (common_inode_args_process(argc, argv, &inode, |
| 528 | CHECK_FS_RW | CHECK_FS_BITMAPS)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 529 | return; |
| 530 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 531 | if (!ext2fs_test_inode_bitmap(current_fs->inode_map,inode)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 532 | com_err(argv[0], 0, "Warning: inode already clear"); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 533 | ext2fs_unmark_inode_bitmap(current_fs->inode_map,inode); |
| 534 | ext2fs_mark_ib_dirty(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | void do_seti(int argc, char *argv[]) |
| 538 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 539 | ext2_ino_t inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 540 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 541 | if (common_inode_args_process(argc, argv, &inode, |
| 542 | CHECK_FS_RW | CHECK_FS_BITMAPS)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 543 | return; |
| 544 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 545 | if (ext2fs_test_inode_bitmap(current_fs->inode_map,inode)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 546 | com_err(argv[0], 0, "Warning: inode already set"); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 547 | ext2fs_mark_inode_bitmap(current_fs->inode_map,inode); |
| 548 | ext2fs_mark_ib_dirty(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | void do_testi(int argc, char *argv[]) |
| 552 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 553 | ext2_ino_t inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 554 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 555 | if (common_inode_args_process(argc, argv, &inode, CHECK_FS_BITMAPS)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 556 | return; |
| 557 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 558 | if (ext2fs_test_inode_bitmap(current_fs->inode_map,inode)) |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 559 | printf("Inode %u is marked in use\n", inode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 560 | else |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 561 | printf("Inode %u is not in use\n", inode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 564 | void do_freeb(int argc, char *argv[]) |
| 565 | { |
| 566 | blk_t block; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 567 | int count = 1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 568 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 569 | if (common_block_args_process(argc, argv, &block, &count)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 570 | return; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 571 | if (check_fs_read_write(argv[0])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 572 | return; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 573 | while (count-- > 0) { |
| 574 | if (!ext2fs_test_block_bitmap(current_fs->block_map,block)) |
| 575 | com_err(argv[0], 0, "Warning: block %d already clear", |
| 576 | block); |
| 577 | ext2fs_unmark_block_bitmap(current_fs->block_map,block); |
| 578 | block++; |
| 579 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 580 | ext2fs_mark_bb_dirty(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | void do_setb(int argc, char *argv[]) |
| 584 | { |
| 585 | blk_t block; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 586 | int count = 1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 587 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 588 | if (common_block_args_process(argc, argv, &block, &count)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 589 | return; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 590 | if (check_fs_read_write(argv[0])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 591 | return; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 592 | while (count-- > 0) { |
| 593 | if (ext2fs_test_block_bitmap(current_fs->block_map,block)) |
| 594 | com_err(argv[0], 0, "Warning: block %d already set", |
| 595 | block); |
| 596 | ext2fs_mark_block_bitmap(current_fs->block_map,block); |
| 597 | block++; |
| 598 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 599 | ext2fs_mark_bb_dirty(current_fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void do_testb(int argc, char *argv[]) |
| 603 | { |
| 604 | blk_t block; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 605 | int count = 1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 606 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 607 | if (common_block_args_process(argc, argv, &block, &count)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 608 | return; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 609 | while (count-- > 0) { |
| 610 | if (ext2fs_test_block_bitmap(current_fs->block_map,block)) |
| 611 | printf("Block %d marked in use\n", block); |
| 612 | else |
| 613 | printf("Block %d not in use\n", block); |
| 614 | block++; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 615 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 618 | static void modify_u8(char *com, const char *prompt, |
| 619 | const char *format, __u8 *val) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 620 | { |
| 621 | char buf[200]; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 622 | unsigned long v; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 623 | char *tmp; |
| 624 | |
| 625 | sprintf(buf, format, *val); |
| 626 | printf("%30s [%s] ", prompt, buf); |
| 627 | fgets(buf, sizeof(buf), stdin); |
| 628 | if (buf[strlen (buf) - 1] == '\n') |
| 629 | buf[strlen (buf) - 1] = '\0'; |
| 630 | if (!buf[0]) |
| 631 | return; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 632 | v = strtoul(buf, &tmp, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 633 | if (*tmp) |
| 634 | com_err(com, 0, "Bad value - %s", buf); |
| 635 | else |
| 636 | *val = v; |
| 637 | } |
| 638 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 639 | static void modify_u16(char *com, const char *prompt, |
| 640 | const char *format, __u16 *val) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 641 | { |
| 642 | char buf[200]; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 643 | unsigned long v; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 644 | char *tmp; |
| 645 | |
| 646 | sprintf(buf, format, *val); |
| 647 | printf("%30s [%s] ", prompt, buf); |
| 648 | fgets(buf, sizeof(buf), stdin); |
| 649 | if (buf[strlen (buf) - 1] == '\n') |
| 650 | buf[strlen (buf) - 1] = '\0'; |
| 651 | if (!buf[0]) |
| 652 | return; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 653 | v = strtoul(buf, &tmp, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 654 | if (*tmp) |
| 655 | com_err(com, 0, "Bad value - %s", buf); |
| 656 | else |
| 657 | *val = v; |
| 658 | } |
| 659 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 660 | static void modify_u32(char *com, const char *prompt, |
| 661 | const char *format, __u32 *val) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 662 | { |
| 663 | char buf[200]; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 664 | unsigned long v; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 665 | char *tmp; |
| 666 | |
| 667 | sprintf(buf, format, *val); |
| 668 | printf("%30s [%s] ", prompt, buf); |
| 669 | fgets(buf, sizeof(buf), stdin); |
| 670 | if (buf[strlen (buf) - 1] == '\n') |
| 671 | buf[strlen (buf) - 1] = '\0'; |
| 672 | if (!buf[0]) |
| 673 | return; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 674 | v = strtoul(buf, &tmp, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 675 | if (*tmp) |
| 676 | com_err(com, 0, "Bad value - %s", buf); |
| 677 | else |
| 678 | *val = v; |
| 679 | } |
| 680 | |
| 681 | |
| 682 | void do_modify_inode(int argc, char *argv[]) |
| 683 | { |
| 684 | struct ext2_inode inode; |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 685 | ext2_ino_t inode_num; |
| 686 | int i; |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 687 | unsigned char *frag, *fsize; |
| 688 | char buf[80]; |
Theodore Ts'o | 7380ac9 | 2002-03-05 01:57:53 -0500 | [diff] [blame] | 689 | int os; |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 690 | const char *hex_format = "0x%x"; |
| 691 | const char *octal_format = "0%o"; |
| 692 | const char *decimal_format = "%d"; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 693 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 694 | if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 695 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 696 | |
Theodore Ts'o | 7380ac9 | 2002-03-05 01:57:53 -0500 | [diff] [blame] | 697 | os = current_fs->super->s_creator_os; |
| 698 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 699 | if (debugfs_read_inode(inode_num, &inode, argv[1])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 700 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 701 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 702 | modify_u16(argv[0], "Mode", octal_format, &inode.i_mode); |
| 703 | modify_u16(argv[0], "User ID", decimal_format, &inode.i_uid); |
| 704 | modify_u16(argv[0], "Group ID", decimal_format, &inode.i_gid); |
| 705 | modify_u32(argv[0], "Size", decimal_format, &inode.i_size); |
| 706 | modify_u32(argv[0], "Creation time", decimal_format, &inode.i_ctime); |
| 707 | modify_u32(argv[0], "Modification time", decimal_format, &inode.i_mtime); |
| 708 | modify_u32(argv[0], "Access time", decimal_format, &inode.i_atime); |
| 709 | modify_u32(argv[0], "Deletion time", decimal_format, &inode.i_dtime); |
| 710 | modify_u16(argv[0], "Link count", decimal_format, &inode.i_links_count); |
| 711 | modify_u32(argv[0], "Block count", decimal_format, &inode.i_blocks); |
| 712 | modify_u32(argv[0], "File flags", hex_format, &inode.i_flags); |
Theodore Ts'o | 3db9305 | 2000-12-30 20:26:31 +0000 | [diff] [blame] | 713 | modify_u32(argv[0], "Generation", hex_format, &inode.i_generation); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 714 | #if 0 |
| 715 | modify_u32(argv[0], "Reserved1", decimal_format, &inode.i_reserved1); |
| 716 | #endif |
| 717 | modify_u32(argv[0], "File acl", decimal_format, &inode.i_file_acl); |
Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 718 | if (LINUX_S_ISDIR(inode.i_mode)) |
| 719 | modify_u32(argv[0], "Directory acl", decimal_format, &inode.i_dir_acl); |
| 720 | else |
| 721 | modify_u32(argv[0], "High 32bits of size", decimal_format, &inode.i_size_high); |
Theodore Ts'o | 62c06f7 | 1997-04-29 14:34:47 +0000 | [diff] [blame] | 722 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 723 | if (current_fs->super->s_creator_os == EXT2_OS_HURD) |
Theodore Ts'o | 62c06f7 | 1997-04-29 14:34:47 +0000 | [diff] [blame] | 724 | modify_u32(argv[0], "Translator Block", |
| 725 | decimal_format, &inode.osd1.hurd1.h_i_translator); |
| 726 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 727 | modify_u32(argv[0], "Fragment address", decimal_format, &inode.i_faddr); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 728 | switch (os) { |
| 729 | case EXT2_OS_LINUX: |
| 730 | frag = &inode.osd2.linux2.l_i_frag; |
| 731 | fsize = &inode.osd2.linux2.l_i_fsize; |
| 732 | break; |
| 733 | case EXT2_OS_HURD: |
| 734 | frag = &inode.osd2.hurd2.h_i_frag; |
| 735 | fsize = &inode.osd2.hurd2.h_i_fsize; |
| 736 | break; |
| 737 | case EXT2_OS_MASIX: |
| 738 | frag = &inode.osd2.masix2.m_i_frag; |
| 739 | fsize = &inode.osd2.masix2.m_i_fsize; |
| 740 | break; |
| 741 | default: |
| 742 | frag = fsize = 0; |
| 743 | } |
| 744 | if (frag) |
| 745 | modify_u8(argv[0], "Fragment number", decimal_format, frag); |
| 746 | if (fsize) |
| 747 | modify_u8(argv[0], "Fragment size", decimal_format, fsize); |
| 748 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 749 | for (i=0; i < EXT2_NDIR_BLOCKS; i++) { |
| 750 | sprintf(buf, "Direct Block #%d", i); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 751 | modify_u32(argv[0], buf, decimal_format, &inode.i_block[i]); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 752 | } |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 753 | modify_u32(argv[0], "Indirect Block", decimal_format, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 754 | &inode.i_block[EXT2_IND_BLOCK]); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 755 | modify_u32(argv[0], "Double Indirect Block", decimal_format, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 756 | &inode.i_block[EXT2_DIND_BLOCK]); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 757 | modify_u32(argv[0], "Triple Indirect Block", decimal_format, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 758 | &inode.i_block[EXT2_TIND_BLOCK]); |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 759 | if (debugfs_write_inode(inode_num, &inode, argv[1])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 760 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 763 | void do_change_working_dir(int argc, char *argv[]) |
| 764 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 765 | ext2_ino_t inode; |
| 766 | int retval; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 767 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 768 | if (common_inode_args_process(argc, argv, &inode, 0)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 769 | return; |
| 770 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 771 | retval = ext2fs_check_directory(current_fs, inode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 772 | if (retval) { |
| 773 | com_err(argv[1], retval, ""); |
| 774 | return; |
| 775 | } |
| 776 | cwd = inode; |
| 777 | return; |
| 778 | } |
| 779 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 780 | void do_print_working_directory(int argc, char *argv[]) |
| 781 | { |
| 782 | int retval; |
| 783 | char *pathname = NULL; |
| 784 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 785 | if (common_args_process(argc, argv, 1, 1, |
| 786 | "print_working_directory", "", 0)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 787 | return; |
| 788 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 789 | retval = ext2fs_get_pathname(current_fs, cwd, 0, &pathname); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 790 | if (retval) { |
| 791 | com_err(argv[0], retval, |
| 792 | "while trying to get pathname of cwd"); |
| 793 | } |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 794 | printf("[pwd] INODE: %6u PATH: %s\n", cwd, pathname); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 795 | free(pathname); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 796 | retval = ext2fs_get_pathname(current_fs, root, 0, &pathname); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 797 | if (retval) { |
| 798 | com_err(argv[0], retval, |
| 799 | "while trying to get pathname of root"); |
| 800 | } |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 801 | printf("[root] INODE: %6u PATH: %s\n", root, pathname); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 802 | free(pathname); |
| 803 | return; |
| 804 | } |
| 805 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 806 | static void make_link(char *sourcename, char *destname) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 807 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 808 | ext2_ino_t inode; |
| 809 | int retval; |
| 810 | ext2_ino_t dir; |
| 811 | char *dest, *cp, *basename; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 812 | |
| 813 | /* |
| 814 | * Get the source inode |
| 815 | */ |
| 816 | inode = string_to_inode(sourcename); |
| 817 | if (!inode) |
| 818 | return; |
| 819 | basename = strrchr(sourcename, '/'); |
| 820 | if (basename) |
| 821 | basename++; |
| 822 | else |
| 823 | basename = sourcename; |
| 824 | /* |
| 825 | * Figure out the destination. First see if it exists and is |
| 826 | * a directory. |
| 827 | */ |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 828 | if (! (retval=ext2fs_namei(current_fs, root, cwd, destname, &dir))) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 829 | dest = basename; |
| 830 | else { |
| 831 | /* |
| 832 | * OK, it doesn't exist. See if it is |
| 833 | * '<dir>/basename' or 'basename' |
| 834 | */ |
| 835 | cp = strrchr(destname, '/'); |
| 836 | if (cp) { |
| 837 | *cp = 0; |
| 838 | dir = string_to_inode(destname); |
| 839 | if (!dir) |
| 840 | return; |
| 841 | dest = cp+1; |
| 842 | } else { |
| 843 | dir = cwd; |
| 844 | dest = destname; |
| 845 | } |
| 846 | } |
| 847 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 848 | retval = ext2fs_link(current_fs, dir, dest, inode, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 849 | if (retval) |
| 850 | com_err("make_link", retval, ""); |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | |
| 855 | void do_link(int argc, char *argv[]) |
| 856 | { |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 857 | if (common_args_process(argc, argv, 3, 3, "link", |
| 858 | "<source file> <dest_name>", CHECK_FS_RW)) |
| 859 | return; |
| 860 | |
| 861 | make_link(argv[1], argv[2]); |
| 862 | } |
| 863 | |
| 864 | static int mark_blocks_proc(ext2_filsys fs, blk_t *blocknr, |
| 865 | int blockcnt, void *private) |
| 866 | { |
| 867 | blk_t block; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 868 | |
| 869 | block = *blocknr; |
| 870 | ext2fs_block_alloc_stats(fs, block, +1); |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | void do_undel(int argc, char *argv[]) |
| 875 | { |
| 876 | ext2_ino_t ino; |
| 877 | struct ext2_inode inode; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 878 | |
| 879 | if (common_args_process(argc, argv, 3, 3, "undelete", |
| 880 | "<inode_num> <dest_name>", |
| 881 | CHECK_FS_RW | CHECK_FS_BITMAPS)) |
| 882 | return; |
| 883 | |
| 884 | ino = string_to_inode(argv[1]); |
| 885 | if (!ino) |
| 886 | return; |
| 887 | |
| 888 | if (debugfs_read_inode(ino, &inode, argv[1])) |
| 889 | return; |
| 890 | |
| 891 | if (ext2fs_test_inode_bitmap(current_fs->inode_map, ino)) { |
| 892 | com_err(argv[1], 0, "Inode is not marked as deleted"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 893 | return; |
| 894 | } |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 895 | |
| 896 | /* |
| 897 | * XXX this function doesn't handle changing the links count on the |
| 898 | * parent directory when undeleting a directory. |
| 899 | */ |
| 900 | inode.i_links_count = LINUX_S_ISDIR(inode.i_mode) ? 2 : 1; |
| 901 | inode.i_dtime = 0; |
| 902 | |
| 903 | if (debugfs_write_inode(ino, &inode, argv[0])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 904 | return; |
| 905 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 906 | ext2fs_block_iterate(current_fs, ino, 0, NULL, |
| 907 | mark_blocks_proc, NULL); |
| 908 | |
Theodore Ts'o | d7f64ae | 2002-07-09 01:27:05 -0400 | [diff] [blame^] | 909 | ext2fs_inode_alloc_stats2(current_fs, ino, +1, 0); |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 910 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 911 | make_link(argv[1], argv[2]); |
| 912 | } |
| 913 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 914 | static void unlink_file_by_name(char *filename) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 915 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 916 | int retval; |
| 917 | ext2_ino_t dir; |
| 918 | char *basename; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 919 | |
| 920 | basename = strrchr(filename, '/'); |
| 921 | if (basename) { |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 922 | *basename++ = '\0'; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 923 | dir = string_to_inode(filename); |
| 924 | if (!dir) |
| 925 | return; |
| 926 | } else { |
| 927 | dir = cwd; |
| 928 | basename = filename; |
| 929 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 930 | retval = ext2fs_unlink(current_fs, dir, basename, 0, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 931 | if (retval) |
| 932 | com_err("unlink_file_by_name", retval, ""); |
| 933 | return; |
| 934 | } |
| 935 | |
| 936 | void do_unlink(int argc, char *argv[]) |
| 937 | { |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 938 | if (common_args_process(argc, argv, 2, 2, "link", |
| 939 | "<pathname>", CHECK_FS_RW)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 940 | return; |
| 941 | |
| 942 | unlink_file_by_name(argv[1]); |
| 943 | } |
| 944 | |
| 945 | void do_find_free_block(int argc, char *argv[]) |
| 946 | { |
| 947 | blk_t free_blk, goal; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 948 | int count; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 949 | errcode_t retval; |
| 950 | char *tmp; |
| 951 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 952 | if ((argc > 3) || (argc==2 && *argv[1] == '?')) { |
| 953 | com_err(argv[0], 0, "Usage: find_free_block [count [goal]]"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 954 | return; |
| 955 | } |
| 956 | if (check_fs_open(argv[0])) |
| 957 | return; |
| 958 | |
| 959 | if (argc > 1) { |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 960 | count = strtol(argv[1],&tmp,0); |
| 961 | if (*tmp) { |
| 962 | com_err(argv[0], 0, "Bad count - %s", argv[1]); |
| 963 | return; |
| 964 | } |
| 965 | } else |
| 966 | count = 1; |
| 967 | |
| 968 | if (argc > 2) { |
| 969 | goal = strtol(argv[2], &tmp, 0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 970 | if (*tmp) { |
| 971 | com_err(argv[0], 0, "Bad goal - %s", argv[1]); |
| 972 | return; |
| 973 | } |
| 974 | } |
| 975 | else |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 976 | goal = current_fs->super->s_first_data_block; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 977 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 978 | printf("Free blocks found: "); |
| 979 | free_blk = goal - 1; |
| 980 | while (count-- > 0) { |
| 981 | retval = ext2fs_new_block(current_fs, free_blk + 1, 0, |
| 982 | &free_blk); |
| 983 | if (retval) { |
| 984 | com_err("ext2fs_new_block", retval, ""); |
| 985 | return; |
| 986 | } else |
| 987 | printf("%d ", free_blk); |
| 988 | } |
| 989 | printf("\n"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | void do_find_free_inode(int argc, char *argv[]) |
| 993 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 994 | ext2_ino_t free_inode, dir; |
| 995 | int mode; |
| 996 | int retval; |
| 997 | char *tmp; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 998 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 999 | if (argc > 3 || (argc>1 && *argv[1] == '?')) { |
| 1000 | com_err(argv[0], 0, "Usage: find_free_inode [dir] [mode]"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1001 | return; |
| 1002 | } |
| 1003 | if (check_fs_open(argv[0])) |
| 1004 | return; |
| 1005 | |
| 1006 | if (argc > 1) { |
| 1007 | dir = strtol(argv[1], &tmp, 0); |
| 1008 | if (*tmp) { |
| 1009 | com_err(argv[0], 0, "Bad dir - %s", argv[1]); |
| 1010 | return; |
| 1011 | } |
| 1012 | } |
| 1013 | else |
| 1014 | dir = root; |
| 1015 | if (argc > 2) { |
| 1016 | mode = strtol(argv[2], &tmp, 0); |
| 1017 | if (*tmp) { |
| 1018 | com_err(argv[0], 0, "Bad mode - %s", argv[2]); |
| 1019 | return; |
| 1020 | } |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1021 | } else |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1022 | mode = 010755; |
| 1023 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1024 | retval = ext2fs_new_inode(current_fs, dir, mode, 0, &free_inode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1025 | if (retval) |
| 1026 | com_err("ext2fs_new_inode", retval, ""); |
| 1027 | else |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1028 | printf("Free inode found: %u\n", free_inode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1031 | static errcode_t copy_file(int fd, ext2_ino_t newfile) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1032 | { |
Theodore Ts'o | 5a51384 | 1997-10-25 22:41:14 +0000 | [diff] [blame] | 1033 | ext2_file_t e2_file; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1034 | errcode_t retval; |
Theodore Ts'o | b784640 | 2001-06-03 23:27:56 +0000 | [diff] [blame] | 1035 | int got; |
| 1036 | unsigned int written; |
Theodore Ts'o | 5a51384 | 1997-10-25 22:41:14 +0000 | [diff] [blame] | 1037 | char buf[8192]; |
| 1038 | char *ptr; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1039 | |
Theodore Ts'o | 5a51384 | 1997-10-25 22:41:14 +0000 | [diff] [blame] | 1040 | retval = ext2fs_file_open(current_fs, newfile, |
| 1041 | EXT2_FILE_WRITE, &e2_file); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1042 | if (retval) |
| 1043 | return retval; |
| 1044 | |
Theodore Ts'o | 5a51384 | 1997-10-25 22:41:14 +0000 | [diff] [blame] | 1045 | while (1) { |
| 1046 | got = read(fd, buf, sizeof(buf)); |
| 1047 | if (got == 0) |
| 1048 | break; |
| 1049 | if (got < 0) { |
| 1050 | retval = errno; |
| 1051 | goto fail; |
| 1052 | } |
| 1053 | ptr = buf; |
| 1054 | while (got > 0) { |
| 1055 | retval = ext2fs_file_write(e2_file, ptr, |
| 1056 | got, &written); |
| 1057 | if (retval) |
| 1058 | goto fail; |
| 1059 | |
| 1060 | got -= written; |
| 1061 | ptr += written; |
| 1062 | } |
| 1063 | } |
| 1064 | retval = ext2fs_file_close(e2_file); |
Theodore Ts'o | 5a51384 | 1997-10-25 22:41:14 +0000 | [diff] [blame] | 1065 | return retval; |
| 1066 | |
| 1067 | fail: |
| 1068 | (void) ext2fs_file_close(e2_file); |
| 1069 | return retval; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Theodore Ts'o | 5a51384 | 1997-10-25 22:41:14 +0000 | [diff] [blame] | 1072 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1073 | void do_write(int argc, char *argv[]) |
| 1074 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1075 | int fd; |
| 1076 | struct stat statbuf; |
| 1077 | ext2_ino_t newfile; |
| 1078 | errcode_t retval; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1079 | struct ext2_inode inode; |
| 1080 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1081 | if (common_args_process(argc, argv, 3, 3, "write", |
| 1082 | "<native file> <new file>", CHECK_FS_RW)) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1083 | return; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1084 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1085 | fd = open(argv[1], O_RDONLY); |
| 1086 | if (fd < 0) { |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1087 | com_err(argv[1], errno, ""); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1088 | return; |
| 1089 | } |
| 1090 | if (fstat(fd, &statbuf) < 0) { |
| 1091 | com_err(argv[1], errno, ""); |
| 1092 | close(fd); |
| 1093 | return; |
| 1094 | } |
| 1095 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1096 | retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1097 | if (retval) { |
| 1098 | com_err(argv[0], retval, ""); |
| 1099 | close(fd); |
| 1100 | return; |
| 1101 | } |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1102 | printf("Allocated inode: %u\n", newfile); |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1103 | retval = ext2fs_link(current_fs, cwd, argv[2], newfile, |
| 1104 | EXT2_FT_REG_FILE); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1105 | if (retval) { |
| 1106 | com_err(argv[2], retval, ""); |
| 1107 | close(fd); |
| 1108 | return; |
| 1109 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1110 | if (ext2fs_test_inode_bitmap(current_fs->inode_map,newfile)) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1111 | com_err(argv[0], 0, "Warning: inode already set"); |
Theodore Ts'o | d7f64ae | 2002-07-09 01:27:05 -0400 | [diff] [blame^] | 1112 | ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1113 | memset(&inode, 0, sizeof(inode)); |
| 1114 | inode.i_mode = statbuf.st_mode; |
| 1115 | inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); |
| 1116 | inode.i_links_count = 1; |
| 1117 | inode.i_size = statbuf.st_size; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1118 | if (debugfs_write_inode(newfile, &inode, argv[0])) { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1119 | close(fd); |
| 1120 | return; |
| 1121 | } |
| 1122 | if (LINUX_S_ISREG(inode.i_mode)) { |
| 1123 | retval = copy_file(fd, newfile); |
| 1124 | if (retval) |
| 1125 | com_err("copy_file", retval, ""); |
| 1126 | } |
| 1127 | close(fd); |
| 1128 | } |
| 1129 | |
| 1130 | void do_mknod(int argc, char *argv[]) |
| 1131 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1132 | unsigned long mode, major, minor, nr; |
| 1133 | ext2_ino_t newfile; |
| 1134 | errcode_t retval; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1135 | struct ext2_inode inode; |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1136 | int filetype; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1137 | |
| 1138 | if (check_fs_open(argv[0])) |
| 1139 | return; |
| 1140 | if (argc < 3 || argv[2][1]) { |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1141 | usage: |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1142 | com_err(argv[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]"); |
| 1143 | return; |
| 1144 | } |
| 1145 | mode = minor = major = 0; |
| 1146 | switch (argv[2][0]) { |
| 1147 | case 'p': |
| 1148 | mode = LINUX_S_IFIFO; |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1149 | filetype = EXT2_FT_FIFO; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1150 | nr = 3; |
| 1151 | break; |
| 1152 | case 'c': |
| 1153 | mode = LINUX_S_IFCHR; |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1154 | filetype = EXT2_FT_CHRDEV; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1155 | nr = 5; |
| 1156 | break; |
| 1157 | case 'b': |
| 1158 | mode = LINUX_S_IFBLK; |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1159 | filetype = EXT2_FT_BLKDEV; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1160 | nr = 5; |
| 1161 | break; |
| 1162 | default: |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1163 | filetype = 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1164 | nr = 0; |
| 1165 | } |
| 1166 | if (nr == 5) { |
| 1167 | major = strtoul(argv[3], argv+3, 0); |
| 1168 | minor = strtoul(argv[4], argv+4, 0); |
| 1169 | if (major > 255 || minor > 255 || argv[3][0] || argv[4][0]) |
| 1170 | nr = 0; |
| 1171 | } |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1172 | if (argc != nr) |
| 1173 | goto usage; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1174 | if (check_fs_read_write(argv[0])) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1175 | return; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1176 | retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1177 | if (retval) { |
| 1178 | com_err(argv[0], retval, ""); |
| 1179 | return; |
| 1180 | } |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1181 | printf("Allocated inode: %u\n", newfile); |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1182 | retval = ext2fs_link(current_fs, cwd, argv[1], newfile, filetype); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1183 | if (retval) { |
| 1184 | if (retval == EXT2_ET_DIR_NO_SPACE) { |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1185 | retval = ext2fs_expand_dir(current_fs, cwd); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1186 | if (!retval) |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1187 | retval = ext2fs_link(current_fs, cwd, |
Theodore Ts'o | 085cb19 | 2001-05-09 06:09:12 +0000 | [diff] [blame] | 1188 | argv[1], newfile, |
| 1189 | filetype); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1190 | } |
| 1191 | if (retval) { |
| 1192 | com_err(argv[1], retval, ""); |
| 1193 | return; |
| 1194 | } |
| 1195 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1196 | if (ext2fs_test_inode_bitmap(current_fs->inode_map,newfile)) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1197 | com_err(argv[0], 0, "Warning: inode already set"); |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1198 | ext2fs_mark_inode_bitmap(current_fs->inode_map, newfile); |
| 1199 | ext2fs_mark_ib_dirty(current_fs); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1200 | memset(&inode, 0, sizeof(inode)); |
| 1201 | inode.i_mode = mode; |
| 1202 | inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); |
| 1203 | inode.i_block[0] = major*256+minor; |
| 1204 | inode.i_links_count = 1; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1205 | if (debugfs_write_inode(newfile, &inode, argv[0])) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1206 | return; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1209 | void do_mkdir(int argc, char *argv[]) |
| 1210 | { |
| 1211 | char *cp; |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1212 | ext2_ino_t parent; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1213 | char *name; |
| 1214 | errcode_t retval; |
| 1215 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1216 | if (common_args_process(argc, argv, 2, 2, "mkdir", |
| 1217 | "<filename>", CHECK_FS_RW)) |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 1218 | return; |
| 1219 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1220 | cp = strrchr(argv[1], '/'); |
| 1221 | if (cp) { |
| 1222 | *cp = 0; |
| 1223 | parent = string_to_inode(argv[1]); |
| 1224 | if (!parent) { |
| 1225 | com_err(argv[1], ENOENT, ""); |
| 1226 | return; |
| 1227 | } |
| 1228 | name = cp+1; |
| 1229 | } else { |
| 1230 | parent = cwd; |
| 1231 | name = argv[1]; |
| 1232 | } |
| 1233 | |
| 1234 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1235 | retval = ext2fs_mkdir(current_fs, parent, 0, name); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1236 | if (retval) { |
| 1237 | com_err("ext2fs_mkdir", retval, ""); |
| 1238 | return; |
| 1239 | } |
| 1240 | |
| 1241 | } |
| 1242 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1243 | static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr, |
| 1244 | int blockcnt, void *private) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1245 | { |
Theodore Ts'o | 3443689 | 2001-12-22 13:06:02 -0500 | [diff] [blame] | 1246 | blk_t block; |
Theodore Ts'o | 3443689 | 2001-12-22 13:06:02 -0500 | [diff] [blame] | 1247 | |
| 1248 | block = *blocknr; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1249 | ext2fs_block_alloc_stats(fs, block, -1); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1250 | return 0; |
| 1251 | } |
| 1252 | |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1253 | static void kill_file_by_inode(ext2_ino_t inode) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1254 | { |
| 1255 | struct ext2_inode inode_buf; |
| 1256 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1257 | if (debugfs_read_inode(inode, &inode_buf, 0)) |
| 1258 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1259 | inode_buf.i_dtime = time(NULL); |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1260 | if (debugfs_write_inode(inode, &inode_buf, 0)) |
| 1261 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1262 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1263 | ext2fs_block_iterate(current_fs, inode, 0, NULL, |
| 1264 | release_blocks_proc, NULL); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 1265 | printf("\n"); |
Theodore Ts'o | d7f64ae | 2002-07-09 01:27:05 -0400 | [diff] [blame^] | 1266 | ext2fs_inode_alloc_stats2(current_fs, inode, -1, |
| 1267 | LINUX_S_ISDIR(inode_buf.i_mode)); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | |
| 1271 | void do_kill_file(int argc, char *argv[]) |
| 1272 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1273 | ext2_ino_t inode_num; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1274 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1275 | if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1276 | return; |
| 1277 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1278 | kill_file_by_inode(inode_num); |
| 1279 | } |
| 1280 | |
| 1281 | void do_rm(int argc, char *argv[]) |
| 1282 | { |
| 1283 | int retval; |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1284 | ext2_ino_t inode_num; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1285 | struct ext2_inode inode; |
| 1286 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1287 | if (common_args_process(argc, argv, 2, 2, "rm", |
| 1288 | "<filename>", CHECK_FS_RW)) |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 1289 | return; |
| 1290 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1291 | retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1292 | if (retval) { |
Theodore Ts'o | 91d6d48 | 1998-08-01 01:03:39 +0000 | [diff] [blame] | 1293 | com_err(argv[0], retval, "while trying to resolve filename"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1294 | return; |
| 1295 | } |
| 1296 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1297 | if (debugfs_read_inode(inode_num, &inode, argv[0])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1298 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1299 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1300 | if (LINUX_S_ISDIR(inode.i_mode)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1301 | com_err(argv[0], 0, "file is a directory"); |
| 1302 | return; |
| 1303 | } |
| 1304 | |
| 1305 | --inode.i_links_count; |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1306 | if (debugfs_write_inode(inode_num, &inode, argv[0])) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1307 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1308 | |
| 1309 | unlink_file_by_name(argv[1]); |
| 1310 | if (inode.i_links_count == 0) |
| 1311 | kill_file_by_inode(inode_num); |
| 1312 | } |
| 1313 | |
Theodore Ts'o | d7f64ae | 2002-07-09 01:27:05 -0400 | [diff] [blame^] | 1314 | struct rd_struct { |
| 1315 | ext2_ino_t parent; |
| 1316 | int empty; |
| 1317 | }; |
| 1318 | |
| 1319 | static int rmdir_proc(ext2_ino_t dir, |
| 1320 | int entry, |
| 1321 | struct ext2_dir_entry *dirent, |
| 1322 | int offset, |
| 1323 | int blocksize, |
| 1324 | char *buf, |
| 1325 | void *private) |
| 1326 | { |
| 1327 | struct rd_struct *rds = (struct rd_struct *) private; |
| 1328 | |
| 1329 | if (dirent->inode == 0) |
| 1330 | return 0; |
| 1331 | if (((dirent->name_len&0xFF) == 1) && (dirent->name[0] == '.')) |
| 1332 | return 0; |
| 1333 | if (((dirent->name_len&0xFF) == 2) && (dirent->name[0] == '.') && |
| 1334 | (dirent->name[1] == '.')) { |
| 1335 | rds->parent = dirent->inode; |
| 1336 | return 0; |
| 1337 | } |
| 1338 | rds->empty = 0; |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
| 1342 | void do_rmdir(int argc, char *argv[]) |
| 1343 | { |
| 1344 | int retval; |
| 1345 | ext2_ino_t inode_num; |
| 1346 | struct ext2_inode inode; |
| 1347 | struct rd_struct rds; |
| 1348 | |
| 1349 | if (common_args_process(argc, argv, 2, 2, "rmdir", |
| 1350 | "<filename>", CHECK_FS_RW)) |
| 1351 | return; |
| 1352 | |
| 1353 | retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num); |
| 1354 | if (retval) { |
| 1355 | com_err(argv[0], retval, "while trying to resolve filename"); |
| 1356 | return; |
| 1357 | } |
| 1358 | |
| 1359 | if (debugfs_read_inode(inode_num, &inode, argv[0])) |
| 1360 | return; |
| 1361 | |
| 1362 | if (!LINUX_S_ISDIR(inode.i_mode)) { |
| 1363 | com_err(argv[0], 0, "file is not a directory"); |
| 1364 | return; |
| 1365 | } |
| 1366 | |
| 1367 | rds.parent = 0; |
| 1368 | rds.empty = 1; |
| 1369 | |
| 1370 | retval = ext2fs_dir_iterate2(current_fs, inode_num, 0, |
| 1371 | 0, rmdir_proc, &rds); |
| 1372 | if (retval) { |
| 1373 | com_err(argv[0], retval, "while iterating over directory"); |
| 1374 | return; |
| 1375 | } |
| 1376 | if (rds.empty == 0) { |
| 1377 | com_err(argv[0], 0, "directory not empty"); |
| 1378 | return; |
| 1379 | } |
| 1380 | |
| 1381 | inode.i_links_count = 0; |
| 1382 | if (debugfs_write_inode(inode_num, &inode, argv[0])) |
| 1383 | return; |
| 1384 | |
| 1385 | unlink_file_by_name(argv[1]); |
| 1386 | kill_file_by_inode(inode_num); |
| 1387 | |
| 1388 | if (rds.parent) { |
| 1389 | if (debugfs_read_inode(rds.parent, &inode, argv[0])) |
| 1390 | return; |
| 1391 | if (inode.i_links_count > 1) |
| 1392 | inode.i_links_count--; |
| 1393 | if (debugfs_write_inode(rds.parent, &inode, argv[0])) |
| 1394 | return; |
| 1395 | } |
| 1396 | } |
| 1397 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1398 | void do_show_debugfs_params(int argc, char *argv[]) |
| 1399 | { |
| 1400 | FILE *out = stdout; |
| 1401 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1402 | if (current_fs) |
| 1403 | fprintf(out, "Open mode: read-%s\n", |
| 1404 | current_fs->flags & EXT2_FLAG_RW ? "write" : "only"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1405 | fprintf(out, "Filesystem in use: %s\n", |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1406 | current_fs ? current_fs->device_name : "--none--"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | void do_expand_dir(int argc, char *argv[]) |
| 1410 | { |
Theodore Ts'o | b044c2e | 2001-01-11 15:26:39 +0000 | [diff] [blame] | 1411 | ext2_ino_t inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1412 | int retval; |
| 1413 | |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1414 | if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1415 | return; |
| 1416 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1417 | retval = ext2fs_expand_dir(current_fs, inode); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1418 | if (retval) |
| 1419 | com_err("ext2fs_expand_dir", retval, ""); |
| 1420 | return; |
| 1421 | } |
| 1422 | |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 1423 | void do_features(int argc, char *argv[]) |
| 1424 | { |
| 1425 | int i; |
| 1426 | |
| 1427 | if (check_fs_open(argv[0])) |
| 1428 | return; |
| 1429 | |
| 1430 | if ((argc != 1) && check_fs_read_write(argv[0])) |
| 1431 | return; |
| 1432 | for (i=1; i < argc; i++) { |
| 1433 | if (e2p_edit_feature(argv[i], |
Theodore Ts'o | 06968e7 | 1999-10-23 03:17:10 +0000 | [diff] [blame] | 1434 | ¤t_fs->super->s_feature_compat, 0)) |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 1435 | com_err(argv[0], 0, "Unknown feature: %s\n", |
| 1436 | argv[i]); |
| 1437 | else |
| 1438 | ext2fs_mark_super_dirty(current_fs); |
| 1439 | } |
Theodore Ts'o | 5dd8f96 | 2001-01-01 15:51:50 +0000 | [diff] [blame] | 1440 | print_features(current_fs->super, stdout); |
Theodore Ts'o | d3aea7d | 1999-09-14 20:55:37 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
Theodore Ts'o | b38cd28 | 2002-05-11 22:13:20 -0400 | [diff] [blame] | 1443 | void do_bmap(int argc, char *argv[]) |
| 1444 | { |
| 1445 | ext2_ino_t ino; |
| 1446 | blk_t blk, pblk; |
| 1447 | int err; |
| 1448 | errcode_t errcode; |
| 1449 | |
| 1450 | if (common_args_process(argc, argv, 3, 3, argv[0], |
| 1451 | "<file> logical_blk", 0)) |
| 1452 | return; |
| 1453 | |
| 1454 | ino = string_to_inode(argv[1]); |
| 1455 | blk = parse_ulong(argv[2], argv[0], "logical_block", &err); |
| 1456 | |
| 1457 | errcode = ext2fs_bmap(current_fs, ino, 0, 0, 0, blk, &pblk); |
| 1458 | if (errcode) { |
| 1459 | com_err("argv[0]", errcode, |
| 1460 | "while mapping logical block %d\n", blk); |
| 1461 | return; |
| 1462 | } |
| 1463 | printf("%d\n", pblk); |
| 1464 | } |
| 1465 | |
| 1466 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1467 | static int source_file(const char *cmd_file, int sci_idx) |
| 1468 | { |
| 1469 | FILE *f; |
| 1470 | char buf[256]; |
| 1471 | char *cp; |
| 1472 | int exit_status = 0; |
| 1473 | int retval; |
| 1474 | |
| 1475 | if (strcmp(cmd_file, "-") == 0) |
| 1476 | f = stdin; |
| 1477 | else { |
| 1478 | f = fopen(cmd_file, "r"); |
| 1479 | if (!f) { |
| 1480 | perror(cmd_file); |
| 1481 | exit(1); |
| 1482 | } |
| 1483 | } |
| 1484 | setbuf(stdout, NULL); |
| 1485 | setbuf(stderr, NULL); |
| 1486 | while (!feof(f)) { |
| 1487 | if (fgets(buf, sizeof(buf), f) == NULL) |
| 1488 | break; |
| 1489 | cp = strchr(buf, '\n'); |
| 1490 | if (cp) |
| 1491 | *cp = 0; |
| 1492 | cp = strchr(buf, '\r'); |
| 1493 | if (cp) |
| 1494 | *cp = 0; |
| 1495 | printf("debugfs: %s\n", buf); |
| 1496 | retval = ss_execute_line(sci_idx, buf); |
| 1497 | if (retval) { |
| 1498 | ss_perror(sci_idx, retval, buf); |
| 1499 | exit_status++; |
| 1500 | } |
| 1501 | } |
| 1502 | return exit_status; |
| 1503 | } |
| 1504 | |
Theodore Ts'o | a8859ca | 1997-09-16 02:08:28 +0000 | [diff] [blame] | 1505 | int main(int argc, char **argv) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1506 | { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1507 | int retval; |
| 1508 | int sci_idx; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 1509 | const char *usage = "Usage: debugfs [-b blocksize] [-s superblock] [-f cmd_file] [-R request] [-V] [[-w] [-c] device]"; |
Theodore Ts'o | f130481 | 1997-10-25 03:51:53 +0000 | [diff] [blame] | 1510 | int c; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1511 | int open_flags = 0; |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1512 | char *request = 0; |
| 1513 | int exit_status = 0; |
| 1514 | char *cmd_file = 0; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 1515 | blk_t superblock = 0; |
| 1516 | blk_t blocksize = 0; |
| 1517 | int catastrophic = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1518 | |
| 1519 | initialize_ext2_error_table(); |
Theodore Ts'o | 0f8973f | 2001-08-27 12:44:23 -0400 | [diff] [blame] | 1520 | fprintf (stderr, "debugfs %s (%s)\n", E2FSPROGS_VERSION, |
| 1521 | E2FSPROGS_DATE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1522 | |
Theodore Ts'o | 59cf7e0 | 2001-05-03 15:05:55 +0000 | [diff] [blame] | 1523 | while ((c = getopt (argc, argv, "iwcR:f:b:s:V")) != EOF) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1524 | switch (c) { |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1525 | case 'R': |
| 1526 | request = optarg; |
| 1527 | break; |
| 1528 | case 'f': |
| 1529 | cmd_file = optarg; |
| 1530 | break; |
Theodore Ts'o | 59cf7e0 | 2001-05-03 15:05:55 +0000 | [diff] [blame] | 1531 | case 'i': |
| 1532 | open_flags |= EXT2_FLAG_IMAGE_FILE; |
| 1533 | break; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1534 | case 'w': |
Theodore Ts'o | 59cf7e0 | 2001-05-03 15:05:55 +0000 | [diff] [blame] | 1535 | open_flags |= EXT2_FLAG_RW; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1536 | break; |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 1537 | case 'b': |
Theodore Ts'o | b38cd28 | 2002-05-11 22:13:20 -0400 | [diff] [blame] | 1538 | blocksize = parse_ulong(optarg, argv[0], |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1539 | "block size", 0); |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 1540 | break; |
| 1541 | case 's': |
Theodore Ts'o | b38cd28 | 2002-05-11 22:13:20 -0400 | [diff] [blame] | 1542 | superblock = parse_ulong(optarg, argv[0], |
Theodore Ts'o | e1018ee | 2002-01-03 04:55:25 -0500 | [diff] [blame] | 1543 | "superblock number", 0); |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 1544 | break; |
| 1545 | case 'c': |
| 1546 | catastrophic = 1; |
| 1547 | break; |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 1548 | case 'V': |
| 1549 | /* Print version number and exit */ |
| 1550 | fprintf(stderr, "\tUsing %s\n", |
| 1551 | error_message(EXT2_ET_BASE)); |
| 1552 | exit(0); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1553 | default: |
| 1554 | com_err(argv[0], 0, usage); |
Theodore Ts'o | b4ac9cc | 1997-10-15 01:54:48 +0000 | [diff] [blame] | 1555 | return 1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | if (optind < argc) |
Theodore Ts'o | 2e8d40d | 2000-05-27 15:15:40 +0000 | [diff] [blame] | 1559 | open_filesystem(argv[optind], open_flags, |
| 1560 | superblock, blocksize, catastrophic); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1561 | |
| 1562 | sci_idx = ss_create_invocation("debugfs", "0.0", (char *) NULL, |
| 1563 | &debug_cmds, &retval); |
| 1564 | if (retval) { |
| 1565 | ss_perror(sci_idx, retval, "creating invocation"); |
| 1566 | exit(1); |
| 1567 | } |
| 1568 | |
| 1569 | (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval); |
| 1570 | if (retval) { |
| 1571 | ss_perror(sci_idx, retval, "adding standard requests"); |
| 1572 | exit (1); |
| 1573 | } |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1574 | if (request) { |
| 1575 | retval = 0; |
| 1576 | retval = ss_execute_line(sci_idx, request); |
| 1577 | if (retval) { |
| 1578 | ss_perror(sci_idx, retval, request); |
| 1579 | exit_status++; |
| 1580 | } |
| 1581 | } else if (cmd_file) { |
| 1582 | exit_status = source_file(cmd_file, sci_idx); |
| 1583 | } else { |
| 1584 | ss_listen(sci_idx); |
| 1585 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1586 | |
Theodore Ts'o | fc6d9d5 | 1997-04-29 14:51:31 +0000 | [diff] [blame] | 1587 | if (current_fs) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1588 | close_filesystem(); |
| 1589 | |
Theodore Ts'o | e597304 | 2000-01-18 17:58:34 +0000 | [diff] [blame] | 1590 | return exit_status; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1591 | } |