summaryrefslogtreecommitdiff
path: root/sbin/pdisk/partition_map.c
AgeCommit message (Collapse)Author
2016-02-01Un-shorten some lines that don't need breaking anymore. Remove a couple ofKenneth R Westerback
indent levels by shuffling code bit.
2016-01-31Nuke pointless map field 'physical_block' and just use 'sbBlkSize' which isKenneth R Westerback
set to the same value.
2016-01-31Use delete_entry()/create_entry() in delete_partition_from_map() instead ofKenneth R Westerback
trying to be clever and tweaking the existing entry into a free space entry by manual manipulation of the fields.
2016-01-31Fold add_data_to_map() into create_entry() as the former is always calledKenneth R Westerback
immediately after the latter, manipulating fields in the same structure. Use create_entry() in create_partition() rather than doing the same actions manually.
2016-01-31Don't use add_data_to_map() when reading from disk, since it resets someKenneth R Westerback
of the dpme_ fields, overwriting data from disk. Add some paranoia checks for map limits when reading from disk.
2016-01-31Just call contains_driver() when you need to know rather than carrying aKenneth R Westerback
flag around. More obviously current data. Nuke unnecessary variables when displaying a partition.
2016-01-31Apple sets lblock_start and lblocks to 0 in free space entries. DoKenneth R Westerback
the same. Don't use lblock_start or lblocks in calculation for length@base display. We no longer display lblock info there.
2016-01-30Move last three lines (#define's) from dpme.h to partition_map.h andKenneth R Westerback
tweak #include's as necessary.
2016-01-30Fold struct dpme into struct entry. Same reasons as for foldingKenneth R Westerback
struct block0 into struct partition_map. Easier to read code.
2016-01-30Refactor add_partition_to_map() to be simpler if perhaps lessKenneth R Westerback
performance optimized. New logic will simplify merging struct dpme into struct entry.
2016-01-30There is not much to do if we run out of memory, so simply exit ifKenneth R Westerback
a malloc() or calloc() fails. Simplifies a bunch of logic, makes add_data_to_map() always succeed or exit, so make it a void.
2016-01-29Fold struct block0 into struct partition map. There can be only oneKenneth R Westerback
and read/write_block0() can move the data from/to disk to/from appropriate fields anywhere. Removes a bunch of dereferencing, malloc'ing and pointer checking.
2016-01-29Warn of partitions extending past the end of the media.Kenneth R Westerback
2016-01-29Shorter names means a few whitespace adjustments.Kenneth R Westerback
2016-01-29Rename struct partition_map_header to struct partition_map. No change toKenneth R Westerback
.o files.
2016-01-29Rename struct partition_map to struct entry. No change to .o files.Kenneth R Westerback
2016-01-29Conform to Apple Mac OS X's behaviour of setting dpme_flags on freeKenneth R Westerback
partitions to 0, and setting them to VALID | ALLOCATED on the map partition.
2016-01-29Conform to Apple Mac OS X's behaviour of not giving 'Apple_Free'Kenneth R Westerback
partitions a name. Nuke kFreeName.
2016-01-28Flip base_order to a LIST().Kenneth R Westerback
2016-01-28Delete a bunch of Morris dancing in delete_partition_from_map().Kenneth R Westerback
No need to create a new dpme. Just rename/retype the existing and let combine_entry() suck in any surrounding empty space partitions.
2016-01-28Hand rolled lists suck. First, replace disk_order with an LIST.Kenneth R Westerback
2016-01-28Oops. Deleted one too many lines. Need to advance pointer when traversingKenneth R Westerback
list.
2016-01-28When adding a new partition to the map, use only existing mappedKenneth R Westerback
space. Don't try to create new free space partitions to use. If the map does not know about all of the space on the disk, it is broken.
2016-01-28Since we don't allow maps to be created or opened with an invalidKenneth R Westerback
block0, there is no point in checking later if block0 has magically become invalid.
2016-01-28Use consistent 'return' idiom -- no parenthesis since that was the styleKenneth R Westerback
of the existing code.
2016-01-28Make 'r' (reorder, a.k.a. swap) command work with any two existingKenneth R Westerback
partitions. Do NOT allow partition 1 to be moved!
2016-01-27Traverse next_by_base when checking maps coverage, not next_on_disk!Kenneth R Westerback
2016-01-27We do not support logical_block != physical_block. Remove logical_blockKenneth R Westerback
field and left over code that checks for logical != physical. Removes confusion with dmpe fields lblock_start and lblocks, which have nothing to do with block sizes! lblock_start is the block offset within the partition where the data actually starts. and lblocks is the number of blocks of data within the partition. Both are in units of *physical blocks*, a.k.a. disk sectors.
2016-01-27Check block 0 signature, physical block size and physical block count whenKenneth R Westerback
reading partition map. Check for unmapped physical blocks and overlapping partitions when reading partition map. No need for duplicate checks in validate_map(), so remove validate.c from build and 'v' command from code and docs.
2016-01-27Nuke another (and I hope final) batch of superfluous '{}' around singleKenneth R Westerback
statements.
2016-01-26dpme_name and dpme_type are NUL-terminated in Apple code, so useKenneth R Westerback
strlcpy() to fill them. They are also supposed to be NUL-padded so zap previous contents before copying in possibly shorter new values.
2016-01-26Whitespace, line wrapping fixes. Nuke many superfluous '{}' around singleKenneth R Westerback
statements. 0 -> NULL for pointer checks.
2016-01-26Whitespace, line wrapping fixes.Kenneth R Westerback
2016-01-26Simplify logic of read_partition_map(), junking retries with various sizesKenneth R Westerback
of logical block. Rely on read_dpme() to do the correct thing.
2016-01-25Use new read/write_block0 and read/write_dpme which handle anyKenneth R Westerback
endian or alignment issues forcefully. Removes need for convert_* functions so unhook convert.c from build. read/write_block become static functions inside file_media.c. Tweak struct block0 to stop trying to handle alignment issues by clever declaration. Rely on the new functions to accurately translate between on-disk and in-memory layouts. Enables pdisk to work on amd64 and likely other architectures if it's ever desirable. Does bring back DEV_BSIZE to pdisk.c since the in-memory structure will *not* be 512 bytes on other archs.
2016-01-24Whitespace.Kenneth R Westerback
2016-01-24Nuke get_align_long() and put_align_long() #define's. They don't doKenneth R Westerback
anything according to gcc & cmp. cmp suggested by & ok stefan@.
2016-01-24Whitespace fixes.Kenneth R Westerback
2016-01-24Delete duplicated line that was setting sbBlkCount to 0; Score oneKenneth R Westerback
for the 'v' command!
2016-01-23Nuke unused kPatchType. Nuke kStringNot and use " not' where needed.Kenneth R Westerback
Nuke kStringEmpty and use "" where needed. Nuke unused static 'g'. Eliminate #include's in *.h files. Some whitespace fixes.
2016-01-23Pass the disk sector size to open_partition_map(), eliminating it'sKenneth R Westerback
internal need for DEV_BSIZE. Ditto create_partition_map(). malloc((sizeof(struct [block0|dpme])) instead of malloc(DEV_BSIZE). Remove another #include <param.h>.
2016-01-23Add comments to ensure future spelunkers realize that struct block0Kenneth R Westerback
and struct dpme must be 512-bytes long at the moment. Use this fact to avoid using DEV_BSIZE and thus replace #include <param.h> with #include <types.h> in pdisk.c. Constrain media size to UINT32_MAX, the actual limit, instead of LONG_MAX, which could be way more on some theoretical future arch running pdisk. And do the constraint inside open_partition_map().
2016-01-23Avoid double prompt after creating default map on startup.Kenneth R Westerback
2016-01-23Flip read_block() and write_block() back to taking sector addressesKenneth R Westerback
instead of off_t values. Do the DEV_BSIZE multiplication in these two functions. Easier to read code and kills two #include <sys/param.h>. Kill unused label.
2016-01-23map->block0 is always allocated or the map is discarded.Kenneth R Westerback
So stop checking for NULL. Nuke get_block_zero() and just use map->block0.
2016-01-23Nuke sync_device_size() and do it's one-field-update in coerce_block0(),Kenneth R Westerback
right after we read/allocate media->block0. Doing sync *before* media->block0 is allocated is bad. The map->physical_block is initialized correctly and never to the magic number '1'. So just use map-physical_block to initialize sbBlkSize.
2016-01-23Always initialize media_size to provided mediasz in open_partition_map().Kenneth R Westerback
2016-01-23Break annoying long line.Kenneth R Westerback
2016-01-22Change partition map field 'data' to 'dmpe'. Change 'create_data'Kenneth R Westerback
to 'create_dmpe'. Sweep up some 'struct dpme *data' to struct dpme *dpme'.
2016-01-22Rename map field 'misc' to 'block0' since that's what it is.Kenneth R Westerback