summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/alignment.c
Commit message (Collapse)AuthorAgeFilesLines
* libfdisk: fix typosMarcos Mello2019-06-201-1/+1
|
* docs: fix typos [codespell]Sami Kerola2019-02-181-1/+1
| | | | | Reference: https://github.com/codespell-project/codespell Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libfdisk: accept grain script headerKarel Zak2018-09-121-0/+1
| | | | | | | | | | | | The "grain" variable is used to calculate partitions alignment. The default is 1MiB (or minimal I/O size). The libfdisk provides API to overwrite this default, but this feature has been nowhere accessible for end-user. This patch support for "grain: <size>" in libfdisk scripts. Addresses: https://github.com/karelzak/util-linux/issues/688 Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: improve alignment debug mesaggesKarel Zak2017-08-221-5/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_save_user_grain()Karel Zak2017-08-221-1/+40
| | | | | | | | | | | Let's provide API for applications that don't want to use the default 1MiB grain. The new function allow to use "as minimal as possible" if grain is set by fdisk_save_user_grain() to 512. If the phy sector size (or minimal I/O size) is greater than specified grain size than smallest possible setting is used. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: move fdisk_reread_partition_table() to another fileKarel Zak2017-07-141-40/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: don't print uninitialized variable [coverity scan]Karel Zak2017-05-171-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix some printf format stringsRuediger Meier2017-04-101-1/+1
| | | | | | | | | | | Fix compiler warnings seen on Linux/i586 and OSX/travis. #type #format #cast unsigned long %lu - uint64_t PRIu64 - fdisk_sector_t %ju (uintmax_t) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* sfdisk: --quiet fixesKarel Zak2017-02-101-0/+1
| | | | | Addresses: https://github.com/karelzak/util-linux/issues/412 Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: apply label alignment propertiesKarel Zak2017-01-161-2/+15
| | | | | | This fix changes from the previous patches. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: change the way how apply user device propertiesKarel Zak2017-01-131-5/+7
| | | | | | | | | | | | | | | | 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>
* libfdisk: recount size when apply user device propertiesKarel Zak2017-01-131-1/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: don't use blkdev ioctls for regular filesKarel Zak2017-01-131-8/+19
| | | | | | | | | | | | | $ fdisk <diskimage> open("sdc.img", O_RDONLY|O_CLOEXEC) = 3 ioctl(3, BLKSSZGET, 0x7ffcf51357c4) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, BLKGETSIZE64, 0x7ffcf51357b0) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, BLKGETSIZE, 0x7ffcf51356c8) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, FDGETPRM, 0x7ffcf51356d0) = -1 ENOTTY (Inappropriate ioctl for device) ioctl(3, HDIO_GETGEO, 0x7ffcf5135790) = -1 ENOTTY (Inappropriate ioctl for device) Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-7/+7
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* misc: fix printf i386 compiler warningsRuediger Meier2016-03-121-1/+1
| | | | | | | | | | | | | | | 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>
* misc: again fixing many printf format stringsRuediger Meier2016-03-071-1/+1
| | | | | | | | | | | | | | | | | | | This is again a huge patch regarding printf format strings to fix compiler warnings seen on clang/OSX. I'm trying to follow these rules strictly: #type #format #cast uintmax_t %ju - intmax_t %jd - uint64_t PRIu64 - int64_t PRId64 - size_t %zu - ssize_t %zd - ino_t %ju (uintmax_t) off_t %jd (intmax_t) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* libfdisk: ignore misaligned optimal I/O sizeKarel Zak2015-06-181-3/+12
| | | | | | | | | | | | | | | | | | 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>
* libfdisk: support alignment to non power of 2Karel Zak2015-06-081-7/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* libfdisk: cleanup gtk-docs warningsKarel Zak2015-01-131-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: rename sector_t to fdisk_sector_tKarel Zak2014-12-041-16/+16
| | | | | | .. just to avoid too generic names for public API. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: fix cfdisk freespace analyzeKarel Zak2014-12-041-0/+4
| | | | | | | | | 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>
* libfdisk: add API docsKarel Zak2014-11-261-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* agetty: fix typoKarel Zak2014-11-211-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add more commentsKarel Zak2014-10-161-12/+58
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: (gpt) don't align last possible LBAKarel Zak2014-09-011-3/+13
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: more docsKarel Zak2014-08-141-0/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: clean up API (alignment.c)Karel Zak2014-08-131-14/+63
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: clean up API (context.c)Karel Zak2014-08-131-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: always print warning for mis-aligned partitionsKarel Zak2014-08-081-1/+1
| | | | | | | This patch restores the original fdisk behavior and always prints information about misaligned partitions in 'p'print output. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: make first sector buffer usage more robustKarel Zak2014-07-141-2/+3
| | | | | | | | | | | | $ ~/util-linux/fdisk -b 4096 xxx .. Segmentation fault The buffer has to be reinitialized always when we apply a new device properties (e.g. sector size). Reported-by: Bernhard Voelker <mail@bernhard-voelker.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: clean up debug outputKarel Zak2014-03-211-16/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: use new debug functionsKarel Zak2014-03-211-16/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: initialize last_lbaKarel Zak2014-03-111-2/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: improve fdisk_save_user_geometry()Karel Zak2013-09-251-4/+9
| | | | | | | The functions should not overwrite old setting if the new value (C/H/S) is zero. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: fix cylinders and sector buffer usageKarel Zak2013-09-181-0/+6
| | | | | | | - sector buffer has to be correctly deallocated - round to cylinders when use cylinder units in dos driver Signed-off-by: Karel Zak <kzak@redhat.com>
* fdisk: remove unused code, coding style changesKarel Zak2013-09-161-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: make default geom usage more robustKarel Zak2013-09-161-10/+8Star
| | | | | | | .. to avoid SIGFPE References: https://bugzilla.redhat.com/show_bug.cgi?id=1005566 Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_has_user_device_properties()Karel Zak2013-09-161-0/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: move sync() and reread PT code from fdisk to libfdiskKarel Zak2013-09-161-0/+32
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: make it possible to reset device propertiesKarel Zak2013-09-161-33/+131
| | | | | | | | | | | | | | | | - remember user C/H/S and sector size - reset all device properties before create a new label (maybe the old setting has been affected by previous on-disk label) - always apply user setting after the reset - improve topology/geometry debug messages Note that for fdisk "user C/H/S and sector size" means on command line specified values. If you override the setting by c/h/s commands in expert menu then the setting is applied to the current disk label only. If you create a new disk label (e.g change MBR to GPT) then fdisk will use the original setting. Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_scround()Karel Zak2013-09-161-0/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* various: fix variable and function declarations [smatch scan]Sami Kerola2013-04-091-2/+3
| | | | | | | | | | | | | | | | | disk-utils/fsck.minix.c:511:9: warning: mixing declarations and code fdisks/sfdisk.c:982:5: warning: mixing declarations and code fdisks/sfdisk.c:1254:5: warning: mixing declarations and code fdisks/sfdisk.c:1564:5: warning: mixing declarations and code lib/mbsalign.c:279:7: warning: mixing declarations and code libblkid/src/devname.c:378:17: warning: mixing declarations and code libfdisk/src/alignment.c:219:9: warning: mixing declarations and code term-utils/wall.c:111:9: warning: mixing declarations and code text-utils/col.c:418:19: warning: non-ANSI function declaration of function 'flush_blanks' text-utils/col.c:553:12: warning: non-ANSI function declaration of function 'alloc_line' text-utils/rev.c:105:9: warning: mixing declarations and code text-utils/tailf.c:245:9: warning: mixing declarations and code Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* fdisk: remove fdisk_label from API functions, add asserts, use size_tKarel Zak2013-03-111-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_label to driver APIKarel Zak2013-03-111-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_new_context(), reuse contextKarel Zak2013-03-111-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: split label and label operationsKarel Zak2013-03-111-2/+2
| | | | | | | | | | | | | | | | | | | | | Changes: - fdisk_label is a private label driver struct - generic header of the fdisk_label points to fdisk_label_operations - the private fdisk_label stuff is always allocated for all drivers during fdisk_context initialization - context->labels[] contains pointers to all supported labels (drivers) - context->label is a pointer to the currently used label This change allows to: - store label specific global settings (e.g. dos compatible mode, display units, ...) independently on the current label - add label specific function to the API Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add fdisk_reset_alignment()Karel Zak2013-03-111-3/+31
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add topology and geometry functionsKarel Zak2013-03-111-0/+251
| | | | | | | | | | - rename __discovery_* to fdisk_discovery_* - rename fdisk_context_force_sector_size() to fdisk_override_sector_size() - rename fdisk_context_set_user_geometry() to fdisk_override_geometry() - remove non-default sector size warning Signed-off-by: Karel Zak <kzak@redhat.com>
* libfdisk: add alignment codeKarel Zak2013-03-111-0/+101
Signed-off-by: Karel Zak <kzak@redhat.com>