1 /* SPDX-License-Identifier: GPL-2.0 */
6 * genhd.h Copyright (C) 1992 Drew Eckhardt
7 * Generic hard disk header file by
13 #include <linux/types.h>
14 #include <linux/kdev_t.h>
15 #include <linux/rcupdate.h>
16 #include <linux/slab.h>
17 #include <linux/percpu-refcount.h>
18 #include <linux/uuid.h>
19 #include <linux/blk_types.h>
20 #include <asm/local.h>
24 #define dev_to_disk(device) container_of((device), struct gendisk, part0.__dev)
25 #define dev_to_part(device) container_of((device), struct hd_struct, __dev)
26 #define disk_to_dev(disk) (&(disk)->part0.__dev)
27 #define part_to_dev(part) (&((part)->__dev))
29 extern struct device_type part_type
;
30 extern struct kobject
*block_depr
;
31 extern struct class block_class
;
34 /* These three have identical behaviour; use the second one if DOS FDISK gets
35 confused about extended/logical partitions starting past cylinder 1023. */
36 DOS_EXTENDED_PARTITION
= 5,
37 LINUX_EXTENDED_PARTITION
= 0x85,
38 WIN98_EXTENDED_PARTITION
= 0x0f,
40 SUN_WHOLE_DISK
= DOS_EXTENDED_PARTITION
,
42 LINUX_SWAP_PARTITION
= 0x82,
43 LINUX_DATA_PARTITION
= 0x83,
44 LINUX_LVM_PARTITION
= 0x8e,
45 LINUX_RAID_PARTITION
= 0xfd, /* autodetect RAID partition */
47 SOLARIS_X86_PARTITION
= LINUX_SWAP_PARTITION
,
48 NEW_SOLARIS_X86_PARTITION
= 0xbf,
50 DM6_AUX1PARTITION
= 0x51, /* no DDO: use xlated geom */
51 DM6_AUX3PARTITION
= 0x53, /* no DDO: use xlated geom */
52 DM6_PARTITION
= 0x54, /* has DDO: use xlated geom & offset */
53 EZD_PARTITION
= 0x55, /* EZ-DRIVE */
55 FREEBSD_PARTITION
= 0xa5, /* FreeBSD Partition ID */
56 OPENBSD_PARTITION
= 0xa6, /* OpenBSD Partition ID */
57 NETBSD_PARTITION
= 0xa9, /* NetBSD Partition ID */
58 BSDI_PARTITION
= 0xb7, /* BSDI Partition ID */
59 MINIX_PARTITION
= 0x81, /* Minix Partition ID */
60 UNIXWARE_PARTITION
= 0x63, /* Same as GNU_HURD and SCO Unix */
63 #define DISK_MAX_PARTS 256
64 #define DISK_NAME_LEN 32
66 #include <linux/major.h>
67 #include <linux/device.h>
68 #include <linux/smp.h>
69 #include <linux/string.h>
71 #include <linux/workqueue.h>
74 unsigned char boot_ind
; /* 0x80 - active */
75 unsigned char head
; /* starting head */
76 unsigned char sector
; /* starting sector */
77 unsigned char cyl
; /* starting cylinder */
78 unsigned char sys_ind
; /* What partition type */
79 unsigned char end_head
; /* end head */
80 unsigned char end_sector
; /* end sector */
81 unsigned char end_cyl
; /* end cylinder */
82 __le32 start_sect
; /* starting sector counting from 0 */
83 __le32 nr_sects
; /* nr of sectors in partition */
84 } __attribute__((packed
));
87 u64 nsecs
[NR_STAT_GROUPS
];
88 unsigned long sectors
[NR_STAT_GROUPS
];
89 unsigned long ios
[NR_STAT_GROUPS
];
90 unsigned long merges
[NR_STAT_GROUPS
];
91 unsigned long io_ticks
;
92 unsigned long time_in_queue
;
96 #define PARTITION_META_INFO_VOLNAMELTH 64
98 * Enough for the string representation of any kind of UUID plus NULL.
99 * EFI UUID is 36 characters. MSDOS UUID is 11 characters.
101 #define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
103 struct partition_meta_info
{
104 char uuid
[PARTITION_META_INFO_UUIDLTH
];
105 u8 volname
[PARTITION_META_INFO_VOLNAMELTH
];
111 * nr_sects is protected by sequence counter. One might extend a
112 * partition while IO is happening to it and update of nr_sects
113 * can be non-atomic on 32bit machines with 64bit sector_t.
116 seqcount_t nr_sects_seq
;
117 sector_t alignment_offset
;
118 unsigned int discard_alignment
;
120 struct kobject
*holder_dir
;
122 struct partition_meta_info
*info
;
123 #ifdef CONFIG_FAIL_MAKE_REQUEST
128 struct disk_stats __percpu
*dkstats
;
130 struct disk_stats dkstats
;
132 struct percpu_ref ref
;
133 struct rcu_work rcu_work
;
136 #define GENHD_FL_REMOVABLE 1
138 #define GENHD_FL_MEDIA_CHANGE_NOTIFY 4
139 #define GENHD_FL_CD 8
140 #define GENHD_FL_UP 16
141 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
142 #define GENHD_FL_EXT_DEVT 64 /* allow extended devt */
143 #define GENHD_FL_NATIVE_CAPACITY 128
144 #define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 256
145 #define GENHD_FL_NO_PART_SCAN 512
146 #define GENHD_FL_HIDDEN 1024
149 DISK_EVENT_MEDIA_CHANGE
= 1 << 0, /* media changed */
150 DISK_EVENT_EJECT_REQUEST
= 1 << 1, /* eject requested */
154 /* Poll even if events_poll_msecs is unset */
155 DISK_EVENT_FLAG_POLL
= 1 << 0,
156 /* Forward events to udev */
157 DISK_EVENT_FLAG_UEVENT
= 1 << 1,
160 struct disk_part_tbl
{
161 struct rcu_head rcu_head
;
163 struct hd_struct __rcu
*last_lookup
;
164 struct hd_struct __rcu
*part
[];
170 #if defined(CONFIG_BLK_DEV_INTEGRITY)
172 struct blk_integrity
{
173 const struct blk_integrity_profile
*profile
;
175 unsigned char tuple_size
;
176 unsigned char interval_exp
;
177 unsigned char tag_size
;
180 #endif /* CONFIG_BLK_DEV_INTEGRITY */
183 /* major, first_minor and minors are input parameters only,
184 * don't use directly. Use disk_devt() and disk_max_parts().
186 int major
; /* major number of driver */
188 int minors
; /* maximum number of minors, =1 for
189 * disks that can't be partitioned. */
191 char disk_name
[DISK_NAME_LEN
]; /* name of major driver */
192 char *(*devnode
)(struct gendisk
*gd
, umode_t
*mode
);
194 unsigned short events
; /* supported events */
195 unsigned short event_flags
; /* flags related to event processing */
197 /* Array of pointers to partitions indexed by partno.
198 * Protected with matching bdev lock but stat and other
199 * non-critical accesses use RCU. Always access through
202 struct disk_part_tbl __rcu
*part_tbl
;
203 struct hd_struct part0
;
205 const struct block_device_operations
*fops
;
206 struct request_queue
*queue
;
210 struct rw_semaphore lookup_sem
;
211 struct kobject
*slave_dir
;
213 struct timer_rand_state
*random
;
214 atomic_t sync_io
; /* RAID */
215 struct disk_events
*ev
;
216 #ifdef CONFIG_BLK_DEV_INTEGRITY
217 struct kobject integrity_kobj
;
218 #endif /* CONFIG_BLK_DEV_INTEGRITY */
220 struct badblocks
*bb
;
221 struct lockdep_map lockdep_map
;
224 static inline struct gendisk
*part_to_disk(struct hd_struct
*part
)
228 return dev_to_disk(part_to_dev(part
)->parent
);
230 return dev_to_disk(part_to_dev(part
));
235 static inline int disk_max_parts(struct gendisk
*disk
)
237 if (disk
->flags
& GENHD_FL_EXT_DEVT
)
238 return DISK_MAX_PARTS
;
242 static inline bool disk_part_scan_enabled(struct gendisk
*disk
)
244 return disk_max_parts(disk
) > 1 &&
245 !(disk
->flags
& GENHD_FL_NO_PART_SCAN
);
248 static inline dev_t
disk_devt(struct gendisk
*disk
)
250 return MKDEV(disk
->major
, disk
->first_minor
);
253 static inline dev_t
part_devt(struct hd_struct
*part
)
255 return part_to_dev(part
)->devt
;
258 extern struct hd_struct
*__disk_get_part(struct gendisk
*disk
, int partno
);
259 extern struct hd_struct
*disk_get_part(struct gendisk
*disk
, int partno
);
261 static inline void disk_put_part(struct hd_struct
*part
)
264 put_device(part_to_dev(part
));
268 * Smarter partition iterator without context limits.
270 #define DISK_PITER_REVERSE (1 << 0) /* iterate in the reverse direction */
271 #define DISK_PITER_INCL_EMPTY (1 << 1) /* include 0-sized parts */
272 #define DISK_PITER_INCL_PART0 (1 << 2) /* include partition 0 */
273 #define DISK_PITER_INCL_EMPTY_PART0 (1 << 3) /* include empty partition 0 */
275 struct disk_part_iter
{
276 struct gendisk
*disk
;
277 struct hd_struct
*part
;
282 extern void disk_part_iter_init(struct disk_part_iter
*piter
,
283 struct gendisk
*disk
, unsigned int flags
);
284 extern struct hd_struct
*disk_part_iter_next(struct disk_part_iter
*piter
);
285 extern void disk_part_iter_exit(struct disk_part_iter
*piter
);
287 extern struct hd_struct
*disk_map_sector_rcu(struct gendisk
*disk
,
291 * Macros to operate on percpu disk statistics:
293 * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters
294 * and should be called between disk_stat_lock() and
295 * disk_stat_unlock().
297 * part_stat_read() can be called at any time.
299 * part_stat_{add|set_all}() and {init|free}_part_stats are for
303 #define part_stat_lock() ({ rcu_read_lock(); get_cpu(); })
304 #define part_stat_unlock() do { put_cpu(); rcu_read_unlock(); } while (0)
306 #define part_stat_get_cpu(part, field, cpu) \
307 (per_cpu_ptr((part)->dkstats, (cpu))->field)
309 #define part_stat_get(part, field) \
310 part_stat_get_cpu(part, field, smp_processor_id())
312 #define part_stat_read(part, field) \
314 typeof((part)->dkstats->field) res = 0; \
316 for_each_possible_cpu(_cpu) \
317 res += per_cpu_ptr((part)->dkstats, _cpu)->field; \
321 static inline void part_stat_set_all(struct hd_struct
*part
, int value
)
325 for_each_possible_cpu(i
)
326 memset(per_cpu_ptr(part
->dkstats
, i
), value
,
327 sizeof(struct disk_stats
));
330 static inline int init_part_stats(struct hd_struct
*part
)
332 part
->dkstats
= alloc_percpu(struct disk_stats
);
338 static inline void free_part_stats(struct hd_struct
*part
)
340 free_percpu(part
->dkstats
);
343 #else /* !CONFIG_SMP */
344 #define part_stat_lock() ({ rcu_read_lock(); 0; })
345 #define part_stat_unlock() rcu_read_unlock()
347 #define part_stat_get(part, field) ((part)->dkstats.field)
348 #define part_stat_get_cpu(part, field, cpu) part_stat_get(part, field)
349 #define part_stat_read(part, field) part_stat_get(part, field)
351 static inline void part_stat_set_all(struct hd_struct
*part
, int value
)
353 memset(&part
->dkstats
, value
, sizeof(struct disk_stats
));
356 static inline int init_part_stats(struct hd_struct
*part
)
361 static inline void free_part_stats(struct hd_struct
*part
)
365 #endif /* CONFIG_SMP */
367 #define part_stat_read_msecs(part, which) \
368 div_u64(part_stat_read(part, nsecs[which]), NSEC_PER_MSEC)
370 #define part_stat_read_accum(part, field) \
371 (part_stat_read(part, field[STAT_READ]) + \
372 part_stat_read(part, field[STAT_WRITE]) + \
373 part_stat_read(part, field[STAT_DISCARD]))
375 #define __part_stat_add(part, field, addnd) \
376 (part_stat_get(part, field) += (addnd))
378 #define part_stat_add(part, field, addnd) do { \
379 __part_stat_add((part), field, addnd); \
380 if ((part)->partno) \
381 __part_stat_add(&part_to_disk((part))->part0, \
385 #define part_stat_dec(gendiskp, field) \
386 part_stat_add(gendiskp, field, -1)
387 #define part_stat_inc(gendiskp, field) \
388 part_stat_add(gendiskp, field, 1)
389 #define part_stat_sub(gendiskp, field, subnd) \
390 part_stat_add(gendiskp, field, -subnd)
392 #define part_stat_local_dec(gendiskp, field) \
393 local_dec(&(part_stat_get(gendiskp, field)))
394 #define part_stat_local_inc(gendiskp, field) \
395 local_inc(&(part_stat_get(gendiskp, field)))
396 #define part_stat_local_read(gendiskp, field) \
397 local_read(&(part_stat_get(gendiskp, field)))
398 #define part_stat_local_read_cpu(gendiskp, field, cpu) \
399 local_read(&(part_stat_get_cpu(gendiskp, field, cpu)))
401 unsigned int part_in_flight(struct request_queue
*q
, struct hd_struct
*part
);
402 void part_in_flight_rw(struct request_queue
*q
, struct hd_struct
*part
,
403 unsigned int inflight
[2]);
404 void part_dec_in_flight(struct request_queue
*q
, struct hd_struct
*part
,
406 void part_inc_in_flight(struct request_queue
*q
, struct hd_struct
*part
,
409 static inline struct partition_meta_info
*alloc_part_info(struct gendisk
*disk
)
412 return kzalloc_node(sizeof(struct partition_meta_info
),
413 GFP_KERNEL
, disk
->node_id
);
414 return kzalloc(sizeof(struct partition_meta_info
), GFP_KERNEL
);
417 static inline void free_part_info(struct hd_struct
*part
)
422 void update_io_ticks(struct hd_struct
*part
, unsigned long now
);
425 extern void device_add_disk(struct device
*parent
, struct gendisk
*disk
,
426 const struct attribute_group
**groups
);
427 static inline void add_disk(struct gendisk
*disk
)
429 device_add_disk(NULL
, disk
, NULL
);
431 extern void device_add_disk_no_queue_reg(struct device
*parent
, struct gendisk
*disk
);
432 static inline void add_disk_no_queue_reg(struct gendisk
*disk
)
434 device_add_disk_no_queue_reg(NULL
, disk
);
437 extern void del_gendisk(struct gendisk
*gp
);
438 extern struct gendisk
*get_gendisk(dev_t dev
, int *partno
);
439 extern struct block_device
*bdget_disk(struct gendisk
*disk
, int partno
);
441 extern void set_device_ro(struct block_device
*bdev
, int flag
);
442 extern void set_disk_ro(struct gendisk
*disk
, int flag
);
444 static inline int get_disk_ro(struct gendisk
*disk
)
446 return disk
->part0
.policy
;
449 extern void disk_block_events(struct gendisk
*disk
);
450 extern void disk_unblock_events(struct gendisk
*disk
);
451 extern void disk_flush_events(struct gendisk
*disk
, unsigned int mask
);
452 extern unsigned int disk_clear_events(struct gendisk
*disk
, unsigned int mask
);
454 /* drivers/char/random.c */
455 extern void add_disk_randomness(struct gendisk
*disk
) __latent_entropy
;
456 extern void rand_initialize_disk(struct gendisk
*disk
);
458 static inline sector_t
get_start_sect(struct block_device
*bdev
)
460 return bdev
->bd_part
->start_sect
;
462 static inline sector_t
get_capacity(struct gendisk
*disk
)
464 return disk
->part0
.nr_sects
;
466 static inline void set_capacity(struct gendisk
*disk
, sector_t size
)
468 disk
->part0
.nr_sects
= size
;
471 #ifdef CONFIG_SOLARIS_X86_PARTITION
473 #define SOLARIS_X86_NUMSLICE 16
474 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
476 struct solaris_x86_slice
{
477 __le16 s_tag
; /* ID tag of partition */
478 __le16 s_flag
; /* permission flags */
479 __le32 s_start
; /* start sector no of partition */
480 __le32 s_size
; /* # of blocks in partition */
483 struct solaris_x86_vtoc
{
484 unsigned int v_bootinfo
[3]; /* info needed by mboot (unsupported) */
485 __le32 v_sanity
; /* to verify vtoc sanity */
486 __le32 v_version
; /* layout version */
487 char v_volume
[8]; /* volume name */
488 __le16 v_sectorsz
; /* sector size in bytes */
489 __le16 v_nparts
; /* number of partitions */
490 unsigned int v_reserved
[10]; /* free space */
491 struct solaris_x86_slice
492 v_slice
[SOLARIS_X86_NUMSLICE
]; /* slice headers */
493 unsigned int timestamp
[SOLARIS_X86_NUMSLICE
]; /* timestamp (unsupported) */
494 char v_asciilabel
[128]; /* for compatibility */
497 #endif /* CONFIG_SOLARIS_X86_PARTITION */
499 #ifdef CONFIG_BSD_DISKLABEL
501 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
502 * updated by Marc Espie <Marc.Espie@openbsd.org>
505 /* check against BSD src/sys/sys/disklabel.h for consistency */
507 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
508 #define BSD_MAXPARTITIONS 16
509 #define OPENBSD_MAXPARTITIONS 16
510 #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
511 struct bsd_disklabel
{
512 __le32 d_magic
; /* the magic number */
513 __s16 d_type
; /* drive type */
514 __s16 d_subtype
; /* controller/d_type specific */
515 char d_typename
[16]; /* type name, e.g. "eagle" */
516 char d_packname
[16]; /* pack identifier */
517 __u32 d_secsize
; /* # of bytes per sector */
518 __u32 d_nsectors
; /* # of data sectors per track */
519 __u32 d_ntracks
; /* # of tracks per cylinder */
520 __u32 d_ncylinders
; /* # of data cylinders per unit */
521 __u32 d_secpercyl
; /* # of data sectors per cylinder */
522 __u32 d_secperunit
; /* # of data sectors per unit */
523 __u16 d_sparespertrack
; /* # of spare sectors per track */
524 __u16 d_sparespercyl
; /* # of spare sectors per cylinder */
525 __u32 d_acylinders
; /* # of alt. cylinders per unit */
526 __u16 d_rpm
; /* rotational speed */
527 __u16 d_interleave
; /* hardware sector interleave */
528 __u16 d_trackskew
; /* sector 0 skew, per track */
529 __u16 d_cylskew
; /* sector 0 skew, per cylinder */
530 __u32 d_headswitch
; /* head switch time, usec */
531 __u32 d_trkseek
; /* track-to-track seek, usec */
532 __u32 d_flags
; /* generic flags */
534 __u32 d_drivedata
[NDDATA
]; /* drive-type specific information */
536 __u32 d_spare
[NSPARE
]; /* reserved for future use */
537 __le32 d_magic2
; /* the magic number (again) */
538 __le16 d_checksum
; /* xor of data incl. partitions */
540 /* filesystem and partition information: */
541 __le16 d_npartitions
; /* number of partitions in following */
542 __le32 d_bbsize
; /* size of boot area at sn0, bytes */
543 __le32 d_sbsize
; /* max size of fs superblock, bytes */
544 struct bsd_partition
{ /* the partition table */
545 __le32 p_size
; /* number of sectors in partition */
546 __le32 p_offset
; /* starting sector */
547 __le32 p_fsize
; /* filesystem basic fragment size */
548 __u8 p_fstype
; /* filesystem type, see below */
549 __u8 p_frag
; /* filesystem fragments per block */
550 __le16 p_cpg
; /* filesystem cylinders per group */
551 } d_partitions
[BSD_MAXPARTITIONS
]; /* actually may be more */
554 #endif /* CONFIG_BSD_DISKLABEL */
556 #ifdef CONFIG_UNIXWARE_DISKLABEL
558 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
559 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
562 #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
563 #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
564 #define UNIXWARE_NUMSLICE 16
565 #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
567 struct unixware_slice
{
568 __le16 s_label
; /* label */
569 __le16 s_flags
; /* permission flags */
570 __le32 start_sect
; /* starting sector */
571 __le32 nr_sects
; /* number of sectors in slice */
574 struct unixware_disklabel
{
575 __le32 d_type
; /* drive type */
576 __le32 d_magic
; /* the magic number */
577 __le32 d_version
; /* version number */
578 char d_serial
[12]; /* serial number of the device */
579 __le32 d_ncylinders
; /* # of data cylinders per device */
580 __le32 d_ntracks
; /* # of tracks per cylinder */
581 __le32 d_nsectors
; /* # of data sectors per track */
582 __le32 d_secsize
; /* # of bytes per sector */
583 __le32 d_part_start
; /* # of first sector of this partition */
584 __le32 d_unknown1
[12]; /* ? */
585 __le32 d_alt_tbl
; /* byte offset of alternate table */
586 __le32 d_alt_len
; /* byte length of alternate table */
587 __le32 d_phys_cyl
; /* # of physical cylinders per device */
588 __le32 d_phys_trk
; /* # of physical tracks per cylinder */
589 __le32 d_phys_sec
; /* # of physical sectors per track */
590 __le32 d_phys_bytes
; /* # of physical bytes per sector */
591 __le32 d_unknown2
; /* ? */
592 __le32 d_unknown3
; /* ? */
593 __le32 d_pad
[8]; /* pad */
595 struct unixware_vtoc
{
596 __le32 v_magic
; /* the magic number */
597 __le32 v_version
; /* version number */
598 char v_name
[8]; /* volume name */
599 __le16 v_nslices
; /* # of slices */
600 __le16 v_unknown1
; /* ? */
601 __le32 v_reserved
[10]; /* reserved */
602 struct unixware_slice
603 v_slice
[UNIXWARE_NUMSLICE
]; /* slice headers */
608 #endif /* CONFIG_UNIXWARE_DISKLABEL */
610 #ifdef CONFIG_MINIX_SUBPARTITION
611 # define MINIX_NR_SUBPARTITIONS 4
612 #endif /* CONFIG_MINIX_SUBPARTITION */
614 #define ADDPART_FLAG_NONE 0
615 #define ADDPART_FLAG_RAID 1
616 #define ADDPART_FLAG_WHOLEDISK 2
618 extern int blk_alloc_devt(struct hd_struct
*part
, dev_t
*devt
);
619 extern void blk_free_devt(dev_t devt
);
620 extern void blk_invalidate_devt(dev_t devt
);
621 extern dev_t
blk_lookup_devt(const char *name
, int partno
);
622 extern char *disk_name (struct gendisk
*hd
, int partno
, char *buf
);
624 extern int disk_expand_part_tbl(struct gendisk
*disk
, int target
);
625 extern int rescan_partitions(struct gendisk
*disk
, struct block_device
*bdev
);
626 extern int invalidate_partitions(struct gendisk
*disk
, struct block_device
*bdev
);
627 extern struct hd_struct
* __must_check
add_partition(struct gendisk
*disk
,
628 int partno
, sector_t start
,
629 sector_t len
, int flags
,
630 struct partition_meta_info
632 extern void __delete_partition(struct percpu_ref
*);
633 extern void delete_partition(struct gendisk
*, int);
634 extern void printk_all_partitions(void);
636 extern struct gendisk
*__alloc_disk_node(int minors
, int node_id
);
637 extern struct kobject
*get_disk_and_module(struct gendisk
*disk
);
638 extern void put_disk(struct gendisk
*disk
);
639 extern void put_disk_and_module(struct gendisk
*disk
);
640 extern void blk_register_region(dev_t devt
, unsigned long range
,
641 struct module
*module
,
642 struct kobject
*(*probe
)(dev_t
, int *, void *),
643 int (*lock
)(dev_t
, void *),
645 extern void blk_unregister_region(dev_t devt
, unsigned long range
);
647 extern ssize_t
part_size_show(struct device
*dev
,
648 struct device_attribute
*attr
, char *buf
);
649 extern ssize_t
part_stat_show(struct device
*dev
,
650 struct device_attribute
*attr
, char *buf
);
651 extern ssize_t
part_inflight_show(struct device
*dev
,
652 struct device_attribute
*attr
, char *buf
);
653 #ifdef CONFIG_FAIL_MAKE_REQUEST
654 extern ssize_t
part_fail_show(struct device
*dev
,
655 struct device_attribute
*attr
, char *buf
);
656 extern ssize_t
part_fail_store(struct device
*dev
,
657 struct device_attribute
*attr
,
658 const char *buf
, size_t count
);
659 #endif /* CONFIG_FAIL_MAKE_REQUEST */
661 #define alloc_disk_node(minors, node_id) \
663 static struct lock_class_key __key; \
664 const char *__name; \
665 struct gendisk *__disk; \
667 __name = "(gendisk_completion)"#minors"("#node_id")"; \
669 __disk = __alloc_disk_node(minors, node_id); \
672 lockdep_init_map(&__disk->lockdep_map, __name, &__key, 0); \
677 #define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)
679 static inline int hd_ref_init(struct hd_struct
*part
)
681 if (percpu_ref_init(&part
->ref
, __delete_partition
, 0,
687 static inline void hd_struct_get(struct hd_struct
*part
)
689 percpu_ref_get(&part
->ref
);
692 static inline int hd_struct_try_get(struct hd_struct
*part
)
694 return percpu_ref_tryget_live(&part
->ref
);
697 static inline void hd_struct_put(struct hd_struct
*part
)
699 percpu_ref_put(&part
->ref
);
702 static inline void hd_struct_kill(struct hd_struct
*part
)
704 percpu_ref_kill(&part
->ref
);
707 static inline void hd_free_part(struct hd_struct
*part
)
709 free_part_stats(part
);
710 free_part_info(part
);
711 percpu_ref_exit(&part
->ref
);
715 * Any access of part->nr_sects which is not protected by partition
716 * bd_mutex or gendisk bdev bd_mutex, should be done using this
719 * Code written along the lines of i_size_read() and i_size_write().
720 * CONFIG_PREEMPT case optimizes the case of UP kernel with preemption
723 static inline sector_t
part_nr_sects_read(struct hd_struct
*part
)
725 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
729 seq
= read_seqcount_begin(&part
->nr_sects_seq
);
730 nr_sects
= part
->nr_sects
;
731 } while (read_seqcount_retry(&part
->nr_sects_seq
, seq
));
733 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
737 nr_sects
= part
->nr_sects
;
741 return part
->nr_sects
;
746 * Should be called with mutex lock held (typically bd_mutex) of partition
747 * to provide mutual exlusion among writers otherwise seqcount might be
748 * left in wrong state leaving the readers spinning infinitely.
750 static inline void part_nr_sects_write(struct hd_struct
*part
, sector_t size
)
752 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
753 write_seqcount_begin(&part
->nr_sects_seq
);
754 part
->nr_sects
= size
;
755 write_seqcount_end(&part
->nr_sects_seq
);
756 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
758 part
->nr_sects
= size
;
761 part
->nr_sects
= size
;
765 #if defined(CONFIG_BLK_DEV_INTEGRITY)
766 extern void blk_integrity_add(struct gendisk
*);
767 extern void blk_integrity_del(struct gendisk
*);
768 #else /* CONFIG_BLK_DEV_INTEGRITY */
769 static inline void blk_integrity_add(struct gendisk
*disk
) { }
770 static inline void blk_integrity_del(struct gendisk
*disk
) { }
771 #endif /* CONFIG_BLK_DEV_INTEGRITY */
773 #else /* CONFIG_BLOCK */
775 static inline void printk_all_partitions(void) { }
777 static inline dev_t
blk_lookup_devt(const char *name
, int partno
)
779 dev_t devt
= MKDEV(0, 0);
782 #endif /* CONFIG_BLOCK */
784 #endif /* _LINUX_GENHD_H */