Skip to content

Commit 233bde2

Browse files
KAGA-KOKOaxboe
authored andcommitted
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. Cc: David S. Miller <[email protected]> Cc: Mike Snitzer <[email protected]> Cc: Dan Williams <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Nitin Gupta <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent ec6dcf6 commit 233bde2

File tree

13 files changed

+38
-41
lines changed

13 files changed

+38
-41
lines changed

arch/xtensa/platforms/iss/simdisk.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <platform/simcall.h>
2222

2323
#define SIMDISK_MAJOR 240
24-
#define SECTOR_SHIFT 9
2524
#define SIMDISK_MINORS 1
2625
#define MAX_SIMDISK_COUNT 10
2726

drivers/block/brd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include <linux/uaccess.h>
2626

27-
#define SECTOR_SHIFT 9
2827
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
2928
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
3029

drivers/block/null_blk.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
#include <linux/badblocks.h>
1717
#include <linux/fault-inject.h>
1818

19-
#define SECTOR_SHIFT 9
2019
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
2120
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
22-
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
2321
#define SECTOR_MASK (PAGE_SECTORS - 1)
2422

2523
#define FREE_BATCH 16

drivers/block/rbd.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@
5050

5151
#define RBD_DEBUG /* Activate rbd_assert() calls */
5252

53-
/*
54-
* The basic unit of block I/O is a sector. It is interpreted in a
55-
* number of contexts in Linux (blk, bio, genhd), but the default is
56-
* universally 512 bytes. These symbols are just slightly more
57-
* meaningful than the bare numbers they represent.
58-
*/
59-
#define SECTOR_SHIFT 9
60-
#define SECTOR_SIZE (1ULL << SECTOR_SHIFT)
61-
6253
/*
6354
* Increment the given counter and return its updated value.
6455
* If the counter is already 0 it will not be incremented.

drivers/block/zram/zram_drv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
3737

3838
/*-- End of configurable params */
3939

40-
#define SECTOR_SHIFT 9
4140
#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
4241
#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
4342
#define ZRAM_LOGICAL_BLOCK_SHIFT 12

drivers/ide/ide-cd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
712712
struct request_queue *q = drive->queue;
713713
int write = rq_data_dir(rq) == WRITE;
714714
unsigned short sectors_per_frame =
715-
queue_logical_block_size(q) >> SECTOR_BITS;
715+
queue_logical_block_size(q) >> SECTOR_SHIFT;
716716

717717
ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, "
718718
"secs_per_frame: %u",
@@ -919,7 +919,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
919919
* end up being bogus.
920920
*/
921921
blocklen = be32_to_cpu(capbuf.blocklen);
922-
blocklen = (blocklen >> SECTOR_BITS) << SECTOR_BITS;
922+
blocklen = (blocklen >> SECTOR_SHIFT) << SECTOR_SHIFT;
923923
switch (blocklen) {
924924
case 512:
925925
case 1024:
@@ -935,7 +935,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
935935
}
936936

937937
*capacity = 1 + be32_to_cpu(capbuf.lba);
938-
*sectors_per_frame = blocklen >> SECTOR_BITS;
938+
*sectors_per_frame = blocklen >> SECTOR_SHIFT;
939939

940940
ide_debug_log(IDE_DBG_PROBE, "cap: %lu, sectors_per_frame: %lu",
941941
*capacity, *sectors_per_frame);
@@ -1012,7 +1012,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
10121012
drive->probed_capacity = toc->capacity * sectors_per_frame;
10131013

10141014
blk_queue_logical_block_size(drive->queue,
1015-
sectors_per_frame << SECTOR_BITS);
1015+
sectors_per_frame << SECTOR_SHIFT);
10161016

10171017
/* first read just the header, so we know how long the TOC is */
10181018
stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,

drivers/ide/ide-cd.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121

2222
/************************************************************************/
2323

24-
#define SECTOR_BITS 9
25-
#ifndef SECTOR_SIZE
26-
#define SECTOR_SIZE (1 << SECTOR_BITS)
27-
#endif
28-
#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS)
24+
#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_SHIFT)
2925
#define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32)
3026

3127
/* Capabilities Page size including 8 bytes of Mode Page Header */

drivers/nvdimm/nd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ enum {
2929
* BTT instance
3030
*/
3131
ND_MAX_LANES = 256,
32-
SECTOR_SHIFT = 9,
3332
INT_LBASIZE_ALIGNMENT = 64,
3433
NVDIMM_IO_ATOMIC = 1,
3534
};

drivers/scsi/gdth.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@
178178
#define MSG_SIZE 34 /* size of message structure */
179179
#define MSG_REQUEST 0 /* async. event: message */
180180

181-
/* cacheservice defines */
182-
#define SECTOR_SIZE 0x200 /* always 512 bytes per sec. */
183-
184181
/* DPMEM constants */
185182
#define DPMEM_MAGIC 0xC0FFEE11
186183
#define IC_HEADER_BYTES 48

include/linux/blkdev.h

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,19 @@ static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
10211021
return bdev->bd_disk->queue; /* this is never NULL */
10221022
}
10231023

1024+
/*
1025+
* The basic unit of block I/O is a sector. It is used in a number of contexts
1026+
* in Linux (blk, bio, genhd). The size of one sector is 512 = 2**9
1027+
* bytes. Variables of type sector_t represent an offset or size that is a
1028+
* multiple of 512 bytes. Hence these two constants.
1029+
*/
1030+
#ifndef SECTOR_SHIFT
1031+
#define SECTOR_SHIFT 9
1032+
#endif
1033+
#ifndef SECTOR_SIZE
1034+
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
1035+
#endif
1036+
10241037
/*
10251038
* blk_rq_pos() : the current sector
10261039
* blk_rq_bytes() : bytes left in the entire request
@@ -1048,12 +1061,12 @@ extern unsigned int blk_rq_err_bytes(const struct request *rq);
10481061

10491062
static inline unsigned int blk_rq_sectors(const struct request *rq)
10501063
{
1051-
return blk_rq_bytes(rq) >> 9;
1064+
return blk_rq_bytes(rq) >> SECTOR_SHIFT;
10521065
}
10531066

10541067
static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
10551068
{
1056-
return blk_rq_cur_bytes(rq) >> 9;
1069+
return blk_rq_cur_bytes(rq) >> SECTOR_SHIFT;
10571070
}
10581071

10591072
static inline unsigned int blk_rq_zone_no(struct request *rq)
@@ -1083,7 +1096,8 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
10831096
int op)
10841097
{
10851098
if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE))
1086-
return min(q->limits.max_discard_sectors, UINT_MAX >> 9);
1099+
return min(q->limits.max_discard_sectors,
1100+
UINT_MAX >> SECTOR_SHIFT);
10871101

10881102
if (unlikely(op == REQ_OP_WRITE_SAME))
10891103
return q->limits.max_write_same_sectors;
@@ -1395,16 +1409,21 @@ extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
13951409
static inline int sb_issue_discard(struct super_block *sb, sector_t block,
13961410
sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
13971411
{
1398-
return blkdev_issue_discard(sb->s_bdev, block << (sb->s_blocksize_bits - 9),
1399-
nr_blocks << (sb->s_blocksize_bits - 9),
1412+
return blkdev_issue_discard(sb->s_bdev,
1413+
block << (sb->s_blocksize_bits -
1414+
SECTOR_SHIFT),
1415+
nr_blocks << (sb->s_blocksize_bits -
1416+
SECTOR_SHIFT),
14001417
gfp_mask, flags);
14011418
}
14021419
static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
14031420
sector_t nr_blocks, gfp_t gfp_mask)
14041421
{
14051422
return blkdev_issue_zeroout(sb->s_bdev,
1406-
block << (sb->s_blocksize_bits - 9),
1407-
nr_blocks << (sb->s_blocksize_bits - 9),
1423+
block << (sb->s_blocksize_bits -
1424+
SECTOR_SHIFT),
1425+
nr_blocks << (sb->s_blocksize_bits -
1426+
SECTOR_SHIFT),
14081427
gfp_mask, 0);
14091428
}
14101429

@@ -1511,7 +1530,8 @@ static inline int queue_alignment_offset(struct request_queue *q)
15111530
static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
15121531
{
15131532
unsigned int granularity = max(lim->physical_block_size, lim->io_min);
1514-
unsigned int alignment = sector_div(sector, granularity >> 9) << 9;
1533+
unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT)
1534+
<< SECTOR_SHIFT;
15151535

15161536
return (granularity + lim->alignment_offset - alignment) % granularity;
15171537
}
@@ -1545,8 +1565,8 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector
15451565
return 0;
15461566

15471567
/* Why are these in bytes, not sectors? */
1548-
alignment = lim->discard_alignment >> 9;
1549-
granularity = lim->discard_granularity >> 9;
1568+
alignment = lim->discard_alignment >> SECTOR_SHIFT;
1569+
granularity = lim->discard_granularity >> SECTOR_SHIFT;
15501570
if (!granularity)
15511571
return 0;
15521572

@@ -1557,7 +1577,7 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector
15571577
offset = (granularity + alignment - offset) % granularity;
15581578

15591579
/* Turn it back into bytes, gaah */
1560-
return offset << 9;
1580+
return offset << SECTOR_SHIFT;
15611581
}
15621582

15631583
static inline int bdev_discard_alignment(struct block_device *bdev)

include/linux/device-mapper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,6 @@ do { \
542542
#define DMEMIT(x...) sz += ((sz >= maxlen) ? \
543543
0 : scnprintf(result + sz, maxlen - sz, x))
544544

545-
#define SECTOR_SHIFT 9
546-
547545
/*
548546
* Definitions of return values from target end_io function.
549547
*/

include/linux/ide.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ struct ide_io_ports {
165165
*/
166166
#define PARTN_BITS 6 /* number of minor dev bits for partitions */
167167
#define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
168-
#define SECTOR_SIZE 512
169168

170169
/*
171170
* Timeouts for various operations:

include/uapi/linux/msdos_fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
* The MS-DOS filesystem constants/structures
1111
*/
1212

13+
#ifndef SECTOR_SIZE
1314
#define SECTOR_SIZE 512 /* sector size (bytes) */
15+
#endif
1416
#define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */
1517
#define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */
1618
#define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */

0 commit comments

Comments
 (0)