Commit Graph

44 Commits

Author SHA1 Message Date
marcel
76165e705c Use :- and not :! for pipes. ! needs to be escaped, which adds to the
hassle.
2014-03-28 04:42:34 +00:00
marcel
533cda2b92 Write verbosity to stderr. The image may be written to stdout.
While here, fix writing to stderr, by not calling errc()
unconditionally, but only when there's an error.
2014-03-28 04:14:40 +00:00
marcel
4cf1c78a43 Write sparse files by default (when SPARSE_FILE is defined).
While here, detect errors when writing to stdout.
2014-03-28 01:55:02 +00:00
marcel
ba63787689 Partitions start on cylinder boundaries. 2014-03-28 01:52:48 +00:00
marcel
fe7be9e673 Partitions start on track boundaries. 2014-03-28 01:51:45 +00:00
marcel
36046d28b3 Partitions start on track boundaries. 2014-03-28 01:50:56 +00:00
marcel
b7c3be9e45 Remove the -z flag. Let's just write a sparse file whenever we can. 2014-03-27 23:44:16 +00:00
marcel
c4d8b579ba Properly fill in d_nsectors, d_ntracks, d_ncylinders & d_secpercyl.
Round the image size to a multiple of the cyclinder size.
2014-03-27 23:16:18 +00:00
marcel
da0f041a0e Remember operator precedence? 2014-03-27 23:15:07 +00:00
marcel
452aa44886 Give vtoc8 a change to work: when setting the physical block size to 4K,
sectors/track to 8 and number or heads to 1, partitions that are block
aligned are also cyclinder aligned. With that trick, fix the vtoc8:
1.  Set physcyls, ncyls, altcyls, nheads and nsecs appropriately.
2.  Truncate the image size to exactly ncyls * nheads * nsecs * secsz.
3.  Properly write the cylinder number as the start of the partition.
4.  Oh, and actually calculate the checksum of the label...
2014-03-27 22:48:48 +00:00
marcel
bfd31b94a3 1. When calculating block addresses, round to the physical block
size.
2.  Replace scheme_first_block() & scheme_next_block() with
    scheme_metadata(). When we round to block sizes, we can't
    reliably fixup any miscalculations.
3.  In scheme_write, calculate ncyls (number of cyclinders), based
    on the total size, sectors/track and number of heads.
4.  Add verbosity when constructing the partitions. This includes
    the starting block address and size in bytes and blocks.
5.  Add verbosity about the sectors/track and number of heads.
2014-03-27 22:45:05 +00:00
marcel
5d04a4dffc Remove trksz, which was hardcoded to 1, and replace it by secs, which
can be set on the command line.
2014-03-27 22:39:22 +00:00
marcel
a349124060 Fix writing the start and size fields. 2014-03-27 21:32:02 +00:00
marcel
6084642f6d 1. Add -v option to increase vebosity levels
2.  Fix copy-paste bug -- acrually check secsz for being a power of 2
3.  Check secsz and blksz parameters
4.  Print the sector and block size when -v is given
2014-03-27 20:14:40 +00:00
marcel
e7f6c0c88b Add scheme_max_secsz() for returning the maximum sector size supported
by the partitioning scheme.
2014-03-27 20:10:26 +00:00
marcel
0a263459f5 First batch of media control:
1.  Change -h to -H and change -t to -T. Use -H to specify the number of
    heads and -T to specify the track size (number of sectors per track).
2.  Add -S and -P. Use -S to specify the logical sector size and -P to
    specify the physical sector size.

Default to 512 for both the logical and physical sector size.
Set nheads and nsecs to 1 by default.
2014-03-25 04:45:55 +00:00
marcel
572e125f42 Move setting CHS fields to mbr_chs() in preparation of ... 2014-03-25 03:58:13 +00:00
marcel
cedbce4789 Allow schemes to specify a maximum sector size. The minimum is fixed
at 512. This allows checking of the sector size up-front when given
on the command line.
2014-03-25 02:32:04 +00:00
marcel
4eff23dbe8 Mostly implement the vtoc8 scheme. The vtoc8 scheme uses cylinders for
the beginning of partitions, which makes it sensitive to geometry.
Again, we'll need to revisit this.
2014-03-25 02:15:19 +00:00
marcel
71584f05df Mostly implement the pc98 scheme. The partition table has no LBA
fields at all, so we're entirely dependent upon CHS addressing.
And CHS addressing is what needs more work.
2014-03-25 00:29:56 +00:00
marcel
1d6c278537 Implement the EBR scheme. Use a function for filling in the CHS fields.
For now, put 0xff in each field. This needs to be revisited when we
have proper geometry. Note that even without proper CHS values, it's
already accepted by the kernel.
2014-03-23 20:17:38 +00:00
marcel
beed2ec1e7 Add support for the fat32 and ebr aliases. 2014-03-23 20:15:21 +00:00
marcel
b64030a756 Add the fat32 and ebr aliases. The ebr alias is needed to support
the EBR scheme, as it can only live inside a MBR partition of type
5 (= DOSPTYP_EXT).
2014-03-23 20:14:49 +00:00
marcel
0c6234c0ae Implement the BSD scheme. This doesn't quite work as geom_part_bsd
finds an invalid label. I'm not going to worry about that right now,
because there's more to worry about: the BSD disk label has the 'c'
partition for the entire disk and we don't handle this at all.
Note also that the BSD disk label wants a geometry, so this will
have to be revisited anyway once a good solution is in place.
2014-03-23 19:22:13 +00:00
marcel
c9139def6c Implement the APM scheme. 2014-03-23 04:21:56 +00:00
marcel
cb6a9cd9ee And the magic number is... necessary. 2014-03-23 01:17:02 +00:00
marcel
3cd87458c0 Revamp:
1.  Make secsz globally visible.
2.  Have all code use the global secsz and nparts, rather than passing
    them around.
3.  Introduce lba_t as the type to use when talking about block addresses.
4.  Work on LBAs instead of offsets. There's just too much division with
    the sector size and there's really no value to use by offsets other
    than that is what lseek() wants. For that we now have mkimg_seek().

The bigger picture is that geometry (cylinders, heads, sectors/track) and
also a possible physical sector size are to be globals that can be used
from anyway. We really don't want to pass all that stuff as arguments to
functions and then add __unused for most of them...
2014-03-23 01:10:05 +00:00
marcel
6cd83f8d68 Flesh-out MBR support. The CHS fields need more thought/work... 2014-03-22 23:34:35 +00:00
marcel
d449c3f144 Handle the -b option for specifying boot code that lives in the
partitioning scheme's meta data. Implement it for GPT.
2014-03-21 19:40:05 +00:00
marcel
ace52aef3d Add more partition types (mostly just the FreeBSD ones) to GPT.
Avoid having schemes use literal strings by introducing an enum
as the intermediate representation (see geom_part).
2014-03-21 16:11:49 +00:00
marcel
8ff772ab00 Update usage for label support. 2014-03-21 05:37:25 +00:00
marcel
ee34aed1b5 Add support for partition labels and write them for GPT. 2014-03-21 05:30:27 +00:00
marcel
8e3f9b93d7 Make this work on big-endian architectures by adding encoding. 2014-03-21 04:52:46 +00:00
marcel
d8d97191a5 Fix writing GPT:
1.  Fix copy-paste bug that resulted in not sizing the image correctly
    for the secondary header and table.
2.  The hdr_lba_end field in the header is the LBA of the last usable
    sector, not the one after it.

While here, fix a white-space nit.
2014-03-21 04:14:26 +00:00
marcel
edfa576ac7 Dump my WIP of write support for GPT. This compiles, appears to be
complete, but isn't accepted by g_part_gpt. Time to debug and fix.
2014-03-21 03:27:42 +00:00
marcel
0dddaf6f49 Add a scheme-specific write callback to write the metadata.
While here:
1.  Move FreeBSD-specific headers to a more centralized place, so that
    it's easier to port mkimg.
2.  Remove inclusion of <uuid.h> where we don't need it (copy-pasted).
3.  Check the partition data given on the command line before we do any
    I/O.
4.  Add scheme_round() for rounding the partition size.
5.  Have scheme_write call the scheme-specific write callback and have
    it propagate errors back to the caller.
2014-03-20 20:14:26 +00:00
marcel
3f2295fee5 Replace *_get_leader() and *_get_trailer() with a single *_metadata().
This single function takes a where argument to indicate the kind of
metadata to "size". This way we can also get rid of the "padding"
field in the scheme structure.
This should make it a little more understandable what's going on.
2014-03-20 19:37:30 +00:00
marcel
5f39eb99a0 Check the partition type alias as defined by the scheme. 2014-03-20 02:27:25 +00:00
marcel
7f983a3b38 Use linker sets to provide build-time selection of the schemes
that need to be supported. Each scheme provides data and callbacks
for handling the scheme-specifics.
To this end, put each scheme in its own source file.
2014-03-20 00:38:17 +00:00
marcel
48a229f1cf Expand usage(). This serves even now as a good reminder. 2014-03-19 22:27:10 +00:00
marcel
cf8b12efb7 Add mkimg.h. It contains the 'part' structure definition and the linked
list (STAILQ) so that it can be shared and re-used in all source files.
Replace the now unneeded scheme_add_part() with scheme_check_part() for
posterity.

Also (should have been a separate commit), remove the enforcement of
creating a GPT table with at least 128 entries. While this is generally
advised as the default or minimum, it's not actually a hard requirement.
We now recreate a table that's precisely enough (rounded of course).

WHile
2014-03-19 21:44:51 +00:00
marcel
72e40274dc Set BINDIR & WARNS while we're outside the source tree. 2014-03-19 21:37:44 +00:00
marcel
6947c304c9 Now that we can include <sys/diskpc98.h> and <sys/diskmbr.h> at
the same time withiut conflict, use the constants defined in them.
2013-08-09 19:20:46 +00:00
marcel
20dbae1acc Safe WIP: mkimg is a user-space utility for creating disk images.
In its current form and shape, it creates images with the correct
partition contents and overall image layout. What it doesn't do
yet is actually scribble the metadata, such as partition tables
and boot code. This is where I'd like to leverage code from other
places, such as geom_part, and if possible/feasible.
Also, the utility should be a little bit smarter about files and
pipes so that we create temporary files only when needed (e.g.
when we don't know the size of a partition's contents in advance
while wrting the image to stdout).
2013-08-04 02:37:05 +00:00