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