Commit 194ec0c0 authored by Borislav Petkov's avatar Borislav Petkov Committed by Bartlomiej Zolnierkiewicz

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: default avatarBorislav Petkov <bbpetkov@yahoo.de>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 8e81bbba
...@@ -119,29 +119,7 @@ typedef struct idefloppy_packet_command_s { ...@@ -119,29 +119,7 @@ typedef struct idefloppy_packet_command_s {
#define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */ #define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */
/* /* format capacities descriptor codes */
* Format capacity
*/
typedef struct {
u8 reserved[3];
u8 length; /* Length of the following descriptors in bytes */
} idefloppy_capacity_header_t;
typedef struct {
u32 blocks; /* Number of blocks */
#if defined(__LITTLE_ENDIAN_BITFIELD)
unsigned dc :2; /* Descriptor Code */
unsigned reserved :6;
#elif defined(__BIG_ENDIAN_BITFIELD)
unsigned reserved :6;
unsigned dc :2; /* Descriptor Code */
#else
#error "Bitfield endianness not defined! Check your byteorder.h"
#endif
u8 length_msb; /* Block Length (MSB)*/
u16 length; /* Block Length */
} idefloppy_capacity_descriptor_t;
#define CAPACITY_INVALID 0x00 #define CAPACITY_INVALID 0x00
#define CAPACITY_UNFORMATTED 0x01 #define CAPACITY_UNFORMATTED 0x01
#define CAPACITY_CURRENT 0x02 #define CAPACITY_CURRENT 0x02
...@@ -184,8 +162,8 @@ typedef struct ide_floppy_obj { ...@@ -184,8 +162,8 @@ typedef struct ide_floppy_obj {
*/ */
/* Current format */ /* Current format */
int blocks, block_size, bs_factor; int blocks, block_size, bs_factor;
/* Last format capacity */ /* Last format capacity descriptor */
idefloppy_capacity_descriptor_t capacity; u8 cap_desc[8];
/* Copy of the flexible disk page */ /* Copy of the flexible disk page */
u8 flexible_disk_page[32]; u8 flexible_disk_page[32];
/* Write protect */ /* Write protect */
...@@ -1141,16 +1119,16 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive) ...@@ -1141,16 +1119,16 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
} }
/* /*
* Determine if a media is present in the floppy drive, and if so, * Determine if a media is present in the floppy drive, and if so, its LBA
* its LBA capacity. * capacity.
*/ */
static int idefloppy_get_capacity (ide_drive_t *drive) static int ide_floppy_get_capacity(ide_drive_t *drive)
{ {
idefloppy_floppy_t *floppy = drive->driver_data; idefloppy_floppy_t *floppy = drive->driver_data;
idefloppy_pc_t pc; idefloppy_pc_t pc;
idefloppy_capacity_header_t *header; u8 *cap_desc;
idefloppy_capacity_descriptor_t *descriptor; u8 header_len, desc_cnt;
int i, descriptors, rc = 1, blocks, length; int i, rc = 1, blocks, length;
drive->bios_cyl = 0; drive->bios_cyl = 0;
drive->bios_head = drive->bios_sect = 0; drive->bios_head = drive->bios_sect = 0;
...@@ -1163,17 +1141,26 @@ static int idefloppy_get_capacity (ide_drive_t *drive) ...@@ -1163,17 +1141,26 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
return 1; return 1;
} }
header = (idefloppy_capacity_header_t *) pc.buffer; header_len = pc.buffer[3];
descriptors = header->length / sizeof(idefloppy_capacity_descriptor_t); cap_desc = &pc.buffer[4];
descriptor = (idefloppy_capacity_descriptor_t *) (header + 1); desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
for (i = 0; i < desc_cnt; i++) {
unsigned int desc_start = 4 + i*8;
for (i = 0; i < descriptors; i++, descriptor++) { blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
blocks = descriptor->blocks = be32_to_cpu(descriptor->blocks); length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
length = descriptor->length = be16_to_cpu(descriptor->length);
if (!i) debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
{ i, blocks * length / 1024, blocks, length);
switch (descriptor->dc) {
if (i)
continue;
/*
* the code below is valid only for the 1st descriptor, ie i=0
*/
switch (pc.buffer[desc_start + 4] & 0x03) {
/* Clik! drive returns this instead of CAPACITY_CURRENT */ /* Clik! drive returns this instead of CAPACITY_CURRENT */
case CAPACITY_UNFORMATTED: case CAPACITY_UNFORMATTED:
if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
...@@ -1184,18 +1171,20 @@ static int idefloppy_get_capacity (ide_drive_t *drive) ...@@ -1184,18 +1171,20 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
break; break;
case CAPACITY_CURRENT: case CAPACITY_CURRENT:
/* Normal Zip/LS-120 disks */ /* Normal Zip/LS-120 disks */
if (memcmp(descriptor, &floppy->capacity, sizeof (idefloppy_capacity_descriptor_t))) if (memcmp(cap_desc, &floppy->cap_desc, 8))
printk(KERN_INFO "%s: %dkB, %d blocks, %d " printk(KERN_INFO "%s: %dkB, %d blocks, %d "
"sector size\n", drive->name, "sector size\n", drive->name,
blocks * length / 1024, blocks, length); blocks * length / 1024, blocks, length);
floppy->capacity = *descriptor; memcpy(&floppy->cap_desc, cap_desc, 8);
if (!length || length % 512) { if (!length || length % 512) {
printk(KERN_NOTICE "%s: %d bytes block size " printk(KERN_NOTICE "%s: %d bytes block size "
"not supported\n", drive->name, length); "not supported\n", drive->name, length);
} else { } else {
floppy->blocks = blocks; floppy->blocks = blocks;
floppy->block_size = length; floppy->block_size = length;
if ((floppy->bs_factor = length / 512) != 1) floppy->bs_factor = length / 512;
if (floppy->bs_factor != 1)
printk(KERN_NOTICE "%s: warning: non " printk(KERN_NOTICE "%s: warning: non "
"512 bytes block size not " "512 bytes block size not "
"fully supported\n", "fully supported\n",
...@@ -1215,52 +1204,42 @@ static int idefloppy_get_capacity (ide_drive_t *drive) ...@@ -1215,52 +1204,42 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
"in drive\n", drive->name); "in drive\n", drive->name);
break; break;
} }
} debug_log("Descriptor 0 Code: %d\n",
if (!i) { pc.buffer[desc_start + 4] & 0x03);
debug_log("Descriptor 0 Code: %d\n", descriptor->dc);
}
debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
i, blocks * length / 1024, blocks, length);
} }
/* Clik! disk does not support get_flexible_disk_page */ /* Clik! disk does not support get_flexible_disk_page */
if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
(void) ide_floppy_get_flexible_disk_page(drive); (void) ide_floppy_get_flexible_disk_page(drive);
}
set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
return rc; return rc;
} }
/* /*
** Obtain the list of formattable capacities. * Obtain the list of formattable capacities.
** Very similar to idefloppy_get_capacity, except that we push the capacity * Very similar to ide_floppy_get_capacity, except that we push the capacity
** descriptors to userland, instead of our own structures. * descriptors to userland, instead of our own structures.
** *
** Userland gives us the following structure: * Userland gives us the following structure:
** *
** struct idefloppy_format_capacities { * struct idefloppy_format_capacities {
** int nformats; * int nformats;
** struct { * struct {
** int nblocks; * int nblocks;
** int blocksize; * int blocksize;
** } formats[]; * } formats[];
** } ; * };
** *
** userland initializes nformats to the number of allocated formats[] * userland initializes nformats to the number of allocated formats[] records.
** records. On exit we set nformats to the number of records we've * On exit we set nformats to the number of records we've actually initialized.
** actually initialized. */
**
*/
static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg) static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
{ {
idefloppy_pc_t pc; idefloppy_pc_t pc;
idefloppy_capacity_header_t *header; u8 header_len, desc_cnt;
idefloppy_capacity_descriptor_t *descriptor; int i, blocks, length, u_array_size, u_index;
int i, descriptors, blocks, length;
int u_array_size;
int u_index;
int __user *argp; int __user *argp;
if (get_user(u_array_size, arg)) if (get_user(u_array_size, arg))
...@@ -1274,28 +1253,25 @@ static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg) ...@@ -1274,28 +1253,25 @@ static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
return (-EIO); return (-EIO);
} }
header = (idefloppy_capacity_header_t *) pc.buffer; header_len = pc.buffer[3];
descriptors = header->length / desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
sizeof(idefloppy_capacity_descriptor_t);
descriptor = (idefloppy_capacity_descriptor_t *) (header + 1);
u_index = 0; u_index = 0;
argp = arg + 1; argp = arg + 1;
/* /*
** We always skip the first capacity descriptor. That's the * We always skip the first capacity descriptor. That's the current
** current capacity. We are interested in the remaining descriptors, * capacity. We are interested in the remaining descriptors, the
** the formattable capacities. * formattable capacities.
*/ */
for (i = 1; i < desc_cnt; i++) {
unsigned int desc_start = 4 + i*8;
for (i=0; i<descriptors; i++, descriptor++) {
if (u_index >= u_array_size) if (u_index >= u_array_size)
break; /* User-supplied buffer too small */ break; /* User-supplied buffer too small */
if (i == 0)
continue; /* Skip the first descriptor */
blocks = be32_to_cpu(descriptor->blocks); blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
length = be16_to_cpu(descriptor->length); length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
if (put_user(blocks, argp)) if (put_user(blocks, argp))
return(-EFAULT); return(-EFAULT);
...@@ -1535,7 +1511,7 @@ static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy) ...@@ -1535,7 +1511,7 @@ static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy)
} }
(void) idefloppy_get_capacity(drive); (void) ide_floppy_get_capacity(drive);
idefloppy_add_settings(drive); idefloppy_add_settings(drive);
} }
...@@ -1630,7 +1606,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp) ...@@ -1630,7 +1606,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
(void) idefloppy_queue_pc_tail(drive, &pc); (void) idefloppy_queue_pc_tail(drive, &pc);
} }
if (idefloppy_get_capacity (drive) if (ide_floppy_get_capacity(drive)
&& (filp->f_flags & O_NDELAY) == 0 && (filp->f_flags & O_NDELAY) == 0
/* /*
** Allow O_NDELAY to open a drive without a disk, or with ** 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,7 +1710,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
return 0; return 0;
case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
return idefloppy_get_format_capacities(drive, argp); return ide_floppy_get_format_capacities(drive, argp);
case IDEFLOPPY_IOCTL_FORMAT_START: case IDEFLOPPY_IOCTL_FORMAT_START:
if (!(file->f_mode & 2)) if (!(file->f_mode & 2))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment