summaryrefslogtreecommitdiffstats
path: root/libfdisk
diff options
context:
space:
mode:
authorKarel Zak2012-11-30 15:27:41 +0100
committerKarel Zak2013-03-11 11:20:40 +0100
commitd56a7c2330d2a361d3820f8ad9a5399fec47afae (patch)
tree79cb30cd341e869208dd79d74a45b2c7faedb815 /libfdisk
parenttests: add fdisk GPT test (diff)
downloadkernel-qcow2-util-linux-d56a7c2330d2a361d3820f8ad9a5399fec47afae.tar.gz
kernel-qcow2-util-linux-d56a7c2330d2a361d3820f8ad9a5399fec47afae.tar.xz
kernel-qcow2-util-linux-d56a7c2330d2a361d3820f8ad9a5399fec47afae.zip
libfdisk: add basic library files
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r--libfdisk/Makemodule.am2
-rw-r--r--libfdisk/src/Makemodule.am32
-rw-r--r--libfdisk/src/fdiskP.h87
-rw-r--r--libfdisk/src/init.c33
-rw-r--r--libfdisk/src/libfdisk.h35
5 files changed, 189 insertions, 0 deletions
diff --git a/libfdisk/Makemodule.am b/libfdisk/Makemodule.am
new file mode 100644
index 000000000..eb0881920
--- /dev/null
+++ b/libfdisk/Makemodule.am
@@ -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
index 000000000..a24b8f90d
--- /dev/null
+++ b/libfdisk/src/Makemodule.am
@@ -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
index 000000000..534916610
--- /dev/null
+++ b/libfdisk/src/fdiskP.h
@@ -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
index 000000000..7d875ee8f
--- /dev/null
+++ b/libfdisk/src/init.c
@@ -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
index 000000000..fcb69b76d
--- /dev/null
+++ b/libfdisk/src/libfdisk.h
@@ -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 */