ia64/xen-unstable

changeset 5162:c7447090c261

bitkeeper revision 1.1559 (4294fab4CMjRyJfuEBP1lUbAC6G9GA)

- pygrub/README provides information on packages needed to compile pygrub
- support reiserfs {2,3} filesystem
- dynamically build modules based on which filesystem libraries the
system has (proposed by Jeremy)
- pump up pygrub to version 0.2


Signed-off-by: Jeremy Katz <katzj@redhat.com>
Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 25 22:22:44 2005 +0000 (2005-05-25)
parents e82fb753b02f
children 1cdd49625356
files .rootkeys tools/pygrub/README tools/pygrub/setup.py tools/pygrub/src/fsys/reiser/__init__.py tools/pygrub/src/fsys/reiser/reisermodule.c
line diff
     1.1 --- a/.rootkeys	Wed May 25 22:18:10 2005 +0000
     1.2 +++ b/.rootkeys	Wed May 25 22:22:44 2005 +0000
     1.3 @@ -743,6 +743,8 @@ 4270cc81CzKMiujDPWcaYhu709vGXw tools/pyg
     1.4  4270cc81RTIiq9si0dI4YRTRE4KRMw tools/pygrub/src/fsys/ext2/__init__.py
     1.5  4270cc81YCYa4pexivBD2NdLE2F_Pg tools/pygrub/src/fsys/ext2/ext2module.c
     1.6  4270cc81o4BL5e8Cs87aSi8EXA5NtQ tools/pygrub/src/fsys/ext2/test.py
     1.7 +4294fab3_A8gB1E3T-8fDt0x0eGRqw tools/pygrub/src/fsys/reiser/__init__.py
     1.8 +4294fab3On_kRmhm1lwm4SDteFP_7Q tools/pygrub/src/fsys/reiser/reisermodule.c
     1.9  4270cc81TS6L_tEO6wSp5wcURcpldQ tools/pygrub/src/pygrub
    1.10  40c9c468icGyC5RAF1bRKsCXPDCvsA tools/python/Makefile
    1.11  40ffc44dOwe1CcYXGCkYHdG_NxcccA tools/python/logging/logging-0.4.9.2/PKG-INFO
     2.1 --- a/tools/pygrub/README	Wed May 25 22:18:10 2005 +0000
     2.2 +++ b/tools/pygrub/README	Wed May 25 22:22:44 2005 +0000
     2.3 @@ -1,1 +1,15 @@
     2.4 -Compiling this needs RPM e2fsprogs-devel installed.
     2.5 \ No newline at end of file
     2.6 +pygrub is a grub-like bootloader for xen. This tool is to use to boot domU images.
     2.7 +
     2.8 +To compile pygrub, you will need the following packages installed:
     2.9 +
    2.10 +1) Libraries of ext2fs, which is the following package (depend on your Linux distribution):
    2.11 +	- e2fslibs-dev on Debian based distributions (Debian, Ubuntu, Linspire, Libranet, Xandros, etc...)
    2.12 +	- e2fsprogs-devel on RedHat, Fedora Core
    2.13 +	- libext2fs2-devel on Mandriva/Mandrake
    2.14 +	- e2fsprogs on Gentoo
    2.15 +
    2.16 +2) Libraries of reiserfs, which is the following package (depend on your Linux distribution):
    2.17 +	- libreiserfs-dev on Debian based distributions (Debian, Ubuntu, Xandros, Libranet, Xandros, etc...)
    2.18 +	- progsreiserfs-devel on RedHat
    2.19 +	- progreiserfs on Gentoo
    2.20 +
     3.1 --- a/tools/pygrub/setup.py	Wed May 25 22:18:10 2005 +0000
     3.2 +++ b/tools/pygrub/setup.py	Wed May 25 22:22:44 2005 +0000
     3.3 @@ -3,14 +3,27 @@ import os
     3.4  
     3.5  extra_compile_args  = [ "-fno-strict-aliasing", "-Wall", "-Werror" ]
     3.6  
     3.7 -# in a perfect world, we'd figure out the fsys modules dynamically
     3.8 -ext2 = Extension("grub.fsys.ext2._pyext2",
     3.9 -                 extra_compile_args = extra_compile_args,
    3.10 -                 libraries = ["ext2fs"],
    3.11 -                 sources = ["src/fsys/ext2/ext2module.c"])
    3.12 +fsys_mods = []
    3.13 +fsys_pkgs = []
    3.14 +
    3.15 +if os.path.exists("/usr/include/ext2fs/ext2_fs.h"):
    3.16 +    ext2 = Extension("grub.fsys.ext2._pyext2",
    3.17 +                     extra_compile_args = extra_compile_args,
    3.18 +                     libraries = ["ext2fs"],
    3.19 +                     sources = ["src/fsys/ext2/ext2module.c"])
    3.20 +    fsys_mods.append(ext2)
    3.21 +    fsys_pkgs.append("grub.fsys.ext2")
    3.22 +
    3.23 +if os.path.exists("/usr/include/reiserfs/reiserfs.h"):
    3.24 +    reiser = Extension("grub.fsys.reiser._pyreiser",
    3.25 +                     extra_compile_args = extra_compile_args,
    3.26 +                     libraries = ["reiserfs"],
    3.27 +                     sources = ["src/fsys/reiser/reisermodule.c"])
    3.28 +    fsys_mods.append(reiser)
    3.29 +    fsys_pkgs.append("grub.fsys.reiser")
    3.30  
    3.31  setup(name='pygrub',
    3.32 -      version='0.1',
    3.33 +      version='0.2',
    3.34        description='Boot loader that looks a lot like grub for Xen',
    3.35        author='Jeremy Katz',
    3.36        author_email='katzj@redhat.com',
    3.37 @@ -18,8 +31,7 @@ setup(name='pygrub',
    3.38        package_dir={'grub': 'src'},
    3.39        scripts = ["src/pygrub"],
    3.40        packages=['grub',
    3.41 -                'grub.fsys',
    3.42 -                'grub.fsys.ext2'],
    3.43 -      ext_modules = [ext2]
    3.44 +                'grub.fsys'].extend(fsys_pkgs),
    3.45 +      ext_modules = fsys_mods
    3.46        )
    3.47                 
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/pygrub/src/fsys/reiser/__init__.py	Wed May 25 22:22:44 2005 +0000
     4.3 @@ -0,0 +1,39 @@
     4.4 +# 
     4.5 +# Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
     4.6 +#
     4.7 +# This software may be freely redistributed under the terms of the GNU
     4.8 +# general public license.
     4.9 +#
    4.10 +# You should have received a copy of the GNU General Public License
    4.11 +# along with this program; if not, write to the Free Software
    4.12 +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    4.13 +#
    4.14 +
    4.15 +from grub.fsys import register_fstype, FileSystemType
    4.16 +from _pyreiser import *
    4.17 +
    4.18 +import os
    4.19 +
    4.20 +FSMAGIC2 = 'ReIsEr2'
    4.21 +FSMAGIC3 = 'ReIsEr3'
    4.22 +
    4.23 +class ReiserFileSystemType(FileSystemType):
    4.24 +    def __init__(self):
    4.25 +        FileSystemType.__init__(self)
    4.26 +        self.name = "reiser"
    4.27 +
    4.28 +    def sniff_magic(self, fn, offset = 0):
    4.29 +        fd = os.open(fn, os.O_RDONLY)
    4.30 +        os.lseek(fd, 0x10000, 0)
    4.31 +        buf = os.read(fd, 0x40)
    4.32 +        if len(buf) == 0x40 and (buf[0x34:0x3B] in [FSMAGIC2, FSMAGIC3]) :
    4.33 +            return True
    4.34 +        return False
    4.35 +
    4.36 +    def open_fs(self, fn, offset = 0):
    4.37 +        if not self.sniff_magic(fn, offset):
    4.38 +            raise ValueError, "Not a reiserfs filesystem"
    4.39 +        return ReiserFs(fn)
    4.40 +
    4.41 +register_fstype(ReiserFileSystemType())
    4.42 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/pygrub/src/fsys/reiser/reisermodule.c	Wed May 25 22:22:44 2005 +0000
     5.3 @@ -0,0 +1,345 @@
     5.4 +/*
     5.5 + * reisermodule.c - simple python binding for libreiserfs{2,3}
     5.6 + *
     5.7 + * Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
     5.8 + *
     5.9 + * This software may be freely redistributed under the terms of the GNU
    5.10 + * general public license.
    5.11 + *
    5.12 + * You should have received a copy of the GNU General Public License
    5.13 + * along with this program; if not, write to the Free Software
    5.14 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    5.15 + */
    5.16 +
    5.17 +#include <Python.h>
    5.18 +
    5.19 +#include <fcntl.h>
    5.20 +#include <stdlib.h>
    5.21 +#include <stdio.h>
    5.22 +
    5.23 +#include <dal/file_dal.h>
    5.24 +#include <reiserfs/reiserfs.h>
    5.25 +
    5.26 +#if (PYTHON_API_VERSION >= 1011)
    5.27 +#define PY_PAD 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L
    5.28 +#else
    5.29 +#define PY_PAD 0L,0L,0L,0L
    5.30 +#endif
    5.31 +
    5.32 +
    5.33 +/* global error object */
    5.34 +PyObject *ReiserError;
    5.35 +
    5.36 +typedef struct {
    5.37 +    PyObject_HEAD
    5.38 +    reiserfs_fs_t *fs;
    5.39 +	dal_t *dal;
    5.40 +} ReiserFs;
    5.41 +
    5.42 +typedef struct _ReiserFile ReiserFile;
    5.43 +struct _ReiserFile {
    5.44 +    PyObject_HEAD
    5.45 +    reiserfs_file_t *file;
    5.46 +};
    5.47 +
    5.48 +void file_dal_close(dal_t *dal) {
    5.49 +
    5.50 +	if (!dal) return;
    5.51 +
    5.52 +	close((int)dal->dev);
    5.53 +	dal_free(dal);
    5.54 +}
    5.55 +
    5.56 +/* reiser file object */
    5.57 +
    5.58 +static PyObject *
    5.59 +reiser_file_close (ReiserFile *file, PyObject *args)
    5.60 +{
    5.61 +    if (file->file != NULL)
    5.62 +	{
    5.63 +        reiserfs_file_close(file->file);
    5.64 +		file->file = NULL;
    5.65 +	}
    5.66 +    Py_INCREF(Py_None);
    5.67 +    return Py_None;
    5.68 +}
    5.69 +
    5.70 +static PyObject *
    5.71 +reiser_file_read (ReiserFile *file, PyObject *args)
    5.72 +{
    5.73 +    int size = 0;
    5.74 +    size_t n, total = 0;
    5.75 +    PyObject * buffer = NULL;
    5.76 +
    5.77 +    if (file->file == NULL) {
    5.78 +        PyErr_SetString(PyExc_ValueError, "Cannot read from closed file");
    5.79 +        return NULL;
    5.80 +    }
    5.81 +
    5.82 +    if (!PyArg_ParseTuple(args, "|i", &size))
    5.83 +        return NULL;
    5.84 +
    5.85 +    buffer = PyString_FromStringAndSize((char *) NULL, (size) ? size : 4096);
    5.86 +    if (buffer == NULL)
    5.87 +        return buffer;
    5.88 + 
    5.89 +    while (1) {
    5.90 +        n = reiserfs_file_read(file->file, PyString_AS_STRING(buffer) + total, 
    5.91 +                               (size) ? size : 4096);
    5.92 +        if (n == 0)
    5.93 +            break;
    5.94 +
    5.95 +        total += n;
    5.96 +
    5.97 +        if (size && size == total)
    5.98 +            break;
    5.99 +
   5.100 +        if (!size) {
   5.101 +            _PyString_Resize(&buffer, total + 4096);
   5.102 +        }
   5.103 +    }
   5.104 +
   5.105 +    _PyString_Resize(&buffer, total);
   5.106 +    return buffer;
   5.107 +}
   5.108 +
   5.109 +static void
   5.110 +reiser_file_dealloc (ReiserFile * file)
   5.111 +{
   5.112 +    if (file->file != NULL) {
   5.113 +        reiserfs_file_close(file->file);
   5.114 +		file->file = NULL;
   5.115 +	}
   5.116 +	PyObject_DEL(file);
   5.117 +}
   5.118 +
   5.119 +static struct PyMethodDef ReiserFileMethods[] = {
   5.120 +	{ "close", (PyCFunction) reiser_file_close, METH_VARARGS, NULL },
   5.121 +	{ "read", (PyCFunction) reiser_file_read, METH_VARARGS, NULL },
   5.122 +	{ NULL, NULL, 0, NULL }	
   5.123 +};
   5.124 +
   5.125 +static PyObject *
   5.126 +reiser_file_getattr (ReiserFile * file, char * name)
   5.127 +{
   5.128 +	return Py_FindMethod (ReiserFileMethods, (PyObject *) file, name);
   5.129 +}
   5.130 +
   5.131 +static char ReiserFileType__doc__[] = "This is the reiser filesystem object";
   5.132 +PyTypeObject ReiserFileType = {
   5.133 +	PyObject_HEAD_INIT(&PyType_Type)
   5.134 +	0,				/* ob_size */
   5.135 +	"ReiserFile",			/* tp_name */
   5.136 +	sizeof(ReiserFile),		/* tp_size */
   5.137 +	0,				/* tp_itemsize */
   5.138 +	(destructor) reiser_file_dealloc, 	/* tp_dealloc */
   5.139 +	0,				/* tp_print */
   5.140 +	(getattrfunc) reiser_file_getattr, 	/* tp_getattr */
   5.141 +	0,				/* tp_setattr */
   5.142 +	0,				/* tp_compare */
   5.143 +	0,				/* tp_repr */
   5.144 +	0,				/* tp_as_number */
   5.145 +	0,	 			/* tp_as_sequence */
   5.146 +	0,				/* tp_as_mapping */
   5.147 +	0,           	/* tp_hash */
   5.148 +	0,             	/* tp_call */
   5.149 +	0,             	/* tp_str */
   5.150 +	0,				/* tp_getattro */
   5.151 +	0,				/* tp_setattro */
   5.152 +	0,				/* tp_as_buffer */
   5.153 +	Py_TPFLAGS_DEFAULT,	       		/* tp_flags */
   5.154 +	ReiserFileType__doc__,
   5.155 +	PY_PAD
   5.156 +};
   5.157 +
   5.158 +static PyObject *
   5.159 +reiser_file_open (ReiserFs *fs, char *name, int flags)
   5.160 +{
   5.161 +    ReiserFile *file;
   5.162 +    reiserfs_file_t *f;
   5.163 +
   5.164 +    file = (ReiserFile *) PyObject_NEW(ReiserFile, &ReiserFileType);
   5.165 +
   5.166 +    f = reiserfs_file_open(fs->fs, name, flags);
   5.167 +    file->file = f;
   5.168 +    
   5.169 +    if (!f) {
   5.170 +        PyErr_SetString(PyExc_ValueError, "unable to open file");
   5.171 +        return NULL;
   5.172 +    }
   5.173 +
   5.174 +    return (PyObject *) file;
   5.175 +}
   5.176 +
   5.177 +static PyObject *
   5.178 +reiser_file_exist (ReiserFs *fs, char *name)
   5.179 +{
   5.180 +    reiserfs_file_t *f;
   5.181 +
   5.182 +    f = reiserfs_file_open(fs->fs, name, O_RDONLY);
   5.183 +
   5.184 +	if (!f) {
   5.185 +		Py_INCREF(Py_False);
   5.186 +		return Py_False;
   5.187 +	}
   5.188 +	reiserfs_file_close(f);
   5.189 +    Py_INCREF(Py_True);
   5.190 +    return Py_True;
   5.191 +}
   5.192 +
   5.193 +/* reiserfs object */
   5.194 +
   5.195 +static PyObject *
   5.196 +reiser_fs_close (ReiserFs *fs, PyObject *args)
   5.197 +{
   5.198 +    if (fs->fs != NULL)
   5.199 +    {
   5.200 +        reiserfs_fs_close(fs->fs);
   5.201 +        file_dal_close(fs->dal);
   5.202 +		fs->fs = NULL;
   5.203 +    }
   5.204 +    Py_INCREF(Py_None);
   5.205 +    return Py_None;
   5.206 +}
   5.207 +
   5.208 +static PyObject *
   5.209 +reiser_fs_open (ReiserFs *fs, PyObject *args)
   5.210 +{
   5.211 +    char *name;
   5.212 +	size_t block_size = DEFAULT_BLOCK_SIZE;
   5.213 +    dal_t *dal;
   5.214 +    reiserfs_fs_t *rfs;
   5.215 +
   5.216 +    if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
   5.217 +        return NULL;
   5.218 +
   5.219 +    if (fs->fs != NULL) {
   5.220 +        PyErr_SetString(PyExc_ValueError, "already have an fs object");
   5.221 +        return NULL;
   5.222 +    }
   5.223 +
   5.224 +    if (!(dal = file_dal_open(name, block_size, O_RDONLY))) {
   5.225 +        PyErr_SetString(PyExc_ValueError, "Couldn't create device abstraction");
   5.226 +        return NULL;    
   5.227 +    }
   5.228 +    
   5.229 +    if (!(rfs = reiserfs_fs_open_fast(dal, dal))) {
   5.230 +		file_dal_close(dal);
   5.231 +        PyErr_SetString(PyExc_ValueError, "unable to open file");
   5.232 +        return NULL;
   5.233 +    }
   5.234 +    
   5.235 +    fs->fs = rfs;
   5.236 +	fs->dal = dal;
   5.237 +
   5.238 +    Py_INCREF(Py_None);
   5.239 +    return Py_None;
   5.240 +}
   5.241 +
   5.242 +static PyObject *
   5.243 +reiser_fs_open_file (ReiserFs *fs, PyObject *args)
   5.244 +{
   5.245 +    char *name;
   5.246 +    int flags = 0;
   5.247 +
   5.248 +    if (!PyArg_ParseTuple(args, "s|i", &name, &flags))
   5.249 +		return NULL;
   5.250 +
   5.251 +    return reiser_file_open(fs, name, flags);
   5.252 +}
   5.253 +
   5.254 +static PyObject *
   5.255 +reiser_fs_file_exist (ReiserFs *fs, PyObject *args)
   5.256 +{
   5.257 +    char * name;
   5.258 +
   5.259 +    if (!PyArg_ParseTuple(args, "s", &name))
   5.260 +        return NULL;
   5.261 +
   5.262 +    return reiser_file_exist(fs, name);
   5.263 +}
   5.264 +
   5.265 +static void
   5.266 +reiser_fs_dealloc (ReiserFs * fs)
   5.267 +{
   5.268 +    if (fs->fs != NULL)
   5.269 +	{
   5.270 +        reiserfs_fs_close(fs->fs);
   5.271 +		file_dal_close(fs->dal);
   5.272 +		fs->fs = NULL;
   5.273 +	}
   5.274 +	PyObject_DEL(fs);
   5.275 +}
   5.276 +
   5.277 +static struct PyMethodDef ReiserFsMethods[] = {
   5.278 +	{ "close", (PyCFunction) reiser_fs_close, METH_VARARGS, NULL },
   5.279 +	{ "open", (PyCFunction) reiser_fs_open, METH_VARARGS, NULL },
   5.280 +	{ "open_file", (PyCFunction) reiser_fs_open_file, METH_VARARGS, NULL },
   5.281 +	{ "file_exist", (PyCFunction) reiser_fs_file_exist, METH_VARARGS, NULL },
   5.282 +	{ NULL, NULL, 0, NULL }	
   5.283 +};
   5.284 +
   5.285 +static PyObject *
   5.286 +reiser_fs_getattr (ReiserFs * fs, char * name)
   5.287 +{
   5.288 +        return Py_FindMethod (ReiserFsMethods, (PyObject *) fs, name);
   5.289 +}
   5.290 +
   5.291 +static char ReiserFsType__doc__[] = "This is the reiser filesystem object";
   5.292 +
   5.293 +PyTypeObject ReiserFsType = {
   5.294 +	PyObject_HEAD_INIT(&PyType_Type)
   5.295 +	0,				/* ob_size */
   5.296 +	"ReiserFs",		/* tp_name */
   5.297 +	sizeof(ReiserFs),		/* tp_size */
   5.298 +	0,				/* tp_itemsize */
   5.299 +	(destructor) reiser_fs_dealloc, 	/* tp_dealloc */
   5.300 +	0,				/* tp_print */
   5.301 +	(getattrfunc) reiser_fs_getattr, 	/* tp_getattr */
   5.302 +	0,				/* tp_setattr */
   5.303 +	0,				/* tp_compare */
   5.304 +	0,				/* tp_repr */
   5.305 +	0,				/* tp_as_number */
   5.306 +	0,	 			/* tp_as_sequence */
   5.307 +	0,				/* tp_as_mapping */
   5.308 +	0,           	/* tp_hash */
   5.309 +	0,             	/* tp_call */
   5.310 +	0,             	/* tp_str */
   5.311 +	0,				/* tp_getattro */
   5.312 +	0,				/* tp_setattro */
   5.313 +	0,				/* tp_as_buffer */
   5.314 +	Py_TPFLAGS_DEFAULT,			/* tp_flags */
   5.315 +	ReiserFsType__doc__,
   5.316 +	PY_PAD
   5.317 +};
   5.318 +
   5.319 +static PyObject *
   5.320 +reiser_fs_new(PyObject *o, PyObject *args) 
   5.321 +{
   5.322 +    char *name;
   5.323 +	size_t block_size = DEFAULT_BLOCK_SIZE;
   5.324 +    ReiserFs *pfs;
   5.325 +    
   5.326 +    if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
   5.327 +        return NULL;
   5.328 +    
   5.329 +    pfs = (ReiserFs *) PyObject_NEW(ReiserFs, &ReiserFsType);
   5.330 +    if (pfs == NULL)
   5.331 +        return NULL;
   5.332 +
   5.333 +    pfs->fs = NULL;
   5.334 +    
   5.335 +    if (!reiser_fs_open(pfs, Py_BuildValue("si", name, block_size)))
   5.336 +        return NULL;
   5.337 +    
   5.338 +    return (PyObject *)pfs;
   5.339 +}
   5.340 +
   5.341 +static struct PyMethodDef ReiserModuleMethods[] = {
   5.342 +    { "ReiserFs", (PyCFunction) reiser_fs_new, METH_VARARGS},
   5.343 +    { NULL, NULL, 0}
   5.344 +};
   5.345 +
   5.346 +void init_pyreiser(void) {
   5.347 +    Py_InitModule("_pyreiser", ReiserModuleMethods);
   5.348 +}