Commit Graph

9521 Commits

Author SHA1 Message Date
Karel Zak 3c7fde5f92 libfdisk: add JSON dump output
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-15 13:18:09 +02:00
Karel Zak 0baeca2aef libfdisk: rename script functions to improve readability
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-15 10:38:47 +02:00
Karel Zak 025f5c0a2b tests: update fdisk BSD
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-11 15:13:17 +02:00
Karel Zak 5989556ad3 libfdisk: add new API to read label specific data
* removes list() label operation from internal API

  The list() has been based on fdisk_info() it was useless for
  anything else than print on stdout...

* add a new get_item() label operation and fdisk_get_disklabel_item() public API

  The new API provides abstract and pretty simple way how to get label
  specific disk label information, for example

     fdisk_get_disklabel_item(cxt, GPT_LABELITEM_ENTRIESLBA, &iterm);

  return LBA of the array with GPT entries.

  Note that this patch does not implement public functions to get
  data from the @item object.

* removes get_id() label operation -- it's subset of the new get_item()

* the new internal API is also used to implement backwardly compatible
  fdisk_list_disklabel() and fdisk_get_disklabel_id()

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-11 14:19:47 +02:00
Karel Zak 535748a617 libfdisk: (dos) fix cylinders calculation
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-10 16:55:29 +02:00
Karel Zak 8dd51c1833 fstrim: de-duplicate by mount source too
Now fstrim de-duplicates by target (mountpoint). This patch adds
de-duplication according to mount source (device) to avoid bind mounts
or devices mounted more than once. Note that the patch also check FS
root, the different FS roots of the same multi-root FS (e.g. btrfs)
maybe mounted on different places.

  # mount --bind /home/wine /mnt/test

old version:

  # fstrim -av
  /mnt/test: 0 B (0 bytes) trimmed            <---
  /home/wine: 0 B (0 bytes) trimmed           <---
  /boot: 0 B (0 bytes) trimmed
  /home: 0 B (0 bytes) trimmed
  /: 0 B (0 bytes) trimmed

new version:

  # fstrim -av
  /mnt/test: 0 B (0 bytes) trimmed            <---
  /boot: 0 B (0 bytes) trimmed
  /home: 171.8 MiB (180113408 bytes) trimmed
  /: 0 B (0 bytes) trimmed

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1162213
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-10 14:19:45 +02:00
Karel Zak 8c73e5096d fdisk: differentiate between +<sector> and +<size>{M,G,...}
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-10 13:06:15 +02:00
Karel Zak 85ccc1d425 libblkid: (nilfs2) check size for backup superblock only
The size of the device seems irrelevant for the primary superblock.
The primary superblock is stored on fixed offset, possible collision
between last partition and whole-disk is possible only for backup
superblock only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-09 16:01:16 +02:00
Karel Zak 3fabc3637c chrt: fix --help inconsistency
Reported-by: Martin Steigerwald <ms@teamix.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-09 11:16:45 +02:00
Karel Zak 00817742ce libblkid: (nilfs2) check devise size
Unfortunately, nilfs2 have the same problem like many RAIDs. It uses
the end of the device to store (backup) superblock. The end of the
last partition is the same location as the end of the whole-disk. It
means that the superblock seems valid for the last partitions as well
as for whole-device.

Fortunately, nilfs2 superblock contains size of the device, so we can
distinguish between whole-disk and partition device.

Reported-by: Heinz Diehl <htd+ml@fritha.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-09 10:37:11 +02:00
Karel Zak 7c43fd23ce libfdisk: improve +0 partition size
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 17:26:31 +02:00
Karel Zak 09a4ca5e45 libfdisk: (dos) fix tiny partitions calculation
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 16:45:15 +02:00
Karel Zak 765004f3eb libfdisk: (gpt) make it possible to create really small partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 16:02:17 +02:00
Karel Zak 68a8648ce5 libfdisk: support alignment to non power of 2
Let's create a disk with 33553920 bytes optimal I/O size:

	# modprobe scsi_debug dev_size_mb=1000 opt_blks=65535

and try to create partition:

	 echo -e 'n\n\n\n\n+512M\np\nq\n'  | fdisk /dev/sdc

old version:

	 Device     Boot Start     End Sectors  Size Id Type
	 /dev/sdc1       65535 1114110 1048576  512M 83 Linux

The next partition will be expected on sector 1114110 + 1, but it's
not aligned to optimal I/O:

        ((1114110 + 1) * 512) % 33553920 = 8192

fixed version:

 Device     Boot Start     End Sectors  Size Id Type
 /dev/sdc1       65535 1114094 1048560  512M 83 Linux

        ((1114094 + 1) * 512) % 33553920 = 0

Note that the same problem with alignment calculation has been fixed
in Linux kernel by commit b8839b8c55f3fdd60dc36abcda7e0266aff7985c
(Oct 2014).

The patch also improves fdisk_align_lba_in_range() to not align sizes
smaller than grain (default 1MiB) to make it possible to create really
small partitions.

Reported-by: Tom Yan <tom.ty89@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 15:57:23 +02:00
Guillem Jover 1c8beb3dfb sulogin: Use read instead of allocated size from getline()
The getline function distinguishes between the allocated and read
lenghts, and we should not mix them up, as we might end up processing
junk.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2015-06-08 12:10:05 +02:00
Guillem Jover f51275eedb include/c: Define F_DUPFD_CLOEXEC on kFreeBSD systems if missing
The kernel of FreeBSD version 10 and higher supports this fcntl command,
but the system libc, in this case glibc, might not yet know about it.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2015-06-08 12:10:04 +02:00
Guillem Jover fef6f84a15 lib/sysfs: Use dup_fd_cloexec instead of direct call to fcntl
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2015-06-08 12:10:03 +02:00
Guillem Jover 8e86d93d1e lib/fileutils: Add new dup_fd_cloexec function
This function duplicates and marks a file descriptor as close-on-exec.
Takes care of build and run-time support for the fcntl F_DUPFD_CLOEXEC
command, and other errors.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2015-06-08 12:10:02 +02:00
Andreas Henriksson c4417ee9d3 man: fix nolazytime typo in mount(8)
Avoids double negation...

Addresses: http://bugs.debian.org/786554
Reported-by: Felix Zielcke <fzielcke@z-51.de>
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2015-06-08 12:09:58 +02:00
Boris Egorov 5e3da11b3e bash-completion: remove unused variables [shellcheck]
Fix shellcheck SC2034 warnings.

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-08 12:09:54 +02:00
Boris Egorov bcce334df8 bash-completion: sync lscpu completion with code
Remove unexistent option, add two not listed in completion.

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-08 12:09:50 +02:00
Boris Egorov b5b80e5a6d bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:

    $ partx --output END,SECTORS,SCHEME,START,

You got these completions:

    END,SECTORS,SCHEME,START,FLAGS,  END,SECTORS,SCHEME,START,NR,
    END,SECTORS,SCHEME,START,TYPE,
    END,SECTORS,SCHEME,START,NAME,   END,SECTORS,SCHEME,START,SIZE,
    END,SECTORS,SCHEME,START,UUID,

Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.

Few issues remained:

    * completion interrupts after encountering ':' in listed option,
    like in 'MAJ:MIN' in lsblk, losetup.
    * lscpu completion is broken: it inserts space after '--extended',
    but lscpu assumes there is no space after this option. It also
    doesn't complete '--parse' option.
    * some completion options are outdated (for example, lscpu MMHZ). We
    need to sync them with code. Fix for lscpu follows.

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-08 12:09:48 +02:00
Karel Zak 6a768b5516 libsmartcols: keep JSON field names lower-case
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-05 11:58:42 +02:00
Karel Zak b3a2e889df lslocks: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-05 10:45:15 +02: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 8449f2cb59 findmnt: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-05 09:47:59 +02:00
Karel Zak 4a102a4871 lsblk: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-04 15:49:52 +02:00
Karel Zak 2a6cfc1361 libsmartcols: add JSON output format
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-04 15:47:21 +02:00
Ronny Chevalier 1280109fdc libmount: (docs) fix wording
Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
2015-06-03 13:21:52 +02:00
Ronny Chevalier 8b1333423a libmount: (docs) fix typo
Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
2015-06-03 13:06:59 +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 28cdf9c612 libmount: do not call umount helper on --fake
The umount.<type> helpers does not support --fake option and it does
not make sense to call the helpers at all. All we need is to remove
mtab/utab entries.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1172297
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-03 11:02:25 +02:00
Karel Zak 6d9b1c19ea lscpu: add warning for __SANITIZE_ADDRESS__
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-02 14:55:52 +02:00
Cristian Rodríguez a680b2abe7 sys-utils: lscpu segfaults when built with -fsanitize=address
This is expected and a false positive, exclude the vmware detection
trick when __SANITIZE_ADDRESS__ is defined.
2015-06-02 11:58:53 +02:00
Stanislav Brabec a79b7cab66 lsblk.8: Fix description of output format
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-06-02 11:58:53 +02:00
Karel Zak 08e193e1e4 libmount: fix mnt_monitor_event_cleanup()
We have to call epoll to drain mountinfo events too. The problem is
visible if the monitor epoll FD is within another (top-level) epoll.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-01 13:17:41 +02:00
Karel Zak 92441d5c1e lsblk: use internally sysfs devnames
It seems better to keep the strange sysfs devnames internally and
translate to real devnames only on output or when we read from /dev.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-29 10:55:01 +02:00
Karel Zak d5dbd57b22 docs: fix gtk-docs related warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:28:23 +02:00
Karel Zak 6c62abc42b lib/sysfs: rename devname functions, cleanup
Well, I don't have mental power to use function names like

 sysfs_devname_to_dev_name()

so this patch renames to

 sysfs_devname_sys_to_dev()
 sysfs_devname_dev_to_sys()

It also cleanups usage of the functions. We have to be sure that
sysfs.c code returns regular devnames. The existence of the sysfs
devnames (with '!') should be completely hidden in sysfs specific
code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:09:41 +02:00
Stanislav Brabec 759b120d85 lib/sysfs: Fix /dev to /sys node name translation
d0dc6c1 introduced translation of /sys names to /dev names, as required
by the kernel linux/drivers/base/core.c: device_get_devnode(). But there
are other places of code that use /dev names in /sys. They need reverse
translation from '/' to '!'.

For example, fdisk -l returns empty list since a22c6eb for device nodes
in subdirectories (used e. g. by cciss driver).

Introduce yet another helper sysfs_dev_name_to_devname() and use it where
appropriate.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-28 10:27:20 +02:00
Stanislav Brabec 97c68d4204 libfdisk: Use predictable /dev/mapper partition names for /dev/dm-N
It is impossible to predict /dev/dm-N partition names. Use predictable
and better readable /dev/mapper names instead.

[kzak@redhat.com: - remove if-before-free]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 10:25:58 +02:00
Stanislav Brabec 8b5940be96 Use correct partition names for /dev/mapper
The default configuration of multipath-tools appends "-partN" to
partition nodes. Follow this conventions and do the same.

It fixes for example fdisk -l /dev/mapper/name_of_the_device.

Note that the current implementation only partially fixes the problem. It
does not reflect any udev configuration changes, as udev does not provide
any function to return names of future (or current) partitions of a
particular device. It also does not fix fdisk -l /dev/dm-0.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-26 11:42:38 +02:00
Stanislav Brabec d0dc6c17c5 Fix /sys to /dev node name translation
linux/drivers/base/core.c: device_get_devnode() defines a translation of
'!' in sysfs nodes to '/' in /dev nodes. The same translation has to be
done to properly support device nodes with slash (e. g. device nodes of
cciss driver and several other drivers).

Introduce new helper sysfs_devname_to_devno() and use it where
appropriate.

Fixes for example lsblk -f on devices using cciss driver.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-26 11:42:38 +02:00
Karel Zak 687cc5d589 hwclock: don't allow non-root access
Fortunately very few people are crazy enough to install hwclock as
setuid. Some comments in code and unfortunately also man page
advertising that setuid is no problem. That's pretty stupid promise.

The code quality is poor and it's obviously not designed to be secure
(things like popen() without drop privileges, etc.).

This patch removes all notes about "setuid support" and for sure
disable hwclock execution for non-root users.

Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=786804
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-26 10:32:38 +02:00
Karel Zak d681e0956c sulogin: don't use strcpy(), enlarge pwd line buffer
* according to "man getpwnam" 16384 bytes is enough to store one
  passwd entry (let's use 2*BUFSIZE to avoid magic numbers in code)

* don't use strcpy() to set empty password

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-25 15:24:13 +02:00
Karel Zak 17d710346a build-sys: add --without-* for all libs
It's necessary for people who want to compile util-linux in very
unusual environment and disable as much as possible dependencies.
For example distro bootstrap.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1223894
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-22 12:43:33 +02:00
Karel Zak 5ec4a890a1 blkid: another hint to the man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-21 13:13:49 +02:00
Karel Zak f36522da5f blkid: be more precise in the man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-21 12:37:18 +02:00
Karel Zak f8098e2b2c blkid: don't ignore info about partitions on non-formated devices
# blkid -p /dev/sdc1; echo $?
 2

but libblkid provides information about partition, fixed version:

 # blkid -p /dev/sdc1; echo $?
 /dev/sdc1: PART_ENTRY_SCHEME="dos" PART_ENTRY_UUID="4c1e518c-01" PART_ENTRY_TYPE="0x83" PART_ENTRY_NUMBER="1" PART_ENTRY_OFFSET="2048" PART_ENTRY_SIZE="1021952" PART_ENTRY_DISK="8:32"
 0

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-21 12:14:55 +02:00
Karel Zak 6ddccd0d6e docs: update TODO
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-19 14:40:42 +02:00