genhd.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. #ifdef CONFIG_BLOCK
  12. enum {
  13. /* These three have identical behaviour; use the second one if DOS FDISK gets
  14. confused about extended/logical partitions starting past cylinder 1023. */
  15. DOS_EXTENDED_PARTITION = 5,
  16. LINUX_EXTENDED_PARTITION = 0x85,
  17. WIN98_EXTENDED_PARTITION = 0x0f,
  18. SUN_WHOLE_DISK = DOS_EXTENDED_PARTITION,
  19. LINUX_SWAP_PARTITION = 0x82,
  20. LINUX_DATA_PARTITION = 0x83,
  21. LINUX_LVM_PARTITION = 0x8e,
  22. LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
  23. SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
  24. NEW_SOLARIS_X86_PARTITION = 0xbf,
  25. DM6_AUX1PARTITION = 0x51, /* no DDO: use xlated geom */
  26. DM6_AUX3PARTITION = 0x53, /* no DDO: use xlated geom */
  27. DM6_PARTITION = 0x54, /* has DDO: use xlated geom & offset */
  28. EZD_PARTITION = 0x55, /* EZ-DRIVE */
  29. FREEBSD_PARTITION = 0xa5, /* FreeBSD Partition ID */
  30. OPENBSD_PARTITION = 0xa6, /* OpenBSD Partition ID */
  31. NETBSD_PARTITION = 0xa9, /* NetBSD Partition ID */
  32. BSDI_PARTITION = 0xb7, /* BSDI Partition ID */
  33. MINIX_PARTITION = 0x81, /* Minix Partition ID */
  34. UNIXWARE_PARTITION = 0x63, /* Same as GNU_HURD and SCO Unix */
  35. };
  36. #ifndef __KERNEL__
  37. struct partition {
  38. unsigned char boot_ind; /* 0x80 - active */
  39. unsigned char head; /* starting head */
  40. unsigned char sector; /* starting sector */
  41. unsigned char cyl; /* starting cylinder */
  42. unsigned char sys_ind; /* What partition type */
  43. unsigned char end_head; /* end head */
  44. unsigned char end_sector; /* end sector */
  45. unsigned char end_cyl; /* end cylinder */
  46. unsigned int start_sect; /* starting sector counting from 0 */
  47. unsigned int nr_sects; /* nr of sectors in partition */
  48. } __attribute__((packed));
  49. #endif
  50. #ifdef __KERNEL__
  51. #include <linux/major.h>
  52. #include <linux/device.h>
  53. #include <linux/smp.h>
  54. #include <linux/string.h>
  55. #include <linux/fs.h>
  56. #include <linux/workqueue.h>
  57. #include <linux/bsg.h>
  58. struct partition {
  59. unsigned char boot_ind; /* 0x80 - active */
  60. unsigned char head; /* starting head */
  61. unsigned char sector; /* starting sector */
  62. unsigned char cyl; /* starting cylinder */
  63. unsigned char sys_ind; /* What partition type */
  64. unsigned char end_head; /* end head */
  65. unsigned char end_sector; /* end sector */
  66. unsigned char end_cyl; /* end cylinder */
  67. __le32 start_sect; /* starting sector counting from 0 */
  68. __le32 nr_sects; /* nr of sectors in partition */
  69. } __attribute__((packed));
  70. struct hd_struct {
  71. sector_t start_sect;
  72. sector_t nr_sects;
  73. struct kobject kobj;
  74. struct kobject *holder_dir;
  75. unsigned ios[2], sectors[2]; /* READs and WRITEs */
  76. int policy, partno;
  77. #ifdef CONFIG_FAIL_MAKE_REQUEST
  78. int make_it_fail;
  79. #endif
  80. struct bsg_class_device bsg_dev;
  81. };
  82. #define GENHD_FL_REMOVABLE 1
  83. #define GENHD_FL_DRIVERFS 2
  84. #define GENHD_FL_MEDIA_CHANGE_NOTIFY 4
  85. #define GENHD_FL_CD 8
  86. #define GENHD_FL_UP 16
  87. #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
  88. #define GENHD_FL_FAIL 64
  89. struct disk_stats {
  90. unsigned long sectors[2]; /* READs and WRITEs */
  91. unsigned long ios[2];
  92. unsigned long merges[2];
  93. unsigned long ticks[2];
  94. unsigned long io_ticks;
  95. unsigned long time_in_queue;
  96. };
  97. struct gendisk {
  98. int major; /* major number of driver */
  99. int first_minor;
  100. int minors; /* maximum number of minors, =1 for
  101. * disks that can't be partitioned. */
  102. char disk_name[32]; /* name of major driver */
  103. struct hd_struct **part; /* [indexed by minor] */
  104. int part_uevent_suppress;
  105. struct block_device_operations *fops;
  106. struct request_queue *queue;
  107. void *private_data;
  108. sector_t capacity;
  109. int flags;
  110. struct device *driverfs_dev;
  111. struct kobject kobj;
  112. struct kobject *holder_dir;
  113. struct kobject *slave_dir;
  114. struct timer_rand_state *random;
  115. int policy;
  116. atomic_t sync_io; /* RAID */
  117. unsigned long stamp;
  118. int in_flight;
  119. #ifdef CONFIG_SMP
  120. struct disk_stats *dkstats;
  121. #else
  122. struct disk_stats dkstats;
  123. #endif
  124. struct work_struct async_notify;
  125. };
  126. /* Structure for sysfs attributes on block devices */
  127. struct disk_attribute {
  128. struct attribute attr;
  129. ssize_t (*show)(struct gendisk *, char *);
  130. ssize_t (*store)(struct gendisk *, const char *, size_t);
  131. };
  132. /*
  133. * Macros to operate on percpu disk statistics:
  134. *
  135. * The __ variants should only be called in critical sections. The full
  136. * variants disable/enable preemption.
  137. */
  138. #ifdef CONFIG_SMP
  139. #define __disk_stat_add(gendiskp, field, addnd) \
  140. (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
  141. #define disk_stat_read(gendiskp, field) \
  142. ({ \
  143. typeof(gendiskp->dkstats->field) res = 0; \
  144. int i; \
  145. for_each_possible_cpu(i) \
  146. res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
  147. res; \
  148. })
  149. static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
  150. int i;
  151. for_each_possible_cpu(i)
  152. memset(per_cpu_ptr(gendiskp->dkstats, i), value,
  153. sizeof (struct disk_stats));
  154. }
  155. #else
  156. #define __disk_stat_add(gendiskp, field, addnd) \
  157. (gendiskp->dkstats.field += addnd)
  158. #define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
  159. static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
  160. memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
  161. }
  162. #endif
  163. #define disk_stat_add(gendiskp, field, addnd) \
  164. do { \
  165. preempt_disable(); \
  166. __disk_stat_add(gendiskp, field, addnd); \
  167. preempt_enable(); \
  168. } while (0)
  169. #define __disk_stat_dec(gendiskp, field) __disk_stat_add(gendiskp, field, -1)
  170. #define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
  171. #define __disk_stat_inc(gendiskp, field) __disk_stat_add(gendiskp, field, 1)
  172. #define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
  173. #define __disk_stat_sub(gendiskp, field, subnd) \
  174. __disk_stat_add(gendiskp, field, -subnd)
  175. #define disk_stat_sub(gendiskp, field, subnd) \
  176. disk_stat_add(gendiskp, field, -subnd)
  177. /* Inlines to alloc and free disk stats in struct gendisk */
  178. #ifdef CONFIG_SMP
  179. static inline int init_disk_stats(struct gendisk *disk)
  180. {
  181. disk->dkstats = alloc_percpu(struct disk_stats);
  182. if (!disk->dkstats)
  183. return 0;
  184. return 1;
  185. }
  186. static inline void free_disk_stats(struct gendisk *disk)
  187. {
  188. free_percpu(disk->dkstats);
  189. }
  190. #else /* CONFIG_SMP */
  191. static inline int init_disk_stats(struct gendisk *disk)
  192. {
  193. return 1;
  194. }
  195. static inline void free_disk_stats(struct gendisk *disk)
  196. {
  197. }
  198. #endif /* CONFIG_SMP */
  199. /* drivers/block/ll_rw_blk.c */
  200. extern void disk_round_stats(struct gendisk *disk);
  201. /* drivers/block/genhd.c */
  202. extern int get_blkdev_list(char *, int);
  203. extern void add_disk(struct gendisk *disk);
  204. extern void del_gendisk(struct gendisk *gp);
  205. extern void unlink_gendisk(struct gendisk *gp);
  206. extern struct gendisk *get_gendisk(dev_t dev, int *part);
  207. extern void set_device_ro(struct block_device *bdev, int flag);
  208. extern void set_disk_ro(struct gendisk *disk, int flag);
  209. /* drivers/char/random.c */
  210. extern void add_disk_randomness(struct gendisk *disk);
  211. extern void rand_initialize_disk(struct gendisk *disk);
  212. static inline sector_t get_start_sect(struct block_device *bdev)
  213. {
  214. return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
  215. }
  216. static inline sector_t get_capacity(struct gendisk *disk)
  217. {
  218. return disk->capacity;
  219. }
  220. static inline void set_capacity(struct gendisk *disk, sector_t size)
  221. {
  222. disk->capacity = size;
  223. }
  224. #endif /* __KERNEL__ */
  225. #ifdef CONFIG_SOLARIS_X86_PARTITION
  226. #define SOLARIS_X86_NUMSLICE 8
  227. #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
  228. struct solaris_x86_slice {
  229. __le16 s_tag; /* ID tag of partition */
  230. __le16 s_flag; /* permission flags */
  231. __le32 s_start; /* start sector no of partition */
  232. __le32 s_size; /* # of blocks in partition */
  233. };
  234. struct solaris_x86_vtoc {
  235. unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */
  236. __le32 v_sanity; /* to verify vtoc sanity */
  237. __le32 v_version; /* layout version */
  238. char v_volume[8]; /* volume name */
  239. __le16 v_sectorsz; /* sector size in bytes */
  240. __le16 v_nparts; /* number of partitions */
  241. unsigned int v_reserved[10]; /* free space */
  242. struct solaris_x86_slice
  243. v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
  244. unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
  245. char v_asciilabel[128]; /* for compatibility */
  246. };
  247. #endif /* CONFIG_SOLARIS_X86_PARTITION */
  248. #ifdef CONFIG_BSD_DISKLABEL
  249. /*
  250. * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
  251. * updated by Marc Espie <Marc.Espie@openbsd.org>
  252. */
  253. /* check against BSD src/sys/sys/disklabel.h for consistency */
  254. #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
  255. #define BSD_MAXPARTITIONS 16
  256. #define OPENBSD_MAXPARTITIONS 16
  257. #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
  258. struct bsd_disklabel {
  259. __le32 d_magic; /* the magic number */
  260. __s16 d_type; /* drive type */
  261. __s16 d_subtype; /* controller/d_type specific */
  262. char d_typename[16]; /* type name, e.g. "eagle" */
  263. char d_packname[16]; /* pack identifier */
  264. __u32 d_secsize; /* # of bytes per sector */
  265. __u32 d_nsectors; /* # of data sectors per track */
  266. __u32 d_ntracks; /* # of tracks per cylinder */
  267. __u32 d_ncylinders; /* # of data cylinders per unit */
  268. __u32 d_secpercyl; /* # of data sectors per cylinder */
  269. __u32 d_secperunit; /* # of data sectors per unit */
  270. __u16 d_sparespertrack; /* # of spare sectors per track */
  271. __u16 d_sparespercyl; /* # of spare sectors per cylinder */
  272. __u32 d_acylinders; /* # of alt. cylinders per unit */
  273. __u16 d_rpm; /* rotational speed */
  274. __u16 d_interleave; /* hardware sector interleave */
  275. __u16 d_trackskew; /* sector 0 skew, per track */
  276. __u16 d_cylskew; /* sector 0 skew, per cylinder */
  277. __u32 d_headswitch; /* head switch time, usec */
  278. __u32 d_trkseek; /* track-to-track seek, usec */
  279. __u32 d_flags; /* generic flags */
  280. #define NDDATA 5
  281. __u32 d_drivedata[NDDATA]; /* drive-type specific information */
  282. #define NSPARE 5
  283. __u32 d_spare[NSPARE]; /* reserved for future use */
  284. __le32 d_magic2; /* the magic number (again) */
  285. __le16 d_checksum; /* xor of data incl. partitions */
  286. /* filesystem and partition information: */
  287. __le16 d_npartitions; /* number of partitions in following */
  288. __le32 d_bbsize; /* size of boot area at sn0, bytes */
  289. __le32 d_sbsize; /* max size of fs superblock, bytes */
  290. struct bsd_partition { /* the partition table */
  291. __le32 p_size; /* number of sectors in partition */
  292. __le32 p_offset; /* starting sector */
  293. __le32 p_fsize; /* filesystem basic fragment size */
  294. __u8 p_fstype; /* filesystem type, see below */
  295. __u8 p_frag; /* filesystem fragments per block */
  296. __le16 p_cpg; /* filesystem cylinders per group */
  297. } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
  298. };
  299. #endif /* CONFIG_BSD_DISKLABEL */
  300. #ifdef CONFIG_UNIXWARE_DISKLABEL
  301. /*
  302. * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
  303. * and Krzysztof G. Baranowski <kgb@knm.org.pl>
  304. */
  305. #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
  306. #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
  307. #define UNIXWARE_NUMSLICE 16
  308. #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
  309. struct unixware_slice {
  310. __le16 s_label; /* label */
  311. __le16 s_flags; /* permission flags */
  312. __le32 start_sect; /* starting sector */
  313. __le32 nr_sects; /* number of sectors in slice */
  314. };
  315. struct unixware_disklabel {
  316. __le32 d_type; /* drive type */
  317. __le32 d_magic; /* the magic number */
  318. __le32 d_version; /* version number */
  319. char d_serial[12]; /* serial number of the device */
  320. __le32 d_ncylinders; /* # of data cylinders per device */
  321. __le32 d_ntracks; /* # of tracks per cylinder */
  322. __le32 d_nsectors; /* # of data sectors per track */
  323. __le32 d_secsize; /* # of bytes per sector */
  324. __le32 d_part_start; /* # of first sector of this partition */
  325. __le32 d_unknown1[12]; /* ? */
  326. __le32 d_alt_tbl; /* byte offset of alternate table */
  327. __le32 d_alt_len; /* byte length of alternate table */
  328. __le32 d_phys_cyl; /* # of physical cylinders per device */
  329. __le32 d_phys_trk; /* # of physical tracks per cylinder */
  330. __le32 d_phys_sec; /* # of physical sectors per track */
  331. __le32 d_phys_bytes; /* # of physical bytes per sector */
  332. __le32 d_unknown2; /* ? */
  333. __le32 d_unknown3; /* ? */
  334. __le32 d_pad[8]; /* pad */
  335. struct unixware_vtoc {
  336. __le32 v_magic; /* the magic number */
  337. __le32 v_version; /* version number */
  338. char v_name[8]; /* volume name */
  339. __le16 v_nslices; /* # of slices */
  340. __le16 v_unknown1; /* ? */
  341. __le32 v_reserved[10]; /* reserved */
  342. struct unixware_slice
  343. v_slice[UNIXWARE_NUMSLICE]; /* slice headers */
  344. } vtoc;
  345. }; /* 408 */
  346. #endif /* CONFIG_UNIXWARE_DISKLABEL */
  347. #ifdef CONFIG_MINIX_SUBPARTITION
  348. # define MINIX_NR_SUBPARTITIONS 4
  349. #endif /* CONFIG_MINIX_SUBPARTITION */
  350. #ifdef __KERNEL__
  351. #define ADDPART_FLAG_NONE 0
  352. #define ADDPART_FLAG_RAID 1
  353. #define ADDPART_FLAG_WHOLEDISK 2
  354. char *disk_name (struct gendisk *hd, int part, char *buf);
  355. extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
  356. extern void add_partition(struct gendisk *, int, sector_t, sector_t, int);
  357. extern void delete_partition(struct gendisk *, int);
  358. extern void printk_all_partitions(void);
  359. extern struct gendisk *alloc_disk_node(int minors, int node_id);
  360. extern struct gendisk *alloc_disk(int minors);
  361. extern struct kobject *get_disk(struct gendisk *disk);
  362. extern void put_disk(struct gendisk *disk);
  363. extern void genhd_media_change_notify(struct gendisk *disk);
  364. extern void blk_register_region(dev_t dev, unsigned long range,
  365. struct module *module,
  366. struct kobject *(*probe)(dev_t, int *, void *),
  367. int (*lock)(dev_t, void *),
  368. void *data);
  369. extern void blk_unregister_region(dev_t dev, unsigned long range);
  370. static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
  371. {
  372. return bdget(MKDEV(disk->major, disk->first_minor) + index);
  373. }
  374. #endif
  375. #else /* CONFIG_BLOCK */
  376. static inline void printk_all_partitions(void) { }
  377. #endif /* CONFIG_BLOCK */
  378. #endif