1 /*
2  *  fs/partitions/osf.c
3  *
4  *  Code extracted from drivers/block/genhd.c
5  *
6  *  Copyright (C) 1991-1998  Linus Torvalds
7  *  Re-organised Feb 1998 Russell King
8  */
9 
10 #include <linux/fs.h>
11 #include <linux/genhd.h>
12 #include <linux/kernel.h>
13 #include <linux/major.h>
14 #include <linux/string.h>
15 #include <linux/blk.h>
16 
17 #include "check.h"
18 #include "osf.h"
19 
osf_partition(struct gendisk * hd,struct block_device * bdev,unsigned long first_sector,int current_minor)20 int osf_partition(struct gendisk *hd, struct block_device *bdev,
21 		unsigned long first_sector, int current_minor)
22 {
23 	int i;
24 	Sector sect;
25 	unsigned char *data;
26 	int mask = (1 << hd->minor_shift) - 1;
27 	struct disklabel {
28 		u32 d_magic;
29 		u16 d_type,d_subtype;
30 		u8 d_typename[16];
31 		u8 d_packname[16];
32 		u32 d_secsize;
33 		u32 d_nsectors;
34 		u32 d_ntracks;
35 		u32 d_ncylinders;
36 		u32 d_secpercyl;
37 		u32 d_secprtunit;
38 		u16 d_sparespertrack;
39 		u16 d_sparespercyl;
40 		u32 d_acylinders;
41 		u16 d_rpm, d_interleave, d_trackskew, d_cylskew;
42 		u32 d_headswitch, d_trkseek, d_flags;
43 		u32 d_drivedata[5];
44 		u32 d_spare[5];
45 		u32 d_magic2;
46 		u16 d_checksum;
47 		u16 d_npartitions;
48 		u32 d_bbsize, d_sbsize;
49 		struct d_partition {
50 			u32 p_size;
51 			u32 p_offset;
52 			u32 p_fsize;
53 			u8  p_fstype;
54 			u8  p_frag;
55 			u16 p_cpg;
56 		} d_partitions[8];
57 	} * label;
58 	struct d_partition * partition;
59 
60 	data = read_dev_sector(bdev, 0, &sect);
61 	if (!data)
62 		return -1;
63 
64 	label = (struct disklabel *) (data+64);
65 	partition = label->d_partitions;
66 	if (le32_to_cpu(label->d_magic) != DISKLABELMAGIC) {
67 		put_dev_sector(sect);
68 		return 0;
69 	}
70 	if (le32_to_cpu(label->d_magic2) != DISKLABELMAGIC) {
71 		put_dev_sector(sect);
72 		return 0;
73 	}
74 	for (i = 0 ; i < le16_to_cpu(label->d_npartitions); i++, partition++) {
75 		if ((current_minor & mask) == 0)
76 		        break;
77 		if (le32_to_cpu(partition->p_size))
78 			add_gd_partition(hd, current_minor,
79 				first_sector+le32_to_cpu(partition->p_offset),
80 				le32_to_cpu(partition->p_size));
81 		current_minor++;
82 	}
83 	printk("\n");
84 	put_dev_sector(sect);
85 	return 1;
86 }
87 
88