summaryrefslogtreecommitdiffstats
path: root/fdisk
Commit message (Collapse)AuthorAgeFilesLines
* fdisk: add device topology to the APIDavidlohr Bueso2012-06-0610-306/+329
| | | | | | | | | | | | | | | | | | | | | | | 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>
* fdisk: sun: use sector_tDavidlohr Bueso2012-06-061-1/+1
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: sgi: use sector_tDavidlohr Bueso2012-06-061-2/+2
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: dos: use sector_tDavidlohr Bueso2012-06-062-19/+15Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: introduce sector_t typeDavidlohr Bueso2012-06-062-31/+31
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: remove useless commentsDavidlohr Bueso2012-06-061-2/+2
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: use context as a parameterDavidlohr Bueso2012-06-0610-142/+144
| | | | | | | | | | | | | | | | | 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>
* fdisk: stop buffering welcome messageDavidlohr Bueso2012-06-061-3/+10
| | | | | | | | | Recently, commit 0a86755fe8af1da510d2eca43bdfcd70af098c19 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>
* fdisk: don't print welcome message to stderrKarel Zak2012-05-231-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: add readonly option to fdisk_new_context_from_filename()Karel Zak2012-05-233-6/+13
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: always use stderr for debug messagesKarel Zak2012-05-232-1/+11
| | | | | | | | * add dbgprint() to provide standardized debug output * print initial debug message to stderr Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: add debug supportDavidlohr Bueso2012-05-233-1/+61
| | | | | | | 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>
* fdisk: introduce fdisk contextDavidlohr Bueso2012-05-238-90/+170
| | | | | | | | | | | | | | | | | | 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>
* fdisk: refactor -s optionDavidlohr Bueso2012-05-231-19/+22
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: use BSD label headerDavidlohr Bueso2012-05-233-6/+6
| | | | | | Move bsd specific function definitions into its own header file and include it in fdisk code. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: remove bogus statementDavidlohr Bueso2012-05-231-5/+4Star
| | | | | | usage() does not return, also move the help option handling to the bottom of the switch. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: add an quit/exit handling functionDavidlohr Bueso2012-05-231-6/+9
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: cleanup strtoxx_or_err()Karel Zak2012-05-153-11/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libuuid: avoid double open and leaking fd (reworked)Petr Uzel2012-05-101-1/+1
| | | | | | | | | | | | | | This reverts commit 6126f7a53c57485a9a29ddd772765695f23c92e6 and fixes the double open and leaking descriptor in a different way, that is by using newly introduced function 'have_random_source()' to check whether good random source is available while deciding which uuid type to generate (random/time). This is better than calling random_get_fd() twice, passing the file descriptor down the stack and reusing it in next call to random_get_fd(). Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
* fdisk: sgi: abort on HDIO_GETGEO failureDavidlohr Bueso2012-05-101-19/+20
| | | | | | | | | | | | | | | | | | | | | | | | | When the HDIO_GETGEO ioctl fails on non IRIX/MIPS platforms (ie: inappropriate ioctl for device) the variables that describe the geometry are compromissed. One clear example is a division by 0 bug because the cylinder size is 0 is verify_sgi(): $> fdisk sgi.img Welcome to fdisk (util-linux 2.21.392-4b1c). ... Command (m for help): x Expert command (m for help): g Building a new SGI disklabel. Partition 11 of type SGI volume and of size 7.9 MiB is set Floating point exception Fix this by simply exiting the program instead of leaving it in a vulnerable state. Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: remove unused function declarationDavidlohr Bueso2012-05-101-2/+0Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: create DOS specific write table functionDavidlohr Bueso2012-05-103-23/+30
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: move DOS new/add partition codeDavidlohr Bueso2012-05-104-348/+365
| | | | | | | | | | | 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>
* fdisk: remove unused hsc2sector macroDavidlohr Bueso2012-05-101-2/+0Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: fix segfault on bsd labelDavidlohr Bueso2012-05-103-1/+4
| | | | | | | | | | | | | | | | | | Commit 8db8295d824cd0c8cba9385e4635d6e311d69d3f 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>
* libuuid: avoid double open and leaking descriptorPetr Uzel2012-05-041-1/+1
| | | | | | | | | | | | | We are opening /dev/urandom twice in uuid_generate(): first to check if the file is available and then later __uuid_generate_random() again to actually get the random data. Moreover, descriptor from the first open is leaking. Fix by passign the descriptor down the stack and reusing it there. References: http://marc.info/?l=util-linux-ng&m=133406051131131&w=2 Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
* fdisk: fix fdiskdoslabel.c global variablesKarel Zak2012-05-024-18/+25
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: isolate dos label logicDavidlohr Bueso2012-05-025-413/+446
| | | | | | | | | | | | | 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>
* fdisk: remove dummy functionDavidlohr Bueso2012-05-021-2/+0Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: rework fatal errorsDavidlohr Bueso2012-05-022-15/+12Star
| | | | | | | | | 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>
* fdisk: remove listing variableDavidlohr Bueso2012-05-021-2/+0Star
| | | | | | useless global variable. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: remove stack jumpingDavidlohr Bueso2012-05-021-15/+2Star
| | | | | | | | 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>
* sfdisk: fix compiler warning [-Wunused-result]Petr Uzel2012-04-271-1/+1
| | | | | | | sfdisk.c: In function ‘do_fdisk’: sfdisk.c:3212:11: error: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Werror=unused-result] Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
* Fix typos found by misspellingsBernhard Voelker2012-04-232-2/+2
| | | | | | | | | | | | | | | 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>
* fdisk: simplify device openingDavidlohr Bueso2012-04-231-23/+16Star
| | | | | | | 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>
* fdisk: remove action enumDavidlohr Bueso2012-04-232-10/+6Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: do not call sgi and sun code when creating a new dos labelDavidlohr Bueso2012-04-231-2/+0Star
| | | | | | | | 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>
* sfdisk: improve F_MEGABYTE headerBernhard Voelker2012-04-231-4/+4
| | | | Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
* fdisk: remove dead codeDavidlohr Bueso2012-04-231-20/+0Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: kernel/bios sectors and heads need not be globalDavidlohr Bueso2012-04-231-3/+2Star
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: standarize version outputDavidlohr Bueso2012-04-231-2/+2
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: make CHS user values more robustDavidlohr Bueso2012-04-233-11/+12
| | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* fdisk: remove unused fileKarel Zak2012-04-112-135/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'close_stream' of git://github.com/kerolasa/lelux-utiliteetitKarel Zak2012-04-115-0/+11
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * '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
| * fdisk: verify writing to streams was successfulSami Kerola2012-04-045-0/+11
| | | | | | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* | fdisk: use randutils for mbr signature creationDavidlohr Bueso2012-04-102-46/+6Star
| | | | | | | | Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* | sfdisk: fix calculation due to type mismatch (ix86)Petr Uzel2012-04-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instructing sfdisk to create one partition spanning across entire disk (",,") on 32bit system, if the disk is sufficiently large (~2TB) leads to wrong calculation in compute_start_sect() due to type mismatch. Can be reproduced as: -------------------------- linux-3ln5:~ # modprobe scsi_debug virtual_gb=2000 linux-3ln5:~ # sfdisk /dev/sda <<< ',,' Checking that no-one is using this disk right now ... OK Disk /dev/sda: 261083 cylinders, 255 heads, 63 sectors/track sfdisk: ERROR: sector 0 does not have an msdos signature sfdisk: /dev/sda: unrecognized partition table type Old situation: sfdisk: No partitions found no room for partition descriptor sfdisk: bad input -------------------------- Addresses: https://bugzilla.novell.com/show_bug.cgi?id=754789 Reported-by: Dan Mares <dan.mares@norcrossgroup.com> Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
* | fdisk: move kernel geometry into blkdevDavidlohr Bueso2012-04-101-14/+1Star
| | | | | | | | | | | | This is a more generic place for this ioctl. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
* | sfdisk: make -l less verbose about missing PTKarel Zak2012-04-061-8/+10
|/ | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: don't print confusing warning on non-partitioned disksKarel Zak2012-03-201-4/+2Star
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=740163 Signed-off-by: Karel Zak <kzak@redhat.com>