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#include <linux/xarray.h>
36
37#define PARTITION_META_INFO_VOLNAMELTH 64
38
39
40
41
42#define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
43
44struct partition_meta_info {
45 char uuid[PARTITION_META_INFO_UUIDLTH];
46 u8 volname[PARTITION_META_INFO_VOLNAMELTH];
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#define GENHD_FL_REMOVABLE 0x0001
94
95
96#define GENHD_FL_CD 0x0008
97#define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020
98#define GENHD_FL_EXT_DEVT 0x0040
99#define GENHD_FL_NATIVE_CAPACITY 0x0080
100#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 0x0100
101#define GENHD_FL_NO_PART_SCAN 0x0200
102#define GENHD_FL_HIDDEN 0x0400
103
104enum {
105 DISK_EVENT_MEDIA_CHANGE = 1 << 0,
106 DISK_EVENT_EJECT_REQUEST = 1 << 1,
107};
108
109enum {
110
111 DISK_EVENT_FLAG_POLL = 1 << 0,
112
113 DISK_EVENT_FLAG_UEVENT = 1 << 1,
114};
115
116struct disk_events;
117struct badblocks;
118
119struct blk_integrity {
120 const struct blk_integrity_profile *profile;
121 unsigned char flags;
122 unsigned char tuple_size;
123 unsigned char interval_exp;
124 unsigned char tag_size;
125};
126
127struct gendisk {
128
129
130
131 int major;
132 int first_minor;
133 int minors;
134
135
136 char disk_name[DISK_NAME_LEN];
137
138 unsigned short events;
139 unsigned short event_flags;
140
141 struct xarray part_tbl;
142 struct block_device *part0;
143
144 const struct block_device_operations *fops;
145 struct request_queue *queue;
146 void *private_data;
147
148 int flags;
149 unsigned long state;
150#define GD_NEED_PART_SCAN 0
151#define GD_READ_ONLY 1
152#define GD_DEAD 2
153
154 struct mutex open_mutex;
155 unsigned open_partitions;
156
157 struct backing_dev_info *bdi;
158 struct kobject *slave_dir;
159#ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
160 struct list_head slave_bdevs;
161#endif
162 struct timer_rand_state *random;
163 atomic_t sync_io;
164 struct disk_events *ev;
165#ifdef CONFIG_BLK_DEV_INTEGRITY
166 struct kobject integrity_kobj;
167#endif
168#if IS_ENABLED(CONFIG_CDROM)
169 struct cdrom_device_info *cdi;
170#endif
171 int node_id;
172 struct badblocks *bb;
173 struct lockdep_map lockdep_map;
174 u64 diskseq;
175};
176
177static inline bool disk_live(struct gendisk *disk)
178{
179 return !inode_unhashed(disk->part0->bd_inode);
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
215void disk_uevent(struct gendisk *disk, enum kobject_action action);
216
217
218int device_add_disk(struct device *parent, struct gendisk *disk,
219 const struct attribute_group **groups);
220static inline int add_disk(struct gendisk *disk)
221{
222 return device_add_disk(NULL, disk, NULL);
223}
224extern void del_gendisk(struct gendisk *gp);
225
226void set_disk_ro(struct gendisk *disk, bool read_only);
227
228static inline int get_disk_ro(struct gendisk *disk)
229{
230 return disk->part0->bd_read_only ||
231 test_bit(GD_READ_ONLY, &disk->state);
232}
233
234extern void disk_block_events(struct gendisk *disk);
235extern void disk_unblock_events(struct gendisk *disk);
236extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
237bool set_capacity_and_notify(struct gendisk *disk, sector_t size);
238bool disk_force_media_change(struct gendisk *disk, unsigned int events);
239
240
241extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
242extern void rand_initialize_disk(struct gendisk *disk);
243
244static inline sector_t get_start_sect(struct block_device *bdev)
245{
246 return bdev->bd_start_sect;
247}
248
249static inline sector_t bdev_nr_sectors(struct block_device *bdev)
250{
251 return i_size_read(bdev->bd_inode) >> 9;
252}
253
254static inline sector_t get_capacity(struct gendisk *disk)
255{
256 return bdev_nr_sectors(disk->part0);
257}
258
259int bdev_disk_changed(struct gendisk *disk, bool invalidate);
260void blk_drop_partitions(struct gendisk *disk);
261
262struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
263 struct lock_class_key *lkclass);
264extern void put_disk(struct gendisk *disk);
265struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass);
266
267
268
269
270
271
272
273
274
275
276#define blk_alloc_disk(node_id) \
277({ \
278 static struct lock_class_key __key; \
279 \
280 __blk_alloc_disk(node_id, &__key); \
281})
282void blk_cleanup_disk(struct gendisk *disk);
283
284int __register_blkdev(unsigned int major, const char *name,
285 void (*probe)(dev_t devt));
286#define register_blkdev(major, name) \
287 __register_blkdev(major, name, NULL)
288void unregister_blkdev(unsigned int major, const char *name);
289
290bool bdev_check_media_change(struct block_device *bdev);
291int __invalidate_device(struct block_device *bdev, bool kill_dirty);
292void set_capacity(struct gendisk *disk, sector_t size);
293
294
295int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
296long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
297
298#ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
299int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
300void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk);
301int bd_register_pending_holders(struct gendisk *disk);
302#else
303static inline int bd_link_disk_holder(struct block_device *bdev,
304 struct gendisk *disk)
305{
306 return 0;
307}
308static inline void bd_unlink_disk_holder(struct block_device *bdev,
309 struct gendisk *disk)
310{
311}
312static inline int bd_register_pending_holders(struct gendisk *disk)
313{
314 return 0;
315}
316#endif
317
318dev_t part_devt(struct gendisk *disk, u8 partno);
319void inc_diskseq(struct gendisk *disk);
320dev_t blk_lookup_devt(const char *name, int partno);
321void blk_request_module(dev_t devt);
322#ifdef CONFIG_BLOCK
323void printk_all_partitions(void);
324#else
325static inline void printk_all_partitions(void)
326{
327}
328#endif
329
330#endif
331