Update to upstream util-linux 2.20.1
[framework/base/util-linux-ng.git] / libblkid / src / blkidP.h
similarity index 54%
rename from shlibs/blkid/src/blkidP.h
rename to libblkid/src/blkidP.h
index e0e5cb8..61a1aad 100644 (file)
 #define CONFIG_BLKID_DEBUG 1
 
 #include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdint.h>
 
+#include "c.h"
 #include "bitops.h"    /* $(top_srcdir)/include/ */
+#include "blkdev.h"
+
 #include "blkid.h"
 #include "list.h"
 
-#ifdef __GNUC__
-#define __BLKID_ATTR(x) __attribute__(x)
-#else
-#define __BLKID_ATTR(x)
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#define FALSE 0
-#endif
-
-#include <limits.h>
-#ifndef PATH_MAX
-# define PATH_MAX 4096
-#endif
-
-/* TODO: move to some top-level util-linux include file */
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
-
 /*
  * This describes the attributes of a specific device.
  * We can traverse all of the tags by bid_tags (linking to the tag bit_names).
@@ -61,6 +46,7 @@ struct blkid_struct_dev
        int                     bid_pri;        /* Device priority */
        dev_t                   bid_devno;      /* Device major/minor number */
        time_t                  bid_time;       /* Last update time of device */
+       suseconds_t             bid_utime;      /* Last update time (microseconds) */
        unsigned int            bid_flags;      /* Device status bitflags */
        char                    *bid_label;     /* Shortcut to device LABEL */
        char                    *bid_uuid;      /* Shortcut to binary UUID */
@@ -68,6 +54,7 @@ struct blkid_struct_dev
 
 #define BLKID_BID_FL_VERIFIED  0x0001  /* Device data validated from disk */
 #define BLKID_BID_FL_INVALID   0x0004  /* Device is invalid */
+#define BLKID_BID_FL_REMOVABLE 0x0008  /* Device added by blkid_probe_all_removable() */
 
 /*
  * Each tag defines a NAME=value pair for a particular device.  The tags
@@ -87,56 +74,79 @@ struct blkid_struct_tag
 typedef struct blkid_struct_tag *blkid_tag;
 
 /*
- * Low-level probe result
+ * Chain IDs
  */
-#define BLKID_PROBVAL_BUFSIZ   64
-#define BLKID_PROBVAL_NVALS    8       /* see blkid.h BLKID_PROBREQ_* */
+enum {
+       BLKID_CHAIN_SUBLKS,     /* FS/RAID superblocks (enabled by default) */
+       BLKID_CHAIN_TOPLGY,     /* Block device topology */
+       BLKID_CHAIN_PARTS,      /* Partition tables */
 
-struct blkid_prval
-{
-       const char      *name;                  /* value name */
-       unsigned char   data[BLKID_PROBVAL_BUFSIZ]; /* value data */
-       size_t          len;                    /* length of value data */
+       BLKID_NCHAINS           /* number of chains */
+};
+
+struct blkid_chain {
+       const struct blkid_chaindrv *driver;    /* chain driver */
+
+       int             enabled;        /* boolean */
+       int             flags;          /* BLKID_<chain>_* */
+       int             binary;         /* boolean */
+       int             idx;            /* index of the current prober (or -1) */
+       unsigned long   *fltr;          /* filter or NULL */
+       void            *data;          /* private chain data or NULL */
 };
 
 /*
- * Low-level probing control struct
+ * Chain driver
  */
-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 */
+struct blkid_chaindrv {
+       const size_t    id;             /* BLKID_CHAIN_* */
+       const char      *name;          /* name of chain (for debug purpose) */
+       const int       dflt_flags;     /* default chain flags */
+       const int       dflt_enabled;   /* default enabled boolean */
+       int             has_fltr;       /* boolean */
+
+       const struct blkid_idinfo **idinfos; /* description of probing functions */
+       const size_t    nidinfos;       /* number of idinfos */
+
+       /* driver operations */
+       int             (*probe)(blkid_probe, struct blkid_chain *);
+       int             (*safeprobe)(blkid_probe, struct blkid_chain *);
+       void            (*free_data)(blkid_probe, void *);
+};
 
-       unsigned char           *sbbuf;         /* superblok buffer */
-       size_t                  sbbuf_len;      /* size of data in superblock buffer */
+/*
+ * Low-level probe result
+ */
+#define BLKID_PROBVAL_BUFSIZ   64
 
-       unsigned char           *buf;           /* seek buffer */
-       blkid_loff_t            buf_off;        /* offset of seek buffer */
-       size_t                  buf_len;        /* size of data in seek buffer */
-       size_t                  buf_max;        /* allocated size of seek buffer */
+#define BLKID_NVALS_SUBLKS     14
+#define BLKID_NVALS_TOPLGY     5
+#define BLKID_NVALS_PARTS      13
 
-       struct blkid_prval      vals[BLKID_PROBVAL_NVALS];
-       int                     nvals;
+/* Max number of all values in probing result */
+#define BLKID_NVALS             (BLKID_NVALS_SUBLKS + \
+                                BLKID_NVALS_TOPLGY + \
+                                BLKID_NVALS_PARTS)
 
-       int                     probreq;        /* BLKID_PROBREQ_* flags */
-       int                     idx;            /* index of the last prober */
+struct blkid_prval
+{
+       const char      *name;                  /* value name */
+       unsigned char   data[BLKID_PROBVAL_BUFSIZ]; /* value data */
+       size_t          len;                    /* length of value data */
 
-       unsigned long           *fltr;          /* filter */
+       struct blkid_chain      *chain;         /* owner */
 };
 
-#define BLKID_SB_BUFSIZ                0x11000
-
 /*
  * Filesystem / Raid magic strings
  */
 struct blkid_idmag
 {
        const char      *magic;         /* magic string */
-       unsigned        len;            /* length of magic */
+       unsigned int    len;            /* length of magic */
 
        long            kboff;          /* kilobyte offset of superblock */
-       unsigned        sboff;          /* byte offset within superblock */
+       unsigned int    sboff;          /* byte offset within superblock */
 };
 
 /*
@@ -144,9 +154,10 @@ struct blkid_idmag
  */
 struct blkid_idinfo
 {
-       const char      *name;          /* FS/RAID name */
+       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);
@@ -163,6 +174,57 @@ struct blkid_idinfo
  */
 #define BLKID_IDINFO_TOLERANT  (1 << 1)
 
+struct blkid_bufinfo {
+       unsigned char           *data;
+       blkid_loff_t            off;
+       blkid_loff_t            len;
+       struct list_head        bufs;   /* list of buffers */
+};
+
+/*
+ * 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 */
+
+       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 blkid_prval      vals[BLKID_NVALS];      /* results */
+       int                     nvals;          /* number of assigned vals */
+
+       struct blkid_struct_probe *parent;      /* for clones */
+       struct blkid_struct_probe *disk_probe;  /* whole-disk probing */
+};
+
+/* 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 */
+
+/* private per-probing flags */
+#define BLKID_PROBE_FL_IGNORE_PT (1 << 1)      /* ignore partition table */
+
+extern blkid_probe blkid_clone_probe(blkid_probe parent);
+extern blkid_probe blkid_probe_get_wholedisk_probe(blkid_probe pr);
+
 /*
  * Evaluation methods (for blkid_eval_* API)
  */
@@ -222,6 +284,7 @@ struct blkid_struct_cache
 
 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);
 
 #define BLKID_CACHE_FILE       "/etc/blkid.tab"
 #define BLKID_CONFIG_FILE      "/etc/blkid.conf"
@@ -237,6 +300,7 @@ extern char *blkid_strndup(const char *s, const int length);
 /*
  * Priority settings for different types of devices
  */
+#define BLKID_PRI_UBI  50
 #define BLKID_PRI_DM   40
 #define BLKID_PRI_EVMS 30
 #define BLKID_PRI_LVM  20
@@ -263,7 +327,6 @@ extern char *blkid_strndup(const char *s, const int length);
 #define DEBUG_ALL      0xFFFF
 
 #ifdef CONFIG_BLKID_DEBUG
-#include <stdio.h>
 extern int blkid_debug_mask;
 extern void blkid_init_debug(int mask);
 extern void blkid_debug_dump_dev(blkid_dev dev);
@@ -282,6 +345,7 @@ struct dir_list {
        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);
 
 /* lseek.c */
 extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
@@ -311,32 +375,90 @@ extern blkid_dev blkid_new_dev(void);
 extern void blkid_free_dev(blkid_dev dev);
 
 /* probe.c */
-unsigned char *blkid_probe_get_buffer(blkid_probe pr,
+extern int blkid_probe_is_tiny(blkid_probe pr);
+extern int blkid_probe_is_cdrom(blkid_probe pr);
+extern unsigned char *blkid_probe_get_buffer(blkid_probe pr,
                                 blkid_loff_t off, blkid_loff_t len);
 
+extern unsigned char *blkid_probe_get_sector(blkid_probe pr, unsigned int sector);
+
+extern int blkid_probe_get_dimension(blkid_probe pr,
+                       blkid_loff_t *off, blkid_loff_t *size);
+
+extern int blkid_probe_set_dimension(blkid_probe pr,
+                       blkid_loff_t off, blkid_loff_t size);
+
+extern int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id,
+                       blkid_loff_t *offset, const struct blkid_idmag **res);
+
 /* 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 int blkid_probe_is_covered_by_pt(blkid_probe pr,
+                                       blkid_loff_t offset, blkid_loff_t size);
+
+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_chain *blkid_probe_get_chain(blkid_probe pr);
+
+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_get_binary_data(blkid_probe pr, struct blkid_chain *chn);
+
 extern int blkid_probe_set_value(blkid_probe pr, const char *name,
                 unsigned char *data, size_t len);
 extern int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
                 const char *fmt, va_list ap);
-extern int blkid_probe_set_version(blkid_probe pr, const char *version);
-extern int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...)
-               __attribute__ ((format (printf, 2, 3)));
-
-extern int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len);
-extern int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
-                size_t len, int enc);
-extern int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
-                size_t len, const char *fmt, ...)
-               __attribute__ ((format (printf, 4, 5)));
-extern int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len);
-
-extern int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid);
-extern int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name);
+extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name,
+                const char *fmt, ...);
+
+extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len);
+extern size_t blkid_rtrim_whitespace(unsigned char *str);
+
+extern void blkid_probe_set_wiper(blkid_probe pr, blkid_loff_t off,
+                                 blkid_loff_t size);
+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);
+
+/* filter bitmap macros */
+#define blkid_bmp_wordsize             (8 * sizeof(unsigned long))
+#define blkid_bmp_idx_bit(item)                (1UL << ((item) % blkid_bmp_wordsize))
+#define blkid_bmp_idx_byte(item)       ((item) / blkid_bmp_wordsize)
+
+#define blkid_bmp_set_item(bmp, item)  \
+               ((bmp)[ blkid_bmp_idx_byte(item) ] |= blkid_bmp_idx_bit(item))
+
+#define blkid_bmp_unset_item(bmp, item)        \
+               ((bmp)[ blkid_bmp_idx_byte(item) ] &= ~blkid_bmp_idx_bit(item))
+
+#define blkid_bmp_get_item(bmp, item)  \
+               ((bmp)[ blkid_bmp_idx_byte(item) ] & blkid_bmp_idx_bit(item))
+
+#define blkid_bmp_nwords(max_items) \
+               (((max_items) + blkid_bmp_wordsize) / blkid_bmp_wordsize)
+
+#define blkid_bmp_nbytes(max_items) \
+               (blkid_bmp_nwords(max_items) * sizeof(unsigned long))
+
+/* encode.c */
+extern size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,
+                       const unsigned char *src, size_t count);
 
 #define BLKID_ENC_UTF16BE      0
 #define BLKID_ENC_UTF16LE      1