12 #include <linux/types.h>
13 #include <linux/kdev_t.h>
15 #include <linux/slab.h>
19 #define dev_to_disk(device) container_of((device), struct gendisk, part0.__dev)
20 #define dev_to_part(device) container_of((device), struct hd_struct, __dev)
21 #define disk_to_dev(disk) (&(disk)->part0.__dev)
22 #define part_to_dev(part) (&((part)->__dev))
31 DOS_EXTENDED_PARTITION = 5,
32 LINUX_EXTENDED_PARTITION = 0x85,
33 WIN98_EXTENDED_PARTITION = 0x0f,
35 SUN_WHOLE_DISK = DOS_EXTENDED_PARTITION,
37 LINUX_SWAP_PARTITION = 0x82,
38 LINUX_DATA_PARTITION = 0x83,
39 LINUX_LVM_PARTITION = 0x8e,
40 LINUX_RAID_PARTITION = 0xfd,
42 SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
43 NEW_SOLARIS_X86_PARTITION = 0xbf,
45 DM6_AUX1PARTITION = 0x51,
46 DM6_AUX3PARTITION = 0x53,
50 FREEBSD_PARTITION = 0xa5,
51 OPENBSD_PARTITION = 0xa6,
52 NETBSD_PARTITION = 0xa9,
53 BSDI_PARTITION = 0xb7,
54 MINIX_PARTITION = 0x81,
55 UNIXWARE_PARTITION = 0x63,
58 #define DISK_MAX_PARTS 256
59 #define DISK_NAME_LEN 32
62 #include <linux/device.h>
64 #include <linux/string.h>
69 unsigned char boot_ind;
73 unsigned char sys_ind;
76 unsigned char end_cyl;
84 unsigned long merges[2];
85 unsigned long ticks[2];
86 unsigned long io_ticks;
87 unsigned long time_in_queue;
90 #define PARTITION_META_INFO_VOLNAMELTH 64
91 #define PARTITION_META_INFO_UUIDLTH 16
93 struct partition_meta_info {
94 u8 uuid[PARTITION_META_INFO_UUIDLTH];
95 u8 volname[PARTITION_META_INFO_VOLNAMELTH];
108 unsigned int discard_alignment;
112 struct partition_meta_info *
info;
113 #ifdef CONFIG_FAIL_MAKE_REQUEST
119 struct disk_stats
__percpu *dkstats;
121 struct disk_stats dkstats;
127 #define GENHD_FL_REMOVABLE 1
129 #define GENHD_FL_MEDIA_CHANGE_NOTIFY 4
130 #define GENHD_FL_CD 8
131 #define GENHD_FL_UP 16
132 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
133 #define GENHD_FL_EXT_DEVT 64
134 #define GENHD_FL_NATIVE_CAPACITY 128
135 #define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 256
136 #define GENHD_FL_NO_PART_SCAN 512
139 DISK_EVENT_MEDIA_CHANGE = 1 << 0,
140 DISK_EVENT_EJECT_REQUEST = 1 << 1,
143 #define BLK_SCSI_MAX_CMDS (256)
144 #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
146 struct blk_scsi_cmd_filter {
147 unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
148 unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
152 struct disk_part_tbl {
155 struct hd_struct
__rcu *last_lookup;
171 char *(*devnode)(
struct gendisk *gd,
umode_t *
mode);
174 unsigned int async_events;
181 struct disk_part_tbl
__rcu *part_tbl;
182 struct hd_struct part0;
184 const struct block_device_operations *
fops;
189 struct device *driverfs_dev;
195 #ifdef CONFIG_BLK_DEV_INTEGRITY
196 struct blk_integrity *integrity;
201 static inline struct gendisk *part_to_disk(
struct hd_struct *
part)
205 return dev_to_disk(part_to_dev(part)->parent);
207 return dev_to_disk(part_to_dev(part));
212 static inline void part_pack_uuid(
const u8 *uuid_str,
u8 *to)
215 for (i = 0; i < 16; ++
i) {
230 static inline int disk_max_parts(
struct gendisk *disk)
232 if (disk->flags & GENHD_FL_EXT_DEVT)
233 return DISK_MAX_PARTS;
237 static inline bool disk_part_scan_enabled(
struct gendisk *disk)
239 return disk_max_parts(disk) > 1 &&
240 !(disk->flags & GENHD_FL_NO_PART_SCAN);
243 static inline dev_t disk_devt(
struct gendisk *disk)
245 return disk_to_dev(disk)->devt;
248 static inline dev_t part_devt(
struct hd_struct *part)
250 return part_to_dev(part)->devt;
253 extern struct hd_struct *
disk_get_part(
struct gendisk *disk,
int partno);
255 static inline void disk_put_part(
struct hd_struct *part)
264 #define DISK_PITER_REVERSE (1 << 0)
265 #define DISK_PITER_INCL_EMPTY (1 << 1)
266 #define DISK_PITER_INCL_PART0 (1 << 2)
267 #define DISK_PITER_INCL_EMPTY_PART0 (1 << 3)
269 struct disk_part_iter {
270 struct gendisk *disk;
271 struct hd_struct *
part;
277 struct gendisk *disk,
unsigned int flags);
297 #define part_stat_lock() ({ rcu_read_lock(); get_cpu(); })
298 #define part_stat_unlock() do { put_cpu(); rcu_read_unlock(); } while (0)
300 #define __part_stat_add(cpu, part, field, addnd) \
301 (per_cpu_ptr((part)->dkstats, (cpu))->field += (addnd))
303 #define part_stat_read(part, field) \
305 typeof((part)->dkstats->field) res = 0; \
307 for_each_possible_cpu(_cpu) \
308 res += per_cpu_ptr((part)->dkstats, _cpu)->field; \
312 static inline void part_stat_set_all(
struct hd_struct *part,
int value)
321 static
inline int init_part_stats(
struct hd_struct *part)
329 static inline void free_part_stats(
struct hd_struct *part)
335 #define part_stat_lock() ({ rcu_read_lock(); 0; })
336 #define part_stat_unlock() rcu_read_unlock()
338 #define __part_stat_add(cpu, part, field, addnd) \
339 ((part)->dkstats.field += addnd)
341 #define part_stat_read(part, field) ((part)->dkstats.field)
343 static inline void part_stat_set_all(
struct hd_struct *part,
int value)
345 memset(&part->dkstats, value,
sizeof(
struct disk_stats));
348 static inline int init_part_stats(
struct hd_struct *part)
353 static inline void free_part_stats(
struct hd_struct *part)
359 #define part_stat_add(cpu, part, field, addnd) do { \
360 __part_stat_add((cpu), (part), field, addnd); \
361 if ((part)->partno) \
362 __part_stat_add((cpu), &part_to_disk((part))->part0, \
366 #define part_stat_dec(cpu, gendiskp, field) \
367 part_stat_add(cpu, gendiskp, field, -1)
368 #define part_stat_inc(cpu, gendiskp, field) \
369 part_stat_add(cpu, gendiskp, field, 1)
370 #define part_stat_sub(cpu, gendiskp, field, subnd) \
371 part_stat_add(cpu, gendiskp, field, -subnd)
373 static inline void part_inc_in_flight(
struct hd_struct *part,
int rw)
377 atomic_inc(&part_to_disk(part)->part0.in_flight[rw]);
380 static inline void part_dec_in_flight(
struct hd_struct *part,
int rw)
384 atomic_dec(&part_to_disk(part)->part0.in_flight[rw]);
387 static inline int part_in_flight(
struct hd_struct *part)
392 static inline struct partition_meta_info *alloc_part_info(
struct gendisk *disk)
395 return kzalloc_node(
sizeof(
struct partition_meta_info),
397 return kzalloc(
sizeof(
struct partition_meta_info),
GFP_KERNEL);
400 static inline void free_part_info(
struct hd_struct *part)
409 extern void add_disk(
struct gendisk *disk);
417 static inline int get_disk_ro(
struct gendisk *disk)
419 return disk->part0.policy;
428 extern void add_disk_randomness(
struct gendisk *disk);
429 extern void rand_initialize_disk(
struct gendisk *disk);
433 return bdev->
bd_part->start_sect;
435 static inline sector_t get_capacity(
struct gendisk *disk)
437 return disk->part0.nr_sects;
439 static inline void set_capacity(
struct gendisk *disk,
sector_t size)
441 disk->part0.nr_sects =
size;
444 #ifdef CONFIG_SOLARIS_X86_PARTITION
446 #define SOLARIS_X86_NUMSLICE 16
447 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
449 struct solaris_x86_slice {
456 struct solaris_x86_vtoc {
457 unsigned int v_bootinfo[3];
463 unsigned int v_reserved[10];
464 struct solaris_x86_slice
465 v_slice[SOLARIS_X86_NUMSLICE];
466 unsigned int timestamp[SOLARIS_X86_NUMSLICE];
467 char v_asciilabel[128];
472 #ifdef CONFIG_BSD_DISKLABEL
480 #define BSD_DISKMAGIC (0x82564557UL)
481 #define BSD_MAXPARTITIONS 16
482 #define OPENBSD_MAXPARTITIONS 16
483 #define BSD_FS_UNUSED 0
484 struct bsd_disklabel {
496 __u16 d_sparespertrack;
497 __u16 d_sparespercyl;
507 __u32 d_drivedata[NDDATA];
509 __u32 d_spare[NSPARE];
517 struct bsd_partition {
524 } d_partitions[BSD_MAXPARTITIONS];
529 #ifdef CONFIG_UNIXWARE_DISKLABEL
535 #define UNIXWARE_DISKMAGIC (0xCA5E600DUL)
536 #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL)
537 #define UNIXWARE_NUMSLICE 16
538 #define UNIXWARE_FS_UNUSED 0
540 struct unixware_slice {
547 struct unixware_disklabel {
568 struct unixware_vtoc {
575 struct unixware_slice
576 v_slice[UNIXWARE_NUMSLICE];
583 #ifdef CONFIG_MINIX_SUBPARTITION
584 # define MINIX_NR_SUBPARTITIONS 4
587 #define ADDPART_FLAG_NONE 0
588 #define ADDPART_FLAG_RAID 1
589 #define ADDPART_FLAG_WHOLEDISK 2
594 extern char *
disk_name (
struct gendisk *hd,
int partno,
char *
buf);
602 struct partition_meta_info
609 extern struct gendisk *
alloc_disk(
int minors);
611 extern void put_disk(
struct gendisk *disk);
615 int (*lock)(
dev_t,
void *),
625 #ifdef CONFIG_FAIL_MAKE_REQUEST
633 static inline void hd_ref_init(
struct hd_struct *part)
639 static inline void hd_struct_get(
struct hd_struct *part)
645 static inline int hd_struct_try_get(
struct hd_struct *part)
650 static inline void hd_struct_put(
struct hd_struct *part)
665 static inline sector_t part_nr_sects_read(
struct hd_struct *part)
667 #if BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_SMP)
671 seq = read_seqcount_begin(&part->nr_sects_seq);
672 nr_sects = part->nr_sects;
673 }
while (read_seqcount_retry(&part->nr_sects_seq, seq));
675 #elif BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_PREEMPT)
679 nr_sects = part->nr_sects;
683 return part->nr_sects;
692 static inline void part_nr_sects_write(
struct hd_struct *part,
sector_t size)
694 #if BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_SMP)
695 write_seqcount_begin(&part->nr_sects_seq);
696 part->nr_sects =
size;
697 write_seqcount_end(&part->nr_sects_seq);
698 #elif BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_PREEMPT)
700 part->nr_sects =
size;
703 part->nr_sects =
size;