- int result = 0;
- static char buffer[1024];
- int ofopened = 0;
-
- DEBUG_ENTER;
- DEBUG_OPEN;
-
- if (opened) {
- prom_printf("ext2_open() : fs busy\n");
- return FILE_ERR_NOTFOUND;
- }
- if (file->device_kind != FILE_DEVICE_BLOCK) {
- prom_printf("Can't open ext2 filesystem on non-block device\n");
- return FILE_ERR_NOTFOUND;
- }
-
- fs = NULL;
-
- /* We don't care too much about the device block size since we run
- * thru the deblocker. We may have to change that is we plan to be
- * compatible with older versions of OF
- */
- bs = 1024;
- doff = 0;
- if (part)
- doff = (unsigned long long)(part->part_start) * part->blocksize;
- cur_file = file;
-
-
- DEBUG_F("partition offset: %d\n", doff);
-
- /* Open the OF device for the entire disk */
- strncpy(buffer, dev_name, 1020);
- strcat(buffer, ":0");
-
- DEBUG_F("<%s>\n", buffer);
-
- file->of_device = prom_open(buffer);
-
- DEBUG_F("file->of_device = %08lx\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;
- }
- ofopened = 1;
-
- /* Open the ext2 filesystem */
- result = ext2fs_open (buffer, EXT2_FLAG_RW, 0, 0, linux_io_manager, &fs);
- if (result) {
-
- if(result == EXT2_ET_BAD_MAGIC)
- {
- DEBUG_F( "ext2fs_open returned bad magic loading file %s\n",
- file );
- }
- else
- {
- DEBUG_F( "ext2fs_open error #%d while loading file %s\n",
- result, file_name);
- }
-
- goto bail;
- }
-
- /* Allocate the block buffer */
- block_buffer = malloc(fs->blocksize * 2);
- if (!block_buffer) {
-
- DEBUG_F("ext2fs: can't alloc block buffer (%d bytes)\n", fs->blocksize * 2);
-
- goto bail;
- }
-
- /* Lookup file by pathname */
- root = cwd = EXT2_ROOT_INO;
- result = ext2fs_namei_follow(fs, root, cwd, file_name, &file->inode);
- if (result) {
-
- DEBUG_F("ext2fs_namei error #%d while loading file %s\n", result, file_name);
- goto bail;
- }
+ int result = 0;
+ int error = FILE_ERR_NOTFOUND;
+ static char buffer[1024];
+ int ofopened = 0;
+ char *dev_name = fspec->dev;
+ char *file_name = fspec->file;
+
+ DEBUG_ENTER;
+ DEBUG_OPEN;
+
+ if (opened) {
+ DEBUG_LEAVE(FILE_ERR_FSBUSY);
+ return FILE_ERR_FSBUSY;
+ }
+ if (file->device_kind != FILE_DEVICE_BLOCK
+ && file->device_kind != FILE_DEVICE_ISCSI) {
+ DEBUG_LEAVE(FILE_ERR_BADDEV);
+ return FILE_ERR_BADDEV;
+ }
+
+ fs = NULL;
+
+ /* We don't care too much about the device block size since we run
+ * thru the deblocker. We may have to change that is we plan to be
+ * compatible with older versions of OF
+ */
+ bs = 1024;
+
+ /*
+ * On the other hand, we do care about the actual size of the
+ * partition, reads or seeks past the end may cause undefined
+ * behavior on some devices. A netapp that tries to seek and
+ * read past the end of the lun takes ~30 secs to recover per
+ * attempt.
+ */
+ doff = dend = 0;
+ if (part) {
+ doff = (unsigned long long)(part->part_start) * part->blocksize;
+ dend = doff + (unsigned long long)part->part_size * part->blocksize;
+ }
+ cur_file = file;
+
+
+ DEBUG_F("partition offset: %Lx, end: %Lx\n", doff, dend);
+
+ /* Open the OF device for the entire disk */
+ strncpy(buffer, dev_name, 1020);
+ if (_machine != _MACH_bplan)
+ strcat(buffer, ":0");
+
+ DEBUG_F("<%s>\n", buffer);
+
+ file->of_device = prom_open(buffer);
+
+ DEBUG_F("file->of_device = %p\n", file->of_device);
+
+ if (file->of_device == PROM_INVALID_HANDLE) {
+
+ DEBUG_F("Can't open device %p\n", file->of_device);
+ DEBUG_LEAVE(FILE_IOERR);
+ return FILE_IOERR;
+ }
+ ofopened = 1;
+
+ /* Open the ext2 filesystem */
+ result = ext2fs_open (buffer, EXT2_FLAG_RW, 0, 0, linux_io_manager, &fs);
+ if (result) {
+
+ if(result == EXT2_ET_BAD_MAGIC)
+ {
+ 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;
+ }
+
+ /* Allocate the block buffer */
+ block_buffer = malloc(fs->blocksize * 2);
+ if (!block_buffer) {
+
+ DEBUG_F("ext2fs: can't alloc block buffer (%d bytes)\n", fs->blocksize * 2);
+ error = FILE_IOERR;
+ goto bail;
+ }
+
+ /* Lookup file by pathname */
+ root = cwd = EXT2_ROOT_INO;
+ result = ext2fs_namei_follow(fs, root, cwd, file_name, &file->inode);
+ 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;
+ }