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 bool disk_has_partitions(struct gendisk
*disk
)
253 if (rcu_dereference(disk
->part_tbl
)->len
> 1)
260 static inline dev_t
disk_devt(struct gendisk
*disk
)
262 return MKDEV(disk
->major
, disk
->first_minor
);
265 static inline dev_t
part_devt(struct hd_struct
*part
)
267 return part_to_dev(part
)->devt
;
270 extern struct hd_struct
*__disk_get_part(struct gendisk
*disk
, int partno
);
271 extern struct hd_struct
*disk_get_part(struct gendisk
*disk
, int partno
);
273 static inline void disk_put_part(struct hd_struct
*part
)
276 put_device(part_to_dev(part
));
280 * Smarter partition iterator without context limits.
282 #define DISK_PITER_REVERSE (1 << 0) /* iterate in the reverse direction */
283 #define DISK_PITER_INCL_EMPTY (1 << 1) /* include 0-sized parts */
284 #define DISK_PITER_INCL_PART0 (1 << 2) /* include partition 0 */
285 #define DISK_PITER_INCL_EMPTY_PART0 (1 << 3) /* include empty partition 0 */
287 struct disk_part_iter
{
288 struct gendisk
*disk
;
289 struct hd_struct
*part
;
294 extern void disk_part_iter_init(struct disk_part_iter
*piter
,
295 struct gendisk
*disk
, unsigned int flags
);
296 extern struct hd_struct
*disk_part_iter_next(struct disk_part_iter
*piter
);
297 extern void disk_part_iter_exit(struct disk_part_iter
*piter
);
299 extern struct hd_struct
*disk_map_sector_rcu(struct gendisk
*disk
,
303 * Macros to operate on percpu disk statistics:
305 * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters
306 * and should be called between disk_stat_lock() and
307 * disk_stat_unlock().
309 * part_stat_read() can be called at any time.
311 * part_stat_{add|set_all}() and {init|free}_part_stats are for
315 #define part_stat_lock() ({ rcu_read_lock(); get_cpu(); })
316 #define part_stat_unlock() do { put_cpu(); rcu_read_unlock(); } while (0)
318 #define part_stat_get_cpu(part, field, cpu) \
319 (per_cpu_ptr((part)->dkstats, (cpu))->field)
321 #define part_stat_get(part, field) \
322 part_stat_get_cpu(part, field, smp_processor_id())
324 #define part_stat_read(part, field) \
326 typeof((part)->dkstats->field) res = 0; \
328 for_each_possible_cpu(_cpu) \
329 res += per_cpu_ptr((part)->dkstats, _cpu)->field; \
333 static inline void part_stat_set_all(struct hd_struct
*part
, int value
)
337 for_each_possible_cpu(i
)
338 memset(per_cpu_ptr(part
->dkstats
, i
), value
,
339 sizeof(struct disk_stats
));
342 static inline int init_part_stats(struct hd_struct
*part
)
344 part
->dkstats
= alloc_percpu(struct disk_stats
);
350 static inline void free_part_stats(struct hd_struct
*part
)
352 free_percpu(part
->dkstats
);
355 #else /* !CONFIG_SMP */
356 #define part_stat_lock() ({ rcu_read_lock(); 0; })
357 #define part_stat_unlock() rcu_read_unlock()
359 #define part_stat_get(part, field) ((part)->dkstats.field)
360 #define part_stat_get_cpu(part, field, cpu) part_stat_get(part, field)
361 #define part_stat_read(part, field) part_stat_get(part, field)
363 static inline void part_stat_set_all(struct hd_struct
*part
, int value
)
365 memset(&part
->dkstats
, value
, sizeof(struct disk_stats
));
368 static inline int init_part_stats(struct hd_struct
*part
)
373 static inline void free_part_stats(struct hd_struct
*part
)
377 #endif /* CONFIG_SMP */
379 #define part_stat_read_msecs(part, which) \
380 div_u64(part_stat_read(part, nsecs[which]), NSEC_PER_MSEC)
382 #define part_stat_read_accum(part, field) \
383 (part_stat_read(part, field[STAT_READ]) + \
384 part_stat_read(part, field[STAT_WRITE]) + \
385 part_stat_read(part, field[STAT_DISCARD]))
387 #define __part_stat_add(part, field, addnd) \
388 (part_stat_get(part, field) += (addnd))
390 #define part_stat_add(part, field, addnd) do { \
391 __part_stat_add((part), field, addnd); \
392 if ((part)->partno) \
393 __part_stat_add(&part_to_disk((part))->part0, \
397 #define part_stat_dec(gendiskp, field) \
398 part_stat_add(gendiskp, field, -1)
399 #define part_stat_inc(gendiskp, field) \
400 part_stat_add(gendiskp, field, 1)
401 #define part_stat_sub(gendiskp, field, subnd) \
402 part_stat_add(gendiskp, field, -subnd)
404 #define part_stat_local_dec(gendiskp, field) \
405 local_dec(&(part_stat_get(gendiskp, field)))
406 #define part_stat_local_inc(gendiskp, field) \
407 local_inc(&(part_stat_get(gendiskp, field)))
408 #define part_stat_local_read(gendiskp, field) \
409 local_read(&(part_stat_get(gendiskp, field)))
410 #define part_stat_local_read_cpu(gendiskp, field, cpu) \
411 local_read(&(part_stat_get_cpu(gendiskp, field, cpu)))
413 unsigned int part_in_flight(struct request_queue
*q
, struct hd_struct
*part
);
414 void part_in_flight_rw(struct request_queue
*q
, struct hd_struct
*part
,
415 unsigned int inflight
[2]);
416 void part_dec_in_flight(struct request_queue
*q
, struct hd_struct
*part
,
418 void part_inc_in_flight(struct request_queue
*q
, struct hd_struct
*part
,
421 static inline struct partition_meta_info
*alloc_part_info(struct gendisk
*disk
)
424 return kzalloc_node(sizeof(struct partition_meta_info
),
425 GFP_KERNEL
, disk
->node_id
);
426 return kzalloc(sizeof(struct partition_meta_info
), GFP_KERNEL
);
429 static inline void free_part_info(struct hd_struct
*part
)
434 void update_io_ticks(struct hd_struct
*part
, unsigned long now
);
437 extern void device_add_disk(struct device
*parent
, struct gendisk
*disk
,
438 const struct attribute_group
**groups
);
439 static inline void add_disk(struct gendisk
*disk
)
441 device_add_disk(NULL
, disk
, NULL
);
443 extern void device_add_disk_no_queue_reg(struct device
*parent
, struct gendisk
*disk
);
444 static inline void add_disk_no_queue_reg(struct gendisk
*disk
)
446 device_add_disk_no_queue_reg(NULL
, disk
);
449 extern void del_gendisk(struct gendisk
*gp
);
450 extern struct gendisk
*get_gendisk(dev_t dev
, int *partno
);
451 extern struct block_device
*bdget_disk(struct gendisk
*disk
, int partno
);
453 extern void set_device_ro(struct block_device
*bdev
, int flag
);
454 extern void set_disk_ro(struct gendisk
*disk
, int flag
);
456 static inline int get_disk_ro(struct gendisk
*disk
)
458 return disk
->part0
.policy
;
461 extern void disk_block_events(struct gendisk
*disk
);
462 extern void disk_unblock_events(struct gendisk
*disk
);
463 extern void disk_flush_events(struct gendisk
*disk
, unsigned int mask
);
464 extern unsigned int disk_clear_events(struct gendisk
*disk
, unsigned int mask
);
466 /* drivers/char/random.c */
467 extern void add_disk_randomness(struct gendisk
*disk
) __latent_entropy
;
468 extern void rand_initialize_disk(struct gendisk
*disk
);
470 static inline sector_t
get_start_sect(struct block_device
*bdev
)
472 return bdev
->bd_part
->start_sect
;
474 static inline sector_t
get_capacity(struct gendisk
*disk
)
476 return disk
->part0
.nr_sects
;
478 static inline void set_capacity(struct gendisk
*disk
, sector_t size
)
480 disk
->part0
.nr_sects
= size
;
483 #ifdef CONFIG_SOLARIS_X86_PARTITION
485 #define SOLARIS_X86_NUMSLICE 16
486 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
488 struct solaris_x86_slice
{
489 __le16 s_tag
; /* ID tag of partition */
490 __le16 s_flag
; /* permission flags */
491 __le32 s_start
; /* start sector no of partition */
492 __le32 s_size
; /* # of blocks in partition */
495 struct solaris_x86_vtoc
{
496 unsigned int v_bootinfo
[3]; /* info needed by mboot (unsupported) */
497 __le32 v_sanity
; /* to verify vtoc sanity */
498 __le32 v_version
; /* layout version */
499 char v_volume
[8]; /* volume name */
500 __le16 v_sectorsz
; /* sector size in bytes */
501 __le16 v_nparts
; /* number of partitions */
502 unsigned int v_reserved
[10]; /* free space */
503 struct solaris_x86_slice
504 v_slice
[SOLARIS_X86_NUMSLICE
]; /* slice headers */
505 unsigned int timestamp
[SOLARIS_X86_NUMSLICE
]; /* timestamp (unsupported) */
506 char v_asciilabel
[128]; /* for compatibility */
509 #endif /* CONFIG_SOLARIS_X86_PARTITION */
511 #ifdef CONFIG_BSD_DISKLABEL
513 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
514 * updated by Marc Espie <Marc.Espie@openbsd.org>
517 /* check against BSD src/sys/sys/disklabel.h for consistency */
519 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
520 #define BSD_MAXPARTITIONS 16
521 #define OPENBSD_MAXPARTITIONS 16
522 #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
523 struct bsd_disklabel
{
524 __le32 d_magic
; /* the magic number */
525 __s16 d_type
; /* drive type */
526 __s16 d_subtype
; /* controller/d_type specific */
527 char d_typename
[16]; /* type name, e.g. "eagle" */
528 char d_packname
[16]; /* pack identifier */
529 __u32 d_secsize
; /* # of bytes per sector */
530 __u32 d_nsectors
; /* # of data sectors per track */
531 __u32 d_ntracks
; /* # of tracks per cylinder */
532 __u32 d_ncylinders
; /* # of data cylinders per unit */
533 __u32 d_secpercyl
; /* # of data sectors per cylinder */
534 __u32 d_secperunit
; /* # of data sectors per unit */
535 __u16 d_sparespertrack
; /* # of spare sectors per track */
536 __u16 d_sparespercyl
; /* # of spare sectors per cylinder */
537 __u32 d_acylinders
; /* # of alt. cylinders per unit */
538 __u16 d_rpm
; /* rotational speed */
539 __u16 d_interleave
; /* hardware sector interleave */
540 __u16 d_trackskew
; /* sector 0 skew, per track */
541 __u16 d_cylskew
; /* sector 0 skew, per cylinder */
542 __u32 d_headswitch
; /* head switch time, usec */
543 __u32 d_trkseek
; /* track-to-track seek, usec */
544 __u32 d_flags
; /* generic flags */
546 __u32 d_drivedata
[NDDATA
]; /* drive-type specific information */
548 __u32 d_spare
[NSPARE
]; /* reserved for future use */
549 __le32 d_magic2
; /* the magic number (again) */
550 __le16 d_checksum
; /* xor of data incl. partitions */
552 /* filesystem and partition information: */
553 __le16 d_npartitions
; /* number of partitions in following */
554 __le32 d_bbsize
; /* size of boot area at sn0, bytes */
555 __le32 d_sbsize
; /* max size of fs superblock, bytes */
556 struct bsd_partition
{ /* the partition table */
557 __le32 p_size
; /* number of sectors in partition */
558 __le32 p_offset
; /* starting sector */
559 __le32 p_fsize
; /* filesystem basic fragment size */
560 __u8 p_fstype
; /* filesystem type, see below */
561 __u8 p_frag
; /* filesystem fragments per block */
562 __le16 p_cpg
; /* filesystem cylinders per group */
563 } d_partitions
[BSD_MAXPARTITIONS
]; /* actually may be more */
566 #endif /* CONFIG_BSD_DISKLABEL */
568 #ifdef CONFIG_UNIXWARE_DISKLABEL
570 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
571 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
574 #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
575 #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
576 #define UNIXWARE_NUMSLICE 16
577 #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
579 struct unixware_slice
{
580 __le16 s_label
; /* label */
581 __le16 s_flags
; /* permission flags */
582 __le32 start_sect
; /* starting sector */
583 __le32 nr_sects
; /* number of sectors in slice */
586 struct unixware_disklabel
{
587 __le32 d_type
; /* drive type */
588 __le32 d_magic
; /* the magic number */
589 __le32 d_version
; /* version number */
590 char d_serial
[12]; /* serial number of the device */
591 __le32 d_ncylinders
; /* # of data cylinders per device */
592 __le32 d_ntracks
; /* # of tracks per cylinder */
593 __le32 d_nsectors
; /* # of data sectors per track */
594 __le32 d_secsize
; /* # of bytes per sector */
595 __le32 d_part_start
; /* # of first sector of this partition */
596 __le32 d_unknown1
[12]; /* ? */
597 __le32 d_alt_tbl
; /* byte offset of alternate table */
598 __le32 d_alt_len
; /* byte length of alternate table */
599 __le32 d_phys_cyl
; /* # of physical cylinders per device */
600 __le32 d_phys_trk
; /* # of physical tracks per cylinder */
601 __le32 d_phys_sec
; /* # of physical sectors per track */
602 __le32 d_phys_bytes
; /* # of physical bytes per sector */
603 __le32 d_unknown2
; /* ? */
604 __le32 d_unknown3
; /* ? */
605 __le32 d_pad
[8]; /* pad */
607 struct unixware_vtoc
{
608 __le32 v_magic
; /* the magic number */
609 __le32 v_version
; /* version number */
610 char v_name
[8]; /* volume name */
611 __le16 v_nslices
; /* # of slices */
612 __le16 v_unknown1
; /* ? */
613 __le32 v_reserved
[10]; /* reserved */
614 struct unixware_slice
615 v_slice
[UNIXWARE_NUMSLICE
]; /* slice headers */
620 #endif /* CONFIG_UNIXWARE_DISKLABEL */
622 #ifdef CONFIG_MINIX_SUBPARTITION
623 # define MINIX_NR_SUBPARTITIONS 4
624 #endif /* CONFIG_MINIX_SUBPARTITION */
626 #define ADDPART_FLAG_NONE 0
627 #define ADDPART_FLAG_RAID 1
628 #define ADDPART_FLAG_WHOLEDISK 2
630 extern int blk_alloc_devt(struct hd_struct
*part
, dev_t
*devt
);
631 extern void blk_free_devt(dev_t devt
);
632 extern void blk_invalidate_devt(dev_t devt
);
633 extern dev_t
blk_lookup_devt(const char *name
, int partno
);
634 extern char *disk_name (struct gendisk
*hd
, int partno
, char *buf
);
636 int bdev_disk_changed(struct block_device
*bdev
, bool invalidate
);
637 int blk_add_partitions(struct gendisk
*disk
, struct block_device
*bdev
);
638 int blk_drop_partitions(struct gendisk
*disk
, struct block_device
*bdev
);
639 extern int disk_expand_part_tbl(struct gendisk
*disk
, int target
);
640 extern struct hd_struct
* __must_check
add_partition(struct gendisk
*disk
,
641 int partno
, sector_t start
,
642 sector_t len
, int flags
,
643 struct partition_meta_info
645 extern void __delete_partition(struct percpu_ref
*);
646 extern void delete_partition(struct gendisk
*, int);
647 extern void printk_all_partitions(void);
649 extern struct gendisk
*__alloc_disk_node(int minors
, int node_id
);
650 extern struct kobject
*get_disk_and_module(struct gendisk
*disk
);
651 extern void put_disk(struct gendisk
*disk
);
652 extern void put_disk_and_module(struct gendisk
*disk
);
653 extern void blk_register_region(dev_t devt
, unsigned long range
,
654 struct module
*module
,
655 struct kobject
*(*probe
)(dev_t
, int *, void *),
656 int (*lock
)(dev_t
, void *),
658 extern void blk_unregister_region(dev_t devt
, unsigned long range
);
660 extern ssize_t
part_size_show(struct device
*dev
,
661 struct device_attribute
*attr
, char *buf
);
662 extern ssize_t
part_stat_show(struct device
*dev
,
663 struct device_attribute
*attr
, char *buf
);
664 extern ssize_t
part_inflight_show(struct device
*dev
,
665 struct device_attribute
*attr
, char *buf
);
666 #ifdef CONFIG_FAIL_MAKE_REQUEST
667 extern ssize_t
part_fail_show(struct device
*dev
,
668 struct device_attribute
*attr
, char *buf
);
669 extern ssize_t
part_fail_store(struct device
*dev
,
670 struct device_attribute
*attr
,
671 const char *buf
, size_t count
);
672 #endif /* CONFIG_FAIL_MAKE_REQUEST */
674 #define alloc_disk_node(minors, node_id) \
676 static struct lock_class_key __key; \
677 const char *__name; \
678 struct gendisk *__disk; \
680 __name = "(gendisk_completion)"#minors"("#node_id")"; \
682 __disk = __alloc_disk_node(minors, node_id); \
685 lockdep_init_map(&__disk->lockdep_map, __name, &__key, 0); \
690 #define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)
692 static inline int hd_ref_init(struct hd_struct
*part
)
694 if (percpu_ref_init(&part
->ref
, __delete_partition
, 0,
700 static inline void hd_struct_get(struct hd_struct
*part
)
702 percpu_ref_get(&part
->ref
);
705 static inline int hd_struct_try_get(struct hd_struct
*part
)
707 return percpu_ref_tryget_live(&part
->ref
);
710 static inline void hd_struct_put(struct hd_struct
*part
)
712 percpu_ref_put(&part
->ref
);
715 static inline void hd_struct_kill(struct hd_struct
*part
)
717 percpu_ref_kill(&part
->ref
);
720 static inline void hd_free_part(struct hd_struct
*part
)
722 free_part_stats(part
);
723 free_part_info(part
);
724 percpu_ref_exit(&part
->ref
);
728 * Any access of part->nr_sects which is not protected by partition
729 * bd_mutex or gendisk bdev bd_mutex, should be done using this
732 * Code written along the lines of i_size_read() and i_size_write().
733 * CONFIG_PREEMPTION case optimizes the case of UP kernel with preemption
736 static inline sector_t
part_nr_sects_read(struct hd_struct
*part
)
738 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
742 seq
= read_seqcount_begin(&part
->nr_sects_seq
);
743 nr_sects
= part
->nr_sects
;
744 } while (read_seqcount_retry(&part
->nr_sects_seq
, seq
));
746 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
750 nr_sects
= part
->nr_sects
;
754 return part
->nr_sects
;
759 * Should be called with mutex lock held (typically bd_mutex) of partition
760 * to provide mutual exlusion among writers otherwise seqcount might be
761 * left in wrong state leaving the readers spinning infinitely.
763 static inline void part_nr_sects_write(struct hd_struct
*part
, sector_t size
)
765 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
766 write_seqcount_begin(&part
->nr_sects_seq
);
767 part
->nr_sects
= size
;
768 write_seqcount_end(&part
->nr_sects_seq
);
769 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
771 part
->nr_sects
= size
;
774 part
->nr_sects
= size
;
778 #if defined(CONFIG_BLK_DEV_INTEGRITY)
779 extern void blk_integrity_add(struct gendisk
*);
780 extern void blk_integrity_del(struct gendisk
*);
781 #else /* CONFIG_BLK_DEV_INTEGRITY */
782 static inline void blk_integrity_add(struct gendisk
*disk
) { }
783 static inline void blk_integrity_del(struct gendisk
*disk
) { }
784 #endif /* CONFIG_BLK_DEV_INTEGRITY */
786 #else /* CONFIG_BLOCK */
788 static inline void printk_all_partitions(void) { }
790 static inline dev_t
blk_lookup_devt(const char *name
, int partno
)
792 dev_t devt
= MKDEV(0, 0);
795 #endif /* CONFIG_BLOCK */
797 #endif /* _LINUX_GENHD_H */