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