Re: [PATCH][REFERENCE ONLY] 9p: ramfs 9p server
Latchesar Ionkov wrote: Sample ramfs file server that uses the in-kernel 9P file server support. This code is for reference only. Reference code generally goes in Documentation/ -- Chris - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH][REFERENCE ONLY] 9p: ramfs 9p server
Sample ramfs file server that uses the in-kernel 9P file server support. This code is for reference only. Signed-off-by: Latchesar Ionkov <[EMAIL PROTECTED]> --- net/9p/Kconfig |8 +- net/9p/Makefile |1 + net/9p/ramfs/ramfs.c | 986 ++ 3 files changed, 994 insertions(+), 1 deletions(-) diff --git a/net/9p/Kconfig b/net/9p/Kconfig index 5b0dc28..68f7496 100644 --- a/net/9p/Kconfig +++ b/net/9p/Kconfig @@ -23,11 +23,17 @@ config NET_9P_FD file descriptors. TCP/IP is the default transport for 9p, so if you are going to use 9p, you'll likely want this. -config NET_9P_SRV +menuconfig NET_9P_SRV tristate "9P server support" depends on NET_9P help Say Y if you want the 9P server support + +config NET_9P_RAMFS +tristate "9P ramfs sample file server" +depends on NET_9P_SRV && NET_9P_LOOP +help + Say Y if you want the 9P ramfs support config NET_9P_VIRTIO depends on NET_9P && EXPERIMENTAL && VIRTIO tristate "9P Virtio Transport (Experimental)" diff --git a/net/9p/Makefile b/net/9p/Makefile index 6ee024e..3808c40 100644 --- a/net/9p/Makefile +++ b/net/9p/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_NET_9P_FD) += 9pnet_fd.o obj-$(CONFIG_NET_9P_LOOP) += 9pnet_loop.o obj-$(CONFIG_NET_9P_SRV) += 9psrv.o obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o +obj-$(CONFIG_NET_9P_RAMFS) += ramfs/ 9pnet-objs := \ mod.o \ diff --git a/net/9p/ramfs/ramfs.c b/net/9p/ramfs/ramfs.c new file mode 100644 index 000..3aff620 --- /dev/null +++ b/net/9p/ramfs/ramfs.c @@ -0,0 +1,986 @@ +/* + * net/9p/srv/ramfs.c + * + * Simple RAM filesystem + * + * Copyright (C) 2007 by Latchesar Ionkov <[EMAIL PROTECTED]> + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#define ROOTPERM 0777 + +struct ramfs_file { + struct mutexlock; /* file lock */ + atomic_trefcount; + unsigned long status; + char*name; + u32 perm; + u64 length; + u32 atime; + u32 mtime; + u32 uid; + u32 gid; + u32 muid; + char*extension; + struct p9_qid qid; + int excl; + + struct ramfs_file *parent; + struct ramfs_file *next; /* protected by parent lock */ + struct ramfs_file *prev; + + struct ramfs_file *dirents; /* if directory */ + struct ramfs_file *dirlast; + + struct list_headfid_list; /* all fids for a file */ + + u8 *data; + u64 datasize; +}; + +struct ramfs_fid { + struct ramfs_file *file; + int omode; + u64 diroffset; + struct ramfs_file *dirent; + struct list_headfid_list; /* all fids for a file */ +}; + +enum { + Removed = 1, +}; + +static struct p9srv_type *ramfs_srv_type; +static struct ramfs_file *root; +static u64 qidpath; +static int blksize = 8192; + +static char *Enospace = "no space left"; +static char *Einternal = "internal error"; + +static void ramfs_attach(struct p9srv_req *req); +static void ramfs_walk(struct p9srv_req *req); +static void ramfs_open(struct p9srv_req *req); +static void ramfs_create(struct p9srv_req *req); +static void ramfs_read(struct p9srv_req *req); +static void ramfs_write(struct p9srv_req *req); +static void ramfs_clunk(struct p9srv_req *req); +static void ramfs_remove(struct p9srv_req *req); +static void ramfs_stat(struct p9srv_req *req); +static void ramfs_wstat(struct p9srv_req *req); +static void ramfs_fiddestroy(struct p9srv_fid *fid); +static void ramfs_connopen(struct p9srv_conn *conn); +static void ramfs_connclose(struct p9srv_conn *conn); + +static char *p9_strdup(struct p9_str *str) +{ + char *ret; + + ret = kmalloc(str->len + 1, GFP_KERNEL); + memmove(ret, str->str, str->len); + ret[str->len] = '\0'; + +
Re: [PATCH][REFERENCE ONLY] 9p: ramfs 9p server
Latchesar Ionkov wrote: Sample ramfs file server that uses the in-kernel 9P file server support. This code is for reference only. Reference code generally goes in Documentation/ -- Chris - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH][REFERENCE ONLY] 9p: ramfs 9p server
Sample ramfs file server that uses the in-kernel 9P file server support. This code is for reference only. Signed-off-by: Latchesar Ionkov [EMAIL PROTECTED] --- net/9p/Kconfig |8 +- net/9p/Makefile |1 + net/9p/ramfs/ramfs.c | 986 ++ 3 files changed, 994 insertions(+), 1 deletions(-) diff --git a/net/9p/Kconfig b/net/9p/Kconfig index 5b0dc28..68f7496 100644 --- a/net/9p/Kconfig +++ b/net/9p/Kconfig @@ -23,11 +23,17 @@ config NET_9P_FD file descriptors. TCP/IP is the default transport for 9p, so if you are going to use 9p, you'll likely want this. -config NET_9P_SRV +menuconfig NET_9P_SRV tristate 9P server support depends on NET_9P help Say Y if you want the 9P server support + +config NET_9P_RAMFS +tristate 9P ramfs sample file server +depends on NET_9P_SRV NET_9P_LOOP +help + Say Y if you want the 9P ramfs support config NET_9P_VIRTIO depends on NET_9P EXPERIMENTAL VIRTIO tristate 9P Virtio Transport (Experimental) diff --git a/net/9p/Makefile b/net/9p/Makefile index 6ee024e..3808c40 100644 --- a/net/9p/Makefile +++ b/net/9p/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_NET_9P_FD) += 9pnet_fd.o obj-$(CONFIG_NET_9P_LOOP) += 9pnet_loop.o obj-$(CONFIG_NET_9P_SRV) += 9psrv.o obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o +obj-$(CONFIG_NET_9P_RAMFS) += ramfs/ 9pnet-objs := \ mod.o \ diff --git a/net/9p/ramfs/ramfs.c b/net/9p/ramfs/ramfs.c new file mode 100644 index 000..3aff620 --- /dev/null +++ b/net/9p/ramfs/ramfs.c @@ -0,0 +1,986 @@ +/* + * net/9p/srv/ramfs.c + * + * Simple RAM filesystem + * + * Copyright (C) 2007 by Latchesar Ionkov [EMAIL PROTECTED] + * + * 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 linux/errno.h +#include linux/fs.h +#include linux/poll.h +#include linux/parser.h +#include net/9p/9p.h +#include net/9p/transport.h +#include net/9p/srv.h + +#define ROOTPERM 0777 + +struct ramfs_file { + struct mutexlock; /* file lock */ + atomic_trefcount; + unsigned long status; + char*name; + u32 perm; + u64 length; + u32 atime; + u32 mtime; + u32 uid; + u32 gid; + u32 muid; + char*extension; + struct p9_qid qid; + int excl; + + struct ramfs_file *parent; + struct ramfs_file *next; /* protected by parent lock */ + struct ramfs_file *prev; + + struct ramfs_file *dirents; /* if directory */ + struct ramfs_file *dirlast; + + struct list_headfid_list; /* all fids for a file */ + + u8 *data; + u64 datasize; +}; + +struct ramfs_fid { + struct ramfs_file *file; + int omode; + u64 diroffset; + struct ramfs_file *dirent; + struct list_headfid_list; /* all fids for a file */ +}; + +enum { + Removed = 1, +}; + +static struct p9srv_type *ramfs_srv_type; +static struct ramfs_file *root; +static u64 qidpath; +static int blksize = 8192; + +static char *Enospace = no space left; +static char *Einternal = internal error; + +static void ramfs_attach(struct p9srv_req *req); +static void ramfs_walk(struct p9srv_req *req); +static void ramfs_open(struct p9srv_req *req); +static void ramfs_create(struct p9srv_req *req); +static void ramfs_read(struct p9srv_req *req); +static void ramfs_write(struct p9srv_req *req); +static void ramfs_clunk(struct p9srv_req *req); +static void ramfs_remove(struct p9srv_req *req); +static void ramfs_stat(struct p9srv_req *req); +static void ramfs_wstat(struct p9srv_req *req); +static void ramfs_fiddestroy(struct p9srv_fid *fid); +static void ramfs_connopen(struct p9srv_conn *conn); +static void ramfs_connclose(struct p9srv_conn *conn); + +static char *p9_strdup(struct p9_str *str) +{ + char *ret; + + ret =