genhd.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. #ifndef _LINUX_GENHD_H
  2. #define _LINUX_GENHD_H
  3. /*
  4. * genhd.h Copyright (C) 1992 Drew Eckhardt
  5. * Generic hard disk header file by
  6. * Drew Eckhardt
  7. *
  8. * <drew@colorado.edu>
  9. */
  10. #include <linux/types.h>
  11. #include <linux/kdev_t.h>
  12. #include <linux/rcupdate.h>
  13. #include <linux/slab.h>
  14. #include <linux/percpu-refcount.h>
  15. #include <linux/uuid.h>
  16. #ifdef CONFIG_BLOCK
  17. #define dev_to_disk(device) container_of((device), struct gendisk, part0.__dev)
  18. #define dev_to_part(device) container_of((device), struct hd_struct, __dev)
  19. #define disk_to_dev(disk) (&(disk)->part0.__dev)
  20. #define part_to_dev(part) (&((part)->__dev))
  21. extern struct device_type part_type;
  22. extern struct kobject *block_depr;
  23. extern struct class block_class;
  24. enum {
  25. /* These three have identical behaviour; use the second one if DOS FDISK gets
  26. confused about extended/logical partitions starting past cylinder 1023. */
  27. DOS_EXTENDED_PARTITION = 5,
  28. LINUX_EXTENDED_PARTITION = 0x85,
  29. WIN98_EXTENDED_PARTITION = 0x0f,
  30. SUN_WHOLE_DISK = DOS_EXTENDED_PARTITION,
  31. LINUX_SWAP_PARTITION = 0x82,
  32. LINUX_DATA_PARTITION = 0x83,
  33. LINUX_LVM_PARTITION = 0x8e,
  34. LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
  35. SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
  36. NEW_SOLARIS_X86_PARTITION = 0xbf,
  37. DM6_AUX1PARTITION = 0x51, /* no DDO: use xlated geom */
  38. DM6_AUX3PARTITION = 0x53, /* no DDO: use xlated geom */
  39. DM6_PARTITION = 0x54, /* has DDO: use xlated geom & offset */
  40. EZD_PARTITION = 0x55, /* EZ-DRIVE */
  41. FREEBSD_PARTITION = 0xa5, /* FreeBSD Partition ID */
  42. OPENBSD_PARTITION = 0xa6, /* OpenBSD Partition ID */
  43. NETBSD_PARTITION = 0xa9, /* NetBSD Partition ID */
  44. BSDI_PARTITION = 0xb7, /* BSDI Partition ID */
  45. MINIX_PARTITION = 0x81, /* Minix Partition ID */
  46. UNIXWARE_PARTITION = 0x63, /* Same as GNU_HURD and SCO Unix */
  47. };
  48. #define DISK_MAX_PARTS 256
  49. #define DISK_NAME_LEN 32
  50. #include <linux/major.h>
  51. #include <linux/device.h>
  52. #include <linux/smp.h>
  53. #include <linux/string.h>
  54. #include <linux/fs.h>
  55. #include <linux/workqueue.h>
  56. struct partition {
  57. unsigned char boot_ind; /* 0x80 - active */
  58. unsigned char head; /* starting head */
  59. unsigned char sector; /* starting sector */
  60. unsigned char cyl; /* starting cylinder */
  61. unsigned char sys_ind; /* What partition type */
  62. unsigned char end_head; /* end head */
  63. unsigned char end_sector; /* end sector */
  64. unsigned char end_cyl; /* end cylinder */
  65. __le32 start_sect; /* starting sector counting from 0 */
  66. __le32 nr_sects; /* nr of sectors in partition */
  67. } __attribute__((packed));
  68. struct disk_stats {
  69. unsigned long sectors[2]; /* READs and WRITEs */
  70. unsigned long ios[2];
  71. unsigned long merges[2];
  72. unsigned long ticks[2];
  73. unsigned long io_ticks;
  74. unsigned long time_in_queue;
  75. };
  76. #define PARTITION_META_INFO_VOLNAMELTH 64
  77. /*
  78. * Enough for the string representation of any kind of UUID plus NULL.
  79. * EFI UUID is 36 characters. MSDOS UUID is 11 characters.
  80. */
  81. #define PARTITION_META_INFO_UUIDLTH (UUID_STRING_LEN + 1)
  82. struct partition_meta_info {
  83. char uuid[PARTITION_META_INFO_UUIDLTH];
  84. u8 volname[PARTITION_META_INFO_VOLNAMELTH];
  85. };
  86. struct hd_struct {
  87. sector_t start_sect;
  88. /*
  89. * nr_sects is protected by sequence counter. One might extend a
  90. * partition while IO is happening to it and update of nr_sects
  91. * can be non-atomic on 32bit machines with 64bit sector_t.
  92. */
  93. sector_t nr_sects;
  94. seqcount_t nr_sects_seq;
  95. sector_t alignment_offset;
  96. unsigned int discard_alignment;
  97. struct device __dev;
  98. struct kobject *holder_dir;
  99. int policy, partno;
  100. struct partition_meta_info *info;
  101. #ifdef CONFIG_FAIL_MAKE_REQUEST
  102. int make_it_fail;
  103. #endif
  104. unsigned long stamp;
  105. atomic_t in_flight[2];
  106. #ifdef CONFIG_SMP
  107. struct disk_stats __percpu *dkstats;
  108. #else
  109. struct disk_stats dkstats;
  110. #endif
  111. struct percpu_ref ref;
  112. struct rcu_head rcu_head;
  113. };
  114. #define GENHD_FL_REMOVABLE 1
  115. /* 2 is unused */
  116. #define GENHD_FL_MEDIA_CHANGE_NOTIFY 4
  117. #define GENHD_FL_CD 8
  118. #define GENHD_FL_UP 16
  119. #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
  120. #define GENHD_FL_EXT_DEVT 64 /* allow extended devt */
  121. #define GENHD_FL_NATIVE_CAPACITY 128
  122. #define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 256
  123. #define GENHD_FL_NO_PART_SCAN 512
  124. enum {
  125. DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */
  126. DISK_EVENT_EJECT_REQUEST = 1 << 1, /* eject requested */
  127. };
  128. #define BLK_SCSI_MAX_CMDS (256)
  129. #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
  130. struct blk_scsi_cmd_filter {
  131. unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
  132. unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
  133. struct kobject kobj;
  134. };
  135. struct disk_part_tbl {
  136. struct rcu_head rcu_head;
  137. int len;
  138. struct hd_struct __rcu *last_lookup;
  139. struct hd_struct __rcu *part[];
  140. };
  141. struct disk_events;
  142. struct badblocks;
  143. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  144. struct blk_integrity {
  145. struct blk_integrity_profile *profile;
  146. unsigned char flags;
  147. unsigned char tuple_size;
  148. unsigned char interval_exp;
  149. unsigned char tag_size;
  150. };
  151. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  152. struct gendisk {
  153. /* major, first_minor and minors are input parameters only,
  154. * don't use directly. Use disk_devt() and disk_max_parts().
  155. */
  156. int major; /* major number of driver */
  157. int first_minor;
  158. int minors; /* maximum number of minors, =1 for
  159. * disks that can't be partitioned. */
  160. char disk_name[DISK_NAME_LEN]; /* name of major driver */
  161. char *(*devnode)(struct gendisk *gd, umode_t *mode);
  162. unsigned int events; /* supported events */
  163. unsigned int async_events; /* async events, subset of all */
  164. /* Array of pointers to partitions indexed by partno.
  165. * Protected with matching bdev lock but stat and other
  166. * non-critical accesses use RCU. Always access through
  167. * helpers.
  168. */
  169. struct disk_part_tbl __rcu *part_tbl;
  170. struct hd_struct part0;
  171. const struct block_device_operations *fops;
  172. struct request_queue *queue;
  173. void *private_data;
  174. int flags;
  175. struct kobject *slave_dir;
  176. struct timer_rand_state *random;
  177. atomic_t sync_io; /* RAID */
  178. struct disk_events *ev;
  179. #ifdef CONFIG_BLK_DEV_INTEGRITY
  180. struct kobject integrity_kobj;
  181. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  182. int node_id;
  183. struct badblocks *bb;
  184. };
  185. static inline struct gendisk *part_to_disk(struct hd_struct *part)
  186. {
  187. if (likely(part)) {
  188. if (part->partno)
  189. return dev_to_disk(part_to_dev(part)->parent);
  190. else
  191. return dev_to_disk(part_to_dev(part));
  192. }
  193. return NULL;
  194. }
  195. static inline int blk_part_pack_uuid(const u8 *uuid_str, u8 *to)
  196. {
  197. uuid_be_to_bin(uuid_str, (uuid_be *)to);
  198. return 0;
  199. }
  200. static inline int disk_max_parts(struct gendisk *disk)
  201. {
  202. if (disk->flags & GENHD_FL_EXT_DEVT)
  203. return DISK_MAX_PARTS;
  204. return disk->minors;
  205. }
  206. static inline bool disk_part_scan_enabled(struct gendisk *disk)
  207. {
  208. return disk_max_parts(disk) > 1 &&
  209. !(disk->flags & GENHD_FL_NO_PART_SCAN);
  210. }
  211. static inline dev_t disk_devt(struct gendisk *disk)
  212. {
  213. return disk_to_dev(disk)->devt;
  214. }
  215. static inline dev_t part_devt(struct hd_struct *part)
  216. {
  217. return part_to_dev(part)->devt;
  218. }
  219. extern struct hd_struct *disk_get_part(struct gendisk *disk, int partno);
  220. static inline void disk_put_part(struct hd_struct *part)
  221. {
  222. if (likely(part))
  223. put_device(part_to_dev(part));
  224. }
  225. /*
  226. * Smarter partition iterator without context limits.
  227. */
  228. #define DISK_PITER_REVERSE (1 << 0) /* iterate in the reverse direction */
  229. #define DISK_PITER_INCL_EMPTY (1 << 1) /* include 0-sized parts */
  230. #define DISK_PITER_INCL_PART0 (1 << 2) /* include partition 0 */
  231. #define DISK_PITER_INCL_EMPTY_PART0 (1 << 3) /* include empty partition 0 */
  232. struct disk_part_iter {
  233. struct gendisk *disk;
  234. struct hd_struct *part;
  235. int idx;
  236. unsigned int flags;
  237. };
  238. extern void disk_part_iter_init(struct disk_part_iter *piter,
  239. struct gendisk *disk, unsigned int flags);
  240. extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter);
  241. extern void disk_part_iter_exit(struct disk_part_iter *piter);
  242. extern struct hd_struct *disk_map_sector_rcu(struct gendisk *disk,
  243. sector_t sector);
  244. /*
  245. * Macros to operate on percpu disk statistics:
  246. *
  247. * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters
  248. * and should be called between disk_stat_lock() and
  249. * disk_stat_unlock().
  250. *
  251. * part_stat_read() can be called at any time.
  252. *
  253. * part_stat_{add|set_all}() and {init|free}_part_stats are for
  254. * internal use only.
  255. */
  256. #ifdef CONFIG_SMP
  257. #define part_stat_lock() ({ rcu_read_lock(); get_cpu(); })
  258. #define part_stat_unlock() do { put_cpu(); rcu_read_unlock(); } while (0)
  259. #define __part_stat_add(cpu, part, field, addnd) \
  260. (per_cpu_ptr((part)->dkstats, (cpu))->field += (addnd))
  261. #define part_stat_read(part, field) \
  262. ({ \
  263. typeof((part)->dkstats->field) res = 0; \
  264. unsigned int _cpu; \
  265. for_each_possible_cpu(_cpu) \
  266. res += per_cpu_ptr((part)->dkstats, _cpu)->field; \
  267. res; \
  268. })
  269. static inline void part_stat_set_all(struct hd_struct *part, int value)
  270. {
  271. int i;
  272. for_each_possible_cpu(i)
  273. memset(per_cpu_ptr(part->dkstats, i), value,
  274. sizeof(struct disk_stats));
  275. }
  276. static inline int init_part_stats(struct hd_struct *part)
  277. {
  278. part->dkstats = alloc_percpu(struct disk_stats);
  279. if (!part->dkstats)
  280. return 0;
  281. return 1;
  282. }
  283. static inline void free_part_stats(struct hd_struct *part)
  284. {
  285. free_percpu(part->dkstats);
  286. }
  287. #else /* !CONFIG_SMP */
  288. #define part_stat_lock() ({ rcu_read_lock(); 0; })
  289. #define part_stat_unlock() rcu_read_unlock()
  290. #define __part_stat_add(cpu, part, field, addnd) \
  291. ((part)->dkstats.field += addnd)
  292. #define part_stat_read(part, field) ((part)->dkstats.field)
  293. static inline void part_stat_set_all(struct hd_struct *part, int value)
  294. {
  295. memset(&part->dkstats, value, sizeof(struct disk_stats));
  296. }
  297. static inline int init_part_stats(struct hd_struct *part)
  298. {
  299. return 1;
  300. }
  301. static inline void free_part_stats(struct hd_struct *part)
  302. {
  303. }
  304. #endif /* CONFIG_SMP */
  305. #define part_stat_add(cpu, part, field, addnd) do { \
  306. __part_stat_add((cpu), (part), field, addnd); \
  307. if ((part)->partno) \
  308. __part_stat_add((cpu), &part_to_disk((part))->part0, \
  309. field, addnd); \
  310. } while (0)
  311. #define part_stat_dec(cpu, gendiskp, field) \
  312. part_stat_add(cpu, gendiskp, field, -1)
  313. #define part_stat_inc(cpu, gendiskp, field) \
  314. part_stat_add(cpu, gendiskp, field, 1)
  315. #define part_stat_sub(cpu, gendiskp, field, subnd) \
  316. part_stat_add(cpu, gendiskp, field, -subnd)
  317. static inline void part_inc_in_flight(struct hd_struct *part, int rw)
  318. {
  319. atomic_inc(&part->in_flight[rw]);
  320. if (part->partno)
  321. atomic_inc(&part_to_disk(part)->part0.in_flight[rw]);
  322. }
  323. static inline void part_dec_in_flight(struct hd_struct *part, int rw)
  324. {
  325. atomic_dec(&part->in_flight[rw]);
  326. if (part->partno)
  327. atomic_dec(&part_to_disk(part)->part0.in_flight[rw]);
  328. }
  329. static inline int part_in_flight(struct hd_struct *part)
  330. {
  331. return atomic_read(&part->in_flight[0]) + atomic_read(&part->in_flight[1]);
  332. }
  333. static inline struct partition_meta_info *alloc_part_info(struct gendisk *disk)
  334. {
  335. if (disk)
  336. return kzalloc_node(sizeof(struct partition_meta_info),
  337. GFP_KERNEL, disk->node_id);
  338. return kzalloc(sizeof(struct partition_meta_info), GFP_KERNEL);
  339. }
  340. static inline void free_part_info(struct hd_struct *part)
  341. {
  342. kfree(part->info);
  343. }
  344. /* block/blk-core.c */
  345. extern void part_round_stats(int cpu, struct hd_struct *part);
  346. /* block/genhd.c */
  347. extern void device_add_disk(struct device *parent, struct gendisk *disk);
  348. static inline void add_disk(struct gendisk *disk)
  349. {
  350. device_add_disk(NULL, disk);
  351. }
  352. extern void del_gendisk(struct gendisk *gp);
  353. extern struct gendisk *get_gendisk(dev_t dev, int *partno);
  354. extern struct block_device *bdget_disk(struct gendisk *disk, int partno);
  355. extern void set_device_ro(struct block_device *bdev, int flag);
  356. extern void set_disk_ro(struct gendisk *disk, int flag);
  357. static inline int get_disk_ro(struct gendisk *disk)
  358. {
  359. return disk->part0.policy;
  360. }
  361. extern void disk_block_events(struct gendisk *disk);
  362. extern void disk_unblock_events(struct gendisk *disk);
  363. extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
  364. extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
  365. /* drivers/char/random.c */
  366. extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
  367. extern void rand_initialize_disk(struct gendisk *disk);
  368. static inline sector_t get_start_sect(struct block_device *bdev)
  369. {
  370. return bdev->bd_part->start_sect;
  371. }
  372. static inline sector_t get_capacity(struct gendisk *disk)
  373. {
  374. return disk->part0.nr_sects;
  375. }
  376. static inline void set_capacity(struct gendisk *disk, sector_t size)
  377. {
  378. disk->part0.nr_sects = size;
  379. }
  380. #ifdef CONFIG_SOLARIS_X86_PARTITION
  381. #define SOLARIS_X86_NUMSLICE 16
  382. #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
  383. struct solaris_x86_slice {
  384. __le16 s_tag; /* ID tag of partition */
  385. __le16 s_flag; /* permission flags */
  386. __le32 s_start; /* start sector no of partition */
  387. __le32 s_size; /* # of blocks in partition */
  388. };
  389. struct solaris_x86_vtoc {
  390. unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */
  391. __le32 v_sanity; /* to verify vtoc sanity */
  392. __le32 v_version; /* layout version */
  393. char v_volume[8]; /* volume name */
  394. __le16 v_sectorsz; /* sector size in bytes */
  395. __le16 v_nparts; /* number of partitions */
  396. unsigned int v_reserved[10]; /* free space */
  397. struct solaris_x86_slice
  398. v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
  399. unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
  400. char v_asciilabel[128]; /* for compatibility */
  401. };
  402. #endif /* CONFIG_SOLARIS_X86_PARTITION */
  403. #ifdef CONFIG_BSD_DISKLABEL
  404. /*
  405. * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
  406. * updated by Marc Espie <Marc.Espie@openbsd.org>
  407. */
  408. /* check against BSD src/sys/sys/disklabel.h for consistency */
  409. #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
  410. #define BSD_MAXPARTITIONS 16
  411. #define OPENBSD_MAXPARTITIONS 16
  412. #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
  413. struct bsd_disklabel {
  414. __le32 d_magic; /* the magic number */
  415. __s16 d_type; /* drive type */
  416. __s16 d_subtype; /* controller/d_type specific */
  417. char d_typename[16]; /* type name, e.g. "eagle" */
  418. char d_packname[16]; /* pack identifier */
  419. __u32 d_secsize; /* # of bytes per sector */
  420. __u32 d_nsectors; /* # of data sectors per track */
  421. __u32 d_ntracks; /* # of tracks per cylinder */
  422. __u32 d_ncylinders; /* # of data cylinders per unit */
  423. __u32 d_secpercyl; /* # of data sectors per cylinder */
  424. __u32 d_secperunit; /* # of data sectors per unit */
  425. __u16 d_sparespertrack; /* # of spare sectors per track */
  426. __u16 d_sparespercyl; /* # of spare sectors per cylinder */
  427. __u32 d_acylinders; /* # of alt. cylinders per unit */
  428. __u16 d_rpm; /* rotational speed */
  429. __u16 d_interleave; /* hardware sector interleave */
  430. __u16 d_trackskew; /* sector 0 skew, per track */
  431. __u16 d_cylskew; /* sector 0 skew, per cylinder */
  432. __u32 d_headswitch; /* head switch time, usec */
  433. __u32 d_trkseek; /* track-to-track seek, usec */
  434. __u32 d_flags; /* generic flags */
  435. #define NDDATA 5
  436. __u32 d_drivedata[NDDATA]; /* drive-type specific information */
  437. #define NSPARE 5
  438. __u32 d_spare[NSPARE]; /* reserved for future use */
  439. __le32 d_magic2; /* the magic number (again) */
  440. __le16 d_checksum; /* xor of data incl. partitions */
  441. /* filesystem and partition information: */
  442. __le16 d_npartitions; /* number of partitions in following */
  443. __le32 d_bbsize; /* size of boot area at sn0, bytes */
  444. __le32 d_sbsize; /* max size of fs superblock, bytes */
  445. struct bsd_partition { /* the partition table */
  446. __le32 p_size; /* number of sectors in partition */
  447. __le32 p_offset; /* starting sector */
  448. __le32 p_fsize; /* filesystem basic fragment size */
  449. __u8 p_fstype; /* filesystem type, see below */
  450. __u8 p_frag; /* filesystem fragments per block */
  451. __le16 p_cpg; /* filesystem cylinders per group */
  452. } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
  453. };
  454. #endif /* CONFIG_BSD_DISKLABEL */
  455. #ifdef CONFIG_UNIXWARE_DISKLABEL
  456. /*
  457. * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
  458. * and Krzysztof G. Baranowski <kgb@knm.org.pl>
  459. */
  460. #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
  461. #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
  462. #define UNIXWARE_NUMSLICE 16
  463. #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
  464. struct unixware_slice {
  465. __le16 s_label; /* label */
  466. __le16 s_flags; /* permission flags */
  467. __le32 start_sect; /* starting sector */
  468. __le32 nr_sects; /* number of sectors in slice */
  469. };
  470. struct unixware_disklabel {
  471. __le32 d_type; /* drive type */
  472. __le32 d_magic; /* the magic number */
  473. __le32 d_version; /* version number */
  474. char d_serial[12]; /* serial number of the device */
  475. __le32 d_ncylinders; /* # of data cylinders per device */
  476. __le32 d_ntracks; /* # of tracks per cylinder */
  477. __le32 d_nsectors; /* # of data sectors per track */
  478. __le32 d_secsize; /* # of bytes per sector */
  479. __le32 d_part_start; /* # of first sector of this partition */
  480. __le32 d_unknown1[12]; /* ? */
  481. __le32 d_alt_tbl; /* byte offset of alternate table */
  482. __le32 d_alt_len; /* byte length of alternate table */
  483. __le32 d_phys_cyl; /* # of physical cylinders per device */
  484. __le32 d_phys_trk; /* # of physical tracks per cylinder */
  485. __le32 d_phys_sec; /* # of physical sectors per track */
  486. __le32 d_phys_bytes; /* # of physical bytes per sector */
  487. __le32 d_unknown2; /* ? */
  488. __le32 d_unknown3; /* ? */
  489. __le32 d_pad[8]; /* pad */
  490. struct unixware_vtoc {
  491. __le32 v_magic; /* the magic number */
  492. __le32 v_version; /* version number */
  493. char v_name[8]; /* volume name */
  494. __le16 v_nslices; /* # of slices */
  495. __le16 v_unknown1; /* ? */
  496. __le32 v_reserved[10]; /* reserved */
  497. struct unixware_slice
  498. v_slice[UNIXWARE_NUMSLICE]; /* slice headers */
  499. } vtoc;
  500. }; /* 408 */
  501. #endif /* CONFIG_UNIXWARE_DISKLABEL */
  502. #ifdef CONFIG_MINIX_SUBPARTITION
  503. # define MINIX_NR_SUBPARTITIONS 4
  504. #endif /* CONFIG_MINIX_SUBPARTITION */
  505. #define ADDPART_FLAG_NONE 0
  506. #define ADDPART_FLAG_RAID 1
  507. #define ADDPART_FLAG_WHOLEDISK 2
  508. extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
  509. extern void blk_free_devt(dev_t devt);
  510. extern dev_t blk_lookup_devt(const char *name, int partno);
  511. extern char *disk_name (struct gendisk *hd, int partno, char *buf);
  512. extern int disk_expand_part_tbl(struct gendisk *disk, int target);
  513. extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
  514. extern int invalidate_partitions(struct gendisk *disk, struct block_device *bdev);
  515. extern struct hd_struct * __must_check add_partition(struct gendisk *disk,
  516. int partno, sector_t start,
  517. sector_t len, int flags,
  518. struct partition_meta_info
  519. *info);
  520. extern void __delete_partition(struct percpu_ref *);
  521. extern void delete_partition(struct gendisk *, int);
  522. extern void printk_all_partitions(void);
  523. extern struct gendisk *alloc_disk_node(int minors, int node_id);
  524. extern struct gendisk *alloc_disk(int minors);
  525. extern struct kobject *get_disk(struct gendisk *disk);
  526. extern void put_disk(struct gendisk *disk);
  527. extern void blk_register_region(dev_t devt, unsigned long range,
  528. struct module *module,
  529. struct kobject *(*probe)(dev_t, int *, void *),
  530. int (*lock)(dev_t, void *),
  531. void *data);
  532. extern void blk_unregister_region(dev_t devt, unsigned long range);
  533. extern ssize_t part_size_show(struct device *dev,
  534. struct device_attribute *attr, char *buf);
  535. extern ssize_t part_stat_show(struct device *dev,
  536. struct device_attribute *attr, char *buf);
  537. extern ssize_t part_inflight_show(struct device *dev,
  538. struct device_attribute *attr, char *buf);
  539. #ifdef CONFIG_FAIL_MAKE_REQUEST
  540. extern ssize_t part_fail_show(struct device *dev,
  541. struct device_attribute *attr, char *buf);
  542. extern ssize_t part_fail_store(struct device *dev,
  543. struct device_attribute *attr,
  544. const char *buf, size_t count);
  545. #endif /* CONFIG_FAIL_MAKE_REQUEST */
  546. static inline int hd_ref_init(struct hd_struct *part)
  547. {
  548. if (percpu_ref_init(&part->ref, __delete_partition, 0,
  549. GFP_KERNEL))
  550. return -ENOMEM;
  551. return 0;
  552. }
  553. static inline void hd_struct_get(struct hd_struct *part)
  554. {
  555. percpu_ref_get(&part->ref);
  556. }
  557. static inline int hd_struct_try_get(struct hd_struct *part)
  558. {
  559. return percpu_ref_tryget_live(&part->ref);
  560. }
  561. static inline void hd_struct_put(struct hd_struct *part)
  562. {
  563. percpu_ref_put(&part->ref);
  564. }
  565. static inline void hd_struct_kill(struct hd_struct *part)
  566. {
  567. percpu_ref_kill(&part->ref);
  568. }
  569. static inline void hd_free_part(struct hd_struct *part)
  570. {
  571. free_part_stats(part);
  572. free_part_info(part);
  573. percpu_ref_exit(&part->ref);
  574. }
  575. /*
  576. * Any access of part->nr_sects which is not protected by partition
  577. * bd_mutex or gendisk bdev bd_mutex, should be done using this
  578. * accessor function.
  579. *
  580. * Code written along the lines of i_size_read() and i_size_write().
  581. * CONFIG_PREEMPT case optimizes the case of UP kernel with preemption
  582. * on.
  583. */
  584. static inline sector_t part_nr_sects_read(struct hd_struct *part)
  585. {
  586. #if BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_SMP)
  587. sector_t nr_sects;
  588. unsigned seq;
  589. do {
  590. seq = read_seqcount_begin(&part->nr_sects_seq);
  591. nr_sects = part->nr_sects;
  592. } while (read_seqcount_retry(&part->nr_sects_seq, seq));
  593. return nr_sects;
  594. #elif BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_PREEMPT)
  595. sector_t nr_sects;
  596. preempt_disable();
  597. nr_sects = part->nr_sects;
  598. preempt_enable();
  599. return nr_sects;
  600. #else
  601. return part->nr_sects;
  602. #endif
  603. }
  604. /*
  605. * Should be called with mutex lock held (typically bd_mutex) of partition
  606. * to provide mutual exlusion among writers otherwise seqcount might be
  607. * left in wrong state leaving the readers spinning infinitely.
  608. */
  609. static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
  610. {
  611. #if BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_SMP)
  612. write_seqcount_begin(&part->nr_sects_seq);
  613. part->nr_sects = size;
  614. write_seqcount_end(&part->nr_sects_seq);
  615. #elif BITS_PER_LONG==32 && defined(CONFIG_LBDAF) && defined(CONFIG_PREEMPT)
  616. preempt_disable();
  617. part->nr_sects = size;
  618. preempt_enable();
  619. #else
  620. part->nr_sects = size;
  621. #endif
  622. }
  623. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  624. extern void blk_integrity_add(struct gendisk *);
  625. extern void blk_integrity_del(struct gendisk *);
  626. #else /* CONFIG_BLK_DEV_INTEGRITY */
  627. static inline void blk_integrity_add(struct gendisk *disk) { }
  628. static inline void blk_integrity_del(struct gendisk *disk) { }
  629. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  630. #else /* CONFIG_BLOCK */
  631. static inline void printk_all_partitions(void) { }
  632. static inline dev_t blk_lookup_devt(const char *name, int partno)
  633. {
  634. dev_t devt = MKDEV(0, 0);
  635. return devt;
  636. }
  637. static inline int blk_part_pack_uuid(const u8 *uuid_str, u8 *to)
  638. {
  639. return -EINVAL;
  640. }
  641. #endif /* CONFIG_BLOCK */
  642. #endif /* _LINUX_GENHD_H */