1997-04-29 21:48:10 +04:00
|
|
|
/*
|
|
|
|
* ls.c --- list directories
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Theodore Ts'o. This file may be redistributed
|
|
|
|
* under the terms of the GNU Public License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "debugfs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* list directory
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LONG_OPT 0x0001
|
|
|
|
|
|
|
|
struct list_dir_struct {
|
|
|
|
FILE *f;
|
|
|
|
int col;
|
|
|
|
int options;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *monstr[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
|
|
|
|
2001-01-11 18:26:39 +03:00
|
|
|
static void ls_l_file(struct list_dir_struct *ls, char *name, ext2_ino_t ino)
|
1997-04-29 21:48:10 +04:00
|
|
|
{
|
|
|
|
struct ext2_inode inode;
|
|
|
|
errcode_t retval;
|
|
|
|
struct tm *tm_p;
|
|
|
|
time_t modtime;
|
|
|
|
char datestr[80];
|
|
|
|
|
|
|
|
retval = ext2fs_read_inode(current_fs, ino, &inode);
|
|
|
|
if (retval) {
|
1997-10-25 07:51:53 +04:00
|
|
|
fprintf(ls->f, "%5ld --- error --- %s\n", retval, name);
|
1997-04-29 21:48:10 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
modtime = inode.i_mtime;
|
|
|
|
tm_p = localtime(&modtime);
|
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
|
|
|
sprintf(datestr, "%2d-%s-%4d %02d:%02d",
|
|
|
|
tm_p->tm_mday, monstr[tm_p->tm_mon], 1900 + tm_p->tm_year,
|
1997-04-29 21:48:10 +04:00
|
|
|
tm_p->tm_hour, tm_p->tm_min);
|
2001-01-11 18:26:39 +03:00
|
|
|
fprintf(ls->f, "%6u %6o %5d %5d ", ino, inode.i_mode,
|
Many files:
block.c (ext2fs_block_iterate3): Make the ref_offset field contain the
offset into the inode.i_blocks array when ref_block is zero. Since we
haven't done a formal release of e2fsprogs since block_iterate2 was
first introduced, I removed block_iterate2, and renamed block_iterate3
to be block_iterate2.
bb_inode.c, bmove.c, dblist_dir.c, dir_iterate.c, expanddir.c,
ext2fs.h, ext2fsP.h, read_bb.c: Change use of block_iterate and
block_iterate2 to block_iterate2 with the new prototype for the
interator function. (using blkcnt_t forr blockcount)
ChangeLog, debugfs.c, ls.c, lsdel.c:
debugfs.c, ls.c, lsdel.c: Add support for large files. (The high 32
bits share space with the i_dir_acl field.)
1998-03-24 19:17:51 +03:00
|
|
|
inode.i_uid, inode.i_gid);
|
|
|
|
if (LINUX_S_ISDIR(inode.i_mode))
|
|
|
|
fprintf(ls->f, "%5d", inode.i_size);
|
|
|
|
else
|
|
|
|
fprintf(ls->f, "%5lld", inode.i_size |
|
|
|
|
((__u64)inode.i_size_high << 32));
|
|
|
|
fprintf (ls->f, " %s %s\n", datestr, name);
|
1997-04-29 21:48:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ls_file(struct list_dir_struct *ls, char *name,
|
2001-01-11 18:26:39 +03:00
|
|
|
ext2_ino_t ino, int rec_len)
|
1997-04-29 21:48:10 +04:00
|
|
|
{
|
|
|
|
char tmp[EXT2_NAME_LEN + 16];
|
|
|
|
int thislen;
|
|
|
|
|
2001-01-11 18:26:39 +03:00
|
|
|
sprintf(tmp, "%u (%d) %s ", ino, rec_len, name);
|
1997-04-29 21:48:10 +04:00
|
|
|
thislen = strlen(tmp);
|
|
|
|
|
|
|
|
if (ls->col + thislen > 80) {
|
|
|
|
fprintf(ls->f, "\n");
|
|
|
|
ls->col = 0;
|
|
|
|
}
|
|
|
|
fprintf(ls->f, "%s", tmp);
|
|
|
|
ls->col += thislen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int list_dir_proc(struct ext2_dir_entry *dirent,
|
|
|
|
int offset,
|
|
|
|
int blocksize,
|
|
|
|
char *buf,
|
|
|
|
void *private)
|
|
|
|
{
|
|
|
|
char name[EXT2_NAME_LEN];
|
|
|
|
|
|
|
|
struct list_dir_struct *ls = (struct list_dir_struct *) private;
|
|
|
|
int thislen;
|
|
|
|
|
1998-03-09 16:07:09 +03:00
|
|
|
thislen = ((dirent->name_len & 0xFF) < EXT2_NAME_LEN) ?
|
|
|
|
(dirent->name_len & 0xFF) : EXT2_NAME_LEN;
|
1997-04-29 21:48:10 +04:00
|
|
|
strncpy(name, dirent->name, thislen);
|
|
|
|
name[thislen] = '\0';
|
|
|
|
|
|
|
|
if (ls->options & LONG_OPT)
|
|
|
|
ls_l_file(ls, name, dirent->inode);
|
|
|
|
else
|
|
|
|
ls_file(ls, name, dirent->inode, dirent->rec_len);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_list_dir(int argc, char *argv[])
|
|
|
|
{
|
2001-01-11 18:26:39 +03:00
|
|
|
ext2_ino_t inode;
|
|
|
|
int retval;
|
1997-04-29 21:48:10 +04:00
|
|
|
struct list_dir_struct ls;
|
2001-01-11 18:26:39 +03:00
|
|
|
int argptr = 1;
|
1997-04-29 21:48:10 +04:00
|
|
|
|
|
|
|
ls.options = 0;
|
|
|
|
if (check_fs_open(argv[0]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((argc > argptr) && (argv[argptr][0] == '-')) {
|
|
|
|
argptr++;
|
|
|
|
ls.options = LONG_OPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc <= argptr)
|
|
|
|
inode = cwd;
|
|
|
|
else
|
|
|
|
inode = string_to_inode(argv[argptr]);
|
|
|
|
if (!inode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ls.f = open_pager();
|
|
|
|
ls.col = 0;
|
|
|
|
retval = ext2fs_dir_iterate(current_fs, inode,
|
|
|
|
DIRENT_FLAG_INCLUDE_EMPTY,
|
|
|
|
0, list_dir_proc, &ls);
|
|
|
|
fprintf(ls.f, "\n");
|
|
|
|
close_pager(ls.f);
|
|
|
|
if (retval)
|
|
|
|
com_err(argv[1], retval, "");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|