diff options
Diffstat (limited to 'libblkid')
-rw-r--r-- | libblkid/Makemodule.am | 2 | ||||
-rw-r--r-- | libblkid/docs/Makefile.am | 2 | ||||
-rw-r--r-- | libblkid/src/Makemodule.am | 17 | ||||
-rw-r--r-- | libblkid/src/blkidP.h | 3 | ||||
-rw-r--r-- | libblkid/src/init.c | 2 | ||||
-rw-r--r-- | libblkid/src/partitions/atari.c | 276 | ||||
-rw-r--r-- | libblkid/src/partitions/dos.c | 25 | ||||
-rw-r--r-- | libblkid/src/partitions/partitions.c | 22 | ||||
-rw-r--r-- | libblkid/src/partitions/partitions.h | 1 | ||||
-rw-r--r-- | libblkid/src/probe.c | 40 | ||||
-rw-r--r-- | libblkid/src/superblocks/bcache.c | 20 | ||||
-rw-r--r-- | libblkid/src/superblocks/hfs.c | 16 | ||||
-rw-r--r-- | libblkid/src/superblocks/mpool.c | 10 | ||||
-rw-r--r-- | libblkid/src/superblocks/stratis.c | 105 | ||||
-rw-r--r-- | libblkid/src/superblocks/superblocks.c | 10 | ||||
-rw-r--r-- | libblkid/src/superblocks/superblocks.h | 2 | ||||
-rw-r--r-- | libblkid/src/superblocks/vdo.c | 48 | ||||
-rw-r--r-- | libblkid/src/verify.c | 2 |
18 files changed, 523 insertions, 80 deletions
diff --git a/libblkid/Makemodule.am b/libblkid/Makemodule.am index b4f6f9c4e..f1d1e8d00 100644 --- a/libblkid/Makemodule.am +++ b/libblkid/Makemodule.am @@ -11,6 +11,6 @@ endif pkgconfig_DATA += libblkid/blkid.pc PATHFILES += libblkid/blkid.pc dist_man_MANS += libblkid/libblkid.3 -EXTRA_DIST += libblkid/libblkid.3 libblkid/COPYING +EXTRA_DIST += libblkid/COPYING endif # BUILD_LIBBLKID diff --git a/libblkid/docs/Makefile.am b/libblkid/docs/Makefile.am index 83232c4a0..c735a132c 100644 --- a/libblkid/docs/Makefile.am +++ b/libblkid/docs/Makefile.am @@ -68,7 +68,7 @@ HTML_IMAGES= # e.g. content_files=running.sgml building.sgml changes-2.0.sgml content_files = $(builddir)/version.xml $(srcdir)/libblkid-config.xml -# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded +# SGML files where gtk-doc abbreviations (#GtkWidget) are expanded # These files must be listed here *and* in content_files # e.g. expand_content_files=running.sgml expand_content_files= diff --git a/libblkid/src/Makemodule.am b/libblkid/src/Makemodule.am index c126b656c..0e1c765fb 100644 --- a/libblkid/src/Makemodule.am +++ b/libblkid/src/Makemodule.am @@ -1,7 +1,7 @@ # blkid.h is generated, so it's store in builddir! blkidincdir = $(includedir)/blkid -nodist_blkidinc_HEADERS = $(top_builddir)/libblkid/src/blkid.h +nodist_blkidinc_HEADERS = libblkid/src/blkid.h usrlib_exec_LTLIBRARIES += libblkid.la libblkid_la_SOURCES = \ @@ -26,10 +26,10 @@ libblkid_la_SOURCES = \ libblkid/src/tag.c \ libblkid/src/verify.c \ libblkid/src/version.c \ - $(nodist_blkidinc_HEADERS) \ \ libblkid/src/partitions/aix.c \ libblkid/src/partitions/aix.h \ + libblkid/src/partitions/atari.c \ libblkid/src/partitions/bsd.c \ libblkid/src/partitions/dos.c \ libblkid/src/partitions/gpt.c \ @@ -82,6 +82,7 @@ libblkid_la_SOURCES = \ libblkid/src/superblocks/romfs.c \ libblkid/src/superblocks/silicon_raid.c \ libblkid/src/superblocks/squashfs.c \ + libblkid/src/superblocks/stratis.c \ libblkid/src/superblocks/superblocks.c \ libblkid/src/superblocks/superblocks.h \ libblkid/src/superblocks/swap.c \ @@ -90,6 +91,7 @@ libblkid_la_SOURCES = \ libblkid/src/superblocks/ubifs.c \ libblkid/src/superblocks/udf.c \ libblkid/src/superblocks/ufs.c \ + libblkid/src/superblocks/vdo.c \ libblkid/src/superblocks/vfat.c \ libblkid/src/superblocks/via_raid.c \ libblkid/src/superblocks/vmfs.c \ @@ -110,13 +112,10 @@ libblkid_la_SOURCES += \ libblkid/src/topology/sysfs.c endif -nodist_libblkid_la_SOURCES = libblkid/src/blkid.h libblkid_la_LIBADD = libcommon.la -libblkid_la_DEPENDENCIES = \ - libcommon.la \ - libblkid/src/libblkid.sym \ - libblkid/src/blkid.h.in +EXTRA_libblkid_la_DEPENDENCIES = \ + libblkid/src/libblkid.sym libblkid_la_CFLAGS = \ $(AM_CFLAGS) \ @@ -126,7 +125,6 @@ libblkid_la_CFLAGS = \ if BUILD_LIBUUID libblkid_la_LIBADD += libuuid.la -libblkid_la_DEPENDENCIES += libuuid.la libblkid_la_CFLAGS += -I$(ul_libuuid_incdir) endif @@ -137,8 +135,7 @@ endif libblkid_la_LDFLAGS += -version-info $(LIBBLKID_VERSION_INFO) EXTRA_DIST += \ - libblkid/src/libblkid.sym \ - libblkid/src/blkid.h.in + libblkid/src/libblkid.sym if BUILD_LIBBLKID_TESTS check_PROGRAMS += \ diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h index 8108b0efa..22c985631 100644 --- a/libblkid/src/blkidP.h +++ b/libblkid/src/blkidP.h @@ -338,6 +338,9 @@ 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 UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(libblkid) +#include "debugobj.h" + extern void blkid_debug_dump_dev(blkid_dev dev); diff --git a/libblkid/src/init.c b/libblkid/src/init.c index a73b7fd07..6dc9ffd56 100644 --- a/libblkid/src/init.c +++ b/libblkid/src/init.c @@ -50,7 +50,7 @@ void blkid_init_debug(int mask) if (libblkid_debug_mask) return; - __UL_INIT_DEBUG(libblkid, BLKID_DEBUG_, mask, LIBBLKID_DEBUG); + __UL_INIT_DEBUG_FROM_ENV(libblkid, BLKID_DEBUG_, mask, LIBBLKID_DEBUG); if (libblkid_debug_mask != BLKID_DEBUG_INIT && libblkid_debug_mask != (BLKID_DEBUG_HELP|BLKID_DEBUG_INIT)) { diff --git a/libblkid/src/partitions/atari.c b/libblkid/src/partitions/atari.c new file mode 100644 index 000000000..1224a577c --- /dev/null +++ b/libblkid/src/partitions/atari.c @@ -0,0 +1,276 @@ +/* + * atari partitions parsing code + * + * Copyright (C) 2018 Vaclav Dolezal <vdolezal@redhat.com> + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + * + * Based on Linux kernel implementation and atari-fdisk + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdint.h> + +#include "partitions.h" + +struct atari_part_def { + /* + * flags: + * 0 (LSB): active + * 1-6: (reserved) + * 7 (MSB): bootable + */ + unsigned char flags; + char id[3]; + uint32_t start; + uint32_t size; +} __attribute__((packed)); + +struct atari_rootsector { + char unused0[0x156]; /* boot code */ + struct atari_part_def icd_part[8]; /* ICD partition entries */ + char unused1[0xc]; + uint32_t hd_size; + struct atari_part_def part[4]; /* primary partition entries */ + uint32_t bsl_start; /* bad sector list start */ + uint32_t bsl_len; /* bad sector list length */ + uint16_t checksum; +} __attribute__((packed)); + + +/* + * Generated using linux kernel ctype.{c,h} + * + * Since kernel uses isalnum() to detect whether it is Atari PT, we need same + * definition of alnum character to be consistent with kernel. + */ +static const unsigned char _linux_isalnum[] = { +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, +0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, +0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1 +}; + +static int linux_isalnum(unsigned char c) { + return _linux_isalnum[c]; +} + +#define isalnum linux_isalnum + +#define IS_ACTIVE(partdef) ((partdef).flags & 1) + +#define IS_PARTDEF_VALID(partdef, hdsize) \ + ( \ + (partdef).flags & 1 && \ + isalnum((partdef).id[0]) && \ + isalnum((partdef).id[1]) && \ + isalnum((partdef).id[2]) && \ + be32_to_cpu((partdef).start) <= (hdsize) && \ + be32_to_cpu((partdef).start) + \ + be32_to_cpu((partdef).size) <= (hdsize) \ + ) + +static int is_id_common(char *id) +{ + const char *ids[] = {"GEM", "BGM", "LNX", "SWP", "RAW", }; + unsigned i; + + for (i = 0; i < ARRAY_SIZE(ids); i++) { + if (!memcmp(ids[i], id, 3)) + return 1; + } + return 0; +} + +static int parse_partition(blkid_partlist ls, blkid_parttable tab, + struct atari_part_def *part, uint32_t offset) +{ + blkid_partition par; + uint32_t start; + uint32_t size; + + start = be32_to_cpu(part->start) + offset; + size = be32_to_cpu(part->size); + + if (blkid_partlist_get_partition_by_start(ls, start)) { + /* Don't increment partno for extended parts */ + if (!offset) + blkid_partlist_increment_partno(ls); + return 0; + } + + par = blkid_partlist_add_partition(ls, tab, start, size); + if (!par) + return -ENOMEM; + + blkid_partition_set_type_string(par, (unsigned char *) part->id, + sizeof(part->id)); + return 1; +} + +/* + * \return 1: OK, 0: bad format or -errno + */ +static int parse_extended(blkid_probe pr, blkid_partlist ls, + blkid_parttable tab, struct atari_part_def *part) +{ + uint32_t x0start, xstart; + unsigned i = 0; + int rc; + + x0start = xstart = be32_to_cpu(part->start); + while (1) { + struct atari_rootsector *xrs; + xrs = (struct atari_rootsector *) blkid_probe_get_sector(pr, xstart); + if (!xrs) { + if (errno) + return -errno; + return 0; + } + + /* + * There must be data partition followed by reference to next + * XGM or inactive entry. + */ + for (i=0; ; i++) { + if (i >= ARRAY_SIZE(xrs->part) - 1) + return 0; + if (IS_ACTIVE(xrs->part[i])) + break; + } + + if (!memcmp(xrs->part[i].id, "XGM", 3)) + return 0; + + rc = parse_partition(ls, tab, &xrs->part[i], xstart); + if (rc <= 0) + return rc; + + if (!IS_ACTIVE(xrs->part[i+1])) + break; + + if (memcmp(xrs->part[i+1].id, "XGM", 3)) + return 0; + + xstart = x0start + be32_to_cpu(xrs->part[i+1].start); + } + + return 1; +} + +static int probe_atari_pt(blkid_probe pr, + const struct blkid_idmag *mag __attribute__((__unused__))) +{ + struct atari_rootsector *rs; + + blkid_parttable tab = NULL; + blkid_partlist ls; + + unsigned i; + int has_xgm = 0; + int rc = 0; + off_t hdsize; + + /* Atari partition is not defined for other sector sizes */ + if (blkid_probe_get_sectorsize(pr) != 512) + goto nothing; + + rs = (struct atari_rootsector *) blkid_probe_get_sector(pr, 0); + if (!rs) { + if (errno) + return -errno; + goto nothing; + } + + hdsize = blkid_probe_get_size(pr) / 512; + + /* Look for validly looking primary partition */ + for (i = 0; ; i++) { + if (i >= ARRAY_SIZE(rs->part)) + goto nothing; + + if (IS_PARTDEF_VALID(rs->part[i], hdsize)) { + blkid_probe_set_magic(pr, + offsetof(struct atari_rootsector, part[i]), + sizeof(rs->part[i].flags) + sizeof(rs->part[i].id), + (unsigned char *) &rs->part[i]); + break; + } + } + + if (blkid_partitions_need_typeonly(pr)) + /* caller does not ask for details about partitions */ + return BLKID_PROBE_OK; + + ls = blkid_probe_get_partlist(pr); + if (!ls) + goto nothing; + + tab = blkid_partlist_new_parttable(ls, "atari", 0); + if (!tab) + goto err; + + for (i = 0; i < ARRAY_SIZE(rs->part); i++) { + struct atari_part_def *p = &rs->part[i]; + + if (!IS_ACTIVE(*p)) { + blkid_partlist_increment_partno(ls); + continue; + } + + if (!memcmp(p->id, "XGM", 3)) { + has_xgm = 1; + rc = parse_extended(pr, ls, tab, p); + } else { + rc = parse_partition(ls, tab, p, 0); + } + if (rc < 0) + return rc; + } + + /* if there are no XGM partitions, we can try ICD format */ + /* if first ICD partition ID is not valid, assume no ICD format */ + if (!has_xgm && is_id_common(rs->icd_part[0].id)) { + for (i = 0; i < ARRAY_SIZE(rs->icd_part); i++) { + struct atari_part_def *p = &rs->icd_part[i]; + + if (!IS_ACTIVE(*p) || !is_id_common(p->id)) { + blkid_partlist_increment_partno(ls); + continue; + } + + rc = parse_partition(ls, tab, p, 0); + if (rc < 0) + return rc; + } + } + + return BLKID_PROBE_OK; + +nothing: + return BLKID_PROBE_NONE; +err: + return -ENOMEM; +} + +const struct blkid_idinfo atari_pt_idinfo = +{ + .name = "atari", + .probefunc = probe_atari_pt, + .magics = BLKID_NONE_MAGIC +}; diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c index 1db238781..659ca9a16 100644 --- a/libblkid/src/partitions/dos.c +++ b/libblkid/src/partitions/dos.c @@ -307,20 +307,31 @@ static int probe_dos_pt(blkid_probe pr, /* Parse subtypes (nested partitions) on large disks */ if (!blkid_probe_is_tiny(pr)) { - for (p = p0, i = 0; i < 4; i++, p++) { + int nparts = blkid_partlist_numof_partitions(ls); + + DBG(LOWPROBE, ul_debug("checking for subtypes")); + + for (i = 0; i < nparts; i++) { size_t n; - int rc; + int type; + blkid_partition pa = blkid_partlist_get_partition(ls, i); - if (!dos_partition_get_size(p) || is_extended(p)) + if (pa == NULL + || blkid_partition_get_size(pa) == 0 + || blkid_partition_is_extended(pa) + || blkid_partition_is_logical(pa)) continue; + type = blkid_partition_get_type(pa); + for (n = 0; n < ARRAY_SIZE(dos_nested); n++) { - if (dos_nested[n].type != p->sys_ind) + int rc; + + if (dos_nested[n].type != type) continue; - rc = blkid_partitions_do_subprobe(pr, - blkid_partlist_get_partition(ls, i), - dos_nested[n].id); + rc = blkid_partitions_do_subprobe(pr, pa, + dos_nested[n].id); if (rc < 0) return rc; break; diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c index d8fc8e3c8..83c3c4f1b 100644 --- a/libblkid/src/partitions/partitions.c +++ b/libblkid/src/partitions/partitions.c @@ -133,7 +133,8 @@ static const struct blkid_idinfo *idinfos[] = &bsd_pt_idinfo, &unixware_pt_idinfo, &solaris_x86_pt_idinfo, - &minix_pt_idinfo + &minix_pt_idinfo, + &atari_pt_idinfo }; /* @@ -379,8 +380,7 @@ static blkid_partlist partitions_init_data(struct blkid_chain *chn) reset_partlist(ls); - DBG(LOWPROBE, ul_debug("parts: initialized partitions list (%p, size=%d)", - ls, ls->nparts_max)); + DBG(LOWPROBE, ul_debug("parts: initialized partitions list (size=%d)", ls->nparts_max)); return ls; } @@ -415,7 +415,7 @@ blkid_parttable blkid_partlist_new_parttable(blkid_partlist ls, list_add_tail(&tab->t_tabs, &ls->l_tabs); DBG(LOWPROBE, ul_debug("parts: create a new partition table " - "(%p, type=%s, offset=%"PRId64")", tab, type, offset)); + "(type=%s, offset=%"PRId64")", type, offset)); return tab; } @@ -456,9 +456,9 @@ blkid_partition blkid_partlist_add_partition(blkid_partlist ls, par->start = start; par->size = size; - DBG(LOWPROBE, ul_debug("parts: add partition (%p start=%" - PRIu64 ", size=%" PRIu64 ", table=%p)", - par, par->start, par->size, tab)); + DBG(LOWPROBE, ul_debug("parts: add partition (start=%" + PRIu64 ", size=%" PRIu64 ")", + par->start, par->size)); return par; } @@ -665,8 +665,8 @@ int blkid_partitions_do_subprobe(blkid_probe pr, blkid_partition parent, uint64_t sz, off; DBG(LOWPROBE, ul_debug( - "parts: ----> %s subprobe requested (parent=%p)", - id->name, parent)); + "parts: ----> %s subprobe requested)", + id->name)); if (!pr || !parent || !parent->size) return -EINVAL; @@ -712,8 +712,8 @@ int blkid_partitions_do_subprobe(blkid_probe pr, blkid_partition parent, blkid_free_probe(prc); /* free cloned prober */ DBG(LOWPROBE, ul_debug( - "parts: <---- %s subprobe done (parent=%p, rc=%d)", - id->name, parent, rc)); + "parts: <---- %s subprobe done (rc=%d)", + id->name, rc)); return rc; } diff --git a/libblkid/src/partitions/partitions.h b/libblkid/src/partitions/partitions.h index 1d99fb6a3..4a718f4ea 100644 --- a/libblkid/src/partitions/partitions.h +++ b/libblkid/src/partitions/partitions.h @@ -69,5 +69,6 @@ extern const struct blkid_idinfo minix_pt_idinfo; extern const struct blkid_idinfo gpt_pt_idinfo; extern const struct blkid_idinfo pmbr_pt_idinfo; extern const struct blkid_idinfo ultrix_pt_idinfo; +extern const struct blkid_idinfo atari_pt_idinfo; #endif /* BLKID_PARTITIONS_H */ diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 476461bc4..647ae416a 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -137,7 +137,7 @@ blkid_probe blkid_new_probe(void) if (!pr) return NULL; - DBG(LOWPROBE, ul_debug("allocate a new probe %p", pr)); + DBG(LOWPROBE, ul_debug("allocate a new probe")); /* initialize chains */ for (i = 0; i < BLKID_NCHAINS; i++) { @@ -251,7 +251,7 @@ void blkid_free_probe(blkid_probe pr) blkid_probe_reset_values(pr); blkid_free_probe(pr->disk_probe); - DBG(LOWPROBE, ul_debug("free probe %p", pr)); + DBG(LOWPROBE, ul_debug("free probe")); free(pr); } @@ -561,8 +561,8 @@ static struct blkid_bufinfo *read_buffer(blkid_probe pr, uint64_t real_off, uint bf->off = real_off; INIT_LIST_HEAD(&bf->bufs); - DBG(LOWPROBE, ul_debug("\tread %p: off=%"PRIu64" len=%"PRIu64"", - bf->data, real_off, len)); + DBG(LOWPROBE, ul_debug("\tread: off=%"PRIu64" len=%"PRIu64"", + real_off, len)); ret = read(pr->fd, bf->data, len); if (ret != (ssize_t) len) { @@ -592,8 +592,8 @@ static struct blkid_bufinfo *get_cached_buffer(blkid_probe pr, uint64_t off, uin list_entry(p, struct blkid_bufinfo, bufs); if (real_off >= x->off && real_off + len <= x->off + x->len) { - DBG(BUFFER, ul_debug("\treuse %p: off=%"PRIu64" len=%"PRIu64" (for off=%"PRIu64" len=%"PRIu64")", - x->data, x->off, x->len, real_off, len)); + DBG(BUFFER, ul_debug("\treuse: off=%"PRIu64" len=%"PRIu64" (for off=%"PRIu64" len=%"PRIu64")", + x->off, x->len, real_off, len)); return x; } } @@ -625,8 +625,8 @@ static int hide_buffer(blkid_probe pr, uint64_t off, uint64_t len) data = real_off ? x->data + (real_off - x->off) : x->data; - DBG(BUFFER, ul_debug("\thidding %p: off=%"PRIu64" len=%"PRIu64, - x->data, off, len)); + DBG(BUFFER, ul_debug("\thidding: off=%"PRIu64" len=%"PRIu64, + off, len)); memset(data, 0, len); ct++; } @@ -712,7 +712,7 @@ int blkid_probe_reset_buffers(blkid_probe pr) if (list_empty(&pr->buffers)) return 0; - DBG(BUFFER, ul_debug("Resetting probing buffers pr=%p", pr)); + DBG(BUFFER, ul_debug("Resetting probing buffers")); while (!list_empty(&pr->buffers)) { struct blkid_bufinfo *bf = list_entry(pr->buffers.next, @@ -721,8 +721,8 @@ int blkid_probe_reset_buffers(blkid_probe pr) len += bf->len; list_del(&bf->bufs); - DBG(BUFFER, ul_debug(" remove buffer: %p [off=%"PRIu64", len=%"PRIu64"]", - bf->data, bf->off, bf->len)); + DBG(BUFFER, ul_debug(" remove buffer: [off=%"PRIu64", len=%"PRIu64"]", + bf->off, bf->len)); free(bf); } @@ -765,7 +765,7 @@ static void blkid_probe_reset_values(blkid_probe pr) if (list_empty(&pr->values)) return; - DBG(LOWPROBE, ul_debug("resetting results pr=%p", pr)); + DBG(LOWPROBE, ul_debug("resetting results")); while (!list_empty(&pr->values)) { struct blkid_prval *v = list_entry(pr->values.next, @@ -923,8 +923,8 @@ int blkid_probe_set_device(blkid_probe pr, int fd, pr->flags |= BLKID_FL_TINY_DEV; if (S_ISBLK(sb.st_mode) && - sysfs_devno_is_lvm_private(sb.st_rdev, &dm_uuid)) { - DBG(LOWPROBE, ul_debug("ignore private LVM device")); + sysfs_devno_is_dm_private(sb.st_rdev, &dm_uuid)) { + DBG(LOWPROBE, ul_debug("ignore private device mapper device")); pr->flags |= BLKID_FL_NOSCAN_DEV; } @@ -964,9 +964,9 @@ int blkid_probe_get_dimension(blkid_probe pr, uint64_t *off, uint64_t *size) int blkid_probe_set_dimension(blkid_probe pr, uint64_t off, uint64_t size) { DBG(LOWPROBE, ul_debug( - "changing probing area pr=%p: size=%"PRIu64", off=%"PRIu64" " + "changing probing area: size=%"PRIu64", off=%"PRIu64" " "-to-> size=%"PRIu64", off=%"PRIu64"", - pr, pr->size, pr->off, size, off)); + pr->size, pr->off, size, off)); pr->off = off; pr->size = size; @@ -1029,7 +1029,7 @@ int blkid_probe_get_idmag(blkid_probe pr, const struct blkid_idinfo *id, static inline void blkid_probe_start(blkid_probe pr) { - DBG(LOWPROBE, ul_debug("%p: start probe", pr)); + DBG(LOWPROBE, ul_debug("start probe")); pr->cur_chain = NULL; pr->prob_flags = 0; blkid_probe_set_wiper(pr, 0, 0); @@ -1037,7 +1037,7 @@ static inline void blkid_probe_start(blkid_probe pr) static inline void blkid_probe_end(blkid_probe pr) { - DBG(LOWPROBE, ul_debug("%p: end probe", pr)); + DBG(LOWPROBE, ul_debug("end probe")); pr->cur_chain = NULL; pr->prob_flags = 0; blkid_probe_set_wiper(pr, 0, 0); @@ -1147,7 +1147,7 @@ int blkid_do_probe(blkid_probe pr) * After successful signature removing the @pr prober will be moved one step * back and the next blkid_do_probe() call will again call previously called * probing function. All in-memory cached data from the device are always - * reseted. + * reset. * * <example> * <title>wipe all filesystems or raids from the device</title> @@ -1248,7 +1248,7 @@ int blkid_do_wipe(blkid_probe pr, int dryrun) * according to the current libblkid probing result. * * Note that blkid_probe_hide_range() changes semantic of this function and - * cached bufferes are not reseted, but library uses in-memory modified + * cached bufferes are not reset, but library uses in-memory modified * buffers to call the next probing function. * * <example> diff --git a/libblkid/src/superblocks/bcache.c b/libblkid/src/superblocks/bcache.c index 82c1a8008..28eb24d5f 100644 --- a/libblkid/src/superblocks/bcache.c +++ b/libblkid/src/superblocks/bcache.c @@ -19,11 +19,6 @@ #define node(i, j) ((i)->d + (j)) #define end(i) node(i, le16_to_cpu((i)->keys)) -static const char bcache_magic[] = { - 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca, - 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 -}; - struct bcache_super_block { uint64_t csum; uint64_t offset; /* sector where this sb was written */ @@ -76,9 +71,9 @@ struct bcache_super_block { }; /* magic string */ -#define BCACHE_SB_MAGIC bcache_magic +#define BCACHE_SB_MAGIC "\xc6\x85\x73\xf6\x4e\x1a\x45\xca\x82\x65\xf5\x7f\x48\xba\x6d\x81" /* magic string len */ -#define BCACHE_SB_MAGIC_LEN sizeof (bcache_magic) +#define BCACHE_SB_MAGIC_LEN (sizeof(BCACHE_SB_MAGIC) - 1) /* super block offset */ #define BCACHE_SB_OFF 0x1000 /* supper block offset in kB */ @@ -111,11 +106,12 @@ const struct blkid_idinfo bcache_idinfo = .minsz = 8192, .magics = { - { .magic = BCACHE_SB_MAGIC - , .len = BCACHE_SB_MAGIC_LEN - , .kboff = BCACHE_SB_KBOFF - , .sboff = BCACHE_SB_MAGIC_OFF - } , + { + .magic = BCACHE_SB_MAGIC, + .len = BCACHE_SB_MAGIC_LEN, + .kboff = BCACHE_SB_KBOFF, + .sboff = BCACHE_SB_MAGIC_OFF + }, { NULL } } }; diff --git a/libblkid/src/superblocks/hfs.c b/libblkid/src/superblocks/hfs.c index c2344114a..19f14ed0d 100644 --- a/libblkid/src/superblocks/hfs.c +++ b/libblkid/src/superblocks/hfs.c @@ -130,19 +130,21 @@ 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] = { + static unsigned char const hash_init[UL_MD5LENGTH] = { 0xb3, 0xe2, 0x0f, 0x39, 0xf2, 0x92, 0x11, 0xd6, 0x97, 0xa4, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac }; - unsigned char uuid[MD5LENGTH]; - struct MD5Context md5c; + unsigned char uuid[UL_MD5LENGTH]; + struct UL_MD5Context md5c; if (memcmp(hfs_info, "\0\0\0\0\0\0\0\0", len) == 0) return -1; - MD5Init(&md5c); - MD5Update(&md5c, hash_init, MD5LENGTH); - MD5Update(&md5c, hfs_info, len); - MD5Final(uuid, &md5c); + + ul_MD5Init(&md5c); + ul_MD5Update(&md5c, hash_init, UL_MD5LENGTH); + ul_MD5Update(&md5c, hfs_info, len); + ul_MD5Final(uuid, &md5c); + uuid[6] = 0x30 | (uuid[6] & 0x0f); uuid[8] = 0x80 | (uuid[8] & 0x3f); return blkid_probe_set_uuid(pr, uuid); diff --git a/libblkid/src/superblocks/mpool.c b/libblkid/src/superblocks/mpool.c index 5f30fd496..b27569ef3 100644 --- a/libblkid/src/superblocks/mpool.c +++ b/libblkid/src/superblocks/mpool.c @@ -13,14 +13,12 @@ #include "crc32c.h" #include "superblocks.h" -#include <uuid.h> - #define MAX_MPOOL_NAME_LEN 32 struct omf_sb_descriptor { uint64_t osb_magic; uint8_t osb_name[MAX_MPOOL_NAME_LEN]; - uuid_t osb_poolid; /* UUID of pool this drive belongs to */ + unsigned char osb_poolid[16]; /* UUID of pool this drive belongs to */ uint16_t osb_vers; uint32_t osb_gen; uint32_t osb_cksum1; /* crc32c of the preceding fields */ @@ -39,7 +37,7 @@ static int probe_mpool(blkid_probe pr, const struct blkid_idmag *mag) offsetof(struct omf_sb_descriptor, osb_cksum1)); sb_crc ^= ~0L; - if (!blkid_probe_verify_csum(pr, sb_crc, osd->osb_cksum1)) + if (!blkid_probe_verify_csum(pr, sb_crc, le32_to_cpu(osd->osb_cksum1))) return 1; blkid_probe_set_label(pr, osd->osb_name, sizeof(osd->osb_name)); @@ -48,9 +46,7 @@ static int probe_mpool(blkid_probe pr, const struct blkid_idmag *mag) return 0; } -/** - * Superblock (sb) -- magic = ASCII "mpoolDev" - */ +/* "mpoolDev" in ASCII */ #define MPOOL_SB_MAGIC "\x6D\x70\x6f\x6f\x6c\x44\x65\x76" const struct blkid_idinfo mpool_idinfo = diff --git a/libblkid/src/superblocks/stratis.c b/libblkid/src/superblocks/stratis.c new file mode 100644 index 000000000..96c7df9aa --- /dev/null +++ b/libblkid/src/superblocks/stratis.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2018 Tony Asleson <tasleson@redhat.com> + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +/* + * Specification for on disk format + * https://stratis-storage.github.io/StratisSoftwareDesign.pdf + */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <stdint.h> +#include <inttypes.h> + +#include "superblocks.h" +#include "crc32c.h" + +struct stratis_sb { + uint32_t crc32; + uint8_t magic[16]; + uint64_t sectors; + uint8_t reserved[4]; + uint8_t pool_uuid[32]; + uint8_t dev_uuid[32]; + uint64_t mda_size; + uint64_t reserved_size; + uint64_t flags; + uint64_t initialization_time; +} __attribute__ ((__packed__)); + +#define BS 512 +#define FIRST_COPY_OFFSET BS +#define SECOND_COPY_OFFSET (BS * 9) +#define SB_AREA_SIZE (BS * 16) + +const char STRATIS_MAGIC[] = "!Stra0tis\x86\xff\x02^\x41rh"; +#define MAGIC_LEN (sizeof(STRATIS_MAGIC) - 1) + +#define _MAGIC_OFFSET (offsetof(const struct stratis_sb, magic)) +#define MAGIC_OFFSET_COPY_1 (FIRST_COPY_OFFSET + _MAGIC_OFFSET) +#define MAGIC_OFFSET_COPY_2 (SECOND_COPY_OFFSET + _MAGIC_OFFSET) + +static int stratis_valid_sb(uint8_t *p) +{ + const struct stratis_sb *stratis = (const struct stratis_sb *)p; + uint32_t crc = 0; + + /* generate CRC from byte position 4 for length 508 == 512 byte sector */ + crc = crc32c(~0L, p + sizeof(stratis->crc32), + BS - sizeof(stratis->crc32)); + crc ^= ~0L; + + return crc == le32_to_cpu(stratis->crc32); +} + +static int probe_stratis(blkid_probe pr, + const struct blkid_idmag *mag __attribute__((__unused__))) +{ + const struct stratis_sb *stratis = NULL; + uint8_t *buf = blkid_probe_get_buffer(pr, 0, SB_AREA_SIZE); + + if (!buf) + return errno ? -errno : 1; + + if (stratis_valid_sb(buf + FIRST_COPY_OFFSET)) { + stratis = (const struct stratis_sb *)(buf + FIRST_COPY_OFFSET); + } else { + if (!stratis_valid_sb(buf + SECOND_COPY_OFFSET)) + return 1; + + stratis = (const struct stratis_sb *) + (buf + SECOND_COPY_OFFSET); + } + + blkid_probe_strncpy_uuid(pr, (unsigned char *)stratis->dev_uuid, + sizeof(stratis->dev_uuid)); + blkid_probe_set_value(pr, "POOL_UUID", + (unsigned char *)stratis->pool_uuid, + sizeof(stratis->pool_uuid)); + + blkid_probe_sprintf_value(pr, "BLOCKDEV_SECTORS", "%" PRIu64, + stratis->sectors); + blkid_probe_sprintf_value(pr, "BLOCKDEV_INITTIME", "%" PRIu64, + stratis->initialization_time); + + return 0; +} + +const struct blkid_idinfo stratis_idinfo = { + .name = "stratis", + .usage = BLKID_USAGE_RAID, + .probefunc = probe_stratis, + .minsz = SB_AREA_SIZE, + .magics = { + { .magic = STRATIS_MAGIC, .len = MAGIC_LEN, + .sboff = MAGIC_OFFSET_COPY_1}, + { .magic = STRATIS_MAGIC, .len = MAGIC_LEN, + .sboff = MAGIC_OFFSET_COPY_2}, + { NULL } + } +}; diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c index 6bd9efe7d..076541d1a 100644 --- a/libblkid/src/superblocks/superblocks.c +++ b/libblkid/src/superblocks/superblocks.c @@ -113,6 +113,8 @@ static const struct blkid_idinfo *idinfos[] = &luks_idinfo, &vmfs_volume_idinfo, &ubi_idinfo, + &vdo_idinfo, + &stratis_idinfo, /* Filesystems */ &vfat_idinfo, @@ -340,14 +342,18 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn) blkid_probe_chain_reset_values(pr, chn); - if (pr->flags & BLKID_FL_NOSCAN_DEV) + if (pr->flags & BLKID_FL_NOSCAN_DEV) { + DBG(LOWPROBE, ul_debug("*** ignore (noscan flag)")); return BLKID_PROBE_NONE; + } - if (pr->size <= 0 || (pr->size <= 1024 && !S_ISCHR(pr->mode))) + if (pr->size <= 0 || (pr->size <= 1024 && !S_ISCHR(pr->mode))) { /* Ignore very very small block devices or regular files (e.g. * extended partitions). Note that size of the UBI char devices * is 1 byte */ + DBG(LOWPROBE, ul_debug("*** ignore (size <= 1024)")); return BLKID_PROBE_NONE; + } DBG(LOWPROBE, ul_debug("--> starting probing loop [SUBLKS idx=%d]", chn->idx)); diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h index 1a64ba6ec..2723fb1d5 100644 --- a/libblkid/src/superblocks/superblocks.h +++ b/libblkid/src/superblocks/superblocks.h @@ -79,6 +79,8 @@ 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 mpool_idinfo; +extern const struct blkid_idinfo vdo_idinfo; +extern const struct blkid_idinfo stratis_idinfo; /* * superblock functions diff --git a/libblkid/src/superblocks/vdo.c b/libblkid/src/superblocks/vdo.c new file mode 100644 index 000000000..bec686f4f --- /dev/null +++ b/libblkid/src/superblocks/vdo.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2017 Red Hat, Inc. + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <ctype.h> +#include <stdint.h> + +#include "superblocks.h" + +struct vdo_super_block { + char magic[8]; /* magic number 'dmvdo001'*/ + char unused[32]; /* 32 bytes of unimportant space */ + unsigned char sb_uuid[16]; /* vdo unique id */ + + /* this is not all... but enough for libblkid */ +} __attribute__((packed)); + +static int probe_vdo(blkid_probe pr, const struct blkid_idmag *mag) +{ + struct vdo_super_block *vsb; + + vsb = blkid_probe_get_sb(pr, mag, struct vdo_super_block); + if (!vsb) + return errno ? -errno : 1; + + blkid_probe_set_uuid(pr, vsb->sb_uuid); + return 0; +} + +const struct blkid_idinfo vdo_idinfo = +{ + .name = "vdo", + .usage = BLKID_USAGE_OTHER, + .probefunc = probe_vdo, + .magics = + { + { .magic = "dmvdo001", .len = 8 }, + { NULL } + } +}; diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c index d84894b10..7f44f5497 100644 --- a/libblkid/src/verify.c +++ b/libblkid/src/verify.c @@ -114,7 +114,7 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev) (unsigned long)diff)); #endif - if (sysfs_devno_is_lvm_private(st.st_rdev, NULL)) { + if (sysfs_devno_is_dm_private(st.st_rdev, NULL)) { blkid_free_dev(dev); return NULL; } |