The current libfdisk code uses gettext() to translate strings. It
means it follows the default text domain (as set by textdomain(3)
usually in the main program). This is useless for public shared
library.
We have call private bindtextdomain() and use dgettext() with private
domain name to be independent on the main program. For this purpose
include/nls.h supports UL_TEXTDOMAIN_EXPLICIT to use dgettext().
Note that libfdisk will continue to use util-linux.po, rather than
keep the texts in the separate file.
The nls.h has to be included only from fdiskP.h to be sure that
nls.h works as expected for the library.
Signed-off-by: Karel Zak <kzak@redhat.com>
read(2) behavior is undefined if you want to read more than SSIZE_MAX
bytes. Let's be paranoid and check for this...
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
If possible use size_t for number of entries (partitions). It
makes code more readable and without unnecessary casts.
Signed-off-by: Karel Zak <kzak@redhat.com>
We blindly assume that our sizeof(struct gpt_entry) is the same
on-disk stored header->sizeof_partition_entry.
It seems more correct would be to use sizeof specified by header to
access the entries array items. This patch introduces gpt_get_entry()
to avoid direct access to gpt->ents[].
Signed-off-by: Karel Zak <kzak@redhat.com>
* '2017wk11' of git://github.com/kerolasa/lelux-utiliteetit:
blkid: add control struct
blkid: simplify version option handling
tests: add static keyword where needed [smatch scan]
tests: do not use plain 0 as NULL [smatch scan]
libsmartcols: fix test variable shadowing
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>
The current code calls fdisk_apply_user_device_properties() after
label probing, because we want to overwrite label geometry by user
settings (e.g. -C -H -S fdisk options).
Unfortunately, this way does not work if we need to use a different
sector size, because label probing depends on sector size... So, the
right way is to apply user setting to the fdisk context before we
start to read from device, and overwrite geometry again after label is
already read. Fortunately, this shit is necessary only rarely and for
SUN and SGI disk labels.
Addresses: https://github.com/karelzak/util-linux/issues/396
Signed-off-by: Karel Zak <kzak@redhat.com>
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>
* use macro for label initialization
* make sure we do not call fdisk_ref_labelitem() and
fdisk_unref_labelitem() for non-allocated items
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisk -l could crash randomly. Only seen on some i586 systems with
certain exotic compiler options.
The problem was that this item is later used in
function fdisk_reset_labelitem() like this:
if (li->type == 's')
free(li->data.str);
This may crash if item is randomly initialized.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* make sure token is terminated
* skip closing quotes
* allow extra space after quotes and before terminater
* skip extra space after terminater
Addresses: https://github.com/karelzak/util-linux/issues/367
Signed-off-by: Karel Zak <kzak@redhat.com>
The parser is not consistent and *case insensitive* Type= and Id= tokens
are not expected on all places.
Addresses: https://github.com/karelzak/util-linux/issues/367
Signed-off-by: Karel Zak <kzak@redhat.com>
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>
We don't modify data it's pointing out and we should not modify it.
Also remove casting to void * as gcc will do it automatically (before
we had to cast it explicitly to avoid warning on discarding 'const'
qualifier).
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
An insufficient check leads to an invalid free space output, as seen here:
$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,1' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Start End Sectors Size
1 2 2 1K
$ _
In this case, libfdisk fails to notice that it tries to calculate space
between two partitions, not between start of disk and first partition.
Currently, the code tries to achieve that by checking the address of the
last "partition", which is the first_lba block. Now if the first
partition is merely 1 block in size, the "last" address is still equal
to the first_lba block, which renders the check in libfdisk for the next
partition invalid.
I chose to use "nparts == 0" for this check, because the partitions are
properly sorted before iterating over them.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
An off-by-one issue exists in fdisk_get_freespaces. It can trigger an
assert, as seen here:
$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,2' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Aborted
$ _
Problem here is an invalid "grain" processing. A grain is considered
expected free space between partitions which can be required for proper
alignment. Normally, it's 1 MB but in this case our iso is merely 1 MB
so the grain is reduced to 1 byte.
The if-condition in question checks for "last + grain <= pa->start" and
therefore even triggers if there is no space between them (due to equal
check). Eventually, the start block address is higher than the end block
address which triggers the assert().
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
It's probably more robust (and readable) to be explicit when we count
with constant and 64bit numbers.
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1344482
Signed-off-by: Karel Zak <kzak@redhat.com>
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>
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
This is useful in two situations:
1. More than 128 partitions are required. Or
2. The partition table must be restricted in size, such as when a system
expects to find a bootloader at a location that would otherwise overlap the
partition table.
The gdisk partitioner supports this feature.
libfdisk is already capable of reading and writing partition tables of any
size, but previously could only create ones of 128 entries and could not
resize.
This change should be fairly safe, as it has no effect unless explicitly
activated.
Signed-off-by: Karel Zak <kzak@redhat.com>
For example:
sfdisk -N <parno>
may address unused partition. In this case we need to redirect from
fdisk_set_partition() to fdisk_add_partition() and follow default
setting (used all free space).
Signed-off-by: Karel Zak <kzak@redhat.com>
Now libfdisk provides functionality wipe disk device only ([s]fdisk
option --wipe).
This patch allows to probe for filesystems/RAIDs on newly created
partitions. It means we can remove signatures before the partition
node (device) is created. This reduces udev events and it's
unnecessary to call wipefs for all partitions. For example
sfdisk --wipe=always --wipe-partitions=always /dev/sda <<<
...
EOF
is a elegant way how to create new disk layout without any obsolete
filesystems/RAIDs.
Signed-off-by: Karel Zak <kzak@redhat.com>
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.
Signed-off-by: Karel Zak <kzak@redhat.com>
Still a few printf warnings found on i386 Linux:
libfdisk/src/alignment.c: In function 'fdisk_align_lba':
libfdisk/src/alignment.c:115:3: warning: format '%ju' expects argument of type 'uintmax_t', but argument 6 has type 'long unsigned int' [-Wformat]
sys-utils/lsns.c: In function ‘add_namespace’:
sys-utils/lsns.c:346:2: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘ino_t’ [-Wformat]
sys-utils/lsns.c: In function ‘add_process_to_namespace’:
sys-utils/lsns.c:362:2: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘ino_t’ [-Wformat]
sys-utils/lsns.c: In function ‘add_scols_line’:
sys-utils/lsns.c:440:4: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘ino_t’ [-Wformat]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Linux/glibc's qsort_r(3) has differently ordered arguments than BSD
implementations. For now we undef that quick and dirty.
The real fix would be to make configure check for qsort_r more
carefully (AC_CHECK_FUNCS with AC_LANG_WERROR). Moreover one could
add a wrapper to swap arguments, see
https://github.com/noporpoise/sort_r/blob/master/sort_r.h
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
While the header says C/H/S the actual numbers where printed as
C/S/H.
Addresses: http://bugs.debian.org/815847
Reported-by: "groups, freeman" <freeman_groups@reason.dyndns.org>
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
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>
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>
This was a major showstopper when building on a system where
LTLIBINTL libs are needed (e.g. OSX). Maybe there are a few test
programs which wouldn't need LDADD ... never mind.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* '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
Now libfdisk warns if another filesystem/RAID/PT signature is detected
on the device. It seems better and user-friendly to make it possible to
wipe the signatures when we write a new disk label to the device.
This patch adds to the library API
fdisk_enable_wipe()
fdisk_has_wipe()
fdisk_get_collision()
to control this new feature. The device modification is done by
libblkid (the same we use in some mkfs-like utils).
Signed-off-by: Karel Zak <kzak@redhat.com>
I got a bit confused with the interaction below:
Command (m for help): p
Disk /dev/sda: 41 GiB, 43965677568 bytes, 85870464 sectors
...
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1026047 1024000 500M 83 Linux
/dev/sda2 1026048 85868543 84842496 40.5G 8e Linux LVM
Command (m for help): n
To create more partitions, first replace a primary with an extended partition.
I knew I should have had two primary partitions available, but I did
not notice that the disk was seen as full (I was trying to grow it)
This change detects available primary partitions, and if so indicates
we are out of space, rather than out of partitions.
Signed-off-by: Ian Wienand <iwienand@redhat.com>
This patch introduces smart crc32 function that is able to exclude
specified. The advantage is that we does not have to modify GPT header
(set the current in-header crc field to zero) when we count crc32.
This allows to keep GPT header in read-only buffers and simplify code.
Signed-off-by: Karel Zak <kzak@redhat.com>
- verify that the new partition fits to the area if the size of the
has not been modified
- fix remaining space calculation (yes, brown-paper-bag bug..)
- offer also space before first partition as free space
Signed-off-by: Karel Zak <kzak@redhat.com>
For example:
# modprobe scsi_debug dev_size_mb=1000 opt_blks=65535 physblk_exp=3
creates a disk with:
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
where 33553920 % 4096 != 0, it means that use Optimal I/O size to
align partition results that partition is not aligned to physical
sector boundary.
Reported-by: Tom Yan <tom.ty89@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
* 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>
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>
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>
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>
The current fdisk_label_get_fields_ids() is too smart as it
differentiate between details mode etc. It's useful for default
output, but in some cases it's better to provide all output fields.
Signed-off-by: Karel Zak <kzak@redhat.com>
The new libfdisk/gpt test (4a4a0927) discovered that we read and write
partition attributes wrongly on BE systems.
Our temporarily used char[8] bits are always LE and do not need to be
converted.
CC: Michael Marineau <michael.marineau@coreos.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
The existing APIs can only toggle individual bits or get and set bits in
a complex text representation, making it impractical to use libfdisk for
manipulating the GPT partition attribute field in more complex ways such
as updating a value that is multiple bits wide. For example priority
based partition selection originally designed for ChromeOS includes two
integer values that are 4-bits wide.
http://www.chromium.org/chromium-os/chromiumos-design-docs/disk-format#TOC-Trusting-the-GPT
[kzak@redhat.com: - add new symbols to .sym file and docs
- remove unused variables from test program]
Signed-off-by: Michael Marineau <michael.marineau@coreos.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Search for the protective partition before attempting to validate that
it covers the GPT header. Some hybrid MBRs list partitions out of order.
For example, CoreOS images ship with a hybrid MBR that lists the boot
partition first and the protective partition second in order to maintain
compatibility with old versions of Xen's PV-GRUB.
Signed-off-by: Michael Marineau <michael.marineau@coreos.com>
Really stupid copy & past mistake. The libfdisk symbols should not be
prefixed by MOUNT_ suffix.
This change makes binaries linked with libfdisk 2.26 incompatible with
new libfdisk. Fortunately, 2.26 has been the first release and very
probably the library has been used for util-linux fdisks only.
Signed-off-by: Karel Zak <kzak@redhat.com>
The current sfdisk does not allow to create partition that
starts before the default libfdisk First LBA (~1MiB). It
means that
# sfdisk --dump /dev/sda > foo
# sfdisk /dev/sdb < foo
does not work on systems where 1st partition does not start at offset
2048.
This patch add new headers to scripts to inform libfdisk about different
First/Last LBA ranges. For example:
label: gpt
first-lba: 34
allows to override the library default.
Signed-off-by: Karel Zak <kzak@redhat.com>
- cfdisk: minimal partitions size is 1 sector
- dos: when align last sector then don't set partition size to zero
for very small partitions.
- don't ignore tiny partitions before free space when define
free-space start offset
- improve some debug messages
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
The current code in add_partition() de-increment number of partitions
on error when logical partition requested and add_logical() does the
same. The result is mess in partitions array.
The another fixed issue is that add_logical() is called if all primary
partitions are already used although 'pa->start' (the template) is
explicitly defined outside the extended partition. The right behavior
is to end with error message.
Signed-off-by: Karel Zak <kzak@redhat.com>
deleting an extended partition with cfdisk leaves its contained
partitions in existence
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
It's better to use exact and explicitly defined types (e.g. uint64_t)
rather than something like off_t to make code more portable.
[reported with gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3)]
The patch also fixes one debug message.
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
Kay reported that Windows 8.1 installed does not recognize GPT created
by libfdisk, but parted works as expected.
It seems (according to the header hexdump) that the problem is
HeaderSize GPT field where libfdisk uses 512 (header + reserved area),
but parted uses 92. The both is pretty valid according to the current
EFI standard, but 92 is probably more backwardly compatible.
I also found places in code where libfdisk gpt driver is inconsistent
and uses sometimes all sector and simetimes sizeof(gpt_header) only.
The right solution is to read all sector (into zeroized memory) and
later write again all sector to the device.
Reported-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
This change fixes all shadow declarations. The worth while to mention
fix is with libfdisk sun geometry. It comes from bitops.h cpu_to_be16
macro that further expands from include/bits/byteswap.h that has the
shadowing.
libfdisk/src/sun.c:961:173: warning: declaration of '__v' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:69: warning: shadowed declaration is here [-Wshadow]
libfdisk/src/sun.c:961:178: warning: declaration of '__x' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:74: warning: shadowed declaration is here [-Wshadow]
That could have caused earlier some unexpected results.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The problem is how fdisk_partition_cmp_start() compare numbers, the
function returns result from "a->start - b->start", unfortunately the
numbers are uint64, but function returns "int".
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
- symbols versioning
- SONAME from configure.ac
- library version to header file
- modify build-sys to compile and install shared lib
Signed-off-by: Karel Zak <kzak@redhat.com>
The struct fdisk_partition has special flag "end_follow_default" to
make the partition large as much as possible. This patch makes this
flag usable for fdisk_set_partition() function.
Command line example (enlarge the first partition):
# echo ',+' | ./sfdisk -N1 /dev/sdb
...
Disk /dev/sdb: 100 MiB, 104857600 bytes, 204800 sectors
...
Old situation:
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 22527 20480 10M 83 Linux
^^^^^
New situation:
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 204799 202752 99M 83 Linux
^^^^^^
Signed-off-by: Karel Zak <kzak@redhat.com>
Was:
Mentioned function returns -1 if adding of primary partition is
impossible. Caller treats this value as size_t (res variable) and then
compares it for negative values, totally ignoring errors.
Becomes:
Now function takes address to variable and fills it with partition
number. Caller treats return value as int and use it appropriately.
[kzak@redhat.com: - don't mix return code and partno at all]
Signed-off-by: Boris Egorov <egorov@linux.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
The GPT first usable LBA is usually aligned to grain (1MiB), but for small
(<=4MiB) devices we strictly follow sector sizes.
In this case there is a small space in front of the aligned begin of
the first partition. This useless space should not be offered for the
next partitions.
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 32768 bytes
Disklabel type: gpt
Disk identifier: 041E2D54-AD0C-4C7E-A50D-363D23058D47
Device Start End Size Type
/dev/sdb1 40 2087 1M Linux filesystem
Command (m for help): n
Partition number (2-128, default 2):
First sector (34-8158, default 2088):
^^
first usable LBA is 34, but first aligned (recommended) LBA is 40, we
use it for the first partition. All this is correct, but the space
before the first partition should be ignored. Fixed version:
Command (m for help): n
Partition number (2-128, default 2):
First sector (2088-8158, default 2088):
^^^^
Note this problem does not exist for "normal" (large) devices where
first usable LBA is aligned to grain.
Reported-by: Boaz Harrosh <boaz@plexistor.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
* use check_ prefix for checking functions
* use plural in function names where we work with more partitions than one
* always use "ents" when when we work with gpt entries array
Signed-off-by: Karel Zak <kzak@redhat.com>
The current offset of cxt->dev_fd may not be still 0, notably when
blkdev_get_size has to resort to using blkdev_find_size
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org
The zero may be valid size and start of the partition. This patch
introduces:
fdisk_partition_has_start()
fdisk_partition_has_size()
fdisk_partition_unset_size()
fdisk_partition_unset_start()
to make it possible to work with zero. The feature is internally
implemented by magic constant ((type) -1) for undefined sizes and
offsets.
Signed-off-by: Karel Zak <kzak@redhat.com>
* this patch add to dos driver support for fdisk_partition->size_explicit
to avoid unexpected last sector alignment for sizes explicitly specified
in sectors
* add support for small "first LBA", the current default is to use
1MiB offset for the first partition and for each EBR. This is not
backwardly compatible and it makes impossible to apply sfdisk
scripts/dumps from old systems, because original offset can be
smaller than 2048 sectors (old sfdisk default is 1 sector).
The solution is on the fly to detect this situation and change
fdisk_context->first_lba to 1 sector. Nasty.
Signed-off-by: Karel Zak <kzak@redhat.com>