* Fix build for python plugin in osx

* Added UFS JFS and POSIX filesystems
* Many fixes in the 'ms' command
* Fix segfault in r_list_empty()
This commit is contained in:
pancake 2011-02-21 18:10:22 +01:00
parent 2290969c05
commit beb735e6e9
10 changed files with 111 additions and 24 deletions

View File

@ -154,7 +154,7 @@ R_API RList *r_fs_dir(RFS* fs, const char *p) {
}
}
free (path);
eprintf ("r_fs_dir: error, path %s is not mounted\n", path);
eprintf ("r_fs_dir: not mounted '%s'\n", path);
}
return NULL;
}
@ -232,25 +232,32 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
RListIter *iter;
RFSFile *file;
r_str_chop_path (root);
strncpy (path, root, sizeof (path)-1);
if (root && *root) {
r_str_chop_path (root);
strncpy (path, root, sizeof (path)-1);
} else strcpy (path, "/");
for (;;) {
printf (Color_MAGENTA"%s> "Color_RESET, path);
printf (Color_MAGENTA"[%s]> "Color_RESET, path);
fflush (stdout);
fgets (buf, sizeof (buf)-1, stdin);
if (feof (stdin)) break;
buf[strlen (buf)-1] = '\0';
if (!strcmp (buf, "q") || !strcmp (buf, "exit"))
return R_TRUE;
else if (!strcmp (buf, "ls")) {
if (buf[0]=='!') {
system (buf+1);
} else
if (!strcmp (buf, "ls")) {
list = r_fs_dir (fs, path);
if (list) {
r_list_foreach (list, iter, file)
printf ("%c %s\n", file->type, file->name);
r_list_free (list);
} else printf ("Unknown path\n");
} else if (!strncmp (buf, "cd ", 3)) {
} else if (!strncmp (buf, "pwd", 3)) {
eprintf ("%s\n", path);
} else if (!memcmp (buf, "cd ", 3)) {
input = buf+3;
while (input[0] == ' ')
input++;
@ -269,14 +276,13 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
strncpy (path, str, sizeof (path)-1);
printf ("Unknown path\n");
}
} else if (!strncmp (buf, "cat ", 4)) {
} else if (!memcmp (buf, "cat ", 4)) {
input = buf+3;
while (input[0] == ' ')
input++;
if (input[0] == '/')
strncpy (str, root, sizeof (str)-1);
else
strncpy (str, path, sizeof (str)-1);
else strncpy (str, path, sizeof (str)-1);
strcat (str, "/");
strcat (str, input);
file = r_fs_open (fs, str);
@ -284,15 +290,19 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
r_fs_read (fs, file, 0, file->size);
write (1, file->data, file->size);
r_fs_close (fs, file);
} else printf ("Cannot open file\n");
} else if (!strncmp (buf, "get ",4)){
} else eprintf ("Cannot open file\n");
} else if (!memcmp (buf, "mount", 5)) {
RFSRoot *root;
r_list_foreach (fs->roots, iter, root) {
eprintf ("%s %s\n", root->path, root->p->name);
}
} else if (!memcmp (buf, "get ",4)) {
input = buf+3;
while (input[0] == ' ')
input++;
if (input[0] == '/')
strncpy (str, root, sizeof (str)-1);
else
strncpy (str, path, sizeof (str)-1);
else strncpy (str, path, sizeof (str)-1);
strcat (str, "/");
strcat (str, input);
file = r_fs_open (fs, str);
@ -301,12 +311,15 @@ R_API int r_fs_prompt (RFS *fs, char *root) {
r_file_dump (input, file->data, file->size);
r_fs_close (fs, file);
} else printf ("Cannot open file\n");
} else if (!strcmp (buf, "help") || !strcmp (buf, "?")) {
printf(
} else if (!memcmp (buf, "help", 4) || !strcmp (buf, "?")) {
printf (
"Commands:\n"
" !cmd ; escape to system\n"
" ls ; list current directory\n"
" cd path ; change current directory\n"
" cat file ; print contents of file\n"
" get file ; dump file to disk\n"
" mount ; list mount points\n"
" q/exit ; leave prompt mode\n"
" ?/help ; show this help\n"
);

View File

@ -44,7 +44,7 @@ static int dirhook (const char *filename, const struct grub_dirhook_info *info,
static RList *FSP(_dir)(RFSRoot *root, const char *path) {
GrubFS *gfs = root->ptr;
list = r_list_new ();
eprintf ("r_fs_???_dir: %s\n", path);
// eprintf ("r_fs_???_dir: %s\n", path);
//gfs->file->device->data = &root->iob;
grubfs_bind_io (&root->iob, root->delta);
gfs->file->fs->dir (gfs->file->device, path, dirhook, 0);

66
libr/fs/p/fs_posix.c Normal file
View File

@ -0,0 +1,66 @@
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
#include <r_fs.h>
#include <dirent.h>
static RFSFile* fs_posix_open(RFSRoot *root, const char *path) {
#if 0
RFSFile *file = r_fs_file_new (root, path);
GrubFS *gfs = grubfs_new (&FSIPTR, &root->iob);
file->ptr = gfs;
file->p = root->p;
if (gfs->file->fs->open (gfs->file, path)) {
r_fs_file_free (file);
grubfs_free (gfs);
file = NULL;
} else file->size = gfs->file->size;
return file;
#endif
eprintf ("TODO\n");
return NULL;
}
static boolt fs_posix_read(RFSFile *file, ut64 addr, int len) {
eprintf ("TODO\n");
return R_FALSE;
}
static void fs_posix_close(RFSFile *file) {
//fclose (file->ptr);
}
static RList *fs_posix_dir(RFSRoot *root, const char *path) {
RList *list;
struct direct *de;
DIR *dir = opendir (path);
if (dir) return NULL;
list = r_list_new ();
while ((de = readdir (dir))) {
#if 0
RFSFile *fsf = r_fs_file_new (NULL, de->d_name);
fsf->type = 'f'; //info->dir? 'd':'f';
fsf->time = 0; // TODO: get info from stat(1)
r_list_append (list, fsf);
#endif
}
return list;
}
static void fs_posix_mount(RFSRoot *root) {
root->ptr = NULL; // XXX: TODO
}
static void fs_posix_umount(RFSRoot *root) {
root->ptr = NULL;
}
struct r_fs_plugin_t r_fs_plugin_posix = {
.name = "posix",
.desc = "POSIX filesystem",
.open = fs_posix_open,
.read = fs_posix_read,
.close = fs_posix_close,
.dir = fs_posix_dir,
.mount = fs_posix_mount,
.umount = fs_posix_umount,
};

View File

@ -21,6 +21,8 @@ KERNFILES+=fs/ntfs.c
KERNFILES+=fs/cpio.c
KERNFILES+=fs/tar.c
KERNFILES+=fs/xfs.c
KERNFILES+=fs/ufs.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

View File

@ -892,7 +892,7 @@ grub_jfs_label (grub_device_t device, char **label)
}
static struct grub_fs grub_jfs_fs =
struct grub_fs grub_jfs_fs =
{
.name = "jfs",
.dir = grub_jfs_dir,

View File

@ -808,7 +808,7 @@ grub_ufs_mtime (grub_device_t device, grub_int32_t *tm)
static struct grub_fs grub_ufs_fs =
struct grub_fs grub_ufs_fs =
{
#ifdef MODE_UFS2
.name = "ufs2",

View File

@ -109,6 +109,7 @@ 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_posix;
#endif

View File

@ -32,7 +32,7 @@ typedef struct r_oflist_t {
#define r_list_foreach_prev(list, it, pos) \
for (it = list->tail; it && (pos = it->data); it = it->p)
#define r_list_iterator(x) (x)?(x)->head:NULL
#define r_list_empty(x) (x->head==NULL && x->tail==NULL)
#define r_list_empty(x) (x==NULL || (x->head==NULL && x->tail==NULL))
#define r_list_head(x) x->head
#define r_list_tail(x) x->tail
#define r_list_unref(x) x

View File

@ -21,14 +21,16 @@ all: ${LANGS}
ifeq ($(OSTYPE),windows)
lang_python.${EXT_SO}:
${CC} ${CFLAGS} -I${HOME}/.wine/drive_c/Python27/include \
-L${HOME}/.wine/drive_c/Python27/libs \
-L../../core/ -lr_core \
-L${HOME}/.wine/drive_c/Python27/libs -L../../core/ -lr_core \
${LDFLAGS_LIB} -shared -o lang_python.${EXT_SO} python.c -lpython27
else
lang_python.${EXT_SO}:
${CC} ${CFLAGS} ${LDFLAGS} \
`python-config --cflags --ldflags 2>/dev/null` \
`python2-config --cflags --ldflags 2>/dev/null` \
${CC} ${CFLAGS} \
`python-config --cflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
`python2-config --cflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
${LDFLAGS} \
`python-config --ldflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
`python2-config --ldflags 2>/dev/null | sed -e 's,-arch .*,,g'` \
${LDFLAGS_LIB} -fPIC -o lang_python.${EXT_SO} python.c
endif

View File

@ -49,6 +49,9 @@ fs.cpio
fs.xfs
fs.iso9660
fs.udf
fs.ufs
fs.posix
fs.jfs
io.debug
io.rap
io.gdb