libblkid-tiny: Update the code from util-linux's libblkid
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Sat, 31 Oct 2015 15:38:41 +0000 (16:38 +0100)
committerJohn Crispin <blogic@openwrt.org>
Thu, 29 Oct 2015 18:51:24 +0000 (19:51 +0100)
This updates the relevant source files to util-linux changeset
4419ffb9eff5801fdbd385a4a6199b3877f802ad.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
14 files changed:
libblkid-tiny/bitops.h
libblkid-tiny/blkdev.h
libblkid-tiny/blkid.h
libblkid-tiny/blkidP.h
libblkid-tiny/btrfs.c
libblkid-tiny/c.h
libblkid-tiny/ext.c
libblkid-tiny/hfs.c
libblkid-tiny/libblkid-tiny.c
libblkid-tiny/libblkid-tiny.h
libblkid-tiny/superblocks.h
libblkid-tiny/swap.c
libblkid-tiny/ubifs.c
libblkid-tiny/vfat.c

index 5bf205794783e41236bcd71e174d8c700f77c842..498ec63e7ecd5a1940459e249ad04c6f280910fd 100644 (file)
+/*
+ * No copyright is claimed.  This code is in the public domain; do with
+ * it what you wish.
+ *
+ * Written by Karel Zak <kzak@redhat.com>
+ */
 #ifndef BITOPS_H
 #define BITOPS_H
 
 #include <stdint.h>
+#include <sys/param.h>
+
+#if defined(HAVE_BYTESWAP_H)
+# include <byteswap.h>
+#endif
+
+#if defined(HAVE_ENDIAN_H)
+#  include <endian.h>
+#elif defined(HAVE_SYS_ENDIAN_H)       /* BSDs have them here */
+#  include <sys/endian.h>
+#endif
+
+#if defined(__OpenBSD__)
+# include <sys/types.h>
+# define be16toh(x) betoh16(x)
+# define be32toh(x) betoh32(x)
+# define be64toh(x) betoh64(x)
+#endif
 
 /*
- * Bit map related macros. Usually provided by libc.
+ * Fallbacks
  */
-#include <sys/param.h>
+#ifndef bswap_16
+# define bswap_16(x)   ((((x) & 0x00FF) << 8) | \
+                       (((x) & 0xFF00) >> 8))
+#endif
+
+#ifndef bswap_32
+# define bswap_32(x)   ((((x) & 0x000000FF) << 24) | \
+                       (((x) & 0x0000FF00) << 8)  | \
+                       (((x) & 0x00FF0000) >> 8)  | \
+                       (((x) & 0xFF000000) >> 24))
+#endif
+
+#ifndef bswap_64
+# define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
+                      (((x) & 0x000000000000FF00ULL) << 40) | \
+                      (((x) & 0x0000000000FF0000ULL) << 24) | \
+                      (((x) & 0x00000000FF000000ULL) << 8)  | \
+                      (((x) & 0x000000FF00000000ULL) >> 8)  | \
+                      (((x) & 0x0000FF0000000000ULL) >> 24) | \
+                      (((x) & 0x00FF000000000000ULL) >> 40) | \
+                      (((x) & 0xFF00000000000000ULL) >> 56))
+#endif
 
+#ifndef htobe16
+# if !defined(WORDS_BIGENDIAN)
+#  define htobe16(x) bswap_16 (x)
+#  define htole16(x) (x)
+#  define be16toh(x) bswap_16 (x)
+#  define le16toh(x) (x)
+#  define htobe32(x) bswap_32 (x)
+#  define htole32(x) (x)
+#  define be32toh(x) bswap_32 (x)
+#  define le32toh(x) (x)
+#  define htobe64(x) bswap_64 (x)
+#  define htole64(x) (x)
+#  define be64toh(x) bswap_64 (x)
+#  define le64toh(x) (x)
+# else
+#  define htobe16(x) (x)
+#  define htole16(x) bswap_16 (x)
+#  define be16toh(x) (x)
+#  define le16toh(x) bswap_16 (x)
+#  define htobe32(x) (x)
+#  define htole32(x) bswap_32 (x)
+#  define be32toh(x) (x)
+#  define le32toh(x) bswap_32 (x)
+#  define htobe64(x) (x)
+#  define htole64(x) bswap_64 (x)
+#  define be64toh(x) (x)
+#  define le64toh(x) bswap_64 (x)
+# endif
+#endif
+
+/*
+ * Byte swab macros (based on linux/byteorder/swab.h)
+ */
+#define swab16(x) bswap_16(x)
+#define swab32(x) bswap_32(x)
+#define swab64(x) bswap_64(x)
+
+#define cpu_to_le16(x) ((uint16_t) htole16(x))
+#define cpu_to_le32(x) ((uint32_t) htole32(x))
+#define cpu_to_le64(x) ((uint64_t) htole64(x))
+
+#define cpu_to_be16(x) ((uint16_t) htobe16(x))
+#define cpu_to_be32(x) ((uint32_t) htobe32(x))
+#define cpu_to_be64(x) ((uint64_t) htobe64(x))
+
+#define le16_to_cpu(x) ((uint16_t) le16toh(x))
+#define le32_to_cpu(x) ((uint32_t) le32toh(x))
+#define le64_to_cpu(x) ((uint64_t) le64toh(x))
+
+#define be16_to_cpu(x) ((uint16_t) be16toh(x))
+#define be32_to_cpu(x) ((uint32_t) be32toh(x))
+#define be64_to_cpu(x) ((uint64_t) be64toh(x))
+
+/*
+ * Bit map related macros. Usually provided by libc.
+ */
 #ifndef NBBY
 # define NBBY            CHAR_BIT
 #endif
 # define isclr(a,i)    (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
 #endif
 
-/*
- * Byte swab macros (based on linux/byteorder/swab.h)
- */
-#define swab16(x) \
-       ((uint16_t)( \
-               (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
-               (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) ))
-
-#define swab32(x) \
-       ((uint32_t)( \
-               (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
-               (((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) | \
-               (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >>  8) | \
-               (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) ))
-
-#define swab64(x) \
-       ((uint64_t)( \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) <<  8) | \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >>  8) | \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
-               (uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
-
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-
-#define cpu_to_le16(x) swab16(x)
-#define cpu_to_le32(x) swab32(x)
-#define cpu_to_le64(x) swab64(x)
-#define cpu_to_be16(x) ((uint16_t)(x))
-#define cpu_to_be32(x) ((uint32_t)(x))
-#define cpu_to_be64(x) ((uint64_t)(x))
-
-#define le16_to_cpu(x) swab16(x)
-#define le32_to_cpu(x) swab32(x)
-#define le64_to_cpu(x) swab64(x)
-#define be16_to_cpu(x) ((uint16_t)(x))
-#define be32_to_cpu(x) ((uint32_t)(x))
-#define be64_to_cpu(x) ((uint64_t)(x))
-
-#else /* !WORDS_BIGENDIAN */
-
-#define cpu_to_le16(x) ((uint16_t)(x))
-#define cpu_to_le32(x) ((uint32_t)(x))
-#define cpu_to_le64(x) ((uint64_t)(x))
-#define cpu_to_be16(x) swab16(x)
-#define cpu_to_be32(x) swab32(x)
-#define cpu_to_be64(x) swab64(x)
-
-#define le16_to_cpu(x) ((uint16_t)(x))
-#define le32_to_cpu(x) ((uint32_t)(x))
-#define le64_to_cpu(x) ((uint64_t)(x))
-#define be16_to_cpu(x) swab16(x)
-#define be32_to_cpu(x) swab32(x)
-#define be64_to_cpu(x) swab64(x)
-
-#endif /* WORDS_BIGENDIAN */
-
 #endif /* BITOPS_H */
 
index 6b18879761c3fef1ac924af12f93aa718ebb82f2..c994795a2ac1e2ab4b7eab70b42cf7e85b0b0012 100644 (file)
@@ -1,3 +1,9 @@
+/*
+ * No copyright is claimed.  This code is in the public domain; do with
+ * it what you wish.
+ *
+ * Written by Karel Zak <kzak@redhat.com>
+ */
 #ifndef BLKDEV_H
 #define BLKDEV_H
 
@@ -16,7 +22,7 @@
 #define DEFAULT_SECTOR_SIZE       512
 
 #ifdef __linux__
-/* very basic ioclts, should be available everywhere */
+/* very basic ioctls, should be available everywhere */
 # ifndef BLKROSET
 #  define BLKROSET   _IO(0x12,93)      /* set device read-only (0 = read-write) */
 #  define BLKROGET   _IO(0x12,94)      /* get read-only status (0 = read_write) */
 #  define FITHAW     _IOWR('X', 120, int)    /* Thaw */
 # endif
 
+/* uniform CD-ROM information */
+# ifndef CDROM_GET_CAPABILITY
+#  define CDROM_GET_CAPABILITY 0x5331
+# endif
+
 #endif /* __linux */
 
+
 #ifdef APPLE_DARWIN
 # define BLKGETSIZE DKIOCGETBLOCKCOUNT32
 #endif
 #  define HDIO_GETGEO 0x0301
 # endif
 
-/* uniform CD-ROM information */
-#ifndef CDROM_GET_CAPABILITY
-# define CDROM_GET_CAPABILITY 0x5331
-#endif
-
 struct hd_geometry {
        unsigned char heads;
        unsigned char sectors;
        unsigned short cylinders;       /* truncated */
        unsigned long start;
 };
-#endif
+#endif /* HDIO_GETGEO */
+
 
 /* are we working with block device? */
 int is_blkdev(int fd);
@@ -110,4 +118,29 @@ int blkdev_get_physector_size(int fd, int *sector_size);
 /* is the device cdrom capable? */
 int blkdev_is_cdrom(int fd);
 
+/* get device's geometry - legacy */
+int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s);
+
+/* SCSI device types.  Copied almost as-is from kernel header.
+ * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/scsi/scsi.h */
+#define SCSI_TYPE_DISK                 0x00
+#define SCSI_TYPE_TAPE                 0x01
+#define SCSI_TYPE_PRINTER              0x02
+#define SCSI_TYPE_PROCESSOR            0x03    /* HP scanners use this */
+#define SCSI_TYPE_WORM                 0x04    /* Treated as ROM by our system */
+#define SCSI_TYPE_ROM                  0x05
+#define SCSI_TYPE_SCANNER              0x06
+#define SCSI_TYPE_MOD                  0x07    /* Magneto-optical disk - treated as SCSI_TYPE_DISK */
+#define SCSI_TYPE_MEDIUM_CHANGER       0x08
+#define SCSI_TYPE_COMM                 0x09    /* Communications device */
+#define SCSI_TYPE_RAID                 0x0c
+#define SCSI_TYPE_ENCLOSURE            0x0d    /* Enclosure Services Device */
+#define SCSI_TYPE_RBC                  0x0e
+#define SCSI_TYPE_OSD                  0x11
+#define SCSI_TYPE_NO_LUN               0x7f
+
+/* convert scsi type code to name */
+const char *blkdev_scsi_type_to_name(int type);
+
+
 #endif /* BLKDEV_H */
index 9ecfa6b04e97b87a2aa56d46f8139481e345e4a4..799e699161421e25ba4a5bb46c8b49d4d0452858 100644 (file)
@@ -17,7 +17,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef _BLKID_BLKID_H
 #include <stdint.h>
 #include <sys/types.h>
 
-#include "libblkid-tiny.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define BLKID_VERSION   "2.21.0"
-#define BLKID_DATE      "25-May-2012"
+#define BLKID_VERSION   "2.27.0"
+#define BLKID_DATE      "07-Sep-2015"
 
 /**
  * blkid_dev:
@@ -122,13 +120,32 @@ typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
 #define BLKID_DEV_VERIFY       0x0002
 #define BLKID_DEV_NORMAL       (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
 
+
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+#  define __GNUC_PREREQ(maj, min)  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+#  define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
+#ifndef __ul_attribute__
+# if __GNUC_PREREQ (3, 4)
+#  define __ul_attribute__(_a_) __attribute__(_a_)
+# else
+#  define __ul_attribute__(_a_)
+# endif
+#endif
+
 /* cache.c */
+extern void blkid_init_debug(int mask);
 extern void blkid_put_cache(blkid_cache cache);
 extern int blkid_get_cache(blkid_cache *cache, const char *filename);
 extern void blkid_gc_cache(blkid_cache cache);
 
 /* dev.c */
-extern const char *blkid_dev_devname(blkid_dev dev);
+extern const char *blkid_dev_devname(blkid_dev dev)
+                       __ul_attribute__((warn_unused_result));
 
 extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
 extern int blkid_dev_set_search(blkid_dev_iterate iter,
@@ -137,16 +154,18 @@ extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
 extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
 
 /* devno.c */
-extern char *blkid_devno_to_devname(dev_t devno);
+extern char *blkid_devno_to_devname(dev_t devno)
+                       __ul_attribute__((warn_unused_result));
 extern int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
-                        size_t len, dev_t *diskdevno);
+                        size_t len, dev_t *diskdevno)
+                       __ul_attribute__((warn_unused_result));
 
 /* devname.c */
 extern int blkid_probe_all(blkid_cache cache);
 extern int blkid_probe_all_new(blkid_cache cache);
 extern int blkid_probe_all_removable(blkid_cache cache);
-extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname,
-                              int flags);
+
+extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags);
 
 /* getsize.c */
 extern blkid_loff_t blkid_get_dev_size(int fd);
@@ -158,25 +177,28 @@ extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
 
 /* resolve.c */
 extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
-                                      const char *devname);
+                                      const char *devname)
+                       __ul_attribute__((warn_unused_result));
 extern char *blkid_get_devname(blkid_cache cache, const char *token,
-                              const char *value);
+                              const char *value)
+                       __ul_attribute__((warn_unused_result));
 
 /* tag.c */
 extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
 extern int blkid_tag_next(blkid_tag_iterate iterate,
                              const char **type, const char **value);
 extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
-extern int blkid_dev_has_tag(blkid_dev dev, const char *type,
-                            const char *value);
+extern int blkid_dev_has_tag(blkid_dev dev, const char *type, const char *value);
+
 extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
                                         const char *type,
                                         const char *value);
-extern int blkid_parse_tag_string(const char *token, char **ret_type,
-                                 char **ret_val);
+
+extern int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val);
 
 /* version.c */
-extern int blkid_parse_version_string(const char *ver_string);
+extern int blkid_parse_version_string(const char *ver_string)
+                       __ul_attribute__((nonnull));
 extern int blkid_get_library_version(const char **ver_string,
                                     const char **date_string);
 
@@ -187,21 +209,31 @@ extern int blkid_safe_string(const char *str, char *str_safe, size_t len);
 /* evaluate.c */
 extern int blkid_send_uevent(const char *devname, const char *action);
 extern char *blkid_evaluate_tag(const char *token, const char *value,
-                               blkid_cache *cache);
-extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache);
+                               blkid_cache *cache)
+                       __ul_attribute__((warn_unused_result));
+extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
+                       __ul_attribute__((warn_unused_result));
 
 /* probe.c */
-extern blkid_probe blkid_new_probe(void);
-extern blkid_probe blkid_new_probe_from_filename(const char *filename);
+extern blkid_probe blkid_new_probe(void)
+                       __ul_attribute__((warn_unused_result));
+extern blkid_probe blkid_new_probe_from_filename(const char *filename)
+                       __ul_attribute__((warn_unused_result));
 extern void blkid_free_probe(blkid_probe pr);
+
 extern void blkid_reset_probe(blkid_probe pr);
 
 extern int blkid_probe_set_device(blkid_probe pr, int fd,
                        blkid_loff_t off, blkid_loff_t size);
 
-extern dev_t blkid_probe_get_devno(blkid_probe pr);
-extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr);
-extern int blkid_probe_is_wholedisk(blkid_probe pr);
+extern dev_t blkid_probe_get_devno(blkid_probe pr)
+                       __ul_attribute__((nonnull));
+
+extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
+                       __ul_attribute__((nonnull));
+
+extern int blkid_probe_is_wholedisk(blkid_probe pr)
+                       __ul_attribute__((nonnull));
 
 extern blkid_loff_t blkid_probe_get_size(blkid_probe pr);
 extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr);
@@ -214,6 +246,7 @@ extern int blkid_probe_get_fd(blkid_probe pr);
  * superblocks probing
  */
 extern int blkid_known_fstype(const char *fstype);
+
 extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);
 
 extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);
@@ -227,12 +260,12 @@ extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);
 #define BLKID_SUBLKS_USAGE     (1 << 7) /* define USAGE result value */
 #define BLKID_SUBLKS_VERSION   (1 << 8) /* read FS type from superblock */
 #define BLKID_SUBLKS_MAGIC     (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
+#define BLKID_SUBLKS_BADCSUM   (1 << 10) /* allow a bad checksum */
 
 #define BLKID_SUBLKS_DEFAULT   (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
                                 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
 
 extern int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags);
-
 extern int blkid_probe_reset_superblocks_filter(blkid_probe pr);
 extern int blkid_probe_invert_superblocks_filter(blkid_probe pr);
 
@@ -260,23 +293,28 @@ extern int blkid_probe_enable_topology(blkid_probe pr, int enable);
 /* binary interface */
 extern blkid_topology blkid_probe_get_topology(blkid_probe pr);
 
-extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp);
-extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp);
-extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp);
-extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp);
-extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp);
+extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
+                       __ul_attribute__((nonnull));
+extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
+                       __ul_attribute__((nonnull));
+extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
+                       __ul_attribute__((nonnull));
+extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
+                       __ul_attribute__((nonnull));
+extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
+                       __ul_attribute__((nonnull));
 
 /*
  * partitions probing
  */
 extern int blkid_known_pttype(const char *pttype);
+
 extern int blkid_probe_enable_partitions(blkid_probe pr, int enable);
 
 extern int blkid_probe_reset_partitions_filter(blkid_probe pr);
 extern int blkid_probe_invert_partitions_filter(blkid_probe pr);
 extern int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[]);
 
-
 /* partitions probing flags */
 #define BLKID_PARTS_FORCE_GPT          (1 << 1)
 #define BLKID_PARTS_ENTRY_DETAILS      (1 << 2)
@@ -289,22 +327,34 @@ extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr);
 extern int blkid_partlist_numof_partitions(blkid_partlist ls);
 extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls);
 extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n);
+extern blkid_partition blkid_partlist_get_partition_by_partno(blkid_partlist ls, int n);
 extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno);
-
 extern blkid_parttable blkid_partition_get_table(blkid_partition par);
+
 extern const char *blkid_partition_get_name(blkid_partition par);
 extern const char *blkid_partition_get_uuid(blkid_partition par);
 extern int blkid_partition_get_partno(blkid_partition par);
 extern blkid_loff_t blkid_partition_get_start(blkid_partition par);
 extern blkid_loff_t blkid_partition_get_size(blkid_partition par);
-extern int blkid_partition_get_type(blkid_partition par);
+
+extern int blkid_partition_get_type(blkid_partition par)
+                       __ul_attribute__((nonnull));
+
 extern const char *blkid_partition_get_type_string(blkid_partition par);
-extern unsigned long long blkid_partition_get_flags(blkid_partition par);
-extern int blkid_partition_is_logical(blkid_partition par);
-extern int blkid_partition_is_extended(blkid_partition par);
-extern int blkid_partition_is_primary(blkid_partition par);
+
+extern unsigned long long blkid_partition_get_flags(blkid_partition par)
+                       __ul_attribute__((nonnull));
+
+extern int blkid_partition_is_logical(blkid_partition par)
+                       __ul_attribute__((nonnull));
+extern int blkid_partition_is_extended(blkid_partition par)
+                       __ul_attribute__((nonnull));
+extern int blkid_partition_is_primary(blkid_partition par)
+                       __ul_attribute__((nonnull));
 
 extern const char *blkid_parttable_get_type(blkid_parttable tab);
+extern const char *blkid_parttable_get_id(blkid_parttable tab);
+
 extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab);
 extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab);
 
@@ -320,9 +370,11 @@ extern int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
                         const char **data, size_t *len);
 extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
                         const char **data, size_t *len);
-extern int blkid_probe_has_value(blkid_probe pr, const char *name);
+extern int blkid_probe_has_value(blkid_probe pr, const char *name)
+                       __ul_attribute__((nonnull));
 
 extern int blkid_do_wipe(blkid_probe pr, int dryrun);
+extern int blkid_probe_step_back(blkid_probe pr);
 
 /*
  * Deprecated functions/macros
@@ -338,11 +390,20 @@ extern int blkid_do_wipe(blkid_probe pr, int dryrun);
 #define BLKID_PROBREQ_USAGE     BLKID_SUBLKS_USAGE
 #define BLKID_PROBREQ_VERSION   BLKID_SUBLKS_VERSION
 
-extern int blkid_probe_set_request(blkid_probe pr, int flags);
-extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage);
-extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[]);
-extern int blkid_probe_invert_filter(blkid_probe pr);
-extern int blkid_probe_reset_filter(blkid_probe pr);
+extern int blkid_probe_set_request(blkid_probe pr, int flags)
+                       __ul_attribute__((deprecated));
+
+extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
+                       __ul_attribute__((deprecated));
+
+extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
+                       __ul_attribute__((deprecated));
+
+extern int blkid_probe_invert_filter(blkid_probe pr)
+                       __ul_attribute__((deprecated));
+
+extern int blkid_probe_reset_filter(blkid_probe pr)
+                       __ul_attribute__((deprecated));
 
 #endif /* BLKID_DISABLE_DEPRECATED */
 
index 0f372a59bd5b751f3f72707af1e7532ace4ce99b..1ba76738b90521d7edf2d7a0b2596747228a1092 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
index a95bd2186dc56edf97088072d6f8584d04eb3a87..7ce3dfff86d643ca52a3fb917a09a4b30606ba2f 100644 (file)
@@ -90,3 +90,4 @@ const struct blkid_idinfo btrfs_idinfo =
          { NULL }
        }
 };
+
index 8c8db73324b590152b70c2e1cdd08fd67be7710e..ee5da87907ac589a235e5bffd653448d0287c393 100644 (file)
@@ -9,17 +9,20 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 
+#include <assert.h>
+
 #ifdef HAVE_ERR_H
 # include <err.h>
 #endif
 
 /*
- * Compiler specific stuff
+ * Compiler-specific stuff
  */
 #ifndef __GNUC_PREREQ
 # if defined __GNUC__ && defined __GNUC_MINOR__
@@ -36,7 +39,7 @@
 # define __must_be_array(a) \
        UL_BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a), __typeof__(&a[0])))
 
-# define ignore_result(x) ({ \
+# define ignore_result(x) __extension__ ({ \
        __typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
 })
 
@@ -51,7 +54,7 @@
  */
 #ifndef __ul_alloc_size
 # if __GNUC_PREREQ (4, 3)
-#  define __ul_alloc_size(s) __attribute__((alloc_size(s)))
+#  define __ul_alloc_size(s) __attribute__((alloc_size(s), warn_unused_result))
 # else
 #  define __ul_alloc_size(s)
 # endif
 
 #ifndef __ul_calloc_size
 # if __GNUC_PREREQ (4, 3)
-#  define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s)))
+#  define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s), warn_unused_result))
 # else
 #  define __ul_calloc_size(n, s)
 # endif
 #endif
 
-/* Force a compilation error if condition is true, but also produce a
+/*
+ * Force a compilation error if condition is true, but also produce a
  * result (of value 0 and type size_t), so the expression can be used
- * e.g. in a structure initializer (or where-ever else comma expressions
+ * e.g. in a structure initializer (or wherever else comma expressions
  * aren't permitted).
  */
-#define UL_BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+#define UL_BUILD_BUG_ON_ZERO(e) __extension__ (sizeof(struct { int:-!!(e); }))
 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
 
 #ifndef ARRAY_SIZE
@@ -90,7 +94,7 @@
 #endif
 
 #ifndef min
-# define min(x, y) ({                          \
+# define min(x, y) __extension__ ({            \
        __typeof__(x) _min1 = (x);              \
        __typeof__(y) _min2 = (y);              \
        (void) (&_min1 == &_min2);              \
 #endif
 
 #ifndef max
-# define max(x, y) ({                          \
+# define max(x, y) __extension__ ({            \
        __typeof__(x) _max1 = (x);              \
        __typeof__(y) _max2 = (y);              \
        (void) (&_max1 == &_max2);              \
        _max1 > _max2 ? _max1 : _max2; })
 #endif
 
+#ifndef cmp_numbers
+# define cmp_numbers(x, y) __extension__ ({    \
+       __typeof__(x) _a = (x);                 \
+       __typeof__(y) _b = (y);                 \
+       (void) (&_a == &_b);                    \
+       _a == _b ? 0 : _a > _b ? 1 : -1; })
+#endif
+
 #ifndef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
 
 #ifndef container_of
-#define container_of(ptr, type, member) ({                       \
+#define container_of(ptr, type, member) __extension__ ({        \
        const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
        (type *)( (char *)__mptr - offsetof(type,member) );})
 #endif
@@ -210,10 +222,24 @@ static inline int dirfd(DIR *d)
  * Fallback defines for old versions of glibc
  */
 #include <fcntl.h>
+
+#ifdef O_CLOEXEC
+#define UL_CLOEXECSTR  "e"
+#else
+#define UL_CLOEXECSTR  ""
+#endif
+
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 0
 #endif
 
+#ifdef __FreeBSD_kernel__
+#ifndef F_DUPFD_CLOEXEC
+#define F_DUPFD_CLOEXEC        17      /* Like F_DUPFD, but FD_CLOEXEC is set */
+#endif
+#endif
+
+
 #ifndef AI_ADDRCONFIG
 #define AI_ADDRCONFIG 0x0020
 #endif
@@ -222,13 +248,55 @@ static inline int dirfd(DIR *d)
 #define IUTF8 0040000
 #endif
 
+#if 0
+/*
+ * MAXHOSTNAMELEN replacement
+ */
+static inline size_t get_hostname_max(void)
+{
+       long len = sysconf(_SC_HOST_NAME_MAX);
+
+       if (0 < len)
+               return len;
+
+#ifdef MAXHOSTNAMELEN
+       return MAXHOSTNAMELEN;
+#elif HOST_NAME_MAX
+       return HOST_NAME_MAX;
+#endif
+       return 64;
+}
+
+/*
+ * The usleep function was marked obsolete in POSIX.1-2001 and was removed
+ * in POSIX.1-2008.  It was replaced with nanosleep() that provides more
+ * advantages (like no interaction with signals and other timer functions).
+ */
+#include <time.h>
+
+static inline int xusleep(useconds_t usec)
+{
+#ifdef HAVE_NANOSLEEP
+       struct timespec waittime = {
+               .tv_sec   =  usec / 1000000L,
+               .tv_nsec  = (usec % 1000000L) * 1000
+       };
+       return nanosleep(&waittime, NULL);
+#elif defined(HAVE_USLEEP)
+       return usleep(usec);
+#else
+# error        "System with usleep() or nanosleep() required!"
+#endif
+}
+#endif
+
 /*
  * Constant strings for usage() functions. For more info see
- * Documentation/howto-usage-function.txt and sys-utils/arch.c
+ * Documentation/howto-usage-function.txt and disk-utils/delpart.c
  */
 #define USAGE_HEADER     _("\nUsage:\n")
 #define USAGE_OPTIONS    _("\nOptions:\n")
-#define USAGE_SEPARATOR  _("\n")
+#define USAGE_SEPARATOR    "\n"
 #define USAGE_HELP       _(" -h, --help     display this help and exit\n")
 #define USAGE_VERSION    _(" -V, --version  output version information and exit\n")
 #define USAGE_MAN_TAIL(_man)   _("\nFor more details see %s.\n"), _man
@@ -244,4 +312,40 @@ static inline int dirfd(DIR *d)
 #define UL_SCNsA       "%as"
 #endif
 
+/*
+ * seek stuff
+ */
+#ifndef SEEK_DATA
+# define SEEK_DATA     3
+#endif
+#ifndef SEEK_HOLE
+# define SEEK_HOLE     4
+#endif
+
+
+/*
+ * Macros to convert #define'itions to strings, for example
+ * #define XYXXY 42
+ * printf ("%s=%s\n", stringify(XYXXY), stringify_value(XYXXY));
+ */
+#define stringify_value(s) stringify(s)
+#define stringify(s) #s
+
+/*
+ * UL_ASAN_BLACKLIST is a macro to tell AddressSanitizer (a compile-time
+ * instrumentation shipped with Clang and GCC) to not instrument the
+ * annotated function.  Furthermore, it will prevent the compiler from
+ * inlining the function because inlining currently breaks the blacklisting
+ * mechanism of AddressSanitizer.
+ */
+#if defined(__has_feature)
+# if __has_feature(address_sanitizer)
+#  define UL_ASAN_BLACKLIST __attribute__((noinline)) __attribute__((no_sanitize_memory)) __attribute__((no_sanitize_address))
+# else
+#  define UL_ASAN_BLACKLIST    /* nothing */
+# endif
+#else
+# define UL_ASAN_BLACKLIST     /* nothing */
+#endif
+
 #endif /* UTIL_LINUX_C_H */
index 687127da05694c4b8fd8c6b32ff229078995b0c2..ecad9f0455ce160bfb631c55395fb70e1c3c7b39 100644 (file)
@@ -18,7 +18,6 @@
 #endif
 #include <time.h>
 
-#include "linux_version.h"
 #include "superblocks.h"
 
 struct ext2_super_block {
@@ -131,132 +130,12 @@ struct ext2_super_block {
 #define EXT3_FEATURE_INCOMPAT_UNSUPPORTED      ~EXT3_FEATURE_INCOMPAT_SUPP
 #define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED     ~EXT3_FEATURE_RO_COMPAT_SUPP
 
-/*
- * Check to see if a filesystem is in /proc/filesystems.
- * Returns 1 if found, 0 if not
- */
-static int fs_proc_check(const char *fs_name)
-{
-       FILE    *f;
-       char    buf[80], *cp, *t;
-
-       f = fopen("/proc/filesystems", "r");
-       if (!f)
-               return 0;
-       while (!feof(f)) {
-               if (!fgets(buf, sizeof(buf), f))
-                       break;
-               cp = buf;
-               if (!isspace(*cp)) {
-                       while (*cp && !isspace(*cp))
-                               cp++;
-               }
-               while (*cp && isspace(*cp))
-                       cp++;
-               if ((t = strchr(cp, '\n')) != NULL)
-                       *t = 0;
-               if ((t = strchr(cp, '\t')) != NULL)
-                       *t = 0;
-               if ((t = strchr(cp, ' ')) != NULL)
-                       *t = 0;
-               if (!strcmp(fs_name, cp)) {
-                       fclose(f);
-                       return 1;
-               }
-       }
-       fclose(f);
-       return (0);
-}
-
-/*
- * Check to see if a filesystem is available as a module
- * Returns 1 if found, 0 if not
- */
-static int check_for_modules(const char *fs_name)
-{
-#ifdef __linux__
-       struct utsname  uts;
-       FILE            *f;
-       char            buf[1024], *cp;
-       int             namesz;
-
-       if (uname(&uts))
-               return 0;
-       snprintf(buf, sizeof(buf), "/lib/modules/%s/modules.dep", uts.release);
-
-       f = fopen(buf, "r");
-       if (!f)
-               return 0;
-
-       namesz = strlen(fs_name);
-
-       while (!feof(f)) {
-               if (!fgets(buf, sizeof(buf), f))
-                       break;
-               if ((cp = strchr(buf, ':')) != NULL)
-                       *cp = 0;
-               else
-                       continue;
-               if ((cp = strrchr(buf, '/')) == NULL)
-                       continue;
-               cp++;
-
-               if (!strncmp(cp, fs_name, namesz) &&
-                   (!strcmp(cp + namesz, ".ko") ||
-                    !strcmp(cp + namesz, ".ko.gz"))) {
-                       fclose(f);
-                       return 1;
-               }
-       }
-       fclose(f);
-#endif /* __linux__ */
-       return 0;
-}
-
 /*
  * Starting in 2.6.29, ext4 can be used to support filesystems
  * without a journal.
  */
 #define EXT4_SUPPORTS_EXT2 KERNEL_VERSION(2, 6, 29)
 
-static int system_supports_ext2(void)
-{
-       static time_t   last_check = 0;
-       static int      ret = -1;
-       time_t          now = time(0);
-
-       if (ret != -1 || (now - last_check) < 5)
-               return ret;
-       last_check = now;
-       ret = (fs_proc_check("ext2") || check_for_modules("ext2"));
-       return ret;
-}
-
-static int system_supports_ext4(void)
-{
-       static time_t   last_check = 0;
-       static int      ret = -1;
-       time_t          now = time(0);
-
-       if (ret != -1 || (now - last_check) < 5)
-               return ret;
-       last_check = now;
-       ret = (fs_proc_check("ext4") || check_for_modules("ext4"));
-       return ret;
-}
-
-static int system_supports_ext4dev(void)
-{
-       static time_t   last_check = 0;
-       static int      ret = -1;
-       time_t          now = time(0);
-
-       if (ret != -1 || (now - last_check) < 5)
-               return ret;
-       last_check = now;
-       ret = (fs_proc_check("ext4dev") || check_for_modules("ext4dev"));
-       return ret;
-}
 /*
  * reads superblock and returns:
  *     fc = feature_compat
@@ -284,9 +163,11 @@ static struct ext2_super_block *ext_get_super(
 
 static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
 {
-       //struct blkid_chain *chn = blkid_probe_get_chain(pr);
+#if 0
+       struct blkid_chain *chn = blkid_probe_get_chain(pr);
+#endif
 
-       DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
+       DBG(PROBE, ul_debug("ext2_sb.compat = %08X:%08X:%08X",
                   le32_to_cpu(es->s_feature_compat),
                   le32_to_cpu(es->s_feature_incompat),
                   le32_to_cpu(es->s_feature_ro_compat)));
@@ -299,11 +180,13 @@ static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
        if (le32_to_cpu(es->s_feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL)
                blkid_probe_set_uuid_as(pr, es->s_journal_uuid, "EXT_JOURNAL");
 
-/*     if (ver != 2 && (chn->flags & BLKID_SUBLKS_SECTYPE) &&
+#if 0
+       if (ver != 2 && (chn->flags & BLKID_SUBLKS_SECTYPE) &&
            ((le32_to_cpu(es->s_feature_incompat) & EXT2_FEATURE_INCOMPAT_UNSUPPORTED) == 0))
                blkid_probe_set_value(pr, "SEC_TYPE",
                                (unsigned char *) "ext2",
-                               sizeof("ext2"));*/
+                               sizeof("ext2"));
+#endif
 
        blkid_probe_sprintf_version(pr, "%u.%u",
                le32_to_cpu(es->s_rev_level),
@@ -319,11 +202,13 @@ static int probe_jbd(blkid_probe pr,
 
        es = ext_get_super(pr, NULL, &fi, NULL);
        if (!es)
-               return -BLKID_ERR_PARAM;
+               return errno ? -errno : 1;
        if (!(fi & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV))
-               return -BLKID_ERR_PARAM;
+               return 1;
 
        ext_get_info(pr, 2, es);
+       blkid_probe_set_uuid_as(pr, es->s_uuid, "LOGUUID");
+
        return 0;
 }
 
@@ -335,25 +220,16 @@ static int probe_ext2(blkid_probe pr,
 
        es = ext_get_super(pr, &fc, &fi, &frc);
        if (!es)
-               return -BLKID_ERR_PARAM;
+               return errno ? -errno : 1;
 
        /* Distinguish between ext3 and ext2 */
        if (fc & EXT3_FEATURE_COMPAT_HAS_JOURNAL)
-               return -BLKID_ERR_PARAM;
+               return 1;
 
        /* Any features which ext2 doesn't understand */
        if ((frc & EXT2_FEATURE_RO_COMPAT_UNSUPPORTED) ||
            (fi  & EXT2_FEATURE_INCOMPAT_UNSUPPORTED))
-               return -BLKID_ERR_PARAM;
-
-       /*
-        * If ext2 is not present, but ext4 or ext4dev are, then
-        * disclaim we are ext2
-        */
-       if (!system_supports_ext2() &&
-           (system_supports_ext4() || system_supports_ext4dev()) &&
-           get_linux_version() >= EXT4_SUPPORTS_EXT2)
-               return -BLKID_ERR_PARAM;
+               return 1;
 
        ext_get_info(pr, 2, es);
        return 0;
@@ -367,16 +243,16 @@ static int probe_ext3(blkid_probe pr,
 
        es = ext_get_super(pr, &fc, &fi, &frc);
        if (!es)
-               return -BLKID_ERR_PARAM;
+               return errno ? -errno : 1;
 
        /* ext3 requires journal */
        if (!(fc & EXT3_FEATURE_COMPAT_HAS_JOURNAL))
-               return -BLKID_ERR_PARAM;
+               return 1;
 
        /* Any features which ext3 doesn't understand */
        if ((frc & EXT3_FEATURE_RO_COMPAT_UNSUPPORTED) ||
            (fi  & EXT3_FEATURE_INCOMPAT_UNSUPPORTED))
-               return -BLKID_ERR_PARAM;
+               return 1;
 
        ext_get_info(pr, 3, es);
        return 0;
@@ -391,40 +267,15 @@ static int probe_ext4dev(blkid_probe pr,
 
        es = ext_get_super(pr, &fc, &fi, &frc);
        if (!es)
-               return -BLKID_ERR_PARAM;
+               return errno ? -errno : 1;
 
        /* Distinguish from jbd */
        if (fi & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
-               return -BLKID_ERR_PARAM;
-
-       /*
-        * If the filesystem does not have a journal and ext2 and ext4
-        * is not present, then force this to be detected as an
-        * ext4dev filesystem.
-        */
-       if (!(fc & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
-           !system_supports_ext2() && !system_supports_ext4() &&
-           system_supports_ext4dev() &&
-           get_linux_version() >= EXT4_SUPPORTS_EXT2)
-               goto force_ext4dev;
+               return 1;
 
-       /*
-        * If the filesystem is marked as OK for use by in-development
-        * filesystem code, but ext4dev is not supported, and ext4 is,
-        * then don't call ourselves ext4dev, since we should be
-        * detected as ext4 in that case.
-        *
-        * If the filesystem is marked as in use by production
-        * filesystem, then it can only be used by ext4 and NOT by
-        * ext4dev, so always disclaim we are ext4dev in that case.
-        */
-       if (le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS) {
-               if (!system_supports_ext4dev() && system_supports_ext4())
-                       return -BLKID_ERR_PARAM;
-       } else
-               return -BLKID_ERR_PARAM;
+       if (!(le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS))
+               return 1;
 
-force_ext4dev:
        ext_get_info(pr, 4, es);
        return 0;
 }
@@ -437,28 +288,17 @@ static int probe_ext4(blkid_probe pr,
 
        es = ext_get_super(pr, &fc, &fi, &frc);
        if (!es)
-               return -1;
+               return errno ? -errno : 1;
 
        /* Distinguish from jbd */
        if (fi & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
-               return -BLKID_ERR_PARAM;
-
-       /*
-        * If the filesystem does not have a journal and ext2 is not
-        * present, then force this to be detected as an ext2
-        * filesystem.
-        */
-       if (!(fc & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
-           !system_supports_ext2() && system_supports_ext4() &&
-           get_linux_version() >= EXT4_SUPPORTS_EXT2)
-               goto force_ext4;
+               return 1;
 
        /* Ext4 has at least one feature which ext3 doesn't understand */
        if (!(frc & EXT3_FEATURE_RO_COMPAT_UNSUPPORTED) &&
            !(fi  & EXT3_FEATURE_INCOMPAT_UNSUPPORTED))
-               return -BLKID_ERR_PARAM;
+               return 1;
 
-force_ext4:
        /*
         * If the filesystem is a OK for use by in-development
         * filesystem code, and ext4dev is supported or ext4 is not
@@ -469,10 +309,8 @@ force_ext4:
         * filesystem, then it can only be used by ext4 and NOT by
         * ext4dev.
         */
-       if (le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS) {
-               if (system_supports_ext4dev() || !system_supports_ext4())
-                       return -BLKID_ERR_PARAM;
-       }
+       if (le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS)
+               return 1;
 
        ext_get_info(pr, 4, es);
        return 0;
index 1398e3879946d3ce6dc66195f7c6c4c1f23908e5..8676d36ef6655860cc26438f4776147d6d563332 100644 (file)
 #include <inttypes.h>
 
 #include "superblocks.h"
-//#include "md5.h"
+
+#if 0
+#include "md5.h"
+#endif
 
 /* HFS / HFS+ */
 struct hfs_finder_info {
@@ -130,7 +133,8 @@ struct hfsplus_vol_header {
 
 static int hfs_set_uuid(blkid_probe pr, unsigned char const *hfs_info, size_t len)
 {
-/*     static unsigned char const hash_init[MD5LENGTH] = {
+#if 0
+       static unsigned char const hash_init[MD5LENGTH] = {
                0xb3, 0xe2, 0x0f, 0x39, 0xf2, 0x92, 0x11, 0xd6,
                0x97, 0xa4, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac
        };
@@ -145,8 +149,10 @@ static int hfs_set_uuid(blkid_probe pr, unsigned char const *hfs_info, size_t le
        MD5Final(uuid, &md5c);
        uuid[6] = 0x30 | (uuid[6] & 0x0f);
        uuid[8] = 0x80 | (uuid[8] & 0x3f);
-       return blkid_probe_set_uuid(pr, uuid);*/
-       return -1;
+       return blkid_probe_set_uuid(pr, uuid);
+#else
+       return -ENOSYS;
+#endif
 }
 
 static int probe_hfs(blkid_probe pr, const struct blkid_idmag *mag)
@@ -155,7 +161,7 @@ static int probe_hfs(blkid_probe pr, const struct blkid_idmag *mag)
 
        hfs = blkid_probe_get_sb(pr, mag, struct hfs_mdb);
        if (!hfs)
-               return -1;
+               return errno ? -errno : 1;
 
        if ((memcmp(hfs->embed_sig, "H+", 2) == 0) ||
            (memcmp(hfs->embed_sig, "HX", 2) == 0))
@@ -194,7 +200,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
 
        sbd = blkid_probe_get_sb(pr, mag, struct hfs_mdb);
        if (!sbd)
-               return -1;
+               return errno ? -errno : 1;
 
        /* Check for a HFS+ volume embedded in a HFS volume */
        if (memcmp(sbd->signature, "BD", 2) == 0) {
@@ -219,7 +225,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
                                struct hfsplus_vol_header);
 
        if (!hfsplus)
-               return -1;
+               return errno ? -errno : 1;
 
        if ((memcmp(hfsplus->signature, "H+", 2) != 0) &&
            (memcmp(hfsplus->signature, "HX", 2) != 0))
@@ -229,7 +235,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
 
        blocksize = be32_to_cpu(hfsplus->blocksize);
        if (blocksize < HFSPLUS_SECTOR_SIZE)
-               return -1;
+               return 1;
 
        memcpy(extents, hfsplus->cat_file.extents, sizeof(extents));
        cat_block = be32_to_cpu(extents[0].start_block);
@@ -237,7 +243,7 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
        buf = blkid_probe_get_buffer(pr,
                        off + ((blkid_loff_t) cat_block * blocksize), 0x2000);
        if (!buf)
-               return 0;
+               return errno ? -errno : 0;
 
        bnode = (struct hfsplus_bheader_record *)
                &buf[sizeof(struct hfsplus_bnode_descriptor)];
@@ -266,13 +272,13 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
        if (ext == HFSPLUS_EXTENT_COUNT)
                return 0;
 
-       leaf_off = (ext_block_start + leaf_block) * blocksize;
+       leaf_off = ((uint64_t) ext_block_start + leaf_block) * blocksize;
 
        buf = blkid_probe_get_buffer(pr,
                                (blkid_loff_t) off + leaf_off,
                                leaf_node_size);
        if (!buf)
-               return 0;
+               return errno ? -errno : 0;
 
        descr = (struct hfsplus_bnode_descriptor *) buf;
        record_count = be16_to_cpu(descr->num_recs);
@@ -288,6 +294,12 @@ static int probe_hfsplus(blkid_probe pr, const struct blkid_idmag *mag)
        if (be32_to_cpu(key->parent_id) != HFSPLUS_POR_CNID)
                return 0;
 
+#if 0
+       blkid_probe_set_utf8label(pr, key->unicode,
+                       be16_to_cpu(key->unicode_len) * 2,
+                       BLKID_ENC_UTF16BE);
+#endif
+
        return 0;
 }
 
index f66f3a1dc16ef3d8d75e8b4092494b0510fb5fb2..7b52468a828500403a4642592a64bf452c1eb699 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <sys/utsname.h>
 
+#include "libblkid-tiny.h"
 #include "superblocks.h"
 #include "linux_version.h"
 
index af12658b36e1812a312584f59357725d6d77fda7..2a54f8b0598388dd6d023c58d3cd06dca1088899 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  */
+#ifndef _LIBBLKID_TINY_H
+#define _LIBBLKID_TINY_H
 
 #include <libubox/list.h>
 
-struct blkid_idmag;
-struct blkid_idmag;
-struct blkid_idinfo;
+struct blkid_struct_probe;
 
+/*
+ * Filesystem / Raid magic strings
+ */
 struct blkid_idmag
 {
-       const char      *magic;
-       unsigned int    len;
+       const char      *magic;         /* magic string */
+       unsigned int    len;            /* length of magic */
 
-       long            kboff;
-       unsigned int    sboff;
+       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 */
 
-struct blkid_idinfo;
+                                       /* probe function */
+       int             (*probefunc)(struct blkid_struct_probe *pr, const struct blkid_idmag *mag);
 
+       struct blkid_idmag      magics[];       /* NULL or array with magic strings */
+};
+
+/* Smaller version of the struct provided in blkidP.h */
 struct blkid_struct_probe
 {
        const struct blkid_idinfo       *id;
@@ -44,15 +61,7 @@ struct blkid_struct_probe
        char    version[64];
 };
 
-struct blkid_idinfo
-{
-       const char      *name;
-       int             usage;
-       int             flags;
-       int             minsz;
-       int (*probefunc)(struct blkid_struct_probe *pr, const struct blkid_idmag *mag);
-       struct blkid_idmag      magics[];
-};
-
 extern int probe_block(char *block, struct blkid_struct_probe *pr);
 extern int mkblkdev(void);
+
+#endif /* _LIBBLKID_TINY_H */
index 24f59bbbb7a284fcb81e90b7beb6520cdf8b94fb..d2b242fb2ff10a377d88f0aac4f28e118458b332 100644 (file)
@@ -29,6 +29,7 @@ extern const struct blkid_idinfo ext2_idinfo;
 extern const struct blkid_idinfo jbd_idinfo;
 extern const struct blkid_idinfo jfs_idinfo;
 extern const struct blkid_idinfo xfs_idinfo;
+extern const struct blkid_idinfo xfs_log_idinfo;
 extern const struct blkid_idinfo gfs_idinfo;
 extern const struct blkid_idinfo gfs2_idinfo;
 extern const struct blkid_idinfo romfs_idinfo;
@@ -40,6 +41,7 @@ extern const struct blkid_idinfo reiser4_idinfo;
 extern const struct blkid_idinfo hfs_idinfo;
 extern const struct blkid_idinfo hfsplus_idinfo;
 extern const struct blkid_idinfo ntfs_idinfo;
+extern const struct blkid_idinfo refs_idinfo;
 extern const struct blkid_idinfo iso9660_idinfo;
 extern const struct blkid_idinfo udf_idinfo;
 extern const struct blkid_idinfo vxfs_idinfo;
@@ -50,10 +52,12 @@ extern const struct blkid_idinfo hpfs_idinfo;
 extern const struct blkid_idinfo lvm2_idinfo;
 extern const struct blkid_idinfo lvm1_idinfo;
 extern const struct blkid_idinfo snapcow_idinfo;
+extern const struct blkid_idinfo verity_hash_idinfo;
 extern const struct blkid_idinfo luks_idinfo;
 extern const struct blkid_idinfo highpoint37x_idinfo;
 extern const struct blkid_idinfo highpoint45x_idinfo;
 extern const struct blkid_idinfo squashfs_idinfo;
+extern const struct blkid_idinfo squashfs3_idinfo;
 extern const struct blkid_idinfo netware_idinfo;
 extern const struct blkid_idinfo sysv_idinfo;
 extern const struct blkid_idinfo xenix_idinfo;
@@ -64,10 +68,13 @@ extern const struct blkid_idinfo bfs_idinfo;
 extern const struct blkid_idinfo vmfs_volume_idinfo;
 extern const struct blkid_idinfo vmfs_fs_idinfo;
 extern const struct blkid_idinfo drbd_idinfo;
+extern const struct blkid_idinfo drbdmanage_idinfo;
 extern const struct blkid_idinfo drbdproxy_datalog_idinfo;
 extern const struct blkid_idinfo befs_idinfo;
 extern const struct blkid_idinfo nilfs2_idinfo;
 extern const struct blkid_idinfo exfat_idinfo;
+extern const struct blkid_idinfo f2fs_idinfo;
+extern const struct blkid_idinfo bcache_idinfo;
 extern const struct blkid_idinfo jffs2_idinfo;
 
 /*
@@ -75,18 +82,22 @@ extern const struct blkid_idinfo jffs2_idinfo;
  */
 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)));
+               __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)));
+               __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_set_id_label(blkid_probe pr, const char *name,
+                            unsigned char *data, size_t len);
+extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
+                            unsigned char *data, size_t len, int enc);
 
 #endif /* _BLKID_SUPERBLOCKS_H */
index a598a7ceeb8801228fea1a56dc6a8993353b8a03..3f21391c8c336c72ec4319d1bccf0a917c191ace 100644 (file)
@@ -44,20 +44,27 @@ static int swap_set_info(blkid_probe pr, const char *version)
        hdr = (struct swap_header_v1_2 *) blkid_probe_get_buffer(pr, 1024,
                                sizeof(struct swap_header_v1_2));
        if (!hdr)
-               return -1;
+               return errno ? -errno : 1;
 
        /* SWAPSPACE2 - check for wrong version or zeroed pagecount */
-       if (strcmp(version, "2") == 0 &&
-               ((hdr->version != 1 && swab32(hdr->version) != 1) || hdr->lastpage == 0))
-               return -1;
+       if (strcmp(version, "1") == 0) {
+               if (hdr->version != 1 && swab32(hdr->version) != 1) {
+                       DBG(LOWPROBE, ul_debug("incorrect swap version"));
+                       return 1;
+               }
+               if (hdr->lastpage == 0) {
+                       DBG(LOWPROBE, ul_debug("not set last swap page"));
+                       return 1;
+               }
+       }
 
        /* arbitrary sanity check.. is there any garbage down there? */
        if (hdr->padding[32] == 0 && hdr->padding[33] == 0) {
                if (hdr->volume[0] && blkid_probe_set_label(pr, hdr->volume,
                                sizeof(hdr->volume)) < 0)
-                       return -1;
+                       return 1;
                if (blkid_probe_set_uuid(pr, hdr->uuid) < 0)
-                       return -1;
+                       return 1;
        }
 
        blkid_probe_set_version(pr, version);
@@ -69,31 +76,31 @@ static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
        unsigned char *buf;
 
        if (!mag)
-               return -1;
+               return 1;
 
        /* TuxOnIce keeps valid swap header at the end of the 1st page */
        buf = blkid_probe_get_buffer(pr, 0, TOI_MAGIC_STRLEN);
        if (!buf)
-               return -1;
+               return errno ? -errno : 1;
 
        if (memcmp(buf, TOI_MAGIC_STRING, TOI_MAGIC_STRLEN) == 0)
                return 1;       /* Ignore swap signature, it's TuxOnIce */
 
        if (!memcmp(mag->magic, "SWAP-SPACE", mag->len)) {
                /* swap v0 doesn't support LABEL or UUID */
-               blkid_probe_set_version(pr, "1");
+               blkid_probe_set_version(pr, "0");
                return 0;
 
        } else if (!memcmp(mag->magic, "SWAPSPACE2", mag->len))
-               return swap_set_info(pr, "2");
+               return swap_set_info(pr, "1");
 
-       return -1;
+       return 1;
 }
 
 static int probe_swsuspend(blkid_probe pr, const struct blkid_idmag *mag)
 {
        if (!mag)
-               return -1;
+               return 1;
        if (!memcmp(mag->magic, "S1SUSPEND", mag->len))
                return swap_set_info(pr, "s1suspend");
        if (!memcmp(mag->magic, "S2SUSPEND", mag->len))
@@ -105,7 +112,7 @@ static int probe_swsuspend(blkid_probe pr, const struct blkid_idmag *mag)
        if (!memcmp(mag->magic, "LINHIB0001", mag->len))
                return swap_set_info(pr, "linhib0001");
 
-       return -1;      /* no signature detected */
+       return 1;       /* no signature detected */
 }
 
 const struct blkid_idinfo swap_idinfo =
index 2d69c2bf378587cd054635b6c20755873fa897eb..dc84260632fdbaa066a51b1a08073289eb950f36 100644 (file)
@@ -99,11 +99,12 @@ static int probe_ubifs(blkid_probe pr, const struct blkid_idmag *mag)
 
        sb = blkid_probe_get_sb(pr, mag, struct ubifs_sb_node);
        if (!sb)
-               return -1;
+               return errno ? -errno : 1;
 
        blkid_probe_set_uuid(pr, sb->uuid);
        blkid_probe_sprintf_version(pr, "w%dr%d",
-                                   sb->fmt_version, sb->ro_compat_version);
+                       le32_to_cpu(sb->fmt_version),
+                       le32_to_cpu(sb->ro_compat_version));
        return 0;
 }
 
index ef66769a09b6d25d153032abc11c03acba741c27..e3daf75b2c2edd692d49f8b279c5805d006a3885 100644 (file)
 #include <ctype.h>
 #include <stdint.h>
 
+#if 0
+#include "pt-mbr.h"
+#endif
+
 #include "superblocks.h"
 
 /* Yucky misaligned values */
@@ -123,9 +127,8 @@ static unsigned char *search_fat_label(blkid_probe pr,
        struct vfat_dir_entry *ent, *dir = NULL;
        uint32_t i;
 
-       DBG(DEBUG_LOWPROBE,
-               printf("\tlook for label in root-dir "
-                       "(entries: %d, offset: %jd)\n", entries, offset));
+       DBG(LOWPROBE, ul_debug("\tlook for label in root-dir "
+                       "(entries: %d, offset: %jd)", entries, offset));
 
        if (!blkid_probe_is_tiny(pr)) {
                /* large disk, read whole root directory */
@@ -163,15 +166,15 @@ static unsigned char *search_fat_label(blkid_probe pr,
 
                if ((ent->attr & (FAT_ATTR_VOLUME_ID | FAT_ATTR_DIR)) ==
                    FAT_ATTR_VOLUME_ID) {
-                       DBG(DEBUG_LOWPROBE,
-                               printf("\tfound fs LABEL at entry %d\n", i));
+                       DBG(LOWPROBE, ul_debug("\tfound fs LABEL at entry %d", i));
                        return ent->name;
                }
        }
        return NULL;
 }
 
-static int fat_valid_superblock(const struct blkid_idmag *mag,
+static int fat_valid_superblock(blkid_probe pr,
+                       const struct blkid_idmag *mag,
                        struct msdos_super_block *ms,
                        struct vfat_super_block *vs,
                        uint32_t *cluster_count, uint32_t *fat_size)
@@ -245,77 +248,84 @@ static int fat_valid_superblock(const struct blkid_idmag *mag,
        if (cluster_count)
                *cluster_count = __cluster_count;
 
+#if 0
+       if (blkid_probe_is_wholedisk(pr)) {
+               /* OK, seems like FAT, but it's possible that we found boot
+                * sector with crazy FAT-like stuff (magic strings, media,
+                * etc..) before MBR. Let's make sure that there is no MBR with
+                * usable partition. */
+               unsigned char *buf = (unsigned char *) ms;
+               if (mbr_is_valid_magic(buf)) {
+                       struct dos_partition *p0 = mbr_get_partition(buf, 0);
+                       if (dos_partition_get_size(p0) != 0 &&
+                           (p0->boot_ind == 0 || p0->boot_ind == 0x80))
+                               return 0;
+               }
+       }
+#endif
+
        return 1;       /* valid */
 }
 
+#if 0
 /*
  * This function is used by MBR partition table parser to avoid
  * misinterpretation of FAT filesystem.
  */
-/*static int blkid_probe_is_vfat(blkid_probe pr)
+int blkid_probe_is_vfat(blkid_probe pr)
 {
        struct vfat_super_block *vs;
        struct msdos_super_block *ms;
        const struct blkid_idmag *mag = NULL;
+       int rc;
 
-       if (blkid_probe_get_idmag(pr, &vfat_idinfo, NULL, &mag) || !mag)
+       rc = blkid_probe_get_idmag(pr, &vfat_idinfo, NULL, &mag);
+       if (rc < 0)
+               return rc;      /* error */
+       if (rc != BLKID_PROBE_OK || !mag)
                return 0;
 
        ms = blkid_probe_get_sb(pr, mag, struct msdos_super_block);
        if (!ms)
-               return 0;
+               return errno ? -errno : 0;
        vs = blkid_probe_get_sb(pr, mag, struct vfat_super_block);
        if (!vs)
-               return 0;
-
-       return fat_valid_superblock(mag, ms, vs, NULL, NULL);
-}*/
-static struct vfat_super_block vs;
-static struct msdos_super_block ms;
-
-static int set_label(blkid_probe pr, unsigned char *vol_label)
-{
-       unsigned char *c;
-
-       for (c = vol_label + 10; c >= vol_label && *c == ' '; c--)
-               *c = 0;
-
-       if (!*vol_label)
-               return 0;
+               return errno ? -errno : 0;
 
-       return blkid_probe_set_label(pr, vol_label, 11);
+       return fat_valid_superblock(pr, mag, ms, vs, NULL, NULL);
 }
+#endif
 
 /* FAT label extraction from the root directory taken from Kay
  * Sievers's volume_id library */
 static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
 {
-       struct vfat_super_block *_vs;
-       struct msdos_super_block *_ms;
+       struct vfat_super_block *vs;
+       struct msdos_super_block *ms;
        const unsigned char *vol_label = 0;
        unsigned char *vol_serno = NULL, vol_label_buf[11];
        uint16_t sector_size = 0, reserved;
        uint32_t cluster_count, fat_size;
        const char *version = NULL;
 
-       _ms = blkid_probe_get_sb(pr, mag, struct msdos_super_block);
-       if (!_ms)
-               return 0;
-       _vs = blkid_probe_get_sb(pr, mag, struct vfat_super_block);
-       if (!_vs)
-               return 0;
-       memcpy(&ms, _ms, sizeof(struct vfat_super_block));
-       memcpy(&vs, _vs, sizeof(struct msdos_super_block));
-       if (!fat_valid_superblock(mag, &ms, &vs, &cluster_count, &fat_size))
+       ms = blkid_probe_get_sb(pr, mag, struct msdos_super_block);
+       if (!ms)
+               return errno ? -errno : 1;
+
+       vs = blkid_probe_get_sb(pr, mag, struct vfat_super_block);
+       if (!vs)
+               return errno ? -errno : 1;
+
+       if (!fat_valid_superblock(pr, mag, ms, vs, &cluster_count, &fat_size))
                return 1;
 
-       sector_size = unaligned_le16(&ms.ms_sector_size);
-       reserved =  le16_to_cpu(ms.ms_reserved);
+       sector_size = unaligned_le16(&ms->ms_sector_size);
+       reserved =  le16_to_cpu(ms->ms_reserved);
 
-       if (ms.ms_fat_length) {
+       if (ms->ms_fat_length) {
                /* the label may be an attribute in the root directory */
                uint32_t root_start = (reserved + fat_size) * sector_size;
-               uint32_t root_dir_entries = unaligned_le16(&vs.vs_dir_entries);
+               uint32_t root_dir_entries = unaligned_le16(&vs->vs_dir_entries);
 
                vol_label = search_fat_label(pr, root_start, root_dir_entries);
                if (vol_label) {
@@ -324,8 +334,8 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
                }
 
                if (!vol_label || !memcmp(vol_label, no_name, 11))
-                       vol_label = ms.ms_label;
-               vol_serno = ms.ms_serno;
+                       vol_label = ms->ms_label;
+               vol_serno = ms->ms_serno;
 
                blkid_probe_set_value(pr, "SEC_TYPE", (unsigned char *) "msdos",
                               sizeof("msdos"));
@@ -335,24 +345,24 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
                else if (cluster_count < FAT16_MAX)
                        version = "FAT16";
 
-       } else if (vs.vs_fat32_length) {
+       } else if (vs->vs_fat32_length) {
                unsigned char *buf;
                uint16_t fsinfo_sect;
                int maxloop = 100;
 
                /* Search the FAT32 root dir for the label attribute */
-               uint32_t buf_size = vs.vs_cluster_size * sector_size;
+               uint32_t buf_size = vs->vs_cluster_size * sector_size;
                uint32_t start_data_sect = reserved + fat_size;
-               uint32_t entries = le32_to_cpu(vs.vs_fat32_length) *
+               uint32_t entries = le32_to_cpu(vs->vs_fat32_length) *
                                        sector_size / sizeof(uint32_t);
-               uint32_t next = le32_to_cpu(vs.vs_root_cluster);
+               uint32_t next = le32_to_cpu(vs->vs_root_cluster);
 
                while (next && next < entries && --maxloop) {
                        uint32_t next_sect_off;
                        uint64_t next_off, fat_entry_off;
                        int count;
 
-                       next_sect_off = (next - 2) * le32_to_cpu(vs.vs_cluster_size);
+                       next_sect_off = (next - 2) * vs->vs_cluster_size;
                        next_off = (uint64_t)(start_data_sect + next_sect_off) *
                                sector_size;
 
@@ -379,15 +389,15 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
                version = "FAT32";
 
                if (!vol_label || !memcmp(vol_label, no_name, 11))
-                       vol_label = NULL;
-               vol_serno = vs.vs_serno;
+                       vol_label = vs->vs_label;
+               vol_serno = vs->vs_serno;
 
                /*
                 * FAT32 should have a valid signature in the fsinfo block,
                 * but also allow all bytes set to '\0', because some volumes
                 * do not set the signature at all.
                 */
-               fsinfo_sect = le16_to_cpu(vs.vs_fsinfo_sector);
+               fsinfo_sect = le16_to_cpu(vs->vs_fsinfo_sector);
                if (fsinfo_sect) {
                        struct fat32_fsinfo *fsinfo;
 
@@ -395,25 +405,25 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
                                        (blkid_loff_t) fsinfo_sect * sector_size,
                                        sizeof(struct fat32_fsinfo));
                        if (buf == NULL)
-                               return -1;
+                               return errno ? -errno : 1;
 
                        fsinfo = (struct fat32_fsinfo *) buf;
                        if (memcmp(fsinfo->signature1, "\x52\x52\x61\x41", 4) != 0 &&
                            memcmp(fsinfo->signature1, "\x52\x52\x64\x41", 4) != 0 &&
                            memcmp(fsinfo->signature1, "\x00\x00\x00\x00", 4) != 0)
-                               return -1;
+                               return 1;
                        if (memcmp(fsinfo->signature2, "\x72\x72\x41\x61", 4) != 0 &&
                            memcmp(fsinfo->signature2, "\x00\x00\x00\x00", 4) != 0)
-                               return -1;
+                               return 1;
                }
        }
 
        if (vol_label && memcmp(vol_label, no_name, 11))
-               set_label(pr, (unsigned char *) vol_label);
+               blkid_probe_set_label(pr, (unsigned char *) vol_label, 11);
 
        /* We can't just print them as %04X, because they are unaligned */
        if (vol_serno)
-               blkid_probe_sprintf_uuid(pr, vol_serno, 4, "%02x%02x-%02x%02x",
+               blkid_probe_sprintf_uuid(pr, vol_serno, 4, "%02X%02X-%02X%02X",
                        vol_serno[3], vol_serno[2], vol_serno[1], vol_serno[0]);
        if (version)
                blkid_probe_set_version(pr, version);