mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-04 12:36:30 +00:00
* Transitional commit removing some nested functions and
simplifying/cleaningup grub code. Still needs more cleanup for OSX
This commit is contained in:
parent
d0af9bcc66
commit
1f4b2af502
@ -6,8 +6,9 @@ LDFLAGS+=${LINK}
|
||||
|
||||
foo: all
|
||||
|
||||
FILESYSTEMS= ext2.mk fat.mk hfs.mk hfsplus.mk iso9660.mk jfs.mk
|
||||
FILESYSTEMS+= ntfs.mk reiserfs.mk tar.mk udf.mk ufs2.mk ufs.mk xfs.mk
|
||||
FILESYSTEMS=hfs.mk hfsplus.mk iso9660.mk
|
||||
FILESYSTEMS+= ext2.mk fat.mk jfs.mk
|
||||
FILESYSTEMS+= ntfs.mk reiserfs.mk tar.mk udf.mk ufs2.mk ufs.mk xfs.mk
|
||||
|
||||
include $(FILESYSTEMS)
|
||||
|
||||
|
@ -10,10 +10,11 @@ KERNFILES+=kern/list.c kern/partition.c
|
||||
KERNFILES+=fs/fshelp.c
|
||||
KERNFILES+=fs/reiserfs.c fs/ext2.c
|
||||
KERNFILES+=fs/fat.c fs/ntfs.c
|
||||
KERNFILES+=fs/hfs.c fs/hfsplus.c
|
||||
KERNFILES+=fs/udf.c fs/iso9660.c
|
||||
#KERNFILES+=fs/hfs.c fs/hfsplus.c
|
||||
#KERNFILES+=fs/udf.c fs/iso9660.c
|
||||
KERNFILES+=fs/cpio.c fs/tar.c
|
||||
KERNFILES+=fs/xfs.c fs/jfs.c
|
||||
KERNFILES+=fs/xfs.c
|
||||
#fs/jfs.c
|
||||
#KERNFILES+=main.c
|
||||
KERNFILES+=grubfs.c
|
||||
|
||||
@ -22,6 +23,7 @@ KERNFILES+=partmap/msdos.c
|
||||
KERNOBJS=$(subst .c,.o,${KERNFILES})
|
||||
CFLAGS=-Iinclude -g
|
||||
CFLAGS+=-I../../../include
|
||||
#CFLAGS+=-fnested-functions
|
||||
BIN=test${EXT_EXE}
|
||||
|
||||
all: ${KERNOBJS} main.o ${BIN}
|
||||
@ -30,7 +32,6 @@ ${BIN}:
|
||||
${CC} -o ${BIN} main.o ${CFLAGS} ${KERNOBJS}
|
||||
|
||||
lib: all libgrubfs.a
|
||||
|
||||
|
||||
libgrubfs.a:
|
||||
rm -f libgrubfs.a
|
||||
|
@ -805,42 +805,22 @@ grub_ext2_open (struct grub_file *file, const char *name)
|
||||
return err;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ext2_close (grub_file_t file)
|
||||
{
|
||||
static grub_err_t grub_ext2_close (grub_file_t file) {
|
||||
grub_free (file->data);
|
||||
|
||||
grub_dl_unref (my_mod);
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Read LEN bytes data from FILE into BUF. */
|
||||
static grub_ssize_t
|
||||
grub_ext2_read (grub_file_t file, char *buf, grub_size_t len)
|
||||
{
|
||||
grub_ext2_read (grub_file_t file, char *buf, grub_size_t len) {
|
||||
struct grub_ext2_data *data = (struct grub_ext2_data *) file->data;
|
||||
|
||||
return grub_ext2_read_file (&data->diropen, file->read_hook,
|
||||
file->offset, len, buf);
|
||||
return grub_ext2_read_file (&data->diropen, file->read_hook, file->offset, len, buf);
|
||||
}
|
||||
|
||||
|
||||
static grub_err_t
|
||||
grub_ext2_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
struct grub_ext2_data *data = 0;
|
||||
struct grub_fshelp_node *fdiro = 0;
|
||||
|
||||
auto int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node);
|
||||
|
||||
int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)
|
||||
static struct grub_ext2_data *data = 0;
|
||||
static int (*hook) (const char *filename, const struct grub_dirhook_info *info);
|
||||
static int iterate (const char *filename, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
@ -862,6 +842,16 @@ grub_ext2_dir (grub_device_t device, const char *path,
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
||||
|
||||
static grub_err_t
|
||||
grub_ext2_dir (grub_device_t device, const char *path,
|
||||
int (*_hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
data = 0;
|
||||
hook = _hook;
|
||||
struct grub_fshelp_node *fdiro = 0;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
data = grub_ext2_mount (device->disk);
|
||||
|
@ -465,17 +465,18 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int (*hook) (const char *filename, struct grub_fat_dir_entry *dir);
|
||||
static grub_err_t
|
||||
grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
|
||||
int (*hook) (const char *filename,
|
||||
struct grub_fat_dir_entry *dir))
|
||||
int (*_hook) (const char *filename, struct grub_fat_dir_entry *dir))
|
||||
{
|
||||
struct grub_fat_dir_entry dir;
|
||||
char *filename, *filep = 0;
|
||||
grub_uint16_t *unibuf;
|
||||
int slot = -1, slots = -1;
|
||||
int checksum = -1;
|
||||
grub_ssize_t offset = -sizeof(dir);
|
||||
grub_ssize_t offset;
|
||||
hook = _hook;
|
||||
|
||||
if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY))
|
||||
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
||||
@ -483,19 +484,17 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
|
||||
/* Allocate space enough to hold a long name. */
|
||||
filename = grub_malloc (0x40 * 13 * 4 + 1);
|
||||
unibuf = (grub_uint16_t *) grub_malloc (0x40 * 13 * 2);
|
||||
if (! filename || ! unibuf)
|
||||
{
|
||||
if (! filename || ! unibuf) {
|
||||
grub_free (filename);
|
||||
grub_free (unibuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
unsigned i;
|
||||
for (offset = 0;;offset+= sizeof (dir)) {
|
||||
unsigned int i;
|
||||
|
||||
/* Adjust the offset. */
|
||||
offset += sizeof (dir);
|
||||
//offset += sizeof (dir);
|
||||
|
||||
/* Read a directory entry. */
|
||||
if ((grub_fat_read_data (disk, data, 0,
|
||||
@ -597,23 +596,12 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static struct grub_fat_data *data;
|
||||
static char *dirname, *dirp;
|
||||
static int call_hook;
|
||||
static int found = 0;
|
||||
|
||||
/* Find the underlying directory or file in PATH and return the
|
||||
next path. If there is no next path or an error occurs, return NULL.
|
||||
If HOOK is specified, call it with each file name. */
|
||||
static char *
|
||||
grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
|
||||
const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
char *dirname, *dirp;
|
||||
int call_hook;
|
||||
int found = 0;
|
||||
|
||||
auto int iter_hook (const char *filename, struct grub_fat_dir_entry *dir);
|
||||
int iter_hook (const char *filename, struct grub_fat_dir_entry *dir)
|
||||
{
|
||||
static int iter_hook (const char *filename, struct grub_fat_dir_entry *dir) {
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
|
||||
@ -642,6 +630,18 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find the underlying directory or file in PATH and return the
|
||||
next path. If there is no next path or an error occurs, return NULL.
|
||||
If HOOK is specified, call it with each file name. */
|
||||
static char *
|
||||
grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *_data,
|
||||
const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
found = 0;
|
||||
data = _data;
|
||||
|
||||
if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
||||
@ -781,14 +781,8 @@ grub_fat_close (grub_file_t file)
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_fat_label (grub_device_t device, char **label)
|
||||
{
|
||||
struct grub_fat_data *data;
|
||||
grub_disk_t disk = device->disk;
|
||||
|
||||
auto int iter_hook (const char *filename, struct grub_fat_dir_entry *dir);
|
||||
int iter_hook (const char *filename, struct grub_fat_dir_entry *dir)
|
||||
static char **label;
|
||||
static int iter_hook2 (const char *filename, struct grub_fat_dir_entry *dir)
|
||||
{
|
||||
if (dir->attr == GRUB_FAT_ATTR_VOLUME_ID)
|
||||
{
|
||||
@ -797,6 +791,12 @@ grub_fat_label (grub_device_t device, char **label)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static grub_err_t
|
||||
grub_fat_label (grub_device_t device, char **_label)
|
||||
{
|
||||
struct grub_fat_data *data;
|
||||
grub_disk_t disk = device->disk;
|
||||
label = _label;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
@ -812,7 +812,7 @@ grub_fat_label (grub_device_t device, char **label)
|
||||
|
||||
*label = 0;
|
||||
|
||||
grub_fat_iterate_dir (disk, data, iter_hook);
|
||||
grub_fat_iterate_dir (disk, data, iter_hook2);
|
||||
|
||||
fail:
|
||||
|
||||
|
@ -23,67 +23,20 @@
|
||||
#include <grub/disk.h>
|
||||
#include <grub/fshelp.h>
|
||||
|
||||
#define free_node(x) {if (x!=rootnode && x!=currroot)grub_free(x);}
|
||||
|
||||
/* Lookup the node PATH. The node ROOTNODE describes the root of the
|
||||
directory tree. The node found is returned in FOUNDNODE, which is
|
||||
either a ROOTNODE or a new malloc'ed node. ITERATE_DIR is used to
|
||||
iterate over all directory entries in the current node.
|
||||
READ_SYMLINK is used to read the symlink if a node is a symlink.
|
||||
EXPECTTYPE is the type node that is expected by the called, an
|
||||
error is generated if the node is not of the expected type. Make
|
||||
sure you use the NESTED_FUNC_ATTR macro for HOOK, this is required
|
||||
because GCC has a nasty bug when using regparm=3. */
|
||||
grub_err_t
|
||||
grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
|
||||
grub_fshelp_node_t *foundnode,
|
||||
int (*iterate_dir) (grub_fshelp_node_t dir,
|
||||
int NESTED_FUNC_ATTR (*hook)
|
||||
(const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)),
|
||||
char *(*read_symlink) (grub_fshelp_node_t node),
|
||||
enum grub_fshelp_filetype expecttype)
|
||||
{
|
||||
grub_err_t err;
|
||||
enum grub_fshelp_filetype foundtype = GRUB_FSHELP_DIR;
|
||||
int symlinknest = 0;
|
||||
static grub_fshelp_node_t currnode;
|
||||
static grub_fshelp_node_t oldnode;
|
||||
static enum grub_fshelp_filetype foundtype = GRUB_FSHELP_DIR;
|
||||
static int symlinknest = 0;
|
||||
static grub_fshelp_node_t rootnode;
|
||||
static enum grub_fshelp_filetype type = GRUB_FSHELP_DIR;
|
||||
static char fpath[4096]; //grub_strlen (currpath) + 1];
|
||||
static char *name;
|
||||
|
||||
auto grub_err_t NESTED_FUNC_ATTR find_file (const char *currpath,
|
||||
grub_fshelp_node_t currroot,
|
||||
grub_fshelp_node_t *currfound);
|
||||
|
||||
grub_err_t NESTED_FUNC_ATTR find_file (const char *currpath,
|
||||
grub_fshelp_node_t currroot,
|
||||
grub_fshelp_node_t *currfound)
|
||||
{
|
||||
char fpath[grub_strlen (currpath) + 1];
|
||||
char *name = fpath;
|
||||
char *next;
|
||||
// unsigned int pos = 0;
|
||||
enum grub_fshelp_filetype type = GRUB_FSHELP_DIR;
|
||||
grub_fshelp_node_t currnode = currroot;
|
||||
grub_fshelp_node_t oldnode = currroot;
|
||||
|
||||
auto int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node);
|
||||
|
||||
auto void free_node (grub_fshelp_node_t node);
|
||||
|
||||
void free_node (grub_fshelp_node_t node)
|
||||
{
|
||||
if (node != rootnode && node != currroot)
|
||||
grub_free (node);
|
||||
}
|
||||
|
||||
int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)
|
||||
{
|
||||
if (filetype == GRUB_FSHELP_UNKNOWN ||
|
||||
(grub_strcmp (name, filename) &&
|
||||
(! (filetype & GRUB_FSHELP_CASE_INSENSITIVE) ||
|
||||
grub_strncasecmp (name, filename, GRUB_LONG_MAX))))
|
||||
static inline int iterate (const char *filename, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node) {
|
||||
if (filetype == GRUB_FSHELP_UNKNOWN || (grub_strcmp (name, filename) &&
|
||||
(! (filetype & GRUB_FSHELP_CASE_INSENSITIVE) || grub_strncasecmp (name, filename, GRUB_LONG_MAX))))
|
||||
{
|
||||
grub_free (node);
|
||||
return 0;
|
||||
@ -95,7 +48,19 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
|
||||
currnode = node;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static char *(*read_symlink) (grub_fshelp_node_t node);
|
||||
static int (*iterate_dir) (grub_fshelp_node_t dir, int NESTED_FUNC_ATTR (*hook)
|
||||
(const char *filename, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node));
|
||||
|
||||
static grub_err_t find_file (const char *currpath, grub_fshelp_node_t currroot, grub_fshelp_node_t *currfound) {
|
||||
name = fpath;
|
||||
char *next;
|
||||
// unsigned int pos = 0;
|
||||
type = GRUB_FSHELP_DIR;
|
||||
currnode = currroot;
|
||||
oldnode = currroot;
|
||||
|
||||
grub_strncpy (fpath, currpath, grub_strlen (currpath) + 1);
|
||||
|
||||
@ -115,8 +80,7 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
|
||||
|
||||
/* Extract the actual part from the pathname. */
|
||||
next = grub_strchr (name, '/');
|
||||
if (next)
|
||||
{
|
||||
if (next) {
|
||||
/* Remove all leading slashes. */
|
||||
while (*next == '/')
|
||||
*(next++) = '\0';
|
||||
@ -124,8 +88,7 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
|
||||
|
||||
/* At this point it is expected that the current node is a
|
||||
directory, check if this is true. */
|
||||
if (type != GRUB_FSHELP_DIR)
|
||||
{
|
||||
if (type != GRUB_FSHELP_DIR) {
|
||||
free_node (currnode);
|
||||
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
||||
}
|
||||
@ -198,6 +161,34 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
|
||||
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
|
||||
}
|
||||
|
||||
/* Lookup the node PATH. The node ROOTNODE describes the root of the
|
||||
directory tree. The node found is returned in FOUNDNODE, which is
|
||||
either a ROOTNODE or a new malloc'ed node. ITERATE_DIR is used to
|
||||
iterate over all directory entries in the current node.
|
||||
READ_SYMLINK is used to read the symlink if a node is a symlink.
|
||||
EXPECTTYPE is the type node that is expected by the called, an
|
||||
error is generated if the node is not of the expected type. Make
|
||||
sure you use the NESTED_FUNC_ATTR macro for HOOK, this is required
|
||||
because GCC has a nasty bug when using regparm=3. */
|
||||
grub_err_t
|
||||
grub_fshelp_find_file (const char *path, grub_fshelp_node_t _rootnode,
|
||||
grub_fshelp_node_t *foundnode,
|
||||
int (*_iterate_dir) (grub_fshelp_node_t dir,
|
||||
int NESTED_FUNC_ATTR (*hook)
|
||||
(const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)),
|
||||
char *(*_read_symlink) (grub_fshelp_node_t node),
|
||||
enum grub_fshelp_filetype expecttype)
|
||||
{
|
||||
grub_err_t err;
|
||||
symlinknest = 0;
|
||||
rootnode = _rootnode;
|
||||
iterate_dir = _iterate_dir;
|
||||
read_symlink = _read_symlink;
|
||||
|
||||
foundtype = GRUB_FSHELP_DIR;
|
||||
|
||||
if (!path || path[0] != '/')
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");
|
||||
@ -293,23 +284,20 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node,
|
||||
return len;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
grub_fshelp_log2blksize (unsigned int blksize, unsigned int *pow)
|
||||
{
|
||||
int mod;
|
||||
unsigned int grub_fshelp_log2blksize (unsigned int blksize, unsigned int *pow) {
|
||||
int mod;
|
||||
|
||||
*pow = 0;
|
||||
while (blksize > 1)
|
||||
{
|
||||
mod = blksize - ((blksize >> 1) << 1);
|
||||
blksize >>= 1;
|
||||
*pow = 0;
|
||||
while (blksize > 1) {
|
||||
mod = blksize - ((blksize >> 1) << 1);
|
||||
blksize >>= 1;
|
||||
|
||||
/* Check if it really is a power of two. */
|
||||
if (mod)
|
||||
return grub_error (GRUB_ERR_BAD_NUMBER,
|
||||
"the blocksize is not a power of two");
|
||||
(*pow)++;
|
||||
}
|
||||
/* Check if it really is a power of two. */
|
||||
if (mod)
|
||||
return grub_error (GRUB_ERR_BAD_NUMBER,
|
||||
"the blocksize is not a power of two");
|
||||
(*pow)++;
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
/* HFS is documented at
|
||||
http://developer.apple.com/documentation/mac/Files/Files-2.html */
|
||||
|
||||
#include <string.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
@ -723,50 +724,37 @@ static int
|
||||
grub_hfs_find_node (struct grub_hfs_data *data, char *key,
|
||||
grub_uint32_t idx, int type, char *datar, int datalen)
|
||||
{
|
||||
int found = -1;
|
||||
int isleaf = 0;
|
||||
int done = 0;
|
||||
int found = -1;
|
||||
int isleaf = 0;
|
||||
int done = 0;
|
||||
|
||||
auto int node_found (struct grub_hfs_node *, struct grub_hfs_record *);
|
||||
int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec) {
|
||||
int cmp;
|
||||
if (type == 0)
|
||||
cmp = grub_hfs_cmp_catkeys (rec->key, (void *) key);
|
||||
else cmp = grub_hfs_cmp_extkeys (rec->key, (void *) key);
|
||||
|
||||
int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec)
|
||||
{
|
||||
int cmp = 1;
|
||||
/* If the key is smaller or equal to the current node, mark the
|
||||
entry. In case of a non-leaf mode it will be used to lookup
|
||||
the rest of the tree. */
|
||||
if (cmp <= 0) {
|
||||
grub_uint32_t *node = (grub_uint32_t *) rec->data;
|
||||
found = grub_be_to_cpu32 (*node);
|
||||
} else return 1; /* The key can not be found in the tree. */
|
||||
|
||||
if (type == 0)
|
||||
cmp = grub_hfs_cmp_catkeys (rec->key, (void *) key);
|
||||
else
|
||||
cmp = grub_hfs_cmp_extkeys (rec->key, (void *) key);
|
||||
|
||||
/* If the key is smaller or equal to the current node, mark the
|
||||
entry. In case of a non-leaf mode it will be used to lookup
|
||||
the rest of the tree. */
|
||||
if (cmp <= 0)
|
||||
{
|
||||
grub_uint32_t *node = (grub_uint32_t *) rec->data;
|
||||
found = grub_be_to_cpu32 (*node);
|
||||
/* Check if this node is a leaf node. */
|
||||
if (hnd->type == GRUB_HFS_NODE_LEAF) {
|
||||
isleaf = 1;
|
||||
/* Found it!!!! */
|
||||
if (cmp == 0) {
|
||||
done = 1;
|
||||
memmove (datar, rec->data,
|
||||
rec->datalen < datalen ? rec->datalen : datalen);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else /* The key can not be found in the tree. */
|
||||
return 1;
|
||||
|
||||
/* Check if this node is a leaf node. */
|
||||
if (hnd->type == GRUB_HFS_NODE_LEAF)
|
||||
{
|
||||
isleaf = 1;
|
||||
|
||||
/* Found it!!!! */
|
||||
if (cmp == 0)
|
||||
{
|
||||
done = 1;
|
||||
|
||||
grub_memcpy (datar, rec->data,
|
||||
rec->datalen < datalen ? rec->datalen : datalen);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -861,64 +861,47 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ntfs_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
struct grub_ntfs_data *data = 0;
|
||||
struct grub_fshelp_node *fdiro = 0;
|
||||
static int (*hook) (const char *filename, const struct grub_dirhook_info *info);
|
||||
|
||||
auto int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node);
|
||||
|
||||
int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
data = grub_ntfs_mount (device->disk);
|
||||
if (!data)
|
||||
goto fail;
|
||||
|
||||
grub_fshelp_find_file (path, &data->cmft, &fdiro, grub_ntfs_iterate_dir,
|
||||
0, GRUB_FSHELP_DIR);
|
||||
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
grub_ntfs_iterate_dir (fdiro, iterate);
|
||||
|
||||
fail:
|
||||
if ((fdiro) && (fdiro != &data->cmft))
|
||||
{
|
||||
free_file (fdiro);
|
||||
grub_free (fdiro);
|
||||
}
|
||||
if (data)
|
||||
{
|
||||
free_file (&data->mmft);
|
||||
free_file (&data->cmft);
|
||||
grub_free (data);
|
||||
}
|
||||
|
||||
grub_dl_unref (my_mod);
|
||||
|
||||
return grub_errno;
|
||||
static int iterate (const char *filename, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node) {
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ntfs_open (grub_file_t file, const char *name)
|
||||
static grub_err_t grub_ntfs_dir (grub_device_t device, const char *path,
|
||||
int (*_hook) (const char *filename, const struct grub_dirhook_info *info))
|
||||
{
|
||||
struct grub_ntfs_data *data = 0;
|
||||
struct grub_fshelp_node *fdiro = 0;
|
||||
|
||||
hook = _hook;
|
||||
grub_dl_ref (my_mod);
|
||||
data = grub_ntfs_mount (device->disk);
|
||||
if (!data)
|
||||
goto fail;
|
||||
grub_fshelp_find_file (path, &data->cmft, &fdiro, grub_ntfs_iterate_dir,
|
||||
0, GRUB_FSHELP_DIR);
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
grub_ntfs_iterate_dir (fdiro, iterate);
|
||||
fail:
|
||||
if ((fdiro) && (fdiro != &data->cmft)) {
|
||||
free_file (fdiro);
|
||||
grub_free (fdiro);
|
||||
}
|
||||
if (data) {
|
||||
free_file (&data->mmft);
|
||||
free_file (&data->cmft);
|
||||
grub_free (data);
|
||||
}
|
||||
grub_dl_unref (my_mod);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t grub_ntfs_open (grub_file_t file, const char *name) {
|
||||
struct grub_ntfs_data *data = 0;
|
||||
struct grub_fshelp_node *mft = 0;
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
# define GRUB_HEXDUMP
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
@ -1255,30 +1256,27 @@ grub_reiserfs_close (grub_file_t file)
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int (*hook) (const char *filename, const struct grub_dirhook_info *info);
|
||||
static int iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype, grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
||||
/* Call HOOK with each file under DIR. */
|
||||
static grub_err_t
|
||||
grub_reiserfs_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
int (*_hook) (const char *filename, const struct grub_dirhook_info *info))
|
||||
{
|
||||
struct grub_reiserfs_data *data = 0;
|
||||
struct grub_fshelp_node root, *found;
|
||||
struct grub_reiserfs_key root_key;
|
||||
hook = _hook;
|
||||
|
||||
auto int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node);
|
||||
|
||||
int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
grub_dl_ref (my_mod);
|
||||
data = grub_reiserfs_mount (device->disk);
|
||||
if (! data)
|
||||
|
@ -910,29 +910,25 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int (*hook) (const char *filename, const struct grub_dirhook_info *info);
|
||||
static int iterate (const char *filename, enum grub_fshelp_filetype filetype, grub_fshelp_node_t node) {
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_udf_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
int (*_hook) (const char *filename, const struct grub_dirhook_info *info))
|
||||
{
|
||||
struct grub_udf_data *data = 0;
|
||||
struct grub_fshelp_node rootnode;
|
||||
struct grub_fshelp_node *foundnode;
|
||||
|
||||
auto int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node);
|
||||
|
||||
int NESTED_FUNC_ATTR iterate (const char *filename,
|
||||
enum grub_fshelp_filetype filetype,
|
||||
grub_fshelp_node_t node)
|
||||
{
|
||||
struct grub_dirhook_info info;
|
||||
grub_memset (&info, 0, sizeof (info));
|
||||
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
|
||||
grub_free (node);
|
||||
return hook (filename, &info);
|
||||
}
|
||||
hook = _hook;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,47 +22,16 @@
|
||||
#include <config.h>
|
||||
#include <grub/symbol.h>
|
||||
|
||||
/* NLS can be disabled through the configure --disable-nls option. */
|
||||
#if (defined(ENABLE_NLS) && ENABLE_NLS) || !defined (GRUB_UTIL)
|
||||
|
||||
extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s);
|
||||
|
||||
# ifdef GRUB_UTIL
|
||||
|
||||
# include <locale.h>
|
||||
# include <libintl.h>
|
||||
|
||||
# endif /* GRUB_UTIL */
|
||||
|
||||
#else /* ! (defined(ENABLE_NLS) && ENABLE_NLS) */
|
||||
|
||||
/* Disabled NLS.
|
||||
The casts to 'const char *' serve the purpose of producing warnings
|
||||
for invalid uses of the value returned from these functions.
|
||||
On pre-ANSI systems without 'const', the config.h file is supposed to
|
||||
contain "#define const". */
|
||||
static inline const char * __attribute__ ((always_inline))
|
||||
gettext (const char *str)
|
||||
{
|
||||
gettext (const char *str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
static inline const char * __attribute__ ((always_inline))
|
||||
_ (const char *str)
|
||||
{
|
||||
return gettext(str);
|
||||
}
|
||||
#else
|
||||
static inline const char * __attribute__ ((always_inline))
|
||||
_ (const char *str)
|
||||
{
|
||||
return grub_gettext(str);
|
||||
}
|
||||
#endif /* GRUB_UTIL */
|
||||
|
||||
#define N_(str) str
|
||||
|
||||
#endif /* GRUB_I18N_H */
|
||||
#endif
|
||||
|
@ -26,144 +26,119 @@
|
||||
#include <grub/env.h>
|
||||
#include <grub/partition.h>
|
||||
|
||||
grub_device_t
|
||||
grub_device_open (const char *name)
|
||||
{
|
||||
grub_disk_t disk = 0;
|
||||
grub_device_t dev = 0;
|
||||
grub_device_t grub_device_open (const char *name) {
|
||||
grub_disk_t disk = 0;
|
||||
grub_device_t dev = 0;
|
||||
|
||||
if (! name)
|
||||
{
|
||||
name = grub_env_get ("root");
|
||||
if (*name == '\0')
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "no device is set");
|
||||
goto fail;
|
||||
if (!name) {
|
||||
name = grub_env_get ("root");
|
||||
if (*name == '\0') {
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "no device is set");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dev = grub_malloc (sizeof (*dev));
|
||||
if (! dev)
|
||||
goto fail;
|
||||
dev = grub_malloc (sizeof (*dev));
|
||||
if (! dev)
|
||||
goto fail;
|
||||
|
||||
/* Try to open a disk. */
|
||||
disk = grub_disk_open (name);
|
||||
if (! disk)
|
||||
goto fail;
|
||||
/* Try to open a disk. */
|
||||
disk = grub_disk_open (name);
|
||||
if (! disk)
|
||||
goto fail;
|
||||
|
||||
dev->disk = disk;
|
||||
dev->net = 0; /* FIXME */
|
||||
dev->disk = disk;
|
||||
dev->net = 0; /* FIXME */
|
||||
|
||||
return dev;
|
||||
return dev;
|
||||
|
||||
fail:
|
||||
if (disk)
|
||||
grub_disk_close (disk);
|
||||
fail:
|
||||
if (disk)
|
||||
grub_disk_close (disk);
|
||||
|
||||
grub_free (dev);
|
||||
grub_free (dev);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_device_close (grub_device_t device)
|
||||
{
|
||||
if (device->disk)
|
||||
grub_disk_close (device->disk);
|
||||
|
||||
grub_free (device);
|
||||
|
||||
return grub_errno;
|
||||
grub_err_t grub_device_close (grub_device_t device) {
|
||||
if (device->disk)
|
||||
grub_disk_close (device->disk);
|
||||
grub_free (device);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
int
|
||||
grub_device_iterate (int (*hook) (const char *name))
|
||||
{
|
||||
auto int iterate_disk (const char *disk_name);
|
||||
auto int iterate_partition (grub_disk_t disk,
|
||||
const grub_partition_t partition);
|
||||
/* unnested code */
|
||||
|
||||
struct part_ent
|
||||
{
|
||||
struct part_ent *next;
|
||||
char *name;
|
||||
} *ents;
|
||||
static struct part_ent {
|
||||
struct part_ent *next;
|
||||
char *name;
|
||||
} *ents;
|
||||
|
||||
int iterate_disk (const char *disk_name)
|
||||
{
|
||||
grub_device_t dev;
|
||||
static int iterate_partition (grub_disk_t disk, const grub_partition_t partition) {
|
||||
struct part_ent *p;
|
||||
char *part_name;
|
||||
|
||||
if (hook (disk_name))
|
||||
return 1;
|
||||
p = grub_malloc (sizeof (*p));
|
||||
if (!p) return 1;
|
||||
|
||||
dev = grub_device_open (disk_name);
|
||||
if (! dev)
|
||||
{
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return 0;
|
||||
part_name = grub_partition_get_name (partition);
|
||||
if (!part_name) {
|
||||
grub_free (p);
|
||||
return 1;
|
||||
}
|
||||
p->name = grub_xasprintf ("%s,%s", disk->name, part_name);
|
||||
grub_free (part_name);
|
||||
if (!p->name) {
|
||||
grub_free (p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dev->disk)
|
||||
{
|
||||
struct part_ent *p;
|
||||
int ret = 0;
|
||||
p->next = ents;
|
||||
ents = p;
|
||||
|
||||
ents = NULL;
|
||||
(void) grub_partition_iterate (dev->disk, iterate_partition);
|
||||
grub_device_close (dev);
|
||||
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
p = ents;
|
||||
while (p != NULL)
|
||||
{
|
||||
struct part_ent *next = p->next;
|
||||
|
||||
if (!ret)
|
||||
ret = hook (p->name);
|
||||
grub_free (p->name);
|
||||
grub_free (p);
|
||||
p = next;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
grub_device_close (dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
|
||||
{
|
||||
struct part_ent *p;
|
||||
char *part_name;
|
||||
|
||||
p = grub_malloc (sizeof (*p));
|
||||
if (!p)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
part_name = grub_partition_get_name (partition);
|
||||
if (!part_name)
|
||||
{
|
||||
grub_free (p);
|
||||
return 1;
|
||||
}
|
||||
p->name = grub_xasprintf ("%s,%s", disk->name, part_name);
|
||||
grub_free (part_name);
|
||||
if (!p->name)
|
||||
{
|
||||
grub_free (p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p->next = ents;
|
||||
ents = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Only disk devices are supported at the moment. */
|
||||
return grub_disk_dev_iterate (iterate_disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iterate_disk (const char *disk_name) {
|
||||
grub_device_t dev;
|
||||
|
||||
if (iterate_disk (disk_name))
|
||||
return 1;
|
||||
|
||||
dev = grub_device_open (disk_name);
|
||||
if (! dev) {
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dev->disk) {
|
||||
struct part_ent *p;
|
||||
int ret = 0;
|
||||
|
||||
ents = NULL;
|
||||
(void) grub_partition_iterate (dev->disk, iterate_partition);
|
||||
grub_device_close (dev);
|
||||
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
p = ents;
|
||||
while (p != NULL) {
|
||||
struct part_ent *next = p->next;
|
||||
|
||||
if (!ret)
|
||||
ret = iterate_disk (p->name);
|
||||
grub_free (p->name);
|
||||
grub_free (p);
|
||||
p = next;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
grub_device_close (dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grub_device_iterate (int (*hook) (const char *name)) {
|
||||
/* Only disk devices are supported at the moment. */
|
||||
return grub_disk_dev_iterate (iterate_disk);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ grub_error (grub_err_t n, const char *fmt, ...)
|
||||
grub_errno = n;
|
||||
|
||||
va_start (ap, fmt);
|
||||
grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap);
|
||||
grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return n;
|
||||
@ -59,7 +59,7 @@ grub_fatal (const char *fmt, ...)
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, fmt);
|
||||
grub_vprintf (_(fmt), ap);
|
||||
grub_vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
grub_abort ();
|
||||
|
@ -28,24 +28,17 @@
|
||||
#include <grub/term.h>
|
||||
|
||||
grub_fs_t grub_fs_list = 0;
|
||||
|
||||
grub_fs_autoload_hook_t grub_fs_autoload_hook = 0;
|
||||
|
||||
grub_fs_t
|
||||
grub_fs_probe (grub_device_t device)
|
||||
{
|
||||
static int dummy_func (const char *filename __attribute__ ((unused)),
|
||||
const struct grub_dirhook_info *info __attribute__ ((unused))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_fs_t grub_fs_probe (grub_device_t device) {
|
||||
grub_fs_t p;
|
||||
auto int dummy_func (const char *filename,
|
||||
const struct grub_dirhook_info *info);
|
||||
|
||||
int dummy_func (const char *filename __attribute__ ((unused)),
|
||||
const struct grub_dirhook_info *info __attribute__ ((unused)))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (device->disk)
|
||||
{
|
||||
if (device->disk) {
|
||||
/* Make it sure not to have an infinite recursive calls. */
|
||||
static int count = 0;
|
||||
|
||||
|
@ -21,103 +21,66 @@
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
static int
|
||||
grub_vsnprintf_real (char *str, grub_size_t n, const char *fmt, va_list args);
|
||||
|
||||
static int
|
||||
grub_iswordseparator (int c)
|
||||
{
|
||||
return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&');
|
||||
static int grub_iswordseparator (int c) {
|
||||
return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&');
|
||||
}
|
||||
|
||||
/* grub_gettext_dummy is not translating anything. */
|
||||
static const char *
|
||||
grub_gettext_dummy (const char *s)
|
||||
{
|
||||
return s;
|
||||
#define grub_gettext(x) (x)
|
||||
|
||||
void * grub_memmove (void *dest, const void *src, grub_size_t n) {
|
||||
char *d = (char *) dest;
|
||||
const char *s = (const char *) src;
|
||||
|
||||
if (d < s) {
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
} else {
|
||||
d += n;
|
||||
s += n;
|
||||
while (n--)
|
||||
*--d = *--s;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
const char* (*grub_gettext) (const char *s) = grub_gettext_dummy;
|
||||
|
||||
void *
|
||||
grub_memmove (void *dest, const void *src, grub_size_t n)
|
||||
{
|
||||
char *d = (char *) dest;
|
||||
const char *s = (const char *) src;
|
||||
|
||||
if (d < s)
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
else
|
||||
{
|
||||
d += n;
|
||||
s += n;
|
||||
|
||||
while (n--)
|
||||
*--d = *--s;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
#ifndef APPLE_CC
|
||||
void *memmove (void *dest, const void *src, grub_size_t n)
|
||||
__attribute__ ((alias ("grub_memmove")));
|
||||
/* GCC emits references to memcpy() for struct copies etc. */
|
||||
void *memcpy (void *dest, const void *src, grub_size_t n)
|
||||
__attribute__ ((alias ("grub_memmove")));
|
||||
#else
|
||||
void *memcpy (void *dest, const void *src, grub_size_t n)
|
||||
{
|
||||
return grub_memmove (dest, src, n);
|
||||
}
|
||||
void *memmove (void *dest, const void *src, grub_size_t n)
|
||||
{
|
||||
return grub_memmove (dest, src, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *
|
||||
grub_strcpy (char *dest, const char *src)
|
||||
{
|
||||
char * grub_strcpy (char *dest, const char *src) {
|
||||
char *p = dest;
|
||||
|
||||
while ((*p++ = *src++) != '\0')
|
||||
;
|
||||
|
||||
while ((*p++ = *src++) != '\0') ;
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_strncpy (char *dest, const char *src, int c)
|
||||
{
|
||||
char * grub_strncpy (char *dest, const char *src, int c) {
|
||||
char *p = dest;
|
||||
|
||||
while ((*p++ = *src++) != '\0' && --c)
|
||||
;
|
||||
|
||||
while ((*p++ = *src++) != '\0' && --c) ;
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_stpcpy (char *dest, const char *src)
|
||||
{
|
||||
char * grub_stpcpy (char *dest, const char *src) {
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
|
||||
do
|
||||
*d++ = *s;
|
||||
while (*s++ != '\0');
|
||||
do *d++ = *s; while (*s++ != '\0');
|
||||
|
||||
return d - 1;
|
||||
}
|
||||
|
||||
int
|
||||
grub_printf (const char *fmt, ...)
|
||||
int grub_printf (const char *fmt, ...) {
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = grub_vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int grub_printf_ (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
@ -129,45 +92,10 @@ grub_printf (const char *fmt, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
grub_printf_ (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = grub_vprintf (_(fmt), ap);
|
||||
va_end (ap);
|
||||
|
||||
return ret;
|
||||
int grub_puts_ (const char *s) {
|
||||
return grub_puts (s);
|
||||
}
|
||||
|
||||
int
|
||||
grub_puts_ (const char *s)
|
||||
{
|
||||
return grub_puts (_(s));
|
||||
}
|
||||
|
||||
#if defined (APPLE_CC) && ! defined (GRUB_UTIL)
|
||||
int
|
||||
grub_err_printf (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = grub_vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ! defined (APPLE_CC) && ! defined (GRUB_UTIL)
|
||||
int grub_err_printf (const char *fmt, ...)
|
||||
__attribute__ ((alias("grub_printf")));
|
||||
#endif
|
||||
|
||||
void
|
||||
grub_real_dprintf (const char *file, const int line, const char *condition,
|
||||
const char *fmt, ...)
|
||||
@ -190,8 +118,7 @@ grub_real_dprintf (const char *file, const int line, const char *condition,
|
||||
|
||||
#define PREALLOC_SIZE 255
|
||||
|
||||
int
|
||||
grub_vprintf (const char *fmt, va_list args)
|
||||
int grub_vprintf (const char *fmt, va_list args)
|
||||
{
|
||||
grub_size_t s;
|
||||
static char buf[PREALLOC_SIZE + 1];
|
||||
@ -223,46 +150,30 @@ grub_vprintf (const char *fmt, va_list args)
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
grub_memcmp (const void *s1, const void *s2, grub_size_t n)
|
||||
{
|
||||
const char *t1 = s1;
|
||||
const char *t2 = s2;
|
||||
int grub_memcmp (const void *s1, const void *s2, grub_size_t n) {
|
||||
const char *t1 = s1;
|
||||
const char *t2 = s2;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if (*t1 != *t2)
|
||||
return (int) *t1 - (int) *t2;
|
||||
while (n--) {
|
||||
if (*t1 != *t2)
|
||||
return (int) *t1 - (int) *t2;
|
||||
t1++;
|
||||
t2++;
|
||||
}
|
||||
|
||||
t1++;
|
||||
t2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#ifndef APPLE_CC
|
||||
int memcmp (const void *s1, const void *s2, grub_size_t n)
|
||||
__attribute__ ((alias ("grub_memcmp")));
|
||||
#else
|
||||
int memcmp (const void *s1, const void *s2, grub_size_t n)
|
||||
{
|
||||
return grub_memcmp (s1, s2, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
grub_strcmp (const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 && *s2)
|
||||
{
|
||||
if (*s1 != *s2)
|
||||
break;
|
||||
int grub_strcmp (const char *s1, const char *s2) {
|
||||
while (*s1 && *s2) {
|
||||
if (*s1 != *s2)
|
||||
break;
|
||||
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (int) *s1 - (int) *s2;
|
||||
return (int) *s1 - (int) *s2;
|
||||
}
|
||||
|
||||
int
|
||||
@ -283,32 +194,23 @@ grub_strncmp (const char *s1, const char *s2, grub_size_t n)
|
||||
return (int) *s1 - (int) *s2;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_strchr (const char *s, int c)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (*s == c)
|
||||
return (char *) s;
|
||||
}
|
||||
while (*s++);
|
||||
|
||||
return 0;
|
||||
char * grub_strchr (const char *s, int c) {
|
||||
do {
|
||||
if (*s == c)
|
||||
return (char *) s;
|
||||
} while (*s++);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_strrchr (const char *s, int c)
|
||||
{
|
||||
char *p = NULL;
|
||||
char * grub_strrchr (const char *s, int c) {
|
||||
char *p = NULL;
|
||||
|
||||
do
|
||||
{
|
||||
if (*s == c)
|
||||
p = (char *) s;
|
||||
}
|
||||
while (*s++);
|
||||
do {
|
||||
if (*s == c)
|
||||
p = (char *) s;
|
||||
} while (*s++);
|
||||
|
||||
return p;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Copied from gnulib.
|
||||
@ -523,6 +425,8 @@ grub_strndup (const char *s, grub_size_t n)
|
||||
void *
|
||||
grub_memset (void *s, int c, grub_size_t len)
|
||||
{
|
||||
return memset(s,c,len);
|
||||
#if 0
|
||||
void *p = s;
|
||||
grub_uint8_t pattern8 = c;
|
||||
|
||||
@ -534,7 +438,7 @@ grub_memset (void *s, int c, grub_size_t len)
|
||||
for (i = 0; i < sizeof (unsigned long); i++)
|
||||
patternl |= ((unsigned long) pattern8) << (8 * i);
|
||||
|
||||
while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) - 1)))
|
||||
while (len > 0 && (((grub_addr_t) p) & (sizeof (void *) - 1)))
|
||||
{
|
||||
*(grub_uint8_t *) p = pattern8;
|
||||
p = (grub_uint8_t *) p + 1;
|
||||
@ -556,16 +460,8 @@ grub_memset (void *s, int c, grub_size_t len)
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
#ifndef APPLE_CC
|
||||
void *memset (void *s, int c, grub_size_t n)
|
||||
__attribute__ ((alias ("grub_memset")));
|
||||
#else
|
||||
void *memset (void *s, int c, grub_size_t n)
|
||||
{
|
||||
return grub_memset (s, c, n);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
grub_size_t
|
||||
grub_strlen (const char *s)
|
||||
@ -679,42 +575,29 @@ grub_lltoa (char *str, int c, unsigned long long n)
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list args)
|
||||
{
|
||||
#if 1
|
||||
static grub_size_t count, max_len;
|
||||
static char *str;
|
||||
|
||||
static void write_char(char ch) {
|
||||
if (count++<max_len) *str++ = ch;
|
||||
}
|
||||
//#define write_str(s) { while(*s) { write_char (*s); s++; } }
|
||||
static int write_str(char *s) {
|
||||
write_char (*s);s++;
|
||||
}
|
||||
#define write_fill(ch,n) {int i;for(i=0;i<n;i++)write_char(ch); }
|
||||
|
||||
int grub_vsnprintf_real (char *_str, grub_size_t _max_len, const char *fmt, va_list args) {
|
||||
char c;
|
||||
grub_size_t count = 0;
|
||||
auto void write_char (unsigned char ch);
|
||||
auto void write_str (const char *s);
|
||||
auto void write_fill (const char ch, int n);
|
||||
str = _str;
|
||||
max_len = _max_len;
|
||||
count = 0;
|
||||
|
||||
void write_char (unsigned char ch)
|
||||
{
|
||||
if (count < max_len)
|
||||
*str++ = ch;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
void write_str (const char *s)
|
||||
{
|
||||
while (*s)
|
||||
write_char (*s++);
|
||||
}
|
||||
|
||||
void write_fill (const char ch, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
write_char (ch);
|
||||
}
|
||||
|
||||
while ((c = *fmt++) != 0)
|
||||
{
|
||||
if (c != '%')
|
||||
while ((c = *fmt++) != 0) {
|
||||
if (c != '%') {
|
||||
write_char (c);
|
||||
else
|
||||
{
|
||||
} else {
|
||||
char tmp[32];
|
||||
char *p;
|
||||
unsigned int format1 = 0;
|
||||
@ -737,8 +620,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list ar
|
||||
while (*p && grub_isdigit (*p))
|
||||
p++;
|
||||
|
||||
if (p > fmt)
|
||||
{
|
||||
if (p > fmt) {
|
||||
char s[p - fmt + 1];
|
||||
grub_strncpy (s, fmt, p - fmt);
|
||||
s[p - fmt] = 0;
|
||||
@ -748,15 +630,13 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list ar
|
||||
fmt = p;
|
||||
}
|
||||
|
||||
if (*p && *p == '.')
|
||||
{
|
||||
if (*p && *p == '.') {
|
||||
p++;
|
||||
fmt++;
|
||||
while (*p && grub_isdigit (*p))
|
||||
p++;
|
||||
|
||||
if (p > fmt)
|
||||
{
|
||||
if (p > fmt) {
|
||||
char fstr[p - fmt + 1];
|
||||
grub_strncpy (fstr, fmt, p - fmt);
|
||||
fstr[p - fmt] = 0;
|
||||
@ -777,58 +657,47 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list ar
|
||||
}
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case 'p':
|
||||
write_str ("0x");
|
||||
c = 'x';
|
||||
longlongfmt |= (sizeof (void *) == sizeof (long long));
|
||||
/* Fall through. */
|
||||
case 'x':
|
||||
case 'u':
|
||||
unsig = 1;
|
||||
/* Fall through. */
|
||||
case 'd':
|
||||
if (longlongfmt)
|
||||
{
|
||||
long long ll;
|
||||
switch (c) {
|
||||
case 'p':
|
||||
write_str ("0x");
|
||||
c = 'x';
|
||||
longlongfmt |= (sizeof (void *) == sizeof (long long));
|
||||
/* Fall through. */
|
||||
case 'x':
|
||||
case 'u':
|
||||
unsig = 1;
|
||||
/* Fall through. */
|
||||
case 'd':
|
||||
if (longlongfmt) {
|
||||
long long ll;
|
||||
|
||||
ll = va_arg (args, long long);
|
||||
grub_lltoa (tmp, c, ll);
|
||||
}
|
||||
else if (longfmt && unsig)
|
||||
{
|
||||
unsigned long l = va_arg (args, unsigned long);
|
||||
grub_lltoa (tmp, c, l);
|
||||
}
|
||||
else if (longfmt)
|
||||
{
|
||||
long l = va_arg (args, long);
|
||||
grub_lltoa (tmp, c, l);
|
||||
}
|
||||
else if (unsig)
|
||||
{
|
||||
unsigned u = va_arg (args, unsigned);
|
||||
grub_lltoa (tmp, c, u);
|
||||
}
|
||||
else
|
||||
{
|
||||
ll = va_arg (args, long long);
|
||||
grub_lltoa (tmp, c, ll);
|
||||
} else if (longfmt && unsig) {
|
||||
unsigned long l = va_arg (args, unsigned long);
|
||||
grub_lltoa (tmp, c, l);
|
||||
} else if (longfmt) {
|
||||
long l = va_arg (args, long);
|
||||
grub_lltoa (tmp, c, l);
|
||||
} else if (unsig) {
|
||||
unsigned u = va_arg (args, unsigned);
|
||||
grub_lltoa (tmp, c, u);
|
||||
} else {
|
||||
n = va_arg (args, int);
|
||||
grub_lltoa (tmp, c, n);
|
||||
}
|
||||
if (! rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
write_str (tmp);
|
||||
if (rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
break;
|
||||
case 'c':
|
||||
n = va_arg (args, int);
|
||||
grub_lltoa (tmp, c, n);
|
||||
}
|
||||
if (! rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
write_str (tmp);
|
||||
if (rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
break;
|
||||
write_char (n & 0xff);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
n = va_arg (args, int);
|
||||
write_char (n & 0xff);
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
case 'C':
|
||||
{
|
||||
grub_uint32_t code = va_arg (args, grub_uint32_t);
|
||||
int shift;
|
||||
@ -912,6 +781,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list ar
|
||||
|
||||
return count;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list ap)
|
||||
@ -983,29 +853,3 @@ grub_abort (void)
|
||||
{
|
||||
grub_printf ("\nAborted.");
|
||||
}
|
||||
|
||||
#if 0
|
||||
#if ! defined (APPLE_CC) && !defined (GRUB_UTIL)
|
||||
/* GCC emits references to abort(). */
|
||||
void abort (void) __attribute__ ((alias ("grub_abort")));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if NEED_ENABLE_EXECUTE_STACK && !defined(GRUB_UTIL) && !defined(GRUB_MACHINE_EMU)
|
||||
/* Some gcc versions generate a call to this function
|
||||
in trampolines for nested functions. */
|
||||
void __enable_execute_stack (void *addr __attribute__ ((unused)))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NEED_REGISTER_FRAME_INFO && !defined(GRUB_UTIL)
|
||||
void __register_frame_info (void)
|
||||
{
|
||||
}
|
||||
|
||||
void __deregister_frame_info (void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <grub/mm.h>
|
||||
#include <grub/partition.h>
|
||||
#include <grub/disk.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/util/misc.h>
|
||||
@ -32,218 +33,181 @@ grub_partition_map_t grub_partition_map_list;
|
||||
* start of part is relative to the start of disk->partition. Returns 1 if
|
||||
* disk->partition is null.
|
||||
*/
|
||||
static int
|
||||
grub_partition_check_containment (const grub_disk_t disk,
|
||||
const grub_partition_t part)
|
||||
{
|
||||
if (disk->partition == NULL)
|
||||
return 1;
|
||||
static int grub_partition_check_containment (const grub_disk_t disk, const grub_partition_t part) {
|
||||
if (disk->partition != NULL && ((part->start + part->len > disk->partition->len))) {
|
||||
char *partname = grub_partition_get_name (disk->partition);
|
||||
grub_dprintf ("partition", "sub-partition %s%d of (%s,%s) ends after parent.\n",
|
||||
part->partmap->name, part->number + 1, disk->name, partname);
|
||||
grub_free (partname);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (part->start + part->len > disk->partition->len)
|
||||
{
|
||||
char *partname;
|
||||
static int partnum = 0;
|
||||
|
||||
partname = grub_partition_get_name (disk->partition);
|
||||
grub_dprintf ("partition", "sub-partition %s%d of (%s,%s) ends after parent.\n",
|
||||
part->partmap->name, part->number + 1, disk->name, partname);
|
||||
grub_free (partname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
static grub_partition_t p = NULL;
|
||||
static int find_func (grub_disk_t dsk, const grub_partition_t partition) {
|
||||
if (partnum != partition->number)
|
||||
return 0;
|
||||
if (!(grub_partition_check_containment (dsk, partition)))
|
||||
return 0;
|
||||
p = (grub_partition_t) malloc (sizeof (*p));
|
||||
if (! p)
|
||||
return 1;
|
||||
memcpy (p, partition, sizeof (*p));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static grub_partition_t
|
||||
grub_partition_map_probe (const grub_partition_map_t partmap,
|
||||
grub_disk_t disk, int partnum)
|
||||
{
|
||||
grub_partition_t p = 0;
|
||||
|
||||
auto int find_func (grub_disk_t d, const grub_partition_t partition);
|
||||
|
||||
int find_func (grub_disk_t dsk,
|
||||
const grub_partition_t partition)
|
||||
{
|
||||
if (partnum != partition->number)
|
||||
return 0;
|
||||
|
||||
if (!(grub_partition_check_containment (dsk, partition)))
|
||||
return 0;
|
||||
|
||||
p = (grub_partition_t) grub_malloc (sizeof (*p));
|
||||
if (! p)
|
||||
return 1;
|
||||
|
||||
grub_memcpy (p, partition, sizeof (*p));
|
||||
return 1;
|
||||
}
|
||||
|
||||
partmap->iterate (disk, find_func);
|
||||
if (grub_errno)
|
||||
goto fail;
|
||||
|
||||
return p;
|
||||
|
||||
fail:
|
||||
grub_free (p);
|
||||
return 0;
|
||||
grub_partition_map_probe (const grub_partition_map_t partmap, grub_disk_t disk, int _partnum) {
|
||||
partnum = _partnum;
|
||||
partmap->iterate (disk, find_func);
|
||||
if (grub_errno) {
|
||||
grub_free (p);
|
||||
return NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
grub_partition_t
|
||||
grub_partition_probe (struct grub_disk *disk, const char *str)
|
||||
{
|
||||
grub_partition_t part = 0;
|
||||
grub_partition_t curpart = 0;
|
||||
grub_partition_t tail;
|
||||
const char *ptr;
|
||||
grub_partition_t grub_partition_probe (struct grub_disk *disk, const char *str) {
|
||||
grub_partition_t part = 0;
|
||||
grub_partition_t curpart = 0;
|
||||
grub_partition_t tail;
|
||||
const char *ptr;
|
||||
|
||||
part = tail = disk->partition;
|
||||
part = tail = disk->partition;
|
||||
|
||||
for (ptr = str; *ptr;)
|
||||
{
|
||||
grub_partition_map_t partmap;
|
||||
int num;
|
||||
const char *partname, *partname_end;
|
||||
for (ptr = str; *ptr;) {
|
||||
grub_partition_map_t partmap;
|
||||
int num;
|
||||
const char *partname, *partname_end;
|
||||
|
||||
partname = ptr;
|
||||
while (*ptr && grub_isalpha (*ptr))
|
||||
ptr++;
|
||||
partname_end = ptr;
|
||||
num = grub_strtoul (ptr, (char **) &ptr, 0) - 1;
|
||||
partname = ptr;
|
||||
while (*ptr && grub_isalpha (*ptr))
|
||||
ptr++;
|
||||
partname_end = ptr;
|
||||
num = grub_strtoul (ptr, (char **) &ptr, 0) - 1;
|
||||
|
||||
curpart = 0;
|
||||
/* Use the first partition map type found. */
|
||||
FOR_PARTITION_MAPS(partmap)
|
||||
{
|
||||
if (partname_end != partname &&
|
||||
(grub_strncmp (partmap->name, partname, partname_end - partname)
|
||||
!= 0 || partmap->name[partname_end - partname] != 0))
|
||||
continue;
|
||||
curpart = 0;
|
||||
/* Use the first partition map type found. */
|
||||
FOR_PARTITION_MAPS(partmap) {
|
||||
if (partname_end != partname &&
|
||||
(grub_strncmp (partmap->name, partname, partname_end - partname)
|
||||
!= 0 || partmap->name[partname_end - partname] != 0))
|
||||
continue;
|
||||
|
||||
disk->partition = part;
|
||||
curpart = grub_partition_map_probe (partmap, disk, num);
|
||||
disk->partition = tail;
|
||||
if (curpart)
|
||||
break;
|
||||
disk->partition = part;
|
||||
curpart = grub_partition_map_probe (partmap, disk, num);
|
||||
disk->partition = tail;
|
||||
if (curpart)
|
||||
break;
|
||||
|
||||
if (grub_errno == GRUB_ERR_BAD_PART_TABLE)
|
||||
{
|
||||
/* Continue to next partition map type. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
continue;
|
||||
}
|
||||
if (grub_errno == GRUB_ERR_BAD_PART_TABLE) {
|
||||
/* Continue to next partition map type. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! curpart)
|
||||
{
|
||||
while (part)
|
||||
{
|
||||
curpart = part->parent;
|
||||
grub_free (part);
|
||||
part = curpart;
|
||||
}
|
||||
return 0;
|
||||
if (! curpart) {
|
||||
while (part) {
|
||||
curpart = part->parent;
|
||||
grub_free (part);
|
||||
part = curpart;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
curpart->parent = part;
|
||||
part = curpart;
|
||||
if (! ptr || *ptr != ',')
|
||||
break;
|
||||
ptr++;
|
||||
}
|
||||
curpart->parent = part;
|
||||
part = curpart;
|
||||
if (! ptr || *ptr != ',')
|
||||
break;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return part;
|
||||
return part;
|
||||
}
|
||||
|
||||
int
|
||||
grub_partition_iterate (struct grub_disk *disk,
|
||||
int (*hook) (grub_disk_t disk,
|
||||
const grub_partition_t partition))
|
||||
{
|
||||
int ret = 0;
|
||||
static int (*hook) (grub_disk_t disk, const grub_partition_t partition);
|
||||
int part_iterate (grub_disk_t dsk, const grub_partition_t partition) {
|
||||
int ret = 0;
|
||||
struct grub_partition p = *partition;
|
||||
|
||||
auto int part_iterate (grub_disk_t dsk, const grub_partition_t p);
|
||||
if (!(grub_partition_check_containment (dsk, partition)))
|
||||
return 0;
|
||||
|
||||
int part_iterate (grub_disk_t dsk,
|
||||
const grub_partition_t partition)
|
||||
{
|
||||
struct grub_partition p = *partition;
|
||||
|
||||
if (!(grub_partition_check_containment (dsk, partition)))
|
||||
return 0;
|
||||
|
||||
p.parent = dsk->partition;
|
||||
dsk->partition = 0;
|
||||
if (hook (dsk, &p))
|
||||
{
|
||||
ret = 1;
|
||||
return 1;
|
||||
p.parent = dsk->partition;
|
||||
dsk->partition = 0;
|
||||
if (hook (dsk, &p)) {
|
||||
ret = 1;
|
||||
return 1;
|
||||
}
|
||||
if (p.start != 0)
|
||||
{
|
||||
const struct grub_partition_map *partmap;
|
||||
dsk->partition = &p;
|
||||
FOR_PARTITION_MAPS(partmap)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = partmap->iterate (dsk, part_iterate);
|
||||
if (err)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
if (p.start != 0) {
|
||||
const struct grub_partition_map *partmap;
|
||||
dsk->partition = &p;
|
||||
FOR_PARTITION_MAPS(partmap) {
|
||||
grub_err_t err;
|
||||
err = partmap->iterate (dsk, part_iterate);
|
||||
if (err)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
dsk->partition = p.parent;
|
||||
return ret;
|
||||
}
|
||||
|
||||
{
|
||||
const struct grub_partition_map *partmap;
|
||||
FOR_PARTITION_MAPS(partmap)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = partmap->iterate (disk, part_iterate);
|
||||
if (err)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
dsk->partition = p.parent;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
grub_partition_get_name (const grub_partition_t partition)
|
||||
int grub_partition_iterate (struct grub_disk *disk,
|
||||
int (*_hook) (grub_disk_t disk, const grub_partition_t partition))
|
||||
{
|
||||
char *out = 0;
|
||||
int curlen = 0;
|
||||
grub_partition_t part;
|
||||
for (part = partition; part; part = part->parent)
|
||||
{
|
||||
/* Even on 64-bit machines this buffer is enough to hold
|
||||
longest number. */
|
||||
char buf[grub_strlen (part->partmap->name) + 25];
|
||||
int strl;
|
||||
grub_snprintf (buf, sizeof (buf), "%s%d", part->partmap->name,
|
||||
part->number + 1);
|
||||
strl = grub_strlen (buf);
|
||||
if (curlen)
|
||||
int ret = 0;
|
||||
hook = _hook;
|
||||
//auto int part_iterate (grub_disk_t dsk, const grub_partition_t p);
|
||||
|
||||
{
|
||||
out = grub_realloc (out, curlen + strl + 2);
|
||||
grub_memcpy (out + strl + 1, out, curlen);
|
||||
out[curlen + 1 + strl] = 0;
|
||||
grub_memcpy (out, buf, strl);
|
||||
out[strl] = ',';
|
||||
curlen = curlen + 1 + strl;
|
||||
const struct grub_partition_map *partmap;
|
||||
FOR_PARTITION_MAPS (partmap) {
|
||||
grub_err_t err;
|
||||
err = partmap->iterate (disk, part_iterate);
|
||||
if (err)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
curlen = strl;
|
||||
out = grub_strdup (buf);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * grub_partition_get_name (const grub_partition_t partition) {
|
||||
char *out = 0;
|
||||
int curlen = 0;
|
||||
grub_partition_t part;
|
||||
for (part = partition; part; part = part->parent)
|
||||
{
|
||||
/* Even on 64-bit machines this buffer is enough to hold
|
||||
longest number. */
|
||||
char buf[grub_strlen (part->partmap->name) + 25];
|
||||
int strl;
|
||||
grub_snprintf (buf, sizeof (buf), "%s%d", part->partmap->name,
|
||||
part->number + 1);
|
||||
strl = grub_strlen (buf);
|
||||
if (curlen)
|
||||
{
|
||||
out = grub_realloc (out, curlen + strl + 2);
|
||||
grub_memcpy (out + strl + 1, out, curlen);
|
||||
out[curlen + 1 + strl] = 0;
|
||||
grub_memcpy (out, buf, strl);
|
||||
out[strl] = ',';
|
||||
curlen = curlen + 1 + strl;
|
||||
}
|
||||
else
|
||||
{
|
||||
curlen = strl;
|
||||
out = grub_strdup (buf);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <grub/file.h>
|
||||
#include <grub/disk.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern struct grub_fs grub_ext2_fs;
|
||||
|
Loading…
x
Reference in New Issue
Block a user