block: Move SECTOR_SIZE and SECTOR_SHIFT definitions into <linux/blkdev.h>
Subsystems (8)
PATCH v3 1/1 block: Move SECTOR_SIZE and SECTOR_SHIFT definitions into <linux/blkdev.h>
It happens often while I'm preparing a patch for a block driver that I'm wondering: is a definition of SECTOR_SIZE and/or SECTOR_SHIFT available for this driver? Do I have to introduce definitions of these constants before I can use these constants? To avoid this confusion, move the existing definitions of SECTOR_SIZE and SECTOR_SHIFT into the <linux/blkdev.h> header file such that these become available for all block drivers. Make the SECTOR_SIZE definition in the uapi msdos_fs.h header file conditional to avoid that including that header file after <linux/blkdev.h> causes the compiler to complain about a SECTOR_SIZE redefinition.
Note: the SECTOR_SIZE / SECTOR_SHIFT / SECTOR_BITS definitions have not been removed from uapi header files nor from NAND drivers in which these constants are used for another purpose than converting block layer offsets and sizes into a number of sectors.
---
Changes compared to v2:
- Updated Reviewed-by tags.
Changes compared to v1:
- Changed enums into defines.
- Defined SECTOR_SIZE in terms of SECTOR_SHIFT.
- Made uapi SECTOR_SIZE definition conditional.
arch/xtensa/platforms/iss/simdisk.c | 1 - drivers/block/brd.c | 1 - drivers/block/null_blk.c | 2 -- drivers/block/rbd.c | 9 -------- drivers/block/zram/zram_drv.h | 1 - drivers/ide/ide-cd.c | 8 +++---- drivers/ide/ide-cd.h | 6 +----- drivers/nvdimm/nd.h | 1 - drivers/scsi/gdth.h | 3 --- include/linux/blkdev.h | 42 +++++++++++++++++++++++++++---------- include/linux/device-mapper.h | 2 -- include/linux/ide.h | 1 - include/uapi/linux/msdos_fs.h | 2 ++ 13 files changed, 38 insertions(+), 41 deletions(-)
arch/xtensa/platforms/iss/simdisk.c +0 -1
@@ -21,7 +21,6 @@#include <platform/simcall.h> #define SIMDISK_MAJOR 240 -#define SECTOR_SHIFT 9#define SIMDISK_MINORS 1#define MAX_SIMDISK_COUNT 10
drivers/block/brd.c +0 -1
@@ -24,7 +24,6 @@#include <linux/uaccess.h> -#define SECTOR_SHIFT 9#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
drivers/block/null_blk.c +0 -2
@@ -16,10 +16,8 @@#include <linux/badblocks.h> #include <linux/fault-inject.h> -#define SECTOR_SHIFT 9#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT) -#define SECTOR_SIZE (1 << SECTOR_SHIFT)#define SECTOR_MASK (PAGE_SECTORS - 1)#define FREE_BATCH 16
drivers/block/rbd.c +0 -9
@@ -50,15 +50,6 @@#define RBD_DEBUG /* Activate rbd_assert() calls */ -/* -* The basic unit of block I/O is a sector. It is interpreted in a -* number of contexts in Linux (blk, bio, genhd), but the default is -* universally 512 bytes. These symbols are just slightly more -* meaningful than the bare numbers they represent. -*/ -#define SECTOR_SHIFT 9 -#define SECTOR_SIZE (1ULL << SECTOR_SHIFT) -/* * Increment the given counter and return its updated value. * If the counter is already 0 it will not be incremented.
drivers/block/zram/zram_drv.h +0 -1
@@ -37,7 +37,6 @@ static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;/*-- End of configurable params */ -#define SECTOR_SHIFT 9#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)#define ZRAM_LOGICAL_BLOCK_SHIFT 12
drivers/ide/ide-cd.c +4 -4
@@ -712,7 +712,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)struct request_queue *q = drive->queue;int write =rq_data_dir (rq) ==WRITE ;unsigned short sectors_per_frame = -queue_logical_block_size (q) >>SECTOR_BITS ; +queue_logical_block_size (q) >>SECTOR_SHIFT ; ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, " "secs_per_frame: %u",
@@ -919,7 +919,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,* end up being bogus. */ blocklen =be32_to_cpu (capbuf.blocklen); - blocklen = (blocklen >>SECTOR_BITS ) <<SECTOR_BITS ; + blocklen = (blocklen >>SECTOR_SHIFT ) <<SECTOR_SHIFT ;switch (blocklen) {case 512 :case 1024 :
@@ -935,7 +935,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity, } *capacity =1 +be32_to_cpu (capbuf.lba); - *sectors_per_frame = blocklen >>SECTOR_BITS ; + *sectors_per_frame = blocklen >>SECTOR_SHIFT ;ide_debug_log (IDE_DBG_PROBE ,"cap: %lu, sectors_per_frame: %lu" , *capacity, *sectors_per_frame);
@@ -1012,7 +1012,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) drive->probed_capacity = toc->capacity * sectors_per_frame;blk_queue_logical_block_size (drive->queue, - sectors_per_frame <<SECTOR_BITS ); + sectors_per_frame <<SECTOR_SHIFT );/* first read just the header, so we know how long the TOC is */ stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
drivers/ide/ide-cd.h +1 -5
@@ -21,11 +21,7 @@/************************************************************************/ -#define SECTOR_BITS 9 -#ifndef SECTOR_SIZE -#define SECTOR_SIZE (1 << SECTOR_BITS) -#endif -#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS) +#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_SHIFT)#define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32)/* Capabilities Page size including 8 bytes of Mode Page Header */
drivers/nvdimm/nd.h +0 -1
@@ -29,7 +29,6 @@ enum {* BTT instance */ ND_MAX_LANES =256 , -SECTOR_SHIFT =9 ,INT_LBASIZE_ALIGNMENT =64 , NVDIMM_IO_ATOMIC = 1, };
drivers/scsi/gdth.h +0 -3
@@ -178,9 +178,6 @@#define MSG_SIZE 34/* size of message structure */ #define MSG_REQUEST 0/* async. event: message */ -/* cacheservice defines */ -#define SECTOR_SIZE 0x200/* always 512 bytes per sec. */ -/* DPMEM constants */ #define DPMEM_MAGIC 0xC0FFEE11#define IC_HEADER_BYTES 48
include/linux/blkdev.h +31 -11
94 lines not on this page · raw message
include/linux/device-mapper.h +0 -2
@@ -542,8 +542,6 @@ do { \ #define DMEMIT(x...) sz += ((sz >= maxlen) ? \ 0 : scnprintf(result + sz, maxlen - sz, x)) -#define SECTOR_SHIFT 9 -/* * Definitions of return values from target end_io function. */
include/linux/ide.h +0 -1
@@ -165,7 +165,6 @@ struct ide_io_ports {*/ #define PARTN_BITS 6/* number of minor dev bits for partitions */ #define MAX_DRIVES 2/* per interface; 2 assumed by lots of code */ -#define SECTOR_SIZE 512/* * Timeouts for various operations:
include/uapi/linux/msdos_fs.h +2 -0
@@ -10,7 +10,9 @@* The MS-DOS filesystem constants/structures */ +#ifndef SECTOR_SIZE #define SECTOR_SIZE 512/* sector size (bytes) */ +#endif #define SECTOR_BITS 9/* log2(SECTOR_SIZE) */ #define MSDOS_DPB (MSDOS_DPS)/* dir entries per block */ #define MSDOS_DPB_BITS 4/* log2(MSDOS_DPB) */
Signature · 1 line
2.16.2
Quoted 1 line · Bart Van Assche
It happens often while I'm preparing a patch for a block driver that
Please ignore this copy of this patch since it was sent to the wrong mailing list.
Bart.