Commit Graph

76 Commits

Author SHA1 Message Date
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
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>
2017-02-20 12:58:49 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
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>
2016-12-19 13:13:34 +01:00
Stanislav Brabec f3b0d1505e losetup --nooverlap: fix typo
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>
2016-10-06 14:56:39 +02:00
Karel Zak d8ba61fcb4 losetup: allow to use --nooverlap when device specified
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-17 13:52:22 +02:00
Stanislav Brabec f27d989c67 losetup: Prevent AUTOCLEAR detach race
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>
2016-08-17 12:58:12 +02:00
Karel Zak 9a94b634a3 losetup: add --nooverlap options
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>
2016-08-17 12:28:33 +02:00
Stanislav Brabec 74a4705a99 Add sizelimit to internal API
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>
2016-08-03 11:53:28 +02:00
Yuriy M. Kaminskiy c79657ca85 losetup: fix outdated comment
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
f98d9641a3, but this comment was not
updated accordingly

Signed-off-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
2016-04-18 11:04:16 +02:00
Karel Zak 3fe3f560b7 Revert "include sysmacros.h where used"
This reverts commit 46a40c0184.
2016-03-08 14:26:33 +01:00
Mike Frysinger 46a40c0184 include sysmacros.h where used
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>
2016-03-08 14:21:55 +01:00
Karel Zak f98d9641a3 losetup: clean up --direct-io
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-11-19 11:57:05 +01:00
Ming Lei faeef4d2e9 losetup: support list direct io
So that user can see if DIO is set for current loop device.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
2015-11-19 11:27:36 +01:00
Ming Lei 64c3bb3cb7 losetup: support ioctl cmd of LOOP_SET_DIRECT_IO
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>
2015-11-19 11:27:36 +01:00
Karel Zak 4827093d4b losetup: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-05 10:30:52 +02:00
Karel Zak 362f5d2035 losetup: print more usable error message on failed -f
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1215370
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-03 12:05:09 +02:00
Karel Zak 40b175084f lib/strutils: fix string_add_to_idarray() int vs. size_t
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>
2015-04-22 11:08:05 +02:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
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>
2015-01-06 11:27:38 +01:00
Karel Zak d78deddc6d losetup: clean up columns[] usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-18 13:52:02 +02:00
Karel Zak 710ed55dcd libsmartcols: add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-06 13:47:06 +02:00
Ruediger Meier 60cb2c3720 build: fix some compiler warnings
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
2014-05-30 01:18:09 +02:00
Stanislav Brabec d6ef7d6c69 losetup: don't ignore EBUSY in losetup when the loop device is given
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>
2014-05-28 09:18:40 +02:00
Karel Zak 3e55659feb losetup: return EXIT_FAILURE on unsuccessful -f
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-13 11:34:30 +02:00
Benno Schulenberg aa06617f6e textual: remove square brackets from around three dots
Also improve some option descriptions here and there.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-05-06 11:12:13 +02:00
Karel Zak 0925a9dd6c libsmartcols: clean up flags usage
* 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>
2014-04-03 16:09:57 +02:00
Karel Zak 145766440a losetup: tiny change to usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:20 +02:00
Karel Zak 48f1f38b73 losetup: clean up scols usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:20 +02:00
Ondrej Oprala 7e86cd5470 losetup: use libsmartcols
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-04-03 12:29:19 +02:00
Karel Zak 5f68593d7a losetup: remove warning for unsupported -e and -E
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-06 09:08:40 +01:00
Karel Zak 961d69f799 losetup, mount: remove --pass-fd at all
The option is unsupported since v2.23, let's cleanup man pages and
code to remove it at all.

Reported-by: "Dale R. Worley" <worley@alum.mit.edu>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-06 09:02:36 +01:00
Sami Kerola f614b73c0e losetup, agetty: remove unnecessary if's before free()
Reference: http://git.savannah.gnu.org/cgit/gnulib.git/tree/build-aux/useless-if-before-free
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-12-02 10:59:20 +01:00
Benno Schulenberg 9c47f25e8d losetup: cut the remaining little block of help text into slices too
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-10-09 11:40:08 +02:00
Karel Zak a7d5202b5e losetup: don't require 512-byte aligned offsets
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>
2013-10-01 15:52:11 +02:00
Yuri Chornoivan 0d0d12adf8 Fix various typos 2013-09-28 13:33:59 +03:00
Karel Zak 5c32f352c8 losetup: use TT_FL_FREEDATA for tt table
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-16 16:46:59 +02:00
Karel Zak 3cb2413b02 losetup: use loop-control to explicitly ask for device
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>
2013-08-06 11:04:35 +02:00
Karel Zak 21ce3f3a4e losetup: fix loop device name usage
The code is not paranoid enough, loopcxt_set_device() only set the
device name to loopdev struct, but it does not check if the device
really exists.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-05 16:08:34 +02:00
Karel Zak 6d62bc0f9b losetup: make -j <path> more robust
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>
2013-08-05 15:35:26 +02:00
Karel Zak 01307ecf1b losetup: set errno for misaligned offsets
References: https://bugs.archlinux.org/task/36189
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-19 17:15:44 +02:00
Benno Schulenberg 97b820bffd textual: improve clarity of some error messages
Reported-by: Petr Písař <petr.pisar@atlas.cz>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:29:44 +02:00
Benno Schulenberg 136b23efde textual: harmonize some loop-device error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:11:13 +02:00
Karel Zak 9f56106df6 losetup: add --raw and --noheadings
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-13 12:00:24 +02:00
Karel Zak b048b8af3a losetup: use warn_size() for regular files only
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-13 11:00:47 +02:00
Jeff Mahoney 293714c0d1 loopdev: sync capacity after setting it
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>
2013-04-09 14:32:50 +02:00
Sami Kerola 114ade3d1b losetup: allow -j option argument to be relative path
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-05 13:56:03 +02:00
Sami Kerola 59a4ed117c losetup: make usage() translator friendly
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-01-25 16:40:05 +01:00
Sami Kerola e0b0676988 losetup: fix declarations [smatch scan]
sys-utils/losetup.c:309:2: error: 'for' loop initial declarations are only allowed in C99 mode
sys-utils/losetup.c:374:2: error: 'for' loop initial declarations are only allowed in C99 mode

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-01-09 13:37:23 +01:00
Karel Zak 65178cb3f2 losetup: allow to use -O without --list
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-12 14:36:29 +01:00
Karel Zak 4ad996d7f9 losetup: rename SIZE->SIZELIMIT
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-12 13:24:45 +01:00
Ondrej Oprala 896352d390 losetup: add --list and --output option
The --list --all is the default output:

  # losetup
  NAME       SIZE OFFSET AUTOCLEAR RO BACK-FILE
  /dev/loop0    0      0         0  0 /home/fs-images/swap.img
  /dev/loop1    0    100         0  0 /home/fs-images/disk.img

[kzak@redhat.com: - default to --all if no device specified,
                  - cleanup column names (add BACK- prefix)
                  - add MAJ:MIN to of the loopdev device]

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-12 13:08:00 +01:00
Karel Zak f4bf95926a lib/loopdev: improve debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-17 11:42:21 +02:00