bug-parted
[Top][All Lists]
Advanced

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

libparted gnu.c patch.


From: Harley D. Eades III
Subject: libparted gnu.c patch.
Date: 16 Aug 2004 00:11:32 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Hello,
        I am working on an fdisk interface to libparted for GNU/Hurd.  
Also, I have been working on fixing problems related to libparted in GNU/Hurd.
With, some help from  Alfred M. Szmidt.  Here is a patch for libparted/gnu.c
which adds a test to determine if the user supplies a path such as /dev/hd2 or
a device type store such as devie:hd2. Please have a look and consider applying
it to libparted. Please feel free to ask any question. 

Thanks
hde

diff -ur libparted/gnu.c 
/home/hde/projects/PATCHED_parted-1.6.11/libparted/gnu.c
--- libparted/gnu.c     2004-04-24 22:34:00.000000000 -0500
+++ /home/hde/projects/PATCHED_parted-1.6.11/libparted/gnu.c    2004-08-15 
13:18:51.000000000 -0500
@@ -223,7 +223,8 @@
 {
        PedDevice*      dev;
        GNUSpecific*    arch_specific;
-       error_t err;
+       error_t         err;
+       error_t         rw_err;
 
        PED_ASSERT (path != NULL, return NULL);
 
@@ -234,43 +235,62 @@
        arch_specific = GNU_SPECIFIC (dev);
        arch_specific->consume = 1;
 
+       /* First we check if we can open the store read-write, if that fails
+          we try to open it read-only.  If all fails, bail out.  */
  retry_open:
-       err = store_typed_open (dev->path, 0, NULL, &arch_specific->store);
-       if (err) {
-               error_t rw_err = err;
+       dev->read_only = 0;
 
-               err = store_typed_open (dev->path, STORE_READONLY, NULL,
-                                       &arch_specific->store);
-               if (err) {
-                       if (ped_exception_throw (
-                               PED_EXCEPTION_ERROR,
-                               PED_EXCEPTION_RETRY_CANCEL,
-                               _("Error opening %s: %s"),
-                               dev->path, strerror (err))
-                                       != PED_EXCEPTION_RETRY) {
-                               return NULL;
-                       } else
-                               goto retry_open;
-               } else {
-                       ped_exception_throw (
-                               PED_EXCEPTION_WARNING,
-                               PED_EXCEPTION_OK,
-                               _("Unable to open %s read-write (%s).  %s has "
-                                 "been opened read-only."),
-                               dev->path, strerror (rw_err), dev->path);
-                       dev->read_only = 1;
-               }
+       /* Simple test to determine if the user uses a path or TYPE:NAME. */
+       if (strchr (path, '/') == NULL) { 
+
+         err = store_typed_open (dev->path, 0, NULL, &arch_specific->store); 
+         rw_err = err;
+         
+         if (err) { 
+           err = store_typed_open (dev->path, STORE_READONLY, NULL, 
&arch_specific->store);
+           dev->read_only = 1;
+         }
        } else {
-               dev->read_only = 0;
+         
+         err = store_open (dev->path, 0, NULL, &arch_specific->store);
+         rw_err = err;
+
+         if (err) {
+           err = store_open (dev->path, STORE_READONLY, NULL, 
&arch_specific->store);
+           dev->read_only = 1;
+         }
+       
+       }
+       if (err) {
+         /* Error out. */
+         if (ped_exception_throw (
+                                  PED_EXCEPTION_ERROR,
+                                  PED_EXCEPTION_RETRY_CANCEL,
+                                  _("Error opening %s: %s"),
+                                  dev->path, strerror (err))
+             != PED_EXCEPTION_RETRY) {
+           return NULL;
+         } else {
+           goto retry_open;
+           
+         }
+       }
+       if (dev->read_only == 1) {
+         ped_exception_throw (
+                              PED_EXCEPTION_WARNING,
+                              PED_EXCEPTION_OK,
+                              _("Unable to open %s read-write (%s).  %s has "
+                                "been opened read-only."),
+                              dev->path, strerror (rw_err), dev->path);
        }
 
        _flush_cache (dev);
-
+       
        if (!init_file (dev)) {
-               gnu_destroy(dev);
-               return NULL;
+         gnu_destroy(dev);
+         return NULL;
        }
-
+       
        return dev;
 }
 





reply via email to

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