# HG changeset patch # User Michael Spacefalcon # Date 1378085291 0 # Node ID ac310ee737886a23a4c8a18c04438e63840f64ff # Parent 7f75ffdd674fa5843f0e8ca3b10898a4e0296156 target-utils/libmpffs: minor refactoring, read into RAM implemented diff -r 7f75ffdd674f -r ac310ee73788 target-utils/libmpffs/Makefile --- a/target-utils/libmpffs/Makefile Mon Sep 02 00:41:18 2013 +0000 +++ b/target-utils/libmpffs/Makefile Mon Sep 02 01:28:11 2013 +0000 @@ -4,7 +4,7 @@ AR= arm-elf-ar RANLIB= arm-elf-ranlib -OBJS= basicfind.o globals.o init.o +OBJS= basicfind.o findfile.o globals.o init.o rdinmem.o all: libmpffs.a diff -r 7f75ffdd674f -r ac310ee73788 target-utils/libmpffs/basicfind.c --- a/target-utils/libmpffs/basicfind.c Mon Sep 02 00:41:18 2013 +0000 +++ b/target-utils/libmpffs/basicfind.c Mon Sep 02 01:28:11 2013 +0000 @@ -6,25 +6,6 @@ extern char *index(); -static u8 * -find_endofchunk(ino) -{ - struct inode *irec = mpffs_active_index + ino; - u8 *p; - int i; - - p = inode_to_dataptr(irec) + irec->len; - for (i = 0; i < 16; i++) { - p--; - if (!*p) - return(p); - if (*p != 0xFF) - break; - } - printf("Error: inode #%x has no valid termination\n", ino); - return(p); /* XXX */ -} - static find_named_child(start, seekname) char *seekname; @@ -82,85 +63,3 @@ } return(ino); } - -mpffs_find_file(pathname, startret, sizeret, continue_ret) - char *pathname; - u8 **startret; - size_t *sizeret; - int *continue_ret; -{ - int ino, cont; - struct inode *irec; - u8 *start, *end; - int size; - - ino = mpffs_pathname_to_inode(pathname); - if (ino <= 0) - return(-1); - irec = mpffs_active_index + ino; - if (irec->type != OBJTYPE_FILE) { - printf("Error: %s is not a regular file\n", pathname); - return(-1); - } - start = inode_to_dataptr(irec); - start += strlen(start) + 1; - end = find_endofchunk(ino); - size = end - start; - if (size < 0) - size = 0; - cont = irec->descend; - if (cont == 0xFFFF) - cont = 0; - if (startret) - *startret = start; - if (sizeret) - *sizeret = size; - if (continue_ret) - *continue_ret = cont; - return(0); -} - -mpffs_get_segment(ino, startret, sizeret, continue_ret) - int ino; - u8 **startret; - size_t *sizeret; - int *continue_ret; -{ - int cont; - struct inode *irec; - u8 *start, *end; - int size; - - for (;;) { - irec = mpffs_active_index + ino; - if (irec->type) - break; - if (irec->sibling == 0xFFFF) { - printf("Error: segment inode #%d: deleted and no sibling\n", - ino); - return(-1); - } - ino = irec->sibling; - } - if (irec->type != OBJTYPE_SEGMENT) { - printf("Error: inode #%x is not a segment\n", ino); - return(-1); - } - start = inode_to_dataptr(irec); - end = find_endofchunk(ino); - size = end - start; - if (size <= 0) { - printf("Error: segment inode #%x: bad length\n", ino); - return(-1); - } - cont = irec->descend; - if (cont == 0xFFFF) - cont = 0; - if (startret) - *startret = start; - if (sizeret) - *sizeret = size; - if (continue_ret) - *continue_ret = cont; - return(0); -} diff -r 7f75ffdd674f -r ac310ee73788 target-utils/libmpffs/findfile.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/findfile.c Mon Sep 02 01:28:11 2013 +0000 @@ -0,0 +1,106 @@ +#include +#include "types.h" +#include "struct.h" +#include "globals.h" +#include "macros.h" + +static u8 * +find_endofchunk(ino) +{ + struct inode *irec = mpffs_active_index + ino; + u8 *p; + int i; + + p = inode_to_dataptr(irec) + irec->len; + for (i = 0; i < 16; i++) { + p--; + if (!*p) + return(p); + if (*p != 0xFF) + break; + } + printf("Error: inode #%x has no valid termination\n", ino); + return(p); /* XXX */ +} + +mpffs_find_file(pathname, startret, sizeret, continue_ret) + char *pathname; + u8 **startret; + size_t *sizeret; + int *continue_ret; +{ + int ino, cont; + struct inode *irec; + u8 *start, *end; + int size; + + ino = mpffs_pathname_to_inode(pathname); + if (ino <= 0) + return(-1); + irec = mpffs_active_index + ino; + if (irec->type != OBJTYPE_FILE) { + printf("Error: %s is not a regular file\n", pathname); + return(-1); + } + start = inode_to_dataptr(irec); + start += strlen(start) + 1; + end = find_endofchunk(ino); + size = end - start; + if (size < 0) + size = 0; + cont = irec->descend; + if (cont == 0xFFFF) + cont = 0; + if (startret) + *startret = start; + if (sizeret) + *sizeret = size; + if (continue_ret) + *continue_ret = cont; + return(0); +} + +mpffs_get_segment(ino, startret, sizeret, continue_ret) + int ino; + u8 **startret; + size_t *sizeret; + int *continue_ret; +{ + int cont; + struct inode *irec; + u8 *start, *end; + int size; + + for (;;) { + irec = mpffs_active_index + ino; + if (irec->type) + break; + if (irec->sibling == 0xFFFF) { + printf("Error: segment inode #%d: deleted and no sibling\n", + ino); + return(-1); + } + ino = irec->sibling; + } + if (irec->type != OBJTYPE_SEGMENT) { + printf("Error: inode #%x is not a segment\n", ino); + return(-1); + } + start = inode_to_dataptr(irec); + end = find_endofchunk(ino); + size = end - start; + if (size <= 0) { + printf("Error: segment inode #%x: bad length\n", ino); + return(-1); + } + cont = irec->descend; + if (cont == 0xFFFF) + cont = 0; + if (startret) + *startret = start; + if (sizeret) + *sizeret = size; + if (continue_ret) + *continue_ret = cont; + return(0); +} diff -r 7f75ffdd674f -r ac310ee73788 target-utils/libmpffs/rdinmem.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/libmpffs/rdinmem.c Mon Sep 02 01:28:11 2013 +0000 @@ -0,0 +1,42 @@ +#include +#include "types.h" +#include "struct.h" +#include "globals.h" +#include "macros.h" + +mpffs_read_into_ram(pathname, buf, maxlen, lenrtn) + char *pathname; + u8 *buf; + size_t maxlen, *lenrtn; +{ + int stat, cont; + u8 *chunk_start; + size_t chunk_size, real_len, roomleft; + + stat = mpffs_find_file(pathname, &chunk_start, &chunk_size, &cont); + if (stat < 0) + return(stat); + if (chunk_size > maxlen) { +toobig: printf("Error: %s is bigger than the read buffer\n", pathname); + return(-1); + } + real_len = chunk_size; + bcopy(chunk_start, buf, chunk_size); + buf += chunk_size; + roomleft = maxlen - chunk_size; + while (cont) { + stat = mpffs_get_segment(cont, &chunk_start, &chunk_size, + &cont); + if (stat < 0) + return(stat); + if (chunk_size > roomleft) + goto toobig; + real_len += chunk_size; + bcopy(chunk_start, buf, chunk_size); + buf += chunk_size; + roomleft -= chunk_size; + } + if (lenrtn) + *lenrtn = real_len; + return(0); +}