Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_GENHD_H |
| 3 | #define _LINUX_GENHD_H |
| 4 | |
| 5 | /* |
| 6 | * genhd.h Copyright (C) 1992 Drew Eckhardt |
| 7 | * Generic hard disk header file by |
| 8 | * Drew Eckhardt |
| 9 | * |
| 10 | * <drew@colorado.edu> |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/types.h> |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 14 | #include <linux/kdev_t.h> |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 15 | #include <linux/rcupdate.h> |
Will Drewry | 6d1d805 | 2010-08-31 15:47:05 -0500 | [diff] [blame] | 16 | #include <linux/slab.h> |
Ming Lei | 6c71013 | 2015-07-16 11:16:45 +0800 | [diff] [blame] | 17 | #include <linux/percpu-refcount.h> |
Andy Shevchenko | 6357978 | 2016-05-20 17:01:24 -0700 | [diff] [blame] | 18 | #include <linux/uuid.h> |
Michael Callahan | dbae2c5 | 2018-07-18 04:47:38 -0700 | [diff] [blame] | 19 | #include <linux/blk_types.h> |
Mikulas Patocka | 1226b8d | 2018-12-06 11:41:20 -0500 | [diff] [blame] | 20 | #include <asm/local.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 22 | #ifdef CONFIG_BLOCK |
| 23 | |
Tejun Heo | 548b10e | 2008-08-29 09:01:47 +0200 | [diff] [blame] | 24 | #define dev_to_disk(device) container_of((device), struct gendisk, part0.__dev) |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 25 | #define dev_to_part(device) container_of((device), struct hd_struct, __dev) |
Tejun Heo | 548b10e | 2008-08-29 09:01:47 +0200 | [diff] [blame] | 26 | #define disk_to_dev(disk) (&(disk)->part0.__dev) |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 27 | #define part_to_dev(part) (&((part)->__dev)) |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 28 | |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 29 | extern struct device_type part_type; |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 30 | extern struct class block_class; |
| 31 | |
Tejun Heo | 689d6fa | 2008-08-25 19:56:16 +0900 | [diff] [blame] | 32 | #define DISK_MAX_PARTS 256 |
Tejun Heo | 3e1a7ff | 2008-08-25 19:56:17 +0900 | [diff] [blame] | 33 | #define DISK_NAME_LEN 32 |
Tejun Heo | 689d6fa | 2008-08-25 19:56:16 +0900 | [diff] [blame] | 34 | |
David Woodhouse | 34186ef | 2006-04-25 14:07:57 +0100 | [diff] [blame] | 35 | #include <linux/major.h> |
| 36 | #include <linux/device.h> |
| 37 | #include <linux/smp.h> |
| 38 | #include <linux/string.h> |
| 39 | #include <linux/fs.h> |
Kristen Carlson Accardi | 8ce7ad7b | 2007-05-23 13:57:38 -0700 | [diff] [blame] | 40 | #include <linux/workqueue.h> |
David Woodhouse | 34186ef | 2006-04-25 14:07:57 +0100 | [diff] [blame] | 41 | |
Jerome Marchand | ea5c48a | 2008-02-08 11:04:09 +0100 | [diff] [blame] | 42 | struct disk_stats { |
Omar Sandoval | b57e99b | 2018-09-21 16:44:34 -0700 | [diff] [blame] | 43 | u64 nsecs[NR_STAT_GROUPS]; |
Michael Callahan | dbae2c5 | 2018-07-18 04:47:38 -0700 | [diff] [blame] | 44 | unsigned long sectors[NR_STAT_GROUPS]; |
| 45 | unsigned long ios[NR_STAT_GROUPS]; |
| 46 | unsigned long merges[NR_STAT_GROUPS]; |
Jerome Marchand | ea5c48a | 2008-02-08 11:04:09 +0100 | [diff] [blame] | 47 | unsigned long io_ticks; |
Mikulas Patocka | 1226b8d | 2018-12-06 11:41:20 -0500 | [diff] [blame] | 48 | local_t in_flight[2]; |
Jerome Marchand | ea5c48a | 2008-02-08 11:04:09 +0100 | [diff] [blame] | 49 | }; |
Will Drewry | 6d1d805 | 2010-08-31 15:47:05 -0500 | [diff] [blame] | 50 | |
| 51 | #define PARTITION_META_INFO_VOLNAMELTH 64 |
Stephen Warren | 1ad7e89 | 2012-11-08 16:12:25 -0800 | [diff] [blame] | 52 | /* |
| 53 | * Enough for the string representation of any kind of UUID plus NULL. |
| 54 | * EFI UUID is 36 characters. MSDOS UUID is 11 characters. |
| 55 | */ |
Andy Shevchenko | 6357978 | 2016-05-20 17:01:24 -0700 | [diff] [blame] | 56 | #define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1) |
Will Drewry | 6d1d805 | 2010-08-31 15:47:05 -0500 | [diff] [blame] | 57 | |
| 58 | struct partition_meta_info { |
Stephen Warren | 1ad7e89 | 2012-11-08 16:12:25 -0800 | [diff] [blame] | 59 | char uuid[PARTITION_META_INFO_UUIDLTH]; |
Will Drewry | 6d1d805 | 2010-08-31 15:47:05 -0500 | [diff] [blame] | 60 | u8 volname[PARTITION_META_INFO_VOLNAMELTH]; |
| 61 | }; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | struct hd_struct { |
| 64 | sector_t start_sect; |
Vivek Goyal | c83f6bf | 2012-08-01 12:24:18 +0200 | [diff] [blame] | 65 | /* |
| 66 | * nr_sects is protected by sequence counter. One might extend a |
| 67 | * partition while IO is happening to it and update of nr_sects |
| 68 | * can be non-atomic on 32bit machines with 64bit sector_t. |
| 69 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | sector_t nr_sects; |
Vivek Goyal | c83f6bf | 2012-08-01 12:24:18 +0200 | [diff] [blame] | 71 | seqcount_t nr_sects_seq; |
Martin K. Petersen | c72758f | 2009-05-22 17:17:53 -0400 | [diff] [blame] | 72 | sector_t alignment_offset; |
Jens Axboe | a1706ac | 2011-05-30 07:42:51 +0200 | [diff] [blame] | 73 | unsigned int discard_alignment; |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 74 | struct device __dev; |
Jun'ichi Nomura | 6a4d44c | 2006-03-27 01:17:55 -0800 | [diff] [blame] | 75 | struct kobject *holder_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | int policy, partno; |
Will Drewry | 6d1d805 | 2010-08-31 15:47:05 -0500 | [diff] [blame] | 77 | struct partition_meta_info *info; |
Akinobu Mita | c17bb49 | 2006-12-08 02:39:46 -0800 | [diff] [blame] | 78 | #ifdef CONFIG_FAIL_MAKE_REQUEST |
| 79 | int make_it_fail; |
| 80 | #endif |
Jerome Marchand | ea5c48a | 2008-02-08 11:04:09 +0100 | [diff] [blame] | 81 | unsigned long stamp; |
Jerome Marchand | ea5c48a | 2008-02-08 11:04:09 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_SMP |
Tejun Heo | 43cf38e | 2010-02-02 14:38:57 +0900 | [diff] [blame] | 83 | struct disk_stats __percpu *dkstats; |
Jerome Marchand | ea5c48a | 2008-02-08 11:04:09 +0100 | [diff] [blame] | 84 | #else |
| 85 | struct disk_stats dkstats; |
| 86 | #endif |
Ming Lei | 6c71013 | 2015-07-16 11:16:45 +0800 | [diff] [blame] | 87 | struct percpu_ref ref; |
Yufen Yu | 94a2c3a | 2018-11-28 16:42:01 +0800 | [diff] [blame] | 88 | struct rcu_work rcu_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Stephen Kitt | 9243c6f | 2020-03-07 15:56:59 +0100 | [diff] [blame] | 91 | /** |
| 92 | * DOC: genhd capability flags |
| 93 | * |
| 94 | * ``GENHD_FL_REMOVABLE`` (0x0001): indicates that the block device |
| 95 | * gives access to removable media. |
| 96 | * When set, the device remains present even when media is not |
| 97 | * inserted. |
| 98 | * Must not be set for devices which are removed entirely when the |
| 99 | * media is removed. |
| 100 | * |
| 101 | * ``GENHD_FL_CD`` (0x0008): the block device is a CD-ROM-style |
| 102 | * device. |
| 103 | * Affects responses to the ``CDROM_GET_CAPABILITY`` ioctl. |
| 104 | * |
| 105 | * ``GENHD_FL_UP`` (0x0010): indicates that the block device is "up", |
| 106 | * with a similar meaning to network interfaces. |
| 107 | * |
| 108 | * ``GENHD_FL_SUPPRESS_PARTITION_INFO`` (0x0020): don't include |
| 109 | * partition information in ``/proc/partitions`` or in the output of |
| 110 | * printk_all_partitions(). |
| 111 | * Used for the null block device and some MMC devices. |
| 112 | * |
| 113 | * ``GENHD_FL_EXT_DEVT`` (0x0040): the driver supports extended |
| 114 | * dynamic ``dev_t``, i.e. it wants extended device numbers |
| 115 | * (``BLOCK_EXT_MAJOR``). |
| 116 | * This affects the maximum number of partitions. |
| 117 | * |
| 118 | * ``GENHD_FL_NATIVE_CAPACITY`` (0x0080): based on information in the |
| 119 | * partition table, the device's capacity has been extended to its |
| 120 | * native capacity; i.e. the device has hidden capacity used by one |
| 121 | * of the partitions (this is a flag used so that native capacity is |
| 122 | * only ever unlocked once). |
| 123 | * |
| 124 | * ``GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE`` (0x0100): event polling is |
| 125 | * blocked whenever a writer holds an exclusive lock. |
| 126 | * |
| 127 | * ``GENHD_FL_NO_PART_SCAN`` (0x0200): partition scanning is disabled. |
| 128 | * Used for loop devices in their default settings and some MMC |
| 129 | * devices. |
| 130 | * |
| 131 | * ``GENHD_FL_HIDDEN`` (0x0400): the block device is hidden; it |
| 132 | * doesn't produce events, doesn't appear in sysfs, and doesn't have |
| 133 | * an associated ``bdev``. |
| 134 | * Implies ``GENHD_FL_SUPPRESS_PARTITION_INFO`` and |
| 135 | * ``GENHD_FL_NO_PART_SCAN``. |
| 136 | * Used for multipath devices. |
| 137 | */ |
| 138 | #define GENHD_FL_REMOVABLE 0x0001 |
| 139 | /* 2 is unused (used to be GENHD_FL_DRIVERFS) */ |
| 140 | /* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */ |
| 141 | #define GENHD_FL_CD 0x0008 |
| 142 | #define GENHD_FL_UP 0x0010 |
| 143 | #define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020 |
| 144 | #define GENHD_FL_EXT_DEVT 0x0040 |
| 145 | #define GENHD_FL_NATIVE_CAPACITY 0x0080 |
| 146 | #define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 0x0100 |
| 147 | #define GENHD_FL_NO_PART_SCAN 0x0200 |
| 148 | #define GENHD_FL_HIDDEN 0x0400 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 150 | enum { |
| 151 | DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */ |
| 152 | DISK_EVENT_EJECT_REQUEST = 1 << 1, /* eject requested */ |
| 153 | }; |
| 154 | |
Martin Wilck | c92e2f0 | 2019-03-27 14:51:02 +0100 | [diff] [blame] | 155 | enum { |
| 156 | /* Poll even if events_poll_msecs is unset */ |
| 157 | DISK_EVENT_FLAG_POLL = 1 << 0, |
| 158 | /* Forward events to udev */ |
| 159 | DISK_EVENT_FLAG_UEVENT = 1 << 1, |
| 160 | }; |
| 161 | |
Tejun Heo | 540eed5 | 2008-08-25 19:56:15 +0900 | [diff] [blame] | 162 | struct disk_part_tbl { |
| 163 | struct rcu_head rcu_head; |
| 164 | int len; |
Arnd Bergmann | 4d2deb4 | 2010-02-24 20:01:56 +0100 | [diff] [blame] | 165 | struct hd_struct __rcu *last_lookup; |
| 166 | struct hd_struct __rcu *part[]; |
Tejun Heo | 540eed5 | 2008-08-25 19:56:15 +0900 | [diff] [blame] | 167 | }; |
| 168 | |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 169 | struct disk_events; |
Vishal Verma | 99e6608 | 2016-01-09 08:36:51 -0800 | [diff] [blame] | 170 | struct badblocks; |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 171 | |
Martin K. Petersen | 25520d5 | 2015-10-21 13:19:49 -0400 | [diff] [blame] | 172 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
| 173 | |
| 174 | struct blk_integrity { |
Eric Biggers | 869ab90 | 2017-03-24 18:03:48 -0700 | [diff] [blame] | 175 | const struct blk_integrity_profile *profile; |
| 176 | unsigned char flags; |
| 177 | unsigned char tuple_size; |
| 178 | unsigned char interval_exp; |
| 179 | unsigned char tag_size; |
Martin K. Petersen | 25520d5 | 2015-10-21 13:19:49 -0400 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | struct gendisk { |
Tejun Heo | 689d6fa | 2008-08-25 19:56:16 +0900 | [diff] [blame] | 185 | /* major, first_minor and minors are input parameters only, |
| 186 | * don't use directly. Use disk_devt() and disk_max_parts(). |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 187 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | int major; /* major number of driver */ |
| 189 | int first_minor; |
| 190 | int minors; /* maximum number of minors, =1 for |
| 191 | * disks that can't be partitioned. */ |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 192 | |
Tejun Heo | 3e1a7ff | 2008-08-25 19:56:17 +0900 | [diff] [blame] | 193 | char disk_name[DISK_NAME_LEN]; /* name of major driver */ |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 194 | |
Martin Wilck | c92e2f0 | 2019-03-27 14:51:02 +0100 | [diff] [blame] | 195 | unsigned short events; /* supported events */ |
| 196 | unsigned short event_flags; /* flags related to event processing */ |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 197 | |
Tejun Heo | b5d0b9d | 2008-09-03 09:06:42 +0200 | [diff] [blame] | 198 | /* Array of pointers to partitions indexed by partno. |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 199 | * Protected with matching bdev lock but stat and other |
| 200 | * non-critical accesses use RCU. Always access through |
| 201 | * helpers. |
| 202 | */ |
Arnd Bergmann | 4d2deb4 | 2010-02-24 20:01:56 +0100 | [diff] [blame] | 203 | struct disk_part_tbl __rcu *part_tbl; |
Tejun Heo | b5d0b9d | 2008-09-03 09:06:42 +0200 | [diff] [blame] | 204 | struct hd_struct part0; |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 205 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 206 | const struct block_device_operations *fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | struct request_queue *queue; |
| 208 | void *private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | int flags; |
Jan Kara | 56c0908 | 2018-02-26 13:01:41 +0100 | [diff] [blame] | 211 | struct rw_semaphore lookup_sem; |
Jun'ichi Nomura | 6a4d44c | 2006-03-27 01:17:55 -0800 | [diff] [blame] | 212 | struct kobject *slave_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | struct timer_rand_state *random; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | atomic_t sync_io; /* RAID */ |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 216 | struct disk_events *ev; |
Martin K. Petersen | 7ba1ba1 | 2008-06-30 20:04:41 +0200 | [diff] [blame] | 217 | #ifdef CONFIG_BLK_DEV_INTEGRITY |
Martin K. Petersen | aff34e1 | 2015-10-21 13:19:27 -0400 | [diff] [blame] | 218 | struct kobject integrity_kobj; |
Martin K. Petersen | 25520d5 | 2015-10-21 13:19:49 -0400 | [diff] [blame] | 219 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ |
Tejun Heo | 540eed5 | 2008-08-25 19:56:15 +0900 | [diff] [blame] | 220 | int node_id; |
Vishal Verma | 99e6608 | 2016-01-09 08:36:51 -0800 | [diff] [blame] | 221 | struct badblocks *bb; |
Byungchul Park | e319e1f | 2017-10-25 17:56:05 +0900 | [diff] [blame] | 222 | struct lockdep_map lockdep_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | }; |
| 224 | |
Tejun Heo | 310a2c1 | 2008-08-25 19:47:17 +0900 | [diff] [blame] | 225 | static inline struct gendisk *part_to_disk(struct hd_struct *part) |
| 226 | { |
Tejun Heo | 548b10e | 2008-08-29 09:01:47 +0200 | [diff] [blame] | 227 | if (likely(part)) { |
| 228 | if (part->partno) |
| 229 | return dev_to_disk(part_to_dev(part)->parent); |
| 230 | else |
| 231 | return dev_to_disk(part_to_dev(part)); |
| 232 | } |
Tejun Heo | 310a2c1 | 2008-08-25 19:47:17 +0900 | [diff] [blame] | 233 | return NULL; |
| 234 | } |
| 235 | |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 236 | static inline int disk_max_parts(struct gendisk *disk) |
| 237 | { |
Tejun Heo | 689d6fa | 2008-08-25 19:56:16 +0900 | [diff] [blame] | 238 | if (disk->flags & GENHD_FL_EXT_DEVT) |
| 239 | return DISK_MAX_PARTS; |
| 240 | return disk->minors; |
Tejun Heo | b5d0b9d | 2008-09-03 09:06:42 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Tejun Heo | d27769e | 2011-08-23 20:01:04 +0200 | [diff] [blame] | 243 | static inline bool disk_part_scan_enabled(struct gendisk *disk) |
Tejun Heo | b5d0b9d | 2008-09-03 09:06:42 +0200 | [diff] [blame] | 244 | { |
Tejun Heo | d27769e | 2011-08-23 20:01:04 +0200 | [diff] [blame] | 245 | return disk_max_parts(disk) > 1 && |
| 246 | !(disk->flags & GENHD_FL_NO_PART_SCAN); |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static inline dev_t disk_devt(struct gendisk *disk) |
| 250 | { |
Christoph Hellwig | 517bf3c | 2017-11-02 21:29:52 +0300 | [diff] [blame] | 251 | return MKDEV(disk->major, disk->first_minor); |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static inline dev_t part_devt(struct hd_struct *part) |
| 255 | { |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 256 | return part_to_dev(part)->devt; |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Greg Edwards | 67f2519 | 2017-10-24 11:21:48 -0600 | [diff] [blame] | 259 | extern struct hd_struct *__disk_get_part(struct gendisk *disk, int partno); |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 260 | extern struct hd_struct *disk_get_part(struct gendisk *disk, int partno); |
| 261 | |
| 262 | static inline void disk_put_part(struct hd_struct *part) |
| 263 | { |
| 264 | if (likely(part)) |
Tejun Heo | ed9e198 | 2008-08-25 19:56:05 +0900 | [diff] [blame] | 265 | put_device(part_to_dev(part)); |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* |
| 269 | * Smarter partition iterator without context limits. |
| 270 | */ |
| 271 | #define DISK_PITER_REVERSE (1 << 0) /* iterate in the reverse direction */ |
| 272 | #define DISK_PITER_INCL_EMPTY (1 << 1) /* include 0-sized parts */ |
Tejun Heo | b5d0b9d | 2008-09-03 09:06:42 +0200 | [diff] [blame] | 273 | #define DISK_PITER_INCL_PART0 (1 << 2) /* include partition 0 */ |
Tejun Heo | 71982a4 | 2009-04-17 08:34:48 +0200 | [diff] [blame] | 274 | #define DISK_PITER_INCL_EMPTY_PART0 (1 << 3) /* include empty partition 0 */ |
Tejun Heo | e71bf0d | 2008-09-03 09:03:02 +0200 | [diff] [blame] | 275 | |
| 276 | struct disk_part_iter { |
| 277 | struct gendisk *disk; |
| 278 | struct hd_struct *part; |
| 279 | int idx; |
| 280 | unsigned int flags; |
| 281 | }; |
| 282 | |
| 283 | extern void disk_part_iter_init(struct disk_part_iter *piter, |
| 284 | struct gendisk *disk, unsigned int flags); |
| 285 | extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter); |
| 286 | extern void disk_part_iter_exit(struct disk_part_iter *piter); |
Linus Torvalds | 10f36b1 | 2020-03-30 11:20:13 -0700 | [diff] [blame] | 287 | extern bool disk_has_partitions(struct gendisk *disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Petros Koutoupis | 32ca163 | 2009-03-10 08:25:54 +0100 | [diff] [blame] | 289 | /* block/genhd.c */ |
Hannes Reinecke | fef912b | 2018-09-28 08:17:19 +0200 | [diff] [blame] | 290 | extern void device_add_disk(struct device *parent, struct gendisk *disk, |
| 291 | const struct attribute_group **groups); |
Dan Williams | e63a46b | 2016-06-15 18:17:27 -0700 | [diff] [blame] | 292 | static inline void add_disk(struct gendisk *disk) |
| 293 | { |
Hannes Reinecke | fef912b | 2018-09-28 08:17:19 +0200 | [diff] [blame] | 294 | device_add_disk(NULL, disk, NULL); |
Dan Williams | e63a46b | 2016-06-15 18:17:27 -0700 | [diff] [blame] | 295 | } |
Mike Snitzer | fa70d2e | 2018-01-08 22:01:13 -0500 | [diff] [blame] | 296 | extern void device_add_disk_no_queue_reg(struct device *parent, struct gendisk *disk); |
| 297 | static inline void add_disk_no_queue_reg(struct gendisk *disk) |
| 298 | { |
| 299 | device_add_disk_no_queue_reg(NULL, disk); |
| 300 | } |
Dan Williams | e63a46b | 2016-06-15 18:17:27 -0700 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | extern void del_gendisk(struct gendisk *gp); |
Tejun Heo | cf771cb | 2008-09-03 09:01:09 +0200 | [diff] [blame] | 303 | extern struct gendisk *get_gendisk(dev_t dev, int *partno); |
Tejun Heo | f331c02 | 2008-09-03 09:01:48 +0200 | [diff] [blame] | 304 | extern struct block_device *bdget_disk(struct gendisk *disk, int partno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
| 306 | extern void set_device_ro(struct block_device *bdev, int flag); |
| 307 | extern void set_disk_ro(struct gendisk *disk, int flag); |
| 308 | |
Tejun Heo | b7db995 | 2008-08-25 19:56:10 +0900 | [diff] [blame] | 309 | static inline int get_disk_ro(struct gendisk *disk) |
| 310 | { |
| 311 | return disk->part0.policy; |
| 312 | } |
| 313 | |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 314 | extern void disk_block_events(struct gendisk *disk); |
| 315 | extern void disk_unblock_events(struct gendisk *disk); |
Tejun Heo | 85ef06d | 2011-07-01 16:17:47 +0200 | [diff] [blame] | 316 | extern void disk_flush_events(struct gendisk *disk, unsigned int mask); |
Balbir Singh | e598a72 | 2020-03-13 05:30:05 +0000 | [diff] [blame] | 317 | extern void set_capacity_revalidate_and_notify(struct gendisk *disk, |
| 318 | sector_t size, bool revalidate); |
Tejun Heo | 77ea887 | 2010-12-08 20:57:37 +0100 | [diff] [blame] | 319 | extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask); |
| 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | /* drivers/char/random.c */ |
Emese Revfy | 0766f78 | 2016-06-20 20:42:34 +0200 | [diff] [blame] | 322 | extern void add_disk_randomness(struct gendisk *disk) __latent_entropy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | extern void rand_initialize_disk(struct gendisk *disk); |
| 324 | |
| 325 | static inline sector_t get_start_sect(struct block_device *bdev) |
| 326 | { |
Tejun Heo | 0762b8b | 2008-08-25 19:56:12 +0900 | [diff] [blame] | 327 | return bdev->bd_part->start_sect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | static inline sector_t get_capacity(struct gendisk *disk) |
| 330 | { |
Tejun Heo | 80795ae | 2008-08-25 19:56:07 +0900 | [diff] [blame] | 331 | return disk->part0.nr_sects; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | static inline void set_capacity(struct gendisk *disk, sector_t size) |
| 334 | { |
Tejun Heo | 80795ae | 2008-08-25 19:56:07 +0900 | [diff] [blame] | 335 | disk->part0.nr_sects = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Tejun Heo | cf771cb | 2008-09-03 09:01:09 +0200 | [diff] [blame] | 338 | extern dev_t blk_lookup_devt(const char *name, int partno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Christoph Hellwig | 142fe8f | 2019-11-14 15:34:35 +0100 | [diff] [blame] | 340 | int bdev_disk_changed(struct block_device *bdev, bool invalidate); |
Christoph Hellwig | a1548b6 | 2019-11-14 15:34:34 +0100 | [diff] [blame] | 341 | int blk_add_partitions(struct gendisk *disk, struct block_device *bdev); |
Christoph Hellwig | d46430b | 2020-04-14 09:28:57 +0200 | [diff] [blame^] | 342 | int blk_drop_partitions(struct block_device *bdev); |
Dave Gilbert | dd2a345 | 2007-05-09 02:33:24 -0700 | [diff] [blame] | 343 | extern void printk_all_partitions(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Byungchul Park | e319e1f | 2017-10-25 17:56:05 +0900 | [diff] [blame] | 345 | extern struct gendisk *__alloc_disk_node(int minors, int node_id); |
Jan Kara | 3079c22 | 2018-02-26 13:01:38 +0100 | [diff] [blame] | 346 | extern struct kobject *get_disk_and_module(struct gendisk *disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | extern void put_disk(struct gendisk *disk); |
Jan Kara | 9df6c29 | 2018-02-26 13:01:39 +0100 | [diff] [blame] | 348 | extern void put_disk_and_module(struct gendisk *disk); |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 349 | extern void blk_register_region(dev_t devt, unsigned long range, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | struct module *module, |
| 351 | struct kobject *(*probe)(dev_t, int *, void *), |
| 352 | int (*lock)(dev_t, void *), |
| 353 | void *data); |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 354 | extern void blk_unregister_region(dev_t devt, unsigned long range); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Byungchul Park | e319e1f | 2017-10-25 17:56:05 +0900 | [diff] [blame] | 356 | #define alloc_disk_node(minors, node_id) \ |
| 357 | ({ \ |
| 358 | static struct lock_class_key __key; \ |
| 359 | const char *__name; \ |
| 360 | struct gendisk *__disk; \ |
| 361 | \ |
| 362 | __name = "(gendisk_completion)"#minors"("#node_id")"; \ |
| 363 | \ |
| 364 | __disk = __alloc_disk_node(minors, node_id); \ |
| 365 | \ |
| 366 | if (__disk) \ |
| 367 | lockdep_init_map(&__disk->lockdep_map, __name, &__key, 0); \ |
| 368 | \ |
| 369 | __disk; \ |
| 370 | }) |
| 371 | |
| 372 | #define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE) |
| 373 | |
Jens Axboe | 87c1efb | 2007-05-11 13:29:54 +0200 | [diff] [blame] | 374 | #else /* CONFIG_BLOCK */ |
| 375 | |
| 376 | static inline void printk_all_partitions(void) { } |
| 377 | |
Tejun Heo | cf771cb | 2008-09-03 09:01:09 +0200 | [diff] [blame] | 378 | static inline dev_t blk_lookup_devt(const char *name, int partno) |
Kay Sievers | edfaa7c | 2007-05-21 22:08:01 +0200 | [diff] [blame] | 379 | { |
| 380 | dev_t devt = MKDEV(0, 0); |
| 381 | return devt; |
| 382 | } |
Jens Axboe | 87c1efb | 2007-05-11 13:29:54 +0200 | [diff] [blame] | 383 | #endif /* CONFIG_BLOCK */ |
David Howells | 9361401 | 2006-09-30 20:45:40 +0200 | [diff] [blame] | 384 | |
David Woodhouse | a8ae50b | 2008-03-12 17:52:56 +0100 | [diff] [blame] | 385 | #endif /* _LINUX_GENHD_H */ |