summaryrefslogtreecommitdiffstats
path: root/disk-utils/sfdisk.c
Commit message (Collapse)AuthorAgeFilesLines
* sfdisk: use xstrcpy()Karel Zak2019-05-201-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: remove unnecessary size check [cppcheck]Sami Kerola2019-05-181-2/+0Star
| | | | | | | | | | | | Following warning is false positive. Size of the buffer is defined using BUFSIZ, and so the strncpy() will never overwrite the last byte that is initialized to zero in get_user_reply(). [disk-utils/sfdisk.c:137] -> [disk-utils/sfdisk.c:136]: (warning) Either the condition 'bufsz!=0' is redundant or strncpy() argument nr 3 can have invalid value. The value is -1 but the valid values are '0:'. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* fdisk: initialize buffers for get_user_reply() [coverity scan]Karel Zak2019-05-141-2/+2
| | | | | | It's probably unnecessary, but better be safe than sorry. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-4/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* various: fix 'uninitialized when used' warnings [clang]Sami Kerola2019-02-181-1/+1
| | | | | | | This change fixes "warning: variable 'var' may be uninitialized when used here [-Wconditional-uninitialized]" warnings reported in various files. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* sfdisk: Avoid out of boundary read with readlineTobias Stoeckmann2019-02-181-1/+3
| | | | | | | | | | | | | | | It is not guaranteed that the returned string of readline() actually contains as many bytes as buf can contain. If bufsz is larger than the allocated memory by readline, an out of boundary read occurs and leads to undefined behaviour. Most likely that will be a crash. This can be reproduced when readline-support is compiled in and when you directly enter "quit" and "n" (to not write changes back to disk) when sfdisk was called with any given device. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
* sfdisk: disable --activate for Hybrid GPT/MBRKarel Zak2018-10-041-0/+3
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/699 Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: be more verbose about PMBR on --activateKarel Zak2018-10-041-0/+2
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/699 Signed-off-by: Karel Zak <kzak@redhat.com>
* include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()Karel Zak2018-01-171-1/+1
| | | | | | | Let's make it possible to use debug.h without environment variables. Suggested-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: (script) support R (RAID) and V (LVM) shortcutsKarel Zak2018-01-091-2/+2
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/560 Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: wait before re-readKarel Zak2018-01-021-1/+8
| | | | | | | | | | | | The original old (v2.13) fdisk had sleep(2) beany ideafore re-read ioctl. It seems overkill, but short sleep is probably a good idea as we call re-read on sfdisk start and at the end. It's possible that sfdisk is too fast and the initial re-read is not gone yet. It would be nice to have something more elegant than sleep, any idea? Addresses: https://github.com/karelzak/util-linux/issues/557 Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: create empty label on 'write' commandKarel Zak2017-11-031-1/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/528 Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: allow to disable bootable flag on all partitionsKarel Zak2017-11-021-1/+5
| | | | | | | | | 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>
* sfdisk: allow to use --activate for PMBRKarel Zak2017-11-021-3/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: use fdisk_device_is_used()Karel Zak2017-07-141-27/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-1/+1
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+2
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: cosmetics, remove argument from usage(FILE*)Ruediger Meier2017-06-261-3/+4
| | | | | | | | | | | | | | 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>
* include/c.h: add USAGE_COMMANDS and USAGE_COLUMNSJ William Piggott2017-06-241-1/+1
| | | | | | | | | | | | * 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>
* sfdisk: disambiguate units of --show-sizeChris Morin2017-05-221-2/+12
| | | | | | | [kzak@redhat.com: - use optutils.h] Signed-off-by: Chris Morin <chris.morin2@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: add hints for scanners [coverity scan]Karel Zak2017-05-171-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk, sfdisk: avoid non-ANSI function declarations [smatch scan]Sami Kerola2017-03-141-0/+1
| | | | | | | | | | | | | | | 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>
* misc: stop mixing declarations and codeSami Kerola2017-03-131-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: add static keyword to where needed [smatch scan]Sami Kerola2017-02-201-1/+1
| | | | | | | text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be static? Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-1/+1
| | | | | | | | | | 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>
* sfdisk: improve --wipe functionalityKarel Zak2017-02-141-19/+35
| | | | | | | | | * 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>
* sfdisk: --quiet fixesKarel Zak2017-02-101-4/+6
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/412 Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: unused parameter 'sf' [-Wunused-parameter]Karel Zak2017-01-051-2/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: support empty label use-caseKarel Zak2016-11-301-0/+17
| | | | | | | | | | | | | | | 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>
* sfdisk: cleanup --dump error messagesKarel Zak2016-11-301-1/+4
| | | | | | | | | | | | | 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>
* sfdisk: don't be silent when list non-existing deviceKarel Zak2016-11-291-6/+10
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/376 Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: cleanup before going out of scope [coverity scan]Karel Zak2016-10-041-5/+12
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: free before going out of scope [coverity scan]Karel Zak2016-10-041-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: add --no-tell-kernelKarel Zak2016-09-021-3/+12
| | | | | | | | 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>
* sfdisk: make non-interactive output more readableKarel Zak2016-08-311-14/+26
| | | | | | | | | | | | | | | | | | | | | # 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>
* sfdisk: add show-pt-geometry to usage() and sfdisk.8Karel Zak2016-08-081-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk: Add --show-pt-geometry compatibility codeStanislav Brabec2016-08-081-1/+4
| | | | | | | --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>
* Revert "sfdisk: exit with error if rereading partition table fails"Karel Zak2016-07-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | This reverts commit 14f644f386a1708483ed446e983c0976e3976a9d. 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>
* misc: Fix various typosSebastian Rasmussen2016-05-311-5/+5
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* sfdisk: exit with error if rereading partition table failsVictor Dodon2016-05-051-1/+1
| | | | | | | 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>
* sfdisk: add --wipe-partitions=auto|never|defaultKarel Zak2016-05-041-5/+61
| | | | | | | | | | | | | 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>
* fdisk, cfdisk, sfdisk: improve the grammar of three messagesBenno Schulenberg2016-03-161-2/+2
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* sfdisk: improve the wording of seven error messagesBenno Schulenberg2016-03-161-7/+7
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* misc: remove duplicate includesKarel Zak2016-03-101-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* sfdisk, fdisk: add fflush()Karel Zak2016-03-101-0/+2
| | | | | | | Let's add fflush(stdout) before we print to stderr to make output order more deterministic. Signed-off-by: Karel Zak <kzak@redhat.com>
* Revert "include sysmacros.h where used"Karel Zak2016-03-081-1/+0Star
| | | | This reverts commit 46a40c018438b7b2b25083a5e5a4a21055a0c1e9.
* include sysmacros.h where usedMike Frysinger2016-03-081-0/+1
| | | | | | | | BSD/Linux systems stick major/minor/makedev in sysmacros.h. Newer Linux libraries have been moving away from including sysmacros.h implicitly via sys/types.h, so include it directly. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* misc: again fixing many printf format stringsRuediger Meier2016-03-071-7/+10
| | | | | | | | | | | | | | | | | | | 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>
* wipefs, sfdisk: include libgen.h for basename(3p)Ruediger Meier2016-03-071-0/+1
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>