* RE: [PATCH] reiserfs module for pygrub
@ 2005-05-18 19:37 Ian Pratt
2005-05-19 1:15 ` aq
2005-05-23 23:57 ` Jeremy Katz
0 siblings, 2 replies; 16+ messages in thread
From: Ian Pratt @ 2005-05-18 19:37 UTC (permalink / raw)
To: aq, xen-devel, Jeremy Katz
> here is a patch to add reiserfs (version 2,3) support to
> pygrub in -unstable (against cset 1.1434)
Does Fedora have a reiserfs tools devel package?
Please can you add something to the tools/check directory that checks
the appropriate headers are installed. Also, at runtime, are there
issues with libraries being present? Can you load the library
dynamically if required?
Thanks,
Ian
> list of changes:
> - update tools/pygrub/README about packages needed to compile pygrub
> - tools/pygrub/setup.py to support reiserfs module
> - toolspygrub/src/fsys/reiserfs/ directory with 2 files
> __init__.py and reisermodule.c to provide reiserfs support to pygrub.
>
> Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>
>
> $ diffstat reiser_pygrub.patch
> README | 16 +
> setup.py | 10 -
> src/fsys/reiser/__init__.py | 39 ++++
> src/fsys/reiser/reisermodule.c | 345
> +++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 407 insertions(+), 3 deletions(-)
>
> --
> regards,
> aq
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] reiserfs module for pygrub
2005-05-18 19:37 [PATCH] reiserfs module for pygrub Ian Pratt
@ 2005-05-19 1:15 ` aq
2005-05-23 23:57 ` Jeremy Katz
1 sibling, 0 replies; 16+ messages in thread
From: aq @ 2005-05-19 1:15 UTC (permalink / raw)
To: Ian Pratt; +Cc: Jeremy Katz, xen-devel
On 5/19/05, Ian Pratt <m+Ian.Pratt@cl.cam.ac.uk> wrote:
>
>
> > here is a patch to add reiserfs (version 2,3) support to
> > pygrub in -unstable (against cset 1.1434)
>
> Does Fedora have a reiserfs tools devel package?
>
actually i dont run FC, and i asked a friend check this package for me
on his FC. anybody could please confirm this?
> Please can you add something to the tools/check directory that checks
> the appropriate headers are installed.
yes, that is easy.
>Also, at runtime, are there
> issues with libraries being present?
what kind of issues do you want to mention?
>Can you load the library
> dynamically if required?
>
i dont understand why you want to load libs "dynamically"?
regards,
aq
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PATCH] reiserfs module for pygrub
2005-05-18 19:37 [PATCH] reiserfs module for pygrub Ian Pratt
2005-05-19 1:15 ` aq
@ 2005-05-23 23:57 ` Jeremy Katz
2005-05-24 1:04 ` aq
1 sibling, 1 reply; 16+ messages in thread
From: Jeremy Katz @ 2005-05-23 23:57 UTC (permalink / raw)
To: Ian Pratt; +Cc: xen-devel
[-- Attachment #1: Type: text/plain, Size: 1058 bytes --]
On Wed, 2005-05-18 at 20:37 +0100, Ian Pratt wrote:
> > here is a patch to add reiserfs (version 2,3) support to
> > pygrub in -unstable (against cset 1.1434)
>
> Does Fedora have a reiserfs tools devel package?
Not at present.
> Please can you add something to the tools/check directory that checks
> the appropriate headers are installed.
What if we check instead for the headers being present and only building
the filesystem modules that there's support for on the system? Then
distributors can ensure they have the right things in their buildsystem
and anyone else can do the same. The attached patch should implement
that for libext2fs.
> Also, at runtime, are there
> issues with libraries being present? Can you load the library
> dynamically if required?
The libraries get linked dynamically into the python module. If at
runtime, the library isn't present, it won't cause a fatal error (you
won't be able to access those types of filesystems, but it won't fall
over on the import)
Signed-off-by: Jeremy Katz <katzj@redhat.com>
Jeremy
[-- Attachment #2: xen-pygrub-fsys-detect.patch --]
[-- Type: text/x-patch, Size: 1424 bytes --]
===== tools/pygrub/setup.py 1.2 vs edited =====
--- 1.2/tools/pygrub/setup.py 2005-04-28 08:27:46 -04:00
+++ edited/tools/pygrub/setup.py 2005-05-23 19:49:51 -04:00
@@ -3,14 +3,19 @@
extra_compile_args = [ "-fno-strict-aliasing", "-Wall", "-Werror" ]
-# in a perfect world, we'd figure out the fsys modules dynamically
-ext2 = Extension("grub.fsys.ext2._pyext2",
- extra_compile_args = extra_compile_args,
- libraries = ["ext2fs"],
- sources = ["src/fsys/ext2/ext2module.c"])
+fsys_mods = []
+fsys_pkgs = []
+
+if os.path.exists("/usr/include/ext2fs/ext2_fs.h"):
+ ext2 = Extension("grub.fsys.ext2._pyext2",
+ extra_compile_args = extra_compile_args,
+ libraries = ["ext2fs"],
+ sources = ["src/fsys/ext2/ext2module.c"])
+ fsys_mods.append(ext2)
+ fsys_pkgs.append("grub.fsys.ext2")
setup(name='pygrub',
- version='0.1',
+ version='0.2',
description='Boot loader that looks a lot like grub for Xen',
author='Jeremy Katz',
author_email='katzj@redhat.com',
@@ -18,8 +23,7 @@
package_dir={'grub': 'src'},
scripts = ["src/pygrub"],
packages=['grub',
- 'grub.fsys',
- 'grub.fsys.ext2'],
- ext_modules = [ext2]
+ 'grub.fsys'].extend(fsys_pkgs),
+ ext_modules = fsys_mods
)
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH] reiserfs module for pygrub
2005-05-23 23:57 ` Jeremy Katz
@ 2005-05-24 1:04 ` aq
0 siblings, 0 replies; 16+ messages in thread
From: aq @ 2005-05-24 1:04 UTC (permalink / raw)
To: Jeremy Katz; +Cc: Ian Pratt, xen-devel
On 5/24/05, Jeremy Katz <katzj@redhat.com> wrote:
> On Wed, 2005-05-18 at 20:37 +0100, Ian Pratt wrote:
> > > here is a patch to add reiserfs (version 2,3) support to
> > > pygrub in -unstable (against cset 1.1434)
> >
> > Does Fedora have a reiserfs tools devel package?
>
> Not at present.
>
> > Please can you add something to the tools/check directory that checks
> > the appropriate headers are installed.
>
> What if we check instead for the headers being present and only building
> the filesystem modules that there's support for on the system? Then
> distributors can ensure they have the right things in their buildsystem
> and anyone else can do the same. The attached patch should implement
> that for libext2fs.
>
> > Also, at runtime, are there
> > issues with libraries being present? Can you load the library
> > dynamically if required?
>
> The libraries get linked dynamically into the python module. If at
> runtime, the library isn't present, it won't cause a fatal error (you
> won't be able to access those types of filesystems, but it won't fall
> over on the import)
>
yes, this trick could be easily adapted to reiserfs and others. but
what if the user keeps the needed libraries, but removes those headers
( like /usr/include/ext2fs/ext2_fs.h )after building (for example to
make the system more compact)? then the check would fail.
actually we should check for those need to present at runtime, not
things at compile time. i propose checking /usr/lib/libext2fs.so
instead of header files (incase we use dynamic libs)
regards,
aq
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PATCH] reiserfs module for pygrub
@ 2005-05-24 1:27 Ian Pratt
2005-05-24 3:17 ` Jeremy Katz
0 siblings, 1 reply; 16+ messages in thread
From: Ian Pratt @ 2005-05-24 1:27 UTC (permalink / raw)
To: aq, Jeremy Katz; +Cc: xen-devel
> > The libraries get linked dynamically into the python module. If at
> > runtime, the library isn't present, it won't cause a fatal
> error (you
> > won't be able to access those types of filesystems, but it
> won't fall
> > over on the import)
> >
>
> yes, this trick could be easily adapted to reiserfs and
> others. but what if the user keeps the needed libraries, but
> removes those headers ( like /usr/include/ext2fs/ext2_fs.h
> )after building (for example to make the system more
> compact)? then the check would fail.
As I understand it, it's a build-time check for the header file
(setup.py)
Ian
> actually we should check for those need to present at
> runtime, not things at compile time. i propose checking
> /usr/lib/libext2fs.so instead of header files (incase we use
> dynamic libs)
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PATCH] reiserfs module for pygrub
2005-05-24 1:27 Ian Pratt
@ 2005-05-24 3:17 ` Jeremy Katz
2005-05-24 4:09 ` aq
2005-05-24 4:15 ` aq
0 siblings, 2 replies; 16+ messages in thread
From: Jeremy Katz @ 2005-05-24 3:17 UTC (permalink / raw)
To: Ian Pratt; +Cc: xen-devel
On Tue, 2005-05-24 at 02:27 +0100, Ian Pratt wrote:
> > > The libraries get linked dynamically into the python module. If at
> > > runtime, the library isn't present, it won't cause a fatal
> > error (you
> > > won't be able to access those types of filesystems, but it
> > won't fall
> > > over on the import)
> >
> > yes, this trick could be easily adapted to reiserfs and
> > others. but what if the user keeps the needed libraries, but
> > removes those headers ( like /usr/include/ext2fs/ext2_fs.h
> > )after building (for example to make the system more
> > compact)? then the check would fail.
>
> As I understand it, it's a build-time check for the header file
> (setup.py)
Exactly.
Jeremy
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] reiserfs module for pygrub
2005-05-24 3:17 ` Jeremy Katz
@ 2005-05-24 4:09 ` aq
2005-05-24 4:15 ` aq
1 sibling, 0 replies; 16+ messages in thread
From: aq @ 2005-05-24 4:09 UTC (permalink / raw)
To: Jeremy Katz; +Cc: Ian Pratt, xen-devel
On 5/24/05, Jeremy Katz <katzj@redhat.com> wrote:
> On Tue, 2005-05-24 at 02:27 +0100, Ian Pratt wrote:
> > > > The libraries get linked dynamically into the python module. If at
> > > > runtime, the library isn't present, it won't cause a fatal
> > > error (you
> > > > won't be able to access those types of filesystems, but it
> > > won't fall
> > > > over on the import)
> > >
> > > yes, this trick could be easily adapted to reiserfs and
> > > others. but what if the user keeps the needed libraries, but
> > > removes those headers ( like /usr/include/ext2fs/ext2_fs.h
> > > )after building (for example to make the system more
> > > compact)? then the check would fail.
> >
> > As I understand it, it's a build-time check for the header file
> > (setup.py)
>
> Exactly.
>
ah yes. this is setup.py, my bad mistake.
thanks,
aq
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] reiserfs module for pygrub
2005-05-24 3:17 ` Jeremy Katz
2005-05-24 4:09 ` aq
@ 2005-05-24 4:15 ` aq
2005-05-24 19:34 ` Jeremy Katz
1 sibling, 1 reply; 16+ messages in thread
From: aq @ 2005-05-24 4:15 UTC (permalink / raw)
To: Jeremy Katz; +Cc: Ian Pratt, xen-devel
On 5/24/05, Jeremy Katz <katzj@redhat.com> wrote:
> On Tue, 2005-05-24 at 02:27 +0100, Ian Pratt wrote:
> > > > The libraries get linked dynamically into the python module. If at
> > > > runtime, the library isn't present, it won't cause a fatal
> > > error (you
> > > > won't be able to access those types of filesystems, but it
> > > won't fall
> > > > over on the import)
> > >
> > > yes, this trick could be easily adapted to reiserfs and
> > > others. but what if the user keeps the needed libraries, but
> > > removes those headers ( like /usr/include/ext2fs/ext2_fs.h
> > > )after building (for example to make the system more
> > > compact)? then the check would fail.
> >
> > As I understand it, it's a build-time check for the header file
> > (setup.py)
>
> Exactly.
>
anyway, i sent in a check file for ext2 and reiserfs tools/check/
check_fslibs_devel (which is filtered by accident, and i dont see it
to be approved to the list yet?). so i doubt that we need to check
(again) for header files in setup.py.
regards,
aq
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] reiserfs module for pygrub
2005-05-24 4:15 ` aq
@ 2005-05-24 19:34 ` Jeremy Katz
2005-05-25 21:57 ` aq
0 siblings, 1 reply; 16+ messages in thread
From: Jeremy Katz @ 2005-05-24 19:34 UTC (permalink / raw)
To: aq; +Cc: Ian Pratt, xen-devel
On Tue, 2005-05-24 at 13:15 +0900, aq wrote:
> On 5/24/05, Jeremy Katz <katzj@redhat.com> wrote:
> > On Tue, 2005-05-24 at 02:27 +0100, Ian Pratt wrote:
> > > > > The libraries get linked dynamically into the python module. If at
> > > > > runtime, the library isn't present, it won't cause a fatal
> > > > error (you
> > > > > won't be able to access those types of filesystems, but it
> > > > won't fall
> > > > > over on the import)
> > > >
> > > > yes, this trick could be easily adapted to reiserfs and
> > > > others. but what if the user keeps the needed libraries, but
> > > > removes those headers ( like /usr/include/ext2fs/ext2_fs.h
> > > > )after building (for example to make the system more
> > > > compact)? then the check would fail.
> > >
> > > As I understand it, it's a build-time check for the header file
> > > (setup.py)
> >
> > Exactly.
> >
>
> anyway, i sent in a check file for ext2 and reiserfs tools/check/
> check_fslibs_devel (which is filtered by accident, and i dont see it
> to be approved to the list yet?). so i doubt that we need to check
> (again) for header files in setup.py.
The question is whether we want all of the libraries to be mandatory or
not. I'd lean towards them not being mandatory (ie, we build what you
have unless you specify an environment variable) instead of having them
all be required.
Jeremy
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] reiserfs module for pygrub
2005-05-24 19:34 ` Jeremy Katz
@ 2005-05-25 21:57 ` aq
0 siblings, 0 replies; 16+ messages in thread
From: aq @ 2005-05-25 21:57 UTC (permalink / raw)
To: Jeremy Katz; +Cc: Ian Pratt, xen-devel
[-- Attachment #1: Type: text/plain, Size: 813 bytes --]
hello,
after some discussions with Ian and Jeremy, i put out the new patch
for reiserfs module. please consider applying/rejecting.
list of changes:
- 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>
$ diffstat pygrub_reiserfs.patch
README | 16 +
setup.py | 30 ++-
src/fsys/reiser/__init__.py | 39 ++++
src/fsys/reiser/reisermodule.c | 345 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 420 insertions(+), 10 deletions(-)
[-- Attachment #2: pygrub_reiserfs.patch --]
[-- Type: application/octet-stream, Size: 12998 bytes --]
diff -Nurp -X dontdiff.xen xeno-today/tools/pygrub/README xeno-unstable.0524/tools/pygrub/README
--- xeno-today/tools/pygrub/README 2005-05-26 06:31:45.000000000 +0900
+++ xeno-unstable.0524/tools/pygrub/README 2005-05-26 05:41:39.000000000 +0900
@@ -1 +1,15 @@
-Compiling this needs RPM e2fsprogs-devel installed.
\ No newline at end of file
+pygrub is a grub-like bootloader for xen. This tool is to use to boot domU images.
+
+To compile pygrub, you will need the following packages installed:
+
+1) Libraries of ext2fs, which is the following package (depend on your Linux distribution):
+ - e2fslibs-dev on Debian based distributions (Debian, Ubuntu, Linspire, Libranet, Xandros, etc...)
+ - e2fsprogs-devel on RedHat, Fedora Core
+ - libext2fs2-devel on Mandriva/Mandrake
+ - e2fsprogs on Gentoo
+
+2) Libraries of reiserfs, which is the following package (depend on your Linux distribution):
+ - libreiserfs-dev on Debian based distributions (Debian, Ubuntu, Xandros, Libranet, Xandros, etc...)
+ - progsreiserfs-devel on RedHat
+ - progreiserfs on Gentoo
+
diff -Nurp -X dontdiff.xen xeno-today/tools/pygrub/setup.py xeno-unstable.0524/tools/pygrub/setup.py
--- xeno-today/tools/pygrub/setup.py 2005-05-26 06:31:45.000000000 +0900
+++ xeno-unstable.0524/tools/pygrub/setup.py 2005-05-26 05:59:12.000000000 +0900
@@ -3,14 +3,27 @@ import os
extra_compile_args = [ "-fno-strict-aliasing", "-Wall", "-Werror" ]
-# in a perfect world, we'd figure out the fsys modules dynamically
-ext2 = Extension("grub.fsys.ext2._pyext2",
- extra_compile_args = extra_compile_args,
- libraries = ["ext2fs"],
- sources = ["src/fsys/ext2/ext2module.c"])
+fsys_mods = []
+fsys_pkgs = []
+
+if os.path.exists("/usr/include/ext2fs/ext2_fs.h"):
+ ext2 = Extension("grub.fsys.ext2._pyext2",
+ extra_compile_args = extra_compile_args,
+ libraries = ["ext2fs"],
+ sources = ["src/fsys/ext2/ext2module.c"])
+ fsys_mods.append(ext2)
+ fsys_pkgs.append("grub.fsys.ext2")
+
+if os.path.exists("/usr/include/reiserfs/reiserfs.h"):
+ reiser = Extension("grub.fsys.reiser._pyreiser",
+ extra_compile_args = extra_compile_args,
+ libraries = ["reiserfs"],
+ sources = ["src/fsys/reiser/reisermodule.c"])
+ fsys_mods.append(reiser)
+ fsys_pkgs.append("grub.fsys.reiser")
setup(name='pygrub',
- version='0.1',
+ version='0.2',
description='Boot loader that looks a lot like grub for Xen',
author='Jeremy Katz',
author_email='katzj@redhat.com',
@@ -18,8 +31,7 @@ setup(name='pygrub',
package_dir={'grub': 'src'},
scripts = ["src/pygrub"],
packages=['grub',
- 'grub.fsys',
- 'grub.fsys.ext2'],
- ext_modules = [ext2]
+ 'grub.fsys'].extend(fsys_pkgs),
+ ext_modules = fsys_mods
)
diff -Nurp -X dontdiff.xen xeno-today/tools/pygrub/src/fsys/reiser/__init__.py xeno-unstable.0524/tools/pygrub/src/fsys/reiser/__init__.py
--- xeno-today/tools/pygrub/src/fsys/reiser/__init__.py 1970-01-01 09:00:00.000000000 +0900
+++ xeno-unstable.0524/tools/pygrub/src/fsys/reiser/__init__.py 2005-05-26 05:41:06.000000000 +0900
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+from grub.fsys import register_fstype, FileSystemType
+from _pyreiser import *
+
+import os
+
+FSMAGIC2 = 'ReIsEr2'
+FSMAGIC3 = 'ReIsEr3'
+
+class ReiserFileSystemType(FileSystemType):
+ def __init__(self):
+ FileSystemType.__init__(self)
+ self.name = "reiser"
+
+ def sniff_magic(self, fn, offset = 0):
+ fd = os.open(fn, os.O_RDONLY)
+ os.lseek(fd, 0x10000, 0)
+ buf = os.read(fd, 0x40)
+ if len(buf) == 0x40 and (buf[0x34:0x3B] in [FSMAGIC2, FSMAGIC3]) :
+ return True
+ return False
+
+ def open_fs(self, fn, offset = 0):
+ if not self.sniff_magic(fn, offset):
+ raise ValueError, "Not a reiserfs filesystem"
+ return ReiserFs(fn)
+
+register_fstype(ReiserFileSystemType())
+
diff -Nurp -X dontdiff.xen xeno-today/tools/pygrub/src/fsys/reiser/reisermodule.c xeno-unstable.0524/tools/pygrub/src/fsys/reiser/reisermodule.c
--- xeno-today/tools/pygrub/src/fsys/reiser/reisermodule.c 1970-01-01 09:00:00.000000000 +0900
+++ xeno-unstable.0524/tools/pygrub/src/fsys/reiser/reisermodule.c 2005-05-26 05:41:06.000000000 +0900
@@ -0,0 +1,345 @@
+/*
+ * reisermodule.c - simple python binding for libreiserfs{2,3}
+ *
+ * Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * general public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <Python.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <dal/file_dal.h>
+#include <reiserfs/reiserfs.h>
+
+#if (PYTHON_API_VERSION >= 1011)
+#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
+#else
+#define PY_PAD 0L,0L,0L,0L
+#endif
+
+
+/* global error object */
+PyObject *ReiserError;
+
+typedef struct {
+ PyObject_HEAD
+ reiserfs_fs_t *fs;
+ dal_t *dal;
+} ReiserFs;
+
+typedef struct _ReiserFile ReiserFile;
+struct _ReiserFile {
+ PyObject_HEAD
+ reiserfs_file_t *file;
+};
+
+void file_dal_close(dal_t *dal) {
+
+ if (!dal) return;
+
+ close((int)dal->dev);
+ dal_free(dal);
+}
+
+/* reiser file object */
+
+static PyObject *
+reiser_file_close (ReiserFile *file, PyObject *args)
+{
+ if (file->file != NULL)
+ {
+ reiserfs_file_close(file->file);
+ file->file = NULL;
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+reiser_file_read (ReiserFile *file, PyObject *args)
+{
+ int size = 0;
+ size_t n, total = 0;
+ PyObject * buffer = NULL;
+
+ if (file->file == NULL) {
+ PyErr_SetString(PyExc_ValueError, "Cannot read from closed file");
+ return NULL;
+ }
+
+ if (!PyArg_ParseTuple(args, "|i", &size))
+ return NULL;
+
+ buffer = PyString_FromStringAndSize((char *) NULL, (size) ? size : 4096);
+ if (buffer == NULL)
+ return buffer;
+
+ while (1) {
+ n = reiserfs_file_read(file->file, PyString_AS_STRING(buffer) + total,
+ (size) ? size : 4096);
+ if (n == 0)
+ break;
+
+ total += n;
+
+ if (size && size == total)
+ break;
+
+ if (!size) {
+ _PyString_Resize(&buffer, total + 4096);
+ }
+ }
+
+ _PyString_Resize(&buffer, total);
+ return buffer;
+}
+
+static void
+reiser_file_dealloc (ReiserFile * file)
+{
+ if (file->file != NULL) {
+ reiserfs_file_close(file->file);
+ file->file = NULL;
+ }
+ PyObject_DEL(file);
+}
+
+static struct PyMethodDef ReiserFileMethods[] = {
+ { "close", (PyCFunction) reiser_file_close, METH_VARARGS, NULL },
+ { "read", (PyCFunction) reiser_file_read, METH_VARARGS, NULL },
+ { NULL, NULL, 0, NULL }
+};
+
+static PyObject *
+reiser_file_getattr (ReiserFile * file, char * name)
+{
+ return Py_FindMethod (ReiserFileMethods, (PyObject *) file, name);
+}
+
+static char ReiserFileType__doc__[] = "This is the reiser filesystem object";
+PyTypeObject ReiserFileType = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "ReiserFile", /* tp_name */
+ sizeof(ReiserFile), /* tp_size */
+ 0, /* tp_itemsize */
+ (destructor) reiser_file_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ (getattrfunc) reiser_file_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ ReiserFileType__doc__,
+ PY_PAD
+};
+
+static PyObject *
+reiser_file_open (ReiserFs *fs, char *name, int flags)
+{
+ ReiserFile *file;
+ reiserfs_file_t *f;
+
+ file = (ReiserFile *) PyObject_NEW(ReiserFile, &ReiserFileType);
+
+ f = reiserfs_file_open(fs->fs, name, flags);
+ file->file = f;
+
+ if (!f) {
+ PyErr_SetString(PyExc_ValueError, "unable to open file");
+ return NULL;
+ }
+
+ return (PyObject *) file;
+}
+
+static PyObject *
+reiser_file_exist (ReiserFs *fs, char *name)
+{
+ reiserfs_file_t *f;
+
+ f = reiserfs_file_open(fs->fs, name, O_RDONLY);
+
+ if (!f) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ reiserfs_file_close(f);
+ Py_INCREF(Py_True);
+ return Py_True;
+}
+
+/* reiserfs object */
+
+static PyObject *
+reiser_fs_close (ReiserFs *fs, PyObject *args)
+{
+ if (fs->fs != NULL)
+ {
+ reiserfs_fs_close(fs->fs);
+ file_dal_close(fs->dal);
+ fs->fs = NULL;
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+reiser_fs_open (ReiserFs *fs, PyObject *args)
+{
+ char *name;
+ size_t block_size = DEFAULT_BLOCK_SIZE;
+ dal_t *dal;
+ reiserfs_fs_t *rfs;
+
+ if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
+ return NULL;
+
+ if (fs->fs != NULL) {
+ PyErr_SetString(PyExc_ValueError, "already have an fs object");
+ return NULL;
+ }
+
+ if (!(dal = file_dal_open(name, block_size, O_RDONLY))) {
+ PyErr_SetString(PyExc_ValueError, "Couldn't create device abstraction");
+ return NULL;
+ }
+
+ if (!(rfs = reiserfs_fs_open_fast(dal, dal))) {
+ file_dal_close(dal);
+ PyErr_SetString(PyExc_ValueError, "unable to open file");
+ return NULL;
+ }
+
+ fs->fs = rfs;
+ fs->dal = dal;
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+reiser_fs_open_file (ReiserFs *fs, PyObject *args)
+{
+ char *name;
+ int flags = 0;
+
+ if (!PyArg_ParseTuple(args, "s|i", &name, &flags))
+ return NULL;
+
+ return reiser_file_open(fs, name, flags);
+}
+
+static PyObject *
+reiser_fs_file_exist (ReiserFs *fs, PyObject *args)
+{
+ char * name;
+
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+ return reiser_file_exist(fs, name);
+}
+
+static void
+reiser_fs_dealloc (ReiserFs * fs)
+{
+ if (fs->fs != NULL)
+ {
+ reiserfs_fs_close(fs->fs);
+ file_dal_close(fs->dal);
+ fs->fs = NULL;
+ }
+ PyObject_DEL(fs);
+}
+
+static struct PyMethodDef ReiserFsMethods[] = {
+ { "close", (PyCFunction) reiser_fs_close, METH_VARARGS, NULL },
+ { "open", (PyCFunction) reiser_fs_open, METH_VARARGS, NULL },
+ { "open_file", (PyCFunction) reiser_fs_open_file, METH_VARARGS, NULL },
+ { "file_exist", (PyCFunction) reiser_fs_file_exist, METH_VARARGS, NULL },
+ { NULL, NULL, 0, NULL }
+};
+
+static PyObject *
+reiser_fs_getattr (ReiserFs * fs, char * name)
+{
+ return Py_FindMethod (ReiserFsMethods, (PyObject *) fs, name);
+}
+
+static char ReiserFsType__doc__[] = "This is the reiser filesystem object";
+
+PyTypeObject ReiserFsType = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "ReiserFs", /* tp_name */
+ sizeof(ReiserFs), /* tp_size */
+ 0, /* tp_itemsize */
+ (destructor) reiser_fs_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ (getattrfunc) reiser_fs_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ ReiserFsType__doc__,
+ PY_PAD
+};
+
+static PyObject *
+reiser_fs_new(PyObject *o, PyObject *args)
+{
+ char *name;
+ size_t block_size = DEFAULT_BLOCK_SIZE;
+ ReiserFs *pfs;
+
+ if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
+ return NULL;
+
+ pfs = (ReiserFs *) PyObject_NEW(ReiserFs, &ReiserFsType);
+ if (pfs == NULL)
+ return NULL;
+
+ pfs->fs = NULL;
+
+ if (!reiser_fs_open(pfs, Py_BuildValue("si", name, block_size)))
+ return NULL;
+
+ return (PyObject *)pfs;
+}
+
+static struct PyMethodDef ReiserModuleMethods[] = {
+ { "ReiserFs", (PyCFunction) reiser_fs_new, METH_VARARGS},
+ { NULL, NULL, 0}
+};
+
+void init_pyreiser(void) {
+ Py_InitModule("_pyreiser", ReiserModuleMethods);
+}
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PATCH] reiserfs module for pygrub
@ 2005-05-24 0:14 Ian Pratt
2005-05-24 3:17 ` Jeremy Katz
0 siblings, 1 reply; 16+ messages in thread
From: Ian Pratt @ 2005-05-24 0:14 UTC (permalink / raw)
To: Jeremy Katz; +Cc: xen-devel
> What if we check instead for the headers being present and
> only building the filesystem modules that there's support for
> on the system? Then distributors can ensure they have the
> right things in their buildsystem and anyone else can do the
> same. The attached patch should implement that for libext2fs.
Seems a sensible approach to me. Some people will no doubt hate the fact
that the output will depend on the build host. Perhaps have an
environment variable that can be set to overide the autodetect? (and
hence cause a build failure)
> > Also, at runtime, are there
> > issues with libraries being present? Can you load the library
> > dynamically if required?
>
> The libraries get linked dynamically into the python module.
> If at runtime, the library isn't present, it won't cause a
> fatal error (you won't be able to access those types of
> filesystems, but it won't fall over on the import)
Given that the libext2fs is 90KB, I wander if we should just staticaly
link? Not sure.
Ian
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PATCH] reiserfs module for pygrub
2005-05-24 0:14 Ian Pratt
@ 2005-05-24 3:17 ` Jeremy Katz
0 siblings, 0 replies; 16+ messages in thread
From: Jeremy Katz @ 2005-05-24 3:17 UTC (permalink / raw)
To: Ian Pratt; +Cc: xen-devel
On Tue, 2005-05-24 at 01:14 +0100, Ian Pratt wrote:
> > What if we check instead for the headers being present and
> > only building the filesystem modules that there's support for
> > on the system? Then distributors can ensure they have the
> > right things in their buildsystem and anyone else can do the
> > same. The attached patch should implement that for libext2fs.
>
> Seems a sensible approach to me. Some people will no doubt hate the fact
> that the output will depend on the build host. Perhaps have an
> environment variable that can be set to overide the autodetect? (and
> hence cause a build failure)
I guess it's easy enough to do something like this. I wish distutils
had a standardized way of doing things like this similar to autoconf
(... and this even with how much I hate autoconf ;-)
> > > Also, at runtime, are there
> > > issues with libraries being present? Can you load the library
> > > dynamically if required?
> >
> > The libraries get linked dynamically into the python module.
> > If at runtime, the library isn't present, it won't cause a
> > fatal error (you won't be able to access those types of
> > filesystems, but it won't fall over on the import)
>
> Given that the libext2fs is 90KB, I wander if we should just staticaly
> link? Not sure.
I'm not sure there's a way to do static linking in distutils without
completely reinventing the wheel. When you start thinking about lib vs
lib64 differences, this is less than fun.
Jeremy
^ permalink raw reply [flat|nested] 16+ messages in thread
* RE: [PATCH] reiserfs module for pygrub
@ 2005-05-19 1:32 Ian Pratt
2005-05-19 2:43 ` aq
0 siblings, 1 reply; 16+ messages in thread
From: Ian Pratt @ 2005-05-19 1:32 UTC (permalink / raw)
To: aq; +Cc: Jeremy Katz, xen-devel
> > Please can you add something to the tools/check directory
> that checks
> > the appropriate headers are installed.
>
> yes, that is easy.
>
> >Also, at runtime, are there
> > issues with libraries being present?
>
> what kind of issues do you want to mention?
Well, what happens if you build the tools on a box that does have the
reiserfs header files and shared libraries, but then try running them on
a box without.
The desired behaviour would be that the tools work fine until you try to
access a reiserfs partition, whereupon they report an error gracefully.
Undesirable behaviour would be refusing to run at all, or crashing if
presented with a resierfs patition.
> >Can you load the library
> > dynamically if required?
> >
>
> i dont understand why you want to load libs "dynamically"?
To be able to work without the reiserfs present we may need to load it
dynamically. (same for ext3, but that's more widely installed).
Best,
Ian
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH] reiserfs module for pygrub
2005-05-19 1:32 Ian Pratt
@ 2005-05-19 2:43 ` aq
0 siblings, 0 replies; 16+ messages in thread
From: aq @ 2005-05-19 2:43 UTC (permalink / raw)
To: Ian Pratt; +Cc: Jeremy Katz, xen-devel
On 5/19/05, Ian Pratt <m+Ian.Pratt@cl.cam.ac.uk> wrote:
> > > Please can you add something to the tools/check directory
> > that checks
> > > the appropriate headers are installed.
> >
> > yes, that is easy.
> >
> > >Also, at runtime, are there
> > > issues with libraries being present?
> >
> > what kind of issues do you want to mention?
>
> Well, what happens if you build the tools on a box that does have the
> reiserfs header files and shared libraries, but then try running them on
> a box without.
>
> The desired behaviour would be that the tools work fine until you try to
> access a reiserfs partition, whereupon they report an error gracefully.
>
> Undesirable behaviour would be refusing to run at all, or crashing if
> presented with a resierfs patition.
>
> > >Can you load the library
> > > dynamically if required?
> > >
> >
> > i dont understand why you want to load libs "dynamically"?
>
> To be able to work without the reiserfs present we may need to load it
> dynamically. (same for ext3, but that's more widely installed).
i see the point. this should be in TODO list, and solve later.
regards,
aq
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH] reiserfs module for pygrub
@ 2005-05-18 18:46 aq
2005-05-23 23:57 ` Jeremy Katz
0 siblings, 1 reply; 16+ messages in thread
From: aq @ 2005-05-18 18:46 UTC (permalink / raw)
To: xen-devel, Jeremy Katz
[-- Attachment #1: Type: text/plain, Size: 755 bytes --]
hello,
here is a patch to add reiserfs (version 2,3) support to pygrub in
-unstable (against cset 1.1434)
list of changes:
- update tools/pygrub/README about packages needed to compile pygrub
- tools/pygrub/setup.py to support reiserfs module
- toolspygrub/src/fsys/reiserfs/ directory with 2 files __init__.py
and reisermodule.c to provide reiserfs support to pygrub.
Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com>
$ diffstat reiser_pygrub.patch
README | 16 +
setup.py | 10 -
src/fsys/reiser/__init__.py | 39 ++++
src/fsys/reiser/reisermodule.c | 345 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 407 insertions(+), 3 deletions(-)
--
regards,
aq
[-- Attachment #2: reiser_pygrub.patch --]
[-- Type: application/octet-stream, Size: 11780 bytes --]
===== tools/pygrub/README 1.1 vs edited =====
--- 1.1/tools/pygrub/README 2005-04-28 22:02:36 +09:00
+++ edited/tools/pygrub/README 2005-05-18 01:47:41 +09:00
@@ -1 +1,15 @@
-Compiling this needs RPM e2fsprogs-devel installed.
\ No newline at end of file
+pygrub is a grub-like bootloader for xen. This tool is to use to boot domU images.
+
+To compile pygrub, you will need the following packages installed:
+
+1) Libraries of ext2fs, which is the following package (depend on your Linux distribution):
+ - e2fslibs-dev on Debian based distributions (Debian, Ubuntu, Linspire, Libranet, Xandros, etc...)
+ - e2fsprogs-devel on RedHat, Fedora Core
+ - libext2fs2-devel on Mandriva/Mandrake
+ - e2fsprogs on Gentoo
+
+2) Libraries of reiserfs, which is the following package (depend on your Linux distribution):
+ - libreiserfs-dev on Debian based distributions (Debian, Ubuntu, Xandros, Libranet, Xandros, etc...)
+ - progsreiserfs-devel on RedHat, Fedora Core
+ - progreiserfs on Gentoo
+
===== tools/pygrub/setup.py 1.2 vs edited =====
--- 1.2/tools/pygrub/setup.py 2005-04-28 21:27:46 +09:00
+++ edited/tools/pygrub/setup.py 2005-05-18 01:47:41 +09:00
@@ -9,6 +9,11 @@ ext2 = Extension("grub.fsys.ext2._pyext2
libraries = ["ext2fs"],
sources = ["src/fsys/ext2/ext2module.c"])
+reiser = Extension("grub.fsys.reiser._pyreiser",
+ extra_compile_args = extra_compile_args,
+ libraries = ["reiserfs"],
+ sources = ["src/fsys/reiser/reisermodule.c"])
+
setup(name='pygrub',
version='0.1',
description='Boot loader that looks a lot like grub for Xen',
@@ -19,7 +24,8 @@ setup(name='pygrub',
scripts = ["src/pygrub"],
packages=['grub',
'grub.fsys',
- 'grub.fsys.ext2'],
- ext_modules = [ext2]
+ 'grub.fsys.ext2',
+ 'grub.fsys.reiser'],
+ ext_modules = [ext2, reiser]
)
===== tools/pygrub/src/fsys/reiser/__init__.py 1.1 vs edited =====
--- 1.1/tools/pygrub/src/fsys/reiser/__init__.py 2005-05-18 01:55:14 +09:00
+++ edited/tools/pygrub/src/fsys/reiser/__init__.py 2005-05-18 01:57:44 +09:00
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+from grub.fsys import register_fstype, FileSystemType
+from _pyreiser import *
+
+import os
+
+FSMAGIC2 = 'ReIsEr2'
+FSMAGIC3 = 'ReIsEr3'
+
+class ReiserFileSystemType(FileSystemType):
+ def __init__(self):
+ FileSystemType.__init__(self)
+ self.name = "reiser"
+
+ def sniff_magic(self, fn, offset = 0):
+ fd = os.open(fn, os.O_RDONLY)
+ os.lseek(fd, 0x10000, 0)
+ buf = os.read(fd, 0x40)
+ if len(buf) == 0x40 and (buf[0x34:0x3B] in [FSMAGIC2, FSMAGIC3]) :
+ return True
+ return False
+
+ def open_fs(self, fn, offset = 0):
+ if not self.sniff_magic(fn, offset):
+ raise ValueError, "Not an reiserfs filesystem"
+ return ReiserFs(fn)
+
+register_fstype(ReiserFileSystemType())
+
===== tools/pygrub/src/fsys/reiser/reisermodule.c 1.1 vs edited =====
--- 1.1/tools/pygrub/src/fsys/reiser/reisermodule.c 2005-05-18 01:55:14 +09:00
+++ edited/tools/pygrub/src/fsys/reiser/reisermodule.c 2005-05-18 01:57:53 +09:00
@@ -0,0 +1,345 @@
+/*
+ * reisermodule.c - simple python binding for libreiserfs{2,3}
+ *
+ * Copyright (C) 2005 Nguyen Anh Quynh <aquynh@gmail.com>
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * general public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <Python.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <dal/file_dal.h>
+#include <reiserfs/reiserfs.h>
+
+#if (PYTHON_API_VERSION >= 1011)
+#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
+#else
+#define PY_PAD 0L,0L,0L,0L
+#endif
+
+
+/* global error object */
+PyObject *ReiserError;
+
+typedef struct {
+ PyObject_HEAD
+ reiserfs_fs_t *fs;
+ dal_t *dal;
+} ReiserFs;
+
+typedef struct _ReiserFile ReiserFile;
+struct _ReiserFile {
+ PyObject_HEAD
+ reiserfs_file_t *file;
+};
+
+void file_dal_close(dal_t *dal) {
+
+ if (!dal) return;
+
+ close((int)dal->dev);
+ dal_free(dal);
+}
+
+/* reiser file object */
+
+static PyObject *
+reiser_file_close (ReiserFile *file, PyObject *args)
+{
+ if (file->file != NULL)
+ {
+ reiserfs_file_close(file->file);
+ file->file = NULL;
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+reiser_file_read (ReiserFile *file, PyObject *args)
+{
+ int size = 0;
+ size_t n, total = 0;
+ PyObject * buffer = NULL;
+
+ if (file->file == NULL) {
+ PyErr_SetString(PyExc_ValueError, "Cannot read from closed file");
+ return NULL;
+ }
+
+ if (!PyArg_ParseTuple(args, "|i", &size))
+ return NULL;
+
+ buffer = PyString_FromStringAndSize((char *) NULL, (size) ? size : 4096);
+ if (buffer == NULL)
+ return buffer;
+
+ while (1) {
+ n = reiserfs_file_read(file->file, PyString_AS_STRING(buffer) + total,
+ (size) ? size : 4096);
+ if (n == 0)
+ break;
+
+ total += n;
+
+ if (size && size == total)
+ break;
+
+ if (!size) {
+ _PyString_Resize(&buffer, total + 4096);
+ }
+ }
+
+ _PyString_Resize(&buffer, total);
+ return buffer;
+}
+
+static void
+reiser_file_dealloc (ReiserFile * file)
+{
+ if (file->file != NULL) {
+ reiserfs_file_close(file->file);
+ file->file = NULL;
+ }
+ PyObject_DEL(file);
+}
+
+static struct PyMethodDef ReiserFileMethods[] = {
+ { "close", (PyCFunction) reiser_file_close, METH_VARARGS, NULL },
+ { "read", (PyCFunction) reiser_file_read, METH_VARARGS, NULL },
+ { NULL, NULL, 0, NULL }
+};
+
+static PyObject *
+reiser_file_getattr (ReiserFile * file, char * name)
+{
+ return Py_FindMethod (ReiserFileMethods, (PyObject *) file, name);
+}
+
+static char ReiserFileType__doc__[] = "This is the reiser filesystem object";
+PyTypeObject ReiserFileType = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "ReiserFile", /* tp_name */
+ sizeof(ReiserFile), /* tp_size */
+ 0, /* tp_itemsize */
+ (destructor) reiser_file_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ (getattrfunc) reiser_file_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ ReiserFileType__doc__,
+ PY_PAD
+};
+
+static PyObject *
+reiser_file_open (ReiserFs *fs, char *name, int flags)
+{
+ ReiserFile *file;
+ reiserfs_file_t *f;
+
+ file = (ReiserFile *) PyObject_NEW(ReiserFile, &ReiserFileType);
+
+ f = reiserfs_file_open(fs->fs, name, flags);
+ file->file = f;
+
+ if (!f) {
+ PyErr_SetString(PyExc_ValueError, "unable to open file");
+ return NULL;
+ }
+
+ return (PyObject *) file;
+}
+
+static PyObject *
+reiser_file_exist (ReiserFs *fs, char *name)
+{
+ reiserfs_file_t *f;
+
+ f = reiserfs_file_open(fs->fs, name, O_RDONLY);
+
+ if (!f) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ reiserfs_file_close(f);
+ Py_INCREF(Py_True);
+ return Py_True;
+}
+
+/* reiserfs object */
+
+static PyObject *
+reiser_fs_close (ReiserFs *fs, PyObject *args)
+{
+ if (fs->fs != NULL)
+ {
+ reiserfs_fs_close(fs->fs);
+ file_dal_close(fs->dal);
+ fs->fs = NULL;
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+reiser_fs_open (ReiserFs *fs, PyObject *args)
+{
+ char *name;
+ size_t block_size = DEFAULT_BLOCK_SIZE;
+ dal_t *dal;
+ reiserfs_fs_t *rfs;
+
+ if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
+ return NULL;
+
+ if (fs->fs != NULL) {
+ PyErr_SetString(PyExc_ValueError, "already have an fs object");
+ return NULL;
+ }
+
+ if (!(dal = file_dal_open(name, block_size, O_RDONLY))) {
+ PyErr_SetString(PyExc_ValueError, "Couldn't create device abstraction");
+ return NULL;
+ }
+
+ if (!(rfs = reiserfs_fs_open_fast(dal, dal))) {
+ file_dal_close(dal);
+ PyErr_SetString(PyExc_ValueError, "unable to open file");
+ return NULL;
+ }
+
+ fs->fs = rfs;
+ fs->dal = dal;
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+reiser_fs_open_file (ReiserFs *fs, PyObject *args)
+{
+ char *name;
+ int flags = 0;
+
+ if (!PyArg_ParseTuple(args, "s|i", &name, &flags))
+ return NULL;
+
+ return reiser_file_open(fs, name, flags);
+}
+
+static PyObject *
+reiser_fs_file_exist (ReiserFs *fs, PyObject *args)
+{
+ char * name;
+
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+ return reiser_file_exist(fs, name);
+}
+
+static void
+reiser_fs_dealloc (ReiserFs * fs)
+{
+ if (fs->fs != NULL)
+ {
+ reiserfs_fs_close(fs->fs);
+ file_dal_close(fs->dal);
+ fs->fs = NULL;
+ }
+ PyObject_DEL(fs);
+}
+
+static struct PyMethodDef ReiserFsMethods[] = {
+ { "close", (PyCFunction) reiser_fs_close, METH_VARARGS, NULL },
+ { "open", (PyCFunction) reiser_fs_open, METH_VARARGS, NULL },
+ { "open_file", (PyCFunction) reiser_fs_open_file, METH_VARARGS, NULL },
+ { "file_exist", (PyCFunction) reiser_fs_file_exist, METH_VARARGS, NULL },
+ { NULL, NULL, 0, NULL }
+};
+
+static PyObject *
+reiser_fs_getattr (ReiserFs * fs, char * name)
+{
+ return Py_FindMethod (ReiserFsMethods, (PyObject *) fs, name);
+}
+
+static char ReiserFsType__doc__[] = "This is the reiser filesystem object";
+
+PyTypeObject ReiserFsType = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /* ob_size */
+ "ReiserFs", /* tp_name */
+ sizeof(ReiserFs), /* tp_size */
+ 0, /* tp_itemsize */
+ (destructor) reiser_fs_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ (getattrfunc) reiser_fs_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ ReiserFsType__doc__,
+ PY_PAD
+};
+
+static PyObject *
+reiser_fs_new(PyObject *o, PyObject *args)
+{
+ char *name;
+ size_t block_size = DEFAULT_BLOCK_SIZE;
+ ReiserFs *pfs;
+
+ if (!PyArg_ParseTuple(args, "s|i", &name, &block_size))
+ return NULL;
+
+ pfs = (ReiserFs *) PyObject_NEW(ReiserFs, &ReiserFsType);
+ if (pfs == NULL)
+ return NULL;
+
+ pfs->fs = NULL;
+
+ if (!reiser_fs_open(pfs, Py_BuildValue("si", name, block_size)))
+ return NULL;
+
+ return (PyObject *)pfs;
+}
+
+static struct PyMethodDef ReiserModuleMethods[] = {
+ { "ReiserFs", (PyCFunction) reiser_fs_new, METH_VARARGS},
+ { NULL, NULL, 0}
+};
+
+void init_pyreiser(void) {
+ Py_InitModule("_pyreiser", ReiserModuleMethods);
+}
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH] reiserfs module for pygrub
2005-05-18 18:46 aq
@ 2005-05-23 23:57 ` Jeremy Katz
0 siblings, 0 replies; 16+ messages in thread
From: Jeremy Katz @ 2005-05-23 23:57 UTC (permalink / raw)
To: aq; +Cc: xen-devel
(As I catch up on mail... sorry about the lag)
On Thu, 2005-05-19 at 03:46 +0900, aq wrote:
> here is a patch to add reiserfs (version 2,3) support to pygrub in
> -unstable (against cset 1.1434)
This looks good to me in general. I agree with Ian that we probably
want to detect at build-time which filesystem libraries are available
instead of requiring everyone building to install everything. See the
patch that I have sitting ready to hit send on for how makes sense to me
for libext2fs. Doing the same for reiserfs should be fairly trivial.
Jeremy
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2005-05-25 21:57 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-18 19:37 [PATCH] reiserfs module for pygrub Ian Pratt
2005-05-19 1:15 ` aq
2005-05-23 23:57 ` Jeremy Katz
2005-05-24 1:04 ` aq
-- strict thread matches above, loose matches on Subject: below --
2005-05-24 1:27 Ian Pratt
2005-05-24 3:17 ` Jeremy Katz
2005-05-24 4:09 ` aq
2005-05-24 4:15 ` aq
2005-05-24 19:34 ` Jeremy Katz
2005-05-25 21:57 ` aq
2005-05-24 0:14 Ian Pratt
2005-05-24 3:17 ` Jeremy Katz
2005-05-19 1:32 Ian Pratt
2005-05-19 2:43 ` aq
2005-05-18 18:46 aq
2005-05-23 23:57 ` Jeremy Katz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.