[Parted-edge] [PATCH 4/4] Move PedArchitecture and ped_set_architecture to private

Otavio Salvador otavio at ossystems.com.br
Fri Nov 2 21:23:14 UTC 2007


From: Otavio Salvador <otavio at ossystems.com.br>

Code that works with libparted isn't suppose to need to change the
architecture where it's running and then doesn't make sense to export
it.

Two new files has been create (libparted/architecture.[hc]) that has
the PedArchitecture structure and the ped_set_architecture
implementation.  All changes that were need to get it suported on all
currently available architectures has been done too.
---

 include/parted/beos.h    |    2 --
 include/parted/gnu.h     |    2 --
 include/parted/linux.h   |    2 --
 include/parted/parted.h  |   14 --------------
 libparted/Makefile.am    |    1 +
 libparted/arch/beos.c    |    2 ++
 libparted/arch/gnu.c     |    2 ++
 libparted/arch/linux.c   |    1 +
 libparted/architecture.c |   32 ++++++++++++++++++++++++++++++++
 libparted/architecture.h |   38 ++++++++++++++++++++++++++++++++++++++
 libparted/device.c       |    2 ++
 libparted/disk.c         |    2 ++
 libparted/libparted.c    |   16 +++++-----------
 13 files changed, 85 insertions(+), 31 deletions(-)
 create mode 100644 libparted/architecture.c
 create mode 100644 libparted/architecture.h


diff --git a/include/parted/beos.h b/include/parted/beos.h
index cb329aa..b4d692c 100644
--- a/include/parted/beos.h
+++ b/include/parted/beos.h
@@ -30,7 +30,5 @@ struct _BEOSSpecific {
 	int	fd;
 };
 
-extern PedArchitecture ped_beos_arch;
-
 #endif /* PED_LINUX_H_INCLUDED */
 
diff --git a/include/parted/gnu.h b/include/parted/gnu.h
index e809fb7..a47b026 100644
--- a/include/parted/gnu.h
+++ b/include/parted/gnu.h
@@ -32,8 +32,6 @@ struct _GNUSpecific {
 	int consume;
 };
 
-extern PedArchitecture ped_gnu_arch;
-
 /* Initialize a PedDevice using SOURCE.  The SOURCE will NOT be destroyed;
    the caller created it, it is the caller's responsilbility to free it
    after it calls ped_device_destory.  SOURCE is not registered in Parted's
diff --git a/include/parted/linux.h b/include/parted/linux.h
index 52d28be..9eb7490 100644
--- a/include/parted/linux.h
+++ b/include/parted/linux.h
@@ -39,7 +39,5 @@ struct _LinuxSpecific {
 #endif
 };
 
-extern PedArchitecture ped_linux_arch;
-
 #endif /* PED_LINUX_H_INCLUDED */
 
diff --git a/include/parted/parted.h b/include/parted/parted.h
index 1302d8f..31ed6ec 100644
--- a/include/parted/parted.h
+++ b/include/parted/parted.h
@@ -23,8 +23,6 @@
 extern "C" {
 #endif
 
-typedef struct _PedArchitecture PedArchitecture;
-
 #include <parted/constraint.h>
 #include <parted/device.h>
 #include <parted/disk.h>
@@ -37,18 +35,6 @@ typedef struct _PedArchitecture PedArchitecture;
 #include <stdlib.h>
 #include <string.h>
 
-struct _PedArchitecture {
-	PedDiskArchOps*		disk_ops;
-	PedDeviceArchOps*	dev_ops;
-};
-
-extern const PedArchitecture*	ped_architecture;
-
-/* the architecture can't be changed if there are any PedDevice's.
- * i.e. you should only be doing this if it's the FIRST thing you do...
- */
-extern int ped_set_architecture (const PedArchitecture* arch);
-
 extern const char* ped_get_version ();
 
 extern void* ped_malloc (size_t size);
diff --git a/libparted/Makefile.am b/libparted/Makefile.am
index 0b013cc..8e20a7d 100644
--- a/libparted/Makefile.am
+++ b/libparted/Makefile.am
@@ -17,6 +17,7 @@ lib_LTLIBRARIES	      =	libparted.la
 libparted_la_LDFLAGS  = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
 						-release $(LT_RELEASE)
 libparted_la_SOURCES  = debug.c			\
+			architecture.c	\
 			device.c		\
 			exception.c		\
 			filesys.c		\
diff --git a/libparted/arch/beos.c b/libparted/arch/beos.c
index 6100e15..ee2e5b3 100644
--- a/libparted/arch/beos.c
+++ b/libparted/arch/beos.c
@@ -45,6 +45,8 @@
 #  define _(String) (String)
 #endif /* ENABLE_NLS */
 
+#include "../architecture.h"
+
 static void
 _scan_for_disks(const char* path)
 {
diff --git a/libparted/arch/gnu.c b/libparted/arch/gnu.c
index a3af905..c2ef370 100644
--- a/libparted/arch/gnu.c
+++ b/libparted/arch/gnu.c
@@ -37,6 +37,8 @@
 #  define _(String) (String)
 #endif /* ENABLE_NLS */
 
+#include "../architecture.h"
+
 static int
 _device_get_sector_size (PedDevice* dev)
 {
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 648bd2b..9854f51 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -42,6 +42,7 @@
 #endif
 
 #include "blkpg.h"
+#include "../architecture.h"
 
 #if ENABLE_NLS
 #  include <libintl.h>
diff --git a/libparted/architecture.c b/libparted/architecture.c
new file mode 100644
index 0000000..e3aaa9b
--- /dev/null
+++ b/libparted/architecture.c
@@ -0,0 +1,32 @@
+ /*
+    libparted - a library for manipulating disk partitions
+    Copyright (C) 2007 Free Software Foundation, Inc.
+
+    This program 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 3 of the License, or
+    (at your option) any later version.
+
+    This program 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <parted/debug.h>
+
+#include "architecture.h"
+
+const PedArchitecture* ped_architecture;
+
+int
+ped_set_architecture (const PedArchitecture* arch)
+{
+	PED_ASSERT (ped_device_get_next (NULL) == NULL, return 0);
+
+	ped_architecture = arch;
+	return 1;
+}
diff --git a/libparted/architecture.h b/libparted/architecture.h
new file mode 100644
index 0000000..4ccffc3
--- /dev/null
+++ b/libparted/architecture.h
@@ -0,0 +1,38 @@
+ /*
+    libparted - a library for manipulating disk partitions
+    Copyright (C) 2007 Free Software Foundation, Inc.
+
+    This program 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 3 of the License, or
+    (at your option) any later version.
+
+    This program 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, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ * WARNING: This shouldn't be exported to the API
+ */
+
+#ifndef _LIBPARTED_ARCH_H_INCLUDED
+#define _LIBPARTED_ARCH_H_INCLUDED
+
+#include <parted/disk.h>
+
+struct _PedArchitecture {
+	PedDiskArchOps*		disk_ops;
+	PedDeviceArchOps*	dev_ops;
+};
+typedef struct _PedArchitecture PedArchitecture;
+
+extern const PedArchitecture*	ped_architecture;
+
+int ped_set_architecture (const PedArchitecture* arch);
+
+#endif /* _LIBPARTED_ARCH_H_INCLUDED */
diff --git a/libparted/device.c b/libparted/device.c
index cbf5a38..e4bbb02 100644
--- a/libparted/device.c
+++ b/libparted/device.c
@@ -44,6 +44,8 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include "architecture.h"
+
 static PedDevice*	devices; /* legal advice says: initialized to NULL,
 				    under section 6.7.8 part 10
 				    of ISO/EIC 9899:1999 */
diff --git a/libparted/disk.c b/libparted/disk.c
index aae2ccf..087fbbf 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -37,6 +37,8 @@
 #include <parted/parted.h>
 #include <parted/debug.h>
 
+#include "architecture.h"
+
 #if ENABLE_NLS
 #  include <libintl.h>
 #  define _(String) dgettext (PACKAGE, String)
diff --git a/libparted/libparted.c b/libparted/libparted.c
index a8c7f0a..6c6de42 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -22,6 +22,8 @@
 #include <parted/parted.h>
 #include <parted/debug.h>
 
+#include "architecture.h"
+
 #ifdef linux
 #  include <parted/linux.h>
 #elif defined(__BEOS__)
@@ -38,8 +40,6 @@
 #  define _(String) (String)
 #endif /* ENABLE_NLS */
 
-const PedArchitecture* ped_architecture;
-
 /* ped_malloc() debugging.  Stick the address and size of memory blocks that
  * weren't ped_free()d in here, and an exception will be thrown when it is
  * allocated.  That way, you can find out what, exactly, the allocated thing
@@ -72,15 +72,6 @@ static pointer_size_type dodgy_malloc_list[] = {
 static int	dodgy_memory_active[100];
 #endif /* DEBUG */
 
-int
-ped_set_architecture (const PedArchitecture* arch)
-{
-	PED_ASSERT (ped_device_get_next (NULL) == NULL, return 0);
-
-	ped_architecture = arch;
-	return 1;
-}
-
 extern void ped_disk_aix_init ();
 extern void ped_disk_bsd_init ();
 extern void ped_disk_dvh_init ();
@@ -192,10 +183,13 @@ _init()
 
 	/* FIXME: a better way of doing this? */
 #ifdef linux
+	extern PedArchitecture ped_linux_arch;
 	ped_set_architecture (&ped_linux_arch);
 #elif defined(__BEOS__)
+	extern PedArchitecture ped_beos_arch;
 	ped_set_architecture (&ped_beos_arch);
 #else
+	extern PedArchitecture ped_gnu_arch;
 	ped_set_architecture (&ped_gnu_arch);
 #endif
 




More information about the parted-edge mailing list