X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=nfs3%2Fnfs3.c;h=95185e59022fa23f33aec8de46afbb611bd61225;hb=386250b1e7b69e1050b8eb96402ea764dbc77b25;hp=aaf23b4d6733747783e21b7623bf2d1bef3bb1b6;hpb=9bf82653d36b735f835d78112c067030de77c9c5;p=bluesky.git diff --git a/nfs3/nfs3.c b/nfs3/nfs3.c index aaf23b4..95185e5 100644 --- a/nfs3/nfs3.c +++ b/nfs3/nfs3.c @@ -188,8 +188,35 @@ read3res * nfsproc3_read_3_svc(read3args *argp, struct svc_req *rqstp) { static read3res result; + static char buf[32768]; - result.status = NFS3ERR_NOTSUPP; + BlueSkyInode *inode = lookup_fh(&argp->file); + if (inode == NULL) { + result.status = NFS3ERR_STALE; + result.read3res_u.resfail.present = FALSE; + return &result; + } + + int count = argp->count; + if (argp->offset >= inode->size) { + count = 0; + result.read3res_u.resok.eof = TRUE; + } else { + count = MIN(count, inode->size - argp->offset); + if (argp->offset + count == inode->size) + result.read3res_u.resok.eof = TRUE; + else + result.read3res_u.resok.eof = FALSE; + + bluesky_file_read(inode, argp->offset, buf, count); + } + + result.status = NFS3_OK; + result.read3res_u.resok.file_attributes.present = TRUE; + encode_fattr3(&result.read3res_u.resok.file_attributes.post_op_attr_u.attributes, inode); + result.read3res_u.resok.count = count; + result.read3res_u.resok.data.data_val = buf; + result.read3res_u.resok.data.data_len = count; return &result; } @@ -198,8 +225,39 @@ write3res * nfsproc3_write_3_svc(write3args *argp, struct svc_req *rqstp) { static write3res result; + struct wcc_data wcc; + memset(&wcc, 0, sizeof(wcc)); - result.status = NFS3ERR_NOTSUPP; + BlueSkyInode *inode = lookup_fh(&argp->file); + if (inode == NULL) { + result.status = NFS3ERR_STALE; + result.write3res_u.resfail = wcc; + return &result; + } + + encode_pre_wcc(&wcc, inode); + if (inode->type != BLUESKY_REGULAR) { + result.status = NFS3ERR_INVAL; + result.write3res_u.resfail = wcc; + return &result; + } + + uint64_t lastbyte = argp->offset + argp->count; + if (lastbyte > inode->size) { + bluesky_file_truncate(inode, lastbyte); + } + + if (argp->data.data_len < argp->count) { + /* ??? */ + } else { + bluesky_file_write(inode, argp->offset, + argp->data.data_val, argp->count); + } + + encode_fattr3(&wcc.after.post_op_attr_u.attributes, inode); + result.write3res_u.resok.file_wcc = wcc; + result.write3res_u.resok.count = argp->count; + result.write3res_u.resok.committed = FILE_SYNC; return &result; } @@ -364,7 +422,7 @@ nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp) BlueSkyDirent *d = g_sequence_get(i); dirents[count].fileid = d->inum; dirents[count].name = d->name; - dirents[count].cookie = d->hash; + dirents[count].cookie = d->cookie; dirents[count].nextentry = NULL; if (count > 0) dirents[count - 1].nextentry = &dirents[count];