* Fix some warnings in r_fs

* Add new filesystems to r_fs
* Fix r_lang Makefile for OSX
This commit is contained in:
capi 2011-02-22 10:49:45 +01:00
parent 26fa19b3d8
commit 5541748e6b
20 changed files with 449 additions and 43 deletions

12
libr/fs/p/fb.mk Normal file
View File

@ -0,0 +1,12 @@
OBJ_FB=fs_fb.o
EXTRA=../p/grub/libgrubfs.a
CFLAGS+=-Igrub/include
STATIC_OBJ+=${OBJ_FB}
#STATIC_OBJ+=${EXTRA}
TARGET_FB=fs_fb.${EXT_SO}
ALL_TARGETS+=${TARGET_FB}
${TARGET_FB}: ${OBJ_FB}
${CC} ${LDFLAGS} ${CFLAGS} -o ${TARGET_FB} ${OBJ_FB} ${EXTRA}

10
libr/fs/p/fs_fb.c Normal file
View File

@ -0,0 +1,10 @@
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
#define FSP(x) fb_##x
#define FSS(x) x##_fb
#define FSNAME "fb"
#define FSDESC "FB filesystem"
#define FSPRFX fb
#define FSIPTR grub_fb_fs
#include "fs_grub_base.c"

10
libr/fs/p/fs_minix.c Normal file
View File

@ -0,0 +1,10 @@
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
#define FSP(x) minix_##x
#define FSS(x) x##_minix
#define FSNAME "minix"
#define FSDESC "MINIX filesystem"
#define FSPRFX minix
#define FSIPTR grub_minix_fs
#include "fs_grub_base.c"

10
libr/fs/p/fs_sfs.c Normal file
View File

@ -0,0 +1,10 @@
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
#define FSP(x) sfs_##x
#define FSS(x) x##_sfs
#define FSNAME "sfs"
#define FSDESC "SFS filesystem"
#define FSPRFX sfs
#define FSIPTR grub_sfs_fs
#include "fs_grub_base.c"

View File

@ -18,17 +18,22 @@ KERNFILES+=fs/reiserfs.c
KERNFILES+=fs/ext2.c
KERNFILES+=fs/fat.c
KERNFILES+=fs/ntfs.c
KERNFILES+=fs/ntfscomp.c
KERNFILES+=fs/cpio.c
KERNFILES+=fs/tar.c
KERNFILES+=fs/xfs.c
KERNFILES+=fs/ufs.c
#KERNFILES+=fs/ufs2.c
KERNFILES+=fs/ufs2.c
# All nested functions are removed from the following .c with a lot of tobacco :-)
KERNFILES+=fs/hfs.c
KERNFILES+=fs/hfsplus.c
KERNFILES+=fs/udf.c
KERNFILES+=fs/iso9660.c
KERNFILES+=fs/minix.c
#KERNFILES+=fs/minix2.c #XXX: Are minix2 and minix the same?
KERNFILES+=fs/jfs.c
KERNFILES+=fs/fb.c
KERNFILES+=fs/sfs.c
KERNFILES+=grubfs.c
KERNFILES+=partmap/msdos.c

251
libr/fs/p/grub/fs/fb.c Normal file
View File

@ -0,0 +1,251 @@
/*
* BURG - Brand-new Universal loadeR from GRUB
* Copyright 2010 Bean Lee - All Rights Reserved
*
* BURG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BURG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BURG. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/fs.h>
#include <grub/mm.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/misc.h>
#include <grub/fbfs.h>
struct grub_fb_data
{
grub_uint32_t ofs;
grub_uint32_t pri_size;
struct fbm_file *ptr;
char fb_list[0];
};
static struct grub_fb_data *
grub_fbfs_mount (grub_disk_t disk)
{
struct fb_mbr *m;
struct fb_data *d;
char buf[512];
struct grub_fb_data *data;
int boot_base, boot_size, list_used, pri_size, ofs, i;
char *fb_list, *p1, *p2;
if (grub_disk_read (disk, 0, 0, sizeof (buf), buf))
goto fail;
m = (struct fb_mbr *) buf;
d = (struct fb_data *) buf;
if (*((grub_uint32_t *) &buf[0]) == FB_AR_MAGIC_LONG)
{
ofs = 0;
boot_base = 0;
boot_size = 0;
pri_size = 0;
}
else
{
if ((m->fb_magic != FB_MAGIC_LONG) || (m->end_magic != 0xaa55))
goto fail;
ofs = m->lba;
boot_base = m->boot_base;
if (grub_disk_read (disk, boot_base + 1 - ofs, 0, sizeof (buf), buf))
goto fail;
boot_size = d->boot_size;
pri_size = d->pri_size;
}
if ((d->ver_major != FB_VER_MAJOR) || (d->ver_minor != FB_VER_MINOR))
goto fail;
list_used = d->list_used;
data = grub_malloc (sizeof (*data) + (list_used << 9));
if (! data)
goto fail;
fb_list = data->fb_list;
if (grub_disk_read (disk, boot_base + 1 + boot_size - ofs, 0,
(list_used << 9), fb_list))
{
grub_free (data);
goto fail;
}
p1 = p2 = fb_list;
for (i = 0; i < list_used - 1; i++)
{
p1 += 510;
p2 += 512;
grub_memcpy (p1, p2, 510);
}
data->ofs = ofs;
data->pri_size = pri_size;
return data;
fail:
grub_error (GRUB_ERR_BAD_FS, "not a fb filesystem");
return 0;
}
static grub_err_t
grub_fbfs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename,
const struct grub_dirhook_info *info,
void *closure),
void *closure)
{
struct grub_dirhook_info info;
struct fbm_file *p;
char *fn;
int len, ofs;
struct grub_fb_data *data;
data = grub_fbfs_mount (device->disk);
if (! data)
return grub_errno;
while (*path == '/')
path++;
len = grub_strlen (path);
fn = grub_strrchr (path, '/');
ofs = (fn) ? (fn + 1 - path) : 0;
grub_memset (&info, 0, sizeof (info));
info.mtimeset = 1;
p = (struct fbm_file *) data->fb_list;
while (p->size)
{
info.mtime = grub_le_to_cpu32 (p->data_time);
if ((! grub_memcmp (path, p->name, len)) &&
(hook (p->name + ofs, &info, closure)))
break;
p = (struct fbm_file *) ((char *) p + p->size + 2);
}
grub_free (data);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_fbfs_open (struct grub_file *file, const char *name)
{
struct fbm_file *p;
struct grub_fb_data *data;
data = grub_fbfs_mount (file->device->disk);
if (! data)
return grub_errno;
while (*name == '/')
name++;
p = (struct fbm_file *) data->fb_list;
while (p->size)
{
if (! grub_strcasecmp (name, p->name))
{
file->data = data;
data->ptr = p;
file->size = p->data_size;
return GRUB_ERR_NONE;
}
p = (struct fbm_file *) ((char *) p + p->size + 2);
}
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
}
static grub_ssize_t
grub_fbfs_read (grub_file_t file, char *buf, grub_size_t len)
{
struct fbm_file *p;
grub_disk_t disk;
grub_uint32_t sector;
grub_size_t saved_len, ofs;
struct grub_fb_data *data;
disk = file->device->disk;
disk->read_hook = file->read_hook;
disk->closure = file->closure;
data = file->data;
p = data->ptr;
if (p->data_start >= data->pri_size)
{
grub_err_t err;
err = grub_disk_read_ex (disk, p->data_start - data->ofs,
file->offset, len, buf, file->flags);
disk->read_hook = 0;
return (err) ? -1 : (grub_ssize_t) len;
}
sector = p->data_start + ((grub_uint32_t) file->offset / 510) - data->ofs;
ofs = ((grub_uint32_t) file->offset % 510);
saved_len = len;
while (len)
{
int n;
n = len;
if (ofs + n > 510)
n = 510 - ofs;
if (grub_disk_read (disk, sector, ofs, n, buf))
{
saved_len = -1;
break;
}
sector++;
if (buf)
buf += n;
len -= n;
ofs = 0;
}
disk->read_hook = 0;
return saved_len;
}
static grub_err_t
grub_fbfs_close (grub_file_t file)
{
grub_free (file->data);
return GRUB_ERR_NONE;
}
static grub_err_t
grub_fbfs_label (grub_device_t device __attribute ((unused)),
char **label __attribute ((unused)))
{
*label = 0;
return GRUB_ERR_NONE;
}
struct grub_fs grub_fb_fs =
{
.name = "fbfs",
.dir = grub_fbfs_dir,
.open = grub_fbfs_open,
.read = grub_fbfs_read,
.close = grub_fbfs_close,
.label = grub_fbfs_label,
.next = 0
};

View File

@ -597,8 +597,9 @@ grub_minix_label (grub_device_t device __attribute ((unused)),
}
struct grub_fs grub_minix_fs =
{
{
.name = "minix",
.dir = grub_minix_dir,
.open = grub_minix_open,
@ -606,4 +607,5 @@ struct grub_fs grub_minix_fs =
.close = grub_minix_close,
.label = grub_minix_label,
.next = 0
};
};

View File

@ -362,3 +362,4 @@ quit:
grub_free (ctx->comp.cbuf);
return ret;
}

View File

@ -592,7 +592,7 @@ grub_sfs_label (grub_device_t device, char **label)
}
static struct grub_fs grub_sfs_fs =
struct grub_fs grub_sfs_fs =
{
.name = "sfs",
.dir = grub_sfs_dir,
@ -602,3 +602,4 @@ static struct grub_fs grub_sfs_fs =
.label = grub_sfs_label,
.next = 0
};

View File

@ -806,23 +806,29 @@ grub_ufs_mtime (grub_device_t device, grub_int32_t *tm)
return grub_errno;
}
struct grub_fs grub_ufs_fs =
{
#ifdef MODE_UFS2
struct grub_fs grub_ufs2_fs =
{
.name = "ufs2",
#else
.name = "ufs1",
#endif
.dir = grub_ufs_dir,
.open = grub_ufs_open,
.read = grub_ufs_read,
.close = grub_ufs_close,
#ifdef MODE_UFS2
.label = grub_ufs_label,
#endif
.uuid = grub_ufs_uuid,
.mtime = grub_ufs_mtime,
.next = 0
};
};
#else
struct grub_fs grub_ufs_fs =
{
.name = "ufs1",
.dir = grub_ufs_dir,
.open = grub_ufs_open,
.read = grub_ufs_read,
.close = grub_ufs_close,
.uuid = grub_ufs_uuid,
.mtime = grub_ufs_mtime,
.next = 0
};
#endif

View File

@ -0,0 +1,79 @@
/*
* BURG - Brand-new Universal loadeR from GRUB
* Copyright 2010 Bean Lee - All Rights Reserved
*
* BURG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BURG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BURG. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_FBFS_H
#define GRUB_FBFS_H 1
#define FB_MAGIC "FBBF"
#define FB_MAGIC_LONG 0x46424246
#define FB_AR_MAGIC "FBAR"
#define FB_AR_MAGIC_LONG 0x52414246
#define FB_VER_MAJOR 1
#define FB_VER_MINOR 6
struct fb_mbr
{
grub_uint8_t jmp_code;
grub_uint8_t jmp_ofs;
grub_uint8_t boot_code[0x1ab];
grub_uint8_t max_sec; /* 0x1ad */
grub_uint16_t lba; /* 0x1ae */
grub_uint8_t spt; /* 0x1b0 */
grub_uint8_t heads; /* 0x1b1 */
grub_uint16_t boot_base; /* 0x1b2 */
grub_uint32_t fb_magic; /* 0x1b4 */
grub_uint8_t mbr_table[0x46]; /* 0x1b8 */
grub_uint16_t end_magic; /* 0x1fe */
} __attribute__((packed));
struct fb_data
{
grub_uint16_t boot_size; /* 0x200 */
grub_uint16_t flags; /* 0x202 */
grub_uint8_t ver_major; /* 0x204 */
grub_uint8_t ver_minor; /* 0x205 */
grub_uint16_t list_used; /* 0x206 */
grub_uint16_t list_size; /* 0x208 */
grub_uint16_t pri_size; /* 0x20a */
grub_uint32_t ext_size; /* 0x20c */
} __attribute__((packed));
struct fb_ar_data
{
grub_uint32_t ar_magic; /* 0x200 */
grub_uint8_t ver_major; /* 0x204 */
grub_uint8_t ver_minor; /* 0x205 */
grub_uint16_t list_used; /* 0x206 */
grub_uint16_t list_size; /* 0x208 */
grub_uint16_t pri_size; /* 0x20a */
grub_uint32_t ext_size; /* 0x20c */
} __attribute__((packed));
struct fbm_file
{
grub_uint8_t size;
grub_uint8_t flag;
grub_uint32_t data_start;
grub_uint32_t data_size;
grub_uint32_t data_time;
char name[0];
} __attribute__((packed));
#endif /* ! GRUB_FBFS_H */

View File

@ -84,27 +84,10 @@ typedef struct grub_fs *grub_fs_t;
/* This is special, because block lists are not files in usual sense. */
extern struct grub_fs grub_fs_blocklist;
/* This hook is used to automatically load filesystem modules.
If this hook loads a module, return non-zero. Otherwise return zero.
The newly loaded filesystem is assumed to be inserted into the head of
the linked list GRUB_FS_LIST through the function grub_fs_register. */
typedef int (*grub_fs_autoload_hook_t) (void);
extern grub_fs_autoload_hook_t grub_fs_autoload_hook;
extern grub_fs_t grub_fs_list;
static inline void
grub_fs_register (grub_fs_t fs)
{
grub_list_push (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
GRUB_MODATTR ("fs", "");
}
static inline void
grub_fs_unregister (grub_fs_t fs)
{
grub_list_remove (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs));
}
static inline void
grub_fs_iterate (int (*hook) (const grub_fs_t fs, void *closure),
void *closure)

View File

@ -19,6 +19,7 @@ void grubfs_disk_free (struct grub_disk *gd);
extern struct grub_fs grub_ext2_fs;
extern struct grub_fs grub_fat_fs;
extern struct grub_fs grub_ntfs_fs;
extern struct grub_fs grub_ntfscomp_fs;
extern struct grub_fs grub_reiserfs_fs;
extern struct grub_fs grub_hfs_fs;
extern struct grub_fs grub_hfsplus_fs;
@ -33,6 +34,8 @@ extern struct grub_fs grub_xfs_fs;
extern struct grub_fs grub_tar_fs;
extern struct grub_fs grub_cpio_fs;
extern struct grub_fs grub_udf_fs;
extern struct grub_fs grub_minix_fs;
extern struct grub_fs grub_fb_fs;
extern struct grub_partition_map grub_msdos_partition_map;
extern struct grub_partition_map grub_apple_partition_map;

View File

@ -142,8 +142,8 @@ get_header_from_pointer (void *ptr, grub_mm_header_t *p, grub_mm_region_t *r)
grub_fatal ("unaligned pointer %p", ptr);
for (*r = base; *r; *r = (*r)->next)
if ((grub_addr_t) ptr > (*r)->addr
&& (grub_addr_t) ptr <= (*r)->addr + (*r)->size)
if ((long) ptr > (*r)->addr
&& (long)ptr <= (*r)->addr + (*r)->size)
break;
if (! *r)
@ -167,7 +167,7 @@ grub_mm_init_region (void *addr, grub_size_t size)
#endif
/* Allocate a region from the head. */
r = (grub_mm_region_t) ALIGN_UP ((grub_addr_t) addr, GRUB_MM_ALIGN);
r = (grub_mm_region_t) ALIGN_UP ((long) addr, GRUB_MM_ALIGN);
size -= (char *) r - (char *) addr + sizeof (*r);
/* If this region is too small, ignore it. */
@ -180,7 +180,7 @@ grub_mm_init_region (void *addr, grub_size_t size)
h->size = (size >> GRUB_MM_ALIGN_LOG2);
r->first = h;
r->addr = (grub_addr_t) h;
r->addr = (long) h;
r->size = (h->size << GRUB_MM_ALIGN_LOG2);
/* Find where to insert this region. Put a smaller one before bigger ones,
@ -212,7 +212,7 @@ grub_real_malloc (grub_mm_header_t *first, grub_size_t n, grub_size_t align)
{
grub_off_t extra;
extra = ((grub_addr_t) (p + 1) >> GRUB_MM_ALIGN_LOG2) % align;
extra = ((long) (p + 1) >> GRUB_MM_ALIGN_LOG2) % align;
if (extra)
extra = align - extra;

View File

@ -121,7 +121,7 @@ int foo_main() {
GrubFS *gfs = grubfs_new (&grub_ext2_fs, NULL);
gfs->file->fs->open (gfs->file, "/test");
gfs->file->fs->read (gfs->file, buf, gfs->file->size);
printf ("fs = %d\n", gfs->file->size);
printf ("fs = %d\n", (int)gfs->file->size);
write (1, buf, gfs->file->size);
gfs->file->fs->close (gfs->file);
gfs->file->fs->dir (gfs->file->device, "/", dirhook, 0);

12
libr/fs/p/minix.mk Normal file
View File

@ -0,0 +1,12 @@
OBJ_MINIX=fs_minix.o
EXTRA=../p/grub/libgrubfs.a
CFLAGS+=-Igrub/include
STATIC_OBJ+=${OBJ_MINIX}
#STATIC_OBJ+=${EXTRA}
TARGET_MINIX=fs_minix.${EXT_SO}
ALL_TARGETS+=${TARGET_MINIX}
${TARGET_MINIX}: ${OBJ_MINIX}
${CC} ${LDFLAGS} ${CFLAGS} -o ${TARGET_MINIX} ${OBJ_MINIX} ${EXTRA}

12
libr/fs/p/sfs.mk Normal file
View File

@ -0,0 +1,12 @@
OBJ_SFS=fs_sfs.o
EXTRA=../p/grub/libgrubfs.a
CFLAGS+=-Igrub/include
STATIC_OBJ+=${OBJ_SFS}
#STATIC_OBJ+=${EXTRA}
TARGET_SFS=fs_sfs.${EXT_SO}
ALL_TARGETS+=${TARGET_SFS}
${TARGET_SFS}: ${OBJ_SFS}
${CC} ${LDFLAGS} ${CFLAGS} -o ${TARGET_SFS} ${OBJ_SFS} ${EXTRA}

View File

@ -109,6 +109,8 @@ extern RFSPlugin r_fs_plugin_afs;
extern RFSPlugin r_fs_plugin_affs;
extern RFSPlugin r_fs_plugin_cpio;
extern RFSPlugin r_fs_plugin_xfs;
extern RFSPlugin r_fs_plugin_fb;
extern RFSPlugin r_fs_plugin_minix;
extern RFSPlugin r_fs_plugin_posix;
#endif

View File

@ -3,6 +3,10 @@ BINDEPS=foo
include ../../config.mk
CFLAGS+=-I../../include -Wall -DPREFIX=\"${PREFIX}\"
ifeq ($(OSTYPE),darwin)
CFLAGS+=-undefined dynamic_lookup
endif
BINDEPS=
LANGS=lang_python.${EXT_SO} lang_perl.${EXT_SO}
@ -26,11 +30,11 @@ lang_python.${EXT_SO}:
else
lang_python.${EXT_SO}:
${CC} ${CFLAGS} \
`python-config --cflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
`python2-config --cflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
`python-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]* //g'` \
`python2-config --cflags 2>/dev/null | sed -e 's/-arch [^\s]* //g'` \
${LDFLAGS} \
`python-config --ldflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
`python2-config --ldflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
`python-config --ldflags 2>/dev/null | sed -e 's/-arch [^\s]* //g'` \
`python2-config --ldflags 2>/dev/null | sed -e 's/-arch [^\s]* //g'` \
${LDFLAGS_LIB} -fPIC -o lang_python.${EXT_SO} python.c
endif
@ -50,8 +54,8 @@ lang_ruby.${EXT_SO}:
lang_perl.${EXT_SO}:
-${CC} ${CFLAGS} -I/usr/lib/perl/5.10/CORE/ \
-fPIC ${LDFLAGS_LIB} -o lang_perl.${EXT_SO} perl.c ${LDFLAGS_LINKPATH}.. \
`perl -MExtUtils::Embed -e ccopts` \
`perl -MExtUtils::Embed -e ldopts` -lncurses
`perl -MExtUtils::Embed -e ccopts | sed -e 's/-arch [^\s]* //g'` \
`perl -MExtUtils::Embed -e ldopts | sed -e 's/-arch [^\s]* //g'` -lncurses
clean:
-rm -f *.${EXT_SO} *.${EXT_AR} *.o

View File

@ -52,6 +52,9 @@ fs.udf
fs.ufs
fs.posix
fs.jfs
fs.minix
fs.fb
fs.sfs
io.debug
io.rap
io.gdb