[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
partition store
From: |
Neal H Walfield |
Subject: |
partition store |
Date: |
Sat, 25 Aug 2001 00:06:39 +0200 |
User-agent: |
Mutt/1.3.18i |
I have been working on a partition store type using libparted. The
implementation is very simply and I have attached it for inspection.
The problem that I am having, however, is with autoconf. I think I
currently support --with{,out}-libparted without a problem. It is,
however, how to add libparted and its dependencies to all of the make
files that use libstore. These libraries are detected in
PARTED_CHECK_LIBPARTED, which also does an AC_SUBST(PARTED_LIBS),
however, that does not really help us as we do not do substitutions on
our make files.
Anyway, here is what I have so far. Maybe you can offer a critique and
some suggestions.
Thanks.
Index: configure.in
===================================================================
RCS file: /cvs/hurd/configure.in,v
retrieving revision 1.20
diff -u -p -r1.20 configure.in
--- configure.in 2001/06/26 13:33:07 1.20
+++ configure.in 2001/08/24 21:26:08
@@ -68,6 +68,21 @@ AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) AC_S
AC_CHECK_LIB(crypt, crypt, LIBCRYPT=-lcrypt)
AC_SUBST(LIBCRYPT)
+# Check if the user wants libparted and whether it is installed
+AC_ARG_WITH(libparted,
+ [ --with-libparted add partition table support (requires
GNU/Parted)],
+ hurd_cv_use_libparted=$withval, hurd_cv_use_libparted=yes)
+
+if test x$hurd_cv_use_libparted = xyes; then
+ AC_CACHE_CHECK([for libparted], [hurd_cv_have_libparted],
+ [hurd_cv_have_libparted=no
+ AC_DEFINE([HAVE_LIBPARTED])],
+ [PARTED_CHECK_LIBPARTED(1.5.4,
+ hurd_cv_have_libparted=yes,
+ [AC_MSG_ERROR([libparted >= 1.5.4 not found; install GNU/Parted
available at http://www.gnu.org/software/parted/parted.html])])]
+ )
+fi
+
# See if --version-script is available.
AC_CACHE_CHECK(for ld --version-script, hurd_cv_ld_version_script_option, [dnl
cat > conftest.c <<\EOF
/* Partition store backend
Copyright (C) 2001 Free Software Foundation, Inc.
Written by Neal H Walfield <address@hidden>
This task is part of the GNU Hurd.
The GNU Hurd is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
The GNU Hurd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <cthreads.h>
#include <hurd/store.h>
#include <parted/parted.h>
#include <parted/device_gnu.h>
/* Return a new store in STORE which contains a remap store of partition
PART from the contents of SOURCE; SOURCE is consumed. */
error_t
store_part_create (struct store *source, int index, int flags,
struct store **store)
{
static struct mutex parted_lock = MUTEX_INITIALIZER;
error_t err = 0;
PedDevice *dev;
PedDisk *disk;
PedPartition *part;
struct store_run run;
if ((source->block_size < PED_SECTOR_SIZE
&& PED_SECTOR_SIZE % source->block_size != 0)
|| (source->block_size > PED_SECTOR_SIZE
&& source->block_size % PED_SECTOR_SIZE != 0))
return EINVAL;
mutex_lock (&parted_lock);
ped_exception_fetch_all ();
dev = ped_device_new_from_store (source);
if (! dev)
{
ped_exception_catch ();
err = EIO;
goto out;
}
assert (ped_device_open (dev) != 0);
disk = ped_disk_new (dev);
if (! disk)
{
ped_exception_catch ();
err = EIO;
goto out_with_dev;
}
for (part = ped_disk_next_partition (disk, NULL); part;
part = ped_disk_next_partition (disk, part))
{
if (part->type != PED_PARTITION_LOGICAL
&& part->type != 0 /* PED_PARTITION_PRIMARY */)
continue;
assert (part->num);
if (part->num == index)
break;
}
if (! part)
{
err = EIO;
goto out_with_disk;
}
if (source->block_size == PED_SECTOR_SIZE)
{
run.start = part->geom.start;
run.length = part->geom.length;
}
else if (source->block_size < PED_SECTOR_SIZE)
{
run.start = part->geom.start * (PED_SECTOR_SIZE / source->block_size);
run.length = part->geom.length * (PED_SECTOR_SIZE / source->block_size);
}
else
/* source->block_size > PED_SECTOR_SIZE */
{
run.start = part->geom.start * PED_SECTOR_SIZE;
if (run.start % source->block_size != 0)
err = EIO;
else
{
run.start /= source->block_size;
run.length = part->geom.length * PED_SECTOR_SIZE;
if (run.length % source->block_size != 0)
err = EIO;
else
run.length /= source->block_size;
}
}
out_with_disk:
assert (ped_device_close (dev) != 0);
assert (ped_disk_destroy (disk));
out_with_dev:
ped_device_destroy (dev);
out:
ped_exception_leave_all ();
mutex_unlock (&parted_lock);
if (! err)
err = store_remap (source, &run, 1, store);
return err;
}
/* Open the part NAME. NAME consists of a partition number, a ':', a another
store class name, a ':' and a name for to by passed to the store class.
E.g. "2:device:hd0" would open the second partition on a DEVICE store
named "hd0". FLAGS indicate how to open the store. CLASSES is used to
select classes specified by the type NAME; if it is 0, STORE_STD_CLASSES
is used. The new store is returned in *STORE. */
error_t
store_part_open (const char *name, int flags,
const struct store_class *const *classes,
struct store **store)
{
int part;
char *endp;
struct store *source;
error_t err;
part = strtol (name, &endp, 0);
if (endp == name || *endp != ':')
return EINVAL;
name = endp + 1;
if (*name == '\0')
return EINVAL;
err = store_typed_open (name, flags, classes, &source);
if (! err)
{
err = store_part_create (source, part, flags, store);
if (err)
store_free (source);
}
return err;
}
struct store_class
store_part_class = { -1, "part", open: store_part_open };
pgpWw4O2VYkX2.pgp
Description: PGP signature