]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add basic library files
authorKarel Zak <kzak@redhat.com>
Fri, 30 Nov 2012 14:27:41 +0000 (15:27 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Mar 2013 10:20:40 +0000 (11:20 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
Makefile.am
libfdisk/Makemodule.am [new file with mode: 0644]
libfdisk/src/Makemodule.am [new file with mode: 0644]
libfdisk/src/fdiskP.h [new file with mode: 0644]
libfdisk/src/init.c [new file with mode: 0644]
libfdisk/src/libfdisk.h [new file with mode: 0644]

index a752bafbda5e2e6241dcac7b97906f2bfc227ff6..3afcad16d3908820e71d21aeabed067f66d8fa1f 100644 (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
diff --git a/libfdisk/Makemodule.am b/libfdisk/Makemodule.am
new file mode 100644 (file)
index 0000000..eb08819
--- /dev/null
@@ -0,0 +1,2 @@
+
+include libfdisk/src/Makemodule.am
diff --git a/libfdisk/src/Makemodule.am b/libfdisk/src/Makemodule.am
new file mode 100644 (file)
index 0000000..a24b8f9
--- /dev/null
@@ -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)
diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h
new file mode 100644 (file)
index 0000000..5349166
--- /dev/null
@@ -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 */
diff --git a/libfdisk/src/init.c b/libfdisk/src/init.c
new file mode 100644 (file)
index 0000000..7d875ee
--- /dev/null
@@ -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;
+}
diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h
new file mode 100644 (file)
index 0000000..fcb69b7
--- /dev/null
@@ -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 */