#include "string.h"
#include "partition.h"
#include "fs.h"
+#include "errors.h"
#define FAST_VERSION
#define MAX_READ_RANGE 256
const char* file_name)
{
int result = 0;
+ int error = FILE_ERR_NOTFOUND;
static char buffer[1024];
int ofopened = 0;
if (opened) {
prom_printf("ext2_open() : fs busy\n");
- return FILE_ERR_NOTFOUND;
+ DEBUG_LEAVE(FILE_ERR_FSBUSY);
+ return FILE_ERR_FSBUSY;
}
if (file->device_kind != FILE_DEVICE_BLOCK) {
prom_printf("Can't open ext2 filesystem on non-block device\n");
- return FILE_ERR_NOTFOUND;
+ DEBUG_LEAVE(FILE_ERR_BADDEV);
+ return FILE_ERR_BADDEV;
}
fs = NULL;
cur_file = file;
- DEBUG_F("partition offset: %d\n", doff);
+ DEBUG_F("partition offset: %Lu\n", doff);
/* Open the OF device for the entire disk */
strncpy(buffer, dev_name, 1020);
file->of_device = prom_open(buffer);
- DEBUG_F("file->of_device = %08lx\n", file->of_device);
+ DEBUG_F("file->of_device = %p\n", file->of_device);
if (file->of_device == PROM_INVALID_HANDLE) {
- DEBUG_F("Can't open device %s\n", file->of_device);
-
- return FILE_ERR_NOTFOUND;
+ DEBUG_F("Can't open device %p\n", file->of_device);
+ DEBUG_LEAVE(FILE_IOERR);
+ return FILE_IOERR;
}
ofopened = 1;
if(result == EXT2_ET_BAD_MAGIC)
{
- DEBUG_F( "ext2fs_open returned bad magic loading file %s\n",
+ DEBUG_F( "ext2fs_open returned bad magic loading file %p\n",
file );
}
else
DEBUG_F( "ext2fs_open error #%d while loading file %s\n",
result, file_name);
}
-
+ error = FILE_ERR_BAD_FSYS;
goto bail;
}
if (!block_buffer) {
DEBUG_F("ext2fs: can't alloc block buffer (%d bytes)\n", fs->blocksize * 2);
-
+ error = FILE_IOERR;
goto bail;
}
if (result) {
DEBUG_F("ext2fs_namei error #%d while loading file %s\n", result, file_name);
+ if (result == EXT2_ET_SYMLINK_LOOP)
+ error = FILE_ERR_SYMLINK_LOOP;
+ else if (result == EXT2_ET_FILE_NOT_FOUND)
+ error = FILE_ERR_NOTFOUND;
+ else
+ error = FILE_IOERR;
goto bail;
}
if (result) {
DEBUG_F("ext2fs_follow_link error #%d while loading file %s\n", result, file_name);
-
+ error = FILE_ERR_NOTFOUND;
goto bail;
}
#endif
if (result) {
DEBUG_F("ext2fs_read_inode error #%d while loading file %s\n", result, file_name);
-
+ if (result == EXT2_ET_FILE_TOO_BIG)
+ error = FILE_ERR_LENGTH;
+ else if (result == EXT2_ET_LLSEEK_FAILED)
+ error = FILE_CANT_SEEK;
+ else if (result == EXT2_ET_FILE_NOT_FOUND)
+ error = FILE_ERR_NOTFOUND;
+ else
+ error = FILE_IOERR;
goto bail;
}
#endif /* FAST_VERSION */
block_buffer = NULL;
cur_file = NULL;
- DEBUG_LEAVE(FILE_ERR_NOTFOUND);
- return FILE_ERR_NOTFOUND;
+ DEBUG_LEAVE_F(error);
+ return error;
}
DEBUG_LEAVE(FILE_ERR_OK);
#ifdef FAST_VERSION
if (!opened)
- return FILE_ERR_NOTFOUND;
+ return FILE_IOERR;
- DEBUG_F("ext_read() from pos 0x%x, size: 0x%x\n", file->pos, size);
+ DEBUG_F("ext_read() from pos 0x%Lx, size: 0x%ux\n", file->pos, size);
read_cur_file = file;
retval = read_result;
}
if (retval)
- prom_printf ("ext2: i/o error %d in read\n", retval);
+ prom_printf ("ext2: i/o error %ld in read\n", (long) retval);
return read_total;
unsigned int read = 0;
if (!opened)
- return FILE_ERR_NOTFOUND;
+ return FILE_IOERR;
DEBUG_F("ext_read() from pos 0x%x, size: 0x%x\n", file->pos, size);
unsigned int newpos)
{
if (!opened)
- return FILE_ERR_NOTFOUND;
+ return FILE_CANT_SEEK;
file->pos = newpos;
return FILE_ERR_OK;
ext2_close( struct boot_file_t* file)
{
if (!opened)
- return FILE_ERR_NOTFOUND;
+ return FILE_IOERR;
if (block_buffer)
free(block_buffer);
fs = NULL;
prom_close(file->of_device);
+ DEBUG_F("ext2_close called\n");
opened = 0;
size = (count < 0) ? -count : count * bs;
prom_lseek(cur_file->of_device, tempb);
if (prom_read(cur_file->of_device, data, size) != size) {
- prom_printf ("\nRead error on block %d", block);
+ DEBUG_F("\nRead error on block %ld\n", block);
return EXT2_ET_SHORT_READ;
}
return 0;
{
return 0;
}
-