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