ibm.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. * History of changes (starts July 2000)
  8. * 07/10/00 Fixed detection of CMS formatted disks
  9. * 02/13/00 VTOC partition support added
  10. * 12/27/01 fixed PL030593 (CMS reserved minidisk not detected on 64 bit)
  11. * 07/24/03 no longer using contents of freed page for CMS label recognition (BZ3611)
  12. */
  13. #include <linux/config.h>
  14. #include <linux/buffer_head.h>
  15. #include <linux/hdreg.h>
  16. #include <linux/slab.h>
  17. #include <asm/dasd.h>
  18. #include <asm/ebcdic.h>
  19. #include <asm/uaccess.h>
  20. #include <asm/vtoc.h>
  21. #include "check.h"
  22. #include "ibm.h"
  23. /*
  24. * compute the block number from a
  25. * cyl-cyl-head-head structure
  26. */
  27. static inline int
  28. cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
  29. return ptr->cc * geo->heads * geo->sectors +
  30. ptr->hh * geo->sectors;
  31. }
  32. /*
  33. * compute the block number from a
  34. * cyl-cyl-head-head-block structure
  35. */
  36. static inline int
  37. cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
  38. return ptr->cc * geo->heads * geo->sectors +
  39. ptr->hh * geo->sectors +
  40. ptr->b;
  41. }
  42. /*
  43. */
  44. int
  45. ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
  46. {
  47. int blocksize, offset, size;
  48. loff_t i_size;
  49. dasd_information_t *info;
  50. struct hd_geometry *geo;
  51. char type[5] = {0,};
  52. char name[7] = {0,};
  53. union label_t {
  54. struct vtoc_volume_label vol;
  55. struct vtoc_cms_label cms;
  56. } *label;
  57. unsigned char *data;
  58. Sector sect;
  59. blocksize = bdev_hardsect_size(bdev);
  60. if (blocksize <= 0)
  61. return 0;
  62. i_size = i_size_read(bdev->bd_inode);
  63. if (i_size == 0)
  64. return 0;
  65. if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
  66. goto out_noinfo;
  67. if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
  68. goto out_nogeo;
  69. if ((label = kmalloc(sizeof(union label_t), GFP_KERNEL)) == NULL)
  70. goto out_nolab;
  71. if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
  72. ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
  73. goto out_noioctl;
  74. /*
  75. * Get volume label, extract name and type.
  76. */
  77. data = read_dev_sector(bdev, info->label_block*(blocksize/512), &sect);
  78. if (data == NULL)
  79. goto out_readerr;
  80. strncpy (type, data, 4);
  81. if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD")))
  82. strncpy(name, data + 8, 6);
  83. else
  84. strncpy(name, data + 4, 6);
  85. memcpy(label, data, sizeof(union label_t));
  86. put_dev_sector(sect);
  87. EBCASC(type, 4);
  88. EBCASC(name, 6);
  89. /*
  90. * Three different types: CMS1, VOL1 and LNX1/unlabeled
  91. */
  92. if (strncmp(type, "CMS1", 4) == 0) {
  93. /*
  94. * VM style CMS1 labeled disk
  95. */
  96. if (label->cms.disk_offset != 0) {
  97. printk("CMS1/%8s(MDSK):", name);
  98. /* disk is reserved minidisk */
  99. blocksize = label->cms.block_size;
  100. offset = label->cms.disk_offset;
  101. size = (label->cms.block_count - 1) * (blocksize >> 9);
  102. } else {
  103. printk("CMS1/%8s:", name);
  104. offset = (info->label_block + 1);
  105. size = i_size >> 9;
  106. }
  107. put_partition(state, 1, offset*(blocksize >> 9),
  108. size-offset*(blocksize >> 9));
  109. } else if ((strncmp(type, "VOL1", 4) == 0) &&
  110. (!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
  111. /*
  112. * New style VOL1 labeled disk
  113. */
  114. unsigned int blk;
  115. int counter;
  116. printk("VOL1/%8s:", name);
  117. /* get block number and read then go through format1 labels */
  118. blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
  119. counter = 0;
  120. while ((data = read_dev_sector(bdev, blk*(blocksize/512),
  121. &sect)) != NULL) {
  122. struct vtoc_format1_label f1;
  123. memcpy(&f1, data, sizeof(struct vtoc_format1_label));
  124. put_dev_sector(sect);
  125. /* skip FMT4 / FMT5 / FMT7 labels */
  126. if (f1.DS1FMTID == _ascebc['4']
  127. || f1.DS1FMTID == _ascebc['5']
  128. || f1.DS1FMTID == _ascebc['7']) {
  129. blk++;
  130. continue;
  131. }
  132. /* only FMT1 valid at this point */
  133. if (f1.DS1FMTID != _ascebc['1'])
  134. break;
  135. /* OK, we got valid partition data */
  136. offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
  137. size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
  138. offset + geo->sectors;
  139. if (counter >= state->limit)
  140. break;
  141. put_partition(state, counter + 1,
  142. offset * (blocksize >> 9),
  143. size * (blocksize >> 9));
  144. counter++;
  145. blk++;
  146. }
  147. } else {
  148. /*
  149. * Old style LNX1 or unlabeled disk
  150. */
  151. if (strncmp(type, "LNX1", 4) == 0)
  152. printk ("LNX1/%8s:", name);
  153. else
  154. printk("(nonl)/%8s:", name);
  155. offset = (info->label_block + 1);
  156. size = i_size >> 9;
  157. put_partition(state, 1, offset*(blocksize >> 9),
  158. size-offset*(blocksize >> 9));
  159. }
  160. printk("\n");
  161. kfree(label);
  162. kfree(geo);
  163. kfree(info);
  164. return 1;
  165. out_readerr:
  166. out_noioctl:
  167. kfree(label);
  168. out_nolab:
  169. kfree(geo);
  170. out_nogeo:
  171. kfree(info);
  172. out_noinfo:
  173. return 0;
  174. }