merge trunk

This commit is contained in:
Colin Watson 2011-04-21 10:36:09 +01:00
commit 2e0fbe00d2
319 changed files with 12002 additions and 1453 deletions

View file

@ -26,6 +26,8 @@
#include <grub/types.h>
#include <grub/fshelp.h>
GRUB_MOD_LICENSE ("GPLv3+");
/* The affs bootblock. */
struct grub_affs_bblock
{
@ -208,7 +210,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 +242,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 +509,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 +537,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
};

View file

@ -26,6 +26,8 @@
#include <grub/types.h>
#include <grub/fshelp.h>
GRUB_MOD_LICENSE ("GPLv3+");
#ifdef MODE_BIGENDIAN
#define GRUB_AFS_FSNAME_SUFFIX "_be"
#else

View file

@ -27,6 +27,8 @@
#include <grub/lib/crc.h>
#include <grub/deflate.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_BTRFS_SIGNATURE "_BHRfS_M"
typedef grub_uint8_t grub_btrfs_checksum_t[0x20];
@ -83,6 +85,7 @@ struct grub_btrfs_data
/* Cached extent data. */
grub_uint64_t extstart;
grub_uint64_t extend;
grub_uint64_t extino;
grub_uint64_t exttree;
grub_size_t extsize;
@ -172,10 +175,18 @@ struct grub_btrfs_root_item
grub_uint64_t inode;
};
struct grub_btrfs_time
{
grub_int64_t sec;
grub_uint32_t nanosec;
} __attribute__ ((aligned(4)));
struct grub_btrfs_inode
{
grub_uint8_t dummy[0x10];
grub_uint8_t dummy1[0x10];
grub_uint64_t size;
grub_uint8_t dummy2[0x70];
struct grub_btrfs_time mtime;
} __attribute__ ((packed));
struct grub_btrfs_extent_data
@ -194,6 +205,7 @@ struct grub_btrfs_extent_data
grub_uint64_t laddr;
grub_uint64_t compressed_size;
grub_uint64_t offset;
grub_uint64_t filled;
};
};
} __attribute__ ((packed));
@ -576,11 +588,13 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
grub_uint8_t *ptr;
struct grub_btrfs_key *key;
struct grub_btrfs_chunk_item *chunk;
grub_ssize_t csize;
grub_uint64_t csize;
grub_err_t err;
struct grub_btrfs_key key_out;
int challoc = 0;
grub_device_t dev;
grub_dprintf ("btrfs", "searching for laddr %" PRIxGRUB_UINT64_T "\n",
addr);
for (ptr = data->sblock.bootstrap_mapping;
ptr < data->sblock.bootstrap_mapping
+ sizeof (data->sblock.bootstrap_mapping)
@ -634,35 +648,49 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
chunk_found:
{
grub_uint32_t stripen;
grub_uint32_t stripe_offset;
grub_uint64_t stripe_offset;
grub_uint64_t off = addr - grub_le_to_cpu64 (key->offset);
unsigned redundancy = 1;
unsigned i, j;
if (grub_le_to_cpu64 (chunk->size) <= off)
{
grub_dprintf ("btrfs", "no chunk\n");
return grub_error (GRUB_ERR_BAD_FS,
"couldn't find the chunk descriptor");
}
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
"+0x%" PRIxGRUB_UINT64_T
" (%d stripes (%d substripes) of %"
PRIxGRUB_UINT64_T ")\n",
grub_le_to_cpu64 (key->offset),
grub_le_to_cpu64 (chunk->size),
grub_le_to_cpu16 (chunk->nstripes),
grub_le_to_cpu16 (chunk->nsubstripes),
grub_le_to_cpu64 (chunk->stripe_length));
switch (grub_le_to_cpu64 (chunk->type)
& ~GRUB_BTRFS_CHUNK_TYPE_BITS_DONTCARE)
{
case GRUB_BTRFS_CHUNK_TYPE_SINGLE:
{
grub_uint32_t stripe_length;
stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size),
grub_le_to_cpu16 (chunk->nstripes),
NULL);
stripen = grub_divmod64 (off, stripe_length, &stripe_offset);
grub_uint64_t stripe_length;
grub_dprintf ("btrfs", "single\n");
stripe_length = grub_divmod64_full (grub_le_to_cpu64 (chunk->size),
grub_le_to_cpu16 (chunk->nstripes),
NULL);
stripen = grub_divmod64_full (off, stripe_length, &stripe_offset);
csize = (stripen + 1) * stripe_length - off;
break;
}
case GRUB_BTRFS_CHUNK_TYPE_DUPLICATED:
case GRUB_BTRFS_CHUNK_TYPE_RAID1:
/* FIXME: Use redundancy. */
{
grub_uint32_t stripe_length;
stripe_length = grub_divmod64 (grub_le_to_cpu64 (chunk->size),
grub_le_to_cpu16 (chunk->nstripes),
NULL);
grub_dprintf ("btrfs", "RAID1\n");
stripen = 0;
stripe_offset = off;
csize = stripe_length - off;
csize = grub_le_to_cpu64 (chunk->size) - off;
redundancy = 2;
break;
}
@ -670,6 +698,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
{
grub_uint64_t middle, high;
grub_uint32_t low;
grub_dprintf ("btrfs", "RAID0\n");
middle = grub_divmod64 (off,
grub_le_to_cpu64 (chunk->stripe_length),
&low);
@ -682,7 +711,6 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
break;
}
case GRUB_BTRFS_CHUNK_TYPE_RAID10:
/* FIXME: Use redundancy. */
{
grub_uint64_t middle, high;
grub_uint32_t low;
@ -703,12 +731,13 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
break;
}
default:
grub_dprintf ("btrfs", "unsupported RAID\n");
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported RAID flags %" PRIxGRUB_UINT64_T,
grub_le_to_cpu64 (chunk->type));
}
if (csize <= 0)
return grub_error (GRUB_ERR_BAD_FS,
if (csize == 0)
return grub_error (GRUB_ERR_BUG,
"couldn't find the chunk descriptor");
if ((grub_size_t) csize > size)
csize = size;
@ -721,7 +750,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
grub_disk_addr_t paddr;
stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1);
/* Right now the redundancy handlind is easy.
/* Right now the redundancy handling is easy.
With RAID5-like it will be more difficult. */
stripe += stripen + i;
@ -858,12 +887,12 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
grub_err_t err;
grub_off_t extoff;
if (!data->extent || data->extstart > pos || data->extino != ino
|| data->exttree != tree
|| grub_le_to_cpu64 (data->extent->size) + data->extstart <= pos)
|| data->exttree != tree || data->extend <= pos)
{
struct grub_btrfs_key key_in, key_out;
grub_disk_addr_t elemaddr;
grub_size_t elemsize;
grub_free (data->extent);
key_in.object_id = ino;
key_in.type = GRUB_BTRFS_ITEM_TYPE_EXTENT_ITEM;
@ -890,15 +919,29 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
data->extent, elemsize);
if (err)
return err;
if (grub_le_to_cpu64 (data->extent->size) + data->extstart <= pos)
return grub_error (GRUB_ERR_BAD_FS, "extent not found");
data->extend = data->extstart
+ grub_le_to_cpu64 (data->extent->size);
if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR
&& (char *) &data->extent + elemsize
>= (char *) &data->extent->filled
+ sizeof (data->extent->filled))
data->extend = data->extstart
+ grub_le_to_cpu64 (data->extent->filled);
grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%"
PRIxGRUB_UINT64_T "\n",
PRIxGRUB_UINT64_T " (0x%"
PRIxGRUB_UINT64_T ")\n",
grub_le_to_cpu64 (key_out.offset),
grub_le_to_cpu64 (data->extent->size));
grub_le_to_cpu64 (data->extent->size),
grub_le_to_cpu64 (data->extent->filled));
if (data->extend <= pos)
{
grub_error (GRUB_ERR_BAD_FS, "extent not found");
return -1;
}
}
csize = grub_le_to_cpu64 (data->extent->size)
+ grub_le_to_cpu64 (data->extstart) - pos;
csize = data->extend - pos;
extoff = pos - data->extstart;
if (csize > len)
csize = len;
@ -975,6 +1018,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
}
err = grub_btrfs_read_logical (data,
grub_le_to_cpu64 (data->extent->laddr)
+ grub_le_to_cpu64 (data->extent->offset)
+ extoff,
buf, csize);
if (err)
@ -1089,12 +1133,9 @@ find_path (struct grub_btrfs_data *data,
+ grub_le_to_cpu16 (cdirel->n)
+ grub_le_to_cpu16 (cdirel->m)))
{
char c;
c = cdirel->name[grub_le_to_cpu16 (cdirel->n)];
cdirel->name[grub_le_to_cpu16 (cdirel->n)] = 0;
if (grub_strncmp (cdirel->name, ctoken, ctokenlen) == 0)
if (ctokenlen == grub_le_to_cpu16 (cdirel->n)
&& grub_memcmp (cdirel->name, ctoken, ctokenlen) == 0)
break;
cdirel->name[grub_le_to_cpu16 (cdirel->n)] = c;
}
if ((grub_uint8_t *) cdirel - (grub_uint8_t *) direl
>= (grub_ssize_t) elemsize)
@ -1263,7 +1304,6 @@ grub_btrfs_dir (grub_device_t device, const char *path,
}
do
{
struct grub_dirhook_info info;
struct grub_btrfs_dir_item *cdirel;
if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM
|| key_out.object_id != key_in.object_id)
@ -1295,9 +1335,20 @@ grub_btrfs_dir (grub_device_t device, const char *path,
+ grub_le_to_cpu16 (cdirel->m)))
{
char c;
struct grub_btrfs_inode inode;
struct grub_dirhook_info info;
err = grub_btrfs_read_inode (data, &inode, cdirel->key.object_id,
tree);
grub_memset (&info, 0, sizeof (info));
if (err)
grub_errno = GRUB_ERR_NONE;
else
{
info.mtime = inode.mtime.sec;
info.mtimeset = 1;
}
c = cdirel->name[grub_le_to_cpu16 (cdirel->n)];
cdirel->name[grub_le_to_cpu16 (cdirel->n)] = 0;
grub_memset (&info, 0, sizeof (info));
info.dir = (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY);
if (hook (cdirel->name, &info))
goto out;
@ -1424,6 +1475,9 @@ static struct grub_fs grub_btrfs_fs =
.close = grub_btrfs_close,
.uuid = grub_btrfs_uuid,
.label = grub_btrfs_label,
#ifdef GRUB_UTIL
.reserved_first_sector = 1,
#endif
};
GRUB_MOD_INIT(btrfs)

View file

@ -23,6 +23,8 @@
#include <grub/disk.h>
#include <grub/dl.h>
GRUB_MOD_LICENSE ("GPLv3+");
#ifndef MODE_USTAR
/* cpio support */
#define MAGIC_BCPIO 070707
@ -354,6 +356,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

View file

@ -51,6 +51,8 @@
#include <grub/types.h>
#include <grub/fshelp.h>
GRUB_MOD_LICENSE ("GPLv3+");
/* Log2 size of ext2 block in 512 blocks. */
#define LOG2_EXT2_BLOCK_SIZE(data) \
(grub_le_to_cpu32 (data->sblock.log2_block_size) + 1)
@ -555,7 +557,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))

View file

@ -27,6 +27,8 @@
#include <grub/dl.h>
#include <grub/charset.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_FAT_DIR_ENTRY_SIZE 32
#define GRUB_FAT_ATTR_READ_ONLY 0x01

View file

@ -22,7 +22,9 @@
#include <grub/misc.h>
#include <grub/disk.h>
#include <grub/fshelp.h>
#include <grub/dl.h>
GRUB_MOD_LICENSE ("GPLv3+");
/* Lookup the node PATH. The node ROOTNODE describes the root of the
directory tree. The node found is returned in FOUNDNODE, which is

View file

@ -29,6 +29,8 @@
#include <grub/types.h>
#include <grub/hfs.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_HFS_SBLOCK 2
#define GRUB_HFS_EMBED_HFSPLUS_SIG 0x482B

View file

@ -30,6 +30,8 @@
#include <grub/hfs.h>
#include <grub/charset.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_HFSPLUS_MAGIC 0x482B
#define GRUB_HFSPLUSX_MAGIC 0x4858
#define GRUB_HFSPLUS_SBLOCK 2
@ -178,7 +180,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 +522,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 +560,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 *

View file

@ -30,6 +30,8 @@
#include <grub/machine/int.h>
#include <grub/machine/memory.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define SEGMENT(x) ((x) >> 4)
#define OFFSET(x) ((x) & 0xF)
#define SEGOFS(x) ((SEGMENT(x) << 16) + OFFSET(x))
@ -281,7 +283,7 @@ grub_pxefs_open (struct grub_file *file, const char *name)
}
file->data = data;
file->not_easly_seekable = 1;
file->not_easily_seekable = 1;
grub_memcpy (file_int, file, sizeof (struct grub_file));
curr_file = file_int;
@ -420,6 +422,7 @@ set_mac_env (grub_uint8_t *mac_addr, grub_size_t mac_len)
grub_env_set ("net_pxe_mac", buf);
/* XXX: Is it possible to change MAC in PXE? */
grub_register_variable_hook ("net_pxe_mac", 0, grub_env_write_readonly);
grub_env_export ("net_pxe_mac");
}
static void
@ -431,6 +434,7 @@ set_env_limn_ro (const char *varname, char *value, grub_size_t len)
grub_env_set (varname, value);
value[len] = c;
grub_register_variable_hook (varname, 0, grub_env_write_readonly);
grub_env_export (varname);
}
static void
@ -479,7 +483,7 @@ parse_dhcp_vendor (void *vend, int limit)
break;
/* If you need any other options please contact GRUB
developpement team. */
development team. */
}
ptr += taglength;
@ -624,12 +628,19 @@ GRUB_MOD_INIT(pxe)
grub_env_write_pxe_default_server);
grub_register_variable_hook ("pxe_default_gateway", 0,
grub_env_write_pxe_default_gateway);
/* XXX: Is it possible to change IP in PXE? */
grub_register_variable_hook ("net_pxe_ip", 0,
grub_env_write_readonly);
grub_register_variable_hook ("pxe_blksize", 0,
grub_env_write_pxe_blocksize);
grub_env_export ("pxe_default_server");
grub_env_export ("pxe_default_gateway");
grub_env_export ("net_pxe_ip");
grub_env_export ("pxe_blksize");
grub_disk_dev_register (&grub_pxe_dev);
grub_fs_register (&grub_pxefs_fs);
}

View file

@ -28,6 +28,8 @@
#include <grub/fshelp.h>
#include <grub/charset.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_ISO9660_FSTYPE_DIR 0040000
#define GRUB_ISO9660_FSTYPE_REG 0100000
#define GRUB_ISO9660_FSTYPE_SYMLINK 0120000
@ -808,6 +810,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

View file

@ -26,6 +26,8 @@
#include <grub/types.h>
#include <grub/charset.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_JFS_MAX_SYMLNK_CNT 8
#define GRUB_JFS_FILETYPE_MASK 0170000
#define GRUB_JFS_FILETYPE_REG 0100000
@ -217,12 +219,12 @@ struct grub_jfs_diropen
struct grub_jfs_tree_dir header;
struct grub_jfs_leaf_dirent dirent[0];
struct grub_jfs_leaf_next_dirent next_dirent[0];
char sorted[0];
grub_uint8_t sorted[0];
} *dirpage __attribute__ ((packed));
struct grub_jfs_data *data;
struct grub_jfs_inode *inode;
int count;
char *sorted;
grub_uint8_t *sorted;
struct grub_jfs_leaf_dirent *leaf;
struct grub_jfs_leaf_next_dirent *next_leaf;
@ -234,13 +236,13 @@ struct grub_jfs_diropen
static grub_dl_t my_mod;
static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, int ino);
static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino);
/* Get the block number for the block BLK in the node INODE in the
mounted filesystem DATA. */
static int
static grub_int64_t
grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
unsigned int blk)
grub_uint64_t blk)
{
auto int getblk (struct grub_jfs_treehead *treehead,
struct grub_jfs_tree_extent *extents);
@ -294,15 +296,15 @@ grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
static grub_err_t
grub_jfs_read_inode (struct grub_jfs_data *data, int ino,
grub_jfs_read_inode (struct grub_jfs_data *data, grub_uint32_t ino,
struct grub_jfs_inode *inode)
{
struct grub_jfs_iag iag;
int iagnum = ino / 4096;
int inoext = (ino % 4096) / 32;
int inonum = (ino % 4096) % 32;
grub_uint32_t iagblk;
grub_uint32_t inoblk;
grub_uint32_t iagnum = ino / 4096;
unsigned inoext = (ino % 4096) / 32;
unsigned inonum = (ino % 4096) % 32;
grub_uint64_t iagblk;
grub_uint64_t inoblk;
iagblk = grub_jfs_blkno (data, &data->fileset, iagnum + 1);
if (grub_errno)
@ -348,6 +350,13 @@ grub_jfs_mount (grub_disk_t disk)
goto fail;
}
if (grub_le_to_cpu32 (data->sblock.blksz)
!= (1U << grub_le_to_cpu16 (data->sblock.log2_blksz)))
{
grub_error (GRUB_ERR_BAD_FS, "not a JFS filesystem");
goto fail;
}
data->disk = disk;
data->pos = 0;
data->linknest = 0;
@ -374,7 +383,7 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
{
struct grub_jfs_internal_dirent *de;
struct grub_jfs_diropen *diro;
int blk;
grub_disk_addr_t blk;
de = (struct grub_jfs_internal_dirent *) inode->dir.dirents;
@ -397,7 +406,7 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
{
diro->leaf = inode->dir.dirents;
diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
diro->sorted = (char *) (inode->dir.header.sorted);
diro->sorted = inode->dir.header.sorted;
diro->count = inode->dir.header.count;
return diro;
@ -475,7 +484,7 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
/* The last node, read in more. */
if (diro->index == diro->count)
{
unsigned int next;
grub_disk_addr_t next;
/* If the inode contains the entry tree or if this was the last
node, there is nothing to read. */
@ -499,7 +508,7 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
diro->index = 0;
}
leaf = &diro->leaf[(int) diro->sorted[diro->index]];
leaf = &diro->leaf[diro->sorted[diro->index]];
next_leaf = &diro->next_leaf[diro->index];
len = leaf->len;
@ -540,21 +549,21 @@ static grub_ssize_t
grub_jfs_read_file (struct grub_jfs_data *data,
void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
unsigned offset, unsigned length),
int pos, grub_size_t len, char *buf)
grub_uint64_t pos, grub_size_t len, char *buf)
{
int i;
int blockcnt;
grub_uint64_t i;
grub_uint64_t blockcnt;
blockcnt = ((len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1)
/ grub_le_to_cpu32 (data->sblock.blksz));
blockcnt = (len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1)
>> grub_le_to_cpu16 (data->sblock.log2_blksz);
for (i = pos / grub_le_to_cpu32 (data->sblock.blksz); i < blockcnt; i++)
for (i = pos >> grub_le_to_cpu16 (data->sblock.log2_blksz); i < blockcnt; i++)
{
int blknr;
int blockoff = pos % grub_le_to_cpu32 (data->sblock.blksz);
int blockend = grub_le_to_cpu32 (data->sblock.blksz);
grub_disk_addr_t blknr;
grub_uint32_t blockoff = pos & (grub_le_to_cpu32 (data->sblock.blksz) - 1);
grub_uint32_t blockend = grub_le_to_cpu32 (data->sblock.blksz);
int skipfirst = 0;
grub_uint64_t skipfirst = 0;
blknr = grub_jfs_blkno (data, &data->currinode, i);
if (grub_errno)
@ -563,14 +572,14 @@ grub_jfs_read_file (struct grub_jfs_data *data,
/* Last block. */
if (i == blockcnt - 1)
{
blockend = (len + pos) % grub_le_to_cpu32 (data->sblock.blksz);
blockend = (len + pos) & (grub_le_to_cpu32 (data->sblock.blksz) - 1);
if (!blockend)
blockend = grub_le_to_cpu32 (data->sblock.blksz);
}
/* First block. */
if (i == (pos / (int) grub_le_to_cpu32 (data->sblock.blksz)))
if (i == (pos >> grub_le_to_cpu16 (data->sblock.log2_blksz)))
{
skipfirst = blockoff;
blockend -= skipfirst;
@ -642,8 +651,8 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
pathname. */
if (!grub_strcmp (name, diro->name))
{
int ino = diro->ino;
int dirino = grub_le_to_cpu32 (data->currinode.inode);
grub_uint32_t ino = diro->ino;
grub_uint32_t dirino = grub_le_to_cpu32 (data->currinode.inode);
grub_jfs_closedir (diro);
diro = 0;
@ -687,9 +696,9 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
static grub_err_t
grub_jfs_lookup_symlink (struct grub_jfs_data *data, int ino)
grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino)
{
int size = grub_le_to_cpu64 (data->currinode.size);
grub_uint64_t size = grub_le_to_cpu64 (data->currinode.size);
char symlink[size + 1];
if (++data->linknest > GRUB_JFS_MAX_SYMLNK_CNT)

View file

@ -25,6 +25,8 @@
#include <grub/dl.h>
#include <grub/types.h>
GRUB_MOD_LICENSE ("GPLv3+");
#ifdef MODE_MINIX2
#define GRUB_MINIX_MAGIC 0x2468
#define GRUB_MINIX_MAGIC_30 0x2478

View file

@ -35,6 +35,8 @@
#include <grub/types.h>
#include <grub/fshelp.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define NILFS_INODE_BMAP_SIZE 7
#define NILFS_SUPORT_REV 2

View file

@ -26,6 +26,8 @@
#include <grub/ntfs.h>
#include <grub/charset.h>
GRUB_MOD_LICENSE ("GPLv3+");
static grub_dl_t my_mod;
ntfscomp_func_t grub_ntfscomp_func;

View file

@ -24,6 +24,8 @@
#include <grub/fshelp.h>
#include <grub/ntfs.h>
GRUB_MOD_LICENSE ("GPLv3+");
static grub_err_t
decomp_nextvcn (struct grub_ntfs_comp *cc)
{

View file

@ -39,6 +39,8 @@
#include <grub/types.h>
#include <grub/fshelp.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define MIN(a, b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \

View file

@ -26,6 +26,8 @@
#include <grub/types.h>
#include <grub/fshelp.h>
GRUB_MOD_LICENSE ("GPLv3+");
/* The common header for a block. */
struct grub_sfs_bheader
{
@ -579,6 +581,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
};

View file

@ -27,6 +27,8 @@
#include <grub/fshelp.h>
#include <grub/charset.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define GRUB_UDF_MAX_PDS 2
#define GRUB_UDF_MAX_PMS 6
@ -788,6 +790,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
@ -841,10 +880,8 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
else
{
enum grub_fshelp_filetype type;
char *filename;
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));
@ -855,27 +892,16 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
!= dirent.file_ident_length)
return 0;
if (raw[0] == 8)
{
unsigned i;
utf16len = dirent.file_ident_length - 1;
for (i = 0; i < utf16len; i++)
utf16[i] = raw[i + 1];
}
if (raw[0] == 16)
{
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';
filename = read_string (raw, dirent.file_ident_length);
if (!filename)
grub_print_error ();
if (hook ((char *) filename, type, child))
return 1;
if (filename && hook (filename, type, child))
{
grub_free (filename);
return 1;
}
grub_free (filename);
}
}
@ -1004,7 +1030,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

View file

@ -25,6 +25,8 @@
#include <grub/dl.h>
#include <grub/types.h>
GRUB_MOD_LICENSE ("GPLv3+");
#ifdef MODE_UFS2
#define GRUB_UFS_MAGIC 0x19540119
#else

View file

@ -26,6 +26,8 @@
#include <grub/types.h>
#include <grub/fshelp.h>
GRUB_MOD_LICENSE ("GPLv3+");
#define XFS_INODE_EXTENTS 9
#define XFS_INODE_FORMAT_INO 1
@ -451,18 +453,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 +819,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
};

2550
grub-core/fs/zfs/zfs.c Normal file

File diff suppressed because it is too large Load diff

View 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);
}

View 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;
}

View 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);
}

409
grub-core/fs/zfs/zfsinfo.c Normal file
View file

@ -0,0 +1,409 @@
/*
* 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>
GRUB_MOD_LICENSE ("GPLv3+");
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);
}