1
2#ifndef _LINUX_GENHD_H
3#define _LINUX_GENHD_H
4
5
6
7
8
9
10
11
12
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>
21
22extern const struct device_type disk_type;
23extern struct device_type part_type;
24extern struct class block_class;
25
26#define DISK_MAX_PARTS 256
27#define DISK_NAME_LEN 32
28
29#include <linux/major.h>
30#include <linux/device.h>
31#include <linux/smp.h>
32#include <linux/string.h>
33#include <linux/fs.h>
34#include <linux/workqueue.h>
35
36#define PARTITION_META_INFO_VOLNAMELTH 64
37
38
39
40
41#define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
42
43struct partition_meta_info {
44 char uuid[PARTITION_META_INFO_UUIDLTH];
45 u8 volname[PARTITION_META_INFO_VOLNAMELTH];
46};
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95#define GENHD_FL_REMOVABLE 0x0001
96
97
98#define GENHD_FL_CD 0x0008
99#define GENHD_FL_UP 0x0010
100#define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020
101#define GENHD_FL_EXT_DEVT 0x0040
102#define GENHD_FL_NATIVE_CAPACITY 0x0080
103#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 0x0100
104#define GENHD_FL_NO_PART_SCAN 0x0200
105#define GENHD_FL_HIDDEN 0x0400
106
107enum {
108 DISK_EVENT_MEDIA_CHANGE = 1 << 0,
109 DISK_EVENT_EJECT_REQUEST = 1 << 1,
110};
111
112enum {
113
114 DISK_EVENT_FLAG_POLL = 1 << 0,
115
116 DISK_EVENT_FLAG_UEVENT = 1 << 1,
117};
118
119struct disk_part_tbl {
120 struct rcu_head rcu_head;
121 int len;
122 struct block_device __rcu *last_lookup;
123 struct block_device __rcu *part[];
124};
125
126struct disk_events;
127struct badblocks;
128
129struct blk_integrity {
130 const struct blk_integrity_profile *profile;
131 unsigned char flags;
132 unsigned char tuple_size;
133 unsigned char interval_exp;
134 unsigned char tag_size;
135};
136
137struct gendisk {
138
139
140
141 int major;
142 int first_minor;
143 int minors;
144
145
146 char disk_name[DISK_NAME_LEN];
147
148 unsigned short events;
149 unsigned short event_flags;
150
151
152
153
154
155
156 struct disk_part_tbl __rcu *part_tbl;
157 struct block_device *part0;
158
159 const struct block_device_operations *fops;
160 struct request_queue *queue;
161 void *private_data;
162
163 int flags;
164 unsigned long state;
165#define GD_NEED_PART_SCAN 0
166 struct kobject *slave_dir;
167
168 struct timer_rand_state *random;
169 atomic_t sync_io;
170 struct disk_events *ev;
171#ifdef CONFIG_BLK_DEV_INTEGRITY
172 struct kobject integrity_kobj;
173#endif
174#if IS_ENABLED(CONFIG_CDROM)
175 struct cdrom_device_info *cdi;
176#endif
177 int node_id;
178 struct badblocks *bb;
179 struct lockdep_map lockdep_map;
180};
181
182
183
184
185
186#define dev_to_disk(device) \
187 (dev_to_bdev(device)->bd_disk)
188#define disk_to_dev(disk) \
189 (&((disk)->part0->bd_device))
190
191#if IS_REACHABLE(CONFIG_CDROM)
192#define disk_to_cdi(disk) ((disk)->cdi)
193#else
194#define disk_to_cdi(disk) NULL
195#endif
196
197static inline int disk_max_parts(struct gendisk *disk)
198{
199 if (disk->flags & GENHD_FL_EXT_DEVT)
200 return DISK_MAX_PARTS;
201 return disk->minors;
202}
203
204static inline bool disk_part_scan_enabled(struct gendisk *disk)
205{
206 return disk_max_parts(disk) > 1 &&
207 !(disk->flags & GENHD_FL_NO_PART_SCAN);
208}
209
210static inline dev_t disk_devt(struct gendisk *disk)
211{
212 return MKDEV(disk->major, disk->first_minor);
213}
214
215
216
217
218#define DISK_PITER_REVERSE (1 << 0)
219#define DISK_PITER_INCL_EMPTY (1 << 1)
220#define DISK_PITER_INCL_PART0 (1 << 2)
221#define DISK_PITER_INCL_EMPTY_PART0 (1 << 3)
222
223struct disk_part_iter {
224 struct gendisk *disk;
225 struct block_device *part;
226 int idx;
227 unsigned int flags;
228};
229
230extern void disk_part_iter_init(struct disk_part_iter *piter,
231 struct gendisk *disk, unsigned int flags);
232struct block_device *disk_part_iter_next(struct disk_part_iter *piter);
233extern void disk_part_iter_exit(struct disk_part_iter *piter);
234extern bool disk_has_partitions(struct gendisk *disk);
235
236
237extern void device_add_disk(struct device *parent, struct gendisk *disk,
238 const struct attribute_group **groups);
239static inline void add_disk(struct gendisk *disk)
240{
241 device_add_disk(NULL, disk, NULL);
242}
243extern void device_add_disk_no_queue_reg(struct device *parent, struct gendisk *disk);
244static inline void add_disk_no_queue_reg(struct gendisk *disk)
245{
246 device_add_disk_no_queue_reg(NULL, disk);
247}
248
249extern void del_gendisk(struct gendisk *gp);
250extern struct block_device *bdget_disk(struct gendisk *disk, int partno);
251
252extern void set_disk_ro(struct gendisk *disk, int flag);
253
254static inline int get_disk_ro(struct gendisk *disk)
255{
256 return disk->part0->bd_read_only;
257}
258
259extern void disk_block_events(struct gendisk *disk);
260extern void disk_unblock_events(struct gendisk *disk);
261extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
262bool set_capacity_and_notify(struct gendisk *disk, sector_t size);
263
264
265extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
266extern void rand_initialize_disk(struct gendisk *disk);
267
268static inline sector_t get_start_sect(struct block_device *bdev)
269{
270 return bdev->bd_start_sect;
271}
272
273static inline sector_t bdev_nr_sectors(struct block_device *bdev)
274{
275 return i_size_read(bdev->bd_inode) >> 9;
276}
277
278static inline sector_t get_capacity(struct gendisk *disk)
279{
280 return bdev_nr_sectors(disk->part0);
281}
282
283int bdev_disk_changed(struct block_device *bdev, bool invalidate);
284int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
285int blk_drop_partitions(struct block_device *bdev);
286
287extern struct gendisk *__alloc_disk_node(int minors, int node_id);
288extern void put_disk(struct gendisk *disk);
289
290#define alloc_disk_node(minors, node_id) \
291({ \
292 static struct lock_class_key __key; \
293 const char *__name; \
294 struct gendisk *__disk; \
295 \
296 __name = "(gendisk_completion)"#minors"("#node_id")"; \
297 \
298 __disk = __alloc_disk_node(minors, node_id); \
299 \
300 if (__disk) \
301 lockdep_init_map(&__disk->lockdep_map, __name, &__key, 0); \
302 \
303 __disk; \
304})
305
306#define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)
307
308int __register_blkdev(unsigned int major, const char *name,
309 void (*probe)(dev_t devt));
310#define register_blkdev(major, name) \
311 __register_blkdev(major, name, NULL)
312void unregister_blkdev(unsigned int major, const char *name);
313
314bool bdev_check_media_change(struct block_device *bdev);
315int __invalidate_device(struct block_device *bdev, bool kill_dirty);
316void set_capacity(struct gendisk *disk, sector_t size);
317
318
319int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
320long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
321
322#ifdef CONFIG_SYSFS
323int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
324void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk);
325#else
326static inline int bd_link_disk_holder(struct block_device *bdev,
327 struct gendisk *disk)
328{
329 return 0;
330}
331static inline void bd_unlink_disk_holder(struct block_device *bdev,
332 struct gendisk *disk)
333{
334}
335#endif
336
337extern struct rw_semaphore bdev_lookup_sem;
338
339dev_t blk_lookup_devt(const char *name, int partno);
340void blk_request_module(dev_t devt);
341#ifdef CONFIG_BLOCK
342void printk_all_partitions(void);
343#else
344static inline void printk_all_partitions(void)
345{
346}
347#endif
348
349#endif
350