2 * linux/fs/9p/trans_fd.c
4 * File Descriptor Transport Layer
6 * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
26 #include <linux/config.h>
27 #include <linux/module.h>
28 #include <linux/net.h>
29 #include <linux/ipv6.h>
30 #include <linux/errno.h>
31 #include <linux/kernel.h>
33 #include <asm/uaccess.h>
34 #include <linux/inet.h>
35 #include <linux/idr.h>
36 #include <linux/file.h>
40 #include "transport.h"
42 struct v9fs_trans_fd
{
44 struct file
*out_file
;
48 * v9fs_fd_recv - receive from a socket
49 * @v9ses: session information
50 * @v: buffer to receive data into
51 * @len: size of receive buffer
55 static int v9fs_fd_recv(struct v9fs_transport
*trans
, void *v
, int len
)
57 struct v9fs_trans_fd
*ts
= trans
? trans
->priv
: NULL
;
59 if (!trans
|| trans
->status
!= Connected
|| !ts
)
62 return kernel_read(ts
->in_file
, ts
->in_file
->f_pos
, v
, len
);
66 * v9fs_fd_send - send to a socket
67 * @v9ses: session information
68 * @v: buffer to send data from
69 * @len: size of send buffer
73 static int v9fs_fd_send(struct v9fs_transport
*trans
, void *v
, int len
)
75 struct v9fs_trans_fd
*ts
= trans
? trans
->priv
: NULL
;
76 mm_segment_t oldfs
= get_fs();
79 if (!trans
|| trans
->status
!= Connected
|| !ts
)
83 /* The cast to a user pointer is valid due to the set_fs() */
84 ret
= vfs_write(ts
->out_file
, (void __user
*)v
, len
, &ts
->out_file
->f_pos
);
91 * v9fs_fd_init - initialize file descriptor transport
92 * @v9ses: session information
93 * @addr: address of server to mount
94 * @data: mount options
99 v9fs_fd_init(struct v9fs_session_info
*v9ses
, const char *addr
, char *data
)
101 struct v9fs_trans_fd
*ts
= NULL
;
102 struct v9fs_transport
*trans
= v9ses
->transport
;
104 if((v9ses
->wfdno
== ~0) || (v9ses
->rfdno
== ~0)) {
105 printk(KERN_ERR
"v9fs: Insufficient options for proto=fd\n");
109 sema_init(&trans
->writelock
, 1);
110 sema_init(&trans
->readlock
, 1);
112 ts
= kmalloc(sizeof(struct v9fs_trans_fd
), GFP_KERNEL
);
117 ts
->in_file
= fget( v9ses
->rfdno
);
118 ts
->out_file
= fget( v9ses
->wfdno
);
120 if (!ts
->in_file
|| !ts
->out_file
) {
132 trans
->status
= Connected
;
139 * v9fs_fd_close - shutdown file descriptor
140 * @trans: private socket structure
144 static void v9fs_fd_close(struct v9fs_transport
*trans
)
146 struct v9fs_trans_fd
*ts
;
151 trans
->status
= Disconnected
;
166 struct v9fs_transport v9fs_trans_fd
= {
167 .init
= v9fs_fd_init
,
168 .write
= v9fs_fd_send
,
169 .read
= v9fs_fd_recv
,
170 .close
= v9fs_fd_close
,