summaryrefslogtreecommitdiffstats
path: root/sbin/pdisk/pdisk.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Remove all the pledge "disklabel" before ioctl DIOCGPDINFO istb2016-05-281-11/+1
| | | | | | | called in order to avoid a pledge crash with 'pdisk /dev/tty'. Only the pledge "stdio" right after the ioctl remains. ok krw
* Tweak command line processing vs pledge logic to make things nicer. Nokrw2016-04-271-4/+6
| | | | | | functional change. Prodded (a while ago) and ok (recently) deraadt@
* Accept only character special devices rather than generating a corekrw2016-03-091-4/+3
| | | | | | | | | | | | dump on the attempt to get a disklabel from a regular file. Regular files have not been acceptable as the 'disk' for some time, and pledging changed the consequences from a somewhat obscure error message to an abort(). Issue discovered by espie@. ok natano@
* Pledge, based on what's done in fdisk.krw2016-02-021-2/+18
|
* Nuke pointless map field 'physical_block' and just use 'sbBlkSize' which iskrw2016-01-311-3/+3
| | | | set to the same value.
* Move last three lines (#define's) from dpme.h to partition_map.h andkrw2016-01-301-3/+2
| | | | tweak #include's as necessary.
* Fold struct dpme into struct entry. Same reasons as for foldingkrw2016-01-301-9/+9
| | | | struct block0 into struct partition_map. Easier to read code.
* Add do_dump_map() to make command processing more consistent. Passkrw2016-01-291-3/+12
| | | | | 1/0 (a.k.a. vverbose/not verbose) do do_dump_map() to differentiate P/p.
* Rename struct partition_map_header to struct partition_map. No change tokrw2016-01-291-31/+31
| | | | .o files.
* Hand rolled lists suck. First, replace disk_order with an LIST.krw2016-01-281-1/+2
|
* Tweak verbiage for 'r' (reorder) command.krw2016-01-281-2/+3
|
* Tweak some verbiage.krw2016-01-271-5/+5
|
* On-disk partition name/types/processorid may or may not be NULkrw2016-01-271-3/+3
| | | | | terminated after all. So add an extra byte for a NUL in the in-memory struct's.
* We do not support logical_block != physical_block. Remove logical_blockkrw2016-01-271-2/+2
| | | | | | | | | | 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.
* Check block 0 signature, physical block size and physical block count whenkrw2016-01-271-6/+1
| | | | | | | | | | 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.
* Rework and simplify string argument parsing. All string arguments are atkrw2016-01-261-48/+54
| | | | | | | | | | | | | most DPISTRLEN (32) characters so there is no need for fancy dynamic growing strings. Use a DPISTRLEN long buffer and bail if it fills up. Rename get_string() to get_dpistr() and get_string_argument() to get_dpstr_argument() to emphasize they will return strings that fit in DPISTRLEN. Rework & simplify a pair of their consumers - do_rename_partition() and do_change_type() - to be more obviously identitical to each other bar the displayed verbiage.
* dpme_name and dpme_type are NUL-terminated in Apple code, so usekrw2016-01-261-3/+13
| | | | | | | strlcpy() to fill them. They are also supposed to be NUL-padded so zap previous contents before copying in possibly shorter new values.
* Whitespace, line wrapping fixes. Nuke many superfluous '{}' around singlekrw2016-01-261-8/+6
| | | | statements. 0 -> NULL for pointer checks.
* Use new read/write_block0 and read/write_dpme which handle anykrw2016-01-251-13/+4
| | | | | | | | | | | | | | 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.
* remove some uneeded includesjsg2016-01-251-2/+1
| | | | ok krw@
* Nuke more pointless checks for map NULLness.krw2016-01-241-25/+1
|
* Whitespace fixes.krw2016-01-241-24/+24
|
* Nuke unused kPatchType. Nuke kStringNot and use " not' where needed.krw2016-01-231-1/+2
| | | | | | | | Nuke kStringEmpty and use "" where needed. Nuke unused static 'g'. Eliminate #include's in *.h files. Some whitespace fixes.
* No need for 'default_value' parameter for get_number_argument() since wekrw2016-01-231-11/+10
| | | | | | always pass kDefault. a.k.a. -1. Nuke kDefault since it is now unused. Nuke unused #define MAXIOSIZE in passing.
* No need for get_string_argument() parameter 'reprompt' since wekrw2016-01-231-5/+5
| | | | always pass it '1'.
* Pass the disk sector size to open_partition_map(), eliminating it'skrw2016-01-231-3/+4
| | | | | | | | internal need for DEV_BSIZE. Ditto create_partition_map(). malloc((sizeof(struct [block0|dpme])) instead of malloc(DEV_BSIZE). Remove another #include <param.h>.
* Add comments to ensure future spelunkers realize that struct block0krw2016-01-231-18/+13
| | | | | | | | | | | 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().
* Change partition map field 'data' to 'dmpe'. Change 'create_data'krw2016-01-221-7/+7
| | | | | to 'create_dmpe'. Sweep up some 'struct dpme *data' to struct dpme *dpme'.
* Repair creation of initial partition table on a blank disk, brokenkrw2016-01-221-12/+9
| | | | | | when hoisting file operations and ioctl to main(). Pass media size to open_partition_map() and create_partition_map() so they can properly initialize a map.
* In the "why use two variables when one would do" category, eliminatekrw2016-01-221-3/+2
| | | | | the 'written' field and just use the 'changed' field to mediate when it is appropriate to ask whether changes should be discarded.
* Nuke 'expert' mode and the enabling, undocumented, '-d' flag bykrw2016-01-221-139/+41
| | | | | | | | | | | | | | | just making all the commands available all the time. Document the newly available commands. Remove the former 'P' command (list partitions in base address order) and use 'P' from expert mode (show map data structures). Stop accepting uppercase aliases for commands documented as lower case. Bring the 'h' help text and man pages into agreement. ok jasper@ millert@
* Hoist all file opening and ioctl calls into main(), passing a pointer tokrw2016-01-211-41/+64
| | | | | | | | | | | | a valid map to edit(). Should enable pledging a la fdisk at some point. Since edit() always gets a valid map (and maintains its validity even when 'I'nitializing a new one) many checks for (map == NULL) are junked. Remove some dances around block sizes by using DEV_BSIZE everywhere since we don't support non-DEV_BSIZE (a.k.a. 512-byte) sectors. Remove many superfluous #include statements.
* Nuke 'writable' field now that it is always in sync with 'rflag'. Sincekrw2016-01-211-28/+4
| | | | | | | (!rflag && writable == 0) can't be true remove those warning blocks and simply leave the not-writable warning when attempting to write the map. Always show 'w' in the help and rely on the check and warning in do_write_partition_map() so the user always gets a message.
* Simplify the main command switch, eliminating a couple of /* fallkrw2016-01-191-10/+8
| | | | | through */ and two variables by simply calling the target functions with the different parameters.
* It's pointless to check for 'dflag' inside do_expert(), since you can'tkrw2016-01-191-10/+4
| | | | get there unless dflag is set. Makes switch() statement easier to grasp.
* Remove forward declarations for functions that do not exist.krw2016-01-191-2/+1
|
* Bring code into line with man page and usage() by only allowing onekrw2016-01-191-16/+15
| | | | | disk to be specified on the command line. Nuke dump() function and hoist its few lines into main() as a result.
* No need for pdisk(8) to provide a version of hexdump. Removekrw2016-01-191-73/+1
| | | | | | the "expert" mode 'd'/'D' command and its supporting code. ok deraadt@ jasper@
* The contents of the Apple_Patches partition is none of our business.krw2016-01-181-24/+1
| | | | | | | | Stop pretending we care or know what's in there. Remove 'debugging' mode command to examine the partition contents and the supporting code. ok deraadt@ jasper@
* struct file_media had 1 field left. And one place where structkrw2016-01-181-8/+7
| | | | | | | | | | file_media was actually stored. So move the last field (fd) into the place formerly used to store pointer to the instance. As a result we can just pass fd's around rather than pointers to a struct containing a fd. close_file_media() becomes empty but for a close(). So just use close() and nuke close_file_media().
* Run indent(1) over it and tweak the results a bit manually to look morekrw2016-01-181-581/+573
| | | | KNF'ish.
* Fold get_options() into main() and eliminate unneeded nFLAG_DEFAULTkrw2016-01-181-44/+23
| | | | #defines. Zero is a well known and acceptable number.
* Remove a grab bag of unused #define's, fields, enum's, variables,krw2016-01-181-11/+1
| | | | functions.
* Change "//" comments to "/**/". Nuke really stupid ones.krw2016-01-171-23/+20
|
* Reduce namespace pollution by eliminating parameter names from forwardkrw2016-01-171-17/+17
| | | | declarations.
* Kill leading, imbedded, trailing whitespace.krw2016-01-171-9/+9
|
* Remove a bunch of ridiculous and uninformative comments like "// Defines".krw2016-01-171-31/+1
|
* The great de-typedef'ification continues.krw2016-01-171-34/+34
| | | | | partition_map -> struct partition_map partition_map_header -> struct partition_map_header
* The great de-typedef'ification continues. Block0 -> struct block0.krw2016-01-171-3/+3
|
* The great de-typedef'ification continues. DPME -> struct dpme.krw2016-01-171-3/+3
|