ibm.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * File...........: linux/fs/partitions/ibm.c
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Volker Sameske <sameske@de.ibm.com>
  5. * Bugreports.to..: <Linux390@de.ibm.com>
  6. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
  7. */
  8. #include <linux/buffer_head.h>
  9. #include <linux/hdreg.h>
  10. #include <linux/slab.h>
  11. #include <asm/dasd.h>
  12. #include <asm/ebcdic.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/vtoc.h>
  15. #include "check.h"
  16. #include "ibm.h"
  17. /*
  18. * compute the block number from a
  19. * cyl-cyl-head-head structure
  20. */
  21. static sector_t
  22. cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
  23. sector_t cyl;
  24. __u16 head;
  25. /*decode cylinder and heads for large volumes */
  26. cyl = ptr->hh & 0xFFF0;
  27. cyl <<= 12;
  28. cyl |= ptr->cc;
  29. head = ptr->hh & 0x000F;
  30. return cyl * geo->heads * geo->sectors +
  31. head * geo->sectors;
  32. }
  33. /*
  34. * compute the block number from a
  35. * cyl-cyl-head-head-block structure
  36. */
  37. static sector_t
  38. cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
  39. sector_t cyl;
  40. __u16 head;
  41. /*decode cylinder and heads for large volumes */
  42. cyl = ptr->hh & 0xFFF0;
  43. cyl <<= 12;
  44. cyl |= ptr->cc;
  45. head = ptr->hh & 0x000F;
  46. return cyl * geo->heads * geo->sectors +
  47. head * geo->sectors +
  48. ptr->b;
  49. }
  50. /*
  51. */
  52. int ibm_partition(struct parsed_partitions *state)
  53. {
  54. struct block_device *bdev = state->bdev;
  55. int blocksize, res;
  56. loff_t i_size, offset, size, fmt_size;
  57. dasd_information2_t *info;
  58. struct hd_geometry *geo;
  59. char type[5] = {0,};
  60. char name[7] = {0,};
  61. union label_t {
  62. struct vtoc_volume_label_cdl vol;
  63. struct vtoc_volume_label_ldl lnx;
  64. struct vtoc_cms_label cms;
  65. } *label;
  66. unsigned char *data;
  67. Sector sect;
  68. res = 0;
  69. blocksize = bdev_logical_block_size(bdev);
  70. if (blocksize <= 0)
  71. goto out_exit;
  72. i_size = i_size_read(bdev->bd_inode);
  73. if (i_size == 0)
  74. goto out_exit;
  75. info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
  76. if (info == NULL)
  77. goto out_exit;
  78. geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL);
  79. if (geo == NULL)
  80. goto out_nogeo;
  81. label = kmalloc(sizeof(union label_t), GFP_KERNEL);
  82. if (label == NULL)
  83. goto out_nolab;
  84. if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0 ||
  85. ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
  86. goto out_freeall;
  87. /*
  88. * Get volume label, extract name and type.
  89. */
  90. data = read_part_sector(state, info->label_block*(blocksize/512),
  91. &sect);
  92. if (data == NULL)
  93. goto out_readerr;
  94. memcpy(label, data, sizeof(union label_t));
  95. put_dev_sector(sect);
  96. if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
  97. strncpy(type, label->vol.vollbl, 4);
  98. strncpy(name, label->vol.volid, 6);
  99. } else {
  100. strncpy(type, label->lnx.vollbl, 4);
  101. strncpy(name, label->lnx.volid, 6);
  102. }
  103. EBCASC(type, 4);
  104. EBCASC(name, 6);
  105. res = 1;
  106. /*
  107. * Three different formats: LDL, CDL and unformated disk
  108. *
  109. * identified by info->format
  110. *
  111. * unformated disks we do not have to care about
  112. */
  113. if (info->format == DASD_FORMAT_LDL) {
  114. if (strncmp(type, "CMS1", 4) == 0) {
  115. /*
  116. * VM style CMS1 labeled disk
  117. */
  118. blocksize = label->cms.block_size;
  119. if (label->cms.disk_offset != 0) {
  120. printk("CMS1/%8s(MDSK):", name);
  121. /* disk is reserved minidisk */
  122. offset = label->cms.disk_offset;
  123. size = (label->cms.block_count - 1)
  124. * (blocksize >> 9);
  125. } else {
  126. printk("CMS1/%8s:", name);
  127. offset = (info->label_block + 1);
  128. size = label->cms.block_count
  129. * (blocksize >> 9);
  130. }
  131. put_partition(state, 1, offset*(blocksize >> 9),
  132. size-offset*(blocksize >> 9));
  133. } else {
  134. if (strncmp(type, "LNX1", 4) == 0) {
  135. printk("LNX1/%8s:", name);
  136. if (label->lnx.ldl_version == 0xf2) {
  137. fmt_size = label->lnx.formatted_blocks
  138. * (blocksize >> 9);
  139. } else if (!strcmp(info->type, "ECKD")) {
  140. /* formated w/o large volume support */
  141. fmt_size = geo->cylinders * geo->heads
  142. * geo->sectors * (blocksize >> 9);
  143. } else {
  144. /* old label and no usable disk geometry
  145. * (e.g. DIAG) */
  146. fmt_size = i_size >> 9;
  147. }
  148. size = i_size >> 9;
  149. if (fmt_size < size)
  150. size = fmt_size;
  151. offset = (info->label_block + 1);
  152. } else {
  153. /* unlabeled disk */
  154. printk("(nonl)");
  155. size = i_size >> 9;
  156. offset = (info->label_block + 1);
  157. }
  158. put_partition(state, 1, offset*(blocksize >> 9),
  159. size-offset*(blocksize >> 9));
  160. }
  161. } else if (info->format == DASD_FORMAT_CDL) {
  162. /*
  163. * New style CDL formatted disk
  164. */
  165. sector_t blk;
  166. int counter;
  167. /*
  168. * check if VOL1 label is available
  169. * if not, something is wrong, skipping partition detection
  170. */
  171. if (strncmp(type, "VOL1", 4) == 0) {
  172. printk("VOL1/%8s:", name);
  173. /*
  174. * get block number and read then go through format1
  175. * labels
  176. */
  177. blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
  178. counter = 0;
  179. data = read_part_sector(state, blk * (blocksize/512),
  180. &sect);
  181. while (data != NULL) {
  182. struct vtoc_format1_label f1;
  183. memcpy(&f1, data,
  184. sizeof(struct vtoc_format1_label));
  185. put_dev_sector(sect);
  186. /* skip FMT4 / FMT5 / FMT7 labels */
  187. if (f1.DS1FMTID == _ascebc['4']
  188. || f1.DS1FMTID == _ascebc['5']
  189. || f1.DS1FMTID == _ascebc['7']
  190. || f1.DS1FMTID == _ascebc['9']) {
  191. blk++;
  192. data = read_part_sector(state,
  193. blk * (blocksize/512), &sect);
  194. continue;
  195. }
  196. /* only FMT1 and 8 labels valid at this point */
  197. if (f1.DS1FMTID != _ascebc['1'] &&
  198. f1.DS1FMTID != _ascebc['8'])
  199. break;
  200. /* OK, we got valid partition data */
  201. offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
  202. size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
  203. offset + geo->sectors;
  204. if (counter >= state->limit)
  205. break;
  206. put_partition(state, counter + 1,
  207. offset * (blocksize >> 9),
  208. size * (blocksize >> 9));
  209. counter++;
  210. blk++;
  211. data = read_part_sector(state,
  212. blk * (blocksize/512), &sect);
  213. }
  214. if (!data)
  215. /* Are we not supposed to report this ? */
  216. goto out_readerr;
  217. } else
  218. printk(KERN_WARNING "Warning, expected Label VOL1 not "
  219. "found, treating as CDL formated Disk");
  220. }
  221. printk("\n");
  222. goto out_freeall;
  223. out_readerr:
  224. res = -1;
  225. out_freeall:
  226. kfree(label);
  227. out_nolab:
  228. kfree(geo);
  229. out_nogeo:
  230. kfree(info);
  231. out_exit:
  232. return res;
  233. }