mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 19:21:31 -04:00
9p: Reorganization of 9p file system code
This patchset moves non-filesystem interfaces of v9fs from fs/9p to net/9p. It moves the transport, packet marshalling and connection layers to net/9p leaving only the VFS related files in fs/9p. This work is being done in preparation for in-kernel 9p servers as well as alternate 9p clients (other than VFS). Signed-off-by: Latchesar Ionkov <[email protected]> Signed-off-by: Eric Van Hensbergen <[email protected]>
This commit is contained in:
parent
8d9107e8c5
commit
bd238fb431
36 changed files with 3423 additions and 3131 deletions
21
net/9p/Kconfig
Normal file
21
net/9p/Kconfig
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# 9P protocol configuration
|
||||
#
|
||||
|
||||
menuconfig NET_9P
|
||||
depends on NET && EXPERIMENTAL
|
||||
tristate "Plan 9 Resource Sharing Support (9P2000) (Experimental)"
|
||||
help
|
||||
If you say Y here, you will get experimental support for
|
||||
Plan 9 resource sharing via the 9P2000 protocol.
|
||||
|
||||
See <http://v9fs.sf.net> for more information.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config NET_9P_DEBUG
|
||||
bool "Debug information"
|
||||
depends on NET_9P
|
||||
help
|
||||
Say Y if you want the 9P subsistem to log debug information.
|
||||
|
||||
13
net/9p/Makefile
Normal file
13
net/9p/Makefile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
obj-$(CONFIG_NET_9P) := 9p.o
|
||||
|
||||
9p-objs := \
|
||||
mod.o \
|
||||
trans_fd.o \
|
||||
mux.o \
|
||||
client.o \
|
||||
conv.o \
|
||||
error.o \
|
||||
fcprint.o \
|
||||
util.o \
|
||||
|
||||
9p-$(CONFIG_SYSCTL) += sysctl.o
|
||||
965
net/9p/client.c
Normal file
965
net/9p/client.c
Normal file
|
|
@ -0,0 +1,965 @@
|
|||
/*
|
||||
* net/9p/clnt.c
|
||||
*
|
||||
* 9P Client
|
||||
*
|
||||
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/idr.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <net/9p/9p.h>
|
||||
#include <net/9p/transport.h>
|
||||
#include <net/9p/conn.h>
|
||||
#include <net/9p/client.h>
|
||||
|
||||
static struct p9_fid *p9_fid_create(struct p9_client *clnt);
|
||||
static void p9_fid_destroy(struct p9_fid *fid);
|
||||
static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu);
|
||||
|
||||
struct p9_client *p9_client_create(struct p9_transport *trans, int msize,
|
||||
int dotu)
|
||||
{
|
||||
int err, n;
|
||||
struct p9_client *clnt;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_str *version;
|
||||
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = kmalloc(sizeof(struct p9_client), GFP_KERNEL);
|
||||
if (!clnt)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "clnt %p trans %p msize %d dotu %d\n",
|
||||
clnt, trans, msize, dotu);
|
||||
spin_lock_init(&clnt->lock);
|
||||
clnt->trans = trans;
|
||||
clnt->msize = msize;
|
||||
clnt->dotu = dotu;
|
||||
INIT_LIST_HEAD(&clnt->fidlist);
|
||||
clnt->fidpool = p9_idpool_create();
|
||||
if (!clnt->fidpool) {
|
||||
err = PTR_ERR(clnt->fidpool);
|
||||
clnt->fidpool = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
clnt->conn = p9_conn_create(clnt->trans, clnt->msize, &clnt->dotu);
|
||||
if (IS_ERR(clnt->conn)) {
|
||||
err = PTR_ERR(clnt->conn);
|
||||
clnt->conn = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
tc = p9_create_tversion(clnt->msize, clnt->dotu?"9P2000.u":"9P2000");
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
version = &rc->params.rversion.version;
|
||||
if (version->len == 8 && !memcmp(version->str, "9P2000.u", 8))
|
||||
clnt->dotu = 1;
|
||||
else if (version->len == 6 && !memcmp(version->str, "9P2000", 6))
|
||||
clnt->dotu = 0;
|
||||
else {
|
||||
err = -EREMOTEIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
n = rc->params.rversion.msize;
|
||||
if (n < clnt->msize)
|
||||
clnt->msize = n;
|
||||
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return clnt;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
p9_client_destroy(clnt);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_create);
|
||||
|
||||
void p9_client_destroy(struct p9_client *clnt)
|
||||
{
|
||||
struct p9_fid *fid, *fidptr;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
|
||||
if (clnt->conn) {
|
||||
p9_conn_destroy(clnt->conn);
|
||||
clnt->conn = NULL;
|
||||
}
|
||||
|
||||
if (clnt->trans) {
|
||||
clnt->trans->close(clnt->trans);
|
||||
kfree(clnt->trans);
|
||||
clnt->trans = NULL;
|
||||
}
|
||||
|
||||
if (clnt->fidpool)
|
||||
p9_idpool_destroy(clnt->fidpool);
|
||||
|
||||
list_for_each_entry_safe(fid, fidptr, &clnt->fidlist, flist)
|
||||
p9_fid_destroy(fid);
|
||||
|
||||
kfree(clnt);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_destroy);
|
||||
|
||||
void p9_client_disconnect(struct p9_client *clnt)
|
||||
{
|
||||
P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
|
||||
clnt->trans->status = Disconnected;
|
||||
p9_conn_cancel(clnt->conn, -EIO);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_disconnect);
|
||||
|
||||
struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
|
||||
char *uname, char *aname)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_fid *fid;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "clnt %p afid %d uname %s aname %s\n",
|
||||
clnt, afid?afid->fid:-1, uname, aname);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
|
||||
fid = p9_fid_create(clnt);
|
||||
if (IS_ERR(fid)) {
|
||||
err = PTR_ERR(fid);
|
||||
fid = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
tc = p9_create_tattach(fid->fid, afid?afid->fid:P9_NOFID, uname, aname);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
memmove(&fid->qid, &rc->params.rattach.qid, sizeof(struct p9_qid));
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return fid;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
if (fid)
|
||||
p9_fid_destroy(fid);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_attach);
|
||||
|
||||
struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname, char *aname)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_fid *fid;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "clnt %p uname %s aname %s\n", clnt, uname,
|
||||
aname);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
|
||||
fid = p9_fid_create(clnt);
|
||||
if (IS_ERR(fid)) {
|
||||
err = PTR_ERR(fid);
|
||||
fid = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
tc = p9_create_tauth(fid->fid, uname, aname);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
memmove(&fid->qid, &rc->params.rauth.qid, sizeof(struct p9_qid));
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return fid;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
if (fid)
|
||||
p9_fid_destroy(fid);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_auth);
|
||||
|
||||
struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
|
||||
int clone)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
struct p9_fid *fid;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d nwname %d wname[0] %s\n",
|
||||
oldfid->fid, nwname, wnames?wnames[0]:NULL);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = oldfid->clnt;
|
||||
if (clone) {
|
||||
fid = p9_fid_create(clnt);
|
||||
if (IS_ERR(fid)) {
|
||||
err = PTR_ERR(fid);
|
||||
fid = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
fid->uid = oldfid->uid;
|
||||
} else
|
||||
fid = oldfid;
|
||||
|
||||
tc = p9_create_twalk(oldfid->fid, fid->fid, nwname, wnames);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err) {
|
||||
if (rc && rc->id == P9_RWALK)
|
||||
goto clunk_fid;
|
||||
else
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (rc->params.rwalk.nwqid != nwname) {
|
||||
err = -ENOENT;
|
||||
goto clunk_fid;
|
||||
}
|
||||
|
||||
if (nwname)
|
||||
memmove(&fid->qid,
|
||||
&rc->params.rwalk.wqids[rc->params.rwalk.nwqid - 1],
|
||||
sizeof(struct p9_qid));
|
||||
else
|
||||
fid->qid = oldfid->qid;
|
||||
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return fid;
|
||||
|
||||
clunk_fid:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
rc = NULL;
|
||||
tc = p9_create_tclunk(fid->fid);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
if (fid && (fid != oldfid))
|
||||
p9_fid_destroy(fid);
|
||||
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_walk);
|
||||
|
||||
int p9_client_open(struct p9_fid *fid, int mode)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d mode %d\n", fid->fid, mode);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
|
||||
if (fid->mode != -1)
|
||||
return -EINVAL;
|
||||
|
||||
tc = p9_create_topen(fid->fid, mode);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto done;
|
||||
|
||||
fid->mode = mode;
|
||||
fid->iounit = rc->params.ropen.iounit;
|
||||
|
||||
done:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_open);
|
||||
|
||||
int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
|
||||
char *extension)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d name %s perm %d mode %d\n", fid->fid,
|
||||
name, perm, mode);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
|
||||
if (fid->mode != -1)
|
||||
return -EINVAL;
|
||||
|
||||
tc = p9_create_tcreate(fid->fid, name, perm, mode, extension,
|
||||
clnt->dotu);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto done;
|
||||
|
||||
fid->mode = mode;
|
||||
fid->iounit = rc->params.ropen.iounit;
|
||||
|
||||
done:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_fcreate);
|
||||
|
||||
int p9_client_clunk(struct p9_fid *fid)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
|
||||
tc = p9_create_tclunk(fid->fid);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto done;
|
||||
|
||||
p9_fid_destroy(fid);
|
||||
|
||||
done:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_clunk);
|
||||
|
||||
int p9_client_remove(struct p9_fid *fid)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
|
||||
tc = p9_create_tremove(fid->fid);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto done;
|
||||
|
||||
p9_fid_destroy(fid);
|
||||
|
||||
done:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_remove);
|
||||
|
||||
int p9_client_read(struct p9_fid *fid, char *data, u64 offset, u32 count)
|
||||
{
|
||||
int err, n, rsize, total;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu %d\n", fid->fid,
|
||||
(long long unsigned) offset, count);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
total = 0;
|
||||
|
||||
rsize = fid->iounit;
|
||||
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
|
||||
rsize = clnt->msize - P9_IOHDRSZ;
|
||||
|
||||
do {
|
||||
if (count < rsize)
|
||||
rsize = count;
|
||||
|
||||
tc = p9_create_tread(fid->fid, offset, rsize);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
n = rc->params.rread.count;
|
||||
if (n > count)
|
||||
n = count;
|
||||
|
||||
memmove(data, rc->params.rread.data, n);
|
||||
count -= n;
|
||||
data += n;
|
||||
offset += n;
|
||||
total += n;
|
||||
kfree(tc);
|
||||
tc = NULL;
|
||||
kfree(rc);
|
||||
rc = NULL;
|
||||
} while (count > 0 && n == rsize);
|
||||
|
||||
return total;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_read);
|
||||
|
||||
int p9_client_write(struct p9_fid *fid, char *data, u64 offset, u32 count)
|
||||
{
|
||||
int err, n, rsize, total;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
|
||||
(long long unsigned) offset, count);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
total = 0;
|
||||
|
||||
rsize = fid->iounit;
|
||||
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
|
||||
rsize = clnt->msize - P9_IOHDRSZ;
|
||||
|
||||
do {
|
||||
if (count < rsize)
|
||||
rsize = count;
|
||||
|
||||
tc = p9_create_twrite(fid->fid, offset, rsize, data);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
n = rc->params.rread.count;
|
||||
count -= n;
|
||||
data += n;
|
||||
offset += n;
|
||||
total += n;
|
||||
kfree(tc);
|
||||
tc = NULL;
|
||||
kfree(rc);
|
||||
rc = NULL;
|
||||
} while (count > 0);
|
||||
|
||||
return total;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_write);
|
||||
|
||||
int
|
||||
p9_client_uread(struct p9_fid *fid, char __user *data, u64 offset, u32 count)
|
||||
{
|
||||
int err, n, rsize, total;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
|
||||
(long long unsigned) offset, count);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
total = 0;
|
||||
|
||||
rsize = fid->iounit;
|
||||
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
|
||||
rsize = clnt->msize - P9_IOHDRSZ;
|
||||
|
||||
do {
|
||||
if (count < rsize)
|
||||
rsize = count;
|
||||
|
||||
tc = p9_create_tread(fid->fid, offset, rsize);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
n = rc->params.rread.count;
|
||||
if (n > count)
|
||||
n = count;
|
||||
|
||||
err = copy_to_user(data, rc->params.rread.data, n);
|
||||
if (err) {
|
||||
err = -EFAULT;
|
||||
goto error;
|
||||
}
|
||||
|
||||
count -= n;
|
||||
data += n;
|
||||
offset += n;
|
||||
total += n;
|
||||
kfree(tc);
|
||||
tc = NULL;
|
||||
kfree(rc);
|
||||
rc = NULL;
|
||||
} while (count > 0 && n == rsize);
|
||||
|
||||
return total;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_uread);
|
||||
|
||||
int
|
||||
p9_client_uwrite(struct p9_fid *fid, const char __user *data, u64 offset,
|
||||
u32 count)
|
||||
{
|
||||
int err, n, rsize, total;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
|
||||
(long long unsigned) offset, count);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
total = 0;
|
||||
|
||||
rsize = fid->iounit;
|
||||
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
|
||||
rsize = clnt->msize - P9_IOHDRSZ;
|
||||
|
||||
do {
|
||||
if (count < rsize)
|
||||
rsize = count;
|
||||
|
||||
tc = p9_create_twrite_u(fid->fid, offset, rsize, data);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
n = rc->params.rread.count;
|
||||
count -= n;
|
||||
data += n;
|
||||
offset += n;
|
||||
total += n;
|
||||
kfree(tc);
|
||||
tc = NULL;
|
||||
kfree(rc);
|
||||
rc = NULL;
|
||||
} while (count > 0);
|
||||
|
||||
return total;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_uwrite);
|
||||
|
||||
int p9_client_readn(struct p9_fid *fid, char *data, u64 offset, u32 count)
|
||||
{
|
||||
int n, total;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
|
||||
(long long unsigned) offset, count);
|
||||
n = 0;
|
||||
total = 0;
|
||||
while (count) {
|
||||
n = p9_client_read(fid, data, offset, count);
|
||||
if (n <= 0)
|
||||
break;
|
||||
|
||||
data += n;
|
||||
offset += n;
|
||||
count -= n;
|
||||
total += n;
|
||||
}
|
||||
|
||||
if (n < 0)
|
||||
total = n;
|
||||
|
||||
return total;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_readn);
|
||||
|
||||
struct p9_stat *p9_client_stat(struct p9_fid *fid)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
struct p9_stat *ret;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
ret = NULL;
|
||||
clnt = fid->clnt;
|
||||
|
||||
tc = p9_create_tstat(fid->fid);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
ret = p9_clone_stat(&rc->params.rstat.stat, clnt->dotu);
|
||||
if (IS_ERR(ret)) {
|
||||
err = PTR_ERR(ret);
|
||||
ret = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
kfree(ret);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_stat);
|
||||
|
||||
int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst)
|
||||
{
|
||||
int err;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
clnt = fid->clnt;
|
||||
|
||||
tc = p9_create_twstat(fid->fid, wst, clnt->dotu);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
|
||||
done:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_wstat);
|
||||
|
||||
struct p9_stat *p9_client_dirread(struct p9_fid *fid, u64 offset)
|
||||
{
|
||||
int err, n, m;
|
||||
struct p9_fcall *tc, *rc;
|
||||
struct p9_client *clnt;
|
||||
struct p9_stat st, *ret;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu\n", fid->fid,
|
||||
(long long unsigned) offset);
|
||||
err = 0;
|
||||
tc = NULL;
|
||||
rc = NULL;
|
||||
ret = NULL;
|
||||
clnt = fid->clnt;
|
||||
|
||||
/* if the offset is below or above the current response, free it */
|
||||
if (offset < fid->rdir_fpos || (fid->rdir_fcall &&
|
||||
offset >= fid->rdir_fpos+fid->rdir_fcall->params.rread.count)) {
|
||||
fid->rdir_pos = 0;
|
||||
if (fid->rdir_fcall)
|
||||
fid->rdir_fpos += fid->rdir_fcall->params.rread.count;
|
||||
|
||||
kfree(fid->rdir_fcall);
|
||||
fid->rdir_fcall = NULL;
|
||||
if (offset < fid->rdir_fpos)
|
||||
fid->rdir_fpos = 0;
|
||||
}
|
||||
|
||||
if (!fid->rdir_fcall) {
|
||||
n = fid->iounit;
|
||||
if (!n || n > clnt->msize-P9_IOHDRSZ)
|
||||
n = clnt->msize - P9_IOHDRSZ;
|
||||
|
||||
while (1) {
|
||||
if (fid->rdir_fcall) {
|
||||
fid->rdir_fpos +=
|
||||
fid->rdir_fcall->params.rread.count;
|
||||
kfree(fid->rdir_fcall);
|
||||
fid->rdir_fcall = NULL;
|
||||
}
|
||||
|
||||
tc = p9_create_tread(fid->fid, fid->rdir_fpos, n);
|
||||
if (IS_ERR(tc)) {
|
||||
err = PTR_ERR(tc);
|
||||
tc = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_conn_rpc(clnt->conn, tc, &rc);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
n = rc->params.rread.count;
|
||||
if (n == 0)
|
||||
goto done;
|
||||
|
||||
fid->rdir_fcall = rc;
|
||||
rc = NULL;
|
||||
if (offset >= fid->rdir_fpos &&
|
||||
offset < fid->rdir_fpos+n)
|
||||
break;
|
||||
}
|
||||
|
||||
fid->rdir_pos = 0;
|
||||
}
|
||||
|
||||
m = offset - fid->rdir_fpos;
|
||||
if (m < 0)
|
||||
goto done;
|
||||
|
||||
n = p9_deserialize_stat(fid->rdir_fcall->params.rread.data + m,
|
||||
fid->rdir_fcall->params.rread.count - m, &st, clnt->dotu);
|
||||
|
||||
if (!n) {
|
||||
err = -EIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
fid->rdir_pos += n;
|
||||
st.size = n;
|
||||
ret = p9_clone_stat(&st, clnt->dotu);
|
||||
if (IS_ERR(ret)) {
|
||||
err = PTR_ERR(ret);
|
||||
ret = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
done:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
kfree(tc);
|
||||
kfree(rc);
|
||||
kfree(ret);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_client_dirread);
|
||||
|
||||
static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu)
|
||||
{
|
||||
int n;
|
||||
char *p;
|
||||
struct p9_stat *ret;
|
||||
|
||||
n = sizeof(struct p9_stat) + st->name.len + st->uid.len + st->gid.len +
|
||||
st->muid.len;
|
||||
|
||||
if (dotu)
|
||||
n += st->extension.len;
|
||||
|
||||
ret = kmalloc(n, GFP_KERNEL);
|
||||
if (!ret)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
memmove(ret, st, sizeof(struct p9_stat));
|
||||
p = ((char *) ret) + sizeof(struct p9_stat);
|
||||
memmove(p, st->name.str, st->name.len);
|
||||
p += st->name.len;
|
||||
memmove(p, st->uid.str, st->uid.len);
|
||||
p += st->uid.len;
|
||||
memmove(p, st->gid.str, st->gid.len);
|
||||
p += st->gid.len;
|
||||
memmove(p, st->muid.str, st->muid.len);
|
||||
p += st->muid.len;
|
||||
|
||||
if (dotu) {
|
||||
memmove(p, st->extension.str, st->extension.len);
|
||||
p += st->extension.len;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct p9_fid *p9_fid_create(struct p9_client *clnt)
|
||||
{
|
||||
int err;
|
||||
struct p9_fid *fid;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
|
||||
fid = kmalloc(sizeof(struct p9_fid), GFP_KERNEL);
|
||||
if (!fid)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
fid->fid = p9_idpool_get(clnt->fidpool);
|
||||
if (fid->fid < 0) {
|
||||
err = -ENOSPC;
|
||||
goto error;
|
||||
}
|
||||
|
||||
memset(&fid->qid, 0, sizeof(struct p9_qid));
|
||||
fid->mode = -1;
|
||||
fid->rdir_fpos = 0;
|
||||
fid->rdir_pos = 0;
|
||||
fid->rdir_fcall = NULL;
|
||||
fid->uid = current->fsuid;
|
||||
fid->clnt = clnt;
|
||||
fid->aux = NULL;
|
||||
|
||||
spin_lock(&clnt->lock);
|
||||
list_add(&fid->flist, &clnt->fidlist);
|
||||
spin_unlock(&clnt->lock);
|
||||
|
||||
return fid;
|
||||
|
||||
error:
|
||||
kfree(fid);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
static void p9_fid_destroy(struct p9_fid *fid)
|
||||
{
|
||||
struct p9_client *clnt;
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_9P, "fid %d\n", fid->fid);
|
||||
clnt = fid->clnt;
|
||||
p9_idpool_put(fid->fid, clnt->fidpool);
|
||||
spin_lock(&clnt->lock);
|
||||
list_del(&fid->flist);
|
||||
spin_unlock(&clnt->lock);
|
||||
kfree(fid->rdir_fcall);
|
||||
kfree(fid);
|
||||
}
|
||||
903
net/9p/conv.c
Normal file
903
net/9p/conv.c
Normal file
|
|
@ -0,0 +1,903 @@
|
|||
/*
|
||||
* net/9p/conv.c
|
||||
*
|
||||
* 9P protocol conversion functions
|
||||
*
|
||||
* Copyright (C) 2004, 2005 by Latchesar Ionkov <lucho@ionkov.net>
|
||||
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
|
||||
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/idr.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <net/9p/9p.h>
|
||||
|
||||
/*
|
||||
* Buffer to help with string parsing
|
||||
*/
|
||||
struct cbuf {
|
||||
unsigned char *sp;
|
||||
unsigned char *p;
|
||||
unsigned char *ep;
|
||||
};
|
||||
|
||||
static inline void buf_init(struct cbuf *buf, void *data, int datalen)
|
||||
{
|
||||
buf->sp = buf->p = data;
|
||||
buf->ep = data + datalen;
|
||||
}
|
||||
|
||||
static inline int buf_check_overflow(struct cbuf *buf)
|
||||
{
|
||||
return buf->p > buf->ep;
|
||||
}
|
||||
|
||||
static int buf_check_size(struct cbuf *buf, int len)
|
||||
{
|
||||
if (buf->p + len > buf->ep) {
|
||||
if (buf->p < buf->ep) {
|
||||
P9_EPRINTK(KERN_ERR,
|
||||
"buffer overflow: want %d has %d\n", len,
|
||||
(int)(buf->ep - buf->p));
|
||||
dump_stack();
|
||||
buf->p = buf->ep + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void *buf_alloc(struct cbuf *buf, int len)
|
||||
{
|
||||
void *ret = NULL;
|
||||
|
||||
if (buf_check_size(buf, len)) {
|
||||
ret = buf->p;
|
||||
buf->p += len;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void buf_put_int8(struct cbuf *buf, u8 val)
|
||||
{
|
||||
if (buf_check_size(buf, 1)) {
|
||||
buf->p[0] = val;
|
||||
buf->p++;
|
||||
}
|
||||
}
|
||||
|
||||
static void buf_put_int16(struct cbuf *buf, u16 val)
|
||||
{
|
||||
if (buf_check_size(buf, 2)) {
|
||||
*(__le16 *) buf->p = cpu_to_le16(val);
|
||||
buf->p += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void buf_put_int32(struct cbuf *buf, u32 val)
|
||||
{
|
||||
if (buf_check_size(buf, 4)) {
|
||||
*(__le32 *)buf->p = cpu_to_le32(val);
|
||||
buf->p += 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void buf_put_int64(struct cbuf *buf, u64 val)
|
||||
{
|
||||
if (buf_check_size(buf, 8)) {
|
||||
*(__le64 *)buf->p = cpu_to_le64(val);
|
||||
buf->p += 8;
|
||||
}
|
||||
}
|
||||
|
||||
static char *buf_put_stringn(struct cbuf *buf, const char *s, u16 slen)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
ret = NULL;
|
||||
if (buf_check_size(buf, slen + 2)) {
|
||||
buf_put_int16(buf, slen);
|
||||
ret = buf->p;
|
||||
memcpy(buf->p, s, slen);
|
||||
buf->p += slen;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void buf_put_string(struct cbuf *buf, const char *s)
|
||||
{
|
||||
buf_put_stringn(buf, s, strlen(s));
|
||||
}
|
||||
|
||||
static u8 buf_get_int8(struct cbuf *buf)
|
||||
{
|
||||
u8 ret = 0;
|
||||
|
||||
if (buf_check_size(buf, 1)) {
|
||||
ret = buf->p[0];
|
||||
buf->p++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u16 buf_get_int16(struct cbuf *buf)
|
||||
{
|
||||
u16 ret = 0;
|
||||
|
||||
if (buf_check_size(buf, 2)) {
|
||||
ret = le16_to_cpu(*(__le16 *)buf->p);
|
||||
buf->p += 2;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u32 buf_get_int32(struct cbuf *buf)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
if (buf_check_size(buf, 4)) {
|
||||
ret = le32_to_cpu(*(__le32 *)buf->p);
|
||||
buf->p += 4;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u64 buf_get_int64(struct cbuf *buf)
|
||||
{
|
||||
u64 ret = 0;
|
||||
|
||||
if (buf_check_size(buf, 8)) {
|
||||
ret = le64_to_cpu(*(__le64 *)buf->p);
|
||||
buf->p += 8;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void buf_get_str(struct cbuf *buf, struct p9_str *vstr)
|
||||
{
|
||||
vstr->len = buf_get_int16(buf);
|
||||
if (!buf_check_overflow(buf) && buf_check_size(buf, vstr->len)) {
|
||||
vstr->str = buf->p;
|
||||
buf->p += vstr->len;
|
||||
} else {
|
||||
vstr->len = 0;
|
||||
vstr->str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void buf_get_qid(struct cbuf *bufp, struct p9_qid *qid)
|
||||
{
|
||||
qid->type = buf_get_int8(bufp);
|
||||
qid->version = buf_get_int32(bufp);
|
||||
qid->path = buf_get_int64(bufp);
|
||||
}
|
||||
|
||||
/**
|
||||
* p9_size_wstat - calculate the size of a variable length stat struct
|
||||
* @stat: metadata (stat) structure
|
||||
* @dotu: non-zero if 9P2000.u
|
||||
*
|
||||
*/
|
||||
|
||||
static int p9_size_wstat(struct p9_wstat *wstat, int dotu)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
if (wstat == NULL) {
|
||||
P9_EPRINTK(KERN_ERR, "p9_size_stat: got a NULL stat pointer\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = /* 2 + *//* size[2] */
|
||||
2 + /* type[2] */
|
||||
4 + /* dev[4] */
|
||||
1 + /* qid.type[1] */
|
||||
4 + /* qid.vers[4] */
|
||||
8 + /* qid.path[8] */
|
||||
4 + /* mode[4] */
|
||||
4 + /* atime[4] */
|
||||
4 + /* mtime[4] */
|
||||
8 + /* length[8] */
|
||||
8; /* minimum sum of string lengths */
|
||||
|
||||
if (wstat->name)
|
||||
size += strlen(wstat->name);
|
||||
if (wstat->uid)
|
||||
size += strlen(wstat->uid);
|
||||
if (wstat->gid)
|
||||
size += strlen(wstat->gid);
|
||||
if (wstat->muid)
|
||||
size += strlen(wstat->muid);
|
||||
|
||||
if (dotu) {
|
||||
size += 4 + /* n_uid[4] */
|
||||
4 + /* n_gid[4] */
|
||||
4 + /* n_muid[4] */
|
||||
2; /* string length of extension[4] */
|
||||
if (wstat->extension)
|
||||
size += strlen(wstat->extension);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* buf_get_stat - safely decode a recieved metadata (stat) structure
|
||||
* @bufp: buffer to deserialize
|
||||
* @stat: metadata (stat) structure
|
||||
* @dotu: non-zero if 9P2000.u
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
buf_get_stat(struct cbuf *bufp, struct p9_stat *stat, int dotu)
|
||||
{
|
||||
stat->size = buf_get_int16(bufp);
|
||||
stat->type = buf_get_int16(bufp);
|
||||
stat->dev = buf_get_int32(bufp);
|
||||
stat->qid.type = buf_get_int8(bufp);
|
||||
stat->qid.version = buf_get_int32(bufp);
|
||||
stat->qid.path = buf_get_int64(bufp);
|
||||
stat->mode = buf_get_int32(bufp);
|
||||
stat->atime = buf_get_int32(bufp);
|
||||
stat->mtime = buf_get_int32(bufp);
|
||||
stat->length = buf_get_int64(bufp);
|
||||
buf_get_str(bufp, &stat->name);
|
||||
buf_get_str(bufp, &stat->uid);
|
||||
buf_get_str(bufp, &stat->gid);
|
||||
buf_get_str(bufp, &stat->muid);
|
||||
|
||||
if (dotu) {
|
||||
buf_get_str(bufp, &stat->extension);
|
||||
stat->n_uid = buf_get_int32(bufp);
|
||||
stat->n_gid = buf_get_int32(bufp);
|
||||
stat->n_muid = buf_get_int32(bufp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* p9_deserialize_stat - decode a received metadata structure
|
||||
* @buf: buffer to deserialize
|
||||
* @buflen: length of received buffer
|
||||
* @stat: metadata structure to decode into
|
||||
* @dotu: non-zero if 9P2000.u
|
||||
*
|
||||
* Note: stat will point to the buf region.
|
||||
*/
|
||||
|
||||
int
|
||||
p9_deserialize_stat(void *buf, u32 buflen, struct p9_stat *stat,
|
||||
int dotu)
|
||||
{
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
unsigned char *p;
|
||||
|
||||
buf_init(bufp, buf, buflen);
|
||||
p = bufp->p;
|
||||
buf_get_stat(bufp, stat, dotu);
|
||||
|
||||
if (buf_check_overflow(bufp))
|
||||
return 0;
|
||||
else
|
||||
return bufp->p - p;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_deserialize_stat);
|
||||
|
||||
/**
|
||||
* deserialize_fcall - unmarshal a response
|
||||
* @buf: recieved buffer
|
||||
* @buflen: length of received buffer
|
||||
* @rcall: fcall structure to populate
|
||||
* @rcalllen: length of fcall structure to populate
|
||||
* @dotu: non-zero if 9P2000.u
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
p9_deserialize_fcall(void *buf, u32 buflen, struct p9_fcall *rcall,
|
||||
int dotu)
|
||||
{
|
||||
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
int i = 0;
|
||||
|
||||
buf_init(bufp, buf, buflen);
|
||||
|
||||
rcall->size = buf_get_int32(bufp);
|
||||
rcall->id = buf_get_int8(bufp);
|
||||
rcall->tag = buf_get_int16(bufp);
|
||||
|
||||
P9_DPRINTK(P9_DEBUG_CONV, "size %d id %d tag %d\n", rcall->size,
|
||||
rcall->id, rcall->tag);
|
||||
|
||||
switch (rcall->id) {
|
||||
default:
|
||||
P9_EPRINTK(KERN_ERR, "unknown message type: %d\n", rcall->id);
|
||||
return -EPROTO;
|
||||
case P9_RVERSION:
|
||||
rcall->params.rversion.msize = buf_get_int32(bufp);
|
||||
buf_get_str(bufp, &rcall->params.rversion.version);
|
||||
break;
|
||||
case P9_RFLUSH:
|
||||
break;
|
||||
case P9_RATTACH:
|
||||
rcall->params.rattach.qid.type = buf_get_int8(bufp);
|
||||
rcall->params.rattach.qid.version = buf_get_int32(bufp);
|
||||
rcall->params.rattach.qid.path = buf_get_int64(bufp);
|
||||
break;
|
||||
case P9_RWALK:
|
||||
rcall->params.rwalk.nwqid = buf_get_int16(bufp);
|
||||
if (rcall->params.rwalk.nwqid > P9_MAXWELEM) {
|
||||
P9_EPRINTK(KERN_ERR,
|
||||
"Rwalk with more than %d qids: %d\n",
|
||||
P9_MAXWELEM, rcall->params.rwalk.nwqid);
|
||||
return -EPROTO;
|
||||
}
|
||||
|
||||
for (i = 0; i < rcall->params.rwalk.nwqid; i++)
|
||||
buf_get_qid(bufp, &rcall->params.rwalk.wqids[i]);
|
||||
break;
|
||||
case P9_ROPEN:
|
||||
buf_get_qid(bufp, &rcall->params.ropen.qid);
|
||||
rcall->params.ropen.iounit = buf_get_int32(bufp);
|
||||
break;
|
||||
case P9_RCREATE:
|
||||
buf_get_qid(bufp, &rcall->params.rcreate.qid);
|
||||
rcall->params.rcreate.iounit = buf_get_int32(bufp);
|
||||
break;
|
||||
case P9_RREAD:
|
||||
rcall->params.rread.count = buf_get_int32(bufp);
|
||||
rcall->params.rread.data = bufp->p;
|
||||
buf_check_size(bufp, rcall->params.rread.count);
|
||||
break;
|
||||
case P9_RWRITE:
|
||||
rcall->params.rwrite.count = buf_get_int32(bufp);
|
||||
break;
|
||||
case P9_RCLUNK:
|
||||
break;
|
||||
case P9_RREMOVE:
|
||||
break;
|
||||
case P9_RSTAT:
|
||||
buf_get_int16(bufp);
|
||||
buf_get_stat(bufp, &rcall->params.rstat.stat, dotu);
|
||||
break;
|
||||
case P9_RWSTAT:
|
||||
break;
|
||||
case P9_RERROR:
|
||||
buf_get_str(bufp, &rcall->params.rerror.error);
|
||||
if (dotu)
|
||||
rcall->params.rerror.errno = buf_get_int16(bufp);
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
P9_DPRINTK(P9_DEBUG_ERROR, "buffer overflow\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return bufp->p - bufp->sp;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_deserialize_fcall);
|
||||
|
||||
static inline void p9_put_int8(struct cbuf *bufp, u8 val, u8 * p)
|
||||
{
|
||||
*p = val;
|
||||
buf_put_int8(bufp, val);
|
||||
}
|
||||
|
||||
static inline void p9_put_int16(struct cbuf *bufp, u16 val, u16 * p)
|
||||
{
|
||||
*p = val;
|
||||
buf_put_int16(bufp, val);
|
||||
}
|
||||
|
||||
static inline void p9_put_int32(struct cbuf *bufp, u32 val, u32 * p)
|
||||
{
|
||||
*p = val;
|
||||
buf_put_int32(bufp, val);
|
||||
}
|
||||
|
||||
static inline void p9_put_int64(struct cbuf *bufp, u64 val, u64 * p)
|
||||
{
|
||||
*p = val;
|
||||
buf_put_int64(bufp, val);
|
||||
}
|
||||
|
||||
static void
|
||||
p9_put_str(struct cbuf *bufp, char *data, struct p9_str *str)
|
||||
{
|
||||
int len;
|
||||
char *s;
|
||||
|
||||
if (data)
|
||||
len = strlen(data);
|
||||
else
|
||||
len = 0;
|
||||
|
||||
s = buf_put_stringn(bufp, data, len);
|
||||
if (str) {
|
||||
str->len = len;
|
||||
str->str = s;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
p9_put_data(struct cbuf *bufp, const char *data, int count,
|
||||
unsigned char **pdata)
|
||||
{
|
||||
*pdata = buf_alloc(bufp, count);
|
||||
memmove(*pdata, data, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static int
|
||||
p9_put_user_data(struct cbuf *bufp, const char __user *data, int count,
|
||||
unsigned char **pdata)
|
||||
{
|
||||
*pdata = buf_alloc(bufp, count);
|
||||
return copy_from_user(*pdata, data, count);
|
||||
}
|
||||
|
||||
static void
|
||||
p9_put_wstat(struct cbuf *bufp, struct p9_wstat *wstat,
|
||||
struct p9_stat *stat, int statsz, int dotu)
|
||||
{
|
||||
p9_put_int16(bufp, statsz, &stat->size);
|
||||
p9_put_int16(bufp, wstat->type, &stat->type);
|
||||
p9_put_int32(bufp, wstat->dev, &stat->dev);
|
||||
p9_put_int8(bufp, wstat->qid.type, &stat->qid.type);
|
||||
p9_put_int32(bufp, wstat->qid.version, &stat->qid.version);
|
||||
p9_put_int64(bufp, wstat->qid.path, &stat->qid.path);
|
||||
p9_put_int32(bufp, wstat->mode, &stat->mode);
|
||||
p9_put_int32(bufp, wstat->atime, &stat->atime);
|
||||
p9_put_int32(bufp, wstat->mtime, &stat->mtime);
|
||||
p9_put_int64(bufp, wstat->length, &stat->length);
|
||||
|
||||
p9_put_str(bufp, wstat->name, &stat->name);
|
||||
p9_put_str(bufp, wstat->uid, &stat->uid);
|
||||
p9_put_str(bufp, wstat->gid, &stat->gid);
|
||||
p9_put_str(bufp, wstat->muid, &stat->muid);
|
||||
|
||||
if (dotu) {
|
||||
p9_put_str(bufp, wstat->extension, &stat->extension);
|
||||
p9_put_int32(bufp, wstat->n_uid, &stat->n_uid);
|
||||
p9_put_int32(bufp, wstat->n_gid, &stat->n_gid);
|
||||
p9_put_int32(bufp, wstat->n_muid, &stat->n_muid);
|
||||
}
|
||||
}
|
||||
|
||||
static struct p9_fcall *
|
||||
p9_create_common(struct cbuf *bufp, u32 size, u8 id)
|
||||
{
|
||||
struct p9_fcall *fc;
|
||||
|
||||
size += 4 + 1 + 2; /* size[4] id[1] tag[2] */
|
||||
fc = kmalloc(sizeof(struct p9_fcall) + size, GFP_KERNEL);
|
||||
if (!fc)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
fc->sdata = (char *)fc + sizeof(*fc);
|
||||
|
||||
buf_init(bufp, (char *)fc->sdata, size);
|
||||
p9_put_int32(bufp, size, &fc->size);
|
||||
p9_put_int8(bufp, id, &fc->id);
|
||||
p9_put_int16(bufp, P9_NOTAG, &fc->tag);
|
||||
|
||||
return fc;
|
||||
}
|
||||
|
||||
void p9_set_tag(struct p9_fcall *fc, u16 tag)
|
||||
{
|
||||
fc->tag = tag;
|
||||
*(__le16 *) (fc->sdata + 5) = cpu_to_le16(tag);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_set_tag);
|
||||
|
||||
struct p9_fcall *p9_create_tversion(u32 msize, char *version)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
size = 4 + 2 + strlen(version); /* msize[4] version[s] */
|
||||
fc = p9_create_common(bufp, size, P9_TVERSION);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, msize, &fc->params.tversion.msize);
|
||||
p9_put_str(bufp, version, &fc->params.tversion.version);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tversion);
|
||||
|
||||
struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
/* afid[4] uname[s] aname[s] */
|
||||
size = 4 + 2 + strlen(uname) + 2 + strlen(aname);
|
||||
fc = p9_create_common(bufp, size, P9_TAUTH);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, afid, &fc->params.tauth.afid);
|
||||
p9_put_str(bufp, uname, &fc->params.tauth.uname);
|
||||
p9_put_str(bufp, aname, &fc->params.tauth.aname);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tauth);
|
||||
|
||||
struct p9_fcall *
|
||||
p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
/* fid[4] afid[4] uname[s] aname[s] */
|
||||
size = 4 + 4 + 2 + strlen(uname) + 2 + strlen(aname);
|
||||
fc = p9_create_common(bufp, size, P9_TATTACH);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.tattach.fid);
|
||||
p9_put_int32(bufp, afid, &fc->params.tattach.afid);
|
||||
p9_put_str(bufp, uname, &fc->params.tattach.uname);
|
||||
p9_put_str(bufp, aname, &fc->params.tattach.aname);
|
||||
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tattach);
|
||||
|
||||
struct p9_fcall *p9_create_tflush(u16 oldtag)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
size = 2; /* oldtag[2] */
|
||||
fc = p9_create_common(bufp, size, P9_TFLUSH);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int16(bufp, oldtag, &fc->params.tflush.oldtag);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tflush);
|
||||
|
||||
struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname,
|
||||
char **wnames)
|
||||
{
|
||||
int i, size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
if (nwname > P9_MAXWELEM) {
|
||||
P9_DPRINTK(P9_DEBUG_ERROR, "nwname > %d\n", P9_MAXWELEM);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = 4 + 4 + 2; /* fid[4] newfid[4] nwname[2] ... */
|
||||
for (i = 0; i < nwname; i++) {
|
||||
size += 2 + strlen(wnames[i]); /* wname[s] */
|
||||
}
|
||||
|
||||
fc = p9_create_common(bufp, size, P9_TWALK);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.twalk.fid);
|
||||
p9_put_int32(bufp, newfid, &fc->params.twalk.newfid);
|
||||
p9_put_int16(bufp, nwname, &fc->params.twalk.nwname);
|
||||
for (i = 0; i < nwname; i++) {
|
||||
p9_put_str(bufp, wnames[i], &fc->params.twalk.wnames[i]);
|
||||
}
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_twalk);
|
||||
|
||||
struct p9_fcall *p9_create_topen(u32 fid, u8 mode)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
size = 4 + 1; /* fid[4] mode[1] */
|
||||
fc = p9_create_common(bufp, size, P9_TOPEN);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.topen.fid);
|
||||
p9_put_int8(bufp, mode, &fc->params.topen.mode);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_topen);
|
||||
|
||||
struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode,
|
||||
char *extension, int dotu)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
/* fid[4] name[s] perm[4] mode[1] */
|
||||
size = 4 + 2 + strlen(name) + 4 + 1;
|
||||
if (dotu) {
|
||||
size += 2 + /* extension[s] */
|
||||
(extension == NULL ? 0 : strlen(extension));
|
||||
}
|
||||
|
||||
fc = p9_create_common(bufp, size, P9_TCREATE);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.tcreate.fid);
|
||||
p9_put_str(bufp, name, &fc->params.tcreate.name);
|
||||
p9_put_int32(bufp, perm, &fc->params.tcreate.perm);
|
||||
p9_put_int8(bufp, mode, &fc->params.tcreate.mode);
|
||||
if (dotu)
|
||||
p9_put_str(bufp, extension, &fc->params.tcreate.extension);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tcreate);
|
||||
|
||||
struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
size = 4 + 8 + 4; /* fid[4] offset[8] count[4] */
|
||||
fc = p9_create_common(bufp, size, P9_TREAD);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.tread.fid);
|
||||
p9_put_int64(bufp, offset, &fc->params.tread.offset);
|
||||
p9_put_int32(bufp, count, &fc->params.tread.count);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tread);
|
||||
|
||||
struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count,
|
||||
const char *data)
|
||||
{
|
||||
int size, err;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
/* fid[4] offset[8] count[4] data[count] */
|
||||
size = 4 + 8 + 4 + count;
|
||||
fc = p9_create_common(bufp, size, P9_TWRITE);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.twrite.fid);
|
||||
p9_put_int64(bufp, offset, &fc->params.twrite.offset);
|
||||
p9_put_int32(bufp, count, &fc->params.twrite.count);
|
||||
err = p9_put_data(bufp, data, count, &fc->params.twrite.data);
|
||||
if (err) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(err);
|
||||
}
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_twrite);
|
||||
|
||||
struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count,
|
||||
const char __user *data)
|
||||
{
|
||||
int size, err;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
/* fid[4] offset[8] count[4] data[count] */
|
||||
size = 4 + 8 + 4 + count;
|
||||
fc = p9_create_common(bufp, size, P9_TWRITE);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.twrite.fid);
|
||||
p9_put_int64(bufp, offset, &fc->params.twrite.offset);
|
||||
p9_put_int32(bufp, count, &fc->params.twrite.count);
|
||||
err = p9_put_user_data(bufp, data, count, &fc->params.twrite.data);
|
||||
if (err) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(err);
|
||||
}
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_twrite_u);
|
||||
|
||||
struct p9_fcall *p9_create_tclunk(u32 fid)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
size = 4; /* fid[4] */
|
||||
fc = p9_create_common(bufp, size, P9_TCLUNK);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.tclunk.fid);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tclunk);
|
||||
|
||||
struct p9_fcall *p9_create_tremove(u32 fid)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
size = 4; /* fid[4] */
|
||||
fc = p9_create_common(bufp, size, P9_TREMOVE);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.tremove.fid);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tremove);
|
||||
|
||||
struct p9_fcall *p9_create_tstat(u32 fid)
|
||||
{
|
||||
int size;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
size = 4; /* fid[4] */
|
||||
fc = p9_create_common(bufp, size, P9_TSTAT);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.tstat.fid);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_tstat);
|
||||
|
||||
struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat,
|
||||
int dotu)
|
||||
{
|
||||
int size, statsz;
|
||||
struct p9_fcall *fc;
|
||||
struct cbuf buffer;
|
||||
struct cbuf *bufp = &buffer;
|
||||
|
||||
statsz = p9_size_wstat(wstat, dotu);
|
||||
size = 4 + 2 + 2 + statsz; /* fid[4] stat[n] */
|
||||
fc = p9_create_common(bufp, size, P9_TWSTAT);
|
||||
if (IS_ERR(fc))
|
||||
goto error;
|
||||
|
||||
p9_put_int32(bufp, fid, &fc->params.twstat.fid);
|
||||
buf_put_int16(bufp, statsz + 2);
|
||||
p9_put_wstat(bufp, wstat, &fc->params.twstat.stat, statsz, dotu);
|
||||
|
||||
if (buf_check_overflow(bufp)) {
|
||||
kfree(fc);
|
||||
fc = ERR_PTR(-ENOMEM);
|
||||
}
|
||||
error:
|
||||
return fc;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_create_twstat);
|
||||
240
net/9p/error.c
Normal file
240
net/9p/error.c
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
/*
|
||||
* linux/fs/9p/error.c
|
||||
*
|
||||
* Error string handling
|
||||
*
|
||||
* Plan 9 uses error strings, Unix uses error numbers. These functions
|
||||
* try to help manage that and provide for dynamically adding error
|
||||
* mappings.
|
||||
*
|
||||
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
|
||||
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/jhash.h>
|
||||
#include <linux/errno.h>
|
||||
#include <net/9p/9p.h>
|
||||
|
||||
struct errormap {
|
||||
char *name;
|
||||
int val;
|
||||
|
||||
int namelen;
|
||||
struct hlist_node list;
|
||||
};
|
||||
|
||||
#define ERRHASHSZ 32
|
||||
static struct hlist_head hash_errmap[ERRHASHSZ];
|
||||
|
||||
/* FixMe - reduce to a reasonable size */
|
||||
static struct errormap errmap[] = {
|
||||
{"Operation not permitted", EPERM},
|
||||
{"wstat prohibited", EPERM},
|
||||
{"No such file or directory", ENOENT},
|
||||
{"directory entry not found", ENOENT},
|
||||
{"file not found", ENOENT},
|
||||
{"Interrupted system call", EINTR},
|
||||
{"Input/output error", EIO},
|
||||
{"No such device or address", ENXIO},
|
||||
{"Argument list too long", E2BIG},
|
||||
{"Bad file descriptor", EBADF},
|
||||
{"Resource temporarily unavailable", EAGAIN},
|
||||
{"Cannot allocate memory", ENOMEM},
|
||||
{"Permission denied", EACCES},
|
||||
{"Bad address", EFAULT},
|
||||
{"Block device required", ENOTBLK},
|
||||
{"Device or resource busy", EBUSY},
|
||||
{"File exists", EEXIST},
|
||||
{"Invalid cross-device link", EXDEV},
|
||||
{"No such device", ENODEV},
|
||||
{"Not a directory", ENOTDIR},
|
||||
{"Is a directory", EISDIR},
|
||||
{"Invalid argument", EINVAL},
|
||||
{"Too many open files in system", ENFILE},
|
||||
{"Too many open files", EMFILE},
|
||||
{"Text file busy", ETXTBSY},
|
||||
{"File too large", EFBIG},
|
||||
{"No space left on device", ENOSPC},
|
||||
{"Illegal seek", ESPIPE},
|
||||
{"Read-only file system", EROFS},
|
||||
{"Too many links", EMLINK},
|
||||
{"Broken pipe", EPIPE},
|
||||
{"Numerical argument out of domain", EDOM},
|
||||
{"Numerical result out of range", ERANGE},
|
||||
{"Resource deadlock avoided", EDEADLK},
|
||||
{"File name too long", ENAMETOOLONG},
|
||||
{"No locks available", ENOLCK},
|
||||
{"Function not implemented", ENOSYS},
|
||||
{"Directory not empty", ENOTEMPTY},
|
||||
{"Too many levels of symbolic links", ELOOP},
|
||||
{"No message of desired type", ENOMSG},
|
||||
{"Identifier removed", EIDRM},
|
||||
{"No data available", ENODATA},
|
||||
{"Machine is not on the network", ENONET},
|
||||
{"Package not installed", ENOPKG},
|
||||
{"Object is remote", EREMOTE},
|
||||
{"Link has been severed", ENOLINK},
|
||||
{"Communication error on send", ECOMM},
|
||||
{"Protocol error", EPROTO},
|
||||
{"Bad message", EBADMSG},
|
||||
{"File descriptor in bad state", EBADFD},
|
||||
{"Streams pipe error", ESTRPIPE},
|
||||
{"Too many users", EUSERS},
|
||||
{"Socket operation on non-socket", ENOTSOCK},
|
||||
{"Message too long", EMSGSIZE},
|
||||
{"Protocol not available", ENOPROTOOPT},
|
||||
{"Protocol not supported", EPROTONOSUPPORT},
|
||||
{"Socket type not supported", ESOCKTNOSUPPORT},
|
||||
{"Operation not supported", EOPNOTSUPP},
|
||||
{"Protocol family not supported", EPFNOSUPPORT},
|
||||
{"Network is down", ENETDOWN},
|
||||
{"Network is unreachable", ENETUNREACH},
|
||||
{"Network dropped connection on reset", ENETRESET},
|
||||
{"Software caused connection abort", ECONNABORTED},
|
||||
{"Connection reset by peer", ECONNRESET},
|
||||
{"No buffer space available", ENOBUFS},
|
||||
{"Transport endpoint is already connected", EISCONN},
|
||||
{"Transport endpoint is not connected", ENOTCONN},
|
||||
{"Cannot send after transport endpoint shutdown", ESHUTDOWN},
|
||||
{"Connection timed out", ETIMEDOUT},
|
||||
{"Connection refused", ECONNREFUSED},
|
||||
{"Host is down", EHOSTDOWN},
|
||||
{"No route to host", EHOSTUNREACH},
|
||||
{"Operation already in progress", EALREADY},
|
||||
{"Operation now in progress", EINPROGRESS},
|
||||
{"Is a named type file", EISNAM},
|
||||
{"Remote I/O error", EREMOTEIO},
|
||||
{"Disk quota exceeded", EDQUOT},
|
||||
/* errors from fossil, vacfs, and u9fs */
|
||||
{"fid unknown or out of range", EBADF},
|
||||
{"permission denied", EACCES},
|
||||
{"file does not exist", ENOENT},
|
||||
{"authentication failed", ECONNREFUSED},
|
||||
{"bad offset in directory read", ESPIPE},
|
||||
{"bad use of fid", EBADF},
|
||||
{"wstat can't convert between files and directories", EPERM},
|
||||
{"directory is not empty", ENOTEMPTY},
|
||||
{"file exists", EEXIST},
|
||||
{"file already exists", EEXIST},
|
||||
{"file or directory already exists", EEXIST},
|
||||
{"fid already in use", EBADF},
|
||||
{"file in use", ETXTBSY},
|
||||
{"i/o error", EIO},
|
||||
{"file already open for I/O", ETXTBSY},
|
||||
{"illegal mode", EINVAL},
|
||||
{"illegal name", ENAMETOOLONG},
|
||||
{"not a directory", ENOTDIR},
|
||||
{"not a member of proposed group", EPERM},
|
||||
{"not owner", EACCES},
|
||||
{"only owner can change group in wstat", EACCES},
|
||||
{"read only file system", EROFS},
|
||||
{"no access to special file", EPERM},
|
||||
{"i/o count too large", EIO},
|
||||
{"unknown group", EINVAL},
|
||||
{"unknown user", EINVAL},
|
||||
{"bogus wstat buffer", EPROTO},
|
||||
{"exclusive use file already open", EAGAIN},
|
||||
{"corrupted directory entry", EIO},
|
||||
{"corrupted file entry", EIO},
|
||||
{"corrupted block label", EIO},
|
||||
{"corrupted meta data", EIO},
|
||||
{"illegal offset", EINVAL},
|
||||
{"illegal path element", ENOENT},
|
||||
{"root of file system is corrupted", EIO},
|
||||
{"corrupted super block", EIO},
|
||||
{"protocol botch", EPROTO},
|
||||
{"file system is full", ENOSPC},
|
||||
{"file is in use", EAGAIN},
|
||||
{"directory entry is not allocated", ENOENT},
|
||||
{"file is read only", EROFS},
|
||||
{"file has been removed", EIDRM},
|
||||
{"only support truncation to zero length", EPERM},
|
||||
{"cannot remove root", EPERM},
|
||||
{"file too big", EFBIG},
|
||||
{"venti i/o error", EIO},
|
||||
/* these are not errors */
|
||||
{"u9fs rhostsauth: no authentication required", 0},
|
||||
{"u9fs authnone: no authentication required", 0},
|
||||
{NULL, -1}
|
||||
};
|
||||
|
||||
/**
|
||||
* p9_error_init - preload
|
||||
* @errstr: error string
|
||||
*
|
||||
*/
|
||||
|
||||
int p9_error_init(void)
|
||||
{
|
||||
struct errormap *c;
|
||||
int bucket;
|
||||
|
||||
/* initialize hash table */
|
||||
for (bucket = 0; bucket < ERRHASHSZ; bucket++)
|
||||
INIT_HLIST_HEAD(&hash_errmap[bucket]);
|
||||
|
||||
/* load initial error map into hash table */
|
||||
for (c = errmap; c->name != NULL; c++) {
|
||||
c->namelen = strlen(c->name);
|
||||
bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ;
|
||||
INIT_HLIST_NODE(&c->list);
|
||||
hlist_add_head(&c->list, &hash_errmap[bucket]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_error_init);
|
||||
|
||||
/**
|
||||
* errstr2errno - convert error string to error number
|
||||
* @errstr: error string
|
||||
*
|
||||
*/
|
||||
|
||||
int p9_errstr2errno(char *errstr, int len)
|
||||
{
|
||||
int errno;
|
||||
struct hlist_node *p;
|
||||
struct errormap *c;
|
||||
int bucket;
|
||||
|
||||
errno = 0;
|
||||
p = NULL;
|
||||
c = NULL;
|
||||
bucket = jhash(errstr, len, 0) % ERRHASHSZ;
|
||||
hlist_for_each_entry(c, p, &hash_errmap[bucket], list) {
|
||||
if (c->namelen == len && !memcmp(c->name, errstr, len)) {
|
||||
errno = c->val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (errno == 0) {
|
||||
/* TODO: if error isn't found, add it dynamically */
|
||||
errstr[len] = 0;
|
||||
printk(KERN_ERR "%s: errstr :%s: not found\n", __FUNCTION__,
|
||||
errstr);
|
||||
errno = 1;
|
||||
}
|
||||
|
||||
return -errno;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_errstr2errno);
|
||||
358
net/9p/fcprint.c
Normal file
358
net/9p/fcprint.c
Normal file
|
|
@ -0,0 +1,358 @@
|
|||
/*
|
||||
* net/9p/fcprint.c
|
||||
*
|
||||
* Print 9P call.
|
||||
*
|
||||
* Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
#include <linux/module.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/idr.h>
|
||||
#include <net/9p/9p.h>
|
||||
|
||||
#ifdef CONFIG_NET_9P_DEBUG
|
||||
|
||||
static int
|
||||
p9_printqid(char *buf, int buflen, struct p9_qid *q)
|
||||
{
|
||||
int n;
|
||||
char b[10];
|
||||
|
||||
n = 0;
|
||||
if (q->type & P9_QTDIR)
|
||||
b[n++] = 'd';
|
||||
if (q->type & P9_QTAPPEND)
|
||||
b[n++] = 'a';
|
||||
if (q->type & P9_QTAUTH)
|
||||
b[n++] = 'A';
|
||||
if (q->type & P9_QTEXCL)
|
||||
b[n++] = 'l';
|
||||
if (q->type & P9_QTTMP)
|
||||
b[n++] = 't';
|
||||
if (q->type & P9_QTSYMLINK)
|
||||
b[n++] = 'L';
|
||||
b[n] = '\0';
|
||||
|
||||
return scnprintf(buf, buflen, "(%.16llx %x %s)",
|
||||
(long long int) q->path, q->version, b);
|
||||
}
|
||||
|
||||
static int
|
||||
p9_printperm(char *buf, int buflen, int perm)
|
||||
{
|
||||
int n;
|
||||
char b[15];
|
||||
|
||||
n = 0;
|
||||
if (perm & P9_DMDIR)
|
||||
b[n++] = 'd';
|
||||
if (perm & P9_DMAPPEND)
|
||||
b[n++] = 'a';
|
||||
if (perm & P9_DMAUTH)
|
||||
b[n++] = 'A';
|
||||
if (perm & P9_DMEXCL)
|
||||
b[n++] = 'l';
|
||||
if (perm & P9_DMTMP)
|
||||
b[n++] = 't';
|
||||
if (perm & P9_DMDEVICE)
|
||||
b[n++] = 'D';
|
||||
if (perm & P9_DMSOCKET)
|
||||
b[n++] = 'S';
|
||||
if (perm & P9_DMNAMEDPIPE)
|
||||
b[n++] = 'P';
|
||||
if (perm & P9_DMSYMLINK)
|
||||
b[n++] = 'L';
|
||||
b[n] = '\0';
|
||||
|
||||
return scnprintf(buf, buflen, "%s%03o", b, perm&077);
|
||||
}
|
||||
|
||||
static int
|
||||
p9_printstat(char *buf, int buflen, struct p9_stat *st, int extended)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = scnprintf(buf, buflen, "'%.*s' '%.*s'", st->name.len,
|
||||
st->name.str, st->uid.len, st->uid.str);
|
||||
if (extended)
|
||||
n += scnprintf(buf+n, buflen-n, "(%d)", st->n_uid);
|
||||
|
||||
n += scnprintf(buf+n, buflen-n, " '%.*s'", st->gid.len, st->gid.str);
|
||||
if (extended)
|
||||
n += scnprintf(buf+n, buflen-n, "(%d)", st->n_gid);
|
||||
|
||||
n += scnprintf(buf+n, buflen-n, " '%.*s'", st->muid.len, st->muid.str);
|
||||
if (extended)
|
||||
n += scnprintf(buf+n, buflen-n, "(%d)", st->n_muid);
|
||||
|
||||
n += scnprintf(buf+n, buflen-n, " q ");
|
||||
n += p9_printqid(buf+n, buflen-n, &st->qid);
|
||||
n += scnprintf(buf+n, buflen-n, " m ");
|
||||
n += p9_printperm(buf+n, buflen-n, st->mode);
|
||||
n += scnprintf(buf+n, buflen-n, " at %d mt %d l %lld",
|
||||
st->atime, st->mtime, (long long int) st->length);
|
||||
|
||||
if (extended)
|
||||
n += scnprintf(buf+n, buflen-n, " ext '%.*s'",
|
||||
st->extension.len, st->extension.str);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int
|
||||
p9_dumpdata(char *buf, int buflen, u8 *data, int datalen)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
i = n = 0;
|
||||
while (i < datalen) {
|
||||
n += scnprintf(buf + n, buflen - n, "%02x", data[i]);
|
||||
if (i%4 == 3)
|
||||
n += scnprintf(buf + n, buflen - n, " ");
|
||||
if (i%32 == 31)
|
||||
n += scnprintf(buf + n, buflen - n, "\n");
|
||||
|
||||
i++;
|
||||
}
|
||||
n += scnprintf(buf + n, buflen - n, "\n");
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int
|
||||
p9_printdata(char *buf, int buflen, u8 *data, int datalen)
|
||||
{
|
||||
return p9_dumpdata(buf, buflen, data, datalen < 16?datalen:16);
|
||||
}
|
||||
|
||||
int
|
||||
p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
|
||||
{
|
||||
int i, ret, type, tag;
|
||||
|
||||
if (!fc)
|
||||
return scnprintf(buf, buflen, "<NULL>");
|
||||
|
||||
type = fc->id;
|
||||
tag = fc->tag;
|
||||
|
||||
ret = 0;
|
||||
switch (type) {
|
||||
case P9_TVERSION:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Tversion tag %u msize %u version '%.*s'", tag,
|
||||
fc->params.tversion.msize,
|
||||
fc->params.tversion.version.len,
|
||||
fc->params.tversion.version.str);
|
||||
break;
|
||||
|
||||
case P9_RVERSION:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Rversion tag %u msize %u version '%.*s'", tag,
|
||||
fc->params.rversion.msize,
|
||||
fc->params.rversion.version.len,
|
||||
fc->params.rversion.version.str);
|
||||
break;
|
||||
|
||||
case P9_TAUTH:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Tauth tag %u afid %d uname '%.*s' aname '%.*s'", tag,
|
||||
fc->params.tauth.afid, fc->params.tauth.uname.len,
|
||||
fc->params.tauth.uname.str, fc->params.tauth.aname.len,
|
||||
fc->params.tauth.aname.str);
|
||||
break;
|
||||
|
||||
case P9_RAUTH:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rauth tag %u qid ", tag);
|
||||
p9_printqid(buf+ret, buflen-ret, &fc->params.rauth.qid);
|
||||
break;
|
||||
|
||||
case P9_TATTACH:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Tattach tag %u fid %d afid %d uname '%.*s' aname '%.*s'", tag,
|
||||
fc->params.tattach.fid, fc->params.tattach.afid,
|
||||
fc->params.tattach.uname.len, fc->params.tattach.uname.str,
|
||||
fc->params.tattach.aname.len, fc->params.tattach.aname.str);
|
||||
break;
|
||||
|
||||
case P9_RATTACH:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rattach tag %u qid ",
|
||||
tag);
|
||||
p9_printqid(buf+ret, buflen-ret, &fc->params.rattach.qid);
|
||||
break;
|
||||
|
||||
case P9_RERROR:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Rerror tag %u ename '%.*s'", tag,
|
||||
fc->params.rerror.error.len,
|
||||
fc->params.rerror.error.str);
|
||||
if (extended)
|
||||
ret += scnprintf(buf+ret, buflen-ret, " ecode %d\n",
|
||||
fc->params.rerror.errno);
|
||||
break;
|
||||
|
||||
case P9_TFLUSH:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Tflush tag %u oldtag %u",
|
||||
tag, fc->params.tflush.oldtag);
|
||||
break;
|
||||
|
||||
case P9_RFLUSH:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rflush tag %u", tag);
|
||||
break;
|
||||
|
||||
case P9_TWALK:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Twalk tag %u fid %d newfid %d nwname %d", tag,
|
||||
fc->params.twalk.fid, fc->params.twalk.newfid,
|
||||
fc->params.twalk.nwname);
|
||||
for (i = 0; i < fc->params.twalk.nwname; i++)
|
||||
ret += scnprintf(buf+ret, buflen-ret, " '%.*s'",
|
||||
fc->params.twalk.wnames[i].len,
|
||||
fc->params.twalk.wnames[i].str);
|
||||
break;
|
||||
|
||||
case P9_RWALK:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rwalk tag %u nwqid %d",
|
||||
tag, fc->params.rwalk.nwqid);
|
||||
for (i = 0; i < fc->params.rwalk.nwqid; i++)
|
||||
ret += p9_printqid(buf+ret, buflen-ret,
|
||||
&fc->params.rwalk.wqids[i]);
|
||||
break;
|
||||
|
||||
case P9_TOPEN:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Topen tag %u fid %d mode %d", tag,
|
||||
fc->params.topen.fid, fc->params.topen.mode);
|
||||
break;
|
||||
|
||||
case P9_ROPEN:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Ropen tag %u", tag);
|
||||
ret += p9_printqid(buf+ret, buflen-ret, &fc->params.ropen.qid);
|
||||
ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
|
||||
fc->params.ropen.iounit);
|
||||
break;
|
||||
|
||||
case P9_TCREATE:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Tcreate tag %u fid %d name '%.*s' perm ", tag,
|
||||
fc->params.tcreate.fid, fc->params.tcreate.name.len,
|
||||
fc->params.tcreate.name.str);
|
||||
|
||||
ret += p9_printperm(buf+ret, buflen-ret,
|
||||
fc->params.tcreate.perm);
|
||||
ret += scnprintf(buf+ret, buflen-ret, " mode %d",
|
||||
fc->params.tcreate.mode);
|
||||
break;
|
||||
|
||||
case P9_RCREATE:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rcreate tag %u", tag);
|
||||
ret += p9_printqid(buf+ret, buflen-ret,
|
||||
&fc->params.rcreate.qid);
|
||||
ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
|
||||
fc->params.rcreate.iounit);
|
||||
break;
|
||||
|
||||
case P9_TREAD:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Tread tag %u fid %d offset %lld count %u", tag,
|
||||
fc->params.tread.fid,
|
||||
(long long int) fc->params.tread.offset,
|
||||
fc->params.tread.count);
|
||||
break;
|
||||
|
||||
case P9_RREAD:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Rread tag %u count %u data ", tag,
|
||||
fc->params.rread.count);
|
||||
ret += p9_printdata(buf+ret, buflen-ret, fc->params.rread.data,
|
||||
fc->params.rread.count);
|
||||
break;
|
||||
|
||||
case P9_TWRITE:
|
||||
ret += scnprintf(buf+ret, buflen-ret,
|
||||
"Twrite tag %u fid %d offset %lld count %u data ",
|
||||
tag, fc->params.twrite.fid,
|
||||
(long long int) fc->params.twrite.offset,
|
||||
fc->params.twrite.count);
|
||||
ret += p9_printdata(buf+ret, buflen-ret, fc->params.twrite.data,
|
||||
fc->params.twrite.count);
|
||||
break;
|
||||
|
||||
case P9_RWRITE:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rwrite tag %u count %u",
|
||||
tag, fc->params.rwrite.count);
|
||||
break;
|
||||
|
||||
case P9_TCLUNK:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Tclunk tag %u fid %d",
|
||||
tag, fc->params.tclunk.fid);
|
||||
break;
|
||||
|
||||
case P9_RCLUNK:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rclunk tag %u", tag);
|
||||
break;
|
||||
|
||||
case P9_TREMOVE:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Tremove tag %u fid %d",
|
||||
tag, fc->params.tremove.fid);
|
||||
break;
|
||||
|
||||
case P9_RREMOVE:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rremove tag %u", tag);
|
||||
break;
|
||||
|
||||
case P9_TSTAT:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Tstat tag %u fid %d",
|
||||
tag, fc->params.tstat.fid);
|
||||
break;
|
||||
|
||||
case P9_RSTAT:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rstat tag %u ", tag);
|
||||
ret += p9_printstat(buf+ret, buflen-ret, &fc->params.rstat.stat,
|
||||
extended);
|
||||
break;
|
||||
|
||||
case P9_TWSTAT:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Twstat tag %u fid %d ",
|
||||
tag, fc->params.twstat.fid);
|
||||
ret += p9_printstat(buf+ret, buflen-ret,
|
||||
&fc->params.twstat.stat, extended);
|
||||
break;
|
||||
|
||||
case P9_RWSTAT:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "Rwstat tag %u", tag);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret += scnprintf(buf+ret, buflen-ret, "unknown type %d", type);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
int
|
||||
p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_printfcall);
|
||||
#endif /* CONFIG_NET_9P_DEBUG */
|
||||
85
net/9p/mod.c
Normal file
85
net/9p/mod.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* net/9p/9p.c
|
||||
*
|
||||
* 9P entry point
|
||||
*
|
||||
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
|
||||
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
|
||||
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <net/9p/9p.h>
|
||||
|
||||
#ifdef CONFIG_NET_9P_DEBUG
|
||||
unsigned int p9_debug_level = 0; /* feature-rific global debug level */
|
||||
EXPORT_SYMBOL(p9_debug_level);
|
||||
module_param_named(debug, p9_debug_level, uint, 0);
|
||||
MODULE_PARM_DESC(debug, "9P debugging level");
|
||||
#endif
|
||||
|
||||
extern int p9_mux_global_init(void);
|
||||
extern void p9_mux_global_exit(void);
|
||||
extern int p9_sysctl_register(void);
|
||||
extern void p9_sysctl_unregister(void);
|
||||
|
||||
/**
|
||||
* v9fs_init - Initialize module
|
||||
*
|
||||
*/
|
||||
static int __init init_p9(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
p9_error_init();
|
||||
printk(KERN_INFO "Installing 9P2000 support\n");
|
||||
ret = p9_mux_global_init();
|
||||
if (ret) {
|
||||
printk(KERN_WARNING "9p: starting mux failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = p9_sysctl_register();
|
||||
if (ret) {
|
||||
printk(KERN_WARNING "9p: registering sysctl failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* v9fs_init - shutdown module
|
||||
*
|
||||
*/
|
||||
|
||||
static void __exit exit_p9(void)
|
||||
{
|
||||
p9_sysctl_unregister();
|
||||
p9_mux_global_exit();
|
||||
}
|
||||
|
||||
module_init(init_p9)
|
||||
module_exit(exit_p9)
|
||||
|
||||
MODULE_AUTHOR("Latchesar Ionkov <[email protected]>");
|
||||
MODULE_AUTHOR("Eric Van Hensbergen <[email protected]>");
|
||||
MODULE_AUTHOR("Ron Minnich <[email protected]>");
|
||||
MODULE_LICENSE("GPL");
|
||||
1050
net/9p/mux.c
Normal file
1050
net/9p/mux.c
Normal file
File diff suppressed because it is too large
Load diff
86
net/9p/sysctl.c
Normal file
86
net/9p/sysctl.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* net/9p/sysctl.c
|
||||
*
|
||||
* 9P sysctl interface
|
||||
*
|
||||
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/sysctl.h>
|
||||
#include <linux/init.h>
|
||||
#include <net/9p/9p.h>
|
||||
|
||||
enum {
|
||||
P9_SYSCTL_NET = 487,
|
||||
P9_SYSCTL_DEBUG = 1,
|
||||
};
|
||||
|
||||
static ctl_table p9_table[] = {
|
||||
#ifdef CONFIG_NET_9P_DEBUG
|
||||
{
|
||||
.ctl_name = P9_SYSCTL_DEBUG,
|
||||
.procname = "debug",
|
||||
.data = &p9_debug_level,
|
||||
.maxlen = sizeof(int),
|
||||
.mode = 0644,
|
||||
.proc_handler = &proc_dointvec
|
||||
},
|
||||
#endif
|
||||
{ .ctl_name = 0 },
|
||||
};
|
||||
|
||||
static ctl_table p9_net_table[] = {
|
||||
{
|
||||
.ctl_name = P9_SYSCTL_NET,
|
||||
.procname = "9p",
|
||||
.maxlen = 0,
|
||||
.mode = 0555,
|
||||
.child = p9_table,
|
||||
},
|
||||
{ .ctl_name = 0 },
|
||||
};
|
||||
|
||||
static ctl_table p9_ctl_table[] = {
|
||||
{
|
||||
.ctl_name = CTL_NET,
|
||||
.procname = "net",
|
||||
.maxlen = 0,
|
||||
.mode = 0555,
|
||||
.child = p9_net_table,
|
||||
},
|
||||
{ .ctl_name = 0 },
|
||||
};
|
||||
|
||||
static struct ctl_table_header *p9_table_header;
|
||||
|
||||
int __init p9_sysctl_register(void)
|
||||
{
|
||||
p9_table_header = register_sysctl_table(p9_ctl_table);
|
||||
if (!p9_table_header)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __exit p9_sysctl_unregister(void)
|
||||
{
|
||||
unregister_sysctl_table(p9_table_header);
|
||||
}
|
||||
363
net/9p/trans_fd.c
Normal file
363
net/9p/trans_fd.c
Normal file
|
|
@ -0,0 +1,363 @@
|
|||
/*
|
||||
* linux/fs/9p/trans_fd.c
|
||||
*
|
||||
* Fd transport layer. Includes deprecated socket layer.
|
||||
*
|
||||
* Copyright (C) 2006 by Russ Cox <rsc@swtch.com>
|
||||
* Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net>
|
||||
* Copyright (C) 2004-2005 by Eric Van Hensbergen <ericvh@gmail.com>
|
||||
* Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/in.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/net.h>
|
||||
#include <linux/ipv6.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/un.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/inet.h>
|
||||
#include <linux/idr.h>
|
||||
#include <linux/file.h>
|
||||
#include <net/9p/9p.h>
|
||||
#include <net/9p/transport.h>
|
||||
|
||||
#define P9_PORT 564
|
||||
|
||||
struct p9_trans_fd {
|
||||
struct file *rd;
|
||||
struct file *wr;
|
||||
};
|
||||
|
||||
static int p9_socket_open(struct p9_transport *trans, struct socket *csocket);
|
||||
static int p9_fd_open(struct p9_transport *trans, int rfd, int wfd);
|
||||
static int p9_fd_read(struct p9_transport *trans, void *v, int len);
|
||||
static int p9_fd_write(struct p9_transport *trans, void *v, int len);
|
||||
static unsigned int p9_fd_poll(struct p9_transport *trans,
|
||||
struct poll_table_struct *pt);
|
||||
static void p9_fd_close(struct p9_transport *trans);
|
||||
|
||||
struct p9_transport *p9_trans_create_tcp(const char *addr, int port)
|
||||
{
|
||||
int err;
|
||||
struct p9_transport *trans;
|
||||
struct socket *csocket;
|
||||
struct sockaddr_in sin_server;
|
||||
|
||||
csocket = NULL;
|
||||
trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL);
|
||||
if (!trans)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
trans->write = p9_fd_write;
|
||||
trans->read = p9_fd_read;
|
||||
trans->close = p9_fd_close;
|
||||
trans->poll = p9_fd_poll;
|
||||
|
||||
sin_server.sin_family = AF_INET;
|
||||
sin_server.sin_addr.s_addr = in_aton(addr);
|
||||
sin_server.sin_port = htons(port);
|
||||
sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket);
|
||||
|
||||
if (!csocket) {
|
||||
P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n");
|
||||
err = -EIO;
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = csocket->ops->connect(csocket,
|
||||
(struct sockaddr *)&sin_server,
|
||||
sizeof(struct sockaddr_in), 0);
|
||||
if (err < 0) {
|
||||
P9_EPRINTK(KERN_ERR,
|
||||
"p9_trans_tcp: problem connecting socket to %s\n",
|
||||
addr);
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_socket_open(trans, csocket);
|
||||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
return trans;
|
||||
|
||||
error:
|
||||
if (csocket)
|
||||
sock_release(csocket);
|
||||
|
||||
kfree(trans);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_trans_create_tcp);
|
||||
|
||||
struct p9_transport *p9_trans_create_unix(const char *addr)
|
||||
{
|
||||
int err;
|
||||
struct socket *csocket;
|
||||
struct sockaddr_un sun_server;
|
||||
struct p9_transport *trans;
|
||||
|
||||
csocket = NULL;
|
||||
trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL);
|
||||
if (!trans)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
trans->write = p9_fd_write;
|
||||
trans->read = p9_fd_read;
|
||||
trans->close = p9_fd_close;
|
||||
trans->poll = p9_fd_poll;
|
||||
|
||||
if (strlen(addr) > UNIX_PATH_MAX) {
|
||||
P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n",
|
||||
addr);
|
||||
err = -ENAMETOOLONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
sun_server.sun_family = PF_UNIX;
|
||||
strcpy(sun_server.sun_path, addr);
|
||||
sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket);
|
||||
err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server,
|
||||
sizeof(struct sockaddr_un) - 1, 0);
|
||||
if (err < 0) {
|
||||
P9_EPRINTK(KERN_ERR,
|
||||
"p9_trans_unix: problem connecting socket: %s: %d\n",
|
||||
addr, err);
|
||||
goto error;
|
||||
}
|
||||
|
||||
err = p9_socket_open(trans, csocket);
|
||||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
return trans;
|
||||
|
||||
error:
|
||||
if (csocket)
|
||||
sock_release(csocket);
|
||||
|
||||
kfree(trans);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_trans_create_unix);
|
||||
|
||||
struct p9_transport *p9_trans_create_fd(int rfd, int wfd)
|
||||
{
|
||||
int err;
|
||||
struct p9_transport *trans;
|
||||
|
||||
if (rfd == ~0 || wfd == ~0) {
|
||||
printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n");
|
||||
return ERR_PTR(-ENOPROTOOPT);
|
||||
}
|
||||
|
||||
trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL);
|
||||
if (!trans)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
trans->write = p9_fd_write;
|
||||
trans->read = p9_fd_read;
|
||||
trans->close = p9_fd_close;
|
||||
trans->poll = p9_fd_poll;
|
||||
|
||||
err = p9_fd_open(trans, rfd, wfd);
|
||||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
return trans;
|
||||
|
||||
error:
|
||||
kfree(trans);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_trans_create_fd);
|
||||
|
||||
static int p9_socket_open(struct p9_transport *trans, struct socket *csocket)
|
||||
{
|
||||
int fd, ret;
|
||||
|
||||
csocket->sk->sk_allocation = GFP_NOIO;
|
||||
fd = sock_map_fd(csocket);
|
||||
if (fd < 0) {
|
||||
P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to map fd\n");
|
||||
return fd;
|
||||
}
|
||||
|
||||
ret = p9_fd_open(trans, fd, fd);
|
||||
if (ret < 0) {
|
||||
P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n");
|
||||
sockfd_put(csocket);
|
||||
return ret;
|
||||
}
|
||||
|
||||
((struct p9_trans_fd *)trans->priv)->rd->f_flags |= O_NONBLOCK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p9_fd_open(struct p9_transport *trans, int rfd, int wfd)
|
||||
{
|
||||
struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd),
|
||||
GFP_KERNEL);
|
||||
if (!ts)
|
||||
return -ENOMEM;
|
||||
|
||||
ts->rd = fget(rfd);
|
||||
ts->wr = fget(wfd);
|
||||
if (!ts->rd || !ts->wr) {
|
||||
if (ts->rd)
|
||||
fput(ts->rd);
|
||||
if (ts->wr)
|
||||
fput(ts->wr);
|
||||
kfree(ts);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
trans->priv = ts;
|
||||
trans->status = Connected;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* p9_fd_read- read from a fd
|
||||
* @v9ses: session information
|
||||
* @v: buffer to receive data into
|
||||
* @len: size of receive buffer
|
||||
*
|
||||
*/
|
||||
static int p9_fd_read(struct p9_transport *trans, void *v, int len)
|
||||
{
|
||||
int ret;
|
||||
struct p9_trans_fd *ts = NULL;
|
||||
|
||||
if (trans && trans->status != Disconnected)
|
||||
ts = trans->priv;
|
||||
|
||||
if (!ts)
|
||||
return -EREMOTEIO;
|
||||
|
||||
if (!(ts->rd->f_flags & O_NONBLOCK))
|
||||
P9_DPRINTK(P9_DEBUG_ERROR, "blocking read ...\n");
|
||||
|
||||
ret = kernel_read(ts->rd, ts->rd->f_pos, v, len);
|
||||
if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
|
||||
trans->status = Disconnected;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* p9_fd_write - write to a socket
|
||||
* @v9ses: session information
|
||||
* @v: buffer to send data from
|
||||
* @len: size of send buffer
|
||||
*
|
||||
*/
|
||||
static int p9_fd_write(struct p9_transport *trans, void *v, int len)
|
||||
{
|
||||
int ret;
|
||||
mm_segment_t oldfs;
|
||||
struct p9_trans_fd *ts = NULL;
|
||||
|
||||
if (trans && trans->status != Disconnected)
|
||||
ts = trans->priv;
|
||||
|
||||
if (!ts)
|
||||
return -EREMOTEIO;
|
||||
|
||||
if (!(ts->wr->f_flags & O_NONBLOCK))
|
||||
P9_DPRINTK(P9_DEBUG_ERROR, "blocking write ...\n");
|
||||
|
||||
oldfs = get_fs();
|
||||
set_fs(get_ds());
|
||||
/* The cast to a user pointer is valid due to the set_fs() */
|
||||
ret = vfs_write(ts->wr, (void __user *)v, len, &ts->wr->f_pos);
|
||||
set_fs(oldfs);
|
||||
|
||||
if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
|
||||
trans->status = Disconnected;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
p9_fd_poll(struct p9_transport *trans, struct poll_table_struct *pt)
|
||||
{
|
||||
int ret, n;
|
||||
struct p9_trans_fd *ts = NULL;
|
||||
mm_segment_t oldfs;
|
||||
|
||||
if (trans && trans->status == Connected)
|
||||
ts = trans->priv;
|
||||
|
||||
if (!ts)
|
||||
return -EREMOTEIO;
|
||||
|
||||
if (!ts->rd->f_op || !ts->rd->f_op->poll)
|
||||
return -EIO;
|
||||
|
||||
if (!ts->wr->f_op || !ts->wr->f_op->poll)
|
||||
return -EIO;
|
||||
|
||||
oldfs = get_fs();
|
||||
set_fs(get_ds());
|
||||
|
||||
ret = ts->rd->f_op->poll(ts->rd, pt);
|
||||
if (ret < 0)
|
||||
goto end;
|
||||
|
||||
if (ts->rd != ts->wr) {
|
||||
n = ts->wr->f_op->poll(ts->wr, pt);
|
||||
if (n < 0) {
|
||||
ret = n;
|
||||
goto end;
|
||||
}
|
||||
ret = (ret & ~POLLOUT) | (n & ~POLLIN);
|
||||
}
|
||||
|
||||
end:
|
||||
set_fs(oldfs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* p9_sock_close - shutdown socket
|
||||
* @trans: private socket structure
|
||||
*
|
||||
*/
|
||||
static void p9_fd_close(struct p9_transport *trans)
|
||||
{
|
||||
struct p9_trans_fd *ts;
|
||||
|
||||
if (!trans)
|
||||
return;
|
||||
|
||||
ts = xchg(&trans->priv, NULL);
|
||||
|
||||
if (!ts)
|
||||
return;
|
||||
|
||||
trans->status = Disconnected;
|
||||
if (ts->rd)
|
||||
fput(ts->rd);
|
||||
if (ts->wr)
|
||||
fput(ts->wr);
|
||||
kfree(ts);
|
||||
}
|
||||
|
||||
125
net/9p/util.c
Normal file
125
net/9p/util.c
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* net/9p/util.c
|
||||
*
|
||||
* This file contains some helper functions
|
||||
*
|
||||
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
|
||||
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
|
||||
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to:
|
||||
* Free Software Foundation
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02111-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/parser.h>
|
||||
#include <linux/idr.h>
|
||||
#include <net/9p/9p.h>
|
||||
|
||||
struct p9_idpool {
|
||||
struct semaphore lock;
|
||||
struct idr pool;
|
||||
};
|
||||
|
||||
struct p9_idpool *p9_idpool_create(void)
|
||||
{
|
||||
struct p9_idpool *p;
|
||||
|
||||
p = kmalloc(sizeof(struct p9_idpool), GFP_KERNEL);
|
||||
if (!p)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
init_MUTEX(&p->lock);
|
||||
idr_init(&p->pool);
|
||||
|
||||
return p;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_idpool_create);
|
||||
|
||||
void p9_idpool_destroy(struct p9_idpool *p)
|
||||
{
|
||||
idr_destroy(&p->pool);
|
||||
kfree(p);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_idpool_destroy);
|
||||
|
||||
/**
|
||||
* p9_idpool_get - allocate numeric id from pool
|
||||
* @p - pool to allocate from
|
||||
*
|
||||
* XXX - This seems to be an awful generic function, should it be in idr.c with
|
||||
* the lock included in struct idr?
|
||||
*/
|
||||
|
||||
int p9_idpool_get(struct p9_idpool *p)
|
||||
{
|
||||
int i = 0;
|
||||
int error;
|
||||
|
||||
retry:
|
||||
if (idr_pre_get(&p->pool, GFP_KERNEL) == 0)
|
||||
return 0;
|
||||
|
||||
if (down_interruptible(&p->lock) == -EINTR) {
|
||||
P9_EPRINTK(KERN_WARNING, "Interrupted while locking\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* no need to store exactly p, we just need something non-null */
|
||||
error = idr_get_new(&p->pool, p, &i);
|
||||
up(&p->lock);
|
||||
|
||||
if (error == -EAGAIN)
|
||||
goto retry;
|
||||
else if (error)
|
||||
return -1;
|
||||
|
||||
return i;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_idpool_get);
|
||||
|
||||
/**
|
||||
* p9_idpool_put - release numeric id from pool
|
||||
* @p - pool to allocate from
|
||||
*
|
||||
* XXX - This seems to be an awful generic function, should it be in idr.c with
|
||||
* the lock included in struct idr?
|
||||
*/
|
||||
|
||||
void p9_idpool_put(int id, struct p9_idpool *p)
|
||||
{
|
||||
if (down_interruptible(&p->lock) == -EINTR) {
|
||||
P9_EPRINTK(KERN_WARNING, "Interrupted while locking\n");
|
||||
return;
|
||||
}
|
||||
idr_remove(&p->pool, id);
|
||||
up(&p->lock);
|
||||
}
|
||||
EXPORT_SYMBOL(p9_idpool_put);
|
||||
|
||||
/**
|
||||
* p9_idpool_check - check if the specified id is available
|
||||
* @id - id to check
|
||||
* @p - pool
|
||||
*/
|
||||
int p9_idpool_check(int id, struct p9_idpool *p)
|
||||
{
|
||||
return idr_find(&p->pool, id) != NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(p9_idpool_check);
|
||||
Loading…
Reference in a new issue