2005-12-25 15:59:50 +00:00
|
|
|
|
/* hfsplus.c - HFS+ Filesystem. */
|
|
|
|
|
/*
|
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2009-05-04 16:08:27 +00:00
|
|
|
|
* Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc.
|
2005-12-25 15:59:50 +00:00
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2005-12-25 15:59:50 +00:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2005-12-25 15:59:50 +00:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2005-12-25 15:59:50 +00:00
|
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2005-12-25 15:59:50 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2006-01-03 14:30:57 +00:00
|
|
|
|
/* HFS+ is documented at http://developer.apple.com/technotes/tn/tn1150.html */
|
|
|
|
|
|
2013-05-07 13:46:17 +00:00
|
|
|
|
#define grub_fshelp_node grub_hfsplus_file
|
2005-12-25 15:59:50 +00:00
|
|
|
|
#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/fshelp.h>
|
2006-01-03 14:30:57 +00:00
|
|
|
|
#include <grub/hfs.h>
|
2009-11-09 17:43:53 +00:00
|
|
|
|
#include <grub/charset.h>
|
2013-05-07 13:46:17 +00:00
|
|
|
|
#include <grub/hfsplus.h>
|
2020-07-19 18:43:31 +00:00
|
|
|
|
#include <grub/safemath.h>
|
2006-01-03 14:30:57 +00:00
|
|
|
|
|
2011-04-11 21:01:51 +00:00
|
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
/* The type of node. */
|
|
|
|
|
enum grub_hfsplus_btnode_type
|
|
|
|
|
{
|
|
|
|
|
GRUB_HFSPLUS_BTNODE_TYPE_LEAF = -1,
|
|
|
|
|
GRUB_HFSPLUS_BTNODE_TYPE_INDEX = 0,
|
|
|
|
|
GRUB_HFSPLUS_BTNODE_TYPE_HEADER = 1,
|
|
|
|
|
GRUB_HFSPLUS_BTNODE_TYPE_MAP = 2,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* The header of a HFS+ B+ Tree. */
|
|
|
|
|
struct grub_hfsplus_btheader
|
|
|
|
|
{
|
|
|
|
|
grub_uint16_t depth;
|
|
|
|
|
grub_uint32_t root;
|
|
|
|
|
grub_uint32_t leaf_records;
|
|
|
|
|
grub_uint32_t first_leaf_node;
|
|
|
|
|
grub_uint32_t last_leaf_node;
|
|
|
|
|
grub_uint16_t nodesize;
|
|
|
|
|
grub_uint16_t keysize;
|
2009-06-05 21:00:43 +00:00
|
|
|
|
grub_uint32_t total_nodes;
|
|
|
|
|
grub_uint32_t free_nodes;
|
|
|
|
|
grub_uint16_t reserved1;
|
|
|
|
|
grub_uint32_t clump_size; /* ignored */
|
|
|
|
|
grub_uint8_t btree_type;
|
|
|
|
|
grub_uint8_t key_compare;
|
|
|
|
|
grub_uint32_t attributes;
|
2013-12-15 13:14:30 +00:00
|
|
|
|
} GRUB_PACKED;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
struct grub_hfsplus_catfile
|
|
|
|
|
{
|
|
|
|
|
grub_uint16_t type;
|
|
|
|
|
grub_uint16_t flags;
|
2012-05-26 22:56:55 +00:00
|
|
|
|
grub_uint32_t parentid; /* Thread only. */
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_uint32_t fileid;
|
2009-04-05 20:19:05 +00:00
|
|
|
|
grub_uint8_t unused1[4];
|
|
|
|
|
grub_uint32_t mtime;
|
|
|
|
|
grub_uint8_t unused2[22];
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_uint16_t mode;
|
2009-04-05 20:19:05 +00:00
|
|
|
|
grub_uint8_t unused3[44];
|
2005-12-25 15:59:50 +00:00
|
|
|
|
struct grub_hfsplus_forkdata data;
|
|
|
|
|
struct grub_hfsplus_forkdata resource;
|
2013-12-15 13:14:30 +00:00
|
|
|
|
} GRUB_PACKED;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* Filetype information as used in inodes. */
|
|
|
|
|
#define GRUB_HFSPLUS_FILEMODE_MASK 0170000
|
|
|
|
|
#define GRUB_HFSPLUS_FILEMODE_REG 0100000
|
|
|
|
|
#define GRUB_HFSPLUS_FILEMODE_DIRECTORY 0040000
|
|
|
|
|
#define GRUB_HFSPLUS_FILEMODE_SYMLINK 0120000
|
|
|
|
|
|
|
|
|
|
/* Some pre-defined file IDs. */
|
2013-05-07 13:46:17 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
GRUB_HFSPLUS_FILEID_ROOTDIR = 2,
|
|
|
|
|
GRUB_HFSPLUS_FILEID_OVERFLOW = 3,
|
|
|
|
|
GRUB_HFSPLUS_FILEID_CATALOG = 4,
|
|
|
|
|
GRUB_HFSPLUS_FILEID_ATTR = 8
|
|
|
|
|
};
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
enum grub_hfsplus_filetype
|
|
|
|
|
{
|
|
|
|
|
GRUB_HFSPLUS_FILETYPE_DIR = 1,
|
|
|
|
|
GRUB_HFSPLUS_FILETYPE_REG = 2,
|
|
|
|
|
GRUB_HFSPLUS_FILETYPE_DIR_THREAD = 3,
|
|
|
|
|
GRUB_HFSPLUS_FILETYPE_REG_THREAD = 4
|
|
|
|
|
};
|
|
|
|
|
|
2009-06-05 21:00:43 +00:00
|
|
|
|
#define GRUB_HFSPLUSX_BINARYCOMPARE 0xBC
|
|
|
|
|
#define GRUB_HFSPLUSX_CASEFOLDING 0xCF
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
static grub_dl_t my_mod;
|
|
|
|
|
|
|
|
|
|
|
2006-05-28 03:20:18 +00:00
|
|
|
|
|
2013-05-07 13:46:17 +00:00
|
|
|
|
grub_err_t (*grub_hfsplus_open_compressed) (struct grub_fshelp_node *node);
|
|
|
|
|
grub_ssize_t (*grub_hfsplus_read_compressed) (struct grub_hfsplus_file *node,
|
|
|
|
|
grub_off_t pos,
|
|
|
|
|
grub_size_t len,
|
|
|
|
|
char *buf);
|
2006-05-28 03:20:18 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
/* Find the extent that points to FILEBLOCK. If it is not in one of
|
|
|
|
|
the 8 extents described by EXTENT, return -1. In that case set
|
2006-05-28 03:20:18 +00:00
|
|
|
|
FILEBLOCK to the next block. */
|
2011-10-14 20:41:21 +00:00
|
|
|
|
static grub_disk_addr_t
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_hfsplus_find_block (struct grub_hfsplus_extent *extent,
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t *fileblock)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t blksleft = *fileblock;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* First lookup the file in the given extents. */
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
if (blksleft < grub_be_to_cpu32 (extent[i].count))
|
|
|
|
|
return grub_be_to_cpu32 (extent[i].start) + blksleft;
|
|
|
|
|
blksleft -= grub_be_to_cpu32 (extent[i].count);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-28 03:20:18 +00:00
|
|
|
|
*fileblock = blksleft;
|
2011-10-14 20:41:21 +00:00
|
|
|
|
return 0xffffffffffffffffULL;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int grub_hfsplus_cmp_extkey (struct grub_hfsplus_key *keya,
|
|
|
|
|
struct grub_hfsplus_key_internal *keyb);
|
|
|
|
|
|
|
|
|
|
/* Search for the block FILEBLOCK inside the file NODE. Return the
|
|
|
|
|
blocknumber of this block on disk. */
|
2008-05-20 05:00:53 +00:00
|
|
|
|
static grub_disk_addr_t
|
|
|
|
|
grub_hfsplus_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_btnode *nnode = 0;
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t blksleft = fileblock;
|
2013-05-07 13:46:17 +00:00
|
|
|
|
struct grub_hfsplus_extent *extents = node->compressed
|
|
|
|
|
? &node->resource_extents[0] : &node->extents[0];
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
2006-05-28 03:20:18 +00:00
|
|
|
|
struct grub_hfsplus_extkey *key;
|
2011-12-13 01:05:58 +00:00
|
|
|
|
struct grub_hfsplus_key_internal extoverflow;
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t blk;
|
|
|
|
|
grub_off_t ptr;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* Try to find this block in the current set of extents. */
|
2006-05-28 03:20:18 +00:00
|
|
|
|
blk = grub_hfsplus_find_block (extents, &blksleft);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* The previous iteration of this loop allocated memory. The
|
2007-12-30 08:52:06 +00:00
|
|
|
|
code above used this memory, it can be freed now. */
|
2006-04-30 17:30:12 +00:00
|
|
|
|
grub_free (nnode);
|
|
|
|
|
nnode = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2011-10-14 20:41:21 +00:00
|
|
|
|
if (blk != 0xffffffffffffffffULL)
|
2012-05-09 11:02:59 +00:00
|
|
|
|
return blk;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* For the extent overflow file, extra extents can't be found in
|
|
|
|
|
the extent overflow file. If this happens, you found a
|
|
|
|
|
bug... */
|
|
|
|
|
if (node->fileid == GRUB_HFSPLUS_FILEID_OVERFLOW)
|
2006-05-28 03:20:18 +00:00
|
|
|
|
{
|
|
|
|
|
grub_error (GRUB_ERR_READ_ERROR,
|
|
|
|
|
"extra extents found in an extend overflow file");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* Set up the key to look for in the extent overflow file. */
|
2011-12-13 01:05:58 +00:00
|
|
|
|
extoverflow.extkey.fileid = node->fileid;
|
2012-05-26 09:54:20 +00:00
|
|
|
|
extoverflow.extkey.type = 0;
|
2011-12-13 01:05:58 +00:00
|
|
|
|
extoverflow.extkey.start = fileblock - blksleft;
|
2013-05-07 13:46:17 +00:00
|
|
|
|
extoverflow.extkey.type = node->compressed ? 0xff : 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
if (grub_hfsplus_btree_search (&node->data->extoverflow_tree,
|
2011-12-13 01:05:58 +00:00
|
|
|
|
&extoverflow,
|
2013-05-07 13:46:17 +00:00
|
|
|
|
grub_hfsplus_cmp_extkey, &nnode, &ptr)
|
|
|
|
|
|| !nnode)
|
2006-05-28 03:20:18 +00:00
|
|
|
|
{
|
|
|
|
|
grub_error (GRUB_ERR_READ_ERROR,
|
|
|
|
|
"no block found for the file id 0x%x and the block offset 0x%x",
|
|
|
|
|
node->fileid, fileblock);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2006-05-28 03:20:18 +00:00
|
|
|
|
/* The extent overflow file has 8 extents right after the key. */
|
|
|
|
|
key = (struct grub_hfsplus_extkey *)
|
|
|
|
|
grub_hfsplus_btree_recptr (&node->data->extoverflow_tree, nnode, ptr);
|
|
|
|
|
extents = (struct grub_hfsplus_extent *) (key + 1);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* The block wasn't found. Perhaps the next iteration will find
|
2006-05-28 03:20:18 +00:00
|
|
|
|
it. The last block we found is stored in BLKSLEFT now. */
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-30 17:30:12 +00:00
|
|
|
|
grub_free (nnode);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* Too bad, you lose. */
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Read LEN bytes from the file described by DATA starting with byte
|
|
|
|
|
POS. Return the amount of read bytes in READ. */
|
2013-05-07 13:46:17 +00:00
|
|
|
|
grub_ssize_t
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_hfsplus_read_file (grub_fshelp_node_t node,
|
2013-02-27 16:19:15 +00:00
|
|
|
|
grub_disk_read_hook_t read_hook, void *read_hook_data,
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_off_t pos, grub_size_t len, char *buf)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
2013-02-27 16:19:15 +00:00
|
|
|
|
return grub_fshelp_read_file (node->data->disk, node,
|
|
|
|
|
read_hook, read_hook_data,
|
2005-12-25 15:59:50 +00:00
|
|
|
|
pos, len, buf, grub_hfsplus_read_block,
|
|
|
|
|
node->size,
|
2012-05-09 11:02:59 +00:00
|
|
|
|
node->data->log2blksize - GRUB_DISK_SECTOR_BITS,
|
|
|
|
|
node->data->embedded_offset);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct grub_hfsplus_data *
|
|
|
|
|
grub_hfsplus_mount (grub_disk_t disk)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_data *data;
|
|
|
|
|
struct grub_hfsplus_btheader header;
|
|
|
|
|
struct grub_hfsplus_btnode node;
|
2009-06-05 21:00:43 +00:00
|
|
|
|
grub_uint16_t magic;
|
2006-01-03 14:30:57 +00:00
|
|
|
|
union {
|
|
|
|
|
struct grub_hfs_sblock hfs;
|
|
|
|
|
struct grub_hfsplus_volheader hfsplus;
|
|
|
|
|
} volheader;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
data = grub_malloc (sizeof (*data));
|
|
|
|
|
if (!data)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
data->disk = disk;
|
|
|
|
|
|
|
|
|
|
/* Read the bootblock. */
|
2006-01-03 14:30:57 +00:00
|
|
|
|
grub_disk_read (disk, GRUB_HFSPLUS_SBLOCK, 0, sizeof (volheader),
|
2009-05-13 18:58:38 +00:00
|
|
|
|
&volheader);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
if (grub_errno)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
2006-01-03 14:30:57 +00:00
|
|
|
|
data->embedded_offset = 0;
|
|
|
|
|
if (grub_be_to_cpu16 (volheader.hfs.magic) == GRUB_HFS_MAGIC)
|
|
|
|
|
{
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t extent_start;
|
|
|
|
|
grub_disk_addr_t ablk_size;
|
|
|
|
|
grub_disk_addr_t ablk_start;
|
2006-01-03 14:30:57 +00:00
|
|
|
|
|
|
|
|
|
/* See if there's an embedded HFS+ filesystem. */
|
|
|
|
|
if (grub_be_to_cpu16 (volheader.hfs.embed_sig) != GRUB_HFSPLUS_MAGIC)
|
|
|
|
|
{
|
|
|
|
|
grub_error (GRUB_ERR_BAD_FS, "not a HFS+ filesystem");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Calculate the offset needed to translate HFS+ sector numbers. */
|
|
|
|
|
extent_start = grub_be_to_cpu16 (volheader.hfs.embed_extent.first_block);
|
|
|
|
|
ablk_size = grub_be_to_cpu32 (volheader.hfs.blksz);
|
|
|
|
|
ablk_start = grub_be_to_cpu16 (volheader.hfs.first_block);
|
|
|
|
|
data->embedded_offset = (ablk_start
|
|
|
|
|
+ extent_start
|
|
|
|
|
* (ablk_size >> GRUB_DISK_SECTOR_BITS));
|
|
|
|
|
|
|
|
|
|
grub_disk_read (disk, data->embedded_offset + GRUB_HFSPLUS_SBLOCK, 0,
|
2009-05-13 18:58:38 +00:00
|
|
|
|
sizeof (volheader), &volheader);
|
2006-01-03 14:30:57 +00:00
|
|
|
|
if (grub_errno)
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make sure this is an HFS+ filesystem. XXX: Do we really support
|
2005-12-25 15:59:50 +00:00
|
|
|
|
HFX? */
|
2009-06-05 21:00:43 +00:00
|
|
|
|
magic = grub_be_to_cpu16 (volheader.hfsplus.magic);
|
2012-05-12 11:31:05 +00:00
|
|
|
|
if (((magic != GRUB_HFSPLUS_MAGIC) && (magic != GRUB_HFSPLUSX_MAGIC))
|
|
|
|
|
|| volheader.hfsplus.blksize == 0
|
|
|
|
|
|| ((volheader.hfsplus.blksize & (volheader.hfsplus.blksize - 1)) != 0)
|
|
|
|
|
|| grub_be_to_cpu32 (volheader.hfsplus.blksize) < GRUB_DISK_SECTOR_SIZE)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
grub_error (GRUB_ERR_BAD_FS, "not a HFS+ filesystem");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-03 14:30:57 +00:00
|
|
|
|
grub_memcpy (&data->volheader, &volheader.hfsplus,
|
2012-05-12 11:31:05 +00:00
|
|
|
|
sizeof (volheader.hfsplus));
|
2006-01-03 14:30:57 +00:00
|
|
|
|
|
2012-05-12 11:31:05 +00:00
|
|
|
|
for (data->log2blksize = 0;
|
|
|
|
|
(1U << data->log2blksize) < grub_be_to_cpu32 (data->volheader.blksize);
|
|
|
|
|
data->log2blksize++);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* Make a new node for the catalog tree. */
|
|
|
|
|
data->catalog_tree.file.data = data;
|
|
|
|
|
data->catalog_tree.file.fileid = GRUB_HFSPLUS_FILEID_CATALOG;
|
2013-05-07 13:46:17 +00:00
|
|
|
|
data->catalog_tree.file.compressed = 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_memcpy (&data->catalog_tree.file.extents,
|
|
|
|
|
data->volheader.catalog_file.extents,
|
|
|
|
|
sizeof data->volheader.catalog_file.extents);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
data->catalog_tree.file.size =
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_be_to_cpu64 (data->volheader.catalog_file.size);
|
|
|
|
|
|
2013-05-07 13:46:17 +00:00
|
|
|
|
data->attr_tree.file.data = data;
|
|
|
|
|
data->attr_tree.file.fileid = GRUB_HFSPLUS_FILEID_ATTR;
|
|
|
|
|
grub_memcpy (&data->attr_tree.file.extents,
|
|
|
|
|
data->volheader.attr_file.extents,
|
|
|
|
|
sizeof data->volheader.attr_file.extents);
|
|
|
|
|
|
|
|
|
|
data->attr_tree.file.size =
|
|
|
|
|
grub_be_to_cpu64 (data->volheader.attr_file.size);
|
|
|
|
|
data->attr_tree.file.compressed = 0;
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
/* Make a new node for the extent overflow file. */
|
|
|
|
|
data->extoverflow_tree.file.data = data;
|
|
|
|
|
data->extoverflow_tree.file.fileid = GRUB_HFSPLUS_FILEID_OVERFLOW;
|
2013-05-07 13:46:17 +00:00
|
|
|
|
data->extoverflow_tree.file.compressed = 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_memcpy (&data->extoverflow_tree.file.extents,
|
|
|
|
|
data->volheader.extents_file.extents,
|
|
|
|
|
sizeof data->volheader.catalog_file.extents);
|
|
|
|
|
|
2009-06-10 21:04:23 +00:00
|
|
|
|
data->extoverflow_tree.file.size =
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_be_to_cpu64 (data->volheader.extents_file.size);
|
|
|
|
|
|
|
|
|
|
/* Read the essential information about the trees. */
|
2013-02-27 16:19:15 +00:00
|
|
|
|
if (grub_hfsplus_read_file (&data->catalog_tree.file, 0, 0,
|
2009-08-23 15:35:22 +00:00
|
|
|
|
sizeof (struct grub_hfsplus_btnode),
|
|
|
|
|
sizeof (header), (char *) &header) <= 0)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
data->catalog_tree.root = grub_be_to_cpu32 (header.root);
|
|
|
|
|
data->catalog_tree.nodesize = grub_be_to_cpu16 (header.nodesize);
|
2009-06-05 21:00:43 +00:00
|
|
|
|
data->case_sensitive = ((magic == GRUB_HFSPLUSX_MAGIC) &&
|
|
|
|
|
(header.key_compare == GRUB_HFSPLUSX_BINARYCOMPARE));
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2015-03-06 21:33:20 +00:00
|
|
|
|
if (data->catalog_tree.nodesize < 2)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
2013-02-27 16:19:15 +00:00
|
|
|
|
if (grub_hfsplus_read_file (&data->extoverflow_tree.file, 0, 0,
|
2009-08-23 15:35:22 +00:00
|
|
|
|
sizeof (struct grub_hfsplus_btnode),
|
|
|
|
|
sizeof (header), (char *) &header) <= 0)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
data->extoverflow_tree.root = grub_be_to_cpu32 (header.root);
|
|
|
|
|
|
2013-02-27 16:19:15 +00:00
|
|
|
|
if (grub_hfsplus_read_file (&data->extoverflow_tree.file, 0, 0, 0,
|
2009-08-23 15:35:22 +00:00
|
|
|
|
sizeof (node), (char *) &node) <= 0)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
data->extoverflow_tree.root = grub_be_to_cpu32 (header.root);
|
|
|
|
|
data->extoverflow_tree.nodesize = grub_be_to_cpu16 (header.nodesize);
|
|
|
|
|
|
2015-03-06 21:33:20 +00:00
|
|
|
|
if (data->extoverflow_tree.nodesize < 2)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
2013-05-07 13:46:17 +00:00
|
|
|
|
if (grub_hfsplus_read_file (&data->attr_tree.file, 0, 0,
|
|
|
|
|
sizeof (struct grub_hfsplus_btnode),
|
|
|
|
|
sizeof (header), (char *) &header) <= 0)
|
|
|
|
|
{
|
|
|
|
|
grub_errno = 0;
|
|
|
|
|
data->attr_tree.root = 0;
|
|
|
|
|
data->attr_tree.nodesize = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data->attr_tree.root = grub_be_to_cpu32 (header.root);
|
|
|
|
|
data->attr_tree.nodesize = grub_be_to_cpu16 (header.nodesize);
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
data->dirroot.data = data;
|
|
|
|
|
data->dirroot.fileid = GRUB_HFSPLUS_FILEID_ROOTDIR;
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
|
|
fail:
|
2007-08-02 17:24:06 +00:00
|
|
|
|
|
|
|
|
|
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
|
2009-12-25 00:04:51 +00:00
|
|
|
|
grub_error (GRUB_ERR_BAD_FS, "not a HFS+ filesystem");
|
2007-08-02 17:24:06 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_free (data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Compare the on disk catalog key KEYA with the catalog key we are
|
|
|
|
|
looking for (KEYB). */
|
|
|
|
|
static int
|
|
|
|
|
grub_hfsplus_cmp_catkey (struct grub_hfsplus_key *keya,
|
|
|
|
|
struct grub_hfsplus_key_internal *keyb)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_catkey *catkey_a = &keya->catkey;
|
|
|
|
|
struct grub_hfsplus_catkey_internal *catkey_b = &keyb->catkey;
|
|
|
|
|
int diff;
|
2012-01-14 14:44:34 +00:00
|
|
|
|
grub_size_t len;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2011-01-03 14:30:41 +00:00
|
|
|
|
/* 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;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2012-01-14 14:44:34 +00:00
|
|
|
|
len = grub_be_to_cpu16 (catkey_a->namelen);
|
|
|
|
|
if (len > catkey_b->namelen)
|
|
|
|
|
len = catkey_b->namelen;
|
2012-05-04 10:08:22 +00:00
|
|
|
|
/* Since it's big-endian memcmp gives the same result as manually comparing
|
|
|
|
|
uint16_t but may be faster. */
|
2011-12-12 21:40:43 +00:00
|
|
|
|
diff = grub_memcmp (catkey_a->name, catkey_b->name,
|
2012-01-14 14:44:34 +00:00
|
|
|
|
len * sizeof (catkey_a->name[0]));
|
2011-12-12 21:40:43 +00:00
|
|
|
|
if (diff == 0)
|
|
|
|
|
diff = grub_be_to_cpu16 (catkey_a->namelen) - catkey_b->namelen;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
return diff;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 22:32:17 +00:00
|
|
|
|
/* Compare the on disk catalog key KEYA with the catalog key we are
|
|
|
|
|
looking for (KEYB). */
|
|
|
|
|
static int
|
|
|
|
|
grub_hfsplus_cmp_catkey_id (struct grub_hfsplus_key *keya,
|
|
|
|
|
struct grub_hfsplus_key_internal *keyb)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_catkey *catkey_a = &keya->catkey;
|
|
|
|
|
struct grub_hfsplus_catkey_internal *catkey_b = &keyb->catkey;
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
/* Compare the on disk extent overflow key KEYA with the extent
|
|
|
|
|
overflow key we are looking for (KEYB). */
|
|
|
|
|
static int
|
|
|
|
|
grub_hfsplus_cmp_extkey (struct grub_hfsplus_key *keya,
|
|
|
|
|
struct grub_hfsplus_key_internal *keyb)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_extkey *extkey_a = &keya->extkey;
|
|
|
|
|
struct grub_hfsplus_extkey_internal *extkey_b = &keyb->extkey;
|
2011-01-03 14:30:41 +00:00
|
|
|
|
grub_uint32_t akey;
|
|
|
|
|
|
|
|
|
|
/* 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;
|
2012-05-26 09:54:20 +00:00
|
|
|
|
|
|
|
|
|
if (extkey_a->type > extkey_b->type)
|
|
|
|
|
return 1;
|
|
|
|
|
if (extkey_a->type < extkey_b->type)
|
|
|
|
|
return -1;
|
2013-05-07 13:46:17 +00:00
|
|
|
|
|
|
|
|
|
if (extkey_a->type > extkey_b->type)
|
|
|
|
|
return +1;
|
|
|
|
|
|
|
|
|
|
if (extkey_a->type < extkey_b->type)
|
|
|
|
|
return -1;
|
2011-01-03 14:30:41 +00:00
|
|
|
|
|
|
|
|
|
akey = grub_be_to_cpu32 (extkey_a->start);
|
|
|
|
|
if (akey > extkey_b->start)
|
|
|
|
|
return 1;
|
|
|
|
|
if (akey < extkey_b->start)
|
|
|
|
|
return -1;
|
|
|
|
|
return 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
grub_hfsplus_read_symlink (grub_fshelp_node_t node)
|
|
|
|
|
{
|
|
|
|
|
char *symlink;
|
|
|
|
|
grub_ssize_t numread;
|
2020-07-19 18:43:31 +00:00
|
|
|
|
grub_size_t sz = node->size;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2020-07-19 18:43:31 +00:00
|
|
|
|
if (grub_add (sz, 1, &sz))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
symlink = grub_malloc (sz);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
if (!symlink)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-02-27 16:19:15 +00:00
|
|
|
|
numread = grub_hfsplus_read_file (node, 0, 0, 0, node->size, symlink);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
if (numread != (grub_ssize_t) node->size)
|
|
|
|
|
{
|
|
|
|
|
grub_free (symlink);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
symlink[node->size] = '\0';
|
|
|
|
|
|
|
|
|
|
return symlink;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-26 21:58:36 +00:00
|
|
|
|
static int
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_hfsplus_btree_iterate_node (struct grub_hfsplus_btree *btree,
|
|
|
|
|
struct grub_hfsplus_btnode *first_node,
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t first_rec,
|
2013-03-01 13:02:27 +00:00
|
|
|
|
int (*hook) (void *record, void *hook_arg),
|
|
|
|
|
void *hook_arg)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t rec;
|
2012-02-24 21:28:45 +00:00
|
|
|
|
grub_uint64_t saved_node = -1;
|
|
|
|
|
grub_uint64_t node_count = 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
char *cnode = (char *) first_node;
|
|
|
|
|
|
|
|
|
|
/* Iterate over all records in this node. */
|
|
|
|
|
for (rec = first_rec; rec < grub_be_to_cpu16 (first_node->count); rec++)
|
|
|
|
|
{
|
2013-03-01 13:02:27 +00:00
|
|
|
|
if (hook (grub_hfsplus_btree_recptr (btree, first_node, rec), hook_arg))
|
2005-12-25 15:59:50 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! first_node->next)
|
|
|
|
|
break;
|
|
|
|
|
|
2012-02-24 21:28:45 +00:00
|
|
|
|
if (node_count && first_node->next == saved_node)
|
|
|
|
|
{
|
|
|
|
|
grub_error (GRUB_ERR_BAD_FS, "HFS+ btree loop");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!(node_count & (node_count - 1)))
|
|
|
|
|
saved_node = first_node->next;
|
|
|
|
|
node_count++;
|
|
|
|
|
|
2013-02-27 16:19:15 +00:00
|
|
|
|
if (grub_hfsplus_read_file (&btree->file, 0, 0,
|
2012-02-24 21:28:45 +00:00
|
|
|
|
(((grub_disk_addr_t)
|
|
|
|
|
grub_be_to_cpu32 (first_node->next))
|
2009-08-23 15:35:22 +00:00
|
|
|
|
* btree->nodesize),
|
|
|
|
|
btree->nodesize, cnode) <= 0)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* Don't skip any record in the next iteration. */
|
|
|
|
|
first_rec = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Lookup the node described by KEY in the B+ Tree BTREE. Compare
|
|
|
|
|
keys using the function COMPARE_KEYS. When a match is found,
|
|
|
|
|
return the node in MATCHNODE and a pointer to the data in this node
|
2007-12-30 08:52:06 +00:00
|
|
|
|
in KEYOFFSET. MATCHNODE should be freed by the caller. */
|
2013-05-07 13:46:17 +00:00
|
|
|
|
grub_err_t
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree,
|
|
|
|
|
struct grub_hfsplus_key_internal *key,
|
|
|
|
|
int (*compare_keys) (struct grub_hfsplus_key *keya,
|
|
|
|
|
struct grub_hfsplus_key_internal *keyb),
|
2011-10-14 20:41:21 +00:00
|
|
|
|
struct grub_hfsplus_btnode **matchnode,
|
|
|
|
|
grub_off_t *keyoffset)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
grub_uint64_t currnode;
|
|
|
|
|
char *node;
|
|
|
|
|
struct grub_hfsplus_btnode *nodedesc;
|
2011-10-14 20:41:21 +00:00
|
|
|
|
grub_disk_addr_t rec;
|
2012-02-24 21:28:45 +00:00
|
|
|
|
grub_uint64_t save_node;
|
|
|
|
|
grub_uint64_t node_count = 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2013-05-07 13:46:17 +00:00
|
|
|
|
if (!btree->nodesize)
|
|
|
|
|
{
|
|
|
|
|
*matchnode = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
node = grub_malloc (btree->nodesize);
|
|
|
|
|
if (! node)
|
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
|
|
currnode = btree->root;
|
2012-02-24 21:28:45 +00:00
|
|
|
|
save_node = currnode - 1;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
int match = 0;
|
|
|
|
|
|
2012-02-24 21:28:45 +00:00
|
|
|
|
if (save_node == currnode)
|
|
|
|
|
{
|
|
|
|
|
grub_free (node);
|
|
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "HFS+ btree loop");
|
|
|
|
|
}
|
|
|
|
|
if (!(node_count & (node_count - 1)))
|
|
|
|
|
save_node = currnode;
|
|
|
|
|
node_count++;
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
/* Read a node. */
|
2013-02-27 16:19:15 +00:00
|
|
|
|
if (grub_hfsplus_read_file (&btree->file, 0, 0,
|
2011-10-25 22:32:17 +00:00
|
|
|
|
(grub_disk_addr_t) currnode
|
|
|
|
|
* (grub_disk_addr_t) btree->nodesize,
|
2009-08-23 15:35:22 +00:00
|
|
|
|
btree->nodesize, (char *) node) <= 0)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
|
|
|
|
grub_free (node);
|
2009-12-24 22:53:05 +00:00
|
|
|
|
return grub_error (GRUB_ERR_BAD_FS, "couldn't read i-node");
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nodedesc = (struct grub_hfsplus_btnode *) node;
|
|
|
|
|
|
|
|
|
|
/* Find the record in this tree. */
|
|
|
|
|
for (rec = 0; rec < grub_be_to_cpu16 (nodedesc->count); rec++)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_key *currkey;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
currkey = grub_hfsplus_btree_recptr (btree, nodedesc, rec);
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
/* The action that has to be taken depend on the type of
|
|
|
|
|
record. */
|
|
|
|
|
if (nodedesc->type == GRUB_HFSPLUS_BTNODE_TYPE_LEAF
|
|
|
|
|
&& compare_keys (currkey, key) == 0)
|
|
|
|
|
{
|
|
|
|
|
/* An exact match was found! */
|
|
|
|
|
|
|
|
|
|
*matchnode = nodedesc;
|
|
|
|
|
*keyoffset = rec;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if (nodedesc->type == GRUB_HFSPLUS_BTNODE_TYPE_INDEX)
|
|
|
|
|
{
|
2011-12-13 01:05:58 +00:00
|
|
|
|
void *pointer;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2007-12-30 08:52:06 +00:00
|
|
|
|
/* The place where the key could have been found didn't
|
2005-12-25 15:59:50 +00:00
|
|
|
|
contain the key. This means that the previous match
|
|
|
|
|
is the one that should be followed. */
|
|
|
|
|
if (compare_keys (currkey, key) > 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Mark the last key which is lower or equal to the key
|
|
|
|
|
that we are looking for. The last match that is
|
|
|
|
|
found will be used to locate the child which can
|
|
|
|
|
contain the record. */
|
2011-12-13 01:05:58 +00:00
|
|
|
|
pointer = ((char *) currkey
|
|
|
|
|
+ grub_be_to_cpu16 (currkey->keylen)
|
|
|
|
|
+ 2);
|
|
|
|
|
currnode = grub_be_to_cpu32 (grub_get_unaligned32 (pointer));
|
2005-12-25 15:59:50 +00:00
|
|
|
|
match = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-28 03:20:18 +00:00
|
|
|
|
/* No match is found, no record with this key exists in the
|
2005-12-25 15:59:50 +00:00
|
|
|
|
tree. */
|
|
|
|
|
if (! match)
|
|
|
|
|
{
|
|
|
|
|
*matchnode = 0;
|
|
|
|
|
grub_free (node);
|
2013-05-07 13:46:17 +00:00
|
|
|
|
return 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
struct list_nodes_ctx
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
grub_fshelp_node_t dir;
|
|
|
|
|
grub_fshelp_iterate_dir_hook_t hook;
|
|
|
|
|
void *hook_data;
|
|
|
|
|
};
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
static int
|
2013-03-01 13:02:27 +00:00
|
|
|
|
list_nodes (void *record, void *hook_arg)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
2013-03-01 13:02:27 +00:00
|
|
|
|
struct grub_hfsplus_catkey *catkey;
|
|
|
|
|
char *filename;
|
|
|
|
|
int i;
|
|
|
|
|
struct grub_fshelp_node *node;
|
2019-04-11 09:14:05 +00:00
|
|
|
|
grub_uint16_t *keyname;
|
2013-03-01 13:02:27 +00:00
|
|
|
|
struct grub_hfsplus_catfile *fileinfo;
|
|
|
|
|
enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN;
|
|
|
|
|
struct list_nodes_ctx *ctx = hook_arg;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
catkey = (struct grub_hfsplus_catkey *) record;
|
|
|
|
|
|
|
|
|
|
fileinfo =
|
|
|
|
|
(struct grub_hfsplus_catfile *) ((char *) record
|
|
|
|
|
+ grub_be_to_cpu16 (catkey->keylen)
|
|
|
|
|
+ 2 + (grub_be_to_cpu16(catkey->keylen)
|
|
|
|
|
% 2));
|
|
|
|
|
|
|
|
|
|
/* Stop iterating when the last directory entry is found. */
|
|
|
|
|
if (grub_be_to_cpu32 (catkey->parent) != ctx->dir->fileid)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* Determine the type of the node that is found. */
|
|
|
|
|
switch (fileinfo->type)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
2013-03-01 13:02:27 +00:00
|
|
|
|
case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_REG):
|
|
|
|
|
{
|
|
|
|
|
int mode = (grub_be_to_cpu16 (fileinfo->mode)
|
|
|
|
|
& GRUB_HFSPLUS_FILEMODE_MASK);
|
|
|
|
|
|
|
|
|
|
if (mode == GRUB_HFSPLUS_FILEMODE_REG)
|
|
|
|
|
type = GRUB_FSHELP_REG;
|
|
|
|
|
else if (mode == GRUB_HFSPLUS_FILEMODE_SYMLINK)
|
|
|
|
|
type = GRUB_FSHELP_SYMLINK;
|
|
|
|
|
else
|
|
|
|
|
type = GRUB_FSHELP_UNKNOWN;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_DIR):
|
|
|
|
|
type = GRUB_FSHELP_DIR;
|
|
|
|
|
break;
|
|
|
|
|
case grub_cpu_to_be16_compile_time (GRUB_HFSPLUS_FILETYPE_DIR_THREAD):
|
|
|
|
|
if (ctx->dir->fileid == 2)
|
|
|
|
|
return 0;
|
|
|
|
|
node = grub_malloc (sizeof (*node));
|
|
|
|
|
if (!node)
|
2006-04-30 17:30:12 +00:00
|
|
|
|
return 1;
|
2013-03-01 13:02:27 +00:00
|
|
|
|
node->data = ctx->dir->data;
|
|
|
|
|
node->mtime = 0;
|
|
|
|
|
node->size = 0;
|
|
|
|
|
node->fileid = grub_be_to_cpu32 (fileinfo->parentid);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
ctx->ret = ctx->hook ("..", GRUB_FSHELP_DIR, node, ctx->hook_data);
|
|
|
|
|
return ctx->ret;
|
|
|
|
|
}
|
2012-05-26 22:56:55 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
if (type == GRUB_FSHELP_UNKNOWN)
|
|
|
|
|
return 0;
|
2006-04-30 17:30:12 +00:00
|
|
|
|
|
2020-07-19 18:43:31 +00:00
|
|
|
|
filename = grub_calloc (grub_be_to_cpu16 (catkey->namelen),
|
|
|
|
|
GRUB_MAX_UTF8_PER_UTF16 + 1);
|
2013-03-01 13:02:27 +00:00
|
|
|
|
if (! filename)
|
|
|
|
|
return 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2020-06-15 16:26:01 +00:00
|
|
|
|
keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname));
|
2019-04-11 09:14:05 +00:00
|
|
|
|
if (!keyname)
|
|
|
|
|
{
|
|
|
|
|
grub_free (filename);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
/* Make sure the byte order of the UTF16 string is correct. */
|
|
|
|
|
for (i = 0; i < grub_be_to_cpu16 (catkey->namelen); i++)
|
|
|
|
|
{
|
2019-04-11 09:14:05 +00:00
|
|
|
|
keyname[i] = grub_be_to_cpu16 (catkey->name[i]);
|
2011-12-12 21:40:43 +00:00
|
|
|
|
|
2019-04-11 09:14:05 +00:00
|
|
|
|
if (keyname[i] == '/')
|
|
|
|
|
keyname[i] = ':';
|
2006-04-30 17:30:12 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
/* If the name is obviously invalid, skip this node. */
|
2019-04-11 09:14:05 +00:00
|
|
|
|
if (keyname[i] == 0)
|
2015-01-27 18:19:28 +00:00
|
|
|
|
{
|
2019-04-11 09:14:05 +00:00
|
|
|
|
grub_free (keyname);
|
2015-01-27 18:19:28 +00:00
|
|
|
|
grub_free (filename);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-03-01 13:02:27 +00:00
|
|
|
|
}
|
2012-01-14 22:34:33 +00:00
|
|
|
|
|
2019-04-11 09:14:05 +00:00
|
|
|
|
*grub_utf16_to_utf8 ((grub_uint8_t *) filename, keyname,
|
2013-03-01 13:02:27 +00:00
|
|
|
|
grub_be_to_cpu16 (catkey->namelen)) = '\0';
|
2006-04-30 17:30:12 +00:00
|
|
|
|
|
2019-04-11 09:14:05 +00:00
|
|
|
|
grub_free (keyname);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
/* hfs+ is case insensitive. */
|
|
|
|
|
if (! ctx->dir->data->case_sensitive)
|
|
|
|
|
type |= GRUB_FSHELP_CASE_INSENSITIVE;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
/* A valid node is found; setup the node and call the
|
|
|
|
|
callback function. */
|
|
|
|
|
node = grub_malloc (sizeof (*node));
|
|
|
|
|
if (!node)
|
2015-01-27 18:19:28 +00:00
|
|
|
|
{
|
|
|
|
|
grub_free (filename);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2013-03-01 13:02:27 +00:00
|
|
|
|
node->data = ctx->dir->data;
|
2013-05-07 13:46:17 +00:00
|
|
|
|
node->compressed = 0;
|
|
|
|
|
node->cbuf = 0;
|
|
|
|
|
node->compress_index = 0;
|
2009-02-07 20:57:23 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
grub_memcpy (node->extents, fileinfo->data.extents,
|
|
|
|
|
sizeof (node->extents));
|
2013-05-07 13:46:17 +00:00
|
|
|
|
grub_memcpy (node->resource_extents, fileinfo->resource.extents,
|
|
|
|
|
sizeof (node->resource_extents));
|
2013-03-01 13:02:27 +00:00
|
|
|
|
node->mtime = grub_be_to_cpu32 (fileinfo->mtime) - 2082844800;
|
|
|
|
|
node->size = grub_be_to_cpu64 (fileinfo->data.size);
|
2013-05-07 13:46:17 +00:00
|
|
|
|
node->resource_size = grub_be_to_cpu64 (fileinfo->resource.size);
|
2013-03-01 13:02:27 +00:00
|
|
|
|
node->fileid = grub_be_to_cpu32 (fileinfo->fileid);
|
2011-12-12 21:40:43 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
ctx->ret = ctx->hook (filename, type, node, ctx->hook_data);
|
2011-12-12 21:40:43 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
grub_free (filename);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
return ctx->ret;
|
|
|
|
|
}
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
static int
|
|
|
|
|
grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
|
|
|
|
|
grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
|
|
|
|
|
{
|
|
|
|
|
struct list_nodes_ctx ctx =
|
|
|
|
|
{
|
|
|
|
|
.ret = 0,
|
|
|
|
|
.dir = dir,
|
|
|
|
|
.hook = hook,
|
|
|
|
|
.hook_data = hook_data
|
|
|
|
|
};
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
struct grub_hfsplus_key_internal intern;
|
2015-03-27 13:44:41 +00:00
|
|
|
|
struct grub_hfsplus_btnode *node = NULL;
|
|
|
|
|
grub_disk_addr_t ptr = 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
2012-05-26 22:56:55 +00:00
|
|
|
|
{
|
|
|
|
|
struct grub_fshelp_node *fsnode;
|
|
|
|
|
fsnode = grub_malloc (sizeof (*fsnode));
|
|
|
|
|
if (!fsnode)
|
|
|
|
|
return 1;
|
|
|
|
|
*fsnode = *dir;
|
2013-01-21 01:33:46 +00:00
|
|
|
|
if (hook (".", GRUB_FSHELP_DIR, fsnode, hook_data))
|
2012-05-26 22:56:55 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
/* Create a key that points to the first entry in the directory. */
|
|
|
|
|
intern.catkey.parent = dir->fileid;
|
2011-12-12 21:40:43 +00:00
|
|
|
|
intern.catkey.name = 0;
|
|
|
|
|
intern.catkey.namelen = 0;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
/* First lookup the first entry. */
|
|
|
|
|
if (grub_hfsplus_btree_search (&dir->data->catalog_tree, &intern,
|
2013-05-07 13:46:17 +00:00
|
|
|
|
grub_hfsplus_cmp_catkey, &node, &ptr)
|
|
|
|
|
|| !node)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* Iterate over all entries in this directory. */
|
2006-04-30 17:30:12 +00:00
|
|
|
|
grub_hfsplus_btree_iterate_node (&dir->data->catalog_tree, node, ptr,
|
2013-03-01 13:02:27 +00:00
|
|
|
|
list_nodes, &ctx);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
grub_free (node);
|
|
|
|
|
|
2013-03-01 13:02:27 +00:00
|
|
|
|
return ctx.ret;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Open a file named NAME and initialize FILE. */
|
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_hfsplus_open (struct grub_file *file, const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_data *data;
|
|
|
|
|
struct grub_fshelp_node *fdiro = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_dl_ref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
data = grub_hfsplus_mount (file->device->disk);
|
|
|
|
|
if (!data)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
grub_fshelp_find_file (name, &data->dirroot, &fdiro,
|
|
|
|
|
grub_hfsplus_iterate_dir,
|
|
|
|
|
grub_hfsplus_read_symlink, GRUB_FSHELP_REG);
|
|
|
|
|
if (grub_errno)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
2013-05-07 13:46:17 +00:00
|
|
|
|
if (grub_hfsplus_open_compressed)
|
|
|
|
|
{
|
|
|
|
|
grub_err_t err;
|
|
|
|
|
err = grub_hfsplus_open_compressed (fdiro);
|
|
|
|
|
if (err)
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
file->size = fdiro->size;
|
|
|
|
|
data->opened_file = *fdiro;
|
|
|
|
|
grub_free (fdiro);
|
|
|
|
|
|
|
|
|
|
file->data = data;
|
|
|
|
|
file->offset = 0;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
if (data && fdiro != &data->dirroot)
|
|
|
|
|
grub_free (fdiro);
|
|
|
|
|
grub_free (data);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_hfsplus_close (grub_file_t file)
|
|
|
|
|
{
|
2013-05-07 13:46:17 +00:00
|
|
|
|
struct grub_hfsplus_data *data =
|
|
|
|
|
(struct grub_hfsplus_data *) file->data;
|
|
|
|
|
|
|
|
|
|
grub_free (data->opened_file.cbuf);
|
|
|
|
|
grub_free (data->opened_file.compress_index);
|
|
|
|
|
|
|
|
|
|
grub_free (data);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read LEN bytes data from FILE into BUF. */
|
|
|
|
|
static grub_ssize_t
|
2006-06-04 Yoshinori K. Okuji <okuji@enbug.org>
Clean up the code to support 64-bit addressing in disks and
files. This change is not enough for filesystems yet.
* util/i386/pc/grub-setup.c (struct boot_blocklist): Change the
type of "start" to grub_uint64_t.
(setup): Change the types of KERNEL_SECTOR and FIRST_SECTOR to
grub_disk_addr_t * and grub_disk_addr_t. Fix the format string in
save_first_sector and save_blocklists. Use grub_le_to_cpu64 to
convert addresses.
* util/i386/pc/biosdisk.c (open_device): Change the type of SECTOR
to grub_disk_addr_t.
* partmap/gpt.c (gpt_partition_map_iterate): Fix the format
string.
* partmap/pc.c (pc_partition_map_iterate): Likewise.
* partmap/amiga.c (amiga_partition_map_iterate): Cast RDSK.MAGIC
to char *.
* normal/script.c (grub_script_parse): Remove unused MEMFREE.
* normal/parser.y (YYLTYPE_IS_TRIVIAL): New macro.
* normal/lexer.c (grub_script_yyerror): Specify unused to LEX.
* loader/i386/pc/multiboot.c (grub_multiboot_load_elf64): Cast -1
to grub_off_t, to detect an error from grub_file_seek.
(grub_multiboot_load_elf32): Likewise.
* kern/misc.c (grub_strtoul): Use grub_strtoull. Return the
maximum unsigned long value when an overflow is detected.
(grub_strtoull): New function.
(grub_divmod64): Likewise.
(grub_lltoa): use grub_divmod64.
* kern/fs.c (struct grub_fs_block): Change the type of "offset" to
grub_disk_addr_t.
(grub_fs_blocklist_open): Increase P if P is not NULL to advance
the pointer to next character. Use grub_strtoull instead of
grub_strtoul.
(grub_fs_blocklist_read): Change the types of SECTOR, OFFSET and
SIZE to grub_disk_addr_t, grub_off_t and grub_size_t,
respectively.
* kern/file.c (grub_file_read): Prevent an oveflow of LEN, as the
return value is signed.
(grub_file_seek): Change the type of OLD to grub_off_t. Do not
test if OFFSET is less than zero, as OFFSET is unsigned now.
* kern/disk.c (struct grub_disk_cache): Change the type of
"sector" to grub_disk_addr_t.
(grub_disk_cache_get_index): Change the type of SECTOR to
grub_disk_addr_t. Calculate the hash with SECTOR casted to
unsigned after shifting.
(grub_disk_cache_invalidate): Change the type of SECTOR to
grub_disk_addr_t.
(grub_disk_cache_unlock): Likewise.
(grub_disk_cache_store): Likewise.
(grub_disk_check_range): Change the types of SECTOR, OFFSET, SIZE,
START and LEN to grub_disk_addr_t *, grub_off_t *, grub_size_t,
grub_disk_addr_t and grub_uint64_t, respectively.
(grub_disk_read): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of START_SECTOR, LEN and
POS to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
(grub_disk_write): Use an unsigned variable REAL_OFFSET for the
body, as the value of OFFSET is tweaked by
grub_disk_check_range. Change the types of LEN and N to
grub_size_t.
* io/gzio.c (struct grub_gzio): Change the types of "data_offset"
and "saved_offset" to grub_off_t.
(test_header): Cast BUF to char *.
(get_byte): Cast GZIO->DATA_OFFSET to grub_off_t. Cast GZIO->INBUF
to char *.
(grub_gzio_read): Change the types of OFFSET and SIZE to
grub_off_t and grub_size_t, respectively.
* include/grub/i386/pc/boot.h (GRUB_BOOT_MACHINE_FORCE_LBA):
Removed.
(GRUB_BOOT_MACHINE_BOOT_DRIVE): Changed to 0x4c.
(GRUB_BOOT_MACHINE_KERNEL_ADDRESS): Changed to 0x40.
(GRUB_BOOT_MACHINE_KERNEL_SEGMENT): Changed to 0x42.
(GRUB_BOOT_MACHINE_DRIVE_CHECK): Changed to 0x4e.
(GRUB_BOOT_MACHINE_LIST_SIZE): Increased to 12.
* include/grub/types.h (grub_off_t): Unconditionally set to
grub_uint64_t.
(grub_disk_addr_t): Changed to grub_uint64_t.
* include/grub/partition.h (struct grub_partition): Change the
types of "start", "len" and "offset" to grub_disk_addr_t,
grub_uint64_t and grub_disk_addr_t, respectively.
(grub_partition_get_start): Return grub_disk_addr_t.
(grub_partition_get_len): Return grub_uint64_t.
* include/grub/misc.h (grub_strtoull): New prototype.
(grub_divmod64): Likewise.
* include/grub/fshelp.h (grub_fshelp_read_file): Change the types
of SECTOR, LEN and FILESIZE to grub_disk_addr_t, grub_size_t and
grub_off_t, respectively.
All callers and references changed.
* include/grub/fs.h (struct grub_fs): Change the type of LEN to
grub_size_t in "read".
All callers and references changed.
* include/grub/file.h (struct grub_file): Change the types of
"offset" and "size" to grub_off_t and grub_off_t,
respectively. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_file_read): Change the type of LEN to grub_size_t.
(grub_file_seek): Return grub_off_t. Change the type of OFFSET to
grub_off_t.
(grub_file_size): Return grub_off_t.
(grub_file_tell): Likewise.
All callers and references changed.
* include/grub/disk.h (struct grub_disk_dev): Change the types of
SECTOR and SIZE to grub_disk_addr_t and grub_size_t in "read" and
"write".
(struct grub_disk): Change the type of "total_sectors" to
grub_uint64_t. Change the type of SECTOR to grub_disk_addr_t in
"read_hook".
(grub_disk_read): Change the types of SECTOR, OFFSET and SIZE to
grub_disk_addr_t, grub_off_t and grub_size_t, respectively.
(grub_disk_write): Likewise.
All callers and references changed.
* fs/iso9660.c (grub_iso9660_susp_iterate): Cast parameters to
char * for grub_strncmp to silence gcc.
(grub_iso9660_mount): Likewise.
(grub_iso9660_mount): Likewise.
(grub_iso9660_read_symlink): Likewise. Also, remove the nonsense
return statement.
(grub_iso9660_iterate_dir): Likewise.
(grub_iso9660_label): Cast DATA->VOLDESC.VOLNAME to char *.
* fs/hfs.c (grub_hfs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/hfsplus.c (grub_hfsplus_read_file): Likewise.
* fs/jfs.c (grub_jfs_read_file): Likewise.
* fs/minix.c (grub_jfs_read_file): Likewise.
* fs/sfs.c (grub_jfs_read_file): Likewise.
* fs/ufs.c (grub_jfs_read_file): Likewise.
* fs/xfs.c (grub_jfs_read_file): Likewise.
* fs/fat.c (grub_fat_read_data): Change the types of SECTOR, LEN
and SIZE to grub_disk_addr_t, grub_size_t and grub_size_t,
respectively.
* fs/ext2.c (grub_ext2_read_block): When an error happens, set
BLKNR to -1 instead of returning GRUB_ERRNO.
(grub_ext2_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* fs/affs.c (grub_affs_read_file): Change the types of SECTOR and
LEN to grub_disk_addr_t and grub_size_t, respectively.
* font/manager.c (grub_font_get_glyph): Cast BITMAP to char * for
grub_file_read.
* disk/ieee1275/ofdisk.c (grub_ofdisk_read): Fix the format
string. Do not cast SECTOR explicitly.
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Change the type of
TOTAL_SECTORS to grub_uint64_t. Do not mask DRP->TOTAL_SECTORS.
(grub_biosdisk_rw): Change the types of SECTOR and SIZE to
grub_disk_addr_t and grub_size_t, respectively. If the sector is
over 2TB and LBA mode is not supported, raise an error.
(get_safe_sectors): New function.
(grub_biosdisk_read): Use get_safe_sectors.
(grub_biosdisk_write): Likewise.
* disk/efi/efidisk.c (grub_efidisk_read): Fix the format string.
(grub_efidisk_write): Likewise.
* disk/loopback.c (delete_loopback): Cosmetic changes.
(grub_cmd_loopback): Likewise. Also, test NEWDEV->FILENAME
correctly.
(grub_loopback_open): Likewise.
(grub_loopback_read): Likewise. Also, change the type of POS to
grub_off_t, and fix the usage of grub_memset.
* commands/i386/pc/play.c: Include grub/machine/time.h.
* commands/ls.c (grub_ls_list_files): Use "llu" instead of "d" to
print FILE->SIZE.
* commands/configfile.c: Include grub/env.h.
* commands/cmp.c (grub_cmd_cmp): Do not use ERR, but use
GRUB_ERRNO directly instead. Change the type of POS to
grub_off_t. Follow the coding standard.
* commands/blocklist.c: Include grub/partition.h.
(grub_cmd_blocklist): Return an error if the underlying device is
not a disk. Take the starting sector of a partition into account,
if a partition is used.
* boot/i386/pc/diskboot.S (bootloop): Adapted to the new offset of
a length field.
(lba_mode): Support 64-bit addresses.
(chs_mode): Likewise.
(copy_buffer): Adapted to the new offsets of a length field and a
segment field.
(blocklist_default_start): Allocate 64-bit space.
* boot/i386/pc/boot.S (force_lba): Removed.
(boot_drive): Moved to under KERNEL_SECTOR.
(kernel_sector): Moved to under KENREL_SEGMENT. Allocate 64-bit
space.
(real_start): Set %si earlier. Remove code for FORCE_LBA, since it
is useless.
(lba_mode): Refactored to support a 64-bit address. More size
optimization.
(setup_sectors): Likewise.
2006-06-04 15:56:55 +00:00
|
|
|
|
grub_hfsplus_read (grub_file_t file, char *buf, grub_size_t len)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
2009-06-10 21:04:23 +00:00
|
|
|
|
struct grub_hfsplus_data *data =
|
2005-12-25 15:59:50 +00:00
|
|
|
|
(struct grub_hfsplus_data *) file->data;
|
|
|
|
|
|
2013-11-02 15:30:53 +00:00
|
|
|
|
data->opened_file.file = file;
|
|
|
|
|
|
2013-05-07 13:46:17 +00:00
|
|
|
|
if (grub_hfsplus_read_compressed && data->opened_file.compressed)
|
|
|
|
|
return grub_hfsplus_read_compressed (&data->opened_file,
|
|
|
|
|
file->offset, len, buf);
|
|
|
|
|
|
2013-02-27 16:19:15 +00:00
|
|
|
|
return grub_hfsplus_read_file (&data->opened_file,
|
|
|
|
|
file->read_hook, file->read_hook_data,
|
|
|
|
|
file->offset, len, buf);
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 01:33:46 +00:00
|
|
|
|
/* Context for grub_hfsplus_dir. */
|
|
|
|
|
struct grub_hfsplus_dir_ctx
|
|
|
|
|
{
|
|
|
|
|
grub_fs_dir_hook_t hook;
|
|
|
|
|
void *hook_data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Helper for grub_hfsplus_dir. */
|
|
|
|
|
static int
|
|
|
|
|
grub_hfsplus_dir_iter (const char *filename,
|
|
|
|
|
enum grub_fshelp_filetype filetype,
|
|
|
|
|
grub_fshelp_node_t node, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_dir_ctx *ctx = data;
|
|
|
|
|
struct grub_dirhook_info info;
|
|
|
|
|
|
|
|
|
|
grub_memset (&info, 0, sizeof (info));
|
|
|
|
|
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
|
|
|
|
info.mtimeset = 1;
|
|
|
|
|
info.mtime = node->mtime;
|
2013-12-17 14:21:02 +00:00
|
|
|
|
info.inodeset = 1;
|
|
|
|
|
info.inode = node->fileid;
|
2013-01-21 01:33:46 +00:00
|
|
|
|
info.case_insensitive = !! (filetype & GRUB_FSHELP_CASE_INSENSITIVE);
|
|
|
|
|
grub_free (node);
|
|
|
|
|
return ctx->hook (filename, &info, ctx->hook_data);
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
static grub_err_t
|
2009-06-10 21:04:23 +00:00
|
|
|
|
grub_hfsplus_dir (grub_device_t device, const char *path,
|
2013-01-21 01:33:46 +00:00
|
|
|
|
grub_fs_dir_hook_t hook, void *hook_data)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
2013-01-21 01:33:46 +00:00
|
|
|
|
struct grub_hfsplus_dir_ctx ctx = { hook, hook_data };
|
2005-12-25 15:59:50 +00:00
|
|
|
|
struct grub_hfsplus_data *data = 0;
|
|
|
|
|
struct grub_fshelp_node *fdiro = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
grub_dl_ref (my_mod);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
data = grub_hfsplus_mount (device->disk);
|
|
|
|
|
if (!data)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
/* Find the directory that should be opened. */
|
|
|
|
|
grub_fshelp_find_file (path, &data->dirroot, &fdiro,
|
|
|
|
|
grub_hfsplus_iterate_dir,
|
|
|
|
|
grub_hfsplus_read_symlink, GRUB_FSHELP_DIR);
|
|
|
|
|
if (grub_errno)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
/* Iterate over all entries in this directory. */
|
2013-01-21 01:33:46 +00:00
|
|
|
|
grub_hfsplus_iterate_dir (fdiro, grub_hfsplus_dir_iter, &ctx);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
fail:
|
|
|
|
|
if (data && fdiro != &data->dirroot)
|
|
|
|
|
grub_free (fdiro);
|
|
|
|
|
grub_free (data);
|
|
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static grub_err_t
|
2011-10-25 22:32:17 +00:00
|
|
|
|
grub_hfsplus_label (grub_device_t device, char **label)
|
2005-12-25 15:59:50 +00:00
|
|
|
|
{
|
2011-10-25 22:32:17 +00:00
|
|
|
|
struct grub_hfsplus_data *data;
|
|
|
|
|
grub_disk_t disk = device->disk;
|
|
|
|
|
struct grub_hfsplus_catkey *catkey;
|
|
|
|
|
int i, label_len;
|
2019-04-11 09:14:05 +00:00
|
|
|
|
grub_uint16_t *label_name;
|
2011-10-25 22:32:17 +00:00
|
|
|
|
struct grub_hfsplus_key_internal intern;
|
2015-03-27 13:44:41 +00:00
|
|
|
|
struct grub_hfsplus_btnode *node = NULL;
|
|
|
|
|
grub_disk_addr_t ptr = 0;
|
2011-10-25 22:32:17 +00:00
|
|
|
|
|
|
|
|
|
*label = 0;
|
|
|
|
|
|
|
|
|
|
data = grub_hfsplus_mount (disk);
|
|
|
|
|
if (!data)
|
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
|
|
/* Create a key that points to the label. */
|
|
|
|
|
intern.catkey.parent = 1;
|
2011-12-12 21:40:43 +00:00
|
|
|
|
intern.catkey.name = 0;
|
|
|
|
|
intern.catkey.namelen = 0;
|
2011-10-25 22:32:17 +00:00
|
|
|
|
|
|
|
|
|
/* First lookup the first entry. */
|
|
|
|
|
if (grub_hfsplus_btree_search (&data->catalog_tree, &intern,
|
2013-05-07 13:46:17 +00:00
|
|
|
|
grub_hfsplus_cmp_catkey_id, &node, &ptr)
|
|
|
|
|
|| !node)
|
2011-10-25 22:32:17 +00:00
|
|
|
|
{
|
|
|
|
|
grub_free (data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catkey = (struct grub_hfsplus_catkey *)
|
2012-05-24 22:47:49 +00:00
|
|
|
|
grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr);
|
2011-10-25 22:32:17 +00:00
|
|
|
|
|
|
|
|
|
label_len = grub_be_to_cpu16 (catkey->namelen);
|
2020-06-15 16:26:01 +00:00
|
|
|
|
label_name = grub_calloc (label_len, sizeof (*label_name));
|
2019-04-11 09:14:05 +00:00
|
|
|
|
if (!label_name)
|
|
|
|
|
{
|
|
|
|
|
grub_free (node);
|
|
|
|
|
grub_free (data);
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 22:32:17 +00:00
|
|
|
|
for (i = 0; i < label_len; i++)
|
|
|
|
|
{
|
2019-04-11 09:14:05 +00:00
|
|
|
|
label_name[i] = grub_be_to_cpu16 (catkey->name[i]);
|
2011-10-25 22:32:17 +00:00
|
|
|
|
|
|
|
|
|
/* If the name is obviously invalid, skip this node. */
|
2019-04-11 09:14:05 +00:00
|
|
|
|
if (label_name[i] == 0)
|
|
|
|
|
{
|
|
|
|
|
grub_free (label_name);
|
|
|
|
|
grub_free (node);
|
|
|
|
|
grub_free (data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-10-25 22:32:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 16:26:01 +00:00
|
|
|
|
*label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1);
|
2011-10-25 22:32:17 +00:00
|
|
|
|
if (! *label)
|
2019-04-11 09:14:05 +00:00
|
|
|
|
{
|
|
|
|
|
grub_free (label_name);
|
|
|
|
|
grub_free (node);
|
|
|
|
|
grub_free (data);
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
2011-10-25 22:32:17 +00:00
|
|
|
|
|
2019-04-11 09:14:05 +00:00
|
|
|
|
*grub_utf16_to_utf8 ((grub_uint8_t *) (*label), label_name,
|
2011-12-12 21:40:43 +00:00
|
|
|
|
label_len) = '\0';
|
2011-10-25 22:32:17 +00:00
|
|
|
|
|
2019-04-11 09:14:05 +00:00
|
|
|
|
grub_free (label_name);
|
2011-10-25 22:32:17 +00:00
|
|
|
|
grub_free (node);
|
|
|
|
|
grub_free (data);
|
|
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
2005-12-25 15:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-05 20:19:05 +00:00
|
|
|
|
/* Get mtime. */
|
2009-06-10 21:04:23 +00:00
|
|
|
|
static grub_err_t
|
2009-04-05 20:19:05 +00:00
|
|
|
|
grub_hfsplus_mtime (grub_device_t device, grub_int32_t *tm)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_data *data;
|
|
|
|
|
grub_disk_t disk = device->disk;
|
|
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
|
|
|
|
|
data = grub_hfsplus_mount (disk);
|
|
|
|
|
if (!data)
|
|
|
|
|
*tm = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
else
|
2009-04-05 20:19:05 +00:00
|
|
|
|
*tm = grub_be_to_cpu32 (data->volheader.utime) - 2082844800;
|
|
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
|
|
grub_free (data);
|
|
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-04 15:50:44 +00:00
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_hfsplus_uuid (grub_device_t device, char **uuid)
|
|
|
|
|
{
|
|
|
|
|
struct grub_hfsplus_data *data;
|
|
|
|
|
grub_disk_t disk = device->disk;
|
|
|
|
|
|
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
|
|
|
|
|
|
data = grub_hfsplus_mount (disk);
|
|
|
|
|
if (data)
|
|
|
|
|
{
|
2010-01-20 08:12:47 +00:00
|
|
|
|
*uuid = grub_xasprintf ("%016llx",
|
2009-12-29 09:04:06 +00:00
|
|
|
|
(unsigned long long)
|
|
|
|
|
grub_be_to_cpu64 (data->volheader.num_serial));
|
2009-05-04 15:50:44 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*uuid = NULL;
|
|
|
|
|
|
|
|
|
|
grub_dl_unref (my_mod);
|
|
|
|
|
|
|
|
|
|
grub_free (data);
|
|
|
|
|
|
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-05 20:19:05 +00:00
|
|
|
|
|
2005-12-25 15:59:50 +00:00
|
|
|
|
|
|
|
|
|
static struct grub_fs grub_hfsplus_fs =
|
|
|
|
|
{
|
|
|
|
|
.name = "hfsplus",
|
2019-04-08 05:24:24 +00:00
|
|
|
|
.fs_dir = grub_hfsplus_dir,
|
|
|
|
|
.fs_open = grub_hfsplus_open,
|
|
|
|
|
.fs_read = grub_hfsplus_read,
|
|
|
|
|
.fs_close = grub_hfsplus_close,
|
|
|
|
|
.fs_label = grub_hfsplus_label,
|
|
|
|
|
.fs_mtime = grub_hfsplus_mtime,
|
|
|
|
|
.fs_uuid = grub_hfsplus_uuid,
|
2009-10-25 15:23:48 +00:00
|
|
|
|
#ifdef GRUB_UTIL
|
|
|
|
|
.reserved_first_sector = 1,
|
2012-02-27 20:36:58 +00:00
|
|
|
|
.blocklist_install = 1,
|
2009-10-25 15:23:48 +00:00
|
|
|
|
#endif
|
2005-12-25 15:59:50 +00:00
|
|
|
|
.next = 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GRUB_MOD_INIT(hfsplus)
|
|
|
|
|
{
|
|
|
|
|
grub_fs_register (&grub_hfsplus_fs);
|
|
|
|
|
my_mod = mod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GRUB_MOD_FINI(hfsplus)
|
|
|
|
|
{
|
|
|
|
|
grub_fs_unregister (&grub_hfsplus_fs);
|
|
|
|
|
}
|