genhd.h 23 KB

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