libblkid-tiny: Update the code from util-linux's libblkid
[project/fstools.git] / libblkid-tiny / blkidP.h
index 0f372a5..1ba7673 100644 (file)
@@ -13,8 +13,8 @@
 #ifndef _BLKID_BLKIDP_H
 #define _BLKID_BLKIDP_H
 
-
-#define CONFIG_BLKID_DEBUG 1
+/* Always confirm that /dev/disk-by symlinks match with LABEL/UUID on device */
+/* #define CONFIG_BLKID_VERIFY_UDEV 1 */
 
 #include <sys/types.h>
 #include <dirent.h>
 #include "bitops.h"    /* $(top_srcdir)/include/ */
 #include "blkdev.h"
 
+#if 0
+#include "debug.h"
+#include "blkid.h"
+#include "list.h"
+#else
+#include "libblkid-tiny.h"
 #include "blkid.h"
 #include <libubox/list.h>
+#endif
 
 /*
  * This describes the attributes of a specific device.
@@ -117,32 +124,47 @@ struct blkid_chaindrv {
 /*
  * Low-level probe result
  */
-#define BLKID_PROBVAL_BUFSIZ   64
-
-#define BLKID_NVALS_SUBLKS     14
-#define BLKID_NVALS_TOPLGY     5
-#define BLKID_NVALS_PARTS      13
-
-/* Max number of all values in probing result */
-#define BLKID_NVALS             (BLKID_NVALS_SUBLKS + \
-                                BLKID_NVALS_TOPLGY + \
-                                BLKID_NVALS_PARTS)
-
 struct blkid_prval
 {
-       const char      *name;                  /* value name */
-       unsigned char   data[BLKID_PROBVAL_BUFSIZ]; /* value data */
-       size_t          len;                    /* length of value data */
+       const char      *name;          /* value name */
+       unsigned char   *data;          /* value data */
+       size_t          len;            /* length of value data */
 
        struct blkid_chain      *chain;         /* owner */
+       struct list_head        prvals;         /* list of results */
 };
 
+/* Moved to libblkid-tiny.h because it's needed outside of the private impl. */
+#if 0
 /*
  * Filesystem / Raid magic strings
  */
+struct blkid_idmag
+{
+       const char      *magic;         /* magic string */
+       unsigned int    len;            /* length of magic */
+
+       long            kboff;          /* kilobyte offset of superblock */
+       unsigned int    sboff;          /* byte offset within superblock */
+};
+
 /*
  * Filesystem / Raid description
  */
+struct blkid_idinfo
+{
+       const char      *name;          /* fs, raid or partition table name */
+       int             usage;          /* BLKID_USAGE_* flag */
+       int             flags;          /* BLKID_IDINFO_* flags */
+       int             minsz;          /* minimal device size */
+
+                                       /* probe function */
+       int             (*probefunc)(blkid_probe pr, const struct blkid_idmag *mag);
+
+       struct blkid_idmag      magics[];       /* NULL or array with magic strings */
+};
+#endif
+
 #define BLKID_NONE_MAGIC       {{ NULL }}
 
 /*
@@ -159,10 +181,47 @@ struct blkid_bufinfo {
        struct list_head        bufs;   /* list of buffers */
 };
 
+/* Replaced by a smaller struct in libblkid-tiny.h */
+#if 0
+/*
+ * Low-level probing control struct
+ */
+struct blkid_struct_probe
+{
+       int                     fd;             /* device file descriptor */
+       blkid_loff_t            off;            /* begin of data on the device */
+       blkid_loff_t            size;           /* end of data on the device */
+       size_t                  mmap_granularity; /* minimal size of mmaped buffer (PAGE_SIZE) */
+
+       dev_t                   devno;          /* device number (st.st_rdev) */
+       dev_t                   disk_devno;     /* devno of the whole-disk or 0 */
+       unsigned int            blkssz;         /* sector size (BLKSSZGET ioctl) */
+       mode_t                  mode;           /* struct stat.sb_mode */
+
+       int                     flags;          /* private libray flags */
+       int                     prob_flags;     /* always zeroized by blkid_do_*() */
+
+       blkid_loff_t            wipe_off;       /* begin of the wiped area */
+       blkid_loff_t            wipe_size;      /* size of the wiped area */
+       struct blkid_chain      *wipe_chain;    /* superblock, partition, ... */
+
+       struct list_head        buffers;        /* list of buffers */
+
+       struct blkid_chain      chains[BLKID_NCHAINS];  /* array of chains */
+       struct blkid_chain      *cur_chain;             /* current chain */
+
+       struct list_head        values;         /* results */
+
+       struct blkid_struct_probe *parent;      /* for clones */
+       struct blkid_struct_probe *disk_probe;  /* whole-disk probing */
+};
+#endif
+
 /* private flags library flags */
 #define BLKID_FL_PRIVATE_FD    (1 << 1)        /* see blkid_new_probe_from_filename() */
 #define BLKID_FL_TINY_DEV      (1 << 2)        /* <= 1.47MiB (floppy or so) */
 #define BLKID_FL_CDROM_DEV     (1 << 3)        /* is a CD/DVD drive */
+#define BLKID_FL_NOSCAN_DEV    (1 << 4)        /* do not scan this device */
 
 /* private per-probing flags */
 #define BLKID_PROBE_FL_IGNORE_PT (1 << 1)      /* ignore partition table */
@@ -190,7 +249,8 @@ struct blkid_config {
        char *cachefile;                /* CACHE_FILE=<path> option */
 };
 
-extern struct blkid_config *blkid_read_config(const char *filename);
+extern struct blkid_config *blkid_read_config(const char *filename)
+                       __ul_attribute__((warn_unused_result));
 extern void blkid_free_config(struct blkid_config *conf);
 
 /*
@@ -227,10 +287,6 @@ struct blkid_struct_cache
 #define BLKID_BIC_FL_PROBED    0x0002  /* We probed /proc/partition devices */
 #define BLKID_BIC_FL_CHANGED   0x0004  /* Cache has changed from disk */
 
-extern char *blkid_strdup(const char *s);
-extern char *blkid_strndup(const char *s, const int length);
-extern char *blkid_strconcat(const char *a, const char *b, const char *c);
-
 /* config file */
 #define BLKID_CONFIG_FILE      "/etc/blkid.conf"
 
@@ -242,6 +298,9 @@ extern char *blkid_strconcat(const char *a, const char *b, const char *c);
 /* old systems */
 #define BLKID_CACHE_FILE_OLD   "/etc/blkid.tab"
 
+#define BLKID_PROBE_OK  0
+#define BLKID_PROBE_NONE 1
+
 #define BLKID_ERR_IO    5
 #define BLKID_ERR_PROC  9
 #define BLKID_ERR_MEM  12
@@ -259,137 +318,215 @@ extern char *blkid_strconcat(const char *a, const char *b, const char *c);
 #define BLKID_PRI_LVM  20
 #define BLKID_PRI_MD   10
 
-#if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
-#define CONFIG_BLKID_DEBUG
-#endif
+#if 0
+#define BLKID_DEBUG_HELP       (1 << 0)
+#define BLKID_DEBUG_INIT       (1 << 1)
+#define BLKID_DEBUG_CACHE      (1 << 2)
+#define BLKID_DEBUG_CONFIG     (1 << 3)
+#define BLKID_DEBUG_DEV                (1 << 4)
+#define BLKID_DEBUG_DEVNAME    (1 << 5)
+#define BLKID_DEBUG_DEVNO      (1 << 6)
+#define BLKID_DEBUG_EVALUATE   (1 << 7)
+#define BLKID_DEBUG_LOWPROBE   (1 << 8)
+#define BLKID_DEBUG_PROBE      (1 << 9)
+#define BLKID_DEBUG_READ       (1 << 10)
+#define BLKID_DEBUG_SAVE       (1 << 11)
+#define BLKID_DEBUG_TAG                (1 << 12)
+#define BLKID_DEBUG_BUFFER     (1 << 13)
+#define BLKID_DEBUG_ALL                0xFFFF          /* (1 << 16) aka FFFF is expected by API */
+
+UL_DEBUG_DECLARE_MASK(libblkid);
+#define DBG(m, x)      __UL_DBG(libblkid, BLKID_DEBUG_, m, x)
+#define ON_DBG(m, x)    __UL_DBG_CALL(libblkid, BLKID_DEBUG_, m, x)
 
-#define DEBUG_CACHE    0x0001
-#define DEBUG_DUMP     0x0002
-#define DEBUG_DEV      0x0004
-#define DEBUG_DEVNAME  0x0008
-#define DEBUG_DEVNO    0x0010
-#define DEBUG_PROBE    0x0020
-#define DEBUG_READ     0x0040
-#define DEBUG_RESOLVE  0x0080
-#define DEBUG_SAVE     0x0100
-#define DEBUG_TAG      0x0200
-#define DEBUG_LOWPROBE 0x0400
-#define DEBUG_CONFIG   0x0800
-#define DEBUG_EVALUATE 0x1000
-#define DEBUG_INIT     0x8000
-#define DEBUG_ALL      0xFFFF
-
-#ifdef CONFIG_BLKID_DEBUG
-extern int blkid_debug_mask;
-extern void blkid_init_debug(int mask);
 extern void blkid_debug_dump_dev(blkid_dev dev);
 extern void blkid_debug_dump_tag(blkid_tag tag);
-
-#define DBG(m,x)       if ((m) & blkid_debug_mask) x;
-
-#else /* !CONFIG_BLKID_DEBUG */
-#define DBG(m,x)
-#define blkid_init_debug(x)
-#endif /* CONFIG_BLKID_DEBUG */
+#else
+#define DBG(m, x)      do {} while (0)
+#endif
 
 /* devno.c */
 struct dir_list {
        char    *name;
        struct dir_list *next;
 };
-extern void blkid__scan_dir(char *, dev_t, struct dir_list **, char **);
-extern int blkid_driver_has_major(const char *drvname, int major);
+extern void blkid__scan_dir(char *, dev_t, struct dir_list **, char **)
+                       __attribute__((nonnull(1,4)));
+extern int blkid_driver_has_major(const char *drvname, int major)
+                       __attribute__((warn_unused_result));
 
 /* lseek.c */
 extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
 
 /* read.c */
-extern void blkid_read_cache(blkid_cache cache);
+extern void blkid_read_cache(blkid_cache cache)
+                       __attribute__((nonnull));
 
 /* save.c */
-extern int blkid_flush_cache(blkid_cache cache);
+extern int blkid_flush_cache(blkid_cache cache)
+                       __attribute__((nonnull));
 
 /* cache */
-extern char *blkid_safe_getenv(const char *arg);
-extern char *blkid_get_cache_filename(struct blkid_config *conf);
+extern char *blkid_safe_getenv(const char *arg)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
 
+extern char *blkid_get_cache_filename(struct blkid_config *conf)
+                       __attribute__((warn_unused_result));
 /*
  * Functions to create and find a specific tag type: tag.c
  */
 extern void blkid_free_tag(blkid_tag tag);
-extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type);
+extern blkid_tag blkid_find_tag_dev(blkid_dev dev, const char *type)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+
 extern int blkid_set_tag(blkid_dev dev, const char *name,
-                        const char *value, const int vlength);
+                        const char *value, const int vlength)
+                       __attribute__((nonnull(1,2)));
 
 /*
  * Functions to create and find a specific tag type: dev.c
  */
-extern blkid_dev blkid_new_dev(void);
+extern blkid_dev blkid_new_dev(void)
+                       __attribute__((warn_unused_result));
 extern void blkid_free_dev(blkid_dev dev);
 
 /* probe.c */
-extern int blkid_probe_is_tiny(blkid_probe pr);
-extern int blkid_probe_is_cdrom(blkid_probe pr);
+extern int blkid_probe_is_tiny(blkid_probe pr)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+extern int blkid_probe_is_cdrom(blkid_probe pr)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+
 extern unsigned char *blkid_probe_get_buffer(blkid_probe pr,
-                                blkid_loff_t off, blkid_loff_t len);
+                                blkid_loff_t off, blkid_loff_t len)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
 
-extern unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector);
+extern unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
 
 extern int blkid_probe_get_dimension(blkid_probe pr,
-                       blkid_loff_t *off, blkid_loff_t *size);
+                       blkid_loff_t *off, blkid_loff_t *size)
+                       __attribute__((nonnull));
 
 extern int blkid_probe_set_dimension(blkid_probe pr,
-                       blkid_loff_t off, blkid_loff_t size);
+                       blkid_loff_t off, blkid_loff_t size)
+                       __attribute__((nonnull));
 
 extern int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
-                       blkid_loff_t *offset, const struct blkid_idmag **res);
+                       blkid_loff_t *offset, const struct blkid_idmag **res)
+                       __attribute__((nonnull(1)));
 
 /* returns superblok according to 'struct blkid_idmag' */
 #define blkid_probe_get_sb(_pr, _mag, type) \
                        ((type *) blkid_probe_get_buffer((_pr),\
                                        (_mag)->kboff << 10, sizeof(type)))
 
-extern blkid_partlist blkid_probe_get_partlist(blkid_probe pr);
+extern blkid_partlist blkid_probe_get_partlist(blkid_probe pr)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
 
 extern int blkid_probe_is_covered_by_pt(blkid_probe pr,
-                                       blkid_loff_t offset, blkid_loff_t size);
+                                       blkid_loff_t offset, blkid_loff_t size)
+                       __attribute__((warn_unused_result));
+
+extern void blkid_probe_chain_reset_values(blkid_probe pr, struct blkid_chain *chn)
+                       __attribute__((nonnull));
+extern int blkid_probe_chain_save_values(blkid_probe pr,
+                                      struct blkid_chain *chn,
+                                      struct list_head *vals)
+                       __attribute__((nonnull));
 
-extern void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn);
-extern int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn,
-                                       struct blkid_prval *vals, int nvals);
-extern struct blkid_prval *blkid_probe_assign_value(blkid_probe pr, const char *name);
-extern int blkid_probe_reset_last_value(blkid_probe pr);
-extern void blkid_probe_append_vals(blkid_probe pr, struct blkid_prval *vals, int nvals);
+extern struct blkid_prval *blkid_probe_assign_value(blkid_probe pr,
+                                       const char *name)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
 
-extern struct blkid_chain *blkid_probe_get_chain(blkid_probe pr);
+extern void blkid_probe_free_value(struct blkid_prval *v);
 
-extern struct blkid_prval *__blkid_probe_get_value(blkid_probe pr, int num);
-extern struct blkid_prval *__blkid_probe_lookup_value(blkid_probe pr, const char *name);
 
-extern unsigned long *blkid_probe_get_filter(blkid_probe pr, int chain, int create);
-extern int __blkid_probe_invert_filter(blkid_probe pr, int chain);
-extern int __blkid_probe_reset_filter(blkid_probe pr, int chain);
-extern int __blkid_probe_filter_types(blkid_probe pr, int chain, int flag, char *names[]);
+extern void blkid_probe_append_values_list(blkid_probe pr,
+                                   struct list_head *vals)
+                       __attribute__((nonnull));
 
-extern void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn);
+extern void blkid_probe_free_values_list(struct list_head *vals);
 
+extern struct blkid_chain *blkid_probe_get_chain(blkid_probe pr)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+
+extern struct blkid_prval *blkid_probe_last_value(blkid_probe pr);
+
+extern struct blkid_prval *__blkid_probe_get_value(blkid_probe pr, int num)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+
+extern struct blkid_prval *__blkid_probe_lookup_value(blkid_probe pr, const char *name)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+
+extern unsigned long *blkid_probe_get_filter(blkid_probe pr, int chain, int create)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+
+extern int __blkid_probe_invert_filter(blkid_probe pr, int chain)
+                       __attribute__((nonnull));
+extern int __blkid_probe_reset_filter(blkid_probe pr, int chain)
+                       __attribute__((nonnull));
+extern int __blkid_probe_filter_types(blkid_probe pr, int chain, int flag, char *names[])
+                       __attribute__((nonnull));
+
+extern void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+
+extern struct blkid_prval *blkid_probe_new_val(void)
+                       __attribute__((warn_unused_result));
 extern int blkid_probe_set_value(blkid_probe pr, const char *name,
-                unsigned char *data, size_t len);
+                               unsigned char *data, size_t len)
+                       __attribute__((nonnull));
+extern int blkid_probe_value_set_data(struct blkid_prval *v,
+                               unsigned char *data, size_t len)
+                       __attribute__((nonnull));
+
 extern int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
-                const char *fmt, va_list ap);
+                               const char *fmt, va_list ap)
+                       __attribute__((nonnull));
+
 extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name,
-                const char *fmt, ...);
+                               const char *fmt, ...)
+                       __attribute__((nonnull))
+                       __attribute__ ((__format__ (__printf__, 3, 4)));
+
 extern int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset,
-               size_t len, unsigned char *magic);
+                               size_t len, unsigned char *magic)
+                       __attribute__((nonnull));
+
+extern int blkid_probe_verify_csum(blkid_probe pr, uint64_t csum, uint64_t expected)
+                       __attribute__((nonnull));
+
+extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len)
+                       __attribute__((nonnull));
+extern int blkid_uuid_is_empty(const unsigned char *buf, size_t len);
 
-extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len);
-extern size_t blkid_rtrim_whitespace(unsigned char *str);
+extern size_t blkid_rtrim_whitespace(unsigned char *str)
+                       __attribute__((nonnull));
+extern size_t blkid_ltrim_whitespace(unsigned char *str)
+                       __attribute__((nonnull));
 
 extern void blkid_probe_set_wiper(blkid_probe pr, blkid_loff_t off,
-                                 blkid_loff_t size);
+                                 blkid_loff_t size)
+                       __attribute__((nonnull));
 extern int blkid_probe_is_wiped(blkid_probe pr, struct blkid_chain **chn,
-                               blkid_loff_t off, blkid_loff_t size);
-extern void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size);
+                               blkid_loff_t off, blkid_loff_t size)
+                       __attribute__((nonnull))
+                       __attribute__((warn_unused_result));
+extern void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t size)
+                       __attribute__((nonnull));
 
 /* filter bitmap macros */
 #define blkid_bmp_wordsize             (8 * sizeof(unsigned long))
@@ -412,8 +549,10 @@ extern void blkid_probe_use_wiper(blkid_probe pr, blkid_loff_t off, blkid_loff_t
                (blkid_bmp_nwords(max_items) * sizeof(unsigned long))
 
 /* encode.c */
+extern unsigned char *blkid_encode_alloc(size_t count, size_t *reslen);
 extern size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
-                       const unsigned char *src, size_t count);
+                               const unsigned char *src, size_t count)
+                       __attribute__((nonnull));
 
 #define BLKID_ENC_UTF16BE      0
 #define BLKID_ENC_UTF16LE      1