This source file includes following definitions.
- scsicam_bios_param
- partsize
- setsize
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/fs.h>
14 #include <linux/genhd.h>
15 #include <linux/kernel.h>
16 #include "../block/blk.h"
17 #include "scsi.h"
18 #include "hosts.h"
19 #include "sd.h"
20
21 static int partsize(struct buffer_head *bh, unsigned long capacity,
22 unsigned int *cyls, unsigned int *hds, unsigned int *secs);
23 static int setsize(unsigned long capacity,unsigned int *cyls,unsigned int *hds,
24 unsigned int *secs);
25
26
27
28
29
30
31
32
33
34
35
36
37 int scsicam_bios_param (Disk *disk,
38 int dev,
39 int *ip ) {
40 struct buffer_head *bh;
41 int ret_code;
42 int size = disk->capacity;
43
44 if (!(bh = bread(dev & ~0xf,0,1024)))
45 return -1;
46
47 #ifdef DEBUG
48 printk ("scsicam_bios_param : trying existing mapping\n");
49 #endif
50 ret_code = partsize (bh, (unsigned long) size, (unsigned int *) ip + 2,
51 (unsigned int *) ip + 0, (unsigned int *) ip + 1);
52 brelse (bh);
53
54 if (ret_code == -1) {
55 #ifdef DEBUG
56 printk ("scsicam_bios_param : trying optimal mapping\n");
57 #endif
58 ret_code = setsize ((unsigned long) size, (unsigned int *) ip + 2,
59 (unsigned int *) ip + 0, (unsigned int *) ip + 1);
60 }
61
62 return ret_code;
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76 static int partsize(struct buffer_head *bh, unsigned long capacity,
77 unsigned int *cyls, unsigned int *hds, unsigned int *secs) {
78 struct partition *p, *largest = NULL;
79 int i, largest_cyl;
80 int cyl, end_head, end_cyl, end_sector;
81 unsigned int logical_end, physical_end;
82
83
84 if (*(unsigned short *) (bh->b_data+510) == 0xAA55) {
85 for (largest_cyl = -1, p = (struct partition *)
86 (0x1BE + bh->b_data), i = 0; i < 4; ++i, ++p) {
87 if (!p->sys_ind)
88 continue;
89 #ifdef DEBUG
90 printk ("scsicam_bios_param : partition %d has system \n",
91 i);
92 #endif
93 cyl = p->cyl + ((p->sector & 0xc0) << 2);
94 if (cyl > largest_cyl) {
95 largest_cyl = cyl;
96 largest = p;
97 }
98 }
99 }
100
101 if (largest) {
102 end_cyl = largest->end_cyl + ((largest->end_sector & 0xc0) << 2);
103 end_head = largest->end_head;
104 end_sector = largest->end_sector & 0x3f;
105 #ifdef DEBUG
106 printk ("scsicam_bios_param : end at h = %d, c = %d, s = %d\n",
107 end_head, end_cyl, end_sector);
108 #endif
109
110 physical_end = end_cyl * (end_head + 1) * end_sector +
111 end_head * end_sector + end_sector;
112
113
114 logical_end = largest->start_sect + largest->nr_sects;
115
116 if (logical_end == physical_end) {
117 *secs = end_sector;
118 *hds = end_head + 1;
119 *cyls = capacity / ((end_head + 1) * end_sector);
120 return 0;
121 }
122 #ifdef DEBUG
123 printk ("scsicam_bios_param : logical (%u) != physical (%u)\n",
124 logical_end, physical_end);
125 #endif
126 }
127 return -1;
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 static int setsize(unsigned long capacity,unsigned int *cyls,unsigned int *hds,
165 unsigned int *secs) {
166 unsigned int rv = 0;
167 unsigned long heads, sectors, cylinders, temp;
168
169 cylinders = 1024L;
170 sectors = 62L;
171
172 temp = cylinders * sectors;
173 heads = capacity / temp;
174 if (capacity % temp) {
175 heads++;
176 temp = cylinders * heads;
177 sectors = capacity / temp;
178
179 if (capacity % temp) {
180 sectors++;
181 temp = heads * sectors;
182 cylinders = capacity / temp;
183 }
184 }
185 if (cylinders == 0) rv=(unsigned)-1;
186
187 *cyls = (unsigned int) cylinders;
188 *secs = (unsigned int) sectors;
189 *hds = (unsigned int) heads;
190 return(rv);
191 }