part/dev_desc: Add log2 of blocksize to block_dev_desc data struct
authorEgbert Eich <eich@suse.com>
Tue, 9 Apr 2013 21:11:56 +0000 (21:11 +0000)
committerChanho Park <chanho61.park@samsung.com>
Thu, 6 Aug 2015 06:02:12 +0000 (15:02 +0900)
log2 of the device block size serves as the shift value used to calculate
the block number to read in file systems when implementing avaiable block
sizes.
It is needed quite often in file systems thus it is pre-calculated and
stored in the block device descriptor.

Signed-off-by: Egbert Eich <eich@suse.com>
common/cmd_ide.c
common/cmd_sata.c
common/cmd_scsi.c
common/usb_storage.c
drivers/block/ata_piix.c
drivers/block/pata_bfin.c
drivers/block/systemace.c
drivers/mmc/mmc.c
include/part.h

index 6e1e5680a2cb94154c34082f263e2fe7f3a58b47..fa5a23b7854cd44b3d439a72b0bdc5fa368a7ec7 100644 (file)
@@ -546,6 +546,8 @@ void ide_init(void)
                ide_dev_desc[i].dev = i;
                ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
                ide_dev_desc[i].blksz = 0;
+               ide_dev_desc[i].log2blksz =
+                       LOG2_INVALID(typeof(ide_dev_desc[i].log2blksz));
                ide_dev_desc[i].lba = 0;
                ide_dev_desc[i].block_read = ide_read;
                ide_dev_desc[i].block_write = ide_write;
@@ -1055,6 +1057,7 @@ static void ide_ident(block_dev_desc_t *dev_desc)
        /* assuming HD */
        dev_desc->type = DEV_TYPE_HARDDISK;
        dev_desc->blksz = ATA_BLOCKSIZE;
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
        dev_desc->lun = 0;      /* just to fill something in... */
 
 #if 0                          /* only used to test the powersaving mode,
@@ -1799,6 +1802,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
        dev_desc->lun = 0;
        dev_desc->lba = 0;
        dev_desc->blksz = 0;
+       dev_desc->log2blksz = LOG2_INVALID(typeof(dev_desc->log2blksz));
        dev_desc->type = iobuf[0] & 0x1f;
 
        if ((iobuf[1] & 0x80) == 0x80)
@@ -1843,6 +1847,7 @@ static void atapi_inquiry(block_dev_desc_t *dev_desc)
        dev_desc->blksz = ((unsigned long) iobuf[4] << 24) +
                ((unsigned long) iobuf[5] << 16) +
                ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]);
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
 #ifdef CONFIG_LBA48
        /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */
        dev_desc->lba48 = 0;
index 3f98235a38a6a0fa725ab1694285085e768f5e80..84f12caf7d951bc145e54a75a71718a595f10deb 100644 (file)
@@ -44,6 +44,7 @@ int __sata_initialize(void)
                sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
                sata_dev_desc[i].lba = 0;
                sata_dev_desc[i].blksz = 512;
+               sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
                sata_dev_desc[i].block_read = sata_read;
                sata_dev_desc[i].block_write = sata_write;
 
index e91e00cd66c4fbfe5e0f35b517d33603777bb0ce..22ced03568a3e2c62c06db8b6ccee973920bf82f 100644 (file)
@@ -93,6 +93,8 @@ void scsi_scan(int mode)
                scsi_dev_desc[i].lun=0xff;
                scsi_dev_desc[i].lba=0;
                scsi_dev_desc[i].blksz=0;
+               scsi_dev_desc[i].log2blksz =
+                       LOG2_INVALID(typeof(scsi_dev_desc[i].log2blksz));
                scsi_dev_desc[i].type=DEV_TYPE_UNKNOWN;
                scsi_dev_desc[i].vendor[0]=0;
                scsi_dev_desc[i].product[0]=0;
@@ -158,6 +160,8 @@ void scsi_scan(int mode)
                                ((unsigned long)tempbuff[6]<<8)|((unsigned long)tempbuff[7]);
                        scsi_dev_desc[scsi_max_devs].lba=capacity;
                        scsi_dev_desc[scsi_max_devs].blksz=blksz;
+                       scsi_dev_desc[scsi_max_devs].log2blksz =
+                               LOG2(scsi_dev_desc[scsi_max_devs].blksz);
                        scsi_dev_desc[scsi_max_devs].type=perq;
                        init_part(&scsi_dev_desc[scsi_max_devs]);
 removable:
index c3e084e1ecf807bbbdf4d5c7b6d1bf3ccf507241..ae53cd783b586d18e5cedcbdf1bafd518e000201 100644 (file)
@@ -1422,6 +1422,7 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
                        *capacity, *blksz);
        dev_desc->lba = *capacity;
        dev_desc->blksz = *blksz;
+       dev_desc->log2blksz = LOG2(dev_desc->blksz);
        dev_desc->type = perq;
        USB_STOR_PRINTF(" address %d\n", dev_desc->target);
        USB_STOR_PRINTF("partype: %d\n", dev_desc->part_type);
index c81d11a6ce35e1800ef652e75392a7dbc3f38430..7c9dc676627ad270b2ec4ca7dfdf007f7451a4c5 100644 (file)
@@ -422,6 +422,7 @@ sata_identify (int num, int dev)
        /* assuming HD */
        sata_dev_desc[devno].type = DEV_TYPE_HARDDISK;
        sata_dev_desc[devno].blksz = ATA_BLOCKSIZE;
+       sata_dev_desc[devno].log2blksz = LOG2(sata_dev_desc[devno].blksz);
        sata_dev_desc[devno].lun = 0;   /* just to fill something in... */
 }
 
index cce21fbc5409bc9b0f206c3bb2b72e0f282c52c9..cac18b57086c6410698fee93bc09c0408b3187af 100644 (file)
@@ -896,6 +896,8 @@ static void bfin_ata_identify(struct ata_port *ap, int dev)
        /* assuming HD */
        sata_dev_desc[ap->port_no].type = DEV_TYPE_HARDDISK;
        sata_dev_desc[ap->port_no].blksz = ATA_SECT_SIZE;
+       sata_dev_desc[ap->port_no].log2blksz =
+               LOG2(sata_dev_desc[ap->port_no].blksz);
        sata_dev_desc[ap->port_no].lun = 0;     /* just to fill something in... */
 
        printf("PATA device#%d %s is found on ata port#%d.\n",
index 58402b9289c4267d59697812acd720875220b4ea..614407735afe78fa303162c8e1984e144bd8ea70 100644 (file)
@@ -115,6 +115,7 @@ block_dev_desc_t *systemace_get_dev(int dev)
                systemace_dev.part_type = PART_TYPE_UNKNOWN;
                systemace_dev.type = DEV_TYPE_HARDDISK;
                systemace_dev.blksz = 512;
+               systemace_dev.log2blksz = LOG2(systemace_dev.blksz);
                systemace_dev.removable = 1;
                systemace_dev.block_read = systemace_read;
 
index 00cc829420954835cab6b059ac40472953b266b4..e5dce266cee9f7087289b7b9fa469e4760b3906e 100644 (file)
@@ -1457,6 +1457,7 @@ int mmc_startup(struct mmc *mmc)
        mmc->block_dev.lun = 0;
        mmc->block_dev.type = 0;
        mmc->block_dev.blksz = mmc->read_bl_len;
+       mmc->block_dev.log2blksz = LOG2(mmc->block_dev.blksz);
        mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
        sprintf(mmc->block_dev.vendor, "Man %06x Snr %08x", mmc->cid[0] >> 8,
                        (mmc->cid[2] << 8) | (mmc->cid[3] >> 24));
index 1c47b565336a269359d289e9dbbac4aa7548a31c..8d5ea5d19d13b8dd76658335acd828ff230e2b97 100644 (file)
@@ -38,6 +38,7 @@ typedef struct block_dev_desc {
 #endif
        lbaint_t        lba;            /* number of blocks */
        unsigned long   blksz;          /* block size */
+       int             log2blksz;      /* for convenience: log2(blksz) */
        char            vendor [40+1];  /* IDE model, SCSI Vendor */
        char            product[20+1];  /* IDE Serial no, SCSI product */
        char            revision[8+1];  /* firmware revision */
@@ -58,6 +59,10 @@ typedef struct block_dev_desc {
 #define BLOCK_CNT(size, block_dev_desc) (PAD_COUNT(size, block_dev_desc->blksz))
 #define PAD_TO_BLOCKSIZE(size, block_dev_desc) \
        (PAD_SIZE(size, block_dev_desc->blksz))
+#define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
+                ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
+                ((x & 0xffff0000) ? 16 : 0))
+#define LOG2_INVALID(type) ((type)((sizeof(type)<<3)-1))
 
 /* Interface types: */
 #define IF_TYPE_UNKNOWN                0