genhd.h 14 KB

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