2 * linux/fs/9p/trans_fd.c
4 * File Descriptor Transport Layer
6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7 * Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/net.h>
30 #include <linux/ipv6.h>
31 #include <linux/errno.h>
32 #include <linux/kernel.h>
34 #include <asm/uaccess.h>
35 #include <linux/inet.h>
36 #include <linux/idr.h>
37 #include <linux/file.h>
41 #include "transport.h"
43 struct v9fs_trans_fd
{
45 struct file
*out_file
;
49 * v9fs_fd_recv - receive from a socket
50 * @v9ses: session information
51 * @v: buffer to receive data into
52 * @len: size of receive buffer
56 static int v9fs_fd_recv(struct v9fs_transport
*trans
, void *v
, int len
)
58 struct v9fs_trans_fd
*ts
= trans
? trans
->priv
: NULL
;
60 if (!trans
|| trans
->status
!= Connected
|| !ts
)
63 return kernel_read(ts
->in_file
, ts
->in_file
->f_pos
, v
, len
);
67 * v9fs_fd_send - send to a socket
68 * @v9ses: session information
69 * @v: buffer to send data from
70 * @len: size of send buffer
74 static int v9fs_fd_send(struct v9fs_transport
*trans
, void *v
, int len
)
76 struct v9fs_trans_fd
*ts
= trans
? trans
->priv
: NULL
;
77 mm_segment_t oldfs
= get_fs();
80 if (!trans
|| trans
->status
!= Connected
|| !ts
)
84 /* The cast to a user pointer is valid due to the set_fs() */
85 ret
= vfs_write(ts
->out_file
, (void __user
*)v
, len
, &ts
->out_file
->f_pos
);
92 * v9fs_fd_init - initialize file descriptor transport
93 * @v9ses: session information
94 * @addr: address of server to mount
95 * @data: mount options
100 v9fs_fd_init(struct v9fs_session_info
*v9ses
, const char *addr
, char *data
)
102 struct v9fs_trans_fd
*ts
= NULL
;
103 struct v9fs_transport
*trans
= v9ses
->transport
;
105 if((v9ses
->wfdno
== ~0) || (v9ses
->rfdno
== ~0)) {
106 printk(KERN_ERR
"v9fs: Insufficient options for proto=fd\n");
110 ts
= kmalloc(sizeof(struct v9fs_trans_fd
), GFP_KERNEL
);
115 ts
->in_file
= fget( v9ses
->rfdno
);
116 ts
->out_file
= fget( v9ses
->wfdno
);
118 if (!ts
->in_file
|| !ts
->out_file
) {
130 trans
->status
= Connected
;
137 * v9fs_fd_close - shutdown file descriptor
138 * @trans: private socket structure
142 static void v9fs_fd_close(struct v9fs_transport
*trans
)
144 struct v9fs_trans_fd
*ts
;
149 ts
= xchg(&trans
->priv
, NULL
);
154 trans
->status
= Disconnected
;
165 v9fs_fd_poll(struct v9fs_transport
*trans
, struct poll_table_struct
*pt
)
168 struct v9fs_trans_fd
*ts
;
175 if (trans
->status
!= Connected
|| !ts
)
181 if (!ts
->in_file
->f_op
|| !ts
->in_file
->f_op
->poll
) {
186 ret
= ts
->in_file
->f_op
->poll(ts
->in_file
, pt
);
188 if (ts
->out_file
!= ts
->in_file
) {
189 if (!ts
->out_file
->f_op
|| !ts
->out_file
->f_op
->poll
) {
194 n
= ts
->out_file
->f_op
->poll(ts
->out_file
, pt
);
208 struct v9fs_transport v9fs_trans_fd
= {
209 .init
= v9fs_fd_init
,
210 .write
= v9fs_fd_send
,
211 .read
= v9fs_fd_recv
,
212 .close
= v9fs_fd_close
,
213 .poll
= v9fs_fd_poll
,