Commit Graph

180 Commits

Author SHA1 Message Date
Davidlohr Bueso 618882d609 fdisk: add total sectors
Add the total_sectors variable to the context structure. This is the initial
geometry information.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06 10:40:40 +02:00
Davidlohr Bueso e53ced85bf fdisk: add device topology to the API
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>
2012-06-06 10:30:07 +02:00
Davidlohr Bueso 50dec1ebff fdisk: introduce sector_t type
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06 10:11:54 +02:00
Davidlohr Bueso d8de095530 fdisk: remove useless comments
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06 10:11:47 +02:00
Davidlohr Bueso 7737f69850 fdisk: use context as a parameter
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>
2012-06-06 10:11:41 +02:00
Davidlohr Bueso 89fd812fcb fdisk: stop buffering welcome message
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>
2012-06-06 10:11:22 +02:00
Karel Zak 0a86755fe8 fdisk: don't print welcome message to stderr
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-23 11:26:42 +02:00
Karel Zak 7657d3e217 fdisk: add readonly option to fdisk_new_context_from_filename()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-23 11:24:04 +02:00
Davidlohr Bueso f7b1f75e68 fdisk: add debug support
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>
2012-05-23 10:53:30 +02:00
Davidlohr Bueso 823f0fd107 fdisk: introduce fdisk context
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>
2012-05-23 10:53:05 +02:00
Davidlohr Bueso 6da365de2d fdisk: refactor -s option
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-23 10:52:09 +02:00
Davidlohr Bueso 37eadc1796 fdisk: use BSD label header
Move bsd specific function definitions into its own header file and include it in fdisk code.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-23 10:51:27 +02:00
Davidlohr Bueso e11447670a fdisk: remove bogus statement
usage() does not return, also move the help option handling to the bottom of the switch.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-23 10:51:23 +02:00
Davidlohr Bueso 365f01fcdf fdisk: add an quit/exit handling function
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-23 10:50:59 +02:00
Karel Zak 0069505932 fdisk: cleanup strtoxx_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 17:43:49 +02:00
Davidlohr Bueso 8335c780ee fdisk: remove unused function declaration
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-10 11:38:14 +02:00
Davidlohr Bueso 0dc13a3863 fdisk: create DOS specific write table function
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-10 11:35:42 +02:00
Davidlohr Bueso 9dea2923c8 fdisk: move DOS new/add partition code
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>
2012-05-10 11:34:43 +02:00
Davidlohr Bueso a2a7d18e62 fdisk: remove unused hsc2sector macro
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-10 11:33:12 +02:00
Davidlohr Bueso 44d2fc8198 fdisk: fix segfault on bsd label
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>
2012-05-10 11:32:04 +02:00
Karel Zak 96f817fb16 fdisk: fix fdiskdoslabel.c global variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-02 14:05:51 +02:00
Davidlohr Bueso e2ee917804 fdisk: isolate dos label logic
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>
2012-05-02 10:35:57 +02:00
Davidlohr Bueso 64115eed34 fdisk: remove dummy function
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-02 09:33:56 +02:00
Davidlohr Bueso 3457420178 fdisk: rework fatal errors
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>
2012-05-02 09:33:46 +02:00
Davidlohr Bueso 337643ad0f fdisk: remove listing variable
useless global variable.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-02 09:33:32 +02:00
Davidlohr Bueso 9f6c866f65 fdisk: remove stack jumping
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>
2012-05-02 09:33:24 +02:00
Bernhard Voelker 455fe9a075 Fix typos found by misspellings
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>
2012-04-23 13:16:35 +02:00
Davidlohr Bueso 8d95e4ee61 fdisk: simplify device opening
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>
2012-04-23 13:07:16 +02:00
Davidlohr Bueso f45121dd46 fdisk: remove action enum
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-23 13:00:00 +02:00
Davidlohr Bueso 3813eb5ead fdisk: do not call sgi and sun code when creating a new dos label
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>
2012-04-23 12:55:52 +02:00
Davidlohr Bueso 68c5a7ea7f fdisk: remove dead code
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-23 12:40:20 +02:00
Davidlohr Bueso c867a8e3b3 fdisk: kernel/bios sectors and heads need not be global
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-23 12:38:22 +02:00
Davidlohr Bueso a2482eb3d9 fdisk: standarize version output
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-23 12:15:15 +02:00
Davidlohr Bueso 9912f01b68 fdisk: make CHS user values more robust
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-23 12:12:32 +02:00
Karel Zak 6259c257d8 Merge branch 'close_stream' of git://github.com/kerolasa/lelux-utiliteetit
* '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
2012-04-11 12:37:59 +02:00
Davidlohr Bueso 2a2319bbac fdisk: use randutils for mbr signature creation
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-10 13:15:32 +02:00
Davidlohr Bueso 64128b705c fdisk: move kernel geometry into blkdev
This is a more generic place for this ioctl.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-04-10 12:21:16 +02:00
Sami Kerola b2d28533dd fdisk: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 20:02:04 +02:00
Karel Zak 96f3eef55e fdisk: don't print confusing warning on non-partitioned disks
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=740163
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-20 11:18:54 +01:00
Karel Zak 1c6b33784b fdisk: fix cdrom detection
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-01 13:42:08 +01:00
Karel Zak 099c7a94ce fdisk: add missing break
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-31 21:06:42 +01:00
Karel Zak baec3e4913 fdisk: fix poor coding style
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-17 16:26:08 +01:00
Francesco Cosoleto 0c38188028 fdisk: fix last sector dialog bug after an incorrect input with suffix
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>
2012-01-16 21:53:00 +01:00
Francesco Cosoleto 2c911261ff fdisk: rename read_int_sx() and some related variables
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2012-01-16 21:52:47 +01:00
Francesco Cosoleto 0c48d37192 fdisk: fix incorrect position of is_ide_cdrom_or_tape() call
Reported-by: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2012-01-04 11:35:26 +01:00
Davidlohr Bueso 3b622ddd72 fdisk: use CDROM_GET_CAPABILITY ioctl
And replace the current archaic logic of is_ide_cdrom_or_tape().

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-01-02 13:43:06 +01:00
Francesco Cosoleto dae4880508 fdisk: improve some messages
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:10 +01:00
Francesco Cosoleto 8db8295d82 fdisk: Fix bad invalid flag 0x00000 warning message
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>
2011-12-16 14:04:09 +01:00
Francesco Cosoleto 4a96a62a09 fdisk: avoid an intermediate variable in command_prompt()
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:07 +01:00
Francesco Cosoleto b152082db3 fdisk: don't use get_existing_partition() if disk label isn't dos
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-12-16 14:04:06 +01:00