summaryrefslogtreecommitdiffstats
path: root/lib/loopdev.c
Commit message (Collapse)AuthorAgeFilesLines
* lib/loopdev: remove test programKarel Zak2014-11-041-149/+0Star
| | | | | | | All is already covered by losetup and mount. The test program has never been used in our regression tests. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: replace custom DBG() with include/debug.hKarel Zak2014-11-041-102/+88Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: comparing an array to null is not useful [coverity scan]Karel Zak2014-07-171-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev.c: reset errno before strtol() callYuriy Nazarov2014-06-191-0/+1
| | | | Fixed unsuccessful attempt to find unused loop devices if 0-7 devices already used and /dev/loop directory exists.
* losetup: don't clear FD at EBUSY error in loopcxt_setup_device()Stanislav Brabec2014-05-281-1/+1
| | | | | | | | | loopback lib clears the existing FD unconditionally at error in loopcxt_setup_device(). This is done even after EBUSY, thus the second call actually clears the previous setup wrongly. Author: Takashi Iwai <tiwai@suse.de> Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* losetup: fix -f on systems without /dev/loop-controlKarel Zak2014-05-141-14/+35
| | | | | Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: wait for udevKarel Zak2014-01-241-5/+18
| | | | | | | | | | | | | On system with /dev/lop-control the udevd creates /dev/loopN nodes. It seems better to wait a moment after unsuccessful open(/dev/loopN) and try it to open again. The problem is pretty visible on systems where udevd also modifies permission for loopN devices, then open() fails with EACCES when losetup executed by non-root user (but user who is in "disk" group). Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1045432 Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: don't require 512-byte aligned offsetsKarel Zak2013-10-011-0/+6
| | | | | | | | | | | | | | | | Kernel aligns the device size, but the offset where the device starts is not required to be aligned. # losetup --offset 32 -f file.img is just fine, the final size of the look device will be (in sectors) (backing_file_size - offset) >> 9 so we have to do the same in userspace when we check for successful set capacity ioctl. Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: use loop-control to explicitly ask for deviceKarel Zak2013-08-061-0/+30
| | | | | | | | | | | | | | | | Now we use LOOP_CTL_GET_FREE ioctl to ask for free device, for example losetup -f foo.img Unfortunately, losetup(8) allows to ask for specified device losetup /dev/loop100 foo.img and in this case we assume that the device already exists in the system. This is incorrect, we should be able to use loop-control LOOP_CTL_ADD ioctl to ask for the specified device. Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: set errno for misaligned offsetsKarel Zak2013-07-191-7/+19
| | | | | References: https://bugs.archlinux.org/task/36189 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: assigned value is never read [clang-analyzer]Sami Kerola2013-07-091-1/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/loopdev: fix loopcxt_check_size() to work with blkdevsKarel Zak2013-05-131-1/+15
| | | | | | | | | | | | | | The loopcxt_check_size() is workaround for kernels < v3.9, kernel has been fixed by commit 541c742a7559eb65f0e36d3e2338c2ca532a3e61. The function sets loopdev size according to backing file size. The problem is that the backing file could be a block device where stat.st_size is zero, so we have to use blkdev_get_size() for block devices. Addresses: https://bugs.archlinux.org/task/35193 Reported-by: Dave Reisner <d@falconindy.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* loopdev: sync capacity after setting itJeff Mahoney2013-04-091-3/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I recently tried to mount an hfsplus file system from an image file with a partition table by using the loop offset and sizelimit options to specify the location of the file system. hfsplus stores some metadata at a set offset from the end of the partition, so it's sensitive to the device size reported by the kernel. It worked with this: But failed with this: /dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000 /dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000 /proc/partitions shows the correct number of blocks to match the sizelimit. But if I set a breakpoint in mount before the mount syscall, I could see: 102400000 102432768 The kernel loop driver will set the gendisk capacity of the device at LOOP_SET_STATUS64 but won't sync it to the block device until one of two conditions are met: All open file descriptors referring to the device are closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl is called to sync it. Since mount opens the device and passes it directly to the mount syscall after LOOP_SET_STATUS64 without closing and reopening it, the sizelimit argument is effectively ignroed. The capacity needs to be synced immediately for it to work as expected. This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since the device isn't yet released to the user, so it's safe to sync the capacity immediately. [kzak@redhat.com: - port to the current git HEAD, - use uint64_t] Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: use O_CLOEXEC in libcommonKarel Zak2013-04-031-5/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include: cleanup copyright headersKarel Zak2013-01-081-1/+4
| | | | | | | We use the code from include/ and lib/ on many places, so use public domain if possible or LGPL for code copied from libs. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: fix loopdev_find_by_backing_file()Karel Zak2012-12-191-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: make loopcxt_get_device() more robustKarel Zak2012-11-121-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: check for /sysKarel Zak2012-10-171-0/+6
| | | | | | | | | The current loopdev code prefers /sys to get information about loop devices. The old methods like scan /dev are fallback solution only. Unfortunately, the code does not check if /sys is mounted. Addresses: http://blog.flameeyes.eu/2012/10/sophistication-can-be-bad Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: improve debug messagesKarel Zak2012-10-171-4/+18
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* mount: losetup: remove obsolete encryption supportLudwig Nussel2012-09-111-56/+0Star
| | | | | | | | | | | | | | | 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: minor bug fix: add missing semicolonSami Kerola2012-07-161-1/+1
| | | | | | | | | Missing semicolon made test_loop_info() to return function loopcxt_enable_debug() return value, which happen to be void. I suspect the loopcxt_enable_debug() was usually not executed, while it should be. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* fix buffer overrun in some calls to sscanfKarel Zak2012-07-091-1/+1
| | | | | Reported-by: Sergei Antonov <saproj@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: use warn_unused_result forimportant functionsKarel Zak2012-06-211-24/+41
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: improve -a to report loopdevs < 512 bytesKarel Zak2012-06-121-17/+95
| | | | | | | | | | | | | | | | | | # ll ~/xxx2 -rw-r--r-- 1 root root 500 Jun 12 14:30 /root/xxx2 old version: # losetup -a new version: # losetup -a /dev/loop0: [2052]:535312 (/root/xxx2) The new version scans /sys/block/loopN, kernel >= 2.6.37 is required otherwise fallback to the original not-so-smart /proc/partitions scan. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=730266 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add MNT_ERR_LOOPDEVKarel Zak2012-05-281-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: more robust initializationKarel Zak2012-04-021-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: remove dead assigment and null deferenceKarel Zak2012-02-021-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: fix part scan detection codeKarel Zak2012-02-021-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: fix possible dir leak on errorKarel Zak2012-02-011-0/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,loopdev: remove duplicate includesKarel Zak2012-01-171-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: avoid duplicate loopdevsKarel Zak2012-01-161-1/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* loopdev: improve debug messagesKarel Zak2012-01-091-2/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* loopdev: support LO_FLAGS_PARTSCAN flag (kernel 3.2)Karel Zak2012-01-091-2/+62
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: rewrite loop setupKarel Zak2011-12-221-0/+8
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,loopdev: add missing functionsKarel Zak2011-12-221-41/+166
| | | | | | | | | - improve loop_info usage (don't call ioctl more than once) - add functions to get devno and inode of the backing file - add function for compare any file with backing file by devno + inode or by filename Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,loopdev: add LOOP_CTL_GET_FREE supportKarel Zak2011-11-071-7/+29
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* umount: use new lib/loopdev.c codeKarel Zak2011-09-301-0/+40
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* mount: use new lib/loopdev.c codeKarel Zak2011-09-301-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,loopdev: add debugu messagesKarel Zak2011-09-291-17/+109
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib,loopdev: fix use of logical '&&' with constant operandFrancesco Cosoleto2011-09-271-2/+2
| | | | | | Found by clang. Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
* libmount: potential null derefence [smatch scan]Karel Zak2011-09-121-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: [loopdev.c] correct qsort compare functionKarel Zak2011-08-231-1/+2
| | | | | Reported-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: [loopdev.c] correct trivial typoDavidlohr Bueso2011-08-081-1/+1
| | | | | | Should say "failed to find" instead of "failed to found". Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* build-sys: fix 'make checkincludes' warningsKarel Zak2011-07-281-2/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: [loopdev.c] cleanup flags usageKarel Zak2011-06-101-17/+97
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: [loopdev.c] add module for work loop devicesKarel Zak2011-05-301-0/+1053
Signed-off-by: Karel Zak <kzak@redhat.com>