ia64/xen-unstable

changeset 9574:c5a833aec2ab

Improve pygrub error reporting when opening ext2 fs is not possible

As reported in the thread:
http://lists.xensource.com/archives/html/xen-users/2006-03/msg00721.html,
pygrub does not open ext2 file systems in partitioned images or sub
partitions on e.g. CentOS/RHEL 4, because e2fsprogs ext2fs_open does not
support an offset into the file to be opened.

With this patch, the error is correctly reported instead of a generic
"unable to open file" (and leaving the user searching in the dark).

Signed-off-by: Michael Paesold <mpaesold@gmx.at>
author mip@xencore04.1virtual.net
date Mon Apr 03 18:28:54 2006 +0100 (2006-04-03)
parents 7df5921af7e4
children b3751c780aa5
files tools/pygrub/src/fsys/ext2/ext2module.c
line diff
     1.1 --- a/tools/pygrub/src/fsys/ext2/ext2module.c	Mon Apr 03 18:23:00 2006 +0100
     1.2 +++ b/tools/pygrub/src/fsys/ext2/ext2module.c	Mon Apr 03 18:28:54 2006 +0100
     1.3 @@ -213,7 +213,9 @@ ext2_fs_open (Ext2Fs *fs, PyObject *args
     1.4      int flags = 0, superblock = 0, offset = 0, err;
     1.5      unsigned int block_size = 0;
     1.6      ext2_filsys efs;
     1.7 +#ifdef HAVE_EXT2FS_OPEN2
     1.8      char offsetopt[30];
     1.9 +#endif
    1.10  
    1.11      if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist, 
    1.12                                       &name, &flags, &superblock, 
    1.13 @@ -225,19 +227,24 @@ ext2_fs_open (Ext2Fs *fs, PyObject *args
    1.14          return NULL;
    1.15      }
    1.16  
    1.17 +#ifdef HAVE_EXT2FS_OPEN2
    1.18      if (offset != 0) {
    1.19          snprintf(offsetopt, 29, "offset=%d", offset);
    1.20      }
    1.21  
    1.22 -#ifdef HAVE_EXT2FS_OPEN2
    1.23      err = ext2fs_open2(name, offsetopt, flags, superblock, block_size, 
    1.24                         unix_io_manager, &efs);
    1.25  #else
    1.26 +    if (offset != 0) {
    1.27 +        PyErr_SetString(PyExc_ValueError, "offset argument not supported");
    1.28 +        return NULL;
    1.29 +    }
    1.30 +
    1.31      err = ext2fs_open(name, flags, superblock, block_size,
    1.32                        unix_io_manager, &efs);
    1.33  #endif
    1.34      if (err) {
    1.35 -        PyErr_SetString(PyExc_ValueError, "unable to open file");
    1.36 +        PyErr_SetString(PyExc_ValueError, "unable to open filesystem");
    1.37          return NULL;
    1.38      }
    1.39