diff options
author | Borislav Petkov <bbpetkov@yahoo.de> | 2008-02-02 13:56:35 -0500 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-02-02 13:56:35 -0500 |
commit | 194ec0c07895d8f8bf3ca8e50d5225f7968ad2d0 (patch) | |
tree | 6f2868b5a6c9096d13b3a7d4ef3f4bd659860f2f /drivers/ide/ide-floppy.c | |
parent | 8e81bbba72453b74e4ceb1480546b1092184c11c (diff) |
ide-floppy: remove struct idefloppy_capacity_descriptor
Also,
- remove the accompanying 4 byte idefloppy_capacity_header.
- rename functions from idefloppy_... to ide_floppy_... after cleanup.
- simplify loop in ide_floppy_get_capacity() by reversing if-test condition
logically.
- finally, fix white space and checkpatch.pl issues
Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-floppy.c')
-rw-r--r-- | drivers/ide/ide-floppy.c | 176 |
1 files changed, 76 insertions, 100 deletions
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index 5d84fa5f3dc6..28a0bae94e82 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c | |||
@@ -119,29 +119,7 @@ typedef struct idefloppy_packet_command_s { | |||
119 | 119 | ||
120 | #define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */ | 120 | #define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */ |
121 | 121 | ||
122 | /* | 122 | /* format capacities descriptor codes */ |
123 | * Format capacity | ||
124 | */ | ||
125 | typedef struct { | ||
126 | u8 reserved[3]; | ||
127 | u8 length; /* Length of the following descriptors in bytes */ | ||
128 | } idefloppy_capacity_header_t; | ||
129 | |||
130 | typedef struct { | ||
131 | u32 blocks; /* Number of blocks */ | ||
132 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
133 | unsigned dc :2; /* Descriptor Code */ | ||
134 | unsigned reserved :6; | ||
135 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
136 | unsigned reserved :6; | ||
137 | unsigned dc :2; /* Descriptor Code */ | ||
138 | #else | ||
139 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
140 | #endif | ||
141 | u8 length_msb; /* Block Length (MSB)*/ | ||
142 | u16 length; /* Block Length */ | ||
143 | } idefloppy_capacity_descriptor_t; | ||
144 | |||
145 | #define CAPACITY_INVALID 0x00 | 123 | #define CAPACITY_INVALID 0x00 |
146 | #define CAPACITY_UNFORMATTED 0x01 | 124 | #define CAPACITY_UNFORMATTED 0x01 |
147 | #define CAPACITY_CURRENT 0x02 | 125 | #define CAPACITY_CURRENT 0x02 |
@@ -184,8 +162,8 @@ typedef struct ide_floppy_obj { | |||
184 | */ | 162 | */ |
185 | /* Current format */ | 163 | /* Current format */ |
186 | int blocks, block_size, bs_factor; | 164 | int blocks, block_size, bs_factor; |
187 | /* Last format capacity */ | 165 | /* Last format capacity descriptor */ |
188 | idefloppy_capacity_descriptor_t capacity; | 166 | u8 cap_desc[8]; |
189 | /* Copy of the flexible disk page */ | 167 | /* Copy of the flexible disk page */ |
190 | u8 flexible_disk_page[32]; | 168 | u8 flexible_disk_page[32]; |
191 | /* Write protect */ | 169 | /* Write protect */ |
@@ -1141,17 +1119,17 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive) | |||
1141 | } | 1119 | } |
1142 | 1120 | ||
1143 | /* | 1121 | /* |
1144 | * Determine if a media is present in the floppy drive, and if so, | 1122 | * Determine if a media is present in the floppy drive, and if so, its LBA |
1145 | * its LBA capacity. | 1123 | * capacity. |
1146 | */ | 1124 | */ |
1147 | static int idefloppy_get_capacity (ide_drive_t *drive) | 1125 | static int ide_floppy_get_capacity(ide_drive_t *drive) |
1148 | { | 1126 | { |
1149 | idefloppy_floppy_t *floppy = drive->driver_data; | 1127 | idefloppy_floppy_t *floppy = drive->driver_data; |
1150 | idefloppy_pc_t pc; | 1128 | idefloppy_pc_t pc; |
1151 | idefloppy_capacity_header_t *header; | 1129 | u8 *cap_desc; |
1152 | idefloppy_capacity_descriptor_t *descriptor; | 1130 | u8 header_len, desc_cnt; |
1153 | int i, descriptors, rc = 1, blocks, length; | 1131 | int i, rc = 1, blocks, length; |
1154 | 1132 | ||
1155 | drive->bios_cyl = 0; | 1133 | drive->bios_cyl = 0; |
1156 | drive->bios_head = drive->bios_sect = 0; | 1134 | drive->bios_head = drive->bios_sect = 0; |
1157 | floppy->blocks = 0; | 1135 | floppy->blocks = 0; |
@@ -1163,17 +1141,26 @@ static int idefloppy_get_capacity (ide_drive_t *drive) | |||
1163 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); | 1141 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); |
1164 | return 1; | 1142 | return 1; |
1165 | } | 1143 | } |
1166 | header = (idefloppy_capacity_header_t *) pc.buffer; | 1144 | header_len = pc.buffer[3]; |
1167 | descriptors = header->length / sizeof(idefloppy_capacity_descriptor_t); | 1145 | cap_desc = &pc.buffer[4]; |
1168 | descriptor = (idefloppy_capacity_descriptor_t *) (header + 1); | 1146 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
1147 | |||
1148 | for (i = 0; i < desc_cnt; i++) { | ||
1149 | unsigned int desc_start = 4 + i*8; | ||
1150 | |||
1151 | blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]); | ||
1152 | length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]); | ||
1153 | |||
1154 | debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", | ||
1155 | i, blocks * length / 1024, blocks, length); | ||
1169 | 1156 | ||
1170 | for (i = 0; i < descriptors; i++, descriptor++) { | 1157 | if (i) |
1171 | blocks = descriptor->blocks = be32_to_cpu(descriptor->blocks); | 1158 | continue; |
1172 | length = descriptor->length = be16_to_cpu(descriptor->length); | 1159 | /* |
1160 | * the code below is valid only for the 1st descriptor, ie i=0 | ||
1161 | */ | ||
1173 | 1162 | ||
1174 | if (!i) | 1163 | switch (pc.buffer[desc_start + 4] & 0x03) { |
1175 | { | ||
1176 | switch (descriptor->dc) { | ||
1177 | /* Clik! drive returns this instead of CAPACITY_CURRENT */ | 1164 | /* Clik! drive returns this instead of CAPACITY_CURRENT */ |
1178 | case CAPACITY_UNFORMATTED: | 1165 | case CAPACITY_UNFORMATTED: |
1179 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) | 1166 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) |
@@ -1184,23 +1171,25 @@ static int idefloppy_get_capacity (ide_drive_t *drive) | |||
1184 | break; | 1171 | break; |
1185 | case CAPACITY_CURRENT: | 1172 | case CAPACITY_CURRENT: |
1186 | /* Normal Zip/LS-120 disks */ | 1173 | /* Normal Zip/LS-120 disks */ |
1187 | if (memcmp(descriptor, &floppy->capacity, sizeof (idefloppy_capacity_descriptor_t))) | 1174 | if (memcmp(cap_desc, &floppy->cap_desc, 8)) |
1188 | printk(KERN_INFO "%s: %dkB, %d blocks, %d " | 1175 | printk(KERN_INFO "%s: %dkB, %d blocks, %d " |
1189 | "sector size\n", drive->name, | 1176 | "sector size\n", drive->name, |
1190 | blocks * length / 1024, blocks, length); | 1177 | blocks * length / 1024, blocks, length); |
1191 | floppy->capacity = *descriptor; | 1178 | memcpy(&floppy->cap_desc, cap_desc, 8); |
1179 | |||
1192 | if (!length || length % 512) { | 1180 | if (!length || length % 512) { |
1193 | printk(KERN_NOTICE "%s: %d bytes block size " | 1181 | printk(KERN_NOTICE "%s: %d bytes block size " |
1194 | "not supported\n", drive->name, length); | 1182 | "not supported\n", drive->name, length); |
1195 | } else { | 1183 | } else { |
1196 | floppy->blocks = blocks; | 1184 | floppy->blocks = blocks; |
1197 | floppy->block_size = length; | 1185 | floppy->block_size = length; |
1198 | if ((floppy->bs_factor = length / 512) != 1) | 1186 | floppy->bs_factor = length / 512; |
1199 | printk(KERN_NOTICE "%s: warning: non " | 1187 | if (floppy->bs_factor != 1) |
1188 | printk(KERN_NOTICE "%s: warning: non " | ||
1200 | "512 bytes block size not " | 1189 | "512 bytes block size not " |
1201 | "fully supported\n", | 1190 | "fully supported\n", |
1202 | drive->name); | 1191 | drive->name); |
1203 | rc = 0; | 1192 | rc = 0; |
1204 | } | 1193 | } |
1205 | break; | 1194 | break; |
1206 | case CAPACITY_NO_CARTRIDGE: | 1195 | case CAPACITY_NO_CARTRIDGE: |
@@ -1215,52 +1204,42 @@ static int idefloppy_get_capacity (ide_drive_t *drive) | |||
1215 | "in drive\n", drive->name); | 1204 | "in drive\n", drive->name); |
1216 | break; | 1205 | break; |
1217 | } | 1206 | } |
1218 | } | 1207 | debug_log("Descriptor 0 Code: %d\n", |
1219 | if (!i) { | 1208 | pc.buffer[desc_start + 4] & 0x03); |
1220 | debug_log("Descriptor 0 Code: %d\n", descriptor->dc); | ||
1221 | } | ||
1222 | debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", | ||
1223 | i, blocks * length / 1024, blocks, length); | ||
1224 | } | 1209 | } |
1225 | 1210 | ||
1226 | /* Clik! disk does not support get_flexible_disk_page */ | 1211 | /* Clik! disk does not support get_flexible_disk_page */ |
1227 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { | 1212 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) |
1228 | (void) ide_floppy_get_flexible_disk_page(drive); | 1213 | (void) ide_floppy_get_flexible_disk_page(drive); |
1229 | } | ||
1230 | 1214 | ||
1231 | set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); | 1215 | set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); |
1232 | return rc; | 1216 | return rc; |
1233 | } | 1217 | } |
1234 | 1218 | ||
1235 | /* | 1219 | /* |
1236 | ** Obtain the list of formattable capacities. | 1220 | * Obtain the list of formattable capacities. |
1237 | ** Very similar to idefloppy_get_capacity, except that we push the capacity | 1221 | * Very similar to ide_floppy_get_capacity, except that we push the capacity |
1238 | ** descriptors to userland, instead of our own structures. | 1222 | * descriptors to userland, instead of our own structures. |
1239 | ** | 1223 | * |
1240 | ** Userland gives us the following structure: | 1224 | * Userland gives us the following structure: |
1241 | ** | 1225 | * |
1242 | ** struct idefloppy_format_capacities { | 1226 | * struct idefloppy_format_capacities { |
1243 | ** int nformats; | 1227 | * int nformats; |
1244 | ** struct { | 1228 | * struct { |
1245 | ** int nblocks; | 1229 | * int nblocks; |
1246 | ** int blocksize; | 1230 | * int blocksize; |
1247 | ** } formats[]; | 1231 | * } formats[]; |
1248 | ** } ; | 1232 | * }; |
1249 | ** | 1233 | * |
1250 | ** userland initializes nformats to the number of allocated formats[] | 1234 | * userland initializes nformats to the number of allocated formats[] records. |
1251 | ** records. On exit we set nformats to the number of records we've | 1235 | * On exit we set nformats to the number of records we've actually initialized. |
1252 | ** actually initialized. | 1236 | */ |
1253 | ** | ||
1254 | */ | ||
1255 | 1237 | ||
1256 | static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg) | 1238 | static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg) |
1257 | { | 1239 | { |
1258 | idefloppy_pc_t pc; | 1240 | idefloppy_pc_t pc; |
1259 | idefloppy_capacity_header_t *header; | 1241 | u8 header_len, desc_cnt; |
1260 | idefloppy_capacity_descriptor_t *descriptor; | 1242 | int i, blocks, length, u_array_size, u_index; |
1261 | int i, descriptors, blocks, length; | ||
1262 | int u_array_size; | ||
1263 | int u_index; | ||
1264 | int __user *argp; | 1243 | int __user *argp; |
1265 | 1244 | ||
1266 | if (get_user(u_array_size, arg)) | 1245 | if (get_user(u_array_size, arg)) |
@@ -1272,30 +1251,27 @@ static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg) | |||
1272 | idefloppy_create_read_capacity_cmd(&pc); | 1251 | idefloppy_create_read_capacity_cmd(&pc); |
1273 | if (idefloppy_queue_pc_tail(drive, &pc)) { | 1252 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
1274 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); | 1253 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); |
1275 | return (-EIO); | 1254 | return (-EIO); |
1276 | } | 1255 | } |
1277 | header = (idefloppy_capacity_header_t *) pc.buffer; | 1256 | header_len = pc.buffer[3]; |
1278 | descriptors = header->length / | 1257 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
1279 | sizeof(idefloppy_capacity_descriptor_t); | ||
1280 | descriptor = (idefloppy_capacity_descriptor_t *) (header + 1); | ||
1281 | 1258 | ||
1282 | u_index = 0; | 1259 | u_index = 0; |
1283 | argp = arg + 1; | 1260 | argp = arg + 1; |
1284 | 1261 | ||
1285 | /* | 1262 | /* |
1286 | ** We always skip the first capacity descriptor. That's the | 1263 | * We always skip the first capacity descriptor. That's the current |
1287 | ** current capacity. We are interested in the remaining descriptors, | 1264 | * capacity. We are interested in the remaining descriptors, the |
1288 | ** the formattable capacities. | 1265 | * formattable capacities. |
1289 | */ | 1266 | */ |
1267 | for (i = 1; i < desc_cnt; i++) { | ||
1268 | unsigned int desc_start = 4 + i*8; | ||
1290 | 1269 | ||
1291 | for (i=0; i<descriptors; i++, descriptor++) { | ||
1292 | if (u_index >= u_array_size) | 1270 | if (u_index >= u_array_size) |
1293 | break; /* User-supplied buffer too small */ | 1271 | break; /* User-supplied buffer too small */ |
1294 | if (i == 0) | ||
1295 | continue; /* Skip the first descriptor */ | ||
1296 | 1272 | ||
1297 | blocks = be32_to_cpu(descriptor->blocks); | 1273 | blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]); |
1298 | length = be16_to_cpu(descriptor->length); | 1274 | length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]); |
1299 | 1275 | ||
1300 | if (put_user(blocks, argp)) | 1276 | if (put_user(blocks, argp)) |
1301 | return(-EFAULT); | 1277 | return(-EFAULT); |
@@ -1535,7 +1511,7 @@ static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy) | |||
1535 | } | 1511 | } |
1536 | 1512 | ||
1537 | 1513 | ||
1538 | (void) idefloppy_get_capacity(drive); | 1514 | (void) ide_floppy_get_capacity(drive); |
1539 | idefloppy_add_settings(drive); | 1515 | idefloppy_add_settings(drive); |
1540 | } | 1516 | } |
1541 | 1517 | ||
@@ -1630,7 +1606,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp) | |||
1630 | (void) idefloppy_queue_pc_tail(drive, &pc); | 1606 | (void) idefloppy_queue_pc_tail(drive, &pc); |
1631 | } | 1607 | } |
1632 | 1608 | ||
1633 | if (idefloppy_get_capacity (drive) | 1609 | if (ide_floppy_get_capacity(drive) |
1634 | && (filp->f_flags & O_NDELAY) == 0 | 1610 | && (filp->f_flags & O_NDELAY) == 0 |
1635 | /* | 1611 | /* |
1636 | ** Allow O_NDELAY to open a drive without a disk, or with | 1612 | ** Allow O_NDELAY to open a drive without a disk, or with |
@@ -1734,7 +1710,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file, | |||
1734 | case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: | 1710 | case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: |
1735 | return 0; | 1711 | return 0; |
1736 | case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: | 1712 | case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: |
1737 | return idefloppy_get_format_capacities(drive, argp); | 1713 | return ide_floppy_get_format_capacities(drive, argp); |
1738 | case IDEFLOPPY_IOCTL_FORMAT_START: | 1714 | case IDEFLOPPY_IOCTL_FORMAT_START: |
1739 | 1715 | ||
1740 | if (!(file->f_mode & 2)) | 1716 | if (!(file->f_mode & 2)) |