Release 4.7 block/partitions/ibm.c
/*
* Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
* Volker Sameske <sameske@de.ibm.com>
* Bugreports.to..: <Linux390@de.ibm.com>
* Copyright IBM Corp. 1999, 2012
*/
#include <linux/buffer_head.h>
#include <linux/hdreg.h>
#include <linux/slab.h>
#include <asm/dasd.h>
#include <asm/ebcdic.h>
#include <asm/uaccess.h>
#include <asm/vtoc.h>
#include "check.h"
#include "ibm.h"
union label_t {
struct vtoc_volume_label_cdl vol;
struct vtoc_volume_label_ldl lnx;
struct vtoc_cms_label cms;
};
/*
* compute the block number from a
* cyl-cyl-head-head structure
*/
static sector_t cchh2blk(struct vtoc_cchh *ptr, struct hd_geometry *geo)
{
sector_t cyl;
__u16 head;
/* decode cylinder and heads for large volumes */
cyl = ptr->hh & 0xFFF0;
cyl <<= 12;
cyl |= ptr->cc;
head = ptr->hh & 0x000F;
return cyl * geo->heads * geo->sectors +
head * geo->sectors;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 34 | 51.52% | 2 | 33.33% |
linus torvalds | linus torvalds | 25 | 37.88% | 2 | 33.33% |
pre-git | pre-git | 5 | 7.58% | 1 | 16.67% |
peter oberparleiter | peter oberparleiter | 2 | 3.03% | 1 | 16.67% |
| Total | 66 | 100.00% | 6 | 100.00% |
/*
* compute the block number from a
* cyl-cyl-head-head-block structure
*/
static sector_t cchhb2blk(struct vtoc_cchhb *ptr, struct hd_geometry *geo)
{
sector_t cyl;
__u16 head;
/* decode cylinder and heads for large volumes */
cyl = ptr->hh & 0xFFF0;
cyl <<= 12;
cyl |= ptr->cc;
head = ptr->hh & 0x000F;
return cyl * geo->heads * geo->sectors +
head * geo->sectors +
ptr->b;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 34 | 48.57% | 2 | 50.00% |
linus torvalds | linus torvalds | 34 | 48.57% | 1 | 25.00% |
peter oberparleiter | peter oberparleiter | 2 | 2.86% | 1 | 25.00% |
| Total | 70 | 100.00% | 4 | 100.00% |
static int find_label(struct parsed_partitions *state,
dasd_information2_t *info,
struct hd_geometry *geo,
int blocksize,
sector_t *labelsect,
char name[],
char type[],
union label_t *label)
{
Sector sect;
unsigned char *data;
sector_t testsect[3];
unsigned char temp[5];
int found = 0;
int i, testcount;
/* There a three places where we may find a valid label:
* - on an ECKD disk it's block 2
* - on an FBA disk it's block 1
* - on an CMS formatted FBA disk it is sector 1, even if the block size
* is larger than 512 bytes (possible if the DIAG discipline is used)
* If we have a valid info structure, then we know exactly which case we
* have, otherwise we just search through all possebilities.
*/
if (info) {
if ((info->cu_type == 0x6310 && info->dev_type == 0x9336) ||
(info->cu_type == 0x3880 && info->dev_type == 0x3370))
testsect[0] = info->label_block;
else
testsect[0] = info->label_block * (blocksize >> 9);
testcount = 1;
} else {
testsect[0] = 1;
testsect[1] = (blocksize >> 9);
testsect[2] = 2 * (blocksize >> 9);
testcount = 3;
}
for (i = 0; i < testcount; ++i) {
data = read_part_sector(state, testsect[i], §);
if (data == NULL)
continue;
memcpy(label, data, sizeof(*label));
memcpy(temp, data, 4);
temp[4] = 0;
EBCASC(temp, 4);
put_dev_sector(sect);
if (!strcmp(temp, "VOL1") ||
!strcmp(temp, "LNX1") ||
!strcmp(temp, "CMS1")) {
if (!strcmp(temp, "VOL1")) {
strncpy(type, label->vol.vollbl, 4);
strncpy(name, label->vol.volid, 6);
} else {
strncpy(type, label->lnx.vollbl, 4);
strncpy(name, label->lnx.volid, 6);
}
EBCASC(type, 4);
EBCASC(name, 6);
*labelsect = testsect[i];
found = 1;
break;
}
}
if (!found)
memset(label, 0, sizeof(*label));
return found;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 238 | 60.10% | 2 | 12.50% |
peter oberparleiter | peter oberparleiter | 50 | 12.63% | 2 | 12.50% |
linus torvalds | linus torvalds | 48 | 12.12% | 4 | 25.00% |
pre-git | pre-git | 26 | 6.57% | 1 | 6.25% |
martin schwidefsky | martin schwidefsky | 19 | 4.80% | 1 | 6.25% |
alexey dobriyan | alexey dobriyan | 4 | 1.01% | 1 | 6.25% |
stefan haberland | stefan haberland | 4 | 1.01% | 1 | 6.25% |
suzuki k poulose | suzuki k poulose | 3 | 0.76% | 1 | 6.25% |
al viro | al viro | 2 | 0.51% | 1 | 6.25% |
tejun heo | tejun heo | 1 | 0.25% | 1 | 6.25% |
horst hummel | horst hummel | 1 | 0.25% | 1 | 6.25% |
| Total | 396 | 100.00% | 16 | 100.00% |
static int find_vol1_partitions(struct parsed_partitions *state,
struct hd_geometry *geo,
int blocksize,
char name[],
union label_t *label)
{
sector_t blk;
int counter;
char tmp[64];
Sector sect;
unsigned char *data;
loff_t offset, size;
struct vtoc_format1_label f1;
int secperblk;
snprintf(tmp, sizeof(tmp), "VOL1/%8s:", name);
strlcat(state->pp_buf, tmp, PAGE_SIZE);
/*
* get start of VTOC from the disk label and then search for format1
* and format8 labels
*/
secperblk = blocksize >> 9;
blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
counter = 0;
data = read_part_sector(state, blk * secperblk, §);
while (data != NULL) {
memcpy(&f1, data, sizeof(struct vtoc_format1_label));
put_dev_sector(sect);
/* skip FMT4 / FMT5 / FMT7 labels */
if (f1.DS1FMTID == _ascebc['4']
|| f1.DS1FMTID == _ascebc['5']
|| f1.DS1FMTID == _ascebc['7']
|| f1.DS1FMTID == _ascebc['9']) {
blk++;
data = read_part_sector(state, blk * secperblk, §);
continue;
}
/* only FMT1 and 8 labels valid at this point */
if (f1.DS1FMTID != _ascebc['1'] &&
f1.DS1FMTID != _ascebc['8'])
break;
/* OK, we got valid partition data */
offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
offset + geo->sectors;
offset *= secperblk;
size *= secperblk;
if (counter >= state->limit)
break;
put_partition(state, counter + 1, offset, size);
counter++;
blk++;
data = read_part_sector(state, blk * secperblk, §);
}
strlcat(state->pp_buf, "\n", PAGE_SIZE);
if (!data)
return -1;
return 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 308 | 90.06% | 1 | 16.67% |
alexey dobriyan | alexey dobriyan | 19 | 5.56% | 1 | 16.67% |
martin schwidefsky | martin schwidefsky | 6 | 1.75% | 1 | 16.67% |
linus torvalds | linus torvalds | 5 | 1.46% | 1 | 16.67% |
peter oberparleiter | peter oberparleiter | 2 | 0.58% | 1 | 16.67% |
pre-git | pre-git | 2 | 0.58% | 1 | 16.67% |
| Total | 342 | 100.00% | 6 | 100.00% |
static int find_lnx1_partitions(struct parsed_partitions *state,
struct hd_geometry *geo,
int blocksize,
char name[],
union label_t *label,
sector_t labelsect,
loff_t i_size,
dasd_information2_t *info)
{
loff_t offset, geo_size, size;
char tmp[64];
int secperblk;
snprintf(tmp, sizeof(tmp), "LNX1/%8s:", name);
strlcat(state->pp_buf, tmp, PAGE_SIZE);
secperblk = blocksize >> 9;
if (label->lnx.ldl_version == 0xf2) {
size = label->lnx.formatted_blocks * secperblk;
} else {
/*
* Formated w/o large volume support. If the sanity check
* 'size based on geo == size based on i_size' is true, then
* we can safely assume that we know the formatted size of
* the disk, otherwise we need additional information
* that we can only get from a real DASD device.
*/
geo_size = geo->cylinders * geo->heads
* geo->sectors * secperblk;
size = i_size >> 9;
if (size != geo_size) {
if (!info) {
strlcat(state->pp_buf, "\n", PAGE_SIZE);
return 1;
}
if (!strcmp(info->type, "ECKD"))
if (geo_size < size)
size = geo_size;
/* else keep size based on i_size */
}
}
/* first and only partition starts in the first block after the label */
offset = labelsect + secperblk;
put_partition(state, 1, offset, size - offset);
strlcat(state->pp_buf, "\n", PAGE_SIZE);
return 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 219 | 100.00% | 1 | 100.00% |
| Total | 219 | 100.00% | 1 | 100.00% |
static int find_cms1_partitions(struct parsed_partitions *state,
struct hd_geometry *geo,
int blocksize,
char name[],
union label_t *label,
sector_t labelsect)
{
loff_t offset, size;
char tmp[64];
int secperblk;
/*
* VM style CMS1 labeled disk
*/
blocksize = label->cms.block_size;
secperblk = blocksize >> 9;
if (label->cms.disk_offset != 0) {
snprintf(tmp, sizeof(tmp), "CMS1/%8s(MDSK):", name);
strlcat(state->pp_buf, tmp, PAGE_SIZE);
/* disk is reserved minidisk */
offset = label->cms.disk_offset * secperblk;
size = (label->cms.block_count - 1) * secperblk;
} else {
snprintf(tmp, sizeof(tmp), "CMS1/%8s:", name);
strlcat(state->pp_buf, tmp, PAGE_SIZE);
/*
* Special case for FBA devices:
* If an FBA device is CMS formatted with blocksize > 512 byte
* and the DIAG discipline is used, then the CMS label is found
* in sector 1 instead of block 1. However, the partition is
* still supposed to start in block 2.
*/
if (labelsect == 1)
offset = 2 * secperblk;
else
offset = labelsect + secperblk;
size = label->cms.block_count * secperblk;
}
put_partition(state, 1, offset, size-offset);
strlcat(state->pp_buf, "\n", PAGE_SIZE);
return 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 147 | 71.01% | 2 | 25.00% |
alexey dobriyan | alexey dobriyan | 38 | 18.36% | 1 | 12.50% |
stefan haberland | stefan haberland | 10 | 4.83% | 1 | 12.50% |
linus torvalds | linus torvalds | 9 | 4.35% | 3 | 37.50% |
martin schwidefsky | martin schwidefsky | 3 | 1.45% | 1 | 12.50% |
| Total | 207 | 100.00% | 8 | 100.00% |
/*
* This is the main function, called by check.c
*/
int ibm_partition(struct parsed_partitions *state)
{
struct block_device *bdev = state->bdev;
int blocksize, res;
loff_t i_size, offset, size;
dasd_information2_t *info;
struct hd_geometry *geo;
char type[5] = {0,};
char name[7] = {0,};
sector_t labelsect;
union label_t *label;
res = 0;
blocksize = bdev_logical_block_size(bdev);
if (blocksize <= 0)
goto out_exit;
i_size = i_size_read(bdev->bd_inode);
if (i_size == 0)
goto out_exit;
info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
if (info == NULL)
goto out_exit;
geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL);
if (geo == NULL)
goto out_nogeo;
label = kmalloc(sizeof(union label_t), GFP_KERNEL);
if (label == NULL)
goto out_nolab;
if (ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
goto out_freeall;
if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0) {
kfree(info);
info = NULL;
}
if (find_label(state, info, geo, blocksize, &labelsect, name, type,
label)) {
if (!strncmp(type, "VOL1", 4)) {
res = find_vol1_partitions(state, geo, blocksize, name,
label);
} else if (!strncmp(type, "LNX1", 4)) {
res = find_lnx1_partitions(state, geo, blocksize, name,
label, labelsect, i_size,
info);
} else if (!strncmp(type, "CMS1", 4)) {
res = find_cms1_partitions(state, geo, blocksize, name,
label, labelsect);
}
} else if (info) {
/*
* ugly but needed for backward compatibility:
* If the block device is a DASD (i.e. BIODASDINFO2 works),
* then we claim it in any case, even though it has no valid
* label. If it has the LDL format, then we simply define a
* partition as if it had an LNX1 label.
*/
res = 1;
if (info->format == DASD_FORMAT_LDL) {
strlcat(state->pp_buf, "(nonl)", PAGE_SIZE);
size = i_size >> 9;
offset = (info->label_block + 1) * (blocksize >> 9);
put_partition(state, 1, offset, size-offset);
strlcat(state->pp_buf, "\n", PAGE_SIZE);
}
} else
res = 0;
out_freeall:
kfree(label);
out_nolab:
kfree(geo);
out_nogeo:
kfree(info);
out_exit:
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 311 | 69.11% | 2 | 14.29% |
martin schwidefsky | martin schwidefsky | 43 | 9.56% | 1 | 7.14% |
linus torvalds | linus torvalds | 41 | 9.11% | 3 | 21.43% |
alexey dobriyan | alexey dobriyan | 16 | 3.56% | 1 | 7.14% |
stefan haberland | stefan haberland | 16 | 3.56% | 1 | 7.14% |
pre-git | pre-git | 10 | 2.22% | 1 | 7.14% |
suzuki k poulose | suzuki k poulose | 6 | 1.33% | 1 | 7.14% |
tejun heo | tejun heo | 3 | 0.67% | 1 | 7.14% |
peter oberparleiter | peter oberparleiter | 2 | 0.44% | 1 | 7.14% |
al viro | al viro | 1 | 0.22% | 1 | 7.14% |
heiko carstens | heiko carstens | 1 | 0.22% | 1 | 7.14% |
| Total | 450 | 100.00% | 14 | 100.00% |
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
stefan weinhuber | stefan weinhuber | 1310 | 72.86% | 2 | 10.00% |
linus torvalds | linus torvalds | 179 | 9.96% | 4 | 20.00% |
alexey dobriyan | alexey dobriyan | 77 | 4.28% | 1 | 5.00% |
martin schwidefsky | martin schwidefsky | 76 | 4.23% | 2 | 10.00% |
peter oberparleiter | peter oberparleiter | 58 | 3.23% | 3 | 15.00% |
pre-git | pre-git | 48 | 2.67% | 1 | 5.00% |
stefan haberland | stefan haberland | 30 | 1.67% | 1 | 5.00% |
suzuki k poulose | suzuki k poulose | 9 | 0.50% | 1 | 5.00% |
tejun heo | tejun heo | 4 | 0.22% | 1 | 5.00% |
horst hummel | horst hummel | 3 | 0.17% | 2 | 10.00% |
al viro | al viro | 3 | 0.17% | 1 | 5.00% |
heiko carstens | heiko carstens | 1 | 0.06% | 1 | 5.00% |
| Total | 1798 | 100.00% | 20 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.