1
/* EXT2 Interface for SILO filesystem access routines
3
Copyright (C) 1996 Maurizio Plaza
4
1996,1997,1999 Jakub Jelinek
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
22
#include <sys/types.h>
25
#include <stringops.h>
27
static ino_t inode = 0;
28
struct fs_ops ext2_fs_ops;
30
void com_err (const char *a, long i, const char *fmt,...)
32
printf ((char *) fmt);
35
static void ext2fs_error (int errcode)
39
for (i = 0; i < sizeof (ext2errors) / sizeof (ext2errors[0]); i++)
40
if (ext2errors[i].errnum == errcode) {
41
printf ("%s", ext2errors [i].desc);
45
printf ("Unknown ext2 error");
48
static int open_ext2 (char *device)
52
retval = ext2fs_open (device, EXT2_FLAG_RW, 0, 0, silo_io_manager, &fs);
53
if (retval == EXT2_ET_BAD_MAGIC)
57
ext2fs_error (retval);
65
static int dump_block_ext2 (ext2_filsys fs, blk_t *blocknr,
66
int blockcnt, void *private)
68
return dump_block(blocknr, blockcnt);
71
static int dump_ext2 (void)
73
if (ext2fs_block_iterate (fs, inode, 0, 0, dump_block_ext2, 0))
76
return dump_finish ();
79
static int ls_ext2_proc(struct ext2_dir_entry *dirent, int offset,
80
int blocksize, char *buf, void *private)
82
struct ext2_inode ino;
83
int sl = 0, name_len = dirent->name_len & 0xFF;
84
char name[256], symlink[256];
86
strncpy(name, dirent->name, name_len);
89
if (ext2fs_read_inode(fs, dirent->inode, &ino))
90
strcpy (name, "--- error ---");
92
if (LINUX_S_ISLNK (ino.i_mode)) {
94
if (ext2fs_inode_data_blocks(fs, &ino)) {
95
if (io_channel_read_blk(fs->io, ino.i_block[0], 1, symlink))
98
strncpy (symlink, (char *)&(ino.i_block[0]),ino.i_size);
100
symlink[ino.i_size] = 0;
103
register_silo_inode(ino.i_mtime, ino.i_size, ino.i_mode, ino.i_uid,
104
ino.i_gid, name, sl ? symlink : NULL);
109
static int ls_ext2 (void)
111
return ext2fs_dir_iterate (fs, inode, DIRENT_FLAG_INCLUDE_EMPTY,
112
0, ls_ext2_proc, NULL);
115
static int ino_size_ext2 (void) {
116
struct ext2_inode ei;
119
if ((retval = ext2fs_read_inode (fs, inode, &ei))) {
121
ext2fs_error (retval);
128
static int namei_follow_ext2 (const char *filename) {
129
int ret = ext2fs_namei_follow (fs, root, root, filename, &inode);
131
ext2_fs_ops.have_inode = (inode) ? 1 : 0;
136
static void print_error_ext2 (int error_val) {
137
ext2fs_error (error_val);
140
void close_ext2 (void) {
144
struct fs_ops ext2_fs_ops = {
145
.name = "Linux EXT2",
150
.ino_size = ino_size_ext2,
151
.print_error = print_error_ext2,
152
.namei_follow = namei_follow_ext2,
156
/* These are silly stubs to satisfy libext2fs symbols */
157
unsigned long time(void)
162
void *realloc(void *p, int size)