libfdisk: add basic library files

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-11-30 15:27:41 +01:00
parent 9dd068103e
commit d56a7c2330
6 changed files with 191 additions and 0 deletions

View File

@ -23,6 +23,7 @@ dist_noinst_DATA = $(dist_man_MANS)
ul_libblkid_incdir = $(top_builddir)/libblkid/src
ul_libmount_incdir = $(top_builddir)/libmount/src
ul_libuuid_incdir = $(top_srcdir)/libuuid/src
ul_libfdisk_incdir = $(top_srcdir)/libfdisk/src
pkgconfigdir = $(usrlib_execdir)/pkgconfig
@ -74,6 +75,7 @@ include lib/Makemodule.am
include libuuid/Makemodule.am
include libblkid/Makemodule.am
include libmount/Makemodule.am
include libfdisk/Makemodule.am
include schedutils/Makemodule.am
include text-utils/Makemodule.am

2
libfdisk/Makemodule.am Normal file
View File

@ -0,0 +1,2 @@
include libfdisk/src/Makemodule.am

View File

@ -0,0 +1,32 @@
#
# The libfdisk is used for internal util-linux purpose. The library is not
# distributed as shared library for now. Maybe one day...
#
noinst_LTLIBRARIES += libfdisk.la
libfdisk_la_SOURCES = \
libfdisk/src/libfdisk.h \
\
libfdisk/src/init.c
nodist_libfdisk_la_SOURCES = libfdisk/src/fdiskP.h
libfdisk_la_LIBADD = libcommon.la
libfdisk_la_CFLAGS = \
-I$(ul_libfdisk_incdir) \
-I$(top_srcdir)/libfdisk/src
if BUILD_LIBBLKID
libfdisk_la_LIBADD += libblkid.la
libfdisk_la_CFLAGS += -I$(ul_libblkid_incdir)
endif
if BUILD_LIBUUID
libfdisk_la_LIBADD += libuuid.la
libfdisk_la_CFLAGS += -I$(ul_libuuid_incdir)
endif
libfdisk_la_DEPENDENCIES = $(libfdisk_la_LIBADD)

87
libfdisk/src/fdiskP.h Normal file
View File

@ -0,0 +1,87 @@
/*
* fdiskP.h - private library header file
*
* Copyright (C) 2012 Karel Zak <kzak@redhat.com>
*
* This file may be redistributed under the terms of the
* GNU Lesser General Public License.
*/
#ifndef _LIBFDISK_PRIVATE_H
#define _LIBFDISK_PRIVATE_H
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "c.h"
#include "libfdisk.h"
/* features */
#define CONFIG_LIBFDISK_ASSERT
#define CONFIG_LIBFDISK_DEBUG
#ifdef CONFIG_LIBFDISK_ASSERT
#include <assert.h>
#endif
/*
* Debug
*/
#if defined(TEST_PROGRAM) && !defined(LIBFDISK_DEBUG)
#define CONFIG_LIBFDISK_DEBUG
#endif
#ifdef CONFIG_LIBFDISK_DEBUG
# include <stdio.h>
# include <stdarg.h>
/* fdisk debugging flags/options */
#define FDISK_DEBUG_INIT (1 << 1)
#define FDISK_DEBUG_CONTEXT (1 << 2)
#define FDISK_DEBUG_TOPOLOGY (1 << 3)
#define FDISK_DEBUG_GEOMETRY (1 << 4)
#define FDISK_DEBUG_LABEL (1 << 5)
#define FDISK_DEBUG_ALL 0xFFFF
# define ON_DBG(m, x) do { \
if ((FDISK_DEBUG_ ## m) & fdisk_debug_mask) { \
x; \
} \
} while (0)
# define DBG(m, x) do { \
if ((FDISK_DEBUG_ ## m) & fdisk_debug_mask) { \
fprintf(stderr, "%d: fdisk: %8s: ", getpid(), # m); \
x; \
} \
} while (0)
# define DBG_FLUSH do { \
if (fdisk_debug_mask && \
fdisk_debug_mask != FDISK_DEBUG_INIT) \
fflush(stderr); \
} while(0)
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
dbgprint(const char *mesg, ...)
{
va_list ap;
va_start(ap, mesg);
vfprintf(stderr, mesg, ap);
va_end(ap);
fputc('\n', stderr);
}
extern int fdisk_debug_mask;
#else /* !CONFIG_LIBFDISK_DEBUG */
# define ON_DBG(m,x) do { ; } while (0)
# define DBG(m,x) do { ; } while (0)
# define DBG_FLUSH do { ; } while(0)
#endif
#endif /* _LIBFDISK_PRIVATE_H */

33
libfdisk/src/init.c Normal file
View File

@ -0,0 +1,33 @@
#include "fdiskP.h"
int fdisk_debug_mask;
/**
* fdisk_init_debug:
* @mask: debug mask (0xffff to enable full debuging)
*
* If the @mask is not specified then this function reads
* FDISK_DEBUG environment variable to get the mask.
*
* Already initialized debugging stuff cannot be changed. It does not
* have effect to call this function twice.
*/
void fdisk_init_debug(int mask)
{
if (fdisk_debug_mask & FDISK_DEBUG_INIT)
return;
if (!mask) {
char *str = getenv("LIBFDISK_DEBUG");
if (str)
fdisk_debug_mask = strtoul(str, 0, 0);
} else
fdisk_debug_mask = mask;
if (fdisk_debug_mask)
fprintf(stderr, "libfdisk: debug mask set to 0x%04x.\n",
fdisk_debug_mask);
fdisk_debug_mask |= FDISK_DEBUG_INIT;
}

35
libfdisk/src/libfdisk.h Normal file
View File

@ -0,0 +1,35 @@
/*
* libfdisk.h - libfdisk API
*
* Copyright (C) 2012 Karel Zak <kzak@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _LIBFDISK_FDISK_H
#define _LIBFDISK_FDISK_H
#ifdef __cplusplus
extern "C" {
#endif
/* init.c */
extern void fdisk_init_debug(int mask);
#ifdef __cplusplus
}
#endif
#endif /* _LIBFDISK_FDISK_H */