This patch adds device topology discovery to the internal API. This
functionality is static only to the API and therefore hidden from general fdisk
code. Functionality itself doesn't really change, min_io_size, io_size, logical
and physical sector sizes and alignment offset are added to the fdisk_context
structure and elements are accessed from there. The logical sector size
(sector_size) is now unsigned long instead of unsigned int, this as no effect
otherwise.
A few things to notice:
- The patch is larger than I wanted but we need to modify function parameters
across fdisk and its labels to use the topology data from cxt-> instances.
Hopefully this will be pretty much it regarding this kind of modifications -
perhaps geometry will need something of the like too.
- The -b option must override internal discovery.
- A new helper function has added to verify if the device provides topology
information, this replaces the 'has_topology' global variable.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
This program heavily uses global variables, which isn't very elegant and can
lead to nasty bugs. Modify functions that use fdisk's context current features
(descriptor and path), to receive the context as a parameter instead of
globally. This includes DOS, SUN, SGI and BSD label code. Another benefit that
comes with this is that as the API grows all the information regarding fdisk
will be accessible from this structure so we can reduce even more global
variables and simply code.
This patch passed:
- building
- regression tests
- local dos/sun/bsd partition changes
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Recently, commit 0a86755fe8 directed the welcome
message output from stderr to stdout breaking regression tests. Correct this
by flushing stdout and stop buffering the output - a trivial function is
created as well.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Based on libmnt, this patch adds basic debugging support for fdisk. Currently
only CONTEXT is debugged, yet keeps exact functionality as libmnt/libblkid.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
This is the first patch that adds the initial parts of the new fdisk internal
API. Two functions are created to both init and deinit the fdisk context. Only
the device's descriptor and path are added as a start and these are replaced
throughout fdisk.c and label specific code.
All logic that opens the file does it with fdisk_new_context_from_filename(),
and this enforces always opening the device with rw, then, if unsuccesfull,
with read-only. This changes the current logic that opens the device with
certain permissions depending on the user given options. For example, -l opens
the device read-only.
This patch passed regression tests and local modifications for sgi/dos/sun disk
labels.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Since this is DOS specific logic, it belongs in its own label file.
Additionally, a dos_new_partition() function is created that asks the user for
partition type and then calls the actual dos_add_partition().
This patch passed fdisk regression tests, builds without problems and it was
locally tested against adding and removing DOS partitions.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Commit 8db8295d82 added a regression that causes the program to crash when
touching the partition structure (pte) for BSD/OSF labels. Since DOS has its own initialization function,
allow BSD labels to use it as well.
Steps to reproduce:
$> fdisk bsd.img (obtained from blkid regression test files)
Command (m for help): p
...
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Segmentation fault
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
DOS specific logic is currently embedded in the heart of fdisk code. This patch
separates DOS label specific code into its own file, just like the rest of the
labels, leaving a more generic fdisk.c file. Most changes are just moving code
from fdisk.c to fdisk.h and fdiskdoslabel.[c/h].
The only logical modification is calling dos_delete_partition() from
read_extended(), instead of the generic delete_partition. This is ok since
read extended is only called from a DOS context.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
When the device cannot be opened, there's no point calling fatal() when we can
just use err(3). When any other kind of fatal error occurs it's Ok, in addition
we can also go ahead and close the descriptor before exiting the program as
it's currently leaking.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
This patch eliminates the long/setjmp code. The current logic does not do
anything with stack jumps as it only exits from
print_partition_table_from_option() when a fatal error occurs.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:
$ git ls-files | grep -v ^po/ | misspellings -f -
* isosize: Fix typo in usage string.
* configure.ac: Fix typo in help string of --enable-most-builds option.
* fdisk: Fix typo in man page.
* libblkid, blkid, mount: Likewise.
* Fix various typos in docs and in source code comments.
Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
This patch makes fdisk open(2) the device in only one place (get_boot), instead
of having to depend on user input (ie: listing -l).
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
When creating a new DOS label, SGI and SUN pt logic have no business being
there. Remove sun/sgi_nolabel(), since the default amount of partitions are
previously set to 4 and the sun/sgi magic nums are not used in this context.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* 'close_stream' of git://github.com/kerolasa/lelux-utiliteetit:
disk-utils: verify writing to streams was successful
fdisk: verify writing to streams was successful
getopt: verify writing to streams was successful
hwclock: verify writing to streams was successful
login-utils: verify writing to streams was successful
misc-utils: verify writing to streams was successful
mount: verify writing to streams was successful
partx: verify writing to streams was successful
schedutils: verify writing to streams was successful
sys-utils: verify writing to streams was successful
term-utils: verify writing to streams was successful
text-utils: verify writing to streams was successful
include: add stream error checking facility
Conflicts:
fdisk/fdisk.c
If user input in a last sector dialog was out of range and with suffix, and if
this was followed by accepting the default value, then the used last sector was
erroneously default - 1.
Reported-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
This splits check_dos_label() and dos_init() off from get_boot() and gets
rid of the invalid flag 0x00000 warning message due to a check for MBR
signs in zeroized buffer:
memset(MBRbuffer, 0, 512);
if (what == create_empty_dos)
goto got_dos_table;
[...]
got_dos_table:
if (!valid_part_table_flag(MBRbuffer)) {
[...]
if (!valid_part_table_flag(pe->sectorbuffer))
fprintf(stderr, _("Warning: invalid flag 0x%04x of partition "
[...]
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>