summaryrefslogtreecommitdiffstats
path: root/libmount/src/context_loopdev.c
Commit message (Collapse)AuthorAgeFilesLines
* libmount: cleanup licenses sections in the filesKarel Zak2018-08-161-3/+8
| | | | | | | | | * add SPDX-License-Identifier (see https://spdx.org/licenses/) * add "This file part of libmount from util-linux project." * use proper text for LGPL-2.1-or-later * use the same texts everywhere Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: switch namespace when appropriateVaclav Dolezal2018-06-111-0/+8
| | | | Signed-off-by: Vaclav Dolezal <vdolezal@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>
* libmount: Fix incorrect detach of reused loop deviceStanislav Brabec2017-01-161-3/+7
| | | | | | | | | | | | | | | If -oloop is used and the loop device is reused, the loop device is detached after umount. It is incorrect as it could break the another task using the loop device. This is caused by mnt_context_enable_loopdel(,TRUE) that is called from mnt_context_prepare_umount() whenever "loop" option is used, independently on AUTOCLEAR flag. Remove the "loop" option for reused devices to prevent detaching of reused loop device. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* libmount: fix mount -oloop=/dev/loopX regressionStanislav Brabec2017-01-161-1/+6
| | | | | | | | | | | | | | | | | | | | | | | If mount option "loop" is used with an argument, it should be respected. Commit 8efad715 introduced a regression. Even with an argument, overlaying loop device is searched and argument is ignored. It could have unexpected side effects. If argument is set, never allocate a new loop device. How to reproduce: mkdir -p cdrom mkisofs -o cdrom.iso cdrom/ 2>/dev/null losetup /dev/loop0 cdrom.iso strace mount -t auto -o ro,loop=/dev/loop1 cdrom.iso /mnt 2>&1 | grep ^mount cat /proc/self/mountinfo | grep /mnt umount /mnt losetup -d /dev/loop0 mount("/dev/loop0", "/mnt", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL) = 0 327 60 7:0 / /mnt ro,relatime shared:241 - iso9660 /dev/loop0 ro losetup: /dev/loop0: detach failed: No such device or address Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* libmount: one iteration to detect overlap and reuse loopdevKarel Zak2016-08-041-32/+31Star
| | | | | | | | | | The current code scans loopdevs to detect already used loop device and another scan to detect overlap. Let's use one scan only, for this purpose loopcxt_find_overlap() has been modified to return info (rc==2) about full size and offset match. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: cleanup sizelimit checkKarel Zak2016-08-041-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmout: Reuse loop device safelyStanislav Brabec2016-08-031-13/+52
| | | | | | | | Add a safety check to mnt_context_setup_loopdev(). Only a loop device with equal offset and sizelimit will be reused. If any overlapping loop device exists, MNT_ERR_LOOPOVERLAP is returned. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* Add sizelimit to internal APIStanislav Brabec2016-08-031-3/+3
| | | | | | | | | | | | | | Fully safe checks of loop device need to check sizelimit. To prevent need of two nearly equal functions, introduce sizelimit parameter to several internal functions: loopdev_is_used() loopdev_find_by_backing_file() loopcxt_is_used() loopcxt_find_by_backing_file() If sizelimit is zero, fall back to the old behavior (ignoring of sizelimit). Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* libmount: Fix possible crash in mnt_context_setup_loopdev()Stanislav Brabec2016-08-031-2/+4
| | | | | | If loopcxt_init() fails, Iloopcxt_deinit() should not be called. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* libmount: don't check nonnull attributes for NULL [-Wnonnull-compare]Karel Zak2016-06-141-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: reuse existing loop deviceStanislav Brabec2016-04-221-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | According to the Al Viro[1], kernel has no way to detect that a single file is used by multiple loop devices, and multiple mounts of the same file using different loop devices will result in a data corruption. Exactly this now happens, if multiple btrfs sub-volumes in one file are mounted with "-oloop". Make use of multiple -oloop mounting the same file safe: Do a loop devices lookup, and if a loop device is already initialized, use it. Hopefully it is possible, as "losetup -d" will return OK, even if the device itself is in use, and is not released. Problems: There is a risk of race condition between the lookup and real mount. Once loop device is initialized read-only, kernel offers no way to turn it to read-write. It has to fail. References: https://lkml.org/lkml/2016/2/26/897 Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* libmount: Re-organize is_mounted_same_loopfile()Stanislav Brabec2016-04-221-12/+14
| | | | | | | | First parse options, then initialize context. No change in function. The change is needed for loop device reuse. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* libmount: add loop to debug outputKarel Zak2016-02-161-16/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: cleanup assert() usageKarel Zak2015-08-041-9/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: replace custom DBG() with include/debug.hKarel Zak2014-11-041-2/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add missing assert()Karel Zak2014-07-171-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't touch mtab when mount -n specifiedKarel Zak2014-06-171-1/+1
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1109367 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use new debug functionsKarel Zak2014-03-211-16/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: be robust when work with loopdev backing file pathsKarel Zak2013-08-051-13/+12Star
| | | | | | | | It's usually unnecessary as we compare devno and ino, but let's use absolute paths for situations when it's necessary to compare paths as strings. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix typosOndrej Oprala2013-08-051-7/+7
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* libmount: allow to use propagation flags in fstabKarel Zak2013-01-151-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Linux kernel does not allow to change more than one propagation flag by one mount(2) syscall. The flags also cannot be mixed with another mount options. It means that the propagation flags cannot be stored in /etc/fstab, manual "mount --make-* <mountpoint>" is always necessary after successful mount. Painful... This patch implements additional mount(2) after previous successful mount(2) (or exec /sbin/mount.<type>). For example: mount /dev/sda1 /A -o private,unbindable,ro or fstab entry: /dev/sda1 /A auto ro,private,unbindable is implemented by three mount(2) calls: - 1st mounts /dev/sda1 with MS_RDONLY - 2nd sets MS_PRIVATE flag - 3rd sets MS_UNBINDABLE flag. It's the same as as to manually call: mount /dev/sda1 /A -o ro mount --make-private /A mount --make-unbindable /A This solution is not atomic, and umount(2) is not called if propagation flags are not successfully applied, only error is returned. This change does not affect libmount API, so one beautiful day when mount(2) syscall will be improved we can drop this nasty patch. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: clean nonnull attribute usageKarel Zak2012-12-041-2/+11
| | | | | | | | | | - use __attribute__((nonnull) for functions where we not able to return an return code ("is", "has" and some "get" functions). - use __attribute__((nonnull) for small functions where we always modify any of the function argument (some mnt_optstr_* functions) Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: append loop option when automatically create loopdevKarel Zak2012-09-181-1/+5
| | | | | | | | | The loop option is optional, mount(8) is able to detect that the source path is regular file (image) with known filesystem -- then a loop device is automatically created. In this case we have to store "loop" option to mtab on systems without autoclear loopdev flag. Signed-off-by: Karel Zak <kzak@redhat.com>
* mount: losetup: remove obsolete encryption supportLudwig Nussel2012-09-111-18/+4Star
| | | | | | | | | | | | | | | kernel cryptoloop is deprecated since ages and support for cryptoloop in util-linux is incomplete/broken. - no password hashing - last 8 bit of key are always set to zero - no binary keys possible (stops reading key at \n and \0) In the past some Distros added the above features with patches. So remove cryptoloop support from util-linux completely to make sure people won't try using it. Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: use warn_unused_result forimportant functionsKarel Zak2012-06-211-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add MNT_ERR_MOUNTOPTKarel Zak2012-05-281-2/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add MNT_ERR_LOOPDEVKarel Zak2012-05-281-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix compiler warnings [-Wuninitialized -Wformat]Karel Zak2012-01-171-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add post-mount checks to detect ro/rwKarel Zak2012-01-161-2/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: avoid duplicate loopdevsKarel Zak2012-01-161-0/+67
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix auto-loopdevKarel Zak2012-01-121-7/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add support for encrypted loopdevsKarel Zak2012-01-111-2/+24
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: consolidate MNT_FS_* codeKarel Zak2012-01-021-3/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: support -o loop=<devname>Karel Zak2011-09-301-3/+8
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use loopdev debug facilityKarel Zak2011-09-291-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: support {offset,sizelimit}= foor loopdevsKarel Zak2011-09-291-18/+51
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix use of logical '&&' with constant operandFrancesco Cosoleto2011-09-271-1/+1
| | | | | | Found by clang. Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
* libmount: add mount support for loopdevsKarel Zak2011-06-101-0/+227
Signed-off-by: Karel Zak <kzak@redhat.com>