Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 2 | /* |
| 3 | * fs/partitions/sysv68.c |
| 4 | * |
| 5 | * Copyright (C) 2007 Philippe De Muyter <phdm@macqel.be> |
| 6 | */ |
| 7 | |
| 8 | #include "check.h" |
| 9 | #include "sysv68.h" |
| 10 | |
| 11 | /* |
| 12 | * Volume ID structure: on first 256-bytes sector of disk |
| 13 | */ |
| 14 | |
| 15 | struct volumeid { |
| 16 | u8 vid_unused[248]; |
| 17 | u8 vid_mac[8]; /* ASCII string "MOTOROLA" */ |
| 18 | }; |
| 19 | |
| 20 | /* |
| 21 | * config block: second 256-bytes sector on disk |
| 22 | */ |
| 23 | |
| 24 | struct dkconfig { |
| 25 | u8 ios_unused0[128]; |
| 26 | __be32 ios_slcblk; /* Slice table block number */ |
| 27 | __be16 ios_slccnt; /* Number of entries in slice table */ |
| 28 | u8 ios_unused1[122]; |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * combined volumeid and dkconfig block |
| 33 | */ |
| 34 | |
| 35 | struct dkblk0 { |
| 36 | struct volumeid dk_vid; |
| 37 | struct dkconfig dk_ios; |
| 38 | }; |
| 39 | |
| 40 | /* |
| 41 | * Slice Table Structure |
| 42 | */ |
| 43 | |
| 44 | struct slice { |
| 45 | __be32 nblocks; /* slice size (in blocks) */ |
| 46 | __be32 blkoff; /* block offset of slice */ |
| 47 | }; |
| 48 | |
| 49 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 50 | int sysv68_partition(struct parsed_partitions *state) |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 51 | { |
| 52 | int i, slices; |
| 53 | int slot = 1; |
| 54 | Sector sect; |
| 55 | unsigned char *data; |
| 56 | struct dkblk0 *b; |
| 57 | struct slice *slice; |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 58 | char tmp[64]; |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 59 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 60 | data = read_part_sector(state, 0, §); |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 61 | if (!data) |
| 62 | return -1; |
| 63 | |
| 64 | b = (struct dkblk0 *)data; |
| 65 | if (memcmp(b->dk_vid.vid_mac, "MOTOROLA", sizeof(b->dk_vid.vid_mac))) { |
| 66 | put_dev_sector(sect); |
| 67 | return 0; |
| 68 | } |
| 69 | slices = be16_to_cpu(b->dk_ios.ios_slccnt); |
| 70 | i = be32_to_cpu(b->dk_ios.ios_slcblk); |
| 71 | put_dev_sector(sect); |
| 72 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 73 | data = read_part_sector(state, i, §); |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 74 | if (!data) |
| 75 | return -1; |
| 76 | |
| 77 | slices -= 1; /* last slice is the whole disk */ |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 78 | snprintf(tmp, sizeof(tmp), "sysV68: %s(s%u)", state->name, slices); |
| 79 | strlcat(state->pp_buf, tmp, PAGE_SIZE); |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 80 | slice = (struct slice *)data; |
| 81 | for (i = 0; i < slices; i++, slice++) { |
| 82 | if (slot == state->limit) |
| 83 | break; |
| 84 | if (be32_to_cpu(slice->nblocks)) { |
| 85 | put_partition(state, slot, |
| 86 | be32_to_cpu(slice->blkoff), |
| 87 | be32_to_cpu(slice->nblocks)); |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 88 | snprintf(tmp, sizeof(tmp), "(s%u)", i); |
| 89 | strlcat(state->pp_buf, tmp, PAGE_SIZE); |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 90 | } |
| 91 | slot++; |
| 92 | } |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 93 | strlcat(state->pp_buf, "\n", PAGE_SIZE); |
Philippe De Muyter | 19d0e8c | 2007-05-08 00:29:15 -0700 | [diff] [blame] | 94 | put_dev_sector(sect); |
| 95 | return 1; |
| 96 | } |