Commit Graph

1228 Commits

Author SHA1 Message Date
Karel Zak 8175ed3d74 sfdisk: allow to disable bootable flag on all partitions
Let use '-' rather than a partition number to disable the bootable flag
on all partitions:

 sfdisk --activate /dev/sdc -

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-02 13:50:30 +01:00
Karel Zak 5d5ca9deaf sfdisk: allow to use --activate for PMBR
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-02 13:19:22 +01:00
Karel Zak c48acf70f7 fdisk: (gpt) make PMBR accessible from main menu
Don't force users to go to expert menu to toggle between GPT and PMBR.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-02 11:17:24 +01:00
Karel Zak 502c5186d3 cfdisk: cleanup die-on-signal code
Let's keep signal handler simple and don't cleanup terminal from the
handler.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-26 12:47:50 +02:00
Karel Zak c431d9015a cfdisk: make resize code more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-26 12:26:19 +02:00
Karel Zak 3da94b1114 swaplabel: fix --disable-libuuid compilation
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-15 13:30:40 +02:00
Philip Prindeville b443c1779e misc: replace magic number 37 with UUID_STR_LEN
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2017-09-05 11:49:21 +02:00
Vaclav Dolezal 6c183c283b fdisk: use strutils to trim whitespace from input
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-08-29 15:26:39 +02:00
Vaclav Dolezal 1d775aa260 fdisk: fix copy from readline and whitespace stripping
Bug fixed:
---
678: fdisk:      ASK: asking for number ['Partition number', <1,4>, default=1, range: 1-4]
678: fdisk:      ASK: asking for user replay [interactive]
Partition number (1-4, default 1): 12345
678: fdisk:      ASK: user's reply: >>>12345<<<
Value out of range.
678: fdisk:      ASK: asking for user replay [interactive]
Partition number (1-4, default 1): 1
678: fdisk:      ASK: user's reply: >>>12345<<<
Value out of range.
678: fdisk:      ASK: asking for user replay [interactive]
Partition number (1-4, default 1):
678: fdisk:      ASK: user's reply: >>>22345<<<
Value out of range.
---

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-08-28 14:06:15 +02:00
Vaclav Dolezal 3063670425 fdisk: minor fixes to make readline work
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-08-28 14:03:30 +02:00
Karel Zak ebfab541cf fdisk: add missing include
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-24 19:59:20 +02:00
Karel Zak c1154128db fdisk: fix readline interaction with signals
The high-level readline API is crazy to use with signals. Fortunately
the library provides low-level rl_callback_* API. In this case we can
use poll() to wait for input and control all signals, etc.

This patch also a little changes fdisk behavior on CTRL+C and CTRL+D.
The signals does not kill fdisk, but forces fdisk to return to the
main menu, if already in the main menu then exit. If the disk layout
has been modified than ask "Do you really want to exit...".

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-24 15:48:46 +02:00
Vaclav Dolezal 6c8c429d49 fdisk: handle SIGINT in dialogs as cancel
[kzak@redhat.com: - use sig_atomic_t]

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-24 13:08:22 +02:00
Vaclav Dolezal 55cf371609 fdisk: add wrap_fgets() for getting user input
make function wrapping rl_fgets() and fputs()&fgets() to remove
code duplication in get_user_reply().

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-08-24 11:27:18 +02:00
Karel Zak 1da83869cf isosize: usage() and coding style cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-21 11:16:51 +02:00
Karel Zak c380180289 isosize: iterate over all arguments even when something fails
Earlier the command exit too early if one of the arguments failed.  After
this change all arguments are examined, and command return value will have
information what happen during processing.

Based on patch from Sami Kerola <kerolasa@iki.fi>

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-21 11:11:11 +02:00
Karel Zak 6b1e439a0e cfdisk: add missing 0x7F key mapping
Addresses: https://github.com/karelzak/util-linux/issues/499
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-15 14:03:43 +02:00
Karel Zak 80701a7ace blockdev: document --setro more properly
Addresses: https://github.com/karelzak/util-linux/issues/498
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-14 11:30:37 +02:00
Karel Zak a351f2e504 cfdisk: add resize function
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 13:27:50 +02:00
Karel Zak 044ebc0c93 cfdisk: use fdisk_reread_changes()
Let's make cfdisk usable for disks where some partitions are mounted.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak fadd8e0877 fdisk: use fdisk_reread_changes()
Let's make fdisk usable for disks where some partitions are mounted.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak 87d04a3339 partx: move partx.h to include/
Let's make the ioctls usable also for libfdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak ea0acfc335 sfdisk: use fdisk_device_is_used()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak 884659b32a libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devices
For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64
add extra warning when the ioctl is used for DM devices. It seems we
can avoid this ioctl when the device has dm/uuid.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-12 14:35:53 +02:00
Karel Zak dda4743b45 fdisk: reset context after failed script
Addresses: https://github.com/karelzak/util-linux/issues/481
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-10 12:34:47 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
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>
2017-06-29 16:54:33 +02:00
Ruediger Meier 43c960c8fa blockdev: correct man page name in --help
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 15:36:39 +02:00
Ruediger Meier 9f3d0fce66 docs: remove some old history from manpages
We assume that users will have a kernel >= 2.6.0 and removel
references to earlier kernels. There are still a few ones
left.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 12:56:22 +02:00
Ruediger Meier a861538cc8 blockdev: improve --help and man page
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:44 +02:00
Ruediger Meier b305445495 misc: consolidate all --help option descriptions
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:36 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
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>
2017-06-27 12:26:19 +02:00
Ruediger Meier 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 5118d1be2a misc: never use usage(ERROR)
We are using better/shorter error messages and somtimes
also errtryhelp().

Here we fix all cases where the usage function took
an int argument for exit_code.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Karel Zak c3a4cfc579 misc: consolidate usage() "Available columns"
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-26 14:09:53 +02:00
Karel Zak d6ec64e824 Merge branch '170622' of github.com:jwpi/util-linux
* '170622' of github.com:jwpi/util-linux:
  Docs: move option naming to howto-contribute.txt
  Docs: update howto-usage-function.txt
  Docs: add a comment for constants to boilerplate.c
  include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
2017-06-26 13:56:45 +02:00
Karel Zak dfdb1ca818 Merge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linux
* 'fix-exit-codes' of https://github.com/rudimeier/util-linux:
  misc: fix optutils.h related exit codes
  misc: fix xalloc.h related exit codes
  misc: fix more strutils related exit codes
  lib: fix strutils.h, remove STRTOXX_EXIT_CODE
  misc: fix some broken exit codes
2017-06-26 13:47:04 +02:00
Ruediger Meier 300d702540 mkfs.cramfs: add --help and --version
Note, we were already using errtryhelp() without providing
a --help option.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-25 02:22:27 +02:00
J William Piggott 6e2d5a4460 include/c.h: add USAGE_COMMANDS and USAGE_COLUMNS
* login-utils/lslogins.c: all uses changed
* misc-utils/findmnt.c: likewise
* sys-utils/blkzone.c: likewise
* disk-utils/sfdisk.c: likewise
* sys-utils/lscpu.c: likewise
* sys-utils/lsmem.c: likewise
* sys-utils/wdctl.c: likewise

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-06-24 13:57:12 -04:00
Ruediger Meier 778ca2a0d4 misc: fix xalloc.h related exit codes
Found by:

grep -L "XALLOC_EXIT_CODE" $(grep -l "xalloc\.h" \
    $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:27 +02:00
Ruediger Meier 0b2b32e8a7 misc: fix more strutils related exit codes
Found by grep:

grep -l "\bEXIT_\|exit *( *[0-9][0-9] *)\|strutils\.h" $(grep -L \
    strutils_set_exitcode  $(git grep -l "_EX_\|FINDFS_\|BLKID_EXIT\|EX_USAGE" -- "*.c"))

The Command shows also some false positives (fstrim.c,
context_mount.c, ...)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:21 +02:00
Ruediger Meier 9c8b9fbacc lib: fix strutils.h, remove STRTOXX_EXIT_CODE
As discussed on the mailing list. We fix all places
where the non-working define STRTOXX_EXIT_CODE was used.

Regarding tunelp, also see 7e3c80a7.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 22:40:12 +02:00
Ruediger Meier 05691d9e88 misc: fix some broken exit codes
These tools have special exit codes. They got changed mistakenly.

See:
  findfs       0e1fa6b6
  fsck         658c0891
  fsck.cramfs  922ec175
  mkfs.cramfs  16154b1f
  tunelp       2ab428f6

FIXME: STRTOXX_EXIT_CODE doesn't work as it should.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:51:40 +02:00
Ruediger Meier 58745f3599 fsck: add --help and --version
Also cleanup usage() function, never write usage to stderr.

FIXME:
 - currently strtou32_or_err() exits with wrong exit code.
 - option -C does not use a safe strto*_err function

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:34:51 +02:00
Sami Kerola 1b5042636f misc: fix reassigned values before old ones has been used [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:19:20 +02:00
Sami Kerola e3e0054f5a isosize: avoid reading more data than what is needed
In same go fix error reporting when input file is not long enough.

$ touch empty
$ isosize empty
isosize: empty: might not be an ISO filesystem
isosize: read error on empty: Success

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:18:27 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Jakub Wilk fc747ee72a fdformat: clear progress message before printing "done"
Before:

    Formatting ... done1

After:

    Formatting ... done

Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
2017-06-02 23:54:10 +02:00
Karel Zak c71f5a568f cfdisk: fix compiler warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-31 10:58:17 +02:00
Chris Morin b0ff9a76b7 sfdisk: disambiguate units of --show-size
[kzak@redhat.com: - use optutils.h]

Signed-off-by: Chris Morin <chris.morin2@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-22 11:29:10 +02:00
Karel Zak 780ce22cda misc: consolidate smartcols error messages
... just to keep translators happy

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-18 11:39:34 +02:00
Karel Zak 76ae3fe37a sfdisk: add hints for scanners [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Karel Zak d2f265d629 mkswap: use memcpy() for non-terminated string [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:27:59 +02:00
Karel Zak 82c7ab9cb8 fsck.minix: add hint for scanners [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 11:38:54 +02:00
Karel Zak 25d1a7e5a6 fdisk: check scols_line_refer_data() return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 11:32:50 +02:00
Karel Zak 08099e41b9 cfdisk: add hints for scanners [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 11:26:54 +02:00
Sami Kerola 51b4b39870 fsck.minix: fix crash
disk-utils/fsck.minix.c:421:30: runtime error: index 513 out of bounds for
type 'unsigned short [512]'

Addresses: https://github.com/karelzak/util-linux/issues/373
Reported-by: Hanno Bock <hanno@gentoo.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-16 14:54:41 +02:00
Karel Zak 84111dbae4 fdisk: fix type dialog
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-11 15:53:07 +02:00
Karel Zak ddead341c5 fdisk: inform on 'p' about wiped partitions
The wipe operation is potentially dangerous. Let's inform about it
always by 'p' (list) command to make sure user knowns about it.

	Command (m for help): p
	...
	Device     Boot Start    End Sectors Size Id Type
	/dev/sdc1        2048 204799  202752  99M 83 Linux

	Filesystem/RAID signature on partition 1 will be wiped.

Addresses: https://github.com/karelzak/util-linux/issues/437
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 14:30:36 +02:00
Karel Zak a4aa4a6c9d fdisk: add to the man page missing option
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 13:05:26 +02:00
Sami Kerola 2cdaf94b55
partx: add --list-types option
Use libblkid as the source of truth what partition type names exist, and are
supported.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Sami Kerola abec3cb1de
docs: try to convince open(2) O_DIRECT rather than using raw device
Tell in manual page that one should use open(2) O_DIRECT flag rather than
raw device.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Sami Kerola 99d8ed0ac5
bash-completion: update disk-utils
fdformat:

	Add --from, --to, and --repair options.

	Commit: e0402441a1

fdisk:

	Add --output [1], --bytes [2], --wipe [3], --wipe-partition [4], and
	remove --geom- from from --cylinders, --heads, --sector options [5].

	Commit [1]: fff8ad5882
	Commit [2]: 354f8cc8cf
	Commit [3]: cb9a4b0033
	Commit [4]: ba465623d8
	Commit [5]: 4b4e391a28

fsck.cramfs:

	Broken since first commit.

	Commit: bf60993cf2

mkswap:

	Provide random uuid when completing --uuid argument.

partx:

	Add --sector-size option.  Fix also list of known partition types to
	match with libblkid blkid_idinfo names.  The fix is also applied to
	manual page.

	Commit: f8a4a0d4f2

	Reference: git grep -A 4 blkid_idinfo libblkid/src/partitions | grep name

sfdisk:

	Add --reoder, --delete, --mode-dataa, -no-tell-kernel, --wipe, and
	--wipe-partitions options.  In same go fix some option argument
	completions.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-17 18:12:10 +01:00
Karel Zak b607e5faca Fix menu spelling in cfdisk debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-22 10:43:55 +01:00
Sami Kerola 57ebfde291 fdisk, sfdisk: avoid non-ANSI function declarations [smatch scan]
Adding _FUNCTION_DEF definition will exclude compatibility type definitions
that do include void key word in empty argument list.

/usr/include/readline/rltypedefs.h:35:23: warning: non-ANSI function
declaration of function 'Function'

These functions has been replaced by set of new ones in readline 4.2 (April
2001), and removed in 6.3 (February 2014).

Reference: https://cnswww.cns.cwru.edu/php/chet/readline/CHANGES
Rererence: https://blueslugs.com/blog/2016-10-23-updating-cppfunction-in-old-readline-consumers/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-14 14:01:14 +01:00
Sami Kerola c308e2050f misc: stop mixing declarations and code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:04 +01:00
Karel Zak 208b2ef0b6 sfdisk: note about small partition in man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-02 13:51:40 +01:00
Karel Zak 86800f5d75 sfdisk: add note about alignment to man page
Addresses: https://github.com/karelzak/util-linux/issues/417
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-02 13:44:26 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
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
Sami Kerola e948f4b616 cfdisk: avoid use of VLA in combination with sizeof() [smatch scan]
disk-utils/cfdisk.c:1066:29: error: cannot size expression

One should use sizeof() only when variable size can be known at time of
compilation.  That is not the case with variable length arrays.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:12 +01:00
Karel Zak 1b6d02fe8c cfdisk: use buffer editor for ui_get_string()
Addresses: https://github.com/karelzak/util-linux/issues/403
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-16 13:47:44 +01:00
Karel Zak 5635d19550 fdisk: improve --wipe functionality
* always (except --wipe=never) wipe old partition tables
* improve warn messages
* improve man page

Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 15:13:35 +01:00
Karel Zak bb88152764 sfdisk: improve --wipe functionality
* always (except --wipe=never) wipe old partition tables
* improve warn messages
* improve man page

Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 15:11:35 +01:00
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Karel Zak 91cce31a8e sfdisk: --quiet fixes
Addresses: https://github.com/karelzak/util-linux/issues/412
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-10 12:54:23 +01:00
Karel Zak e7e7697612 cfdisk: add copyright to help
... to make it obvious this is a new cfdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-02 10:28:38 +01:00
Karel Zak 2f4eb047e5 cfdisk: support UI refresh on ^L
Addresses: https://github.com/karelzak/util-linux/issues/404
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 15:34:57 +01:00
Karel Zak f8a4a0d4f2 partx: add --sector-size option
/dev/sdc is 4K disk:

 # fdisk -l /dev/sdc
 Disk /dev/sdc: 100 MiB, 104857600 bytes, 25600 sectors
 ...
 Device     Boot Start   End Sectors Size Id Type
 /dev/sdc1        1024 25599   24576  96M 83 Linux

let's use it as disk image:

 # dd if=/dev/sdc of=~/sdc.img
 # losetup -f ~/sdc.img

old version:

 # partx --show /dev/loop0
 NR START   END SECTORS SIZE NAME UUID
 1  1024 25599   24576  12M      6a4ba75b-01

new version:

 # partx --show /dev/loop0 --sector-size 4096
 NR START    END SECTORS SIZE NAME UUID
  1  8192 204799  196608  96M      6a4ba75b-01

Addresses: https://github.com/karelzak/util-linux/issues/396
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-13 13:30:22 +01:00
Sami Kerola 12d69ae8bb man: fix couple tools/checkmans.sh warnings
<standard input>:407: warning: macro `fi.' not defined (possibly missing space after `fi')
From: cat ./disk-utils/fsck.8 | troff -mandoc -ww -z

<standard input>:71: warning: escape character ignored before `1'
From: cat ./disk-utils/partx.8 | troff -mandoc -ww -z

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-10 17:32:32 +01:00
Karel Zak 11e1097e6c sfdisk: unused parameter 'sf' [-Wunused-parameter]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-05 11:53:56 +01:00
Nate Clark b7b26945d1 disk-utils/mkfs.minix: Set ninodes after checking max
ninodes in the superblock needs to be set after inodes is checked
against MINIX_MAX_INODES otherwise a value larger than MINIX_MAX_INODES
can be attempted to be stored in the superblock.

Without this change the command "mkfs.minix -2 -i 65530 <dev>" would
write a minix superblock with ninodes set to 0.

Signed-off-by: Nate Clark <nate@neworld.us>
2017-01-04 14:42:59 -05: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
Sébastien Helleu d673b74e9d docs: replace FTP by HTTPS in kernel.org URLs
The links to ftp://ftp.kernel.org/ are replaced by
https://www.kernel.org/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:22:26 +01:00
Karel Zak 8fdd483c53 fdisk: don't be silent when list non-existing device
Addresses: https://github.com/karelzak/util-linux/issues/376
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-13 12:11:32 +01:00
Michael Kerrisk 46f057ed37 docs: various pages: Format pathnames as italic (.I)
In the majority of pages, pathnames are formatted as Italic,
which is the norm. However, there are several cases where they
are formatted as bold. This patch fixes a number of those
exceptions.

Signed-off-by: Michael Kerrisk <mtk.man-pages@gmail.com>
2016-12-09 13:45:09 +01:00
Ruediger Meier 223939d95b misc: spelling, always use "cannot" instead of "can not"
Just to be consistent ...

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-11-30 14:56:50 +01:00
Karel Zak 35ca511827 sfdisk: support empty label use-case
By default sfdisk creates partition table when a first partition is
specified, otherwise the device is not modified. This force users to
create at least one partition.

This commit allows to create empty label without partitions if "label:
<name>" header line is specified by script.

The commit also modifies "New situation:" output to list label name
and label identifier.

Addresses: https://github.com/karelzak/util-linux/issues/374
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-11-30 13:01:33 +01:00
Karel Zak c49b765a6e sfdisk: cleanup --dump error messages
old:
  # truncate -s 1G empty && ./sfdisk --dump empty
  sfdisk: failed to dump partition table: Success

new:
  # truncate -s 1G empty && ./sfdisk --dump empty
  sfdisk: empty: does not contain a recognized partition table.

Addresses: https://github.com/karelzak/util-linux/issues/375
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-11-30 10:57:39 +01:00
Karel Zak fed304837f sfdisk: don't be silent when list non-existing device
Addresses: https://github.com/karelzak/util-linux/issues/376
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-11-29 16:01:46 +01:00
Michael Kerrisk (man-pages) b2cc2a7fc6 Fix formatting errors in page cross references
These pages had errors such as

    .BR page (x) .

which should be

    .BR page (x).

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-11-29 10:44:19 +01:00
Michael Kerrisk (man-pages) f053ff1e3a Place SEE ALSO entries in order
This patch does only the following:

* Order SEE ALSO entries first by section name, then alphabetically
  within section
* Adds one or two missing commas in SEE ALSO lists
* Removes one or two periods that were (inconsistently) used
  at the end of SEE ALSO lists.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-11-29 10:44:19 +01:00
Ruediger Meier 0f2eb577ac fdisk: fix memleak in list_disk_geometry()
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 11:03:16 +02:00
Karel Zak e4015b348f fdisk: fix compiler warning
disk-utils/fdisk-menu.c: In function ‘gpt_menu_cb’:
disk-utils/fdisk-menu.c:709: warning: passing argument 6 of ‘fdisk_ask_number’ from incompatible pointer type
./libfdisk/src/libfdisk.h:688: note: expected ‘uintmax_t *’ but argument is of type ‘long unsigned int *’

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-26 10:28:41 +02:00
Karel Zak bae57b5a3c misc: fix unsigned int usage for ctype.h functions
Reported-by: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-26 10:13:47 +02:00
Karel Zak 2687686cf4 cramfs: revert crc32 changes
We cannot use our crc32 without changes in the code, because our
ul_crc32() assumes that post-conditioning (xor) is done by
application. The zlib implementation does everything.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-19 13:33:15 +02:00
Karel Zak 98fd13a169 cramfs: add missing includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-19 12:17:19 +02:00
Gustavo Zacarias 7f0d4d56a2 lib/crc32: prefix public functions
Make the publicly-visible crc32 library functions prefixed by ul_, such
as crc32() -> ul_crc32().
This is because it clashes with the crc32() function from zlib.
For newer versions of glib (2.50+) zlib and libblkid are required
dependencies and otherwise results in build failure when building
statically.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
2016-10-19 12:11:59 +02:00
Karel Zak 17dd04c92a isosize: fix read() result check 2016-10-04 20:15:09 +02:00
Karel Zak 2d1fa4fdc3 sfdisk: cleanup before going out of scope [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 16:08:55 +02:00
Karel Zak 6387bf33db sfdisk: free before going out of scope [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 16:03:11 +02:00
Karel Zak 4c906abea2 isosize: don't ignore read() result [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 15:56:59 +02:00
Karel Zak 10c66b0b9e fsck.cramfs: don't ignore read() result [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 15:53:55 +02:00
Karel Zak cf9b302d46 cfdisk: fix mountpoint detection
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 15:02:00 +02:00
Karel Zak 37948503c9 libsmartcols: support LIBSMARTCOLS_DEBUG_PADDING=on
This env.variable forces libsmartcols to use visible padding chars.
The standard debug has to be enabled (to minimize overhead for
non-debug execution).

For example:

 $ LIBSMARTCOLS_DEBUG=all LIBSMARTCOLS_DEBUG_PADDING=on findmnt 2> ~/log

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-07 12:25:06 +02:00
Karel Zak 7208ef864b fsck: remove fs-specific options from man page
Let's force users to read fs-specific man pages rather than try to be
smart and maintain some non-fsck options in fsck.8.

Reported-by: Matej Cepl <mcepl@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-06 14:49:48 +02:00
Karel Zak d4a90151e3 sfdisk: add --no-tell-kernel
The option forces sfdisk to not call re-read partitions ioctl after
write PT.

Requested-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-02 11:20:06 +02:00
Karel Zak ad8cd66adf sfdisk: make non-interactive output more readable
# echo -e ',1M\n,2M' | sfdisk /dev/sdc

Old version:

  >>> Created a new DOS disklabel with disk identifier 0x8fc7d065.
  Created a new partition 1 of type 'Linux' and of size 1 MiB.
  /dev/sdc2: Created a new partition 2 of type 'Linux' and of size 2 MiB.
  /dev/sdc3:

New version:

  >>> Created a new DOS disklabel with disk identifier 0x9afe17c0.
 /dev/sdc1: Created a new partition 1 of type 'Linux' and of size 1 MiB.
 /dev/sdc2: Created a new partition 2 of type 'Linux' and of size 2 MiB.
 /dev/sdc3: Done.

Addresses: https://github.com/karelzak/util-linux/issues/337
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-31 15:51:11 +02:00
Karel Zak 8d2f449818 fdisk: use PAGER for 'l' command.
The list of the partition types is too long. Let's try to use $PAGER.

Reported-by: Bruce Dubbs <bruce.dubbs@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-26 12:15:38 +02:00
Karel Zak 090d8c763a include/closestream: define exit codes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-16 13:35:06 +02:00
Karel Zak 349ac67273 sfdisk: add show-pt-geometry to usage() and sfdisk.8
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-08 12:15:47 +02:00
Stanislav Brabec f7c6c31f08 sfdisk: Add --show-pt-geometry compatibility code
--show-pt-geometry existed since cf3f26bf (2006), and it is used by third party
tools. To prevent failure of these tools, add a minimal compatibility code.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-08 12:03:12 +02:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak 78e7f78896 Revert "sfdisk: exit with error if rereading partition table fails"
This reverts commit 14f644f386.

It seems we have mess in reread-after-write:

all old versions to v2.20  -- returns 0
from v2.20 to v2.26        -- returns 1
since v2.26                -- returns 0

I think re-read errors should not be interpreted as fatal errors,
because it's pretty common that you want to modify only one partition
(e.g. resize) and then another partitions are probably still in use
and re-read all PT does not make sense.

What we need is to improve granularity for re-read and calls it only
when really necessary (all PT modified) and otherwise call BLKPG
(add/delete/resize) ioctls.

Reported-by: Nikhil Valluru <vvnikhil@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-20 11:24:36 +02:00
Thierry Vignaud 04c163ed16 fdisk: make -l <dev ...> behaves like fdisk -l
aka having the same spacing between disks

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-14 12:04:04 +02:00
Karel Zak 6e51ab0c5c cfisk: add /dev/vda as another default disk
And use array for all default alternative disks.

Reported-by: Thierry Vignaud <thierry.vignaud@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-07 15:02:20 +02:00
Karel Zak 9907a95a7d cfdisk: use libsmartcols ASCII for non-widechar environment
Reported-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-03 12:20:24 +02:00
Karel Zak 65c74885df fsck.minix: fix endless loop and out of stack
It seems there is no elegant way how to recovery if a directory i_zone
(and i_size) is out of reality. Let's require human interaction to
avoid endless loop when executed with --auto, etc.

Addresses: https://github.com/karelzak/util-linux/issues/228
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-01 14:55:15 +02:00
Sebastian Rasmussen d1b7bfe506 fdisk: Fix typo RequiredPartiton -> RequiredPartition
This typo fix is backwards compatible in that fdisk will accept both
the GPT attribute RequiredPartition and RequiredPartiton with the typo.
Update documentation and tests to all use the new attribute name.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:51:07 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Sebastian Rasmussen d35df4db5b docs: Fix various typos
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Tobias Stoeckmann 8f35b3a998 fsck.minix: Verify more fields in super-block.
The field s_ninodes in super-block is used for memory allocation and
division without verifications. The memory allocation increments the
unchecked value by 1, making it vulnerable to an integer overflow
on 32 bit systems with minix 3 file systems. I did not find a (good)
way to exploit this by crafting a malicious file system, so I consider
it as a reliability issue. If it's 0, a division by zero occurs when
"-v" has been used. A filesystem without any inodes is definitely
wrong, because it means that there's not even the root inode, which is
accessed unchecked later on.

The field s_firstdatazone has to be checked against s_(n)zones. If it
is larger than the highest allowed index, the file system is definitely
corrupted -- hard to say which value is wrong though, therefore I
decided to simply call die(). A maliciously created file system could
do more harm in this way: single bits inside the memory area could be
flipped because range checks would fail. Hard to consider it as a
security issue though, because these addresses are not arbitrarily
accessible without very careful crafting (if at all possible).

[kzak@redhat.com: - fix compiler warning (cast get_nzones()) [-Wsign-compare]]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-31 13:18:06 +02:00
Mike Frysinger 5593132a90 man pages: fix spacing between man page name & section number
Most have standardized correctly, but fix a few latent ones.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-05-20 10:54:31 +02:00
Sassan Panahinejad 304cf9499d fdisk: Add support for altering GPT size
Adds an options (l) to the GPT menu to resize the GPT.
2016-05-18 13:46:35 +02:00
Victor Dodon 14f644f386 sfdisk: exit with error if rereading partition table fails
Use the return value of fdisk_reread_partition_table in write_changes so that
sfdisk exits with error if re-reading the partition table fails.

Signed-off-by: Victor Dodon <dodonvictor@gmail.com>
2016-05-05 11:43:07 +02:00
Karel Zak 832bbc73b2 build-sys: remove obsolete [cs]fdisk LDADDs
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 15:02:02 +02:00
Karel Zak 3d6db3fdb1 sfdisk: add --wipe-partitions=auto|never|default
The option allows to remove filesystes/RAIDs from newly created
partitions before the partition table is updated (and partition
device created).

The default is "auto" in this case wipe is enabled in interactive mode
only and user's confirmation (yes/no dialog) is required. Note that
keep filesystem signature on partition is pretty valid use-case, so we
don't erase anything by default.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 12:47:17 +02:00
Karel Zak ba465623d8 fdisk: add --wipe-partitions=auto|never|default
The option allows to remove filesystes/RAIDs from newly created
partitions before the partition table is updated (and partition
device created).

The default is "auto" in this case wipe is enabled in interactive mode
only and user's confirmation (yes/no dialog) is required. Note that
keep filesystem signature on partition is pretty valid use-case, so we
don't erase anything by default.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 12:43:35 +02:00
Yuriy M. Kaminskiy fc75981a22 fsck: fix racing between unlock/unlink and open
Process A	Process B	Process C
open()
[creates file]
lock()
[succeed]
		open()
		[open existing]
		lock()...
running()
close()
		[...succeed]
unlink()
		running()
				open()
				[creates file] {BAD!}
				lock()
				[succeed] {BAD!}
				running() {BAD!}
		close()

Cons: leaves empty (unlocked/harmless) .lock files in /run/fsck/
Signed-off-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
2016-04-22 11:07:42 +02:00
Lubomir Rintel d97dc0ee25 mkswap: tolerate ENOTSUP when failing to relabel
It might be that the underlying filesystem just doesn't support SELinux
labeling. This fixes creating swap on vfat live media:

  # livecd-iso-to-disk.sh --msdos --swap-size-mb 666 ...

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
2016-04-18 10:51:28 +02:00
Karel Zak c6121fec26 fdisk: remove dead assignment [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-29 14:13:22 +02:00
Karel Zak 2d47fa3921 partx: fix --nr usage
Reported-by: Serge van den Boom <serge+util-linux@vdboom.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-22 15:49:00 +01:00
Benno Schulenberg 49b7f95e43 docs: miscellaneous tiny tweaks of man pages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-17 12:18:54 +01:00
Benno Schulenberg 718b6f0cda fdisk: fix the grammar of an option description
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-17 12:18:54 +01:00
Benno Schulenberg b779c1aecb mount, umount, swapon, fsck, lsblk, findmnt: harmonize six error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-16 10:39:38 +01:00
Benno Schulenberg cb19f5479b fdisk, cfdisk, sfdisk: improve the grammar of three messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-16 10:39:35 +01:00
Benno Schulenberg 1a60a5ecb0 sfdisk: improve the wording of seven error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-16 10:39:34 +01:00
Karel Zak 785539baa3 Merge branch 'travis-osx' of https://github.com/rudimeier/util-linux
* 'travis-osx' of https://github.com/rudimeier/util-linux:
  travis: add OSX build
  travis: switch to Ubuntu 14.04 Trusty
  build-sys: improve uuidd and script build conditions
  build-sys: use AC_PROG_MKDIR_P and remove a few gnuisms
  build-sys: add missing "not found" strings
  build-sys: fix again UL_SCANF_TYPE_MODIFIER
  tests: don't use system's mount commands
  tests: improve skipping of old btrfs-tools
  tests: remove invalid argument in libmount/debug
  tests: skip old socat silently
  misc: fix icc/clang compiler warnings
  misc: fix printf i386 compiler warnings
2016-03-14 15:59:10 +01:00
Sami Kerola 5a2ed45309 isosize: stop unmeaningful printing errno message
Earlier printout had strange looking 'Success'.

$ isosize --sectors /dev/urandom
isosize: /dev/urandom: might not be an ISO filesystem
isosize: 733error: le=-1971599244 be=1633181607: Success
...

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-03-14 13:15:12 +01:00
Ruediger Meier 58c87bd045 misc: fix icc/clang compiler warnings
clang warning:
libmount/src/tab.c:1833:6: warning: variable 'rc' is used uninitialized whenever
      'if' condition is true [-Wsometimes-uninitialized]
        if (!mpc)
            ^~~~

icc printf warnings:
    libmount/src/monitor.c(348): warning #2279: printf/scanf format not a string literal and no format arguments
            DBG(MONITOR, ul_debugobj(mn, status == 1 ? " success" : " nothing"));
            ^
    login-utils/vipw.c(348): warning #2279: printf/scanf format not a string literal and no format arguments
                           : _("You are using shadow passwords on this system.\n"));
                                                                                  ^

icc enum warnings:
    disk-utils/fdisk-menu.c(150): warning #188: enumerated type mixed with another type
            .exclude = FDISK_DISKLABEL_GPT | FDISK_DISKLABEL_BSD,
                       ^
    libsmartcols/src/table_print.c(750): warning #188: enumerated type mixed with another type
                            &width, align,
                                    ^

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-13 21:47:27 +01:00
Karel Zak 8e2e9144ef misc: remove duplicate includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-10 14:30:32 +01:00
Karel Zak 95aae4fcee sfdisk, fdisk: add fflush()
Let's add fflush(stdout) before we print to stderr to make output
order more deterministic.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-10 12:26:43 +01:00
Karel Zak 322e553a1c Merge branch 'port-osx' of https://github.com/rudimeier/util-linux
* 'port-osx' of https://github.com/rudimeier/util-linux:
  fdisk: fix warning, uninitialized variable
  logger: fix compiler warning, const facilitynames
  include/bitops: avoid fallbacks for more systems
  include/bitops: add casts to bswap functions
2016-03-09 13:12:50 +01:00
Ruediger Meier 056e622c91 fdisk: fix warning, uninitialized variable
This was a typo in 4afb337e.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-08 14:56:02 +01:00
Karel Zak 075d2c0754 include: move sys/sysmacros.h to c.h
The file is no portable (#ifdef HAVE_SYS_SYSMACROS_H is necessary),
but needed on many places. It seems better to keep it in c.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-08 14:29:45 +01:00
Karel Zak 3fe3f560b7 Revert "include sysmacros.h where used"
This reverts commit 46a40c0184.
2016-03-08 14:26:33 +01:00
Benno Schulenberg c805c36923 sfdisk: adjust more wordings and formatting in the man page
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-08 14:21:55 +01:00
Benno Schulenberg 589b69316c fdisk, sfdisk: adjust the wording of the --wipe option
Use "when" as argument, to match the argument of --color,
that can have the same three values.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-08 14:21:55 +01:00
Benno Schulenberg 7e3b3f4710 fdisk, sfdisk: adjust some formatting in the man pages
Only the optional argument should be in italics,
the literal = should be bold.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-08 14:21:55 +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
Ruediger Meier fea1cbf748 misc: never cast void* from malloc(3) and friends
Such cast could hide serious compiler warnings in case we are
missing includes (e.g. <stdlib.h> or "xalloc.h").

See
http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:27 +01:00
Ruediger Meier fdbd7bb940 misc: again fixing many printf format strings
This is again a huge patch regarding printf format strings to
fix compiler warnings seen on clang/OSX.

I'm trying to follow these rules strictly:

 #type      #format   #cast
 uintmax_t   %ju      -
 intmax_t    %jd      -
 uint64_t    PRIu64   -
 int64_t     PRId64   -
 size_t      %zu      -
 ssize_t     %zd      -
 ino_t       %ju      (uintmax_t)
 off_t       %jd      (intmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:16:04 +01:00
Ruediger Meier 8acff75afc wipefs, sfdisk: include libgen.h for basename(3p)
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 21:25:36 +01:00
Karel Zak fdbfe2e7f0 Merge branch 'fix-minix' of https://github.com/rudimeier/util-linux
* 'fix-minix' of https://github.com/rudimeier/util-linux:
  tests: minix, add a useful non-root check
  tests: fix minix tests for big endian
  mkfs.minix: fix v2/v3 .badblocks inode number for big endian
  fsck.minix: fix v3 version offset
  tests: minix, some corrections and cleanup
  tests: minix, use hexdump instead of md5sum
2016-03-07 15:50:34 +01:00
Ruediger Meier e0dfdfeca0 fdisk: remove unused include sysfs.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:37:09 +01:00
Ruediger Meier 2208b3ccb2 lib: remove openat fallback functions (include/at.h)
I have validated that we are still compatible at least back to
  - openSUSE 11.4
  - SLE 11
  - RHEL/CentOS 6
  - OSX 10.10.x, (Xcode 6.3)
  - FreeBSD 10.2

Confirmed incompatibility:
  - OSX 10.9.x, (Xcode 6.2)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 15:33:56 +01:00
Yuriy M. Kaminskiy 06fa581748 misc: safer (and uniform) handling of return value
When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:11:06 +01:00
Ruediger Meier 7252874a48 mkfs.minix: fix v2/v3 .badblocks inode number for big endian
For minix v2/v3 on big endian systems the inode number of the unwanted
".badblocks" file was not set to zero. This was introduced when v3 was
added in a2657ae3.

Actually it did not seem to cause any problems but since we zero it out
at all we should do it correctly. Now we zero out the whole directory
entry (inclusive ".badblocks" file name, also for v1). Unfortunately we
have to update the test data checksums.

CC: Davidlohr Bueso <davidlohr@hp.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-03 09:25:10 +01:00
Ruediger Meier fcb1242601 fsck.minix: fix v3 version offset
Our test-suite discoverd it on big endian systems, but it was also
broken on little endian for inode numbers > 0xffff.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-03 09:24:06 +01:00
Ruediger Meier 262c94c2c7 fdisk: fix warning, incompatible pointer types passing 'uint64_t *'
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-29 13:04:48 +01:00
Ruediger Meier b9710f1f08 misc: fix compiler warnungs (unsigned/signed)
These ones should be fixed:
libblkid/src/probe.c:393:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/probe.c:907:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/probe.c:1221:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:540:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1043:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1056:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1057:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1061:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1199:27: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/partitions/partitions.c:1410:26: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/partitions/partitions.c:1431:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/superblocks/linux_raid.c:151:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
libblkid/src/superblocks/linux_raid.c:155:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
libblkid/src/superblocks/superblocks.c:375:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/superblocks/xfs.c:141:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libsmartcols/src/table.c:333:24: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libsmartcols/src/table.c:344:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libsmartcols/src/table_print.c:753:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/ask.c:364:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/utils.c:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/context.c:435:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/context.c:730:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/script.c:557:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/dos.c:1791:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/gpt.c:813:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:140:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:551:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:640:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:27 +01:00
Ruediger Meier b0b54cc582 build-sys: always add AM_CFLAGS
We were missing our nice compliler warnings for many programs
and libs. See next commits how many trivial and non-trival
warnings have to be fixed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:17:29 +01:00
Karel Zak 45c9a3d27f Merge branch 'port-osx' of https://github.com/rudimeier/util-linux
* 'port-osx' of https://github.com/rudimeier/util-linux:
  include: fix sys/sysinfo.h
  libblkid: don't include endian.h
  lib: fix ismounted includes for FreeBSD
  lib: remove unused variable
  lsns: use xcalloc()
  include: remove unused mntent.h
  include: check for sys/sysmacros.h
  lib: define LOGIN_NAME_MAX fallback
  include: provide MAP_ANONYMOUS on OSX
  lib: rename strmode() and setmode()
  tests: fix ts_option helpers
  build-sys: fix [g]libtoolize version for OSX
  build-sys: check linker support for version scripts
  build-sys: portable usage of find command
  travis: minor cleanup
2016-02-19 11:30:53 +01:00
Ruediger Meier f3e0213aa4 include: remove unused mntent.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:23 +01:00
Ruediger Meier 66daee0765 include: check for sys/sysmacros.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 16:54:17 +01:00
Karel Zak 97ffbd43d2 cfdisk: wipe device if create a new label
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-18 12:58:12 +01:00
Karel Zak 15b5e942f2 sfdisk: add --wipe
This patch changes sfdisk behavior and it wipes foreign signatures
from the device to avoid collisions. The wipe functionality is
automatically enabled in the interactive mode only (user is always
warned about it), otherwise it's possible to control all by --wipe
<auto|never|always>.

The program does not change behavior when executed in scripts (echo
<something> | sfdisk), the option "--wipe=always" is required to enable
in this case.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-18 12:58:12 +01:00
Karel Zak cb9a4b0033 fdisk: add --wipe
This patch changes fdisk behavior and it wipes foreign signatures
from the device to avoid collisions. The wipe functionality is
automatically enabled in the interactive mode only (user is always
warned about it), otherwise it's possible to control all by --wipe
<auto|never|always>.

The program does not change behavior when executed in scripts (echo
<something> | fdisk), the option "--wipe=always" is required to enable
in this case.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-18 12:58:12 +01:00
Ruediger Meier 7231fb2a5b misc: fix some printf format strings
Fix the warnings below for OSX clang and add a few more
casts for timeval:

lib/at.c:131:27: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'off_t' (aka 'long long') [-Wformat]

                        printf("%16jd bytes ", st.st_size);

                                ~~~~~          ^~~~~~~~~~

lib/strutils.c:522:52: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]

                snprintf(buf, sizeof(buf), "%d%s%jd%s", dec, dp, frac, suffix);

                                                ~~~              ^~~~

lib/sysfs.c:468:42: warning: format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]

        len = snprintf(buf, sizeof(buf), "%ju", num);

                                          ~~~   ^~~

libuuid/src/gen_uuid.c:316:34: warning: format specifies type 'unsigned long' but the argument has type '__darwin_suseconds_t' (aka 'int') [-Wformat]

                              clock_seq, last.tv_sec, last.tv_usec, adjustment);

                                                      ^~~~~~~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-11 13:39:56 +01:00
Karel Zak 300e24a8ea sfdisk: add ESP shortcut also for Legacy MBR
References: https://github.com/karelzak/util-linux/issues/267
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-08 16:37:03 +01:00
Karel Zak b1d31d03de Merge branch 'master' of https://github.com/rudimeier/util-linux
* 'master' of https://github.com/rudimeier/util-linux:
  script: fix misspelling
  docs: fix typos found by codespell
2016-02-04 16:02:17 +01:00
Ruediger Meier 3fd1f7711e docs: fix typos found by codespell
Using "codespell" from https://github.com/lucasdemarchi/codespell

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-03 15:10:08 +01:00
Karel Zak 4afb337e00 fdisk: make 'f' command more verbose
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-03 13:40:25 +01:00
Karel Zak c809b20aa4 sfdisk: make --quiet really quiet
References: https://github.com/karelzak/util-linux/issues/268
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-01 14:30:31 +01:00
Karel Zak d09c06baf4 sfdisk: add 'U' shortcut for ESP
echo -e ',512M,U\n,,L' | sfdisk --label gpt /dev/foo

to make ESP system partition.

References: https://github.com/karelzak/util-linux/issues/267
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-01 14:08:04 +01:00
Wayne R. Roth cc706d9f09 mkswap: add warnings for insecure device permissions/owners
Logic modified from sys-utils/swapon.c

Signed-off-by: Wayne R. Roth <wayneroth42@gmail.com>
2016-01-26 11:26:00 +01:00
Boris Egorov 43b4f7ea5f lib/tty: Pass default width to get_terminal_width()
Almost any code calling get_terminal_width() checks returned width for
non-positive values and sets it to some default value (say, 80). So,
let's pass this default value directly to the function.

[kzak@redhat.com: - get_terminal_width() refactoring]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-06 12:22:07 +01:00
Karel Zak 717fff869e cfdisk: use new libsmartcols functionality to fix output
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-12-07 12:23:26 +01:00
Karel Zak 86688c378b Revert "cfdisk: make sure that output fits to terminal width"
This reverts commit ed99eac0e2.
2015-12-07 10:42:15 +01:00
Sami Kerola f5320b483c
fdformat: fix block device open race
This fix makes fdformat also to detect if block device is busy, and warn if
the device is misaligned.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:38 +00:00
Sami Kerola 80c320fac1
mkswap: fix block device open race
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:38 +00:00
Sami Kerola 8a4eb983d8
mkfs.minix: fix block device open race
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:38 +00:00
Sami Kerola 98b4f74e1f
mkfs.bfs: allow creating file system to a file
Most, if not all, linux file systems allow this and there should not be a
reason why bfs could not do the same.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:37 +00:00
Sami Kerola 5fc7694a54
mkfs.bfs: fix block device open race
This fix makes mkfs.bfs also to detect if block device is busy, and warn if
the device is misaligned.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-22 20:56:37 +00:00
Sami Kerola d0a050e0f9 fsck: retire stat(3) when access(3) does better job
The stat(3) and access(3) are in this case almost interchangeable, so choose
the lightweight function with additional advantage checking the file is
executable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-09 09:56:14 +01:00
Karel Zak 1cd9d0d746 mount, umount, swapon, fsck, lsblk, findmnt: ignore malformed lines
The libmount provides way how to deal with parsing errors in fstab --
on error callback function is executed and according to the return
libmount manipulate with the malformed line, possible are three
states:

  1/ fatal error; all file ignored              (callback rc < 0)
  2/ recoverable error; malformed line ignored  (callback rc > 0)
  3/ ignore the error                           (callback rc == 0)

The 2/ is the default if no callback specified.

Unfortunately our utils uses 3/. The correct way is to use 2/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-15 12:01:48 +02:00
Karel Zak 24b7db7e4e partx: prevent code duplication
Reported-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-10-09 12:18:28 +02:00
Karel Zak aab9be66c4 sfdisk: add --delete
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-17 13:57:44 +02:00
Karel Zak 31c79e1823 sfdisk: fix -N return code detection, add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-17 11:45:02 +02:00
Karel Zak d85a7fa744 sfdisk: cleanup and optimize --move-data
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-09 14:48:33 +02:00
Karel Zak f42205d89a sfdisk: add --move-data
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-08 16:37:08 +02:00
Karel Zak 9a17d9460a sfdisk: add --reorder
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1232707
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-07 10:18:46 +02:00
Yuri Chornoivan 75a8e726e9 Fix trivial typos 2015-08-25 20:02:53 +03:00
Sami Kerola 624e147ba2 misc: fix shadow declarations
sys-utils/zramctl.c: In function 'get_mm_stat':
sys-utils/zramctl.c:276:58: warning: declaration of 'inbytes' shadows a global declaration [-Wshadow]
 static char *get_mm_stat(struct zram *z, size_t idx, int inbytes)
sys-utils/zramctl.c:119:39: note: shadowed declaration is here
 static unsigned int raw, no_headings, inbytes;

libmount/src/tab.c: In function 'mnt_table_get_fs_root':
libmount/src/tab.c:1221:22: warning: declaration of 'fs' shadows a parameter [-Wshadow]
    struct libmnt_fs *fs = mnt_table_find_mountpoint(tb,
libmount/src/tab.c:1197:24: note: shadowed declaration is here
      struct libmnt_fs *fs,

disk-utils/fsck.minix.c: In function 'main':
disk-utils/fsck.minix.c:1364:17: warning: declaration of 'i' shadows a previous local [-Wshadow]
   unsigned long i, free;
disk-utils/fsck.minix.c:1250:6: note: shadowed declaration is here
  int i;

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-08-24 10:55:37 +02:00
Karel Zak ffab025db8 cfdisk, sfdisk: remove unused variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 12:41:46 +02:00
Ian Wienand 11aa2aa290 sfdisk: clarification for sfdisk man page
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1249893
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 09:21:27 +02:00
Karel Zak 70e0513563 mkfs.minix: add hint for scanners [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 11:42:27 +02:00
Karel Zak cd16685e94 mkfs.minix: use xalloc
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 11:39:49 +02:00
Karel Zak 101c80f316 mkfs.cramfs: remove dead code [coverity scan]
There two possible ways, print error and exit on too long names or
truncate the filename -- but it's impossible to do both in the same
code :-) It seems that code already assumes warning on long names, so
let's remove errx() and keep the behavior in dependence on -E.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 11:33:57 +02:00
Karel Zak 1e9d849b8d fsck.minix: be more paranoid with block buffers [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 11:15:53 +02:00
Karel Zak 4c166c2200 cfdisk: check return value [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 10:59:52 +02:00
Sami Kerola 98f8b800dc tests: add way to control mkfs.minix time stamps
Needed in order to create reproducable file systems image files, so that
out come of mkfs.minix can be checksum'ed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-08-03 11:27:37 +02:00
Sami Kerola 3e56e36291 mkfs.minix: re-fix block count maths
Error, that Joshua Hudson already pointed out, creapped back to commit
da41ff5 when changes were applied from mailbox rather than git remote, as
the corrected change had included some accidental rubbish.

Reference: http://www.spinics.net/lists/util-linux-ng/msg11764.html
Reference: http://www.spinics.net/lists/util-linux-ng/msg11848.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-08-03 11:27:36 +02:00
Benno Schulenberg 62eea9ce12 textual: adjust grammar and punctuation of some messages
Also equalize three messages to one other one,
and fix a typo in USE_COLORS_BY_DEFAULT.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-08-03 11:18:56 +02:00
Karel Zak 901f85fe54 sfdisk: don't print extra linebreaks on --quiet
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-30 13:22:35 +02:00
Sami Kerola e87a6ee0f5 docs: make fsck.minix(8) more pretty
Use real table to device list, add missing new paragraph markers, remove
braces that cause reader to wonder if test is meant or not, squeeze error
code list, move references to bottom of the manual, and use mail or web
address macro when possible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:18 +02:00
Sami Kerola 158b8d6918 fsck.minix: introduce long options to the command
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:17 +02:00
Sami Kerola 86a9f3dad5 fsck.minix: add minix v3 support
Relates-to: a2657ae3ff
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:16 +02:00
Sami Kerola e1df9d4cd6 fsck.minix: rename device file descriptor variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:16 +02:00
Sami Kerola ed7f9c5d96 mkfs.minix: refactor root block content creation
This does not belong to main() function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:15 +02:00
Sami Kerola a232cfdc0a mkfs.minix: check requested blocks will not exceed available on device
Earlier user could define more blocks than device, or backing file for
loopback file system, had available.  That lead to a system crash with
following commands;

fallocate --length 64KiB test-file
mkfs.minix -3 -i 842160 test-file 104882174
mkdir test-file.d
mount test-file test-file.d
cp /etc/service test-file.d
Killed
sudo umount test-file.d

The minix driver should probably not hang the whole kernel, but the least
that mkfs.minix ought to do is not to let users to get that condition
quite as easily.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:15 +02:00
Sami Kerola 2159dbf365 mkfs.minix: check user input carefully
File name lenght and version input needs to be checked against each
other, which will determine what version of file system is in question.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:14 +02:00
Sami Kerola 77799d7c38 mkfs.minix: add fs_control structure, and remove most global variables
This allows better code structure in future.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:14 +02:00
Sami Kerola 3bb74a3ada mkfs.minix: remove unuseful code
Checks about inodes vs block sizes does not add much robustness.  Both
values are derived at compilation time from struct minix_inode size, and
they form full definition circle.

Bad block check for none-block devices should not be supressed, user
requested it so let him have it.

Check for st_rdev == 0x0300 || st_rdev == 0x0340 was unreachable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:13 +02:00
Sami Kerola c99128bcf5 mkfs.minix: use is_mounted() from libcommon
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:13 +02:00
Sami Kerola b59c5925ce mkfs.minix: introduce long options to the command
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-07-30 11:39:12 +02:00
Joshua Hudson da41ff553a mkfs.minix: increase maximum minix v2 and v3 file system sizes
mkfs.minix misbehaves when attempting to create a large v2 or v3
filesystem.  I finally traced it down to attempting to create too many
inodes so that the first zone is past 65535 blocks in.  This obviously
doesn't work as the on-disk superblock says this is a 16 bit integer.

I wrote a patch that catches this, clamps to the absolute v2/v3 limit
(like it already does for v1), and sets the blocks per inode to a more
reasonable ratio when exceeding half a gigabyte.  Having a half-gig
filesystem with most files being smaller than 3k isn't really reasonable.

I suppose if you don't want to adjust inode sizes automatically you could
take that part out, and it will just crab sooner.

Given the non-attention in the code, I suspect nobody ever had cause to
try such a big minix filesystem.  Well I have my reasons involving some
deeply embedded work where ext2 would place too much strain on the
hardware.

Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Joshua Hudson <joshudson@gmail.com>
2015-07-30 11:39:12 +02:00
Karel Zak 4df892812b fdisk: value is never read [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 13:59:19 +02:00
Karel Zak e5161deefb fdisk: value is never read [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 13:57:28 +02:00
Karel Zak f45f5c83f9 fdisk: value is never read [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 13:51:05 +02:00
Karel Zak 8abdb91211 sfdisk: add --list-free
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-28 15:54:07 +02:00
Karel Zak 0efd951c80 fdisk: add 'F' command to list free unpartitioned space
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-28 15:53:42 +02:00
Karel Zak 1b2e9dd01d cfdisk: don't print obsolete CHS addresses
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-27 15:49:14 +02:00
Karel Zak ed99eac0e2 cfdisk: make sure that output fits to terminal width
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-27 15:29:37 +02:00
Karel Zak 053939a45a fdisk: init libsmartcols debug
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-27 13:33:09 +02:00
Karel Zak 6e07b904e7 cfdisk: remove extra line between menu and info line
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-27 12:37:15 +02:00
Benno Schulenberg d48fc38307 cfdisk: spell "label" in lower case
To be less shouty.  It is not an abbreviation like "UUID".

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-07-27 11:57:11 +02:00
Benno Schulenberg 80351b1f4a cfdisk: allow an uppercase X to toggle the extra info
To make true the help text line that says that all commands
can be entered with either upper or lower case.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-07-27 11:57:08 +02:00
Karel Zak cbcafba2bb cfdisk: make sure that extra info is refreshed/removed
For example when you move from a Partition to the FreeSapce then we
need to remove old extra info and draw nothing.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-22 14:28:33 +02:00
Karel Zak a2d0dbb433 cfdisk: properly toggle extra info window, make it more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-22 14:11:27 +02:00
Karel Zak 4bd02cdfdf libfdisk: fix fdisk_label_parse_parttype() for unknown types
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-15 15:42:22 +02:00
Sami Kerola 55034ed00e docs: unify mkswap(8) with swapon(8) about holes warning
Reviewed-by: Dave Rutherford <dave@evilpettingzoo.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 12:06:00 +02:00
Boris Egorov 13c551f259 cfdisk: fix condition logic [cppcheck]
[disk-utils/cfdisk.c:1181] -> [disk-utils/cfdisk.c:1181]: (warning)
Possible null pointer dereference: data - otherwise it is redundant to
check it against null.

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-25 12:08:53 +02:00
Boris Egorov e3ca1312a2 sys-utils/disk-utils/lib: fix printf format types [cppcheck]
Fix 'invalidPrintfArgType' cppcheck warnings

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-25 12:08:45 +02:00
Benno Schulenberg 7f5769182f sfdisk: improve some formatting and wording in the man page
The main fix is: giving -J, --json its own paragraph.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-06-17 11:01:38 +02:00
Benno Schulenberg 3f43f5d05e sfdisk: show that the command --verify optionally takes device names
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-06-17 11:01:33 +02:00
Karel Zak a592b4b580 sfdisk: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-15 13:23:36 +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 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 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 6360bccad5 fdisk: provide more information by 'i'nfo command
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-11 12:45:21 +02:00
Jean-Loup 'clippix' Bogalho 3e3b51b3b1 fdisk: add the 'i'nfo command
Add the 'i'nfo command to fdisk that prints details about a specific partition.
Details are everything the function 'fdisk_label_get_field' can return.

Signed-off-by: Jean-Loup 'clippix' Bogalho <clippix@lse.epita.fr>
2015-05-11 12:26:30 +02:00
Stanislav Brabec d60d5b74d2 fsck: Fix parsing of -r
Fix regression introduced by commit 658c089: -r cannot be used as a last
option:

fsck -r /dev/sda1
fsck: invalid argument -r: '/dev/sda1'

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-05 12:28:41 +02:00
Karel Zak 658c089190 fsck: print errors on invalid -r argument
The patch also add support for -r 0.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-28 13:43:14 +02:00
Stanislav Brabec 07c09a29ea fsck: implement fsck -r {fd}
Make possible sending of statistics to a dedicated file descriptor.

Rationale: When UI is calling fsck from a remote terminal, fsck progress
needs to be sent to stdout. It is mixed there with output of statistics,
and it is impossible to parse the output to get the statistics.

Now it will be possible e. g. with "fsck -C -r 3 /dev/sda1"

Note: Code in if and else is intentionally partially duplicated. Current
human readable output of floats does not conform to locale conventions,
and may be changed in future. But we want to keep machine readable output
exactly same as it is now.

[kzak@redhat.com: - don't use report_stats_fd globally]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-28 13:16:41 +02:00
Karel Zak a03bdbcd20 fsck: use PATH or fallback to /sbin
It's overkill to support all the obscure paths like /sbin/fs.d. We
have PATH for customization, that's enough.

It still seems like a good idea to keep fsck robust, because it's used
by boot scripts/systemd. For this reason fsck fallbacks to "/sbin" if
PATH is undefined or empty.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-27 10:52:09 +02:00
Mike Frysinger 07b5156790 mkfs: drop hardcoded search path
Rather than maintain a hardcoded search path for looking up tools and
override the user's PATH env setting, respect whatever the user has.
This matches the convention of just about every other tool out there.

It might break on systems that don't have /sbin in their PATH and they
try to run /sbin/mkfs directly, but so be it.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-04-27 10:28:44 +02:00
Karel Zak 9d9a1b8760 libfdisk: (gpt) add extra check for First/Last LBA
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-23 12:32:36 +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