Merge mainline.
This commit is contained in:
commit
50ee5d686d
193 changed files with 9983 additions and 1425 deletions
|
@ -208,7 +208,7 @@ grub_affs_mount (grub_disk_t disk)
|
|||
rblock = (struct grub_affs_rblock *) rootblock;
|
||||
|
||||
/* Read the rootblock. */
|
||||
grub_disk_read (disk, (disk->total_sectors >> 1) + blocksize, 0,
|
||||
grub_disk_read (disk, grub_be_to_cpu32 (data->bblock.rootblock), 0,
|
||||
GRUB_DISK_SECTOR_SIZE * 16, rootblock);
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
|
@ -240,7 +240,7 @@ grub_affs_mount (grub_disk_t disk)
|
|||
data->disk = disk;
|
||||
data->htsize = grub_be_to_cpu32 (rblock->htsize);
|
||||
data->diropen.data = data;
|
||||
data->diropen.block = (disk->total_sectors >> 1);
|
||||
data->diropen.block = grub_be_to_cpu32 (data->bblock.rootblock);
|
||||
|
||||
grub_free (rootblock);
|
||||
|
||||
|
@ -507,7 +507,7 @@ grub_affs_label (grub_device_t device, char **label)
|
|||
{
|
||||
/* The rootblock maps quite well on a file header block, it's
|
||||
something we can use here. */
|
||||
grub_disk_read (data->disk, disk->total_sectors >> 1,
|
||||
grub_disk_read (data->disk, grub_be_to_cpu32 (data->bblock.rootblock),
|
||||
data->blocksize * (GRUB_DISK_SECTOR_SIZE
|
||||
- GRUB_AFFS_FILE_LOCATION),
|
||||
sizeof (file), &file);
|
||||
|
@ -535,6 +535,9 @@ static struct grub_fs grub_affs_fs =
|
|||
.read = grub_affs_read,
|
||||
.close = grub_affs_close,
|
||||
.label = grub_affs_label,
|
||||
#ifdef GRUB_UTIL
|
||||
.reserved_first_sector = 0,
|
||||
#endif
|
||||
.next = 0
|
||||
};
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ grub_btrfs_mount (grub_disk_t disk)
|
|||
&data->sblock) != GRUB_ERR_NONE)
|
||||
goto fail;
|
||||
|
||||
if (grub_strncmp ((char *) data->sblock.signature, BTRFS_SIGNATURE, sizeof (BTRFS_SIGNATURE) - 1))
|
||||
if (grub_memcmp ((char *) data->sblock.signature, BTRFS_SIGNATURE, sizeof (BTRFS_SIGNATURE) - 1))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a Btrfs filesystem");
|
||||
goto fail;
|
||||
|
@ -60,6 +60,9 @@ grub_btrfs_mount (grub_disk_t disk)
|
|||
return data;
|
||||
|
||||
fail:
|
||||
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
|
||||
grub_error (GRUB_ERR_BAD_FS, "not a Btrfs filesystem");
|
||||
|
||||
grub_free (data);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -354,6 +354,9 @@ static struct grub_fs grub_cpio_fs = {
|
|||
.open = grub_cpio_open,
|
||||
.read = grub_cpio_read,
|
||||
.close = grub_cpio_close,
|
||||
#ifdef GRUB_UTIL
|
||||
.reserved_first_sector = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef MODE_USTAR
|
||||
|
|
|
@ -229,7 +229,7 @@ struct grub_ext2_inode
|
|||
};
|
||||
grub_uint32_t version;
|
||||
grub_uint32_t acl;
|
||||
grub_uint32_t dir_acl;
|
||||
grub_uint32_t size_high;
|
||||
grub_uint32_t fragment_addr;
|
||||
grub_uint32_t osd2[3];
|
||||
};
|
||||
|
@ -470,10 +470,41 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
|||
blknr = grub_le_to_cpu32 (indir[rblock % perblock]);
|
||||
}
|
||||
/* triple indirect. */
|
||||
else if (fileblock < INDIRECT_BLOCKS + blksz / 4 * (blksz / 4 + 1)
|
||||
+ (blksz / 4) * (blksz / 4) * (blksz / 4 + 1))
|
||||
{
|
||||
unsigned int perblock = blksz / 4;
|
||||
unsigned int rblock = fileblock - (INDIRECT_BLOCKS + blksz / 4
|
||||
* (blksz / 4 + 1));
|
||||
grub_uint32_t indir[blksz / 4];
|
||||
|
||||
if (grub_disk_read (data->disk,
|
||||
((grub_disk_addr_t)
|
||||
grub_le_to_cpu32 (inode->blocks.triple_indir_block))
|
||||
<< log2_blksz,
|
||||
0, blksz, indir))
|
||||
return grub_errno;
|
||||
|
||||
if (grub_disk_read (data->disk,
|
||||
((grub_disk_addr_t)
|
||||
grub_le_to_cpu32 (indir[(rblock / perblock) / perblock]))
|
||||
<< log2_blksz,
|
||||
0, blksz, indir))
|
||||
return grub_errno;
|
||||
|
||||
if (grub_disk_read (data->disk,
|
||||
((grub_disk_addr_t)
|
||||
grub_le_to_cpu32 (indir[(rblock / perblock) % perblock]))
|
||||
<< log2_blksz,
|
||||
0, blksz, indir))
|
||||
return grub_errno;
|
||||
|
||||
blknr = grub_le_to_cpu32 (indir[rblock % perblock]);
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"ext2fs doesn't support triple indirect blocks");
|
||||
"ext2fs doesn't support quadruple indirect blocks");
|
||||
}
|
||||
|
||||
return blknr;
|
||||
|
@ -485,11 +516,12 @@ static grub_ssize_t
|
|||
grub_ext2_read_file (grub_fshelp_node_t node,
|
||||
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
|
||||
unsigned offset, unsigned length),
|
||||
int pos, grub_size_t len, char *buf)
|
||||
grub_off_t pos, grub_size_t len, char *buf)
|
||||
{
|
||||
return grub_fshelp_read_file (node->data->disk, node, read_hook,
|
||||
pos, len, buf, grub_ext2_read_block,
|
||||
node->inode.size,
|
||||
grub_cpu_to_le32 (node->inode.size)
|
||||
| (((grub_off_t) grub_cpu_to_le32 (node->inode.size_high)) << 32),
|
||||
LOG2_EXT2_BLOCK_SIZE (node->data));
|
||||
|
||||
}
|
||||
|
@ -523,7 +555,7 @@ grub_ext2_read_inode (struct grub_ext2_data *data,
|
|||
|
||||
/* Read the inode. */
|
||||
if (grub_disk_read (data->disk,
|
||||
((grub_le_to_cpu32 (blkgrp.inode_table_id) + blkno)
|
||||
(((grub_disk_addr_t) grub_le_to_cpu32 (blkgrp.inode_table_id) + blkno)
|
||||
<< LOG2_EXT2_BLOCK_SIZE (data)),
|
||||
EXT2_INODE_SIZE (data) * blkoff,
|
||||
sizeof (struct grub_ext2_inode), inode))
|
||||
|
@ -756,6 +788,7 @@ grub_ext2_open (struct grub_file *file, const char *name)
|
|||
grub_free (fdiro);
|
||||
|
||||
file->size = grub_le_to_cpu32 (data->inode->size);
|
||||
file->size |= ((grub_off_t) grub_le_to_cpu32 (data->inode->size_high)) << 32;
|
||||
file->data = data;
|
||||
file->offset = 0;
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ enum grub_hfsplus_filetype
|
|||
/* Internal representation of a catalog key. */
|
||||
struct grub_hfsplus_catkey_internal
|
||||
{
|
||||
int parent;
|
||||
grub_uint32_t parent;
|
||||
char *name;
|
||||
};
|
||||
|
||||
|
@ -520,9 +520,12 @@ grub_hfsplus_cmp_catkey (struct grub_hfsplus_key *keya,
|
|||
int i;
|
||||
int diff;
|
||||
|
||||
diff = grub_be_to_cpu32 (catkey_a->parent) - catkey_b->parent;
|
||||
if (diff)
|
||||
return diff;
|
||||
/* Safe unsigned comparison */
|
||||
grub_uint32_t aparent = grub_be_to_cpu32 (catkey_a->parent);
|
||||
if (aparent > catkey_b->parent)
|
||||
return 1;
|
||||
if (aparent < catkey_b->parent)
|
||||
return -1;
|
||||
|
||||
/* Change the filename in keya so the endianness is correct. */
|
||||
for (i = 0; i < grub_be_to_cpu16 (catkey_a->namelen); i++)
|
||||
|
@ -555,15 +558,21 @@ grub_hfsplus_cmp_extkey (struct grub_hfsplus_key *keya,
|
|||
{
|
||||
struct grub_hfsplus_extkey *extkey_a = &keya->extkey;
|
||||
struct grub_hfsplus_extkey_internal *extkey_b = &keyb->extkey;
|
||||
int diff;
|
||||
grub_uint32_t akey;
|
||||
|
||||
diff = grub_be_to_cpu32 (extkey_a->fileid) - extkey_b->fileid;
|
||||
|
||||
if (diff)
|
||||
return diff;
|
||||
|
||||
diff = grub_be_to_cpu32 (extkey_a->start) - extkey_b->start;
|
||||
return diff;
|
||||
/* Safe unsigned comparison */
|
||||
akey = grub_be_to_cpu32 (extkey_a->fileid);
|
||||
if (akey > extkey_b->fileid)
|
||||
return 1;
|
||||
if (akey < extkey_b->fileid)
|
||||
return -1;
|
||||
|
||||
akey = grub_be_to_cpu32 (extkey_a->start);
|
||||
if (akey > extkey_b->start)
|
||||
return 1;
|
||||
if (akey < extkey_b->start)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
|
|
@ -808,6 +808,15 @@ grub_iso9660_label (grub_device_t device, char **label)
|
|||
((grub_uint16_t *) &data->voldesc.volname, 16);
|
||||
else
|
||||
*label = grub_strndup ((char *) data->voldesc.volname, 32);
|
||||
if (*label)
|
||||
{
|
||||
char *ptr;
|
||||
for (ptr = *label; *ptr;ptr++);
|
||||
ptr--;
|
||||
while (ptr >= *label && *ptr == ' ')
|
||||
*ptr-- = 0;
|
||||
}
|
||||
|
||||
grub_free (data);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1072,7 +1072,11 @@ grub_ntfs_uuid (grub_device_t device, char **uuid)
|
|||
data = grub_ntfs_mount (disk);
|
||||
if (data)
|
||||
{
|
||||
char *ptr;
|
||||
*uuid = grub_xasprintf ("%016llx", (unsigned long long) data->uuid);
|
||||
if (*uuid)
|
||||
for (ptr = *uuid; *ptr; ptr++)
|
||||
*ptr = grub_toupper (*ptr);
|
||||
}
|
||||
else
|
||||
*uuid = NULL;
|
||||
|
|
|
@ -579,6 +579,9 @@ static struct grub_fs grub_sfs_fs =
|
|||
.read = grub_sfs_read,
|
||||
.close = grub_sfs_close,
|
||||
.label = grub_sfs_label,
|
||||
#ifdef GRUB_UTIL
|
||||
.reserved_first_sector = 0,
|
||||
#endif
|
||||
.next = 0
|
||||
};
|
||||
|
||||
|
|
|
@ -34,9 +34,6 @@
|
|||
#define U32 grub_le_to_cpu32
|
||||
#define U64 grub_le_to_cpu64
|
||||
|
||||
#define GRUB_UDF_LOG2_BLKSZ 2
|
||||
#define GRUB_UDF_BLKSZ 2048
|
||||
|
||||
#define GRUB_UDF_TAG_IDENT_PVD 0x0001
|
||||
#define GRUB_UDF_TAG_IDENT_AVDP 0x0002
|
||||
#define GRUB_UDF_TAG_IDENT_VDP 0x0003
|
||||
|
@ -336,6 +333,13 @@ struct grub_udf_lvd
|
|||
grub_uint8_t part_maps[1608];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_udf_aed
|
||||
{
|
||||
struct grub_udf_tag tag;
|
||||
grub_uint32_t prev_ae;
|
||||
grub_uint32_t ae_len;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_udf_data
|
||||
{
|
||||
grub_disk_t disk;
|
||||
|
@ -343,7 +347,7 @@ struct grub_udf_data
|
|||
struct grub_udf_pd pds[GRUB_UDF_MAX_PDS];
|
||||
struct grub_udf_partmap *pms[GRUB_UDF_MAX_PMS];
|
||||
struct grub_udf_long_ad root_icb;
|
||||
int npd, npm;
|
||||
int npd, npm, lbshift;
|
||||
};
|
||||
|
||||
struct grub_fshelp_node
|
||||
|
@ -389,7 +393,7 @@ grub_udf_read_icb (struct grub_udf_data *data,
|
|||
if (grub_errno)
|
||||
return grub_errno;
|
||||
|
||||
if (grub_disk_read (data->disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
|
||||
if (grub_disk_read (data->disk, block << data->lbshift, 0,
|
||||
sizeof (struct grub_udf_file_entry),
|
||||
&node->fe))
|
||||
return grub_errno;
|
||||
|
@ -406,19 +410,26 @@ grub_udf_read_icb (struct grub_udf_data *data,
|
|||
static grub_disk_addr_t
|
||||
grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
||||
{
|
||||
char *buf = NULL;
|
||||
char *ptr;
|
||||
int len;
|
||||
grub_ssize_t len;
|
||||
grub_disk_addr_t filebytes;
|
||||
|
||||
if (U16 (node->fe.tag.tag_ident) == GRUB_UDF_TAG_IDENT_FE)
|
||||
switch (U16 (node->fe.tag.tag_ident))
|
||||
{
|
||||
case GRUB_UDF_TAG_IDENT_FE:
|
||||
ptr = (char *) &node->fe.ext_attr[0] + U32 (node->fe.ext_attr_length);
|
||||
len = U32 (node->fe.alloc_descs_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
|
||||
case GRUB_UDF_TAG_IDENT_EFE:
|
||||
ptr = (char *) &node->efe.ext_attr[0] + U32 (node->efe.ext_attr_length);
|
||||
len = U32 (node->efe.alloc_descs_length);
|
||||
break;
|
||||
|
||||
default:
|
||||
grub_error (GRUB_ERR_BAD_FS, "invalid file entry");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((U16 (node->fe.icbtag.flags) & GRUB_UDF_ICBTAG_FLAG_AD_MASK)
|
||||
|
@ -426,43 +437,115 @@ grub_udf_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
|||
{
|
||||
struct grub_udf_short_ad *ad = (struct grub_udf_short_ad *) ptr;
|
||||
|
||||
len /= sizeof (struct grub_udf_short_ad);
|
||||
filebytes = fileblock * GRUB_UDF_BLKSZ;
|
||||
while (len > 0)
|
||||
filebytes = fileblock * U32 (node->data->lvd.bsize);
|
||||
while (len >= (grub_ssize_t) sizeof (struct grub_udf_short_ad))
|
||||
{
|
||||
if (filebytes < U32 (ad->length))
|
||||
return ((U32 (ad->position) & GRUB_UDF_EXT_MASK) ? 0 :
|
||||
(grub_udf_get_block (node->data,
|
||||
node->part_ref,
|
||||
ad->position)
|
||||
+ (filebytes / GRUB_UDF_BLKSZ)));
|
||||
grub_uint32_t adlen = U32 (ad->length) & 0x3fffffff;
|
||||
grub_uint32_t adtype = U32 (ad->length) >> 30;
|
||||
if (adtype == 3)
|
||||
{
|
||||
struct grub_udf_aed *extension;
|
||||
grub_disk_addr_t sec = grub_udf_get_block(node->data,
|
||||
node->part_ref,
|
||||
ad->position);
|
||||
if (!buf)
|
||||
{
|
||||
buf = grub_malloc (U32 (node->data->lvd.bsize));
|
||||
if (!buf)
|
||||
return 0;
|
||||
}
|
||||
if (grub_disk_read (node->data->disk, sec << node->data->lbshift,
|
||||
0, adlen, buf))
|
||||
goto fail;
|
||||
|
||||
filebytes -= U32 (ad->length);
|
||||
extension = (struct grub_udf_aed *) buf;
|
||||
if (U16 (extension->tag.tag_ident) != GRUB_UDF_TAG_IDENT_AED)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "invalid aed tag");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
len = U32 (extension->ae_len);
|
||||
ad = (struct grub_udf_short_ad *)
|
||||
(buf + sizeof (struct grub_udf_aed));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filebytes < adlen)
|
||||
{
|
||||
grub_uint32_t ad_pos = ad->position;
|
||||
grub_free (buf);
|
||||
return ((U32 (ad_pos) & GRUB_UDF_EXT_MASK) ? 0 :
|
||||
(grub_udf_get_block (node->data, node->part_ref, ad_pos)
|
||||
+ (filebytes >> (GRUB_DISK_SECTOR_BITS
|
||||
+ node->data->lbshift))));
|
||||
}
|
||||
|
||||
filebytes -= adlen;
|
||||
ad++;
|
||||
len--;
|
||||
len -= sizeof (struct grub_udf_short_ad);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
struct grub_udf_long_ad *ad = (struct grub_udf_long_ad *) ptr;
|
||||
|
||||
len /= sizeof (struct grub_udf_long_ad);
|
||||
filebytes = fileblock * GRUB_UDF_BLKSZ;
|
||||
while (len > 0)
|
||||
filebytes = fileblock * U32 (node->data->lvd.bsize);
|
||||
while (len >= (grub_ssize_t) sizeof (struct grub_udf_long_ad))
|
||||
{
|
||||
if (filebytes < U32 (ad->length))
|
||||
return ((U32 (ad->block.block_num) & GRUB_UDF_EXT_MASK) ? 0 :
|
||||
(grub_udf_get_block (node->data,
|
||||
ad->block.part_ref,
|
||||
ad->block.block_num)
|
||||
+ (filebytes / GRUB_UDF_BLKSZ)));
|
||||
grub_uint32_t adlen = U32 (ad->length) & 0x3fffffff;
|
||||
grub_uint32_t adtype = U32 (ad->length) >> 30;
|
||||
if (adtype == 3)
|
||||
{
|
||||
struct grub_udf_aed *extension;
|
||||
grub_disk_addr_t sec = grub_udf_get_block(node->data,
|
||||
ad->block.part_ref,
|
||||
ad->block.block_num);
|
||||
if (!buf)
|
||||
{
|
||||
buf = grub_malloc (U32 (node->data->lvd.bsize));
|
||||
if (!buf)
|
||||
return 0;
|
||||
}
|
||||
if (grub_disk_read (node->data->disk, sec << node->data->lbshift,
|
||||
0, adlen, buf))
|
||||
goto fail;
|
||||
|
||||
filebytes -= U32 (ad->length);
|
||||
extension = (struct grub_udf_aed *) buf;
|
||||
if (U16 (extension->tag.tag_ident) != GRUB_UDF_TAG_IDENT_AED)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "invalid aed tag");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
len = U32 (extension->ae_len);
|
||||
ad = (struct grub_udf_long_ad *)
|
||||
(buf + sizeof (struct grub_udf_aed));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filebytes < adlen)
|
||||
{
|
||||
grub_uint32_t ad_block_num = ad->block.block_num;
|
||||
grub_uint32_t ad_part_ref = ad->block.part_ref;
|
||||
grub_free (buf);
|
||||
return ((U32 (ad_block_num) & GRUB_UDF_EXT_MASK) ? 0 :
|
||||
(grub_udf_get_block (node->data, ad_part_ref,
|
||||
ad_block_num)
|
||||
+ (filebytes >> (GRUB_DISK_SECTOR_BITS
|
||||
+ node->data->lbshift))));
|
||||
}
|
||||
|
||||
filebytes -= adlen;
|
||||
ad++;
|
||||
len--;
|
||||
len -= sizeof (struct grub_udf_long_ad);
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
if (buf)
|
||||
grub_free (buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -471,7 +554,7 @@ grub_udf_read_file (grub_fshelp_node_t node,
|
|||
void NESTED_FUNC_ATTR
|
||||
(*read_hook) (grub_disk_addr_t sector,
|
||||
unsigned offset, unsigned length),
|
||||
int pos, grub_size_t len, char *buf)
|
||||
grub_off_t pos, grub_size_t len, char *buf)
|
||||
{
|
||||
switch (U16 (node->fe.icbtag.flags) & GRUB_UDF_ICBTAG_FLAG_AD_MASK)
|
||||
{
|
||||
|
@ -496,21 +579,21 @@ grub_udf_read_file (grub_fshelp_node_t node,
|
|||
}
|
||||
|
||||
return grub_fshelp_read_file (node->data->disk, node, read_hook,
|
||||
pos, len, buf, grub_udf_read_block,
|
||||
U64 (node->fe.file_size),
|
||||
GRUB_UDF_LOG2_BLKSZ);
|
||||
pos, len, buf, grub_udf_read_block,
|
||||
U64 (node->fe.file_size),
|
||||
node->data->lbshift);
|
||||
}
|
||||
|
||||
static int sblocklist[] = { 256, 512, 0 };
|
||||
static unsigned sblocklist[] = { 256, 512, 0 };
|
||||
|
||||
static struct grub_udf_data *
|
||||
grub_udf_mount (grub_disk_t disk)
|
||||
{
|
||||
struct grub_udf_data *data = 0;
|
||||
struct grub_udf_fileset root_fs;
|
||||
int *sblklist = sblocklist;
|
||||
grub_uint32_t block;
|
||||
int i;
|
||||
unsigned *sblklist;
|
||||
grub_uint32_t block, vblock;
|
||||
int i, lbshift;
|
||||
|
||||
data = grub_malloc (sizeof (struct grub_udf_data));
|
||||
if (!data)
|
||||
|
@ -518,12 +601,48 @@ grub_udf_mount (grub_disk_t disk)
|
|||
|
||||
data->disk = disk;
|
||||
|
||||
/* Search for Anchor Volume Descriptor Pointer (AVDP)
|
||||
* and determine logical block size. */
|
||||
block = 0;
|
||||
for (lbshift = 0; lbshift < 4; lbshift++)
|
||||
{
|
||||
for (sblklist = sblocklist; *sblklist; sblklist++)
|
||||
{
|
||||
struct grub_udf_avdp avdp;
|
||||
|
||||
if (grub_disk_read (disk, *sblklist << lbshift, 0,
|
||||
sizeof (struct grub_udf_avdp), &avdp))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (U16 (avdp.tag.tag_ident) == GRUB_UDF_TAG_IDENT_AVDP &&
|
||||
U32 (avdp.tag.tag_location) == *sblklist)
|
||||
{
|
||||
block = U32 (avdp.vds.start);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (block)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!block)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
|
||||
goto fail;
|
||||
}
|
||||
data->lbshift = lbshift;
|
||||
|
||||
/* Search for Volume Recognition Sequence (VRS). */
|
||||
for (block = 16;; block++)
|
||||
for (vblock = (32767 >> (lbshift + GRUB_DISK_SECTOR_BITS)) + 1;;
|
||||
vblock += (2047 >> (lbshift + GRUB_DISK_SECTOR_BITS)) + 1)
|
||||
{
|
||||
struct grub_udf_vrs vrs;
|
||||
|
||||
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
|
||||
if (grub_disk_read (disk, vblock << lbshift, 0,
|
||||
sizeof (struct grub_udf_vrs), &vrs))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
|
||||
|
@ -545,39 +664,13 @@ grub_udf_mount (grub_disk_t disk)
|
|||
}
|
||||
}
|
||||
|
||||
/* Search for Anchor Volume Descriptor Pointer (AVDP). */
|
||||
while (1)
|
||||
{
|
||||
struct grub_udf_avdp avdp;
|
||||
|
||||
if (grub_disk_read (disk, *sblklist << GRUB_UDF_LOG2_BLKSZ, 0,
|
||||
sizeof (struct grub_udf_avdp), &avdp))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (U16 (avdp.tag.tag_ident) == GRUB_UDF_TAG_IDENT_AVDP)
|
||||
{
|
||||
block = U32 (avdp.vds.start);
|
||||
break;
|
||||
}
|
||||
|
||||
sblklist++;
|
||||
if (*sblklist == 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
data->npd = data->npm = 0;
|
||||
/* Locate Partition Descriptor (PD) and Logical Volume Descriptor (LVD). */
|
||||
while (1)
|
||||
{
|
||||
struct grub_udf_tag tag;
|
||||
|
||||
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
|
||||
if (grub_disk_read (disk, block << lbshift, 0,
|
||||
sizeof (struct grub_udf_tag), &tag))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
|
||||
|
@ -593,7 +686,7 @@ grub_udf_mount (grub_disk_t disk)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
|
||||
if (grub_disk_read (disk, block << lbshift, 0,
|
||||
sizeof (struct grub_udf_pd),
|
||||
&data->pds[data->npd]))
|
||||
{
|
||||
|
@ -609,7 +702,7 @@ grub_udf_mount (grub_disk_t disk)
|
|||
|
||||
struct grub_udf_partmap *ppm;
|
||||
|
||||
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
|
||||
if (grub_disk_read (disk, block << lbshift, 0,
|
||||
sizeof (struct grub_udf_lvd),
|
||||
&data->lvd))
|
||||
{
|
||||
|
@ -673,7 +766,7 @@ grub_udf_mount (grub_disk_t disk)
|
|||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
if (grub_disk_read (disk, block << GRUB_UDF_LOG2_BLKSZ, 0,
|
||||
if (grub_disk_read (disk, block << lbshift, 0,
|
||||
sizeof (struct grub_udf_fileset), &root_fs))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FS, "not an UDF filesystem");
|
||||
|
@ -695,6 +788,43 @@ fail:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
read_string (grub_uint8_t *raw, grub_size_t sz)
|
||||
{
|
||||
grub_uint16_t *utf16 = NULL;
|
||||
char *ret;
|
||||
grub_size_t utf16len = 0;
|
||||
|
||||
if (raw[0] != 8 && raw[0] != 16)
|
||||
return NULL;
|
||||
|
||||
if (raw[0] == 8)
|
||||
{
|
||||
unsigned i;
|
||||
utf16len = sz - 1;
|
||||
utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
|
||||
if (!utf16)
|
||||
return NULL;
|
||||
for (i = 0; i < utf16len; i++)
|
||||
utf16[i] = raw[i + 1];
|
||||
}
|
||||
if (raw[0] == 16)
|
||||
{
|
||||
unsigned i;
|
||||
utf16len = (sz - 1) / 2;
|
||||
utf16 = grub_malloc (utf16len * sizeof (utf16[0]));
|
||||
if (!utf16)
|
||||
return NULL;
|
||||
for (i = 0; i < utf16len; i++)
|
||||
utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2];
|
||||
}
|
||||
ret = grub_malloc (utf16len * 3 + 1);
|
||||
if (ret)
|
||||
*grub_utf16_to_utf8 ((grub_uint8_t *) ret, utf16, utf16len) = '\0';
|
||||
grub_free (utf16);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_udf_iterate_dir (grub_fshelp_node_t dir,
|
||||
int NESTED_FUNC_ATTR
|
||||
|
@ -704,7 +834,7 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
|
|||
{
|
||||
grub_fshelp_node_t child;
|
||||
struct grub_udf_file_ident dirent;
|
||||
grub_uint32_t offset = 0;
|
||||
grub_off_t offset = 0;
|
||||
|
||||
child = grub_malloc (sizeof (struct grub_fshelp_node));
|
||||
if (!child)
|
||||
|
@ -729,57 +859,47 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
|
|||
return 0;
|
||||
}
|
||||
|
||||
child = grub_malloc (sizeof (struct grub_fshelp_node));
|
||||
if (!child)
|
||||
return 0;
|
||||
|
||||
if (grub_udf_read_icb (dir->data, &dirent.icb, child))
|
||||
return 0;
|
||||
|
||||
offset += sizeof (dirent) + U16 (dirent.imp_use_length);
|
||||
if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT)
|
||||
if (!(dirent.characteristics & GRUB_UDF_FID_CHAR_DELETED))
|
||||
{
|
||||
/* This is the parent directory. */
|
||||
if (hook ("..", GRUB_FSHELP_DIR, child))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
enum grub_fshelp_filetype type;
|
||||
grub_uint8_t raw[dirent.file_ident_length];
|
||||
grub_uint16_t utf16[dirent.file_ident_length - 1];
|
||||
grub_uint8_t filename[dirent.file_ident_length * 2];
|
||||
grub_size_t utf16len = 0;
|
||||
|
||||
type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ?
|
||||
(GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG));
|
||||
|
||||
if ((grub_udf_read_file (dir, 0, offset,
|
||||
dirent.file_ident_length,
|
||||
(char *) raw))
|
||||
!= dirent.file_ident_length)
|
||||
child = grub_malloc (sizeof (struct grub_fshelp_node));
|
||||
if (!child)
|
||||
return 0;
|
||||
|
||||
if (raw[0] == 8)
|
||||
if (grub_udf_read_icb (dir->data, &dirent.icb, child))
|
||||
return 0;
|
||||
|
||||
if (dirent.characteristics & GRUB_UDF_FID_CHAR_PARENT)
|
||||
{
|
||||
unsigned i;
|
||||
utf16len = dirent.file_ident_length - 1;
|
||||
for (i = 0; i < utf16len; i++)
|
||||
utf16[i] = raw[i + 1];
|
||||
/* This is the parent directory. */
|
||||
if (hook ("..", GRUB_FSHELP_DIR, child))
|
||||
return 1;
|
||||
}
|
||||
if (raw[0] == 16)
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
utf16len = (dirent.file_ident_length - 1) / 2;
|
||||
for (i = 0; i < utf16len; i++)
|
||||
utf16[i] = (raw[2 * i + 1] << 8) | raw[2*i + 2];
|
||||
}
|
||||
if (raw[0] == 8 || raw[0] == 16)
|
||||
{
|
||||
*grub_utf16_to_utf8 (filename, utf16, utf16len) = '\0';
|
||||
|
||||
if (hook ((char *) filename, type, child))
|
||||
return 1;
|
||||
enum grub_fshelp_filetype type;
|
||||
char *filename;
|
||||
grub_uint8_t raw[dirent.file_ident_length];
|
||||
|
||||
type = ((dirent.characteristics & GRUB_UDF_FID_CHAR_DIRECTORY) ?
|
||||
(GRUB_FSHELP_DIR) : (GRUB_FSHELP_REG));
|
||||
|
||||
if ((grub_udf_read_file (dir, 0, offset,
|
||||
dirent.file_ident_length,
|
||||
(char *) raw))
|
||||
!= dirent.file_ident_length)
|
||||
return 0;
|
||||
|
||||
filename = read_string (raw, dirent.file_ident_length);
|
||||
if (!filename)
|
||||
grub_print_error ();
|
||||
|
||||
if (filename && hook (filename, type, child))
|
||||
{
|
||||
grub_free (filename);
|
||||
return 1;
|
||||
}
|
||||
grub_free (filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -908,7 +1028,7 @@ grub_udf_label (grub_device_t device, char **label)
|
|||
|
||||
if (data)
|
||||
{
|
||||
*label = grub_strdup ((char *) &data->lvd.ident[1]);
|
||||
*label = read_string (data->lvd.ident, sizeof (data->lvd.ident));
|
||||
grub_free (data);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -451,18 +451,27 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
|
|||
for (i = 0; i < diro->inode.data.dir.dirhead.count; i++)
|
||||
{
|
||||
grub_uint64_t ino;
|
||||
void *inopos = (((char *) de)
|
||||
grub_uint8_t *inopos = (((grub_uint8_t *) de)
|
||||
+ sizeof (struct grub_xfs_dir_entry)
|
||||
+ de->len - 1);
|
||||
char name[de->len + 1];
|
||||
|
||||
/* inopos might be unaligned. */
|
||||
if (smallino)
|
||||
{
|
||||
ino = grub_be_to_cpu32 (*(grub_uint32_t *) inopos);
|
||||
ino = grub_cpu_to_be64 (ino);
|
||||
}
|
||||
ino = (((grub_uint32_t) inopos[0]) << 24)
|
||||
| (((grub_uint32_t) inopos[1]) << 16)
|
||||
| (((grub_uint32_t) inopos[2]) << 8)
|
||||
| (((grub_uint32_t) inopos[3]) << 0);
|
||||
else
|
||||
ino = *(grub_uint64_t *) inopos;
|
||||
ino = (((grub_uint64_t) inopos[0]) << 56)
|
||||
| (((grub_uint64_t) inopos[1]) << 48)
|
||||
| (((grub_uint64_t) inopos[2]) << 40)
|
||||
| (((grub_uint64_t) inopos[3]) << 32)
|
||||
| (((grub_uint64_t) inopos[4]) << 24)
|
||||
| (((grub_uint64_t) inopos[5]) << 16)
|
||||
| (((grub_uint64_t) inopos[6]) << 8)
|
||||
| (((grub_uint64_t) inopos[7]) << 0);
|
||||
ino = grub_cpu_to_be64 (ino);
|
||||
|
||||
grub_memcpy (name, de->name, de->len);
|
||||
name[de->len] = '\0';
|
||||
|
@ -808,6 +817,9 @@ static struct grub_fs grub_xfs_fs =
|
|||
.close = grub_xfs_close,
|
||||
.label = grub_xfs_label,
|
||||
.uuid = grub_xfs_uuid,
|
||||
#ifdef GRUB_UTIL
|
||||
.reserved_first_sector = 0,
|
||||
#endif
|
||||
.next = 0
|
||||
};
|
||||
|
||||
|
|
2548
grub-core/fs/zfs/zfs.c
Normal file
2548
grub-core/fs/zfs/zfs.c
Normal file
File diff suppressed because it is too large
Load diff
84
grub-core/fs/zfs/zfs_fletcher.c
Normal file
84
grub-core/fs/zfs/zfs_fletcher.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
|
||||
* Copyright 2007 Sun Microsystems, Inc.
|
||||
*
|
||||
* GRUB is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/err.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/zfs/zfs.h>
|
||||
#include <grub/zfs/zio.h>
|
||||
#include <grub/zfs/dnode.h>
|
||||
#include <grub/zfs/uberblock_impl.h>
|
||||
#include <grub/zfs/vdev_impl.h>
|
||||
#include <grub/zfs/zio_checksum.h>
|
||||
#include <grub/zfs/zap_impl.h>
|
||||
#include <grub/zfs/zap_leaf.h>
|
||||
#include <grub/zfs/zfs_znode.h>
|
||||
#include <grub/zfs/dmu.h>
|
||||
#include <grub/zfs/dmu_objset.h>
|
||||
#include <grub/zfs/dsl_dir.h>
|
||||
#include <grub/zfs/dsl_dataset.h>
|
||||
|
||||
void
|
||||
fletcher_2(const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
|
||||
zio_cksum_t *zcp)
|
||||
{
|
||||
const grub_uint64_t *ip = buf;
|
||||
const grub_uint64_t *ipend = ip + (size / sizeof (grub_uint64_t));
|
||||
grub_uint64_t a0, b0, a1, b1;
|
||||
|
||||
for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2)
|
||||
{
|
||||
a0 += grub_zfs_to_cpu64 (ip[0], endian);
|
||||
a1 += grub_zfs_to_cpu64 (ip[1], endian);
|
||||
b0 += a0;
|
||||
b1 += a1;
|
||||
}
|
||||
|
||||
zcp->zc_word[0] = grub_cpu_to_zfs64 (a0, endian);
|
||||
zcp->zc_word[1] = grub_cpu_to_zfs64 (a1, endian);
|
||||
zcp->zc_word[2] = grub_cpu_to_zfs64 (b0, endian);
|
||||
zcp->zc_word[3] = grub_cpu_to_zfs64 (b1, endian);
|
||||
}
|
||||
|
||||
void
|
||||
fletcher_4 (const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
|
||||
zio_cksum_t *zcp)
|
||||
{
|
||||
const grub_uint32_t *ip = buf;
|
||||
const grub_uint32_t *ipend = ip + (size / sizeof (grub_uint32_t));
|
||||
grub_uint64_t a, b, c, d;
|
||||
|
||||
for (a = b = c = d = 0; ip < ipend; ip++)
|
||||
{
|
||||
a += grub_zfs_to_cpu32 (ip[0], endian);;
|
||||
b += a;
|
||||
c += b;
|
||||
d += c;
|
||||
}
|
||||
|
||||
zcp->zc_word[0] = grub_cpu_to_zfs64 (a, endian);
|
||||
zcp->zc_word[1] = grub_cpu_to_zfs64 (b, endian);
|
||||
zcp->zc_word[2] = grub_cpu_to_zfs64 (c, endian);
|
||||
zcp->zc_word[3] = grub_cpu_to_zfs64 (d, endian);
|
||||
}
|
||||
|
93
grub-core/fs/zfs/zfs_lzjb.c
Normal file
93
grub-core/fs/zfs/zfs_lzjb.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
|
||||
* Copyright 2007 Sun Microsystems, Inc.
|
||||
*
|
||||
* GRUB is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/err.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/zfs/zfs.h>
|
||||
#include <grub/zfs/zio.h>
|
||||
#include <grub/zfs/dnode.h>
|
||||
#include <grub/zfs/uberblock_impl.h>
|
||||
#include <grub/zfs/vdev_impl.h>
|
||||
#include <grub/zfs/zio_checksum.h>
|
||||
#include <grub/zfs/zap_impl.h>
|
||||
#include <grub/zfs/zap_leaf.h>
|
||||
#include <grub/zfs/zfs_znode.h>
|
||||
#include <grub/zfs/dmu.h>
|
||||
#include <grub/zfs/dmu_objset.h>
|
||||
#include <grub/zfs/dsl_dir.h>
|
||||
#include <grub/zfs/dsl_dataset.h>
|
||||
|
||||
#define MATCH_BITS 6
|
||||
#define MATCH_MIN 3
|
||||
#define OFFSET_MASK ((1 << (16 - MATCH_BITS)) - 1)
|
||||
|
||||
/*
|
||||
* Decompression Entry - lzjb
|
||||
*/
|
||||
#ifndef NBBY
|
||||
#define NBBY 8
|
||||
#endif
|
||||
|
||||
grub_err_t
|
||||
lzjb_decompress (void *s_start, void *d_start, grub_size_t s_len,
|
||||
grub_size_t d_len);
|
||||
|
||||
grub_err_t
|
||||
lzjb_decompress (void *s_start, void *d_start, grub_size_t s_len,
|
||||
grub_size_t d_len)
|
||||
{
|
||||
grub_uint8_t *src = s_start;
|
||||
grub_uint8_t *dst = d_start;
|
||||
grub_uint8_t *d_end = (grub_uint8_t *) d_start + d_len;
|
||||
grub_uint8_t *s_end = (grub_uint8_t *) s_start + s_len;
|
||||
grub_uint8_t *cpy, copymap = 0;
|
||||
int copymask = 1 << (NBBY - 1);
|
||||
|
||||
while (dst < d_end && src < s_end)
|
||||
{
|
||||
if ((copymask <<= 1) == (1 << NBBY))
|
||||
{
|
||||
copymask = 1;
|
||||
copymap = *src++;
|
||||
}
|
||||
if (src >= s_end)
|
||||
return grub_error (GRUB_ERR_BAD_FS, "lzjb decompression failed");
|
||||
if (copymap & copymask)
|
||||
{
|
||||
int mlen = (src[0] >> (NBBY - MATCH_BITS)) + MATCH_MIN;
|
||||
int offset = ((src[0] << NBBY) | src[1]) & OFFSET_MASK;
|
||||
src += 2;
|
||||
cpy = dst - offset;
|
||||
if (src > s_end || cpy < (grub_uint8_t *) d_start)
|
||||
return grub_error (GRUB_ERR_BAD_FS, "lzjb decompression failed");
|
||||
while (--mlen >= 0 && dst < d_end)
|
||||
*dst++ = *cpy++;
|
||||
}
|
||||
else
|
||||
*dst++ = *src++;
|
||||
}
|
||||
if (dst < d_end)
|
||||
return grub_error (GRUB_ERR_BAD_FS, "lzjb decompression failed");
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
143
grub-core/fs/zfs/zfs_sha256.c
Normal file
143
grub-core/fs/zfs/zfs_sha256.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
|
||||
* Copyright 2007 Sun Microsystems, Inc.
|
||||
*
|
||||
* GRUB is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/err.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/zfs/zfs.h>
|
||||
#include <grub/zfs/zio.h>
|
||||
#include <grub/zfs/dnode.h>
|
||||
#include <grub/zfs/uberblock_impl.h>
|
||||
#include <grub/zfs/vdev_impl.h>
|
||||
#include <grub/zfs/zio_checksum.h>
|
||||
#include <grub/zfs/zap_impl.h>
|
||||
#include <grub/zfs/zap_leaf.h>
|
||||
#include <grub/zfs/zfs_znode.h>
|
||||
#include <grub/zfs/dmu.h>
|
||||
#include <grub/zfs/dmu_objset.h>
|
||||
#include <grub/zfs/dsl_dir.h>
|
||||
#include <grub/zfs/dsl_dataset.h>
|
||||
|
||||
/*
|
||||
* SHA-256 checksum, as specified in FIPS 180-2, available at:
|
||||
* http://csrc.nist.gov/cryptval
|
||||
*
|
||||
* This is a very compact implementation of SHA-256.
|
||||
* It is designed to be simple and portable, not to be fast.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The literal definitions according to FIPS180-2 would be:
|
||||
*
|
||||
* Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
|
||||
* Maj(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
*
|
||||
* We use logical equivalents which require one less op.
|
||||
*/
|
||||
#define Ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define Maj(x, y, z) (((x) & (y)) ^ ((z) & ((x) ^ (y))))
|
||||
#define Rot32(x, s) (((x) >> s) | ((x) << (32 - s)))
|
||||
#define SIGMA0(x) (Rot32(x, 2) ^ Rot32(x, 13) ^ Rot32(x, 22))
|
||||
#define SIGMA1(x) (Rot32(x, 6) ^ Rot32(x, 11) ^ Rot32(x, 25))
|
||||
#define sigma0(x) (Rot32(x, 7) ^ Rot32(x, 18) ^ ((x) >> 3))
|
||||
#define sigma1(x) (Rot32(x, 17) ^ Rot32(x, 19) ^ ((x) >> 10))
|
||||
|
||||
static const grub_uint32_t SHA256_K[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
static void
|
||||
SHA256Transform(grub_uint32_t *H, const grub_uint8_t *cp)
|
||||
{
|
||||
grub_uint32_t a, b, c, d, e, f, g, h, t, T1, T2, W[64];
|
||||
|
||||
for (t = 0; t < 16; t++, cp += 4)
|
||||
W[t] = (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
|
||||
|
||||
for (t = 16; t < 64; t++)
|
||||
W[t] = sigma1(W[t - 2]) + W[t - 7] +
|
||||
sigma0(W[t - 15]) + W[t - 16];
|
||||
|
||||
a = H[0]; b = H[1]; c = H[2]; d = H[3];
|
||||
e = H[4]; f = H[5]; g = H[6]; h = H[7];
|
||||
|
||||
for (t = 0; t < 64; t++) {
|
||||
T1 = h + SIGMA1(e) + Ch(e, f, g) + SHA256_K[t] + W[t];
|
||||
T2 = SIGMA0(a) + Maj(a, b, c);
|
||||
h = g; g = f; f = e; e = d + T1;
|
||||
d = c; c = b; b = a; a = T1 + T2;
|
||||
}
|
||||
|
||||
H[0] += a; H[1] += b; H[2] += c; H[3] += d;
|
||||
H[4] += e; H[5] += f; H[6] += g; H[7] += h;
|
||||
}
|
||||
|
||||
void
|
||||
zio_checksum_SHA256(const void *buf, grub_uint64_t size,
|
||||
grub_zfs_endian_t endian, zio_cksum_t *zcp)
|
||||
{
|
||||
grub_uint32_t H[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
|
||||
grub_uint8_t pad[128];
|
||||
unsigned padsize = size & 63;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < size - padsize; i += 64)
|
||||
SHA256Transform(H, (grub_uint8_t *)buf + i);
|
||||
|
||||
for (i = 0; i < padsize; i++)
|
||||
pad[i] = ((grub_uint8_t *)buf)[i];
|
||||
|
||||
for (pad[padsize++] = 0x80; (padsize & 63) != 56; padsize++)
|
||||
pad[padsize] = 0;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
pad[padsize++] = (size << 3) >> (56 - 8 * i);
|
||||
|
||||
for (i = 0; i < padsize; i += 64)
|
||||
SHA256Transform(H, pad + i);
|
||||
|
||||
zcp->zc_word[0] = grub_cpu_to_zfs64 ((grub_uint64_t)H[0] << 32 | H[1],
|
||||
endian);
|
||||
zcp->zc_word[1] = grub_cpu_to_zfs64 ((grub_uint64_t)H[2] << 32 | H[3],
|
||||
endian);
|
||||
zcp->zc_word[2] = grub_cpu_to_zfs64 ((grub_uint64_t)H[4] << 32 | H[5],
|
||||
endian);
|
||||
zcp->zc_word[3] = grub_cpu_to_zfs64 ((grub_uint64_t)H[6] << 32 | H[7],
|
||||
endian);
|
||||
}
|
407
grub-core/fs/zfs/zfsinfo.c
Normal file
407
grub-core/fs/zfs/zfsinfo.c
Normal file
|
@ -0,0 +1,407 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
|
||||
* Copyright 2008 Sun Microsystems, Inc.
|
||||
*
|
||||
* GRUB is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/zfs/zfs.h>
|
||||
#include <grub/device.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
static inline void
|
||||
print_tabs (int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
grub_printf (" ");
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
print_state (char *nvlist, int tab)
|
||||
{
|
||||
grub_uint64_t ival;
|
||||
int isok = 1;
|
||||
|
||||
print_tabs (tab);
|
||||
grub_printf ("State: ");
|
||||
|
||||
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_REMOVED, &ival))
|
||||
{
|
||||
grub_printf ("removed ");
|
||||
isok = 0;
|
||||
}
|
||||
|
||||
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_FAULTED, &ival))
|
||||
{
|
||||
grub_printf ("faulted ");
|
||||
isok = 0;
|
||||
}
|
||||
|
||||
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_OFFLINE, &ival))
|
||||
{
|
||||
grub_printf ("offline ");
|
||||
isok = 0;
|
||||
}
|
||||
|
||||
if (grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_FAULTED, &ival))
|
||||
grub_printf ("degraded ");
|
||||
|
||||
if (isok)
|
||||
grub_printf ("online");
|
||||
grub_printf ("\n");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
print_vdev_info (char *nvlist, int tab)
|
||||
{
|
||||
char *type = 0;
|
||||
|
||||
type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
|
||||
|
||||
if (!type)
|
||||
{
|
||||
print_tabs (tab);
|
||||
grub_printf ("Incorrect VDEV: no type available\n");
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
|
||||
{
|
||||
char *bootpath = 0;
|
||||
char *path = 0;
|
||||
char *devid = 0;
|
||||
|
||||
print_tabs (tab);
|
||||
grub_printf ("Leaf VDEV\n");
|
||||
|
||||
print_state (nvlist, tab);
|
||||
|
||||
bootpath =
|
||||
grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_PHYS_PATH);
|
||||
print_tabs (tab);
|
||||
if (!bootpath)
|
||||
grub_printf ("Bootpath: unavailable\n");
|
||||
else
|
||||
grub_printf ("Bootpath: %s\n", bootpath);
|
||||
|
||||
path = grub_zfs_nvlist_lookup_string (nvlist, "path");
|
||||
print_tabs (tab);
|
||||
if (!path)
|
||||
grub_printf ("Path: unavailable\n");
|
||||
else
|
||||
grub_printf ("Path: %s\n", path);
|
||||
|
||||
devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
|
||||
print_tabs (tab);
|
||||
if (!devid)
|
||||
grub_printf ("Devid: unavailable\n");
|
||||
else
|
||||
grub_printf ("Devid: %s\n", devid);
|
||||
grub_free (bootpath);
|
||||
grub_free (devid);
|
||||
grub_free (path);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0)
|
||||
{
|
||||
int nelm, i;
|
||||
|
||||
nelm = grub_zfs_nvlist_lookup_nvlist_array_get_nelm
|
||||
(nvlist, ZPOOL_CONFIG_CHILDREN);
|
||||
|
||||
print_tabs (tab);
|
||||
if (nelm <= 0)
|
||||
{
|
||||
grub_printf ("Incorrect mirror VDEV\n");
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
grub_printf ("Mirror VDEV with %d children\n", nelm);
|
||||
print_state (nvlist, tab);
|
||||
|
||||
for (i = 0; i < nelm; i++)
|
||||
{
|
||||
char *child;
|
||||
|
||||
child = grub_zfs_nvlist_lookup_nvlist_array
|
||||
(nvlist, ZPOOL_CONFIG_CHILDREN, i);
|
||||
|
||||
print_tabs (tab);
|
||||
if (!child)
|
||||
{
|
||||
grub_printf ("Mirror VDEV element %d isn't correct\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
grub_printf ("Mirror VDEV element %d:\n", i);
|
||||
print_vdev_info (child, tab + 1);
|
||||
|
||||
grub_free (child);
|
||||
}
|
||||
}
|
||||
|
||||
print_tabs (tab);
|
||||
grub_printf ("Unknown VDEV type: %s\n", type);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
get_bootpath (char *nvlist, char **bootpath, char **devid)
|
||||
{
|
||||
char *type = 0;
|
||||
|
||||
type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE);
|
||||
|
||||
if (!type)
|
||||
return grub_errno;
|
||||
|
||||
if (grub_strcmp (type, VDEV_TYPE_DISK) == 0)
|
||||
{
|
||||
*bootpath = grub_zfs_nvlist_lookup_string (nvlist,
|
||||
ZPOOL_CONFIG_PHYS_PATH);
|
||||
*devid = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_DEVID);
|
||||
if (!*bootpath || !*devid)
|
||||
{
|
||||
grub_free (*bootpath);
|
||||
grub_free (*devid);
|
||||
*bootpath = 0;
|
||||
*devid = 0;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0)
|
||||
{
|
||||
int nelm, i;
|
||||
|
||||
nelm = grub_zfs_nvlist_lookup_nvlist_array_get_nelm
|
||||
(nvlist, ZPOOL_CONFIG_CHILDREN);
|
||||
|
||||
for (i = 0; i < nelm; i++)
|
||||
{
|
||||
char *child;
|
||||
|
||||
child = grub_zfs_nvlist_lookup_nvlist_array (nvlist,
|
||||
ZPOOL_CONFIG_CHILDREN,
|
||||
i);
|
||||
|
||||
get_bootpath (child, bootpath, devid);
|
||||
|
||||
grub_free (child);
|
||||
|
||||
if (*bootpath && *devid)
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static char *poolstates[] = {
|
||||
[POOL_STATE_ACTIVE] = "active",
|
||||
[POOL_STATE_EXPORTED] = "exported",
|
||||
[POOL_STATE_DESTROYED] = "destroyed",
|
||||
[POOL_STATE_SPARE] = "reserved for hot spare",
|
||||
[POOL_STATE_L2CACHE] = "level 2 ARC device",
|
||||
[POOL_STATE_UNINITIALIZED] = "uninitialized",
|
||||
[POOL_STATE_UNAVAIL] = "unavailable",
|
||||
[POOL_STATE_POTENTIALLY_ACTIVE] = "potentially active"
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_zfsinfo (grub_command_t cmd __attribute__ ((unused)), int argc,
|
||||
char **args)
|
||||
{
|
||||
grub_device_t dev;
|
||||
char *devname;
|
||||
grub_err_t err;
|
||||
char *nvlist = 0;
|
||||
char *nv = 0;
|
||||
char *poolname;
|
||||
grub_uint64_t guid;
|
||||
grub_uint64_t pool_state;
|
||||
int found;
|
||||
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
|
||||
|
||||
if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
|
||||
{
|
||||
devname = grub_strdup (args[0] + 1);
|
||||
if (devname)
|
||||
devname[grub_strlen (devname) - 1] = 0;
|
||||
}
|
||||
else
|
||||
devname = grub_strdup (args[0]);
|
||||
if (!devname)
|
||||
return grub_errno;
|
||||
|
||||
dev = grub_device_open (devname);
|
||||
grub_free (devname);
|
||||
if (!dev)
|
||||
return grub_errno;
|
||||
|
||||
err = grub_zfs_fetch_nvlist (dev, &nvlist);
|
||||
|
||||
grub_device_close (dev);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
poolname = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_POOL_NAME);
|
||||
if (!poolname)
|
||||
grub_printf ("Pool name: unavailable\n");
|
||||
else
|
||||
grub_printf ("Pool name: %s\n", poolname);
|
||||
|
||||
found =
|
||||
grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_GUID, &guid);
|
||||
if (!found)
|
||||
grub_printf ("Pool GUID: unavailable\n");
|
||||
else
|
||||
grub_printf ("Pool GUID: %016llx\n", (long long unsigned) guid);
|
||||
|
||||
found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_STATE,
|
||||
&pool_state);
|
||||
if (!found)
|
||||
grub_printf ("Unable to retrieve pool state\n");
|
||||
else if (pool_state >= ARRAY_SIZE (poolstates))
|
||||
grub_printf ("Unrecognized pool state\n");
|
||||
else
|
||||
grub_printf ("Pool state: %s\n", poolstates[pool_state]);
|
||||
|
||||
nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
|
||||
|
||||
if (!nv)
|
||||
grub_printf ("No vdev tree available\n");
|
||||
else
|
||||
print_vdev_info (nv, 1);
|
||||
|
||||
grub_free (nv);
|
||||
grub_free (nvlist);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_zfs_bootfs (grub_command_t cmd __attribute__ ((unused)), int argc,
|
||||
char **args)
|
||||
{
|
||||
grub_device_t dev;
|
||||
char *devname;
|
||||
grub_err_t err;
|
||||
char *nvlist = 0;
|
||||
char *nv = 0;
|
||||
char *bootpath = 0, *devid = 0;
|
||||
char *fsname;
|
||||
char *bootfs;
|
||||
char *poolname;
|
||||
grub_uint64_t mdnobj;
|
||||
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "filesystem name required");
|
||||
|
||||
devname = grub_file_get_device_name (args[0]);
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
|
||||
dev = grub_device_open (devname);
|
||||
grub_free (devname);
|
||||
if (!dev)
|
||||
return grub_errno;
|
||||
|
||||
err = grub_zfs_fetch_nvlist (dev, &nvlist);
|
||||
|
||||
fsname = grub_strchr (args[0], ')');
|
||||
if (fsname)
|
||||
fsname++;
|
||||
else
|
||||
fsname = args[0];
|
||||
|
||||
if (!err)
|
||||
err = grub_zfs_getmdnobj (dev, fsname, &mdnobj);
|
||||
|
||||
grub_device_close (dev);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
poolname = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_POOL_NAME);
|
||||
if (!poolname)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_BAD_FS, "No poolname found");
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE);
|
||||
|
||||
if (nv)
|
||||
get_bootpath (nv, &bootpath, &devid);
|
||||
|
||||
grub_free (nv);
|
||||
grub_free (nvlist);
|
||||
|
||||
bootfs = grub_xasprintf ("zfs-bootfs=%s/%llu%s%s%s%s%s%s",
|
||||
poolname, (unsigned long long) mdnobj,
|
||||
bootpath ? ",bootpath=\"" : "",
|
||||
bootpath ? : "",
|
||||
bootpath ? "\"" : "",
|
||||
devid ? ",diskdevid=\"" : "",
|
||||
devid ? : "",
|
||||
devid ? "\"" : "");
|
||||
if (!bootfs)
|
||||
return grub_errno;
|
||||
if (argc >= 2)
|
||||
grub_env_set (args[1], bootfs);
|
||||
else
|
||||
grub_printf ("%s\n", bootfs);
|
||||
|
||||
grub_free (bootfs);
|
||||
grub_free (poolname);
|
||||
grub_free (bootpath);
|
||||
grub_free (devid);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
static grub_command_t cmd_info, cmd_bootfs;
|
||||
|
||||
GRUB_MOD_INIT (zfsinfo)
|
||||
{
|
||||
cmd_info = grub_register_command ("zfsinfo", grub_cmd_zfsinfo,
|
||||
"zfsinfo DEVICE",
|
||||
"Print ZFS info about DEVICE.");
|
||||
cmd_bootfs = grub_register_command ("zfs-bootfs", grub_cmd_zfs_bootfs,
|
||||
"zfs-bootfs FILESYSTEM [VARIABLE]",
|
||||
"Print ZFS-BOOTFSOBJ or set it to VARIABLE");
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI (zfsinfo)
|
||||
{
|
||||
grub_unregister_command (cmd_info);
|
||||
grub_unregister_command (cmd_bootfs);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue