]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add lsblk.h
authorKarel Zak <kzak@redhat.com>
Fri, 14 Sep 2018 13:36:59 +0000 (15:36 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 14 Sep 2018 13:36:59 +0000 (15:36 +0200)
* move core struct to the header file
* move debug stuff to the header file

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/Makemodule.am
misc-utils/lsblk.c
misc-utils/lsblk.h [new file with mode: 0644]

index 36195b7a309f1c886117c7d5b7b115bdf44a1ab3..3fb3114ed8697bfdee8149cd140287305b355f38 100644 (file)
@@ -77,7 +77,9 @@ endif
 if BUILD_LSBLK
 bin_PROGRAMS += lsblk
 dist_man_MANS += misc-utils/lsblk.8
-lsblk_SOURCES = misc-utils/lsblk.c
+lsblk_SOURCES = \
+       misc-utils/lsblk.c \
+       misc-utils/lsblk.h
 lsblk_LDADD = $(LDADD) libblkid.la libmount.la libcommon.la libsmartcols.la
 lsblk_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) -I$(ul_libmount_incdir) -I$(ul_libsmartcols_incdir)
 if HAVE_UDEV
index 97bddecfac265a693997610d84153895d3965189..75ddd70ee57e334a2d39ac64d7285fb92e18e54d 100644 (file)
 #include <getopt.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <stdint.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <string.h>
 #include <sys/ioctl.h>
-#include <inttypes.h>
 #include <stdarg.h>
 #include <locale.h>
 #include <pwd.h>
 #include <grp.h>
 #include <ctype.h>
-#include <sys/statvfs.h>
 
 #include <blkid.h>
 #include <libmount.h>
-#include <libsmartcols.h>
 
 #ifdef HAVE_LIBUDEV
 #include <libudev.h>
 #include "mangle.h"
 #include "optutils.h"
 
-#include "debug.h"
+#include "lsblk.h"
 
-static UL_DEBUG_DEFINE_MASK(lsblk);
+UL_DEBUG_DEFINE_MASK(lsblk);
 UL_DEBUG_DEFINE_MASKNAMES(lsblk) = UL_DEBUG_EMPTY_MASKNAMES;
 
-#define LSBLK_DEBUG_INIT       (1 << 1)
-#define LSBLK_DEBUG_FILTER     (1 << 2)
-#define LSBLK_DEBUG_DEV                (1 << 3)
-#define LSBLK_DEBUG_CXT                (1 << 4)
-#define LSBLK_DEBUG_ALL                0xFFFF
-
-#define DBG(m, x)       __UL_DBG(lsblk, LSBLK_DEBUG_, m, x)
-#define ON_DBG(m, x)    __UL_DBG_CALL(lsblk, LSBLK_DEBUG_, m, x)
-
-#define UL_DEBUG_CURRENT_MASK  UL_DEBUG_MASK(lsblk)
-#include "debugobj.h"
-
 #define LSBLK_EXIT_SOMEOK 64
 #define LSBLK_EXIT_ALLFAILED 32
 
@@ -230,25 +214,7 @@ static struct colinfo infos[] = {
        [COL_ZONED]  = { "ZONED", 0.3, 0, N_("zone model") },
 };
 
-struct lsblk {
-       struct libscols_table *table;   /* output table */
-       struct libscols_column *sort_col;/* sort output by this column */
-       int sort_id;
-
-       const char *sysroot;
-       int flags;                      /* LSBLK_* */
-
-       unsigned int all_devices:1;     /* print all devices, including empty */
-       unsigned int bytes:1;           /* print SIZE in bytes */
-       unsigned int inverse:1;         /* print inverse dependencies */
-       unsigned int nodeps:1;          /* don't print slaves/holders */
-       unsigned int scsi:1;            /* print only device with HCTL (SCSI) */
-       unsigned int paths:1;           /* print devnames with "/dev" prefix */
-       unsigned int sort_hidden:1;     /* sort column not between output columns */
-       unsigned int force_tree_order:1;/* sort lines by parent->tree relation */
-};
-
-static struct lsblk *lsblk;    /* global handler */
+struct lsblk *lsblk;   /* global handler */
 
 /* columns[] array specifies all currently wanted output column. The columns
  * are defined by infos[] array and you can specify (on command line) each
@@ -286,50 +252,6 @@ static struct libmnt_cache *mntcache;
 static struct udev *udev;
 #endif
 
-struct blkdev_cxt {
-       struct blkdev_cxt *parent;
-
-       struct libscols_line *scols_line;
-       struct stat     st;
-
-       char *name;             /* kernel name in /sys/block */
-       char *dm_name;          /* DM name (dm/block) */
-
-       char *filename;         /* path to device node */
-
-       struct path_cxt *sysfs;
-
-       int partition;          /* is partition? TRUE/FALSE */
-
-       int probed;             /* already probed */
-       char *fstype;           /* detected fs, NULL or "?" if cannot detect */
-       char *uuid;             /* filesystem UUID (or stack uuid) */
-       char *ptuuid;           /* partition table UUID */
-       char *pttype;           /* partition table type */
-       char *label;            /* filesystem label */
-       char *parttype;         /* partition type UUID */
-       char *partuuid;         /* partition UUID */
-       char *partlabel;        /* partition label */
-       char *partflags;        /* partition flags */
-       char *wwn;              /* storage WWN */
-       char *serial;           /* disk serial number */
-       char *model;            /* disk model */
-
-       char *mountpoint;       /* device mountpoint */
-       struct statvfs fsstat;  /* statvfs() result */
-
-       int npartitions;        /* # of partitions this device has */
-       int nholders;           /* # of devices mapped directly to this device
-                                * /sys/block/.../holders */
-       int nslaves;            /* # of devices this device maps to */
-       int maj, min;           /* devno */
-       int discard;            /* supports discard */
-
-       uint64_t size;          /* device size */
-
-       unsigned int    is_mounted : 1;
-};
-
 static void lsblk_init_debug(void)
 {
        __UL_INIT_DEBUG_FROM_ENV(lsblk, LSBLK_DEBUG_, 0, LSBLK_DEBUG);
diff --git a/misc-utils/lsblk.h b/misc-utils/lsblk.h
new file mode 100644 (file)
index 0000000..5608c45
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
+ * Written by Milan Broz <mbroz@redhat.com>
+ *            Karel Zak <kzak@redhat.com>
+ */
+#ifndef UTIL_LINUX_LSBLK_H
+#define UTIL_LINUX_LSBLK_H
+
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/statvfs.h>
+
+#include <libsmartcols.h>
+
+#include "c.h"
+#include "debug.h"
+
+#define LSBLK_DEBUG_INIT       (1 << 1)
+#define LSBLK_DEBUG_FILTER     (1 << 2)
+#define LSBLK_DEBUG_DEV                (1 << 3)
+#define LSBLK_DEBUG_CXT                (1 << 4)
+#define LSBLK_DEBUG_ALL                0xFFFF
+
+UL_DEBUG_DECLARE_MASK(lsblk);
+#define DBG(m, x)       __UL_DBG(lsblk, LSBLK_DEBUG_, m, x)
+#define ON_DBG(m, x)    __UL_DBG_CALL(lsblk, LSBLK_DEBUG_, m, x)
+
+#define UL_DEBUG_CURRENT_MASK  UL_DEBUG_MASK(lsblk)
+#include "debugobj.h"
+
+struct lsblk {
+       struct libscols_table *table;   /* output table */
+       struct libscols_column *sort_col;/* sort output by this column */
+       int sort_id;
+
+       const char *sysroot;
+       int flags;                      /* LSBLK_* */
+
+       unsigned int all_devices:1;     /* print all devices, including empty */
+       unsigned int bytes:1;           /* print SIZE in bytes */
+       unsigned int inverse:1;         /* print inverse dependencies */
+       unsigned int nodeps:1;          /* don't print slaves/holders */
+       unsigned int scsi:1;            /* print only device with HCTL (SCSI) */
+       unsigned int paths:1;           /* print devnames with "/dev" prefix */
+       unsigned int sort_hidden:1;     /* sort column not between output columns */
+       unsigned int force_tree_order:1;/* sort lines by parent->tree relation */
+};
+
+extern struct lsblk *lsblk;     /* global handler */
+
+struct blkdev_cxt {
+       struct blkdev_cxt *parent;
+
+       struct libscols_line *scols_line;
+       struct stat     st;
+
+       char *name;             /* kernel name in /sys/block */
+       char *dm_name;          /* DM name (dm/block) */
+
+       char *filename;         /* path to device node */
+
+       struct path_cxt *sysfs;
+
+       int partition;          /* is partition? TRUE/FALSE */
+
+       int probed;             /* already probed */
+       char *fstype;           /* detected fs, NULL or "?" if cannot detect */
+       char *uuid;             /* filesystem UUID (or stack uuid) */
+       char *ptuuid;           /* partition table UUID */
+       char *pttype;           /* partition table type */
+       char *label;            /* filesystem label */
+       char *parttype;         /* partition type UUID */
+       char *partuuid;         /* partition UUID */
+       char *partlabel;        /* partition label */
+       char *partflags;        /* partition flags */
+       char *wwn;              /* storage WWN */
+       char *serial;           /* disk serial number */
+       char *model;            /* disk model */
+
+       char *mountpoint;       /* device mountpoint */
+       struct statvfs fsstat;  /* statvfs() result */
+
+       int npartitions;        /* # of partitions this device has */
+       int nholders;           /* # of devices mapped directly to this device
+                                * /sys/block/.../holders */
+       int nslaves;            /* # of devices this device maps to */
+       int maj, min;           /* devno */
+       int discard;            /* supports discard */
+
+       uint64_t size;          /* device size */
+
+       unsigned int    is_mounted : 1;
+};
+
+#endif /* UTIL_LINUX_LSBLK_H */