Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * fs/partitions/osf.c |
| 4 | * |
| 5 | * Code extracted from drivers/block/genhd.c |
| 6 | * |
| 7 | * Copyright (C) 1991-1998 Linus Torvalds |
| 8 | * Re-organised Feb 1998 Russell King |
| 9 | */ |
| 10 | |
| 11 | #include "check.h" |
| 12 | #include "osf.h" |
| 13 | |
Linus Torvalds | 34d211a | 2011-03-16 08:04:07 -0700 | [diff] [blame] | 14 | #define MAX_OSF_PARTITIONS 18 |
Timo Warns | 1eafbfe | 2011-03-14 14:59:33 +0100 | [diff] [blame] | 15 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 16 | int osf_partition(struct parsed_partitions *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | { |
| 18 | int i; |
| 19 | int slot = 1; |
Timo Warns | 1eafbfe | 2011-03-14 14:59:33 +0100 | [diff] [blame] | 20 | unsigned int npartitions; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | Sector sect; |
| 22 | unsigned char *data; |
| 23 | struct disklabel { |
| 24 | __le32 d_magic; |
| 25 | __le16 d_type,d_subtype; |
| 26 | u8 d_typename[16]; |
| 27 | u8 d_packname[16]; |
| 28 | __le32 d_secsize; |
| 29 | __le32 d_nsectors; |
| 30 | __le32 d_ntracks; |
| 31 | __le32 d_ncylinders; |
| 32 | __le32 d_secpercyl; |
| 33 | __le32 d_secprtunit; |
| 34 | __le16 d_sparespertrack; |
| 35 | __le16 d_sparespercyl; |
| 36 | __le32 d_acylinders; |
| 37 | __le16 d_rpm, d_interleave, d_trackskew, d_cylskew; |
| 38 | __le32 d_headswitch, d_trkseek, d_flags; |
| 39 | __le32 d_drivedata[5]; |
| 40 | __le32 d_spare[5]; |
| 41 | __le32 d_magic2; |
| 42 | __le16 d_checksum; |
| 43 | __le16 d_npartitions; |
| 44 | __le32 d_bbsize, d_sbsize; |
| 45 | struct d_partition { |
| 46 | __le32 p_size; |
| 47 | __le32 p_offset; |
| 48 | __le32 p_fsize; |
| 49 | u8 p_fstype; |
| 50 | u8 p_frag; |
| 51 | __le16 p_cpg; |
Timo Warns | 1eafbfe | 2011-03-14 14:59:33 +0100 | [diff] [blame] | 52 | } d_partitions[MAX_OSF_PARTITIONS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } * label; |
| 54 | struct d_partition * partition; |
| 55 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 56 | data = read_part_sector(state, 0, §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | if (!data) |
| 58 | return -1; |
| 59 | |
| 60 | label = (struct disklabel *) (data+64); |
| 61 | partition = label->d_partitions; |
| 62 | if (le32_to_cpu(label->d_magic) != DISKLABELMAGIC) { |
| 63 | put_dev_sector(sect); |
| 64 | return 0; |
| 65 | } |
| 66 | if (le32_to_cpu(label->d_magic2) != DISKLABELMAGIC) { |
| 67 | put_dev_sector(sect); |
| 68 | return 0; |
| 69 | } |
Timo Warns | 1eafbfe | 2011-03-14 14:59:33 +0100 | [diff] [blame] | 70 | npartitions = le16_to_cpu(label->d_npartitions); |
| 71 | if (npartitions > MAX_OSF_PARTITIONS) { |
| 72 | put_dev_sector(sect); |
| 73 | return 0; |
| 74 | } |
| 75 | for (i = 0 ; i < npartitions; i++, partition++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | if (slot == state->limit) |
| 77 | break; |
| 78 | if (le32_to_cpu(partition->p_size)) |
| 79 | put_partition(state, slot, |
| 80 | le32_to_cpu(partition->p_offset), |
| 81 | le32_to_cpu(partition->p_size)); |
| 82 | slot++; |
| 83 | } |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 84 | strlcat(state->pp_buf, "\n", PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | put_dev_sector(sect); |
| 86 | return 1; |
| 87 | } |