bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 1 | /* |
| 2 | * uktrix partition parsing code |
| 3 | * |
| 4 | * Copyright (C) 2010 Karel Zak <kzak@redhat.com> |
| 5 | * |
| 6 | * This file may be redistributed under the terms of the |
| 7 | * GNU Lesser General Public License. |
| 8 | * |
| 9 | */ |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <stdint.h> |
| 14 | |
| 15 | #include "partitions.h" |
| 16 | |
| 17 | #define ULTRIX_MAXPARTITIONS 8 |
| 18 | |
| 19 | #define ULTRIX_MAGIC 0x032957 |
| 20 | #define ULTRIX_MAGIC_STR "\x02\x29\x57" |
| 21 | |
| 22 | /* sector with partition table */ |
| 23 | #define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9) |
| 24 | /* position of partition table within ULTRIX_SECTOR */ |
| 25 | #define ULTRIX_OFFSET (512 - sizeof(struct ultrix_disklabel)) |
| 26 | |
| 27 | struct ultrix_disklabel { |
| 28 | int32_t pt_magic; /* magic no. indicating part. info exits */ |
| 29 | int32_t pt_valid; /* set by driver if pt is current */ |
| 30 | struct pt_info { |
| 31 | int32_t pi_nblocks; /* no. of sectors */ |
| 32 | uint32_t pi_blkoff; /* block offset for start */ |
| 33 | } pt_part[ULTRIX_MAXPARTITIONS]; |
| 34 | } __attribute__((packed)); |
| 35 | |
| 36 | |
| 37 | static int probe_ultrix_pt(blkid_probe pr, |
| 38 | const struct blkid_idmag *mag __attribute__((__unused__))) |
| 39 | { |
| 40 | unsigned char *data; |
| 41 | struct ultrix_disklabel *l; |
| 42 | blkid_parttable tab = NULL; |
| 43 | blkid_partlist ls; |
| 44 | int i; |
| 45 | |
| 46 | data = blkid_probe_get_sector(pr, ULTRIX_SECTOR); |
| 47 | if (!data) |
| 48 | goto nothing; |
| 49 | |
| 50 | l = (struct ultrix_disklabel *) (data + ULTRIX_OFFSET); |
| 51 | |
| 52 | if (l->pt_magic != ULTRIX_MAGIC || l->pt_valid != 1) |
| 53 | goto nothing; |
| 54 | |
| 55 | if (blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET, |
| 56 | sizeof(ULTRIX_MAGIC_STR) - 1, |
| 57 | (unsigned char *) ULTRIX_MAGIC_STR)) |
| 58 | goto err; |
| 59 | |
| 60 | if (blkid_partitions_need_typeonly(pr)) |
| 61 | /* caller does not ask for details about partitions */ |
| 62 | return 0; |
| 63 | |
| 64 | ls = blkid_probe_get_partlist(pr); |
| 65 | if (!ls) |
| 66 | goto err; |
| 67 | |
| 68 | tab = blkid_partlist_new_parttable(ls, "ultrix", 0); |
| 69 | if (!tab) |
| 70 | goto err; |
| 71 | |
| 72 | for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) { |
| 73 | if (!l->pt_part[i].pi_nblocks) |
| 74 | blkid_partlist_increment_partno(ls); |
| 75 | else { |
| 76 | if (!blkid_partlist_add_partition(ls, tab, |
| 77 | l->pt_part[i].pi_blkoff, |
| 78 | l->pt_part[i].pi_nblocks)) |
| 79 | goto err; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | nothing: |
| 85 | return 1; |
| 86 | err: |
| 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | const struct blkid_idinfo ultrix_pt_idinfo = |
| 91 | { |
| 92 | .name = "ultrix", |
| 93 | .probefunc = probe_ultrix_pt, |
| 94 | .magics = BLKID_NONE_MAGIC |
| 95 | }; |
| 96 | |