int nfs_proc_readlink(struct nfs_server *server, struct nfs_fh *fhandle, int **p0, char **string, unsigned int *len, unsigned int maxlen) { int *p; int status, ruid = 0; PRINTK("NFS call readlink\n"); if (!(*p0 = nfs_rpc_alloc(server->rsize))) return -EIO; retry: p = nfs_rpc_header(*p0, NFSPROC_READLINK, ruid); p = xdr_encode_fhandle(p, fhandle); if ((status = nfs_rpc_call(server, *p0, p, server->rsize)) < 0) return status; if (!(p = nfs_rpc_verify(*p0))) status = -errno_NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { if (!(p = xdr_decode_string2(p, string, len, maxlen))) { printk("nfs_proc_readlink: giant pathname\n"); status = -errno_NFSERR_IO; } else /* status = 0, */ PRINTK("NFS reply readlink\n"); } else { if (!ruid && current->fsuid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply readlink failed = %d\n", status); status = -nfs_stat_to_errno(status); } return status; }
int nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *res) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call statfs\n"); if (!(p0 = nfs_rpc_alloc(server->rsize))) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_STATFS, ruid); p = xdr_encode_fhandle(p, fhandle); if ((status = nfs_rpc_call(server, p0, p, server->rsize)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = -errno_NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fsinfo(p, res); PRINTK("NFS reply statfs\n"); /* status = 0; */ } else { if (!ruid && current->fsuid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply statfs failed = %d\n", status); status = -nfs_stat_to_errno(status); } nfs_rpc_free(p0); return status; }
int nfs_proc_rmdir(struct nfs_server *server, struct nfs_fh *dir, const char *name) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call rmdir %s\n", name); if (!(p0 = nfs_rpc_alloc(server->wsize))) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_RMDIR, ruid); p = xdr_encode_fhandle(p, dir); p = xdr_encode_string(p, name); if ((status = nfs_rpc_call(server, p0, p, server->wsize)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = -errno_NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { PRINTK("NFS reply rmdir\n"); /* status = 0; */ } else { if (!ruid && current->fsuid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply rmdir failed = %d\n", status); status = -nfs_stat_to_errno(status); } nfs_rpc_free(p0); return status; }
int nfs_proc_symlink(struct nfs_server *server, struct nfs_fh *dir, const char *name, const char *path, struct nfs_sattr *sattr) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call symlink %s -> %s\n", name, path); if (!(p0 = nfs_rpc_alloc())) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_SYMLINK, ruid); p = xdr_encode_fhandle(p, dir); p = xdr_encode_string(p, name); p = xdr_encode_string(p, path); p = xdr_encode_sattr(p, sattr); if ((status = nfs_rpc_call(server, p0, p)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { PRINTK("NFS reply symlink\n"); } else { if (!ruid && current->euid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply symlink failed = %d\n", status); } nfs_rpc_free(p0); return -nfs_stat_to_errno(status); }
int nfs_proc_setattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_sattr *sattr, struct nfs_fattr *fattr) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call setattr\n"); if (!(p0 = nfs_rpc_alloc())) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_SETATTR, ruid); p = xdr_encode_fhandle(p, fhandle); p = xdr_encode_sattr(p, sattr); if ((status = nfs_rpc_call(server, p0, p)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fattr(p, fattr); PRINTK("NFS reply setattr\n"); } else { if (!ruid && current->euid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply setattr failed = %d\n", status); } nfs_rpc_free(p0); return -nfs_stat_to_errno(status); }
int nfs_proc_null(struct nfs_fh *fhandle) { int *p; int status; int ruid = 0; static int done = 0; int *p0; struct generic_server *server = fhandle->server; if (done && 0) {return 0;} else {done = 1;} DPRINTF(CLUHELP_LEVEL,("NFS call null\n")); if (!(p0 = overhead_rpc_alloc(server->rsize))) return -EIO; p = nfs_rpc_header(p0, NFSPROC_NULL, ruid); DPRINTF(CLUHELP_LEVEL,("ORIGNAL\n")); /* print_rpc2(p0,128); */ if ((status = generic_rpc_call(server, p0, p)) < 0) { printf("generic_rpc_call failed\n"); overhead_rpc_free(p0); return status; } if (!(p = generic_rpc_verify(p0))){ status = NFSERR_IO; printf("NP BAD NULL REQUEST %d\n",status); return -1; } overhead_rpc_free(p0); return 0; }
int nfs_proc_readdir(struct nfs_server *server, struct nfs_fh *fhandle, int cookie, int count, struct nfs_entry *entry) { int *p, *p0; int status; int ruid = 0; int i; int size; int eof; PRINTK("NFS call readdir %d @ %d\n", count, cookie); size = server->rsize; if (!(p0 = nfs_rpc_alloc(server->rsize))) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_READDIR, ruid); p = xdr_encode_fhandle(p, fhandle); *p++ = htonl(cookie); *p++ = htonl(size); if ((status = nfs_rpc_call(server, p0, p, server->rsize)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = -errno_NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { for (i = 0; i < count && *p++; i++) { if (!(p = xdr_decode_entry(p, entry++))) break; } if (!p) { printk("nfs_proc_readdir: giant filename\n"); status = -errno_NFSERR_IO; } else { eof = (i == count && !*p++ && *p++) || (i < count && *p++); if (eof && i) entry[-1].eof = 1; PRINTK("NFS reply readdir %d %s\n", i, eof ? "eof" : ""); status = i; } } else { if (!ruid && current->fsuid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply readdir failed = %d\n", status); status = -nfs_stat_to_errno(status); } nfs_rpc_free(p0); return status; }
int nfs_proc_read(struct nfs_server *server, struct nfs_fh *fhandle, int offset, int count, char *data, struct nfs_fattr *fattr, int fs) { int *p, *p0; int status; int ruid = 0; int len; PRINTK("NFS call read %d @ %d\n", count, offset); if (!(p0 = nfs_rpc_alloc(server->rsize))) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_READ, ruid); p = xdr_encode_fhandle(p, fhandle); *p++ = htonl(offset); *p++ = htonl(count); *p++ = htonl(count); /* traditional, could be any value */ if ((status = nfs_rpc_call(server, p0, p, server->rsize)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = -errno_NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fattr(p, fattr); if (!(p = xdr_decode_data(p, data, &len, count, fs))) { printk("nfs_proc_read: giant data size\n"); status = -errno_NFSERR_IO; } else { status = len; PRINTK("NFS reply read %d\n", len); } } else { if (!ruid && current->fsuid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply read failed = %d\n", status); status = -nfs_stat_to_errno(status); } nfs_rpc_free(p0); return status; }
/* not parallel */ int nfs_proc_read_np(struct nfs_fh *fhandle, int offset, int count, char *data, struct nfs_fattr *fattr) { int *p; int len = 0; int status; int ruid = 0; struct generic_server *server = fhandle->server; int *p0; DPRINTF(CLUHELP_LEVEL,("NFS call read %d @ %d\n", count, offset)); if (!(p0 = overhead_rpc_alloc(server->rsize))) return -EIO; p = nfs_rpc_header(p0, NFSPROC_READ, ruid); p = xdr_encode_fhandle(p, fhandle); *p++ = htonl(offset); *p++ = htonl(count); *p++ = htonl(count); /* traditional, could be any value */ DPRINTF(CLUHELP_LEVEL,("ORIGNAL\n")); /* print_rpc2(p0,128); */ if ((status = generic_rpc_call(server, p0, p)) < 0) { overhead_rpc_free(p0); return status; } if (!(p = generic_rpc_verify(p0))) status = NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fattr(p, fattr); if (!(p = xdr_decode_data(p, data, &len, count))) { DPRINTF(CLUHELP_LEVEL,("nfs_proc_read: giant data size\n")); status = NFSERR_IO; } else DPRINTF(CLUHELP_LEVEL,("NFS reply read %d\n", len)); } overhead_rpc_free(p0); return (status == NFS_OK) ? len : nfs_stat_to_errno(status); }
int nfs_proc_lookup(struct nfs_server *server, struct nfs_fh *dir, const char *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call lookup %s\n", name); #ifdef NFS_PROC_DEBUG if (!strcmp(name, "xyzzy")) proc_debug = 1 - proc_debug; #endif if (!(p0 = nfs_rpc_alloc(server->rsize))) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_LOOKUP, ruid); p = xdr_encode_fhandle(p, dir); p = xdr_encode_string(p, name); if ((status = nfs_rpc_call(server, p0, p, server->rsize)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = -errno_NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fhandle(p, fhandle); p = xdr_decode_fattr(p, fattr); PRINTK("NFS reply lookup\n"); /* status = 0; */ } else { if (!ruid && current->fsuid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply lookup failed = %d\n", status); status = -nfs_stat_to_errno(status); } nfs_rpc_free(p0); return status; }
int nfs_proc_write(struct nfs_server *server, struct nfs_fh *fhandle, int offset, int count, char *data, struct nfs_fattr *fattr) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call write %d @ %d\n", count, offset); if (!(p0 = nfs_rpc_alloc(server->wsize))) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_WRITE, ruid); p = xdr_encode_fhandle(p, fhandle); *p++ = htonl(offset); /* traditional, could be any value */ *p++ = htonl(offset); *p++ = htonl(count); /* traditional, could be any value */ p = xdr_encode_data(p, data, count); if ((status = nfs_rpc_call(server, p0, p, server->wsize)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = -errno_NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fattr(p, fattr); PRINTK("NFS reply write\n"); /* status = 0; */ } else { if (!ruid && current->fsuid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply write failed = %d\n", status); status = -nfs_stat_to_errno(status); } nfs_rpc_free(p0); return status; }
int nfs_proc_readlink(struct nfs_server *server, struct nfs_fh *fhandle, char *res) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call readlink\n"); if (!(p0 = nfs_rpc_alloc())) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_READLINK, ruid); p = xdr_encode_fhandle(p, fhandle); if ((status = nfs_rpc_call(server, p0, p)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { if (!(p = xdr_decode_string(p, res, NFS_MAXPATHLEN))) { printk("nfs_proc_readlink: giant pathname\n"); status = NFSERR_IO; } else PRINTK("NFS reply readlink %s\n", res); } else { if (!ruid && current->euid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply readlink failed = %d\n", status); } nfs_rpc_free(p0); return -nfs_stat_to_errno(status); }
int nfs_proc_rename(struct nfs_server *server, struct nfs_fh *old_dir, const char *old_name, struct nfs_fh *new_dir, const char *new_name) { int *p, *p0; int status; int ruid = 0; PRINTK("NFS call rename %s -> %s\n", old_name, new_name); if (!(p0 = nfs_rpc_alloc())) return -EIO; retry: p = nfs_rpc_header(p0, NFSPROC_RENAME, ruid); p = xdr_encode_fhandle(p, old_dir); p = xdr_encode_string(p, old_name); p = xdr_encode_fhandle(p, new_dir); p = xdr_encode_string(p, new_name); if ((status = nfs_rpc_call(server, p0, p)) < 0) { nfs_rpc_free(p0); return status; } if (!(p = nfs_rpc_verify(p0))) status = NFSERR_IO; else if ((status = ntohl(*p++)) == NFS_OK) { PRINTK("NFS reply rename\n"); } else { if (!ruid && current->euid == 0 && current->uid != 0) { ruid = 1; goto retry; } PRINTK("NFS reply rename failed = %d\n", status); } nfs_rpc_free(p0); return -nfs_stat_to_errno(status); }
int nfs_proc_writev(struct nfs_fh *fhandle, int offset, int count, struct ae_recv *r, struct nfs_fattr *fattr) { int *p; int status; int ruid = 0; struct generic_server *server = fhandle->server; char *tmp_data; int i; int wsize; /* to be used with new prpc */ int remaining_count = count; struct p_rpc *prpc; struct p_rpc_rec *rw; DPRINTF(CLUHELP_LEVEL,("NFS call write %p %d @ %d\n", r, count, offset)); wsize = server->wsize; if (!(prpc = p_overhead_rpc_alloc(wsize, count))) return -EIO; demand(count <= wsize, we only handle up to 8K for now); tmp_data = NULL; // data; for (i = 0; i < prpc->n ; i++) { static char overflow[4]; rw = &prpc->rw[i]; rw->start = nfs_rpc_header(rw->ptr, NFSPROC_WRITE, ruid); rw->start = xdr_encode_fhandle(rw->start, fhandle); *rw->start++ = htonl(offset + i*wsize); /* offset */ *rw->start++ = htonl(offset + i*wsize); /* offset */ rw->count = (remaining_count >= wsize) ? wsize : remaining_count; *rw->start++ = htonl(rw->count); /* count */ *rw->start++ = htonl(rw->count); /* data len */ rw->end = rw->start; rw->r.n = 1; rw->r = *r; if ((rw->count % 4) != 0) { rw->r.r[r->n].data = overflow; rw->r.r[r->n].sz = 4 - (rw->count % 4); rw->r.n++; } pr_ae_recv(&rw->r); tmp_data += rw->count; remaining_count -= rw->count; rw->xid = rw->ptr[0]; rw->done = 0; /* print_rpc2(prpc->rw[i].ptr,128); */ } /* pr_p_rpc(prpc); */ lprintf("p_generic_rpc_call start\n"); if ((status = p_generic_rpc_call(server,prpc)) < 0) { p_overhead_rpc_free(prpc); return status; } lprintf("p_generic_rpc_call done\n"); DPRINTF(CLUHELP_LEVEL,("P_GENERIC_RPC_CALL: %d\n",status)); for (i = 0; i < prpc->n ; i++) { rw = &prpc->rw[i]; if (!(p = generic_rpc_verify(rw->ptr))) { status = NFSERR_IO; break; } else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fattr(p, fattr); DPRINTF(CLUHELP_LEVEL,("NFS reply write xid: %d, count %d\n", rw->xid,rw->count)); } } DPRINTF(CLUHELP_LEVEL,("status: %d\n",status)); p_overhead_rpc_free(prpc); return nfs_stat_to_errno(status); }
int nfs_proc_read_p(struct nfs_fh *fhandle, int offset, int count, char *data, struct nfs_fattr *fattr) { int *p; int len = 0; int status; int ruid = 0; struct generic_server *server = fhandle->server; struct p_rpc *prpc; struct p_rpc_rec *rw; int i; int rsize; /* to be used with new prpc */ int remaining_count = count; int total_length = 0; char *tmp_data; char *tmp_data0; DPRINTF(CLUHELP_LEVEL,("NFS call read %d @ %d\n", count, offset)); rsize = server->rsize; //rsize = 1366; if ((offset < NFSMAXOFFSET) && ((offset % 4096) != 0)) { kprintf("warning non page aligned read: %d:%d\n",offset,count); } if (!(prpc = p_overhead_rpc_alloc(rsize, count))) return -EIO; for (i = 0; i < prpc->n ; i++) { rw = &prpc->rw[i]; rw->start = nfs_rpc_header(rw->ptr, NFSPROC_READ, ruid); rw->start = xdr_encode_fhandle(rw->start, fhandle); *rw->start++ = htonl(offset + i*rsize); /* offset */ *rw->start++ = htonl((remaining_count >= rsize) ? rsize : remaining_count); /* count */ rw->count = (remaining_count >= rsize) ? rsize : remaining_count; remaining_count -= rsize; *rw->start++ = htonl(rsize); /* traditional, could be any value */ rw->end = rw->start; rw->r.n = 0; rw->xid = rw->ptr[0]; rw->done = 0; /* print_rpc2(prpc->rw[i].ptr,128); */ } /* pr_p_rpc(prpc); */ if ((status = p_generic_rpc_call(server,prpc)) < 0) { p_overhead_rpc_free(prpc); return status; } DPRINTF(CLUHELP_LEVEL,("P_GENERIC_RPC_CALL: %d\n",status)); tmp_data = tmp_data0 = data; for (i = 0; i < prpc->n ; i++) { rw = &prpc->rw[i]; if (!(p = generic_rpc_verify(rw->ptr))) { status = NFSERR_IO; break; } else if ((status = ntohl(*p++)) == NFS_OK) { p = xdr_decode_fattr(p, fattr); if (!(p = xdr_decode_data(p, tmp_data, &len, rw->count))) { DPRINTF(CLUHELP_LEVEL,("nfs_proc_read: giant data size\n")); status = NFSERR_IO; break; } else { DPRINTF(CLUHELP_LEVEL,("NFS reply read xid: %d, length: %d count %d\n", rw->xid,len,rw->count)); tmp_data += len; total_length += len; } } } DPRINTF(CLUHELP_LEVEL,("status: %d\n",status)); p_overhead_rpc_free(prpc); return (status == NFS_OK) ? total_length : nfs_stat_to_errno(status); }