summaryrefslogtreecommitdiffstats
path: root/sys-utils/losetup.c
Commit message (Collapse)AuthorAgeFilesLines
* losetup: Typo fixStanislav Brabec2019-06-211-1/+1
| | | | | | Fix a typo in usage introduced in a1a41597bf. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* misc: replaces atexit(close_stdout) with new close_stdout_atexit()Karel Zak2019-06-171-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-6/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: update an error messageJeffrey Ferreira2019-01-221-1/+1
| | | | | | | | Update an error message to add --partscan to the list of options only allowed during loop device setup. Signed-off-by: Jeffrey Ferreira <jeffpferreira@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: properly use --sector-size when create a new deviceKarel Zak2019-01-221-17/+19
| | | | | | | | | | | | | The --partscan functionality depends on sector size. Make sure sector size is set before we force kernel to scan the device for partitions. For example: losetup -f loopfile --sector-size 4KiB --partscan --show where 'loopfile' contains GPT with 4096 sectors. Reported-by: Jeffrey Ferreira <jeffpferreira@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/loopdev: differentiate between setter()s and ioctl callsKarel Zak2019-01-221-4/+4
| | | | | | | | Now the internal API uses loopcxt_set_...() to set context variables as well as to call ioctls. This patch introduces loopcxt_ioctl_...() to makes things more obvious to readers. Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: use offset in warn_size() calculationKarel Zak2019-01-181-2/+5
| | | | | | | | | | | | | | | | | | # dd if=/dev/urandom of=dummy bs=513 count=1 2>/dev/null # losetup -f --show --offset 1 dummy /dev/loop0 losetup: dummy: Warning: file does not fit into a 512-byte sector; the end of the file will be ignore The warning is bogus as with offset the size of the file fits into 512-byte sector. Simple test that all is right: # dd if=dummy bs=1 skip=1 2>/dev/null | sha256sum - /dev/loop0 da2ed0ade6ea518a802cd8a7a3c01c408ad8699ef6856b0b01f92b867d4ba9b5 - da2ed0ade6ea518a802cd8a7a3c01c408ad8699ef6856b0b01f92b867d4ba9b5 /dev/loop0 Addresses: https://github.com/karelzak/util-linux/issues/722 Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: fix mem leak, improve code [coverity scan]Karel Zak2018-07-251-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path lib/sysfs: add debugKarel Zak2018-06-211-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: keep -f and <devname> mutually exclusiveKarel Zak2018-06-071-0/+3
| | | | | | | | | | | | | | | | losetup tries to blindly use specified device as well as search for the first free device, the result is: # losetup /dev/loop1 -f /tmp/tfile_loop1 losetup: /dev/loop1: failed to set up loop device: Invalid argument fixed version: # losetup /dev/loop10 -f img losetup: unexpected arguments Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1566432 Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: add --output-all optionSami Kerola2018-05-031-1/+8
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* losetup: use scols_column_set_json_type()Karel Zak2018-04-181-9/+15
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: fix bitwise vs. logical typo [coverity scan]Karel Zak2017-10-121-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: rename to --sector-size and LOG-SECKarel Zak2017-10-021-6/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: Add support for logical block sizeStanislav Brabec2017-09-271-13/+38
| | | | | | | | | | | | | | | | | | | | Kernel since 4.14 supports setting of logical block size[1]. It allows to create loop devices that report logical block size different from 512. Add support for this feature to losetup. References: [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/block/loop.c?id=89e4fdecb51cf5535867026274bc97de9480ade5 [kzak@redhat.com: - fix loopcxt_get_blocksize() - remove lo_blocksize from loop_info64] Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Cc: Ming Lei <ming.lei@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Omar Sandoval <osandov@fb.com> Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-4/+6
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: consolidate usage() "Available columns"Karel Zak2017-06-261-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: add missing initializer [clang]Sami Kerola2017-06-141-1/+1
| | | | | | | | | | | sys-utils/losetup.c:290:12: warning: variable 'rc' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] sys-utils/losetup.c:293:7: note: uninitialized use occurs here sys-utils/losetup.c:290:8: note: remove the 'if' if its condition is always true sys-utils/losetup.c:228:9: note: initialize the variable 'rc' to silence this warning Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* 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>
* misc: consolidate smartcols error messagesKarel Zak2017-05-181-6/+10
| | | | | | ... just to keep translators happy Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup.8: Reorder options documentationFrederick Grose2017-04-041-5/+6
| | | | | | | | | | | | Reorder options to match onboard help and group functionally. Include some missing optional arguments. [kzak@redhat.com: - don't include available columns in man page, - add comments to the usage() - fix order in usage() - fix typo in usage()] Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-22/+22
| | | | | | | | | | text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer Since many 'struct option' has used zero as NULL make them more readable in same go by reindenting, and using named argument requirements. Reference: https://lwn.net/Articles/93577/ Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup --nooverlap: fix typoStanislav Brabec2016-10-061-1/+1
| | | | | | | | Option is documented and used as --nooverlap, bud coded as --nooverlaps. --nooverlap is considered as shortened option, making the typo invisible. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* losetup: allow to use --nooverlap when device specifiedKarel Zak2016-08-171-1/+20
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: Prevent AUTOCLEAR detach raceStanislav Brabec2016-08-171-0/+6
| | | | | | | | | | | | | Kernel needs some time to delete a device after losetup --detach. If the losetup --find --nooverlay is called just after losetup --delete, it can sometimes attempt to recycle the device that is just being released. To prevent this race, clear the AUTOCLEAR flag of the device. [kzak@redhat.com: - rebase to the new version of the code] Signed-off-by: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: add --nooverlap optionsKarel Zak2016-08-171-42/+94
| | | | | | | | | | | | | | | | | | | | | This patch introduces overlap detections and loop devices re-use for losetup(8). We already support this feature for mount(8) where it's enabled by default (because we mount filesystems and it's always mistake to share the same filesystem between more loop devices). Stanislav has suggested to enable this feature also for losetup by default. I'm not sure about it, IMHO it's better to keep losetup(8) simple and stupid by default, and inform users about possible problems and solutions in the man page. The feature forces losetup to scan all loop devices always when new one is requested. This maybe disadvantage (especially when we use control-loop to avoid /sys or /dev scans) on system with huge number of loop devices. Co-Author: Stanislav Brabec <sbrabec@suse.cz> Signed-off-by: Karel Zak <kzak@redhat.com>
* Add sizelimit to internal APIStanislav Brabec2016-08-031-4/+4
| | | | | | | | | | | | | | 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>
* losetup: fix outdated commentYuriy M. Kaminskiy2016-04-181-1/+1
| | | | | | | | | | | | | From abb2a420924c792be33aa3ed825b1348ea7d51a9 Mon Sep 17 00:00:00 2001 From: "Yuriy M. Kaminskiy" <yumkam@gmail.com> Date: Wed, 13 Apr 2016 17:30:10 +0300 Subject: [PATCH] losetup: fix outdated comment --direct-io argument was made optional by f98d9641a371421640a8f1cfe497030758f86dca, but this comment was not updated accordingly Signed-off-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
* Revert "include sysmacros.h where used"Karel Zak2016-03-081-1/+0Star
| | | | This reverts commit 46a40c018438b7b2b25083a5e5a4a21055a0c1e9.
* include sysmacros.h where usedMike Frysinger2016-03-081-0/+1
| | | | | | | | BSD/Linux systems stick major/minor/makedev in sysmacros.h. Newer Linux libraries have been moving away from including sysmacros.h implicitly via sys/types.h, so include it directly. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* losetup: clean up --direct-ioKarel Zak2015-11-191-4/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: support list direct ioMing Lei2015-11-191-0/+6
| | | | | | So that user can see if DIO is set for current loop device. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
* losetup: support ioctl cmd of LOOP_SET_DIRECT_IOMing Lei2015-11-191-2/+25
| | | | | | | | From v4.4, linux kernel starts to support direct I/O and AIO to backing file for loop driver, so allow losetup to enable the feature by using LOOP_SET_DIRECT_IO ioctl cmd. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
* losetup: add --jsonKarel Zak2015-06-051-1/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: print more usable error message on failed -fKarel Zak2015-06-031-2/+11
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1215370 Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/strutils: fix string_add_to_idarray() int vs. size_tKarel Zak2015-04-221-4/+6
| | | | | | | | | | | | | | | | | | | | The function uses "int" as argument, but for array size (and index) is better to use unsigned type (size_t). If we mix "size_t" in util (e.g. fdisk) and "int" in lib/strutils.c then result is unexpected behavior on ppc64. # sfdisk --list -o DEVICE,START,SIZE /dev/sdb Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 32768 bytes Disklabel type: gpt Disk identifier: 3B8559DB-33AF-43E9-BEFC-C331D829B539 lt-sfdisk: libfdisk/src/label.c:178: fdisk_label_get_field: Assertion `id > 0' failed. The patch cleanup all code to use size_t everywhere. Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-0/+3
| | | | | | | | | This adds a concise description of a tool to its usage text. A first form of this patch was proposed by Steven Honeyman (see http://www.spinics.net/lists/util-linux-ng/msg09994.html). Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* losetup: clean up columns[] usageKarel Zak2014-07-181-7/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libsmartcols: add debug messagesKarel Zak2014-06-061-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build: fix some compiler warningsRuediger Meier2014-05-301-2/+0Star
| | | | | | | | | | | | Most of them catched on 32bit gcc and icc. disk-utils/fsck.cramfs.c: printf format type lib/boottime.c: unused variables misc-utils/cal.c: set but never used sys-utils/losetup.c: set but never used sys-utils/lscpu-dmi.c: defined but not used sys-utils/switch_root.c: comparison between signed and unsigned tests/helpers/test_sysinfo.c: printf format type
* losetup: don't ignore EBUSY in losetup when the loop device is givenStanislav Brabec2014-05-281-1/+1
| | | | | | | | | | losetup ignores the EBUSY error. In the loop fo A_CREATE action, it skips the error handling when errno = EBUSY. It's OK for the case where no loop device is specified, but the error has to be handled when the device is given explicitly. Author: Takashi Iwai <tiwai@suse.de> Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* losetup: return EXIT_FAILURE on unsuccessful -fKarel Zak2014-05-131-1/+2
| | | | | Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: remove square brackets from around three dotsBenno Schulenberg2014-05-061-5/+5
| | | | | | Also improve some option descriptions here and there. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* libsmartcols: clean up flags usageKarel Zak2014-04-031-3/+3
| | | | | | | | | * rename flags functions to scols_table_enable_* * rename *_no_foo() functions to _nofoo() * output formats are mutually exclusive, so don't use flags there * don't assume symbols in scols_new_table(), use scols_table_set_symbols() Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: tiny change to usage()Karel Zak2014-04-031-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: clean up scols usageKarel Zak2014-04-031-68/+58Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* losetup: use libsmartcolsOndrej Oprala2014-04-031-36/+46
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>