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

David Cantrell dcantrell at redhat.com
Mon Nov 5 03:55:45 UTC 2007


On Sat, 03 Nov 2007 17:41:12 -0200
Otavio Salvador <otavio at ossystems.com.br> wrote:

ACK

> 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 |   42 ++++++++++++++++++++++++++++++++++++++++++
>  libparted/architecture.h |   38 ++++++++++++++++++++++++++++++++++++++
>  libparted/device.c       |    2 ++
>  libparted/disk.c         |    2 ++
>  libparted/libparted.c    |   30 ++----------------------------
>  13 files changed, 92 insertions(+), 48 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..c102563
> --- /dev/null
> +++ b/libparted/architecture.c
> @@ -0,0 +1,42 @@
> + /*
> +    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 "architecture.h"
> +
> +const PedArchitecture* ped_architecture;
> +
> +void
> +ped_set_architecture ()
> +{
> +	/* Set just once */
> +	if (ped_architecture)
> +		return;
> +
> +#ifdef linux
> +	extern PedArchitecture ped_linux_arch;
> +	const PedArchitecture* arch = &ped_linux_arch;
> +#elif defined(__BEOS__)
> +	extern PedArchitecture ped_beos_arch;
> +	const PedArchitecture* arch = &ped_beos_arch;
> +#else
> +	extern PedArchitecture ped_gnu_arch;
> +	const PedArchitecture* arch = &ped_gnu_arch;
> +#endif
> +
> +	ped_architecture = arch;
> +}
> diff --git a/libparted/architecture.h b/libparted/architecture.h
> new file mode 100644
> index 0000000..012af4c
> --- /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;
> +
> +extern void ped_set_architecture ();
> +
> +#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..9759174 100644
> --- a/libparted/libparted.c
> +++ b/libparted/libparted.c
> @@ -22,13 +22,7 @@
>  #include <parted/parted.h>
>  #include <parted/debug.h>
>  
> -#ifdef linux
> -#  include <parted/linux.h>
> -#elif defined(__BEOS__)
> -#  include <parted/beos.h>
> -#else
> -#  include <parted/gnu.h>
> -#endif
> +#include "architecture.h"
>  
>  #if ENABLE_NLS
>  #  include <locale.h>
> @@ -38,8 +32,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 +64,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 ();
> @@ -189,16 +172,7 @@ _init()
>  #ifdef ENABLE_FS
>  	init_file_system_types ();
>  #endif
> -
> -	/* FIXME: a better way of doing this? */
> -#ifdef linux
> -	ped_set_architecture (&ped_linux_arch);
> -#elif defined(__BEOS__)
> -	ped_set_architecture (&ped_beos_arch);
> -#else
> -	ped_set_architecture (&ped_gnu_arch);
> -#endif
> -
> +	ped_set_architecture ();
>  #ifdef DEBUG
>  	memset (dodgy_memory_active, 0, sizeof (dodgy_memory_active));
>  #endif
> 
> 
> _______________________________________________
> parted-edge mailing list
> parted-edge at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/parted-edge


-- 
David Cantrell <dcantrell at redhat.com>
Red Hat / Westford, MA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/parted-edge/attachments/20071104/45bf2eb2/attachment-0001.pgp 


More information about the parted-edge mailing list