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); |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 47 | if (!data) { |
| 48 | if (errno) |
| 49 | return -errno; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 50 | goto nothing; |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 51 | } |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 52 | |
| 53 | l = (struct ultrix_disklabel *) (data + ULTRIX_OFFSET); |
| 54 | |
| 55 | if (l->pt_magic != ULTRIX_MAGIC || l->pt_valid != 1) |
| 56 | goto nothing; |
| 57 | |
| 58 | if (blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET, |
| 59 | sizeof(ULTRIX_MAGIC_STR) - 1, |
| 60 | (unsigned char *) ULTRIX_MAGIC_STR)) |
| 61 | goto err; |
| 62 | |
| 63 | if (blkid_partitions_need_typeonly(pr)) |
| 64 | /* caller does not ask for details about partitions */ |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 65 | return BLKID_PROBE_OK; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 66 | |
| 67 | ls = blkid_probe_get_partlist(pr); |
| 68 | if (!ls) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 69 | goto nothing; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 70 | |
| 71 | tab = blkid_partlist_new_parttable(ls, "ultrix", 0); |
| 72 | if (!tab) |
| 73 | goto err; |
| 74 | |
| 75 | for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) { |
| 76 | if (!l->pt_part[i].pi_nblocks) |
| 77 | blkid_partlist_increment_partno(ls); |
| 78 | else { |
| 79 | if (!blkid_partlist_add_partition(ls, tab, |
| 80 | l->pt_part[i].pi_blkoff, |
| 81 | l->pt_part[i].pi_nblocks)) |
| 82 | goto err; |
| 83 | } |
| 84 | } |
| 85 | |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 86 | return BLKID_PROBE_OK; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 87 | nothing: |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 88 | return BLKID_PROBE_NONE; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 89 | err: |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 90 | return -ENOMEM; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | const struct blkid_idinfo ultrix_pt_idinfo = |
| 94 | { |
| 95 | .name = "ultrix", |
| 96 | .probefunc = probe_ultrix_pt, |
| 97 | .magics = BLKID_NONE_MAGIC |
| 98 | }; |
| 99 | |