]> git.ozlabs.org Git - yaboot.git/blobdiff - second/fs_ext2.c
Commit yaboot 1.3.4-pre3
[yaboot.git] / second / fs_ext2.c
index e2a5070f7a4480416e1aae2238a89bdbf91e8f7b..66e1ba8950532dcda2b7e6b283bc7c0c8923a352 100644 (file)
@@ -33,6 +33,8 @@
 #include "string.h"
 #include "partition.h"
 #include "fs.h"
+#include "errors.h"
+#include "debug.h"
 
 #define FAST_VERSION
 #define MAX_READ_RANGE 256
@@ -124,6 +126,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 +135,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 +157,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 +167,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 +183,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 +191,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 +200,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 +210,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 +224,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 +234,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 +260,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 +438,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 +465,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 +474,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 +525,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 +535,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 +546,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 +605,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 +620,3 @@ static errcode_t linux_flush (io_channel channel)
 {
     return 0;
 }
-