summaryrefslogtreecommitdiffstats
path: root/libblkid/src/probe.c
Commit message (Collapse)AuthorAgeFilesLines
* libblkid: fix file descriptor leak in blkid_verify()Karel Zak2019-07-311-3/+16
| | | | | | | | | | | | | | The function blkid_verify() uses private device file descriptor and uses blkid_probe_set_device() to assign the descriptor to low-level probing code. Unfortunately, close() in this case is not enough as the prober can internally open whole-disk device too. The library API has been extended so blkid_probe_set_device() deallocates and close previously used prober for whole-disk. This new functionality is used in blkid_verify() now. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1734545 Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: fix typos [codespell]Sami Kerola2019-02-181-1/+1
| | | | | Reference: https://github.com/codespell-project/codespell Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libblkid: tiny code simplificationKarel Zak2019-02-181-3/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: remove dependence on libuuidKarel Zak2019-01-221-8/+0Star
| | | | | | | | | | | Currently we use libuuid to print UUID only. This code is possible to replace by one snprintf(). It seems better to duplicate this one snprintf than force all distros to keep libuuid together with libblkid. Note, this scenario has been already supported on --disable-libuuid. Reported-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: Fix hidding typoAndreas Henriksson2018-11-211-1/+1
| | | | | | Spelling error spotted by lintian. Signed-off-by: Andreas Henriksson <andreas@fatal.se>
* libblkid: const qualifier cleanupKarel Zak2018-07-201-3/+3
| | | | | | | | * use "const" in functions where we don't modify arguments * use "const" when cast from const buffer to any struct (superblock etc.) Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: ignore private Stratis devicesTony Asleson2018-03-091-2/+2
| | | | | | | | [kzak@redhat.com: - tiny coding style changes] References: 20e1c3dc03399d6988ef35dedc1364cfc12e9263 Signed-off-by: Tony Asleson <tasleson@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix typos using codespellRuediger Meier2018-02-161-2/+2
| | | | | | Some more funny typos, please review carefully. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: remove %p from debug messagesKarel Zak2018-02-011-16/+16
| | | | | | From libs where suid program may be executed by non-root user. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: cleanup UUID_STR_LEN definitionsKarel Zak2017-09-151-4/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devicesKarel Zak2017-07-121-1/+5
| | | | | | | | | For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64 add extra warning when the ioctl is used for DM devices. It seems we can avoid this ioctl when the device has dm/uuid. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532 Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: don't check for size on UBI (char dev)Karel Zak2017-07-111-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: allow to hide already detected signaturesKarel Zak2017-06-281-25/+123
| | | | | | | | | | | | | | | | | | | | The libblkid probing functions returns the first successful result of the filesystem/RAID/PT. Unfortunately, some signatures is possible to detect by more ways or device may contains more copies (e.g. GPT). This is no problem when we wipe signatures from the device. In this case we zeroize on-device signature and re-scan for the signature (by blkid_probe_step_back()). The problem is if we want to read all permutations without the device modification (for example wipefs(8) dry run). This patch add blkid_probe_hide_range(). The function remove (zeroize) specified signature from in-memory cached buffers. If the buffer is later re-used by probing functions then the signature is invisible and we can try detect another variant of the magic string. Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: remove dead code and blkid_probe_new_value()Karel Zak2017-06-271-34/+2Star
| | | | | | The function blkid_probe_new_value() is unnecessary. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix reassigned values before old ones has been used [cppcheck]Sami Kerola2017-06-141-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libblkid: (docs) add missing 'since' tagsKarel Zak2017-05-231-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: declare across file variables in blkidP.h [smatch scan]Sami Kerola2017-02-201-5/+0Star
| | | | | | | | | Else these variables will cause following warning: libblkid/src/superblocks/superblocks.c:165:29: warning: symbol 'superblocks_drv' was not declared. Should it be static? Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libblkid: add blkid_probe_set_sectorsize()Karel Zak2017-01-131-0/+16
| | | | | | | | | The usual way is to use ioctl to ask block device for sector size, but this is useless for disk images (regular files). And the default (512-bytes) may be pretty wrong for disk images from 4K disks. Let's support a way how to specify proper sector size. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: once again some printf format stringsRuediger Meier2016-10-271-1/+1
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: fix some compiler warningsRuediger Meier2016-10-271-0/+4
| | | | | | | | | | libsmartcols/samples/fromfile.c:59:2: warning: passing argument 3 of 'string_to_bitmask' from incompatible pointer type text-utils/pg.c:79:0: warning: "TABSIZE" redefined libblkid/src/read.c:455:13: warning: 'debug_dump_dev' defined but not used [-Wunused-function] libblkid/src/probe.c:769:13: warning: unused function 'cdrom_size_correction' [-Wunused-function] /usr/include/sys/termios.h:3:2: warning: "this file includes <sys/termios.h> which is deprecated, use <termios.h> instead" [-W#warnings] Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libblkid: remove unused functionKarel Zak2016-08-301-9/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: simplify if clause [oclint]Sami Kerola2016-07-211-6/+4Star
| | | | | | | | Move negative and positive testing of 'has' variable to top level, and test flag bit mask on second level. This way the 'has' needs to be checked only once. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libblkid: don't check nonnull attributes for NULL [-Wnonnull-compare]Karel Zak2016-06-141-79/+27Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-9/+9
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* libblkid: make I/O errors on CDROMs non-fatalKarel Zak2016-04-281-1/+4
| | | | | | | | | It seems too tricky to get a real size of the data track on hybrid disks with audio+data. It seems overkill to analyze all header in libblkid and on some disks it's probably possible to get I/O error almost everywhere due to crazy copy protection etc. Signed-off-by: Karel Zak <kzak@redhat.com>
* Revert "libblkid: check for multi-session CDROMs"Karel Zak2016-04-271-45/+6Star
| | | | | | | | | | | This reverts commit a14cc9a5046bc4954b4110323c83599f90f9f35e. We need a better way (probably analyze track ioctls CDROMREADTOCHDR and CDROMREADTOCENTRY) to get also proper track size. The original patch works only if data track is the last track. Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: check for multi-session CDROMsKarel Zak2016-04-271-6/+45
| | | | | | | | | | | | | | | .. and read last session if probing offset is not specified. udev uses cdrom_id to get last session offset, so people don't see a problem with hybrid media (audio+data), but if you execute blkid on command line (without -O <offset>) then you get I/O errors. It seems that we can use the same way as kernel filesystem iso9960 driver when session= mount option is not specified ... just use CDROMMULTISESSION ioctl to get last session offset and probe this last session rather than all medium. Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: fix mistake in debug messageKarel Zak2016-04-191-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: reduce probing area for crazy CDROMsKarel Zak2016-04-191-1/+49
| | | | | | | | | | Linux kernel reports devices greater than area readable by read(2). The readable area is usually 2-3 CD blocks smaller (CD block is 2048-bytes) than size returned by BLKGETSIZE. This patch checks for this issues to avoid I/O errors in probing functions. Reported-by: Thomas Schmitt <scdbackup@gmx.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: make blkid_do_wipe() work with probes with offsetPetr Uzel2016-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a probe is created with an offset, e.g. via blkid_probe_set_device(), this offset is correctly used when looking for the signatures, but is not respected by blkid_do_wipe() function. Therefore the signature is removed from an invalid location. Usecase: Wiping signatures from an area on the block device where partition is to be created (but as it does not exist yet, there's no device node for it and probe on the whole block device has to be used with correct offset and length). Reproducer: ======================== wiper.c =========================== const char *dev; unsigned long offset; unsigned long size; int main(int argc, char** argv) { if (argc != 4) { printf("usage: wiper dev offset size\n"); exit(1); } dev = argv[1]; offset = strtoull(argv[2], NULL, 10); size = strtoull(argv[3], NULL, 10); printf("dev=%s, off=%llu, size=%llu\n", dev, offset, size); int fd = open (dev, O_RDWR); if (fd == -1) { perror("open"); exit(1); } blkid_loff_t wipe_offset = offset * SECTOR_SIZE; blkid_loff_t wipe_size = size * SECTOR_SIZE; int ret; blkid_probe pr; pr = blkid_new_probe(); if (!pr) return 0; ret = blkid_probe_set_device(pr, fd, wipe_offset, wipe_size); ret = blkid_probe_enable_superblocks(pr, 1); ret = blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC); while (blkid_do_probe(pr) == 0) { ret = blkid_do_wipe(pr, 0); } blkid_free_probe(pr); close(fd); } ======================== wiper.c =========================== Steps to reproduce: modprobe scsi_debug parted -s /dev/sdX mklabel gpt parted -s /dev/sdX mkpart first 2048s 4095s mkfs.ext2 /dev/sdX1 wipefs -np /dev/sdX1 ./wiper /dev/sdX1 2048 2048 Actual result: wiper gets into endless loop, because blkid_do_wipe() wipes at wrong location (1080), leaving the signature on /dev/sdc1. So it is again found by blkid_do_probe(), and so on. Expected result: wiper clears the ext2 signature at offset 1049656(=1080+2048*512). Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
* libblkid: revert mmap usageKarel Zak2016-03-301-88/+2Star
| | | | | | | | | | | | | The implementation has not been ready for I/O errors and it seems that there is no elegant way how to resolve this issue. Linux returns SIGBUS on mmap errors and play with signals (or longjumps) in shared library is really bad idea. It also seems that mmaped devices have some unexpected side-effects with page-cache where for example dd returns old data for already modified device etc. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: again fixing many printf format stringsRuediger Meier2016-03-071-13/+15
| | | | | | | | | | | | | | | | | | | This is again a huge patch regarding printf format strings to fix compiler warnings seen on clang/OSX. I'm trying to follow these rules strictly: #type #format #cast uintmax_t %ju - intmax_t %jd - uint64_t PRIu64 - int64_t PRId64 - size_t %zu - ssize_t %zd - ino_t %ju (uintmax_t) off_t %jd (intmax_t) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: fix compiler warnungs (unsigned/signed)Ruediger Meier2016-02-231-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These ones should be fixed: libblkid/src/probe.c:393:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/probe.c:907:25: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/probe.c:1221:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:540:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1043:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1056:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1057:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1061:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1199:27: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/partitions/partitions.c:1410:26: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/partitions/partitions.c:1431:25: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/superblocks/linux_raid.c:151:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] libblkid/src/superblocks/linux_raid.c:155:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] libblkid/src/superblocks/superblocks.c:375:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/superblocks/xfs.c:141:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libsmartcols/src/table.c:333:24: warning: signed and unsigned type in conditional expression [-Wsign-compare] libsmartcols/src/table.c:344:25: warning: signed and unsigned type in conditional expression [-Wsign-compare] libsmartcols/src/table_print.c:753:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/ask.c:364:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/utils.c:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/context.c:435:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/context.c:730:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/script.c:557:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/dos.c:1791:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/gpt.c:813:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] disk-utils/partx.c:140:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] disk-utils/partx.c:551:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] disk-utils/partx.c:640:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* docs: fix typos found by codespellRuediger Meier2016-02-031-2/+2
| | | | | | Using "codespell" from https://github.com/lucasdemarchi/codespell Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libblkid: use internally uint64_t for offsets and sizesKarel Zak2016-01-121-55/+39Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: fix buffers mapping on 32bit archsKarel Zak2015-12-031-9/+12
| | | | | Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* blkid: don't mark zfs as RAIDKarel Zak2015-11-181-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: add read() based fallback for char (UBI) devsKarel Zak2015-09-241-9/+60
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: use mmap() rather than read()Karel Zak2015-09-241-64/+141
| | | | | | | | | | | | | | | | | | | | | | diff between perf stat -e 'syscalls:sys_enter_*' for old and new version: - 35 syscalls:sys_enter_lseek - 38 syscalls:sys_enter_read + 3 syscalls:sys_enter_read ... - 19 syscalls:sys_enter_mmap + 17 syscalls:sys_enter_mmap - 0.001083084 seconds time elapsed + 0.000751722 seconds time elapsed The patch dramatically reduces malloc()+seek()+read() operations in libblkid. The code mmaps ~2MiB of the begin and the end of the device and it moves buffers management to kernel. Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: fix inconsistent indenting [smatch scan]Karel Zak2015-08-051-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: fix gtk-docs related warningsKarel Zak2015-05-281-2/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: cleanup names, don't copy probing resultsKarel Zak2015-02-241-42/+66
| | | | | | | | | | * cleanup function and variable names (s/vals/values/) * in "safe probe" mode libblkid copies probing result from the first attempt, this is unnecessary, with values list we can just move values to another list rather than copy all. * add new debug messages Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: make probing data structures more dynamicOndrej Oprala2015-02-241-68/+133
| | | | | | | | | | | | | * replace static probing result array with list * use allocated buffers for probing result variables [kzak@redhat.com: - rename some functions - clean up \0 terminator usage in variables - remove never used code to convert UUID to lower-case - remove possible memory leaks on errors] Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: fix potential bufer overflowsSebastian Krahmer2014-12-051-0/+7
| | | | | | | | | | While digging deeper into libblk probing, I found that some computations might wrap and allocate too few buffer space which then overflows. In particular on 32bit systems (chromebook) where size_t is 32bit, this is problematic (for 64bit the result fits into the calloc size_t). Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: zeroize errno on blkid_probe_get_buffer() successKarel Zak2014-10-071-1/+4
| | | | | | | | | | Since 37f4060225df0591ab8e1dd676dbc8115d900d4f prober functions are sensitive to errno, it seems more robust to set errno=0 with in blkid_probe_get_buffer() on success than set the zero on all places where we call blkid_probe_get_buffer(). Addresses: https://github.com/karelzak/util-linux/issues/119 Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: move string trim function to strutils.hKarel Zak2014-08-251-19/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: fix compiler warning [-Wimplicit-function-declaration]Karel Zak2014-06-181-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add sysfs_devno_is_lvm_private() from libblkidKarel Zak2014-06-171-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: ignore private LVM devicesKarel Zak2014-06-101-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The virtual private LVM devices do not contain any blkid relevant data and it does not make any sense to scan for superblocks or partitions on the devices, because we can interpret data from the devices in bad way. Unfortunately, for LVM has "private" very special meaning. The private LVM devices are accessible and readable (according to LVM guys it's feature, because debugging etc.). The problem is pretty visible with LVM thin provisioning where a virtual pool device contains segments from the top-level thin devices. Mountable top-level LVM-thin device: # blkid -o udev -p /dev/mapper/vg-thin1 ID_FS_UUID=57ed6490-903b-416c-91d2-6d06804ec60c ID_FS_TYPE=ext4 Virtual private LVM-pool device (contains data from all thin devices): # blkid -o udev -p /dev/mapper/vg-pool0 ID_FS_UUID=57ed6490-903b-416c-91d2-6d06804ec60c ID_FS_TYPE=ext4 ... this is incorrect, vg-pool0 is unmountable. LVM uses special UUID suffixes for private devices. All devices with uuid in format "LVM-<uuid>-<type>" are private. This patch modifies libblkid to not scan such devices. The high-level API ignores such devices at all now. The low-level API allows to assign the device to blkid_prober, but all scan functions always return nothing and library does not read anything from the device. The another functionality (get parental device, topology, sector sizes, etc.) still works as expected. The change affects only probing code. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1101345 Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: remove private function from docsKarel Zak2014-04-071-7/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>