~ubuntu-branches/ubuntu/hardy/silo/hardy-updates

« back to all changes in this revision

Viewing changes to second/fs/ext2.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* EXT2 Interface for SILO filesystem access routines
 
2
   
 
3
   Copyright (C) 1996 Maurizio Plaza
 
4
                 1996,1997,1999 Jakub Jelinek
 
5
                 2001 Ben Collins
 
6
   
 
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.
 
11
   
 
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.
 
16
 
 
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,
 
20
   USA.  */
 
21
 
 
22
#include <sys/types.h>
 
23
#include <silo.h>
 
24
#include <file.h>
 
25
#include <stringops.h>
 
26
 
 
27
static ino_t inode = 0;
 
28
struct fs_ops ext2_fs_ops;
 
29
 
 
30
void com_err (const char *a, long i, const char *fmt,...)
 
31
{
 
32
    printf ((char *) fmt);
 
33
}
 
34
 
 
35
static void ext2fs_error (int errcode)
 
36
{
 
37
#if 0
 
38
    int i;
 
39
    for (i = 0; i < sizeof (ext2errors) / sizeof (ext2errors[0]); i++)
 
40
        if (ext2errors[i].errnum == errcode) {
 
41
            printf ("%s", ext2errors [i].desc);
 
42
            return;
 
43
        }
 
44
#endif
 
45
    printf ("Unknown ext2 error");
 
46
}
 
47
 
 
48
static int open_ext2 (char *device)
 
49
{
 
50
    int retval;
 
51
 
 
52
    retval = ext2fs_open (device, EXT2_FLAG_RW, 0, 0, silo_io_manager, &fs);
 
53
    if (retval == EXT2_ET_BAD_MAGIC)
 
54
        return 0;
 
55
    if (retval) {
 
56
        printf ("\n");
 
57
        ext2fs_error (retval);
 
58
        printf ("\n");
 
59
        return 0;
 
60
    }
 
61
    root = EXT2_ROOT_INO;
 
62
    return 1;
 
63
}
 
64
 
 
65
static int dump_block_ext2 (ext2_filsys fs, blk_t *blocknr,
 
66
                            int blockcnt, void *private)
 
67
{
 
68
    return dump_block(blocknr, blockcnt);
 
69
}
 
70
 
 
71
static int dump_ext2 (void)
 
72
{
 
73
    if (ext2fs_block_iterate (fs, inode, 0, 0, dump_block_ext2, 0))
 
74
        return 0;
 
75
 
 
76
    return dump_finish ();
 
77
}
 
78
 
 
79
static int ls_ext2_proc(struct ext2_dir_entry *dirent, int offset,
 
80
                        int blocksize, char *buf, void *private)
 
81
{
 
82
    struct ext2_inode ino;
 
83
    int sl = 0, name_len = dirent->name_len & 0xFF;
 
84
    char name[256], symlink[256];
 
85
 
 
86
    strncpy(name, dirent->name, name_len);
 
87
    name[name_len] = 0;
 
88
 
 
89
    if (ext2fs_read_inode(fs, dirent->inode, &ino))
 
90
        strcpy (name, "--- error ---");
 
91
 
 
92
    if (LINUX_S_ISLNK (ino.i_mode)) {
 
93
        sl = 1;
 
94
        if (ext2fs_inode_data_blocks(fs, &ino)) {
 
95
            if (io_channel_read_blk(fs->io, ino.i_block[0], 1, symlink))
 
96
                ino.i_size = 0;
 
97
        } else {
 
98
            strncpy (symlink, (char *)&(ino.i_block[0]),ino.i_size);
 
99
        }
 
100
        symlink[ino.i_size] = 0;
 
101
    }
 
102
 
 
103
    register_silo_inode(ino.i_mtime, ino.i_size, ino.i_mode, ino.i_uid,
 
104
                        ino.i_gid, name, sl ? symlink : NULL);
 
105
 
 
106
    return 0;
 
107
}
 
108
 
 
109
static int ls_ext2 (void)
 
110
{
 
111
    return ext2fs_dir_iterate (fs, inode, DIRENT_FLAG_INCLUDE_EMPTY,
 
112
                                 0, ls_ext2_proc, NULL);
 
113
}
 
114
 
 
115
static int ino_size_ext2 (void) {
 
116
    struct ext2_inode ei;
 
117
    int retval;
 
118
 
 
119
    if ((retval = ext2fs_read_inode (fs, inode, &ei))) {
 
120
        printf ("\n");
 
121
        ext2fs_error (retval);
 
122
        printf ("\n");
 
123
        return 0;
 
124
    }
 
125
    return ei.i_size;
 
126
}
 
127
 
 
128
static int namei_follow_ext2 (const char *filename) {
 
129
    int ret = ext2fs_namei_follow (fs, root, root, filename, &inode);
 
130
 
 
131
    ext2_fs_ops.have_inode = (inode) ? 1 : 0;
 
132
 
 
133
    return ret;
 
134
}
 
135
 
 
136
static void print_error_ext2 (int error_val) {
 
137
    ext2fs_error (error_val);
 
138
}
 
139
 
 
140
void close_ext2 (void) {
 
141
    ext2fs_close(fs);
 
142
}
 
143
 
 
144
struct fs_ops ext2_fs_ops = {
 
145
    .name               = "Linux EXT2",
 
146
    .open               = open_ext2,
 
147
    .ls                 = ls_ext2,
 
148
    .dump               = dump_ext2,
 
149
    .close              = close_ext2,
 
150
    .ino_size           = ino_size_ext2,
 
151
    .print_error        = print_error_ext2,
 
152
    .namei_follow       = namei_follow_ext2,
 
153
    .have_inode         = 0,
 
154
};
 
155
 
 
156
/* These are silly stubs to satisfy libext2fs symbols */
 
157
unsigned long time(void)
 
158
{
 
159
        return 0;
 
160
}
 
161
 
 
162
void *realloc(void *p, int size)
 
163
{
 
164
        return NULL;
 
165
}