blob: a88cf8704180261dc17559ca69d2ca3abbcbd203 [file] [log] [blame]
stroese2b918712004-12-16 17:26:24 +00001/*
2 * (C) Copyright 2004
3 * esd gmbh <www.esd-electronics.com>
4 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
5 *
6 * based on code from grub2 fs/ext2.c and fs/fshelp.c by
7 *
8 * GRUB -- GRand Unified Bootloader
9 * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <common.h>
stroese2b918712004-12-16 17:26:24 +000027#include <ext2fs.h>
28#include <malloc.h>
29#include <asm/byteorder.h>
30
wdenkefe2a4d2004-12-16 21:44:03 +000031extern int ext2fs_devread (int sector, int byte_offset, int byte_len,
32 char *buf);
stroese2b918712004-12-16 17:26:24 +000033
34/* Magic value used to identify an ext2 filesystem. */
35#define EXT2_MAGIC 0xEF53
36/* Amount of indirect blocks in an inode. */
37#define INDIRECT_BLOCKS 12
38/* Maximum lenght of a pathname. */
39#define EXT2_PATH_MAX 4096
40/* Maximum nesting of symlinks, used to prevent a loop. */
41#define EXT2_MAX_SYMLINKCNT 8
42
43/* Filetype used in directory entry. */
44#define FILETYPE_UNKNOWN 0
45#define FILETYPE_REG 1
46#define FILETYPE_DIRECTORY 2
47#define FILETYPE_SYMLINK 7
48
49/* Filetype information as used in inodes. */
50#define FILETYPE_INO_MASK 0170000
51#define FILETYPE_INO_REG 0100000
52#define FILETYPE_INO_DIRECTORY 0040000
53#define FILETYPE_INO_SYMLINK 0120000
54
55/* Bits used as offset in sector */
56#define DISK_SECTOR_BITS 9
57
58/* Log2 size of ext2 block in 512 blocks. */
59#define LOG2_EXT2_BLOCK_SIZE(data) (__le32_to_cpu (data->sblock.log2_block_size) + 1)
60
61/* Log2 size of ext2 block in bytes. */
62#define LOG2_BLOCK_SIZE(data) (__le32_to_cpu (data->sblock.log2_block_size) + 10)
63
64/* The size of an ext2 block in bytes. */
65#define EXT2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE(data))
66
67/* The ext2 superblock. */
wdenkefe2a4d2004-12-16 21:44:03 +000068struct ext2_sblock {
stroese2b918712004-12-16 17:26:24 +000069 uint32_t total_inodes;
70 uint32_t total_blocks;
71 uint32_t reserved_blocks;
72 uint32_t free_blocks;
73 uint32_t free_inodes;
74 uint32_t first_data_block;
75 uint32_t log2_block_size;
76 uint32_t log2_fragment_size;
77 uint32_t blocks_per_group;
78 uint32_t fragments_per_group;
79 uint32_t inodes_per_group;
80 uint32_t mtime;
81 uint32_t utime;
82 uint16_t mnt_count;
83 uint16_t max_mnt_count;
84 uint16_t magic;
85 uint16_t fs_state;
86 uint16_t error_handling;
87 uint16_t minor_revision_level;
88 uint32_t lastcheck;
89 uint32_t checkinterval;
90 uint32_t creator_os;
91 uint32_t revision_level;
92 uint16_t uid_reserved;
93 uint16_t gid_reserved;
94 uint32_t first_inode;
95 uint16_t inode_size;
96 uint16_t block_group_number;
97 uint32_t feature_compatibility;
98 uint32_t feature_incompat;
99 uint32_t feature_ro_compat;
100 uint32_t unique_id[4];
101 char volume_name[16];
102 char last_mounted_on[64];
103 uint32_t compression_info;
104};
105
106/* The ext2 blockgroup. */
wdenkefe2a4d2004-12-16 21:44:03 +0000107struct ext2_block_group {
stroese2b918712004-12-16 17:26:24 +0000108 uint32_t block_id;
109 uint32_t inode_id;
110 uint32_t inode_table_id;
111 uint16_t free_blocks;
112 uint16_t free_inodes;
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200113 uint16_t used_dir_cnt;
stroese2b918712004-12-16 17:26:24 +0000114 uint32_t reserved[3];
115};
116
117/* The ext2 inode. */
wdenkefe2a4d2004-12-16 21:44:03 +0000118struct ext2_inode {
stroese2b918712004-12-16 17:26:24 +0000119 uint16_t mode;
120 uint16_t uid;
121 uint32_t size;
122 uint32_t atime;
123 uint32_t ctime;
124 uint32_t mtime;
125 uint32_t dtime;
126 uint16_t gid;
127 uint16_t nlinks;
wdenkefe2a4d2004-12-16 21:44:03 +0000128 uint32_t blockcnt; /* Blocks of 512 bytes!! */
stroese2b918712004-12-16 17:26:24 +0000129 uint32_t flags;
130 uint32_t osd1;
wdenkefe2a4d2004-12-16 21:44:03 +0000131 union {
132 struct datablocks {
stroese2b918712004-12-16 17:26:24 +0000133 uint32_t dir_blocks[INDIRECT_BLOCKS];
134 uint32_t indir_block;
135 uint32_t double_indir_block;
136 uint32_t tripple_indir_block;
137 } blocks;
138 char symlink[60];
wdenkefe2a4d2004-12-16 21:44:03 +0000139 } b;
stroese2b918712004-12-16 17:26:24 +0000140 uint32_t version;
141 uint32_t acl;
142 uint32_t dir_acl;
143 uint32_t fragment_addr;
144 uint32_t osd2[3];
145};
146
147/* The header of an ext2 directory entry. */
wdenkefe2a4d2004-12-16 21:44:03 +0000148struct ext2_dirent {
stroese2b918712004-12-16 17:26:24 +0000149 uint32_t inode;
150 uint16_t direntlen;
wdenkefe2a4d2004-12-16 21:44:03 +0000151 uint8_t namelen;
152 uint8_t filetype;
stroese2b918712004-12-16 17:26:24 +0000153};
154
wdenkefe2a4d2004-12-16 21:44:03 +0000155struct ext2fs_node {
stroese2b918712004-12-16 17:26:24 +0000156 struct ext2_data *data;
157 struct ext2_inode inode;
wdenkefe2a4d2004-12-16 21:44:03 +0000158 int ino;
159 int inode_read;
stroese2b918712004-12-16 17:26:24 +0000160};
161
162/* Information about a "mounted" ext2 filesystem. */
wdenkefe2a4d2004-12-16 21:44:03 +0000163struct ext2_data {
stroese2b918712004-12-16 17:26:24 +0000164 struct ext2_sblock sblock;
165 struct ext2_inode *inode;
166 struct ext2fs_node diropen;
167};
168
169
170typedef struct ext2fs_node *ext2fs_node_t;
171
wdenkefe2a4d2004-12-16 21:44:03 +0000172struct ext2_data *ext2fs_root = NULL;
173ext2fs_node_t ext2fs_file = NULL;
174int symlinknest = 0;
175uint32_t *indir1_block = NULL;
176int indir1_size = 0;
177int indir1_blkno = -1;
178uint32_t *indir2_block = NULL;
179int indir2_size = 0;
180int indir2_blkno = -1;
Michael Brandt270737a2009-11-22 14:13:27 +0100181static unsigned int inode_size;
stroese2b918712004-12-16 17:26:24 +0000182
183
184static int ext2fs_blockgroup
wdenkefe2a4d2004-12-16 21:44:03 +0000185 (struct ext2_data *data, int group, struct ext2_block_group *blkgrp) {
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200186 unsigned int blkno;
187 unsigned int blkoff;
188 unsigned int desc_per_blk;
189
190 desc_per_blk = EXT2_BLOCK_SIZE(data) / sizeof(struct ext2_block_group);
191
192 blkno = __le32_to_cpu(data->sblock.first_data_block) + 1 +
193 group / desc_per_blk;
194 blkoff = (group % desc_per_blk) * sizeof(struct ext2_block_group);
stroese2b918712004-12-16 17:26:24 +0000195#ifdef DEBUG
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200196 printf ("ext2fs read %d group descriptor (blkno %d blkoff %d)\n",
197 group, blkno, blkoff);
stroese2b918712004-12-16 17:26:24 +0000198#endif
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200199 return (ext2fs_devread (blkno << LOG2_EXT2_BLOCK_SIZE(data),
200 blkoff, sizeof(struct ext2_block_group), (char *)blkgrp));
201
stroese2b918712004-12-16 17:26:24 +0000202}
203
204
205static int ext2fs_read_inode
wdenkefe2a4d2004-12-16 21:44:03 +0000206 (struct ext2_data *data, int ino, struct ext2_inode *inode) {
207 struct ext2_block_group blkgrp;
208 struct ext2_sblock *sblock = &data->sblock;
209 int inodes_per_block;
210 int status;
stroese2b918712004-12-16 17:26:24 +0000211
wdenkefe2a4d2004-12-16 21:44:03 +0000212 unsigned int blkno;
213 unsigned int blkoff;
stroese2b918712004-12-16 17:26:24 +0000214
stroese2b918712004-12-16 17:26:24 +0000215#ifdef DEBUG
Michael Brandt270737a2009-11-22 14:13:27 +0100216 printf ("ext2fs read inode %d, inode_size %d\n", ino, inode_size);
stroese2b918712004-12-16 17:26:24 +0000217#endif
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200218 /* It is easier to calculate if the first inode is 0. */
219 ino--;
220 status = ext2fs_blockgroup (data, ino / __le32_to_cpu
221 (sblock->inodes_per_group), &blkgrp);
wdenkefe2a4d2004-12-16 21:44:03 +0000222 if (status == 0) {
223 return (0);
stroese2b918712004-12-16 17:26:24 +0000224 }
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200225
Michael Brandt270737a2009-11-22 14:13:27 +0100226 inodes_per_block = EXT2_BLOCK_SIZE(data) / inode_size;
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200227
228 blkno = __le32_to_cpu (blkgrp.inode_table_id) +
229 (ino % __le32_to_cpu (sblock->inodes_per_group))
230 / inodes_per_block;
Michael Brandt270737a2009-11-22 14:13:27 +0100231 blkoff = (ino % inodes_per_block) * inode_size;
stroese2b918712004-12-16 17:26:24 +0000232#ifdef DEBUG
wdenkefe2a4d2004-12-16 21:44:03 +0000233 printf ("ext2fs read inode blkno %d blkoff %d\n", blkno, blkoff);
stroese2b918712004-12-16 17:26:24 +0000234#endif
235 /* Read the inode. */
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200236 status = ext2fs_devread (blkno << LOG2_EXT2_BLOCK_SIZE (data), blkoff,
wdenkefe2a4d2004-12-16 21:44:03 +0000237 sizeof (struct ext2_inode), (char *) inode);
238 if (status == 0) {
239 return (0);
stroese2b918712004-12-16 17:26:24 +0000240 }
Weirich, Bernhard56fdaad2009-06-10 14:00:37 +0200241
wdenkefe2a4d2004-12-16 21:44:03 +0000242 return (1);
stroese2b918712004-12-16 17:26:24 +0000243}
244
245
wdenkefe2a4d2004-12-16 21:44:03 +0000246void ext2fs_free_node (ext2fs_node_t node, ext2fs_node_t currroot) {
247 if ((node != &ext2fs_root->diropen) && (node != currroot)) {
stroese2b918712004-12-16 17:26:24 +0000248 free (node);
249 }
250}
251
252
wdenkefe2a4d2004-12-16 21:44:03 +0000253static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
254 struct ext2_data *data = node->data;
255 struct ext2_inode *inode = &node->inode;
256 int blknr;
257 int blksz = EXT2_BLOCK_SIZE (data);
258 int log2_blksz = LOG2_EXT2_BLOCK_SIZE (data);
259 int status;
stroese2b918712004-12-16 17:26:24 +0000260
261 /* Direct blocks. */
wdenkefe2a4d2004-12-16 21:44:03 +0000262 if (fileblock < INDIRECT_BLOCKS) {
stroese2b918712004-12-16 17:26:24 +0000263 blknr = __le32_to_cpu (inode->b.blocks.dir_blocks[fileblock]);
wdenkefe2a4d2004-12-16 21:44:03 +0000264 }
stroese2b918712004-12-16 17:26:24 +0000265 /* Indirect. */
wdenkefe2a4d2004-12-16 21:44:03 +0000266 else if (fileblock < (INDIRECT_BLOCKS + (blksz / 4))) {
267 if (indir1_block == NULL) {
268 indir1_block = (uint32_t *) malloc (blksz);
269 if (indir1_block == NULL) {
270 printf ("** ext2fs read block (indir 1) malloc failed. **\n");
271 return (-1);
stroese2b918712004-12-16 17:26:24 +0000272 }
wdenkefe2a4d2004-12-16 21:44:03 +0000273 indir1_size = blksz;
stroese2b918712004-12-16 17:26:24 +0000274 indir1_blkno = -1;
275 }
wdenkefe2a4d2004-12-16 21:44:03 +0000276 if (blksz != indir1_size) {
277 free (indir1_block);
stroese2b918712004-12-16 17:26:24 +0000278 indir1_block = NULL;
wdenkefe2a4d2004-12-16 21:44:03 +0000279 indir1_size = 0;
stroese2b918712004-12-16 17:26:24 +0000280 indir1_blkno = -1;
wdenkefe2a4d2004-12-16 21:44:03 +0000281 indir1_block = (uint32_t *) malloc (blksz);
282 if (indir1_block == NULL) {
283 printf ("** ext2fs read block (indir 1) malloc failed. **\n");
284 return (-1);
stroese2b918712004-12-16 17:26:24 +0000285 }
wdenkefe2a4d2004-12-16 21:44:03 +0000286 indir1_size = blksz;
stroese2b918712004-12-16 17:26:24 +0000287 }
wdenkefe2a4d2004-12-16 21:44:03 +0000288 if ((__le32_to_cpu (inode->b.blocks.indir_block) <<
289 log2_blksz) != indir1_blkno) {
290 status = ext2fs_devread (__le32_to_cpu(inode->b.blocks.indir_block) << log2_blksz,
291 0, blksz,
292 (char *) indir1_block);
293 if (status == 0) {
294 printf ("** ext2fs read block (indir 1) failed. **\n");
295 return (0);
stroese2b918712004-12-16 17:26:24 +0000296 }
wdenkefe2a4d2004-12-16 21:44:03 +0000297 indir1_blkno =
298 __le32_to_cpu (inode->b.blocks.
299 indir_block) << log2_blksz;
stroese2b918712004-12-16 17:26:24 +0000300 }
wdenkefe2a4d2004-12-16 21:44:03 +0000301 blknr = __le32_to_cpu (indir1_block
302 [fileblock - INDIRECT_BLOCKS]);
stroese2b918712004-12-16 17:26:24 +0000303 }
304 /* Double indirect. */
wdenkefe2a4d2004-12-16 21:44:03 +0000305 else if (fileblock <
306 (INDIRECT_BLOCKS + (blksz / 4 * (blksz / 4 + 1)))) {
stroese2b918712004-12-16 17:26:24 +0000307 unsigned int perblock = blksz / 4;
308 unsigned int rblock = fileblock - (INDIRECT_BLOCKS
309 + blksz / 4);
310
wdenkefe2a4d2004-12-16 21:44:03 +0000311 if (indir1_block == NULL) {
312 indir1_block = (uint32_t *) malloc (blksz);
313 if (indir1_block == NULL) {
314 printf ("** ext2fs read block (indir 2 1) malloc failed. **\n");
315 return (-1);
stroese2b918712004-12-16 17:26:24 +0000316 }
wdenkefe2a4d2004-12-16 21:44:03 +0000317 indir1_size = blksz;
stroese2b918712004-12-16 17:26:24 +0000318 indir1_blkno = -1;
319 }
wdenkefe2a4d2004-12-16 21:44:03 +0000320 if (blksz != indir1_size) {
321 free (indir1_block);
stroese2b918712004-12-16 17:26:24 +0000322 indir1_block = NULL;
wdenkefe2a4d2004-12-16 21:44:03 +0000323 indir1_size = 0;
stroese2b918712004-12-16 17:26:24 +0000324 indir1_blkno = -1;
wdenkefe2a4d2004-12-16 21:44:03 +0000325 indir1_block = (uint32_t *) malloc (blksz);
326 if (indir1_block == NULL) {
327 printf ("** ext2fs read block (indir 2 1) malloc failed. **\n");
328 return (-1);
stroese2b918712004-12-16 17:26:24 +0000329 }
wdenkefe2a4d2004-12-16 21:44:03 +0000330 indir1_size = blksz;
stroese2b918712004-12-16 17:26:24 +0000331 }
wdenkefe2a4d2004-12-16 21:44:03 +0000332 if ((__le32_to_cpu (inode->b.blocks.double_indir_block) <<
333 log2_blksz) != indir1_blkno) {
334 status = ext2fs_devread (__le32_to_cpu(inode->b.blocks.double_indir_block) << log2_blksz,
335 0, blksz,
336 (char *) indir1_block);
337 if (status == 0) {
338 printf ("** ext2fs read block (indir 2 1) failed. **\n");
339 return (-1);
stroese2b918712004-12-16 17:26:24 +0000340 }
wdenkefe2a4d2004-12-16 21:44:03 +0000341 indir1_blkno =
342 __le32_to_cpu (inode->b.blocks.double_indir_block) << log2_blksz;
stroese2b918712004-12-16 17:26:24 +0000343 }
344
wdenkefe2a4d2004-12-16 21:44:03 +0000345 if (indir2_block == NULL) {
346 indir2_block = (uint32_t *) malloc (blksz);
347 if (indir2_block == NULL) {
348 printf ("** ext2fs read block (indir 2 2) malloc failed. **\n");
349 return (-1);
stroese2b918712004-12-16 17:26:24 +0000350 }
wdenkefe2a4d2004-12-16 21:44:03 +0000351 indir2_size = blksz;
stroese2b918712004-12-16 17:26:24 +0000352 indir2_blkno = -1;
353 }
wdenkefe2a4d2004-12-16 21:44:03 +0000354 if (blksz != indir2_size) {
355 free (indir2_block);
stroese2b918712004-12-16 17:26:24 +0000356 indir2_block = NULL;
wdenkefe2a4d2004-12-16 21:44:03 +0000357 indir2_size = 0;
stroese2b918712004-12-16 17:26:24 +0000358 indir2_blkno = -1;
wdenkefe2a4d2004-12-16 21:44:03 +0000359 indir2_block = (uint32_t *) malloc (blksz);
360 if (indir2_block == NULL) {
361 printf ("** ext2fs read block (indir 2 2) malloc failed. **\n");
362 return (-1);
stroese2b918712004-12-16 17:26:24 +0000363 }
wdenkefe2a4d2004-12-16 21:44:03 +0000364 indir2_size = blksz;
stroese2b918712004-12-16 17:26:24 +0000365 }
wdenkefe2a4d2004-12-16 21:44:03 +0000366 if ((__le32_to_cpu (indir1_block[rblock / perblock]) <<
Aaron Pacea2740dd2010-07-26 14:24:44 -0600367 log2_blksz) != indir2_blkno) {
wdenkefe2a4d2004-12-16 21:44:03 +0000368 status = ext2fs_devread (__le32_to_cpu(indir1_block[rblock / perblock]) << log2_blksz,
369 0, blksz,
370 (char *) indir2_block);
371 if (status == 0) {
372 printf ("** ext2fs read block (indir 2 2) failed. **\n");
373 return (-1);
stroese2b918712004-12-16 17:26:24 +0000374 }
wdenkefe2a4d2004-12-16 21:44:03 +0000375 indir2_blkno =
376 __le32_to_cpu (indir1_block[rblock / perblock]) << log2_blksz;
stroese2b918712004-12-16 17:26:24 +0000377 }
wdenkefe2a4d2004-12-16 21:44:03 +0000378 blknr = __le32_to_cpu (indir2_block[rblock % perblock]);
stroese2b918712004-12-16 17:26:24 +0000379 }
380 /* Tripple indirect. */
wdenkefe2a4d2004-12-16 21:44:03 +0000381 else {
382 printf ("** ext2fs doesn't support tripple indirect blocks. **\n");
383 return (-1);
384 }
stroese2b918712004-12-16 17:26:24 +0000385#ifdef DEBUG
wdenkefe2a4d2004-12-16 21:44:03 +0000386 printf ("ext2fs_read_block %08x\n", blknr);
stroese2b918712004-12-16 17:26:24 +0000387#endif
wdenkefe2a4d2004-12-16 21:44:03 +0000388 return (blknr);
stroese2b918712004-12-16 17:26:24 +0000389}
390
391
392int ext2fs_read_file
wdenkefe2a4d2004-12-16 21:44:03 +0000393 (ext2fs_node_t node, int pos, unsigned int len, char *buf) {
394 int i;
395 int blockcnt;
396 int log2blocksize = LOG2_EXT2_BLOCK_SIZE (node->data);
397 int blocksize = 1 << (log2blocksize + DISK_SECTOR_BITS);
Stefan Roesea7b9fb92006-01-18 20:05:34 +0100398 unsigned int filesize = __le32_to_cpu(node->inode.size);
stroese2b918712004-12-16 17:26:24 +0000399
400 /* Adjust len so it we can't read past the end of the file. */
wdenkefe2a4d2004-12-16 21:44:03 +0000401 if (len > filesize) {
stroese2b918712004-12-16 17:26:24 +0000402 len = filesize;
403 }
wdenkefe2a4d2004-12-16 21:44:03 +0000404 blockcnt = ((len + pos) + blocksize - 1) / blocksize;
stroese2b918712004-12-16 17:26:24 +0000405
wdenkefe2a4d2004-12-16 21:44:03 +0000406 for (i = pos / blocksize; i < blockcnt; i++) {
stroese2b918712004-12-16 17:26:24 +0000407 int blknr;
408 int blockoff = pos % blocksize;
409 int blockend = blocksize;
410
411 int skipfirst = 0;
412
wdenkefe2a4d2004-12-16 21:44:03 +0000413 blknr = ext2fs_read_block (node, i);
414 if (blknr < 0) {
415 return (-1);
stroese2b918712004-12-16 17:26:24 +0000416 }
417 blknr = blknr << log2blocksize;
418
419 /* Last block. */
wdenkefe2a4d2004-12-16 21:44:03 +0000420 if (i == blockcnt - 1) {
stroese2b918712004-12-16 17:26:24 +0000421 blockend = (len + pos) % blocksize;
422
423 /* The last portion is exactly blocksize. */
wdenkefe2a4d2004-12-16 21:44:03 +0000424 if (!blockend) {
stroese2b918712004-12-16 17:26:24 +0000425 blockend = blocksize;
426 }
427 }
428
429 /* First block. */
wdenkefe2a4d2004-12-16 21:44:03 +0000430 if (i == pos / blocksize) {
stroese2b918712004-12-16 17:26:24 +0000431 skipfirst = blockoff;
432 blockend -= skipfirst;
433 }
434
435 /* If the block number is 0 this block is not stored on disk but
436 is zero filled instead. */
wdenkefe2a4d2004-12-16 21:44:03 +0000437 if (blknr) {
stroese2b918712004-12-16 17:26:24 +0000438 int status;
439
440 status = ext2fs_devread (blknr, skipfirst, blockend, buf);
wdenkefe2a4d2004-12-16 21:44:03 +0000441 if (status == 0) {
442 return (-1);
stroese2b918712004-12-16 17:26:24 +0000443 }
wdenkefe2a4d2004-12-16 21:44:03 +0000444 } else {
Wolfgang Denk0ddb8962008-01-09 10:16:33 +0100445 memset (buf, 0, blocksize - skipfirst);
stroese2b918712004-12-16 17:26:24 +0000446 }
447 buf += blocksize - skipfirst;
wdenkefe2a4d2004-12-16 21:44:03 +0000448 }
449 return (len);
stroese2b918712004-12-16 17:26:24 +0000450}
451
452
wdenkefe2a4d2004-12-16 21:44:03 +0000453static int ext2fs_iterate_dir (ext2fs_node_t dir, char *name, ext2fs_node_t * fnode, int *ftype)
stroese2b918712004-12-16 17:26:24 +0000454{
455 unsigned int fpos = 0;
wdenkefe2a4d2004-12-16 21:44:03 +0000456 int status;
stroese2b918712004-12-16 17:26:24 +0000457 struct ext2fs_node *diro = (struct ext2fs_node *) dir;
wdenkefe2a4d2004-12-16 21:44:03 +0000458
stroese2b918712004-12-16 17:26:24 +0000459#ifdef DEBUG
wdenkefe2a4d2004-12-16 21:44:03 +0000460 if (name != NULL)
461 printf ("Iterate dir %s\n", name);
stroese2b918712004-12-16 17:26:24 +0000462#endif /* of DEBUG */
wdenkefe2a4d2004-12-16 21:44:03 +0000463 if (!diro->inode_read) {
464 status = ext2fs_read_inode (diro->data, diro->ino,
465 &diro->inode);
466 if (status == 0) {
467 return (0);
stroese2b918712004-12-16 17:26:24 +0000468 }
469 }
470 /* Search the file. */
wdenkefe2a4d2004-12-16 21:44:03 +0000471 while (fpos < __le32_to_cpu (diro->inode.size)) {
stroese2b918712004-12-16 17:26:24 +0000472 struct ext2_dirent dirent;
473
wdenkefe2a4d2004-12-16 21:44:03 +0000474 status = ext2fs_read_file (diro, fpos,
475 sizeof (struct ext2_dirent),
476 (char *) &dirent);
477 if (status < 1) {
478 return (0);
stroese2b918712004-12-16 17:26:24 +0000479 }
wdenkefe2a4d2004-12-16 21:44:03 +0000480 if (dirent.namelen != 0) {
481 char filename[dirent.namelen + 1];
482 ext2fs_node_t fdiro;
483 int type = FILETYPE_UNKNOWN;
stroese2b918712004-12-16 17:26:24 +0000484
wdenkefe2a4d2004-12-16 21:44:03 +0000485 status = ext2fs_read_file (diro,
486 fpos + sizeof (struct ext2_dirent),
487 dirent.namelen, filename);
488 if (status < 1) {
489 return (0);
stroese2b918712004-12-16 17:26:24 +0000490 }
491 fdiro = malloc (sizeof (struct ext2fs_node));
wdenkefe2a4d2004-12-16 21:44:03 +0000492 if (!fdiro) {
493 return (0);
stroese2b918712004-12-16 17:26:24 +0000494 }
495
496 fdiro->data = diro->data;
wdenkefe2a4d2004-12-16 21:44:03 +0000497 fdiro->ino = __le32_to_cpu (dirent.inode);
stroese2b918712004-12-16 17:26:24 +0000498
499 filename[dirent.namelen] = '\0';
500
wdenkefe2a4d2004-12-16 21:44:03 +0000501 if (dirent.filetype != FILETYPE_UNKNOWN) {
stroese2b918712004-12-16 17:26:24 +0000502 fdiro->inode_read = 0;
503
wdenkefe2a4d2004-12-16 21:44:03 +0000504 if (dirent.filetype == FILETYPE_DIRECTORY) {
stroese2b918712004-12-16 17:26:24 +0000505 type = FILETYPE_DIRECTORY;
wdenkefe2a4d2004-12-16 21:44:03 +0000506 } else if (dirent.filetype ==
507 FILETYPE_SYMLINK) {
stroese2b918712004-12-16 17:26:24 +0000508 type = FILETYPE_SYMLINK;
wdenkefe2a4d2004-12-16 21:44:03 +0000509 } else if (dirent.filetype == FILETYPE_REG) {
510 type = FILETYPE_REG;
stroese2b918712004-12-16 17:26:24 +0000511 }
wdenkefe2a4d2004-12-16 21:44:03 +0000512 } else {
stroese2b918712004-12-16 17:26:24 +0000513 /* The filetype can not be read from the dirent, get it from inode */
514
wdenkefe2a4d2004-12-16 21:44:03 +0000515 status = ext2fs_read_inode (diro->data,
516 __le32_to_cpu(dirent.inode),
517 &fdiro->inode);
518 if (status == 0) {
519 free (fdiro);
520 return (0);
stroese2b918712004-12-16 17:26:24 +0000521 }
522 fdiro->inode_read = 1;
523
wdenkefe2a4d2004-12-16 21:44:03 +0000524 if ((__le16_to_cpu (fdiro->inode.mode) &
525 FILETYPE_INO_MASK) ==
526 FILETYPE_INO_DIRECTORY) {
stroese2b918712004-12-16 17:26:24 +0000527 type = FILETYPE_DIRECTORY;
wdenkefe2a4d2004-12-16 21:44:03 +0000528 } else if ((__le16_to_cpu (fdiro->inode.mode)
529 & FILETYPE_INO_MASK) ==
530 FILETYPE_INO_SYMLINK) {
stroese2b918712004-12-16 17:26:24 +0000531 type = FILETYPE_SYMLINK;
wdenkefe2a4d2004-12-16 21:44:03 +0000532 } else if ((__le16_to_cpu (fdiro->inode.mode)
533 & FILETYPE_INO_MASK) ==
534 FILETYPE_INO_REG) {
stroese2b918712004-12-16 17:26:24 +0000535 type = FILETYPE_REG;
536 }
537 }
538#ifdef DEBUG
wdenkefe2a4d2004-12-16 21:44:03 +0000539 printf ("iterate >%s<\n", filename);
stroese2b918712004-12-16 17:26:24 +0000540#endif /* of DEBUG */
wdenkefe2a4d2004-12-16 21:44:03 +0000541 if ((name != NULL) && (fnode != NULL)
542 && (ftype != NULL)) {
543 if (strcmp (filename, name) == 0) {
stroese2b918712004-12-16 17:26:24 +0000544 *ftype = type;
545 *fnode = fdiro;
wdenkefe2a4d2004-12-16 21:44:03 +0000546 return (1);
stroese2b918712004-12-16 17:26:24 +0000547 }
wdenkefe2a4d2004-12-16 21:44:03 +0000548 } else {
549 if (fdiro->inode_read == 0) {
550 status = ext2fs_read_inode (diro->data,
551 __le32_to_cpu (dirent.inode),
552 &fdiro->inode);
553 if (status == 0) {
554 free (fdiro);
555 return (0);
stroese2b918712004-12-16 17:26:24 +0000556 }
557 fdiro->inode_read = 1;
558 }
wdenkefe2a4d2004-12-16 21:44:03 +0000559 switch (type) {
stroese2b918712004-12-16 17:26:24 +0000560 case FILETYPE_DIRECTORY:
wdenkefe2a4d2004-12-16 21:44:03 +0000561 printf ("<DIR> ");
stroese2b918712004-12-16 17:26:24 +0000562 break;
563 case FILETYPE_SYMLINK:
wdenkefe2a4d2004-12-16 21:44:03 +0000564 printf ("<SYM> ");
stroese2b918712004-12-16 17:26:24 +0000565 break;
566 case FILETYPE_REG:
wdenkefe2a4d2004-12-16 21:44:03 +0000567 printf (" ");
stroese2b918712004-12-16 17:26:24 +0000568 break;
569 default:
wdenkec0aee72004-12-19 09:58:11 +0000570 printf ("< ? > ");
stroese2b918712004-12-16 17:26:24 +0000571 break;
572 }
wdenkefe2a4d2004-12-16 21:44:03 +0000573 printf ("%10d %s\n",
574 __le32_to_cpu (fdiro->inode.size),
575 filename);
stroese2b918712004-12-16 17:26:24 +0000576 }
wdenkefe2a4d2004-12-16 21:44:03 +0000577 free (fdiro);
stroese2b918712004-12-16 17:26:24 +0000578 }
579 fpos += __le16_to_cpu (dirent.direntlen);
580 }
wdenkefe2a4d2004-12-16 21:44:03 +0000581 return (0);
stroese2b918712004-12-16 17:26:24 +0000582}
583
584
wdenkefe2a4d2004-12-16 21:44:03 +0000585static char *ext2fs_read_symlink (ext2fs_node_t node) {
586 char *symlink;
stroese2b918712004-12-16 17:26:24 +0000587 struct ext2fs_node *diro = node;
wdenkefe2a4d2004-12-16 21:44:03 +0000588 int status;
stroese2b918712004-12-16 17:26:24 +0000589
wdenkefe2a4d2004-12-16 21:44:03 +0000590 if (!diro->inode_read) {
591 status = ext2fs_read_inode (diro->data, diro->ino,
592 &diro->inode);
593 if (status == 0) {
594 return (0);
stroese2b918712004-12-16 17:26:24 +0000595 }
596 }
597 symlink = malloc (__le32_to_cpu (diro->inode.size) + 1);
wdenkefe2a4d2004-12-16 21:44:03 +0000598 if (!symlink) {
599 return (0);
stroese2b918712004-12-16 17:26:24 +0000600 }
601 /* If the filesize of the symlink is bigger than
602 60 the symlink is stored in a separate block,
603 otherwise it is stored in the inode. */
wdenkefe2a4d2004-12-16 21:44:03 +0000604 if (__le32_to_cpu (diro->inode.size) <= 60) {
605 strncpy (symlink, diro->inode.b.symlink,
606 __le32_to_cpu (diro->inode.size));
607 } else {
608 status = ext2fs_read_file (diro, 0,
609 __le32_to_cpu (diro->inode.size),
610 symlink);
611 if (status == 0) {
stroese2b918712004-12-16 17:26:24 +0000612 free (symlink);
wdenkefe2a4d2004-12-16 21:44:03 +0000613 return (0);
stroese2b918712004-12-16 17:26:24 +0000614 }
615 }
616 symlink[__le32_to_cpu (diro->inode.size)] = '\0';
wdenkefe2a4d2004-12-16 21:44:03 +0000617 return (symlink);
stroese2b918712004-12-16 17:26:24 +0000618}
619
620
621int ext2fs_find_file1
wdenkefe2a4d2004-12-16 21:44:03 +0000622 (const char *currpath,
623 ext2fs_node_t currroot, ext2fs_node_t * currfound, int *foundtype) {
624 char fpath[strlen (currpath) + 1];
625 char *name = fpath;
626 char *next;
627 int status;
628 int type = FILETYPE_DIRECTORY;
629 ext2fs_node_t currnode = currroot;
630 ext2fs_node_t oldnode = currroot;
stroese2b918712004-12-16 17:26:24 +0000631
632 strncpy (fpath, currpath, strlen (currpath) + 1);
633
634 /* Remove all leading slashes. */
wdenkefe2a4d2004-12-16 21:44:03 +0000635 while (*name == '/') {
stroese2b918712004-12-16 17:26:24 +0000636 name++;
wdenkefe2a4d2004-12-16 21:44:03 +0000637 }
638 if (!*name) {
stroese2b918712004-12-16 17:26:24 +0000639 *currfound = currnode;
wdenkefe2a4d2004-12-16 21:44:03 +0000640 return (1);
stroese2b918712004-12-16 17:26:24 +0000641 }
642
wdenkefe2a4d2004-12-16 21:44:03 +0000643 for (;;) {
stroese2b918712004-12-16 17:26:24 +0000644 int found;
645
646 /* Extract the actual part from the pathname. */
647 next = strchr (name, '/');
wdenkefe2a4d2004-12-16 21:44:03 +0000648 if (next) {
stroese2b918712004-12-16 17:26:24 +0000649 /* Remove all leading slashes. */
wdenkefe2a4d2004-12-16 21:44:03 +0000650 while (*next == '/') {
stroese2b918712004-12-16 17:26:24 +0000651 *(next++) = '\0';
652 }
653 }
654
655 /* At this point it is expected that the current node is a directory, check if this is true. */
wdenkefe2a4d2004-12-16 21:44:03 +0000656 if (type != FILETYPE_DIRECTORY) {
stroese2b918712004-12-16 17:26:24 +0000657 ext2fs_free_node (currnode, currroot);
wdenkefe2a4d2004-12-16 21:44:03 +0000658 return (0);
stroese2b918712004-12-16 17:26:24 +0000659 }
660
661 oldnode = currnode;
662
663 /* Iterate over the directory. */
664 found = ext2fs_iterate_dir (currnode, name, &currnode, &type);
wdenkefe2a4d2004-12-16 21:44:03 +0000665 if (found == 0) {
666 return (0);
stroese2b918712004-12-16 17:26:24 +0000667 }
wdenkefe2a4d2004-12-16 21:44:03 +0000668 if (found == -1) {
stroese2b918712004-12-16 17:26:24 +0000669 break;
670 }
671
672 /* Read in the symlink and follow it. */
wdenkefe2a4d2004-12-16 21:44:03 +0000673 if (type == FILETYPE_SYMLINK) {
stroese2b918712004-12-16 17:26:24 +0000674 char *symlink;
675
676 /* Test if the symlink does not loop. */
wdenkefe2a4d2004-12-16 21:44:03 +0000677 if (++symlinknest == 8) {
stroese2b918712004-12-16 17:26:24 +0000678 ext2fs_free_node (currnode, currroot);
wdenkefe2a4d2004-12-16 21:44:03 +0000679 ext2fs_free_node (oldnode, currroot);
680 return (0);
stroese2b918712004-12-16 17:26:24 +0000681 }
682
683 symlink = ext2fs_read_symlink (currnode);
684 ext2fs_free_node (currnode, currroot);
685
wdenkefe2a4d2004-12-16 21:44:03 +0000686 if (!symlink) {
stroese2b918712004-12-16 17:26:24 +0000687 ext2fs_free_node (oldnode, currroot);
wdenkefe2a4d2004-12-16 21:44:03 +0000688 return (0);
stroese2b918712004-12-16 17:26:24 +0000689 }
690#ifdef DEBUG
wdenkefe2a4d2004-12-16 21:44:03 +0000691 printf ("Got symlink >%s<\n", symlink);
stroese2b918712004-12-16 17:26:24 +0000692#endif /* of DEBUG */
693 /* The symlink is an absolute path, go back to the root inode. */
wdenkefe2a4d2004-12-16 21:44:03 +0000694 if (symlink[0] == '/') {
stroese2b918712004-12-16 17:26:24 +0000695 ext2fs_free_node (oldnode, currroot);
696 oldnode = &ext2fs_root->diropen;
697 }
698
699 /* Lookup the node the symlink points to. */
wdenkefe2a4d2004-12-16 21:44:03 +0000700 status = ext2fs_find_file1 (symlink, oldnode,
701 &currnode, &type);
stroese2b918712004-12-16 17:26:24 +0000702
703 free (symlink);
704
wdenkefe2a4d2004-12-16 21:44:03 +0000705 if (status == 0) {
stroese2b918712004-12-16 17:26:24 +0000706 ext2fs_free_node (oldnode, currroot);
wdenkefe2a4d2004-12-16 21:44:03 +0000707 return (0);
stroese2b918712004-12-16 17:26:24 +0000708 }
709 }
710
711 ext2fs_free_node (oldnode, currroot);
712
713 /* Found the node! */
wdenkefe2a4d2004-12-16 21:44:03 +0000714 if (!next || *next == '\0') {
stroese2b918712004-12-16 17:26:24 +0000715 *currfound = currnode;
716 *foundtype = type;
wdenkefe2a4d2004-12-16 21:44:03 +0000717 return (1);
stroese2b918712004-12-16 17:26:24 +0000718 }
719 name = next;
720 }
wdenkefe2a4d2004-12-16 21:44:03 +0000721 return (-1);
stroese2b918712004-12-16 17:26:24 +0000722}
723
724
725int ext2fs_find_file
wdenkefe2a4d2004-12-16 21:44:03 +0000726 (const char *path,
727 ext2fs_node_t rootnode, ext2fs_node_t * foundnode, int expecttype) {
stroese2b918712004-12-16 17:26:24 +0000728 int status;
729 int foundtype = FILETYPE_DIRECTORY;
730
731
732 symlinknest = 0;
wdenk20a80412005-02-04 15:02:06 +0000733 if (!path) {
wdenkefe2a4d2004-12-16 21:44:03 +0000734 return (0);
stroese2b918712004-12-16 17:26:24 +0000735 }
736
wdenkefe2a4d2004-12-16 21:44:03 +0000737 status = ext2fs_find_file1 (path, rootnode, foundnode, &foundtype);
738 if (status == 0) {
739 return (0);
stroese2b918712004-12-16 17:26:24 +0000740 }
741 /* Check if the node that was found was of the expected type. */
wdenkefe2a4d2004-12-16 21:44:03 +0000742 if ((expecttype == FILETYPE_REG) && (foundtype != expecttype)) {
743 return (0);
744 } else if ((expecttype == FILETYPE_DIRECTORY)
745 && (foundtype != expecttype)) {
746 return (0);
stroese2b918712004-12-16 17:26:24 +0000747 }
wdenkefe2a4d2004-12-16 21:44:03 +0000748 return (1);
stroese2b918712004-12-16 17:26:24 +0000749}
750
751
wdenkefe2a4d2004-12-16 21:44:03 +0000752int ext2fs_ls (char *dirname) {
stroese2b918712004-12-16 17:26:24 +0000753 ext2fs_node_t dirnode;
wdenkefe2a4d2004-12-16 21:44:03 +0000754 int status;
stroese2b918712004-12-16 17:26:24 +0000755
wdenkefe2a4d2004-12-16 21:44:03 +0000756 if (ext2fs_root == NULL) {
757 return (0);
stroese2b918712004-12-16 17:26:24 +0000758 }
759
wdenkefe2a4d2004-12-16 21:44:03 +0000760 status = ext2fs_find_file (dirname, &ext2fs_root->diropen, &dirnode,
761 FILETYPE_DIRECTORY);
762 if (status != 1) {
763 printf ("** Can not find directory. **\n");
764 return (1);
765 }
766 ext2fs_iterate_dir (dirnode, NULL, NULL, NULL);
767 ext2fs_free_node (dirnode, &ext2fs_root->diropen);
768 return (0);
stroese2b918712004-12-16 17:26:24 +0000769}
770
771
wdenkefe2a4d2004-12-16 21:44:03 +0000772int ext2fs_open (char *filename) {
773 ext2fs_node_t fdiro = NULL;
774 int status;
775 int len;
stroese2b918712004-12-16 17:26:24 +0000776
wdenkefe2a4d2004-12-16 21:44:03 +0000777 if (ext2fs_root == NULL) {
wdenk20a80412005-02-04 15:02:06 +0000778 return (-1);
stroese2b918712004-12-16 17:26:24 +0000779 }
780 ext2fs_file = NULL;
wdenkefe2a4d2004-12-16 21:44:03 +0000781 status = ext2fs_find_file (filename, &ext2fs_root->diropen, &fdiro,
782 FILETYPE_REG);
783 if (status == 0) {
stroese2b918712004-12-16 17:26:24 +0000784 goto fail;
785 }
wdenkefe2a4d2004-12-16 21:44:03 +0000786 if (!fdiro->inode_read) {
787 status = ext2fs_read_inode (fdiro->data, fdiro->ino,
788 &fdiro->inode);
789 if (status == 0) {
stroese2b918712004-12-16 17:26:24 +0000790 goto fail;
791 }
792 }
793 len = __le32_to_cpu (fdiro->inode.size);
794 ext2fs_file = fdiro;
wdenkefe2a4d2004-12-16 21:44:03 +0000795 return (len);
stroese2b918712004-12-16 17:26:24 +0000796
wdenk20a80412005-02-04 15:02:06 +0000797fail:
wdenkefe2a4d2004-12-16 21:44:03 +0000798 ext2fs_free_node (fdiro, &ext2fs_root->diropen);
wdenk20a80412005-02-04 15:02:06 +0000799 return (-1);
stroese2b918712004-12-16 17:26:24 +0000800}
801
802
wdenkefe2a4d2004-12-16 21:44:03 +0000803int ext2fs_close (void
804 ) {
805 if ((ext2fs_file != NULL) && (ext2fs_root != NULL)) {
806 ext2fs_free_node (ext2fs_file, &ext2fs_root->diropen);
stroese2b918712004-12-16 17:26:24 +0000807 ext2fs_file = NULL;
808 }
wdenkefe2a4d2004-12-16 21:44:03 +0000809 if (ext2fs_root != NULL) {
810 free (ext2fs_root);
811 ext2fs_root = NULL;
stroese2b918712004-12-16 17:26:24 +0000812 }
wdenkefe2a4d2004-12-16 21:44:03 +0000813 if (indir1_block != NULL) {
814 free (indir1_block);
815 indir1_block = NULL;
816 indir1_size = 0;
817 indir1_blkno = -1;
stroese2b918712004-12-16 17:26:24 +0000818 }
wdenkefe2a4d2004-12-16 21:44:03 +0000819 if (indir2_block != NULL) {
820 free (indir2_block);
821 indir2_block = NULL;
822 indir2_size = 0;
823 indir2_blkno = -1;
stroese2b918712004-12-16 17:26:24 +0000824 }
wdenkefe2a4d2004-12-16 21:44:03 +0000825 return (0);
stroese2b918712004-12-16 17:26:24 +0000826}
827
828
wdenkefe2a4d2004-12-16 21:44:03 +0000829int ext2fs_read (char *buf, unsigned len) {
stroese2b918712004-12-16 17:26:24 +0000830 int status;
831
wdenkefe2a4d2004-12-16 21:44:03 +0000832 if (ext2fs_root == NULL) {
833 return (0);
stroese2b918712004-12-16 17:26:24 +0000834 }
835
wdenkefe2a4d2004-12-16 21:44:03 +0000836 if (ext2fs_file == NULL) {
837 return (0);
stroese2b918712004-12-16 17:26:24 +0000838 }
839
wdenkefe2a4d2004-12-16 21:44:03 +0000840 status = ext2fs_read_file (ext2fs_file, 0, len, buf);
841 return (status);
stroese2b918712004-12-16 17:26:24 +0000842}
843
844
wdenkefe2a4d2004-12-16 21:44:03 +0000845int ext2fs_mount (unsigned part_length) {
stroese2b918712004-12-16 17:26:24 +0000846 struct ext2_data *data;
wdenkefe2a4d2004-12-16 21:44:03 +0000847 int status;
stroese2b918712004-12-16 17:26:24 +0000848
849 data = malloc (sizeof (struct ext2_data));
wdenkefe2a4d2004-12-16 21:44:03 +0000850 if (!data) {
851 return (0);
stroese2b918712004-12-16 17:26:24 +0000852 }
853 /* Read the superblock. */
wdenkefe2a4d2004-12-16 21:44:03 +0000854 status = ext2fs_devread (1 * 2, 0, sizeof (struct ext2_sblock),
855 (char *) &data->sblock);
856 if (status == 0) {
stroese2b918712004-12-16 17:26:24 +0000857 goto fail;
858 }
859 /* Make sure this is an ext2 filesystem. */
wdenkefe2a4d2004-12-16 21:44:03 +0000860 if (__le16_to_cpu (data->sblock.magic) != EXT2_MAGIC) {
stroese2b918712004-12-16 17:26:24 +0000861 goto fail;
862 }
Michael Brandt270737a2009-11-22 14:13:27 +0100863 if (__le32_to_cpu(data->sblock.revision_level == 0)) {
864 inode_size = 128;
865 } else {
866 inode_size = __le16_to_cpu(data->sblock.inode_size);
867 }
868#ifdef DEBUG
869 printf("EXT2 rev %d, inode_size %d\n",
870 __le32_to_cpu(data->sblock.revision_level), inode_size);
871#endif
wdenkefe2a4d2004-12-16 21:44:03 +0000872 data->diropen.data = data;
873 data->diropen.ino = 2;
874 data->diropen.inode_read = 1;
875 data->inode = &data->diropen.inode;
stroese2b918712004-12-16 17:26:24 +0000876
877 status = ext2fs_read_inode (data, 2, data->inode);
wdenkefe2a4d2004-12-16 21:44:03 +0000878 if (status == 0) {
stroese2b918712004-12-16 17:26:24 +0000879 goto fail;
880 }
881
882 ext2fs_root = data;
883
wdenkefe2a4d2004-12-16 21:44:03 +0000884 return (1);
stroese2b918712004-12-16 17:26:24 +0000885
wdenkefe2a4d2004-12-16 21:44:03 +0000886fail:
887 printf ("Failed to mount ext2 filesystem...\n");
888 free (data);
stroese2b918712004-12-16 17:26:24 +0000889 ext2fs_root = NULL;
wdenkefe2a4d2004-12-16 21:44:03 +0000890 return (0);
stroese2b918712004-12-16 17:26:24 +0000891}