Create SFFS library out of HGFS

This Shared Folders File System library (libsffs) now contains all the
file system logic originally in HGFS. The actual HGFS server code is
now a stub that passes on all the work to libsffs. The libhgfs library
is changed accordingly.
This commit is contained in:
David van Moolenbroek
2012-04-09 18:08:26 +02:00
parent 09b327b042
commit ef7b484e5c
41 changed files with 664 additions and 534 deletions
+1 -1
View File
@@ -2,6 +2,6 @@
LIB= hgfs
SRCS= backdoor.S attr.c channel.c dir.c error.c file.c \
info.c link.c misc.c path.c rpc.c time.c
hgfs.c info.c link.c path.c rpc.c time.c
.include <bsd.lib.mk>
+15 -15
View File
@@ -8,7 +8,7 @@
* attr_get *
*===========================================================================*/
void attr_get(attr)
struct hgfs_attr *attr;
struct sffs_attr *attr;
{
/* Get attribute information from the RPC buffer, storing the requested parts
* in the given attr structure.
@@ -20,16 +20,16 @@ struct hgfs_attr *attr;
size_lo = RPC_NEXT32;
size_hi = RPC_NEXT32;
if (attr->a_mask & HGFS_ATTR_SIZE)
if (attr->a_mask & SFFS_ATTR_SIZE)
attr->a_size = make64(size_lo, size_hi);
time_get((attr->a_mask & HGFS_ATTR_CRTIME) ? &attr->a_crtime : NULL);
time_get((attr->a_mask & HGFS_ATTR_ATIME) ? &attr->a_atime : NULL);
time_get((attr->a_mask & HGFS_ATTR_MTIME) ? &attr->a_mtime : NULL);
time_get((attr->a_mask & HGFS_ATTR_CTIME) ? &attr->a_ctime : NULL);
time_get((attr->a_mask & SFFS_ATTR_CRTIME) ? &attr->a_crtime : NULL);
time_get((attr->a_mask & SFFS_ATTR_ATIME) ? &attr->a_atime : NULL);
time_get((attr->a_mask & SFFS_ATTR_MTIME) ? &attr->a_mtime : NULL);
time_get((attr->a_mask & SFFS_ATTR_CTIME) ? &attr->a_ctime : NULL);
mode |= HGFS_PERM_TO_MODE(RPC_NEXT8);
if (attr->a_mask & HGFS_ATTR_MODE) attr->a_mode = mode;
if (attr->a_mask & SFFS_ATTR_MODE) attr->a_mode = mode;
}
/*===========================================================================*
@@ -37,7 +37,7 @@ struct hgfs_attr *attr;
*===========================================================================*/
int hgfs_getattr(path, attr)
char *path;
struct hgfs_attr *attr;
struct sffs_attr *attr;
{
/* Get selected attributes of a file by path name.
*/
@@ -60,7 +60,7 @@ struct hgfs_attr *attr;
*===========================================================================*/
int hgfs_setattr(path, attr)
char *path;
struct hgfs_attr *attr;
struct sffs_attr *attr;
{
/* Set selected attributes of a file by path name.
*/
@@ -74,14 +74,14 @@ struct hgfs_attr *attr;
* HGFS protocol version (v2/v3).
*/
mask = 0;
if (attr->a_mask & HGFS_ATTR_MODE) mask |= HGFS_ATTR_MODE;
if (attr->a_mask & HGFS_ATTR_SIZE) mask |= HGFS_ATTR_SIZE;
if (attr->a_mask & HGFS_ATTR_CRTIME) mask |= HGFS_ATTR_CRTIME;
if (attr->a_mask & HGFS_ATTR_ATIME)
if (attr->a_mask & SFFS_ATTR_MODE) mask |= HGFS_ATTR_MODE;
if (attr->a_mask & SFFS_ATTR_SIZE) mask |= HGFS_ATTR_SIZE;
if (attr->a_mask & SFFS_ATTR_CRTIME) mask |= HGFS_ATTR_CRTIME;
if (attr->a_mask & SFFS_ATTR_ATIME)
mask |= HGFS_ATTR_ATIME | HGFS_ATTR_ATIME_SET;
if (attr->a_mask & HGFS_ATTR_MTIME)
if (attr->a_mask & SFFS_ATTR_MTIME)
mask |= HGFS_ATTR_MTIME | HGFS_ATTR_MTIME_SET;
if (attr->a_mask & HGFS_ATTR_CTIME) mask |= HGFS_ATTR_CTIME;
if (attr->a_mask & SFFS_ATTR_CTIME) mask |= HGFS_ATTR_CTIME;
RPC_NEXT8 = mask;
+5 -5
View File
@@ -7,7 +7,7 @@
*===========================================================================*/
int hgfs_opendir(path, handle)
char *path;
hgfs_dir_t *handle;
sffs_dir_t *handle;
{
/* Open a directory. Store a directory handle upon success.
*/
@@ -20,7 +20,7 @@ hgfs_dir_t *handle;
if ((r = rpc_query()) != OK)
return r;
*handle = (hgfs_dir_t)RPC_NEXT32;
*handle = (sffs_dir_t)RPC_NEXT32;
return OK;
}
@@ -29,11 +29,11 @@ hgfs_dir_t *handle;
* hgfs_readdir *
*===========================================================================*/
int hgfs_readdir(handle, index, buf, size, attr)
hgfs_dir_t handle;
sffs_dir_t handle;
unsigned int index;
char *buf;
size_t size;
struct hgfs_attr *attr;
struct sffs_attr *attr;
{
/* Read a directory entry from an open directory, using a zero-based index
* number. Upon success, the resulting path name is stored in the given buffer
@@ -67,7 +67,7 @@ struct hgfs_attr *attr;
* hgfs_closedir *
*===========================================================================*/
int hgfs_closedir(handle)
hgfs_dir_t handle;
sffs_dir_t handle;
{
/* Close an open directory.
*/
+7 -7
View File
@@ -12,7 +12,7 @@ int hgfs_open(path, flags, mode, handle)
char *path; /* path name to open */
int flags; /* open flags to use */
int mode; /* mode to create (user bits only) */
hgfs_file_t *handle; /* place to store resulting handle */
sffs_file_t *handle; /* place to store resulting handle */
{
/* Open a file. Store a file handle upon success.
*/
@@ -42,7 +42,7 @@ hgfs_file_t *handle; /* place to store resulting handle */
if ((r = rpc_query()) != OK)
return r;
*handle = (hgfs_file_t)RPC_NEXT32;
*handle = (sffs_file_t)RPC_NEXT32;
return OK;
}
@@ -50,8 +50,8 @@ hgfs_file_t *handle; /* place to store resulting handle */
/*===========================================================================*
* hgfs_read *
*===========================================================================*/
int hgfs_read(handle, buf, size, off)
hgfs_file_t handle; /* handle to open file */
ssize_t hgfs_read(handle, buf, size, off)
sffs_file_t handle; /* handle to open file */
char *buf; /* data buffer or NULL */
size_t size; /* maximum number of bytes to read */
u64_t off; /* file offset */
@@ -84,8 +84,8 @@ u64_t off; /* file offset */
/*===========================================================================*
* hgfs_write *
*===========================================================================*/
int hgfs_write(handle, buf, len, off)
hgfs_file_t handle; /* handle to open file */
ssize_t hgfs_write(handle, buf, len, off)
sffs_file_t handle; /* handle to open file */
char *buf; /* data buffer or NULL */
size_t len; /* number of bytes to write */
u64_t off; /* file offset */
@@ -116,7 +116,7 @@ u64_t off; /* file offset */
* hgfs_close *
*===========================================================================*/
int hgfs_close(handle)
hgfs_file_t handle; /* handle to open file */
sffs_file_t handle; /* handle to open file */
{
/* Close an open file.
*/
+33 -2
View File
@@ -2,18 +2,48 @@
#include "inc.h"
struct sffs_table hgfs_table = {
.t_open = hgfs_open,
.t_read = hgfs_read,
.t_write = hgfs_write,
.t_close = hgfs_close,
.t_readbuf = hgfs_readbuf,
.t_writebuf = hgfs_writebuf,
.t_opendir = hgfs_opendir,
.t_readdir = hgfs_readdir,
.t_closedir = hgfs_closedir,
.t_getattr = hgfs_getattr,
.t_setattr = hgfs_setattr,
.t_mkdir = hgfs_mkdir,
.t_unlink = hgfs_unlink,
.t_rmdir = hgfs_rmdir,
.t_rename = hgfs_rename,
.t_queryvol = hgfs_queryvol,
};
/*===========================================================================*
* hgfs_init *
*===========================================================================*/
int hgfs_init()
int hgfs_init(const struct sffs_table **tablep)
{
/* Initialize the library. Return OK on success, or a negative error code
* otherwise. If EAGAIN is returned, shared folders are disabled.
*/
int r;
time_init();
return rpc_open();
r = rpc_open();
if (r == OK)
*tablep = &hgfs_table;
return r;
}
/*===========================================================================*
@@ -26,3 +56,4 @@ void hgfs_cleanup()
rpc_close();
}
+2 -11
View File
@@ -1,16 +1,7 @@
/* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
#ifndef __NBSD_LIBC
#define _POSIX_SOURCE 1 /* need PATH_MAX */
#endif
#define _SYSTEM 1 /* need negative error codes */
#include <minix/config.h>
#include <minix/const.h>
#include <string.h>
#include <errno.h>
#include <minix/drivers.h>
#include <minix/sffs.h>
#include <minix/hgfs.h>
#define PREFIX(x) __libhgfs_##x
+26 -1
View File
@@ -2,7 +2,9 @@
/* attr.c */
#define attr_get PREFIX(attr_get)
void attr_get(struct hgfs_attr *attr);
void attr_get(struct sffs_attr *attr);
int hgfs_getattr(char *path, struct sffs_attr *attr);
int hgfs_setattr(char *path, struct sffs_attr *attr);
/* backdoor.s */
#define backdoor PREFIX(backdoor)
@@ -22,10 +24,33 @@ void channel_close(struct channel *ch);
int channel_send(struct channel *ch, char *buf, int len);
int channel_recv(struct channel *ch, char *buf, int max);
/* dir.c */
int hgfs_opendir(char *path, sffs_dir_t *handle);
int hgfs_readdir(sffs_dir_t handle, unsigned int index, char *buf, size_t size,
struct sffs_attr *attr);
int hgfs_closedir(sffs_dir_t handle);
/* error.c */
#define error_convert PREFIX(error_convert)
int error_convert(int err);
/* file.c */
int hgfs_open(char *path, int flags, int mode, sffs_file_t *handle);
ssize_t hgfs_read(sffs_file_t handle, char *buf, size_t size, u64_t offset);
ssize_t hgfs_write(sffs_file_t handle, char *buf, size_t len, u64_t offset);
int hgfs_close(sffs_file_t handle);
size_t hgfs_readbuf(char **ptr);
size_t hgfs_writebuf(char **ptr);
/* info.c */
int hgfs_queryvol(char *path, u64_t *free, u64_t *total);
/* link.c */
int hgfs_mkdir(char *path, int mode);
int hgfs_unlink(char *path);
int hgfs_rmdir(char *path);
int hgfs_rename(char *opath, char *npath);
/* path.c */
#define path_put PREFIX(path_put)
#define path_get PREFIX(path_get)