Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3521 → Rev 3519

/trunk/uspace/srv/fs/fat/fat_ops.c
40,7 → 40,6
#include "fat_fat.h"
#include "../../vfs/vfs.h"
#include <libfs.h>
#include <libblock.h>
#include <ipc/ipc.h>
#include <ipc/services.h>
#include <ipc/devmap.h>
61,6 → 60,48
/** List of cached free FAT nodes. */
static LIST_INITIALIZE(ffn_head);
 
static int dev_phone = -1; /* FIXME */
static void *dev_buffer = NULL; /* FIXME */
 
block_t *block_get(dev_handle_t dev_handle, off_t offset, size_t bs)
{
/* FIXME */
block_t *b;
off_t bufpos = 0;
size_t buflen = 0;
off_t pos = offset * bs;
 
assert(dev_phone != -1);
assert(dev_buffer);
 
b = malloc(sizeof(block_t));
if (!b)
return NULL;
b->data = malloc(bs);
if (!b->data) {
free(b);
return NULL;
}
b->size = bs;
 
if (!libfs_blockread(dev_phone, dev_buffer, &bufpos, &buflen, &pos,
b->data, bs, bs)) {
free(b->data);
free(b);
return NULL;
}
 
return b;
}
 
void block_put(block_t *block)
{
/* FIXME */
free(block->data);
free(block);
}
 
static void fat_node_initialize(fat_node_t *node)
{
futex_initialize(&node->lock, 1);
/trunk/uspace/srv/fs/fat/fat_fat.c
40,7 → 40,6
#include "fat.h"
#include "../../vfs/vfs.h"
#include <libfs.h>
#include <libblock.h>
#include <errno.h>
#include <byteorder.h>
#include <align.h>
/trunk/uspace/srv/fs/fat/fat.h
197,6 → 197,16
bool dirty;
} fat_node_t;
 
/* TODO move somewhere else */
typedef struct block {
void *data;
size_t size;
bool dirty;
} block_t;
 
extern block_t *block_get(dev_handle_t, off_t, size_t);
extern void block_put(block_t *);
 
extern fs_reg_t fat_reg;
 
extern void fat_mounted(ipc_callid_t, ipc_call_t *);
/trunk/uspace/srv/fs/fat/Makefile
31,16 → 31,12
 
LIBC_PREFIX = ../../../lib/libc
LIBFS_PREFIX = ../../../lib/libfs
LIBBLOCK_PREFIX = ../../../lib/libblock
SOFTINT_PREFIX = ../../../lib/softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I $(LIBFS_PREFIX) -I $(LIBBLOCK_PREFIX)
CFLAGS += -I $(LIBFS_PREFIX)
 
LIBS = \
$(LIBC_PREFIX)/libc.a \
$(LIBFS_PREFIX)/libfs.a \
$(LIBBLOCK_PREFIX)/libblock.a
LIBS = $(LIBC_PREFIX)/libc.a $(LIBFS_PREFIX)/libfs.a
 
## Sources
#
/trunk/uspace/srv/fs/tmpfs/tmpfs_dump.c
45,7 → 45,7
#include <string.h>
#include <sys/types.h>
#include <as.h>
#include <libblock.h>
#include <libfs.h>
#include <ipc/services.h>
#include <ipc/devmap.h>
#include <sys/mman.h>
70,7 → 70,7
tmpfs_dentry_t *node;
uint32_t size;
if (!blockread(phone, block, bufpos, buflen, pos, &entry,
if (!libfs_blockread(phone, block, bufpos, buflen, pos, &entry,
sizeof(entry), TMPFS_BLOCK_SIZE))
return false;
90,8 → 90,8
return false;
}
if (!blockread(phone, block, bufpos, buflen, pos, fname,
entry.len, TMPFS_BLOCK_SIZE)) {
if (!libfs_blockread(phone, block, bufpos, buflen, pos,
fname, entry.len, TMPFS_BLOCK_SIZE)) {
ops->destroy((void *) node);
free(fname);
return false;
105,8 → 105,8
}
free(fname);
if (!blockread(phone, block, bufpos, buflen, pos, &size,
sizeof(size), TMPFS_BLOCK_SIZE))
if (!libfs_blockread(phone, block, bufpos, buflen, pos,
&size, sizeof(size), TMPFS_BLOCK_SIZE))
return false;
size = uint32_t_le2host(size);
116,7 → 116,7
return false;
node->size = size;
if (!blockread(phone, block, bufpos, buflen, pos,
if (!libfs_blockread(phone, block, bufpos, buflen, pos,
node->data, size, TMPFS_BLOCK_SIZE))
return false;
132,8 → 132,8
return false;
}
if (!blockread(phone, block, bufpos, buflen, pos, fname,
entry.len, TMPFS_BLOCK_SIZE)) {
if (!libfs_blockread(phone, block, bufpos, buflen, pos,
fname, entry.len, TMPFS_BLOCK_SIZE)) {
ops->destroy((void *) node);
free(fname);
return false;
187,7 → 187,7
off_t pos = 0;
char tag[6];
if (!blockread(phone, block, &bufpos, &buflen, &pos, tag, 5,
if (!libfs_blockread(phone, block, &bufpos, &buflen, &pos, tag, 5,
TMPFS_BLOCK_SIZE))
goto error;
/trunk/uspace/srv/fs/tmpfs/Makefile
31,16 → 31,12
 
LIBC_PREFIX = ../../../lib/libc
LIBFS_PREFIX = ../../../lib/libfs
LIBBLOCK_PREFIX = ../../../lib/libblock
SOFTINT_PREFIX = ../../../lib/softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I $(LIBFS_PREFIX) -I $(LIBBLOCK_PREFIX)
CFLAGS += -I $(LIBFS_PREFIX)
 
LIBS = \
$(LIBC_PREFIX)/libc.a \
$(LIBFS_PREFIX)/libfs.a \
$(LIBBLOCK_PREFIX)/libblock.a
LIBS = $(LIBC_PREFIX)/libc.a $(LIBFS_PREFIX)/libfs.a
 
## Sources
#
/trunk/uspace/lib/libblock/Makefile
File deleted
/trunk/uspace/lib/libblock/libblock.c
File deleted
/trunk/uspace/lib/libblock/libblock.h
File deleted
/trunk/uspace/lib/libfs/libfs.c
36,6 → 36,7
 
#include "libfs.h"
#include "../../srv/vfs/vfs.h"
#include "../../srv/rd/rd.h"
#include <errno.h>
#include <async.h>
#include <ipc/ipc.h>
330,5 → 331,62
ops->node_put(tmp);
}
 
/** Read data from a block device.
*
* @param phone Phone to be used to communicate with the device.
* @param buffer Communication buffer shared with the device.
* @param bufpos Pointer to the first unread valid offset within the
* communication buffer.
* @param buflen Pointer to the number of unread bytes that are ready in
* the communication buffer.
* @param pos Device position to be read.
* @param dst Destination buffer.
* @param size Size of the destination buffer.
* @param block_size Block size to be used for the transfer.
*
* @return True on success, false on failure.
*/
bool libfs_blockread(int phone, void *buffer, off_t *bufpos, size_t *buflen,
off_t *pos, void *dst, size_t size, size_t block_size)
{
off_t offset = 0;
size_t left = size;
while (left > 0) {
size_t rd;
if (*bufpos + left < *buflen)
rd = left;
else
rd = *buflen - *bufpos;
if (rd > 0) {
/*
* Copy the contents of the communication buffer to the
* destination buffer.
*/
memcpy(dst + offset, buffer + *bufpos, rd);
offset += rd;
*bufpos += rd;
*pos += rd;
left -= rd;
}
if (*bufpos == *buflen) {
/* Refill the communication buffer with a new block. */
ipcarg_t retval;
int rc = async_req_2_1(phone, RD_READ_BLOCK,
*pos / block_size, block_size, &retval);
if ((rc != EOK) || (retval != EOK))
return false;
*bufpos = 0;
*buflen = block_size;
}
}
return true;
}
 
/** @}
*/
/trunk/uspace/lib/libfs/libfs.h
69,6 → 69,9
 
extern void libfs_lookup(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
 
extern bool libfs_blockread(int, void *, off_t *, size_t *, off_t *, void *,
size_t, size_t);
 
#endif
 
/** @}
/trunk/uspace/Makefile
34,7 → 34,6
DIRS = \
lib/libc \
lib/libfs \
lib/libblock \
lib/softint \
lib/softfloat \
srv/ns \