On Mon, Jul 20, 2009 at 12:32:44AM +0200, Christoph Hellwig wrote: > I'm not entirely sure how such APIs would fit into the blkid library > design. I have extended the low-level API to better fit to all future requirements (topology and partitions probing). The probing functions are organized in separate "chains". Currently the library supports superblocks, topology and partitions chains. The partitions chain is not implemented yet. And the topology chain includes Christoph's code - ALIGNMENT_OFFSET, MINIMUM_IO_SIZE and OPTIMAL_IO_SIZE. The arbitrary chain could be enabled or disabled and fully controlled (chain specific filters, and flags) by API. The superblocks chain is enabled by default. All changes are backwardly compatible. The high-level API is unchanged and still works with filesystems information (LABEL, UUID, ...) only. I don't think that topology and partitions probing should be exported to this API. See my "mkfs" sample below. For more details see topic/libblkid-2.17 branch in the u-l-ng git repository. Karel /* * Copyright (C) 2009 Karel Zak <kzak@xxxxxxxxxx> * * This file may be redistributed under the terms of the * GNU Lesser General Public License. */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <err.h> #include <errno.h> #include <blkid.h> #ifndef TRUE # define TRUE 1 # define FALSE 0 #endif int main(int argc, char *argv[]) { int fd, rc; unsigned long offset; char *devname; blkid_probe pr; if (argc < 2) { fprintf(stderr, "usage: %s <device> " "-- checks based on libblkid for mkfs-like programs.\n", program_invocation_short_name); return EXIT_FAILURE; } devname = argv[1]; fd = open(devname, O_RDONLY); if (fd < 0) err(EXIT_FAILURE, "%s: open() failed", devname); pr = blkid_new_probe(); if (!pr) err(EXIT_FAILURE, "faild to allocate a new libblkid probe"); if (blkid_probe_set_device(pr, fd, 0, 0) != 0) err(EXIT_FAILURE, "failed to assign device to libblkid probe"); /* enable topology probing */ blkid_probe_enable_chain(pr, BLKID_CHAIN_TOPLGY, TRUE); /* enable partitions probing */ blkid_probe_enable_chain(pr, BLKID_CHAIN_PARTS, TRUE); /* superblocks probing is enabled by default */ /* it's would be nice to have binary data rather than strings */ blkid_probe_chain_enable_binary(pr, BLKID_CHAIN_TOPLGY, TRUE); rc = blkid_do_fullprobe(pr); if (rc == -1) errx(EXIT_FAILURE, "%s: blkid_do_fullprobe() failed", devname); else if (rc == 0) { const char *type; /* * check overwrite */ if (!blkid_probe_lookup_value(pr, "TYPE", &type, NULL)) errx(EXIT_FAILURE, "%s: appears to contain an existing " "filesystem (%s)", devname, type); if (!blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL)) errx(EXIT_FAILURE, "%s: appears to contain an partition " "table (%s)", devname, type); /* * get topology details */ blkid_probe_lookup_ulong_value(pr, "ALIGNMENT_OFFSET", &offset); } /* ... your mkfs.<type> code or so ... */ return EXIT_SUCCESS; } -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html