X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=second%2Ffs_ext2.c;fp=second%2Ffs_ext2.c;h=af3d115acb171f9f9cdbb6a83bb427ae3736287b;hb=8d5a42062f8b88eaea91434e53973ce9f55589d9;hp=e2a5070f7a4480416e1aae2238a89bdbf91e8f7b;hpb=67d317029778e6f068badf7b8e3eec6482ecb00e;p=yaboot.git diff --git a/second/fs_ext2.c b/second/fs_ext2.c index e2a5070..af3d115 100644 --- a/second/fs_ext2.c +++ b/second/fs_ext2.c @@ -33,6 +33,7 @@ #include "string.h" #include "partition.h" #include "fs.h" +#include "errors.h" #define FAST_VERSION #define MAX_READ_RANGE 256 @@ -124,6 +125,7 @@ ext2_open( struct boot_file_t* file, const char* file_name) { int result = 0; + int error = FILE_ERR_NOTFOUND; static char buffer[1024]; int ofopened = 0; @@ -132,11 +134,13 @@ ext2_open( struct boot_file_t* file, 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; @@ -152,7 +156,7 @@ ext2_open( struct boot_file_t* file, 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); @@ -162,13 +166,13 @@ ext2_open( struct boot_file_t* file, 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; @@ -178,7 +182,7 @@ ext2_open( struct boot_file_t* file, 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 @@ -186,7 +190,7 @@ ext2_open( struct boot_file_t* file, DEBUG_F( "ext2fs_open error #%d while loading file %s\n", result, file_name); } - + error = FILE_ERR_BAD_FSYS; goto bail; } @@ -195,7 +199,7 @@ ext2_open( struct boot_file_t* file, if (!block_buffer) { DEBUG_F("ext2fs: can't alloc block buffer (%d bytes)\n", fs->blocksize * 2); - + error = FILE_IOERR; goto bail; } @@ -205,6 +209,12 @@ ext2_open( struct boot_file_t* file, 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; } @@ -213,7 +223,7 @@ ext2_open( struct boot_file_t* file, if (result) { DEBUG_F("ext2fs_follow_link error #%d while loading file %s\n", result, file_name); - + error = FILE_ERR_NOTFOUND; goto bail; } #endif @@ -223,7 +233,14 @@ ext2_open( struct boot_file_t* file, 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 */ @@ -242,8 +259,8 @@ bail: 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); @@ -420,10 +437,10 @@ ext2_read( struct boot_file_t* file, #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; @@ -447,7 +464,7 @@ ext2_read( struct boot_file_t* 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; @@ -456,7 +473,7 @@ ext2_read( struct boot_file_t* file, 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); @@ -507,7 +524,7 @@ ext2_seek( struct boot_file_t* file, unsigned int newpos) { if (!opened) - return FILE_ERR_NOTFOUND; + return FILE_CANT_SEEK; file->pos = newpos; return FILE_ERR_OK; @@ -517,7 +534,7 @@ static int ext2_close( struct boot_file_t* file) { if (!opened) - return FILE_ERR_NOTFOUND; + return FILE_IOERR; if (block_buffer) free(block_buffer); @@ -528,6 +545,7 @@ ext2_close( struct boot_file_t* file) fs = NULL; prom_close(file->of_device); + DEBUG_F("ext2_close called\n"); opened = 0; @@ -586,7 +604,7 @@ static errcode_t linux_read_blk (io_channel channel, unsigned long block, int co 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; @@ -601,4 +619,3 @@ static errcode_t linux_flush (io_channel channel) { return 0; } -