typedef struct _tree_t {
data_t key;
data_t fh;
+ ssize_t size;
struct _tree_t *parent;
struct _tree_t *left;
struct _tree_t *right;
return ;
}
-static data_t *lookup_fhandle(struct nfsio *nfsio, const char *name)
+static data_t *lookup_fhandle(struct nfsio *nfsio, const char *name, ssize_t *size)
{
tree_t *t;
return recursive_lookup_fhandle(nfsio, name);
}
+ if (size) {
+ *size = t->size;
+ }
+
return &t->fh;
}
return;
}
-static void insert_fhandle(struct nfsio *nfsio, const char *name, const char *fhandle, int length)
+static void insert_fhandle(struct nfsio *nfsio, const char *name, const char *fhandle, int length, ssize_t size)
{
tree_t *tmp_t;
tree_t *t;
int i;
+printf("insert_fhandle:%s size:%d\n", name, size);
while (name[0] == '.') name++;
t = malloc(sizeof(tree_t));
memcpy(discard_const(t->fh.dptr), fhandle, length);
t->fh.dsize = length;
+ t->size = size;
+
t->left = NULL;
t->right = NULL;
t->parent = NULL;
}
fh = &mountres->mountres3_u.mountinfo.fhandle;
- insert_fhandle(nfsio, "/", fh->fhandle3_val, fh->fhandle3_len);
+ insert_fhandle(nfsio, "/",
+ fh->fhandle3_val,
+ fh->fhandle3_len,
+ 0);
/* we dont need the mount client any more */
struct GETATTR3res *GETATTR3res;
data_t *fh;
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_getattr\n");
return NFS3ERR_SERVERFAULT;
*ptr = 0;
ptr++;
- fh = lookup_fhandle(nfsio, tmp_name);
+ fh = lookup_fhandle(nfsio, tmp_name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch parent handle for '%s' in nfsio_lookup\n", tmp_name);
ret = NFS3ERR_SERVERFAULT;
goto finished;
}
-
insert_fhandle(nfsio, name,
LOOKUP3res->LOOKUP3res_u.resok.object.data.data_val,
- LOOKUP3res->LOOKUP3res_u.resok.object.data.data_len);
+ LOOKUP3res->LOOKUP3res_u.resok.object.data.data_len,
+ LOOKUP3res->LOOKUP3res_u.resok.obj_attributes.post_op_attr_u.attributes.size);
free(LOOKUP3res->LOOKUP3res_u.resok.object.data.data_val);
struct ACCESS3res *ACCESS3res;
data_t *fh;
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_access\n");
return NFS3ERR_SERVERFAULT;
*ptr = 0;
ptr++;
- fh = lookup_fhandle(nfsio, tmp_name);
+ fh = lookup_fhandle(nfsio, tmp_name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_create\n");
ret = NFS3ERR_SERVERFAULT;
insert_fhandle(nfsio, name,
CREATE3res->CREATE3res_u.resok.obj.post_op_fh3_u.handle.data.data_val,
- CREATE3res->CREATE3res_u.resok.obj.post_op_fh3_u.handle.data.data_len);
+ CREATE3res->CREATE3res_u.resok.obj.post_op_fh3_u.handle.data.data_len,
+ 0 /*qqq*/
+ );
finished:
*ptr = 0;
ptr++;
- fh = lookup_fhandle(nfsio, tmp_name);
+ fh = lookup_fhandle(nfsio, tmp_name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_remove\n");
ret = NFS3ERR_SERVERFAULT;
int ret = NFS3_OK;
data_t *fh;
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_write\n");
ret = NFS3ERR_SERVERFAULT;
struct READ3res *READ3res;
int ret = NFS3_OK;
data_t *fh;
+ ssize_t size;
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, &size);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_read\n");
ret = NFS3ERR_SERVERFAULT;
goto finished;
}
+ if (offset >= size) {
+ offset = offset % size;
+ }
+ if (offset+len >= size) {
+ offset = 0;
+ }
+
READ3args.file.data.data_len = fh->dsize;
READ3args.file.data.data_val = discard_const(fh->dptr);
READ3args.offset = offset;
int ret = NFS3_OK;
data_t *fh;
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_commit\n");
ret = NFS3ERR_SERVERFAULT;
struct FSINFO3res *FSINFO3res;
data_t *fh;
- fh = lookup_fhandle(nfsio, "/");
+ fh = lookup_fhandle(nfsio, "/", NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_fsinfo\n");
return NFS3ERR_SERVERFAULT;
struct FSSTAT3res *FSSTAT3res;
data_t *fh;
- fh = lookup_fhandle(nfsio, "/");
+ fh = lookup_fhandle(nfsio, "/", NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_fsstat\n");
return NFS3ERR_SERVERFAULT;
struct PATHCONF3res *PATHCONF3res;
data_t *fh;
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_pathconf\n");
return NFS3ERR_SERVERFAULT;
*ptr = 0;
ptr++;
- fh = lookup_fhandle(nfsio, tmp_name);
+ fh = lookup_fhandle(nfsio, tmp_name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_symlink\n");
ret = NFS3ERR_SERVERFAULT;
insert_fhandle(nfsio, old,
SYMLINK3res->SYMLINK3res_u.resok.obj.post_op_fh3_u.handle.data.data_val,
- SYMLINK3res->SYMLINK3res_u.resok.obj.post_op_fh3_u.handle.data.data_len);
+ SYMLINK3res->SYMLINK3res_u.resok.obj.post_op_fh3_u.handle.data.data_len,
+ 0 /*qqq*/
+ );
finished:
*ptr = 0;
ptr++;
- fh = lookup_fhandle(nfsio, tmp_name);
+ fh = lookup_fhandle(nfsio, tmp_name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_link\n");
ret = NFS3ERR_SERVERFAULT;
}
- new_fh = lookup_fhandle(nfsio, new);
+ new_fh = lookup_fhandle(nfsio, new, NULL);
if (new_fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_link\n");
ret = NFS3ERR_SERVERFAULT;
struct READLINK3res *READLINK3res;
data_t *fh;
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle in nfsio_readlink\n");
return NFS3ERR_SERVERFAULT;
*ptr = 0;
ptr++;
- fh = lookup_fhandle(nfsio, tmp_name);
+ fh = lookup_fhandle(nfsio, tmp_name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_rmdir\n");
ret = NFS3ERR_SERVERFAULT;
*ptr = 0;
ptr++;
- fh = lookup_fhandle(nfsio, tmp_name);
+ fh = lookup_fhandle(nfsio, tmp_name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_mkdir\n");
ret = NFS3ERR_SERVERFAULT;
insert_fhandle(nfsio, name,
MKDIR3res->MKDIR3res_u.resok.obj.post_op_fh3_u.handle.data.data_val,
- MKDIR3res->MKDIR3res_u.resok.obj.post_op_fh3_u.handle.data.data_len);
+ MKDIR3res->MKDIR3res_u.resok.obj.post_op_fh3_u.handle.data.data_len,
+ 0 /*qqq*/
+ );
finished:
if (tmp_name) {
dir[strlen(dir)-1] = 0;
}
- fh = lookup_fhandle(nfsio, name);
+ fh = lookup_fhandle(nfsio, name, NULL);
if (fh == NULL) {
fprintf(stderr, "failed to fetch handle for '%s' in nfsio_readdirplus\n", name);
ret = NFS3ERR_SERVERFAULT;
asprintf(&new_name, "%s/%s", dir, e->name);
insert_fhandle(nfsio, new_name,
e->name_handle.post_op_fh3_u.handle.data.data_val,
- e->name_handle.post_op_fh3_u.handle.data.data_len);
+ e->name_handle.post_op_fh3_u.handle.data.data_len,
+ 0 /*qqq*/
+ );
free(new_name);
if (cb) {
*old_ptr = 0;
old_ptr++;
- old_fh = lookup_fhandle(nfsio, tmp_old_name);
+ old_fh = lookup_fhandle(nfsio, tmp_old_name, NULL);
if (old_fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_rename\n");
ret = NFS3ERR_SERVERFAULT;
*new_ptr = 0;
new_ptr++;
- new_fh = lookup_fhandle(nfsio, tmp_new_name);
+ new_fh = lookup_fhandle(nfsio, tmp_new_name, NULL);
if (new_fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_rename\n");
ret = NFS3ERR_SERVERFAULT;
}
- old_fh = lookup_fhandle(nfsio, old);
+ old_fh = lookup_fhandle(nfsio, old, NULL);
if (old_fh == NULL) {
fprintf(stderr, "failed to fetch parent handle in nfsio_rename\n");
ret = NFS3ERR_SERVERFAULT;
}
- insert_fhandle(nfsio, new, old_fh->dptr, old_fh->dsize);
+ insert_fhandle(nfsio, new, old_fh->dptr, old_fh->dsize, 0 /*qqq*/);
delete_fhandle(nfsio, old);