1997-04-26 17:34:30 +04:00
|
|
|
/*
|
|
|
|
* dump.c --- dump the contents of an inode out to a file
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-26 17:34:30 +04:00
|
|
|
* Copyright (C) 1994 Theodore Ts'o. This file may be redistributed
|
|
|
|
* under the terms of the GNU Public License.
|
|
|
|
*/
|
|
|
|
|
2011-06-11 18:58:25 +04:00
|
|
|
#ifndef _GNU_SOURCE
|
2007-04-03 02:30:46 +04:00
|
|
|
#define _GNU_SOURCE /* for O_LARGEFILE */
|
2011-06-11 18:58:25 +04:00
|
|
|
#endif
|
2007-04-03 02:30:46 +04:00
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
1997-04-26 17:58:21 +04:00
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
1997-04-29 18:51:31 +04:00
|
|
|
#include <utime.h>
|
|
|
|
#ifdef HAVE_GETOPT_H
|
|
|
|
#include <getopt.h>
|
2008-08-28 07:07:54 +04:00
|
|
|
#else
|
1997-04-29 18:51:31 +04:00
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
#include "debugfs.h"
|
|
|
|
|
2003-01-23 02:25:39 +03:00
|
|
|
#ifndef O_LARGEFILE
|
|
|
|
#define O_LARGEFILE 0
|
|
|
|
#endif
|
|
|
|
|
1997-04-29 18:51:31 +04:00
|
|
|
/*
|
|
|
|
* The mode_xlate function translates a linux mode into a native-OS mode_t.
|
|
|
|
*/
|
|
|
|
static struct {
|
|
|
|
__u16 lmask;
|
|
|
|
mode_t mask;
|
|
|
|
} mode_table[] = {
|
|
|
|
{ LINUX_S_IRUSR, S_IRUSR },
|
|
|
|
{ LINUX_S_IWUSR, S_IWUSR },
|
|
|
|
{ LINUX_S_IXUSR, S_IXUSR },
|
|
|
|
{ LINUX_S_IRGRP, S_IRGRP },
|
|
|
|
{ LINUX_S_IWGRP, S_IWGRP },
|
|
|
|
{ LINUX_S_IXGRP, S_IXGRP },
|
|
|
|
{ LINUX_S_IROTH, S_IROTH },
|
|
|
|
{ LINUX_S_IWOTH, S_IWOTH },
|
|
|
|
{ LINUX_S_IXOTH, S_IXOTH },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 18:51:31 +04:00
|
|
|
static mode_t mode_xlate(__u16 lmode)
|
|
|
|
{
|
|
|
|
mode_t mode = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; mode_table[i].lmask; i++) {
|
|
|
|
if (lmode & mode_table[i].lmask)
|
|
|
|
mode |= mode_table[i].mask;
|
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
static void fix_perms(const char *cmd, const struct ext2_inode *inode,
|
|
|
|
int fd, const char *name)
|
|
|
|
{
|
|
|
|
struct utimbuf ut;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (fd != -1)
|
|
|
|
i = fchmod(fd, mode_xlate(inode->i_mode));
|
|
|
|
else
|
|
|
|
i = chmod(name, mode_xlate(inode->i_mode));
|
|
|
|
if (i == -1)
|
|
|
|
com_err(cmd, errno, "while setting permissions of %s", name);
|
|
|
|
|
|
|
|
#ifndef HAVE_FCHOWN
|
2000-12-31 04:39:54 +03:00
|
|
|
i = chown(name, inode->i_uid, inode->i_gid);
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
#else
|
|
|
|
if (fd != -1)
|
|
|
|
i = fchown(fd, inode->i_uid, inode->i_gid);
|
|
|
|
else
|
|
|
|
i = chown(name, inode->i_uid, inode->i_gid);
|
|
|
|
#endif
|
|
|
|
if (i == -1)
|
|
|
|
com_err(cmd, errno, "while changing ownership of %s", name);
|
|
|
|
|
|
|
|
if (fd != -1)
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
ut.actime = inode->i_atime;
|
|
|
|
ut.modtime = inode->i_mtime;
|
|
|
|
if (utime(name, &ut) == -1)
|
|
|
|
com_err(cmd, errno, "while setting times of %s", name);
|
|
|
|
}
|
|
|
|
|
2001-01-11 18:26:39 +03:00
|
|
|
static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
|
|
|
|
int preserve, char *outname)
|
1997-04-26 17:34:30 +04:00
|
|
|
{
|
|
|
|
errcode_t retval;
|
1997-04-29 18:51:31 +04:00
|
|
|
struct ext2_inode inode;
|
2013-01-01 16:30:14 +04:00
|
|
|
char *buf = 0;
|
1997-10-26 02:41:14 +04:00
|
|
|
ext2_file_t e2_file;
|
ChangeLog, Makefile.in, bmap.c, bmove.c, ext2fs.h, jump.funcs:
ext2fs.h: If __STRICT_ANSI__ is defined and we're on a platform with
32 bit longs, then we need to manually define __s64 and __u64, since
the current kernel header files don't define these if __STRICT_ANSI__
is defined. This is a problem if we are compiling with full GCC
warnings, since we do need 64 bit support.
Makefile.in (OBJS): Remove bmove.o from files to be built, since we're
not using ext2fs_move_blocks() and there is some question as to its
usefulness in its current form.
bmap.c (block_bmap): Remove unused function.
bmove.c (process_block): Fix -Wall warning.
ChangeLog, debugfs.c, debugfs.h, dump.c:
debugfs.h: Add declaration for do_dirty_filsys() to prevent -Wall
warnings.
debugfs.c (copy_file):
dump.c (dump_file): Fix -Wall warning caused by signed/unsigned mismatch.
1998-03-30 05:27:25 +04:00
|
|
|
int nbytes;
|
2013-01-01 16:30:14 +04:00
|
|
|
unsigned int got, blocksize = current_fs->blocksize;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2002-01-03 12:55:25 +03:00
|
|
|
if (debugfs_read_inode(ino, &inode, cmdname))
|
1997-04-29 18:51:31 +04:00
|
|
|
return;
|
1997-04-26 17:34:30 +04:00
|
|
|
|
1997-10-26 02:41:14 +04:00
|
|
|
retval = ext2fs_file_open(current_fs, ino, 0, &e2_file);
|
|
|
|
if (retval) {
|
|
|
|
com_err(cmdname, retval, "while opening ext2 file");
|
1997-04-26 17:34:30 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-01 16:30:14 +04:00
|
|
|
retval = ext2fs_get_mem(blocksize, &buf);
|
|
|
|
if (retval) {
|
|
|
|
com_err(cmdname, retval, "while allocating memory");
|
|
|
|
return;
|
|
|
|
}
|
1997-10-26 02:41:14 +04:00
|
|
|
while (1) {
|
2013-01-01 16:30:14 +04:00
|
|
|
retval = ext2fs_file_read(e2_file, buf, blocksize, &got);
|
2008-08-28 07:07:54 +04:00
|
|
|
if (retval)
|
1997-10-26 02:41:14 +04:00
|
|
|
com_err(cmdname, retval, "while reading ext2 file");
|
|
|
|
if (got == 0)
|
|
|
|
break;
|
|
|
|
nbytes = write(fd, buf, got);
|
2003-12-07 09:28:50 +03:00
|
|
|
if ((unsigned) nbytes != got)
|
1997-10-26 02:41:14 +04:00
|
|
|
com_err(cmdname, errno, "while writing file");
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
2013-01-01 16:30:14 +04:00
|
|
|
if (buf)
|
|
|
|
ext2fs_free_mem(&buf);
|
1997-10-26 02:41:14 +04:00
|
|
|
retval = ext2fs_file_close(e2_file);
|
|
|
|
if (retval) {
|
|
|
|
com_err(cmdname, retval, "while closing ext2 file");
|
|
|
|
return;
|
1997-04-26 17:34:30 +04:00
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
if (preserve)
|
|
|
|
fix_perms("dump_file", &inode, fd, outname);
|
|
|
|
else if (fd != 1)
|
1997-04-29 18:51:31 +04:00
|
|
|
close(fd);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_dump(int argc, char **argv)
|
|
|
|
{
|
2001-01-11 18:26:39 +03:00
|
|
|
ext2_ino_t inode;
|
|
|
|
int fd;
|
|
|
|
int c;
|
|
|
|
int preserve = 0;
|
|
|
|
char *in_fn, *out_fn;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
util.c, ls.c, logdump.c, htree.c, dump.c, debugfs.h, debugfs.c, ChangeLog:
util.c (reset_getopt), debugfs.c (do_open_filesys,
do_show_super_stats), ls.c (do_list_dir), dump.c (do_dump),
htree.c (do_htree_dump, do_dx_hash), logdump.c (do_logdump):
Define and use a new function, reset_getopt(), which does whatever
is necessary to reset getopt() again. This is different for
different implementations, so the portabilty issues are a bit of a
nightmare. (Addresses Debian bug #192834)
2003-05-14 07:03:43 +04:00
|
|
|
reset_getopt();
|
1997-04-29 18:51:31 +04:00
|
|
|
while ((c = getopt (argc, argv, "p")) != EOF) {
|
|
|
|
switch (c) {
|
|
|
|
case 'p':
|
|
|
|
preserve++;
|
|
|
|
break;
|
|
|
|
default:
|
2009-01-20 21:05:25 +03:00
|
|
|
print_usage:
|
|
|
|
com_err(argv[0], 0, "Usage: dump_inode [-p] "
|
|
|
|
"<file> <output_file>");
|
1997-04-29 18:51:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-01-20 21:05:25 +03:00
|
|
|
if (optind != argc-2)
|
|
|
|
goto print_usage;
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
if (check_fs_open(argv[0]))
|
|
|
|
return;
|
|
|
|
|
1997-04-29 18:51:31 +04:00
|
|
|
in_fn = argv[optind];
|
|
|
|
out_fn = argv[optind+1];
|
|
|
|
|
|
|
|
inode = string_to_inode(in_fn);
|
2008-08-28 07:07:54 +04:00
|
|
|
if (!inode)
|
1997-04-26 17:34:30 +04:00
|
|
|
return;
|
|
|
|
|
2003-01-23 02:25:39 +03:00
|
|
|
fd = open(out_fn, O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE, 0666);
|
1997-04-26 17:34:30 +04:00
|
|
|
if (fd < 0) {
|
|
|
|
com_err(argv[0], errno, "while opening %s for dump_inode",
|
1997-04-29 18:51:31 +04:00
|
|
|
out_fn);
|
1997-04-26 17:34:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-04-29 18:51:31 +04:00
|
|
|
dump_file(argv[0], inode, fd, preserve, out_fn);
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-01-11 18:26:39 +03:00
|
|
|
static void rdump_symlink(ext2_ino_t ino, struct ext2_inode *inode,
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
const char *fullname)
|
|
|
|
{
|
|
|
|
ext2_file_t e2_file;
|
|
|
|
char *buf;
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
buf = malloc(inode->i_size + 1);
|
|
|
|
if (!buf) {
|
|
|
|
com_err("rdump", errno, "while allocating for symlink");
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apparently, this is the right way to detect and handle fast
|
|
|
|
* symlinks; see do_stat() in debugfs.c. */
|
|
|
|
if (inode->i_blocks == 0)
|
|
|
|
strcpy(buf, (char *) inode->i_block);
|
|
|
|
else {
|
|
|
|
unsigned bytes = inode->i_size;
|
|
|
|
char *p = buf;
|
|
|
|
retval = ext2fs_file_open(current_fs, ino, 0, &e2_file);
|
|
|
|
if (retval) {
|
|
|
|
com_err("rdump", retval, "while opening symlink");
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
unsigned int got;
|
|
|
|
retval = ext2fs_file_read(e2_file, p, bytes, &got);
|
|
|
|
if (retval) {
|
|
|
|
com_err("rdump", retval, "while reading symlink");
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
bytes -= got;
|
|
|
|
p += got;
|
|
|
|
if (got == 0 || bytes == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[inode->i_size] = 0;
|
|
|
|
retval = ext2fs_file_close(e2_file);
|
|
|
|
if (retval)
|
|
|
|
com_err("rdump", retval, "while closing symlink");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (symlink(buf, fullname) == -1) {
|
|
|
|
com_err("rdump", errno, "while creating symlink %s -> %s", buf, fullname);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
errout:
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rdump_dirent(struct ext2_dir_entry *, int, int, char *, void *);
|
|
|
|
|
2001-01-11 18:26:39 +03:00
|
|
|
static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
const char *name, const char *dumproot)
|
|
|
|
{
|
|
|
|
char *fullname;
|
|
|
|
|
|
|
|
/* There are more efficient ways to do this, but this method
|
|
|
|
* requires only minimal debugging. */
|
|
|
|
fullname = malloc(strlen(dumproot) + strlen(name) + 2);
|
|
|
|
if (!fullname) {
|
|
|
|
com_err("rdump", errno, "while allocating memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sprintf(fullname, "%s/%s", dumproot, name);
|
|
|
|
|
|
|
|
if (LINUX_S_ISLNK(inode->i_mode))
|
|
|
|
rdump_symlink(ino, inode, fullname);
|
|
|
|
else if (LINUX_S_ISREG(inode->i_mode)) {
|
|
|
|
int fd;
|
2007-04-03 02:30:46 +04:00
|
|
|
fd = open(fullname, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, S_IRWXU);
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
if (fd == -1) {
|
|
|
|
com_err("rdump", errno, "while dumping %s", fullname);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
dump_file("rdump", ino, fd, 1, fullname);
|
|
|
|
}
|
|
|
|
else if (LINUX_S_ISDIR(inode->i_mode) && strcmp(name, ".") && strcmp(name, "..")) {
|
|
|
|
errcode_t retval;
|
|
|
|
|
|
|
|
/* Create the directory with 0700 permissions, because we
|
|
|
|
* expect to have to create entries it. Then fix its perms
|
|
|
|
* once we've done the traversal. */
|
|
|
|
if (mkdir(fullname, S_IRWXU) == -1) {
|
|
|
|
com_err("rdump", errno, "while making directory %s", fullname);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
|
|
|
|
rdump_dirent, (void *) fullname);
|
|
|
|
if (retval)
|
|
|
|
com_err("rdump", retval, "while dumping %s", fullname);
|
|
|
|
|
|
|
|
fix_perms("rdump", inode, -1, fullname);
|
|
|
|
}
|
|
|
|
/* else do nothing (don't dump device files, sockets, fifos, etc.) */
|
|
|
|
|
|
|
|
errout:
|
|
|
|
free(fullname);
|
|
|
|
}
|
|
|
|
|
2008-08-28 07:07:54 +04:00
|
|
|
static int rdump_dirent(struct ext2_dir_entry *dirent,
|
2003-12-07 09:28:50 +03:00
|
|
|
int offset EXT2FS_ATTR((unused)),
|
|
|
|
int blocksize EXT2FS_ATTR((unused)),
|
|
|
|
char *buf EXT2FS_ATTR((unused)), void *private)
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
{
|
2007-03-21 22:09:15 +03:00
|
|
|
char name[EXT2_NAME_LEN + 1];
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
int thislen;
|
|
|
|
const char *dumproot = private;
|
|
|
|
struct ext2_inode inode;
|
|
|
|
|
2011-09-17 00:49:17 +04:00
|
|
|
thislen = dirent->name_len & 0xFF;
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
strncpy(name, dirent->name, thislen);
|
|
|
|
name[thislen] = 0;
|
|
|
|
|
2002-01-03 12:55:25 +03:00
|
|
|
if (debugfs_read_inode(dirent->inode, &inode, name))
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
rdump_inode(dirent->inode, &inode, name, dumproot);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_rdump(int argc, char **argv)
|
|
|
|
{
|
2001-01-11 18:26:39 +03:00
|
|
|
ext2_ino_t ino;
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
struct ext2_inode inode;
|
|
|
|
struct stat st;
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
|
2002-01-03 12:55:25 +03:00
|
|
|
if (common_args_process(argc, argv, 3, 3, "rdump",
|
|
|
|
"<directory> <native directory>", 0))
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
ino = string_to_inode(argv[1]);
|
|
|
|
if (!ino)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Ensure ARGV[2] is a directory. */
|
|
|
|
i = stat(argv[2], &st);
|
|
|
|
if (i == -1) {
|
|
|
|
com_err("rdump", errno, "while statting %s", argv[2]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!S_ISDIR(st.st_mode)) {
|
|
|
|
com_err("rdump", 0, "%s is not a directory", argv[2]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-03 12:55:25 +03:00
|
|
|
if (debugfs_read_inode(ino, &inode, argv[1]))
|
ChangeLog, debug_cmds.ct, debugfs.8.in, debugfs.c, dump.c, ls.c:
debugfs.8.in: Documented new behaviour.
ls.c (ls_l_file): Fix Y2K bug -- was printing 22-May-100 for recent
files. Switched to 4-digit years.
dump.c, debug_cmds.ct (do_rdump): Add new debugfs command "rdump",
which recursively dumps a directory and its contents.
(fix_perms): New function. Break permission-fixing code out of
dump_file() so it can be called by rdump code as well.
(dump_file): Call fix_perms().
debugfs.c, debug_cmds.ct (do_lcd): Add new debugfs command "lcd",
which changes the cwd on the native filesystem.
debugfs.c (open_filesystem): Extra args for superblock, blocksize, and
catastrophic mode. Changed callers.
(do_open_filesys, main): Accept new -b, -s, -c options for
open_filesystem.
ChangeLog, mkdir.c:
mkdir.c (ext2fs_mkdir): Read the parent directory's inode earlier, so
that if there's an error reading it, we can more cleanly back out of
the operation.
version.h:
Update version file for WIP release.
2000-05-27 19:15:40 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
p = strrchr(argv[1], '/');
|
|
|
|
if (p)
|
|
|
|
p++;
|
|
|
|
else
|
|
|
|
p = argv[1];
|
|
|
|
|
|
|
|
rdump_inode(ino, &inode, p, argv[2]);
|
|
|
|
}
|
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
void do_cat(int argc, char **argv)
|
|
|
|
{
|
2001-01-11 18:26:39 +03:00
|
|
|
ext2_ino_t inode;
|
1997-04-26 17:34:30 +04:00
|
|
|
|
2002-01-03 12:55:25 +03:00
|
|
|
if (common_inode_args_process(argc, argv, &inode, 0))
|
1997-04-26 17:34:30 +04:00
|
|
|
return;
|
|
|
|
|
1997-04-29 18:51:31 +04:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
2008-08-28 07:07:54 +04:00
|
|
|
dump_file(argv[0], inode, 1, 0, argv[2]);
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|