summaryrefslogtreecommitdiff
path: root/fdisk
AgeCommit message (Collapse)AuthorFilesLines
2012-06-26build-sys: rename fdisk -> fdisks/, convert to moduleKarel Zak27-14392/+0
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21fdisk: add some debug messagesKarel Zak1-1/+9
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21fdisk: use memset() rather than bzero()Karel Zak1-1/+1
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21fdisk: API: add geometryDavidlohr Bueso9-200/+220
Add device geometry to the fdisk API. While it maintains traditional behaviour, the cylinders are changed to sector_t instead of unsigned int in order to avoid dealing with truncated cylinders. A new helper is added to compute the amount of cylinders based on the heads and sectors - if a user passed -H or -S to the program, it must call this function to update the corresponding values. This patch passes regression tests. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-21fdisk: mark dos compatibility/CHS options deprecated in manpageDavidlohr Bueso1-5/+6
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-21fdisk: sun: remove unused functionDavidlohr Bueso2-7/+0
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-21fdisk: sgi: remove unused functionDavidlohr Bueso2-7/+0
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-21fdisk: sgi: remove unused codeDavidlohr Bueso1-17/+0
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-21fdisk: API: add mbrDavidlohr Bueso13-210/+262
This patch adds to the fdisk API the relevant logic to buffers that have MBR. This also serves for future GPT support for the protective MBR. All labels have been updated to have access to the cxt structure for the corresponding buffer. An important observation is that SGI no longer uses the standard qsort(3) function to sort partitions, as it needs access to cxt. To address this, a heap sort implementation from the kernel was added to the label code and adapted to fdisk. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-21fdisk: API: add topology debugDavidlohr Bueso2-0/+6
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-21fdisk: extend comments for fdisk_new_context()Davidlohr Bueso1-4/+6
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: fix io_size usage in new APIKarel Zak2-7/+10
properly implemented fdisk_dev_has_topology() requires optimal I/O size to detect that the device provides topology. Unfortunately, currently used cxt->io_size maybe overwritten in __discover_topology() to min_io_size. This patch introduces cxt->optimal_io_size and keeps it independent on cxt->io_size. The cxt->io_size is I/O size used by fdisk for alignment calculation. Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-06fdisk: fix compiler warning [-Wunused-variable]Karel Zak1-2/+3
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-06fdisk: fix compiler warning [-Wpointer-sign]Karel Zak1-3/+5
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-06fdisk: fix compiler warnings [-Wsign-compare]Karel Zak1-2/+2
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-06fdisk: remove user specified sector size global variableDavidlohr Bueso1-4/+2
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: add fdisk_dev_sectsz_is_default helperDavidlohr Bueso3-3/+16
Instead of printing this warning from the API, add a helper and call it from fdisk logic. Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: use EXIT_SUCCESS for -l optionDavidlohr Bueso1-1/+1
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: add total sectorsDavidlohr Bueso4-16/+26
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-06fdisk: add device topology to the APIDavidlohr Bueso10-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>
2012-06-06fdisk: sun: use sector_tDavidlohr Bueso1-1/+1
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: sgi: use sector_tDavidlohr Bueso1-2/+2
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: dos: use sector_tDavidlohr Bueso2-19/+15
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: introduce sector_t typeDavidlohr Bueso2-31/+31
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: remove useless commentsDavidlohr Bueso1-2/+2
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-06-06fdisk: use context as a parameterDavidlohr Bueso10-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>
2012-06-06fdisk: stop buffering welcome messageDavidlohr Bueso1-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>
2012-05-23fdisk: don't print welcome message to stderrKarel Zak1-1/+1
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-23fdisk: add readonly option to fdisk_new_context_from_filename()Karel Zak3-6/+13
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-23fdisk: always use stderr for debug messagesKarel Zak2-1/+11
* add dbgprint() to provide standardized debug output * print initial debug message to stderr Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-23fdisk: add debug supportDavidlohr Bueso3-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>
2012-05-23fdisk: introduce fdisk contextDavidlohr Bueso8-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>
2012-05-23fdisk: refactor -s optionDavidlohr Bueso1-19/+22
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-23fdisk: use BSD label headerDavidlohr Bueso3-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>
2012-05-23fdisk: remove bogus statementDavidlohr Bueso1-5/+4
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-23fdisk: add an quit/exit handling functionDavidlohr Bueso1-6/+9
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-15fdisk: cleanup strtoxx_or_err()Karel Zak3-11/+11
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-10libuuid: avoid double open and leaking fd (reworked)Petr Uzel1-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>
2012-05-10fdisk: sgi: abort on HDIO_GETGEO failureDavidlohr Bueso1-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>
2012-05-10fdisk: remove unused function declarationDavidlohr Bueso1-2/+0
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-10fdisk: create DOS specific write table functionDavidlohr Bueso3-23/+30
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-10fdisk: move DOS new/add partition codeDavidlohr Bueso4-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>
2012-05-10fdisk: remove unused hsc2sector macroDavidlohr Bueso1-2/+0
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-10fdisk: fix segfault on bsd labelDavidlohr Bueso3-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>
2012-05-04libuuid: avoid double open and leaking descriptorPetr Uzel1-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>
2012-05-02fdisk: fix fdiskdoslabel.c global variablesKarel Zak4-18/+25
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-02fdisk: isolate dos label logicDavidlohr Bueso5-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>
2012-05-02fdisk: remove dummy functionDavidlohr Bueso1-2/+0
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-05-02fdisk: rework fatal errorsDavidlohr Bueso2-15/+12
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-02fdisk: remove listing variableDavidlohr Bueso1-2/+0
useless global variable. Signed-off-by: Davidlohr Bueso <dave@gnu.org>