This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / fs / ncpfs / sock.c
index 845bfe4..4d49900 100644 (file)
 
 #include "ncpsign_kernel.h"
 
-static int _recv(struct socket *sock, void *buf, int size, unsigned flags)
+static int _recv(struct socket *sock, unsigned char *ubuf, int size,
+                unsigned flags)
 {
-       struct msghdr msg = {NULL, };
-       struct kvec iov = {buf, size};
-       return kernel_recvmsg(sock, &msg, &iov, 1, size, flags);
-}
+       struct iovec iov;
+       struct msghdr msg;
 
-static inline int do_send(struct socket *sock, struct kvec *vec, int count,
-                         int len, unsigned flags)
-{
-       struct msghdr msg = { .msg_flags = flags };
-       return kernel_sendmsg(sock, &msg, vec, count, len);
+       iov.iov_base = ubuf;
+       iov.iov_len = size;
+
+       msg.msg_name = NULL;
+       msg.msg_namelen = 0;
+       msg.msg_control = NULL;
+       msg.msg_iov = &iov;
+       msg.msg_iovlen = 1;
+
+       return sock_recvmsg(sock, &msg, size, flags);
 }
 
-static int _send(struct socket *sock, const void *buff, int len)
+static inline int _send(struct socket *sock, const void *buff, int len)
 {
-       struct kvec vec;
-       vec.iov_base = (void *) buff;
-       vec.iov_len = len;
-       return do_send(sock, &vec, 1, len, 0);
+       struct iovec iov;
+       struct msghdr msg;
+
+       iov.iov_base = (void *) buff;
+       iov.iov_len = len;
+
+       msg.msg_name = NULL;
+       msg.msg_namelen = 0;
+       msg.msg_control = NULL;
+       msg.msg_iov = &iov;
+       msg.msg_iovlen = 1;
+       msg.msg_flags = 0;
+
+       return sock_sendmsg(sock, &msg, len);
 }
 
 struct ncp_request_reply {
@@ -60,57 +74,52 @@ struct ncp_request_reply {
        size_t datalen;
        int result;
        enum { RQ_DONE, RQ_INPROGRESS, RQ_QUEUED, RQ_IDLE } status;
-       struct kvec* tx_ciov;
+       struct iovec* tx_ciov;
        size_t tx_totallen;
        size_t tx_iovlen;
-       struct kvec tx_iov[3];
+       struct iovec tx_iov[3];
        u_int16_t tx_type;
        u_int32_t sign[6];
 };
 
-void ncp_tcp_data_ready(struct sock *sk, int len)
-{
+void ncp_tcp_data_ready(struct sock *sk, int len) {
        struct ncp_server *server = sk->sk_user_data;
 
        server->data_ready(sk, len);
        schedule_work(&server->rcv.tq);
 }
 
-void ncp_tcp_error_report(struct sock *sk)
-{
+void ncp_tcp_error_report(struct sock *sk) {
        struct ncp_server *server = sk->sk_user_data;
        
        server->error_report(sk);
        schedule_work(&server->rcv.tq);
 }
 
-void ncp_tcp_write_space(struct sock *sk)
-{
+void ncp_tcp_write_space(struct sock *sk) {
        struct ncp_server *server = sk->sk_user_data;
        
        /* We do not need any locking: we first set tx.creq, and then we do sendmsg,
           not vice versa... */
        server->write_space(sk);
-       if (server->tx.creq)
+       if (server->tx.creq) {
                schedule_work(&server->tx.tq);
+       }
 }
 
-void ncpdgram_timeout_call(unsigned long v)
-{
+void ncpdgram_timeout_call(unsigned long v) {
        struct ncp_server *server = (void*)v;
        
        schedule_work(&server->timeout_tq);
 }
 
-static inline void ncp_finish_request(struct ncp_request_reply *req, int result)
-{
+static inline void ncp_finish_request(struct ncp_request_reply *req, int result) {
        req->result = result;
        req->status = RQ_DONE;
        wake_up_all(&req->wq);
 }
 
-static void __abort_ncp_connection(struct ncp_server *server, struct ncp_request_reply *aborted, int err)
-{
+static void __abort_ncp_connection(struct ncp_server *server, struct ncp_request_reply *aborted, int err) {
        struct ncp_request_reply *req;
 
        ncp_invalidate_conn(server);
@@ -147,13 +156,11 @@ static void __abort_ncp_connection(struct ncp_server *server, struct ncp_request
        }
 }
 
-static inline int get_conn_number(struct ncp_reply_header *rp)
-{
+static inline int get_conn_number(struct ncp_reply_header *rp) {
        return rp->conn_low | (rp->conn_high << 8);
 }
 
-static inline void __ncp_abort_request(struct ncp_server *server, struct ncp_request_reply *req, int err)
-{
+static inline void __ncp_abort_request(struct ncp_server *server, struct ncp_request_reply *req, int err) {
        /* If req is done, we got signal, but we also received answer... */
        switch (req->status) {
                case RQ_IDLE:
@@ -169,46 +176,55 @@ static inline void __ncp_abort_request(struct ncp_server *server, struct ncp_req
        }
 }
 
-static inline void ncp_abort_request(struct ncp_server *server, struct ncp_request_reply *req, int err)
-{
+static inline void ncp_abort_request(struct ncp_server *server, struct ncp_request_reply *req, int err) {
        down(&server->rcv.creq_sem);
        __ncp_abort_request(server, req, err);
        up(&server->rcv.creq_sem);
 }
 
-static inline void __ncptcp_abort(struct ncp_server *server)
-{
+static inline void __ncptcp_abort(struct ncp_server *server) {
        __abort_ncp_connection(server, NULL, 0);
 }
 
-static int ncpdgram_send(struct socket *sock, struct ncp_request_reply *req)
-{
-       struct kvec vec[3];
+static int ncpdgram_send(struct socket *sock, struct ncp_request_reply *req) {
+       struct msghdr msg;
+       struct iovec iov[3];
+       
        /* sock_sendmsg updates iov pointers for us :-( */
-       memcpy(vec, req->tx_ciov, req->tx_iovlen * sizeof(vec[0]));
-       return do_send(sock, vec, req->tx_iovlen,
-                      req->tx_totallen, MSG_DONTWAIT);
+       memcpy(iov, req->tx_ciov, req->tx_iovlen * sizeof(iov[0]));
+       msg.msg_name = NULL;
+       msg.msg_namelen = 0;
+       msg.msg_control = NULL;
+       msg.msg_iov = iov;
+       msg.msg_iovlen = req->tx_iovlen;
+       msg.msg_flags = MSG_DONTWAIT;
+       return sock_sendmsg(sock, &msg, req->tx_totallen);
 }
 
-static void __ncptcp_try_send(struct ncp_server *server)
-{
+static void __ncptcp_try_send(struct ncp_server *server) {
        struct ncp_request_reply *rq;
-       struct kvec *iov;
-       struct kvec iovc[3];
+       struct msghdr msg;
+       struct iovec* iov;
+       struct iovec iovc[3];
        int result;
 
        rq = server->tx.creq;
-       if (!rq)
+       if (!rq) {
                return;
+       }
 
        /* sock_sendmsg updates iov pointers for us :-( */
        memcpy(iovc, rq->tx_ciov, rq->tx_iovlen * sizeof(iov[0]));
-       result = do_send(server->ncp_sock, iovc, rq->tx_iovlen,
-                        rq->tx_totallen, MSG_NOSIGNAL | MSG_DONTWAIT);
-
-       if (result == -EAGAIN)
+       msg.msg_name = NULL;
+       msg.msg_namelen = 0;
+       msg.msg_control = NULL;
+       msg.msg_iov = iovc;
+       msg.msg_iovlen = rq->tx_iovlen;
+       msg.msg_flags = MSG_NOSIGNAL | MSG_DONTWAIT;
+       result = sock_sendmsg(server->ncp_sock, &msg, rq->tx_totallen);
+       if (result == -EAGAIN) {
                return;
-
+       }
        if (result < 0) {
                printk(KERN_ERR "ncpfs: tcp: Send failed: %d\n", result);
                __ncp_abort_request(server, rq, result);
@@ -231,16 +247,14 @@ static void __ncptcp_try_send(struct ncp_server *server)
        rq->tx_ciov = iov;
 }
 
-static inline void ncp_init_header(struct ncp_server *server, struct ncp_request_reply *req, struct ncp_request_header *h)
-{
+static inline void ncp_init_header(struct ncp_server *server, struct ncp_request_reply *req, struct ncp_request_header *h) {
        req->status = RQ_INPROGRESS;
        h->conn_low = server->connection;
        h->conn_high = server->connection >> 8;
        h->sequence = ++server->sequence;
 }
        
-static void ncpdgram_start_request(struct ncp_server *server, struct ncp_request_reply *req)
-{
+static void ncpdgram_start_request(struct ncp_server *server, struct ncp_request_reply *req) {
        size_t signlen;
        struct ncp_request_header* h;
        
@@ -268,8 +282,7 @@ static void ncpdgram_start_request(struct ncp_server *server, struct ncp_request
 #define NCP_TCP_XMIT_VERSION   (1)
 #define NCP_TCP_RCVD_MAGIC     (0x744E6350)
 
-static void ncptcp_start_request(struct ncp_server *server, struct ncp_request_reply *req)
-{
+static void ncptcp_start_request(struct ncp_server *server, struct ncp_request_reply *req) {
        size_t signlen;
        struct ncp_request_header* h;
 
@@ -293,16 +306,14 @@ static void ncptcp_start_request(struct ncp_server *server, struct ncp_request_r
        __ncptcp_try_send(server);
 }
 
-static inline void __ncp_start_request(struct ncp_server *server, struct ncp_request_reply *req)
-{
+static inline void __ncp_start_request(struct ncp_server *server, struct ncp_request_reply *req) {
        if (server->ncp_sock->type == SOCK_STREAM)
                ncptcp_start_request(server, req);
        else
                ncpdgram_start_request(server, req);
 }
 
-static int ncp_add_request(struct ncp_server *server, struct ncp_request_reply *req)
-{
+static int ncp_add_request(struct ncp_server *server, struct ncp_request_reply *req) {
        down(&server->rcv.creq_sem);
        if (!ncp_conn_valid(server)) {
                up(&server->rcv.creq_sem);
@@ -320,8 +331,7 @@ static int ncp_add_request(struct ncp_server *server, struct ncp_request_reply *
        return 0;
 }
 
-static void __ncp_next_request(struct ncp_server *server)
-{
+static void __ncp_next_request(struct ncp_server *server) {
        struct ncp_request_reply *req;
 
        server->rcv.creq = NULL;
@@ -333,10 +343,10 @@ static void __ncp_next_request(struct ncp_server *server)
        __ncp_start_request(server, req);
 }
 
-static void info_server(struct ncp_server *server, unsigned int id, const void * data, size_t len)
-{
+static void info_server(struct ncp_server *server, unsigned int id, const void * data, size_t len) {
        if (server->info_sock) {
-               struct kvec iov[2];
+               struct iovec iov[2];
+               struct msghdr msg;
                __u32 hdr[2];
        
                hdr[0] = cpu_to_be32(len + 8);
@@ -347,12 +357,18 @@ static void info_server(struct ncp_server *server, unsigned int id, const void *
                iov[1].iov_base = (void *) data;
                iov[1].iov_len = len;
 
-               do_send(server->info_sock, iov, 2, len + 8, MSG_NOSIGNAL);
+               msg.msg_name = NULL;
+               msg.msg_namelen = 0;
+               msg.msg_control = NULL;
+               msg.msg_iov = iov;
+               msg.msg_iovlen = 2;
+               msg.msg_flags = MSG_NOSIGNAL;
+
+               sock_sendmsg(server->info_sock, &msg, len + 8);
        }
 }
 
-void ncpdgram_rcv_proc(void *s)
-{
+static void __ncpdgram_rcv_proc(void *s) {
        struct ncp_server *server = s;
        struct socket* sock;
        
@@ -362,7 +378,7 @@ void ncpdgram_rcv_proc(void *s)
                struct ncp_reply_header reply;
                int result;
 
-               result = _recv(sock, &reply, sizeof(reply), MSG_PEEK | MSG_DONTWAIT);
+               result = _recv(sock, (void*)&reply, sizeof(reply), MSG_PEEK | MSG_DONTWAIT);
                if (result < 0) {
                        break;
                }
@@ -437,12 +453,21 @@ void ncpdgram_rcv_proc(void *s)
                        up(&server->rcv.creq_sem);
                }
 drop:;         
-               _recv(sock, &reply, sizeof(reply), MSG_DONTWAIT);
+               _recv(sock, (void*)&reply, sizeof(reply), MSG_DONTWAIT);
        }
 }
 
-static void __ncpdgram_timeout_proc(struct ncp_server *server)
-{
+void ncpdgram_rcv_proc(void *s) {
+       mm_segment_t fs;
+       struct ncp_server *server = s;
+       
+       fs = get_fs();
+       set_fs(get_ds());
+       __ncpdgram_rcv_proc(server);
+       set_fs(fs);
+}
+
+static void __ncpdgram_timeout_proc(struct ncp_server *server) {
        /* If timer is pending, we are processing another request... */
        if (!timer_pending(&server->timeout_tm)) {
                struct ncp_request_reply* req;
@@ -469,22 +494,24 @@ static void __ncpdgram_timeout_proc(struct ncp_server *server)
        }
 }
 
-void ncpdgram_timeout_proc(void *s)
-{
+void ncpdgram_timeout_proc(void *s) {
+       mm_segment_t fs;
        struct ncp_server *server = s;
+       
+       fs = get_fs();
+       set_fs(get_ds());
        down(&server->rcv.creq_sem);
        __ncpdgram_timeout_proc(server);
        up(&server->rcv.creq_sem);
+       set_fs(fs);
 }
 
-static inline void ncp_init_req(struct ncp_request_reply* req)
-{
+static inline void ncp_init_req(struct ncp_request_reply* req) {
        init_waitqueue_head(&req->wq);
        req->status = RQ_IDLE;
 }
 
-static int do_tcp_rcv(struct ncp_server *server, void *buffer, size_t len)
-{
+static int do_tcp_rcv(struct ncp_server *server, void *buffer, size_t len) {
        int result;
        
        if (buffer) {
@@ -507,8 +534,7 @@ static int do_tcp_rcv(struct ncp_server *server, void *buffer, size_t len)
        return result;
 }      
 
-static int __ncptcp_rcv_proc(struct ncp_server *server)
-{
+static int __ncptcp_rcv_proc(struct ncp_server *server) {
        /* We have to check the result, so store the complete header */
        while (1) {
                int result;
@@ -653,22 +679,30 @@ skipdata:;
        }
 }
 
-void ncp_tcp_rcv_proc(void *s)
-{
+void ncp_tcp_rcv_proc(void *s) {
+       mm_segment_t fs;
        struct ncp_server *server = s;
 
+       fs = get_fs();
+       set_fs(get_ds());
        down(&server->rcv.creq_sem);
        __ncptcp_rcv_proc(server);
        up(&server->rcv.creq_sem);
+       set_fs(fs);
+       return;
 }
 
-void ncp_tcp_tx_proc(void *s)
-{
+void ncp_tcp_tx_proc(void *s) {
+       mm_segment_t fs;
        struct ncp_server *server = s;
        
+       fs = get_fs();
+       set_fs(get_ds());
        down(&server->rcv.creq_sem);
        __ncptcp_try_send(server);
        up(&server->rcv.creq_sem);
+       set_fs(fs);
+       return;
 }
 
 static int do_ncp_rpc_call(struct ncp_server *server, int size,
@@ -680,7 +714,7 @@ static int do_ncp_rpc_call(struct ncp_server *server, int size,
        ncp_init_req(&req);
        req.reply_buf = reply_buf;
        req.datalen = max_reply_size;
-       req.tx_iov[1].iov_base = server->packet;
+       req.tx_iov[1].iov_base = (void *) server->packet;
        req.tx_iov[1].iov_len = size;
        req.tx_iovlen = 1;
        req.tx_totallen = size;
@@ -714,6 +748,7 @@ static int ncp_do_request(struct ncp_server *server, int size,
                return -EIO;
        }
        {
+               mm_segment_t fs;
                sigset_t old_set;
                unsigned long mask, flags;
 
@@ -738,8 +773,13 @@ static int ncp_do_request(struct ncp_server *server, int size,
                recalc_sigpending();
                spin_unlock_irqrestore(&current->sighand->siglock, flags);
                
+               fs = get_fs();
+               set_fs(get_ds());
+
                result = do_ncp_rpc_call(server, size, reply, max_reply_size);
 
+               set_fs(fs);
+
                spin_lock_irqsave(&current->sighand->siglock, flags);
                current->blocked = old_set;
                recalc_sigpending();