bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] ped_device_from_store


From: Neal H Walfield
Subject: [patch] ped_device_from_store
Date: Tue, 14 Aug 2001 10:57:25 +0200
User-agent: Mutt/1.3.18i

This patch adds a new function, ped_device_from_store, to libparted.
This is useful only on GNU/Hurd and where an application would like to
use libparted.  The function has the following prototype:

        PedDevice *ped_device_from_store (struct store *source,
                                          int consume)

This function creates a PedDevice from SOURCE with a single reference;
the PedDevice is not registered in parted's list of available devices.
If CONSUME is true, SOURCE will be destoryed when the reference count of
the PedDevice drops to zero.

The change log:

2001-08-14  Neal H Walfield  <address@hidden>

        * parted/device_gnu.h (_GNUSpecific): New field, CONSUME.
        (ped_device_from_store): Prototype it.
        * libparted/device_gnu.c (_arch_device_new): Move funtion's guts
        from here . . .
        (init_PedDevice): . . . to here.
        (_arch_device_new): Call init_PedDevice.
        (ped_device_from_store): New function.
        (_arch_device_destory): Only free the store if
        ARCH_SPECIFIC->consume is true.


diff --exclude aclocal.m4 --exclude configure --exclude Makefile.in -urNp 
parted-1.5.4-pre1.orig/include/parted/device_gnu.h 
parted-1.5.4-pre1/include/parted/device_gnu.h
--- parted-1.5.4-pre1.orig/include/parted/device_gnu.h  Sun Jul 29 02:38:43 2001
+++ parted-1.5.4-pre1/include/parted/device_gnu.h       Mon Aug 13 17:51:00 2001
@@ -28,7 +28,14 @@ typedef      struct _GNUSpecific     GNUSpecific;
 
 struct _GNUSpecific {
        struct store*   store;
+       int consume;
 };
+
+/* Initialize a PedDevice using SOURCE.  The device has an
+   open count of one, it is not registered with Parted's list of devices
+   and, if CONSUME is true, is destoryed when its reference count drops
+   to zero.  */
+PedDevice* ped_device_from_store (struct store *source, int consume);
 
 #endif /* PED_DEVICE_GNU_H_INCLUDED */
 
diff --exclude aclocal.m4 --exclude configure --exclude Makefile.in -urNp 
parted-1.5.4-pre1.orig/libparted/device_gnu.c 
parted-1.5.4-pre1/libparted/device_gnu.c
--- parted-1.5.4-pre1.orig/libparted/device_gnu.c       Sun Aug 12 05:35:23 2001
+++ parted-1.5.4-pre1/libparted/device_gnu.c    Tue Aug 14 09:41:33 2001
@@ -135,13 +135,11 @@ error:
        return 0;
 }
 
-PedDevice*
-_arch_device_new (const char* path)
+static PedDevice*
+init_PedDevice (const char *path)
 {
        PedDevice*      dev;
 
-       PED_ASSERT (path != NULL, return NULL);
-
        dev = (PedDevice*) ped_malloc (sizeof (PedDevice));
        if (!dev)
                goto error;
@@ -164,9 +162,6 @@ _arch_device_new (const char* path)
        dev->geom_known = 1;
        dev->geom_already_guessed = 0;
 
-       if (!init_file (dev))
-               goto error_free_dev;
-
        return dev;
 
 error_free_arch_specific:
@@ -179,6 +174,57 @@ error:
        return NULL;
 }
 
+PedDevice*
+_arch_device_new (const char* path)
+{
+       PedDevice*      dev;
+       GNUSpecific*    arch_specific;
+
+       PED_ASSERT (path != NULL, return NULL);
+
+       dev = init_PedDevice (path);
+       if (! dev)
+               return NULL;
+
+       if (!init_file (dev)) {
+               ped_free (dev);
+               return NULL;
+       }
+
+       arch_specific = GNU_SPECIFIC (dev);
+       arch_specific->consume = 1;
+
+       return dev;
+}
+
+PedDevice*
+ped_device_from_store (struct store *source, int consume)
+{
+       PedDevice*      dev;
+       GNUSpecific*    arch_specific;
+
+       PED_ASSERT (source != NULL, return NULL);
+
+       dev = init_PedDevice (source->name ?: "(unknown)");
+       if (!dev)
+               return NULL;
+
+       arch_specific = GNU_SPECIFIC (dev);
+       arch_specific->store = source;
+       arch_specific->consume = consume;
+
+       dev->read_only = source->flags & (STORE_READONLY|STORE_HARD_READONLY);
+
+       dev->open_count = 1;
+
+       if (!init_file (dev)) {
+               ped_free (dev);
+               return NULL;
+       }
+
+       return dev;
+}
+
 void
 _arch_device_destroy (PedDevice* dev)
 {
@@ -265,7 +310,8 @@ _arch_device_close (PedDevice* dev)
                        dev->dirty = 0;
        }
 
-       store_free (arch_specific->store);
+       if (arch_specific->consume)
+               store_free (arch_specific->store);
 
        if (dev->dirty && dev->boot_dirty && dev->type != PED_DEVICE_FILE) {
                /* ouch! */

Attachment: pgp2XFdXSWJQU.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]