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