diff options
author | marcel <marcel@FreeBSD.org> | 2002-10-27 03:23:05 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2002-10-27 03:23:05 +0000 |
commit | 533c9e097154395bf0644b81f7c3f14953d56176 (patch) | |
tree | bb533945621b7c18ab431e6fe7b390ef9a32170c /sbin/gpt/map.c | |
parent | 9316f3838a06082b0d11dc4de03d67ee1e123738 (diff) | |
download | FreeBSD-src-533c9e097154395bf0644b81f7c3f14953d56176.zip FreeBSD-src-533c9e097154395bf0644b81f7c3f14953d56176.tar.gz |
o Add functionality to add a GPT partition,
o Use DCE compliant UUID functions and provide local
implementations if they don't exist,
o Move dumping of the map to show.c and print the
partition type,
o Some cleanups and rearrangements.
The default GPT partition type is UFS. When no starting block
or size are specified, the tool will create a partition in the
first free space it find (or that fits, depending on the size).
Diffstat (limited to 'sbin/gpt/map.c')
-rw-r--r-- | sbin/gpt/map.c | 77 |
1 files changed, 28 insertions, 49 deletions
diff --git a/sbin/gpt/map.c b/sbin/gpt/map.c index 5aba63c..fbce87f 100644 --- a/sbin/gpt/map.c +++ b/sbin/gpt/map.c @@ -33,7 +33,8 @@ #include "map.h" -static int lbawidth; +int lbawidth; + static map_t *mediamap; static map_t * @@ -133,6 +134,31 @@ map_add(off_t start, off_t size, int type, void *data) } map_t * +map_alloc(off_t start, off_t size) +{ + off_t delta; + map_t *m; + + for (m = mediamap; m != NULL; m = m->map_next) { + if (m->map_type != MAP_TYPE_UNUSED || m->map_start < 2) + continue; + if (start != 0 && m->map_start > start) + return (NULL); + delta = (start != 0) ? start - m->map_start : 0; + if (size == 0 || m->map_size - delta >= size) { + if (m->map_size - delta <= 0) + continue; + if (size == 0) + size = m->map_size - delta; + return (map_add(m->map_start + delta, size, + MAP_TYPE_GPT_PART, NULL)); + } + } + + return (NULL); +} + +map_t * map_find(int type) { map_t *m; @@ -161,7 +187,7 @@ map_last(void) } off_t -map_unused(off_t start, off_t size) +map_free(off_t start, off_t size) { map_t *m; @@ -177,53 +203,6 @@ map_unused(off_t start, off_t size) } void -map_dump(void) -{ - off_t end; - map_t *m; - - printf(" %*s", lbawidth, "start"); - printf(" %*s", lbawidth, "end"); - printf(" %*s", lbawidth, "size"); - printf(" %s\n", "contents"); - - m = mediamap; - while (m != NULL) { - end = m->map_start + m->map_size - 1; - printf(" %*llu", lbawidth, (long long)m->map_start); - printf(" %*llu", lbawidth, (long long)end); - printf(" %*llu", lbawidth, (long long)m->map_size); - - putchar(' '); putchar(' '); - switch (m->map_type) { - case MAP_TYPE_MBR: - printf("MBR"); - break; - case MAP_TYPE_PRI_GPT_HDR: - printf("Pri GPT header"); - break; - case MAP_TYPE_SEC_GPT_HDR: - printf("Sec GPT header"); - break; - case MAP_TYPE_PRI_GPT_TBL: - printf("Pri GPT table"); - break; - case MAP_TYPE_SEC_GPT_TBL: - printf("Sec GPT table"); - break; - case MAP_TYPE_MBR_PART: - printf("MBR partition"); - break; - case MAP_TYPE_GPT_PART: - printf("GPT partition"); - break; - } - putchar('\n'); - m = m->map_next; - } -} - -void map_init(off_t size) { char buf[32]; |