[PATCH] (1/2) inode trimming
[opensuse:kernel.git] / fs / smbfs / sock.c
1 /*
2  *  sock.c
3  *
4  *  Copyright (C) 1995, 1996 by Paal-Kr. Engstad and Volker Lendecke
5  *  Copyright (C) 1997 by Volker Lendecke
6  *
7  *  Please add a note about your changes to smbfs in the ChangeLog file.
8  */
9
10 #include <linux/sched.h>
11 #include <linux/errno.h>
12 #include <linux/socket.h>
13 #include <linux/fcntl.h>
14 #include <linux/file.h>
15 #include <linux/in.h>
16 #include <linux/net.h>
17 #include <linux/mm.h>
18 #include <linux/netdevice.h>
19 #include <linux/smp_lock.h>
20 #include <net/scm.h>
21 #include <net/ip.h>
22
23 #include <linux/smb_fs.h>
24 #include <linux/smb.h>
25 #include <linux/smbno.h>
26
27 #include <asm/uaccess.h>
28
29 #include "smb_debug.h"
30 #include "proto.h"
31
32
33 static int
34 _recvfrom(struct socket *socket, unsigned char *ubuf, int size,
35           unsigned flags)
36 {
37         struct iovec iov;
38         struct msghdr msg;
39         struct scm_cookie scm;
40
41         msg.msg_name = NULL;
42         msg.msg_namelen = 0;
43         msg.msg_iov = &iov;
44         msg.msg_iovlen = 1;
45         msg.msg_control = NULL;
46         iov.iov_base = ubuf;
47         iov.iov_len = size;
48         
49         memset(&scm, 0,sizeof(scm));
50         size=socket->ops->recvmsg(socket, &msg, size, flags, &scm);
51         if(size>=0)
52                 scm_recv(socket,&msg,&scm,flags);
53         return size;
54 }
55
56 static int
57 _send(struct socket *socket, const void *buff, int len)
58 {
59         struct iovec iov;
60         struct msghdr msg;
61         struct scm_cookie scm;
62         int err;
63
64         msg.msg_name = NULL;
65         msg.msg_namelen = 0;
66         msg.msg_iov = &iov;
67         msg.msg_iovlen = 1;
68         msg.msg_control = NULL;
69         msg.msg_controllen = 0;
70         
71         iov.iov_base = (void *)buff;
72         iov.iov_len = len;
73
74         msg.msg_flags = 0;
75
76         err = scm_send(socket, &msg, &scm);
77         if (err >= 0)
78         {
79                 err = socket->ops->sendmsg(socket, &msg, len, &scm);
80                 scm_destroy(&scm);
81         }
82         return err;
83 }
84
85 struct data_callback {
86         struct tq_struct cb;
87         struct sock *sk;
88 };
89 /*
90  * N.B. What happens if we're in here when the socket closes??
91  */
92 static void
93 found_data(struct sock *sk)
94 {
95         /*
96          * FIXME: copied from sock_def_readable, it should be a call to
97          * server->data_ready() -- manfreds@colorfullife.com
98          */
99         read_lock(&sk->callback_lock);
100         if(!sk->dead) {
101                 wake_up_interruptible(sk->sleep);
102                 sock_wake_async(sk->socket,1,POLL_IN);
103         }
104         read_unlock(&sk->callback_lock);
105 }
106
107 static void
108 smb_data_callback(void* ptr)
109 {
110         struct data_callback* job=ptr;
111         struct socket *socket = job->sk->socket;
112         unsigned char peek_buf[4];
113         int result = 0;
114         mm_segment_t fs;
115         int count = 100;   /* this is a lot, we should have some data waiting */
116         int found = 0;
117
118         fs = get_fs();
119         set_fs(get_ds());
120
121         lock_kernel();
122         while (count-- > 0) {
123                 peek_buf[0] = 0;
124
125                 result = -EIO;
126                 if (job->sk->dead) {
127                         PARANOIA("sock dead!\n");
128                         break;
129                 }
130
131                 result = _recvfrom(socket, (void *) peek_buf, 1,
132                                    MSG_PEEK | MSG_DONTWAIT);
133                 if (result < 0)
134                         break;
135                 if (peek_buf[0] != 0x85)
136                         break;
137
138                 /* got SESSION KEEP ALIVE */
139                 result = _recvfrom(socket, (void *) peek_buf, 4,
140                                    MSG_DONTWAIT);
141
142                 DEBUG1("got SESSION KEEPALIVE\n");
143
144                 if (result < 0)
145                         break;
146                 found = 1;
147         }
148         unlock_kernel();
149         set_fs(fs);
150
151         DEBUG1("found=%d, count=%d, result=%d\n", found, count, result);
152         if (found)
153                 found_data(job->sk);
154         smb_kfree(ptr);
155 }
156
157 static void
158 smb_data_ready(struct sock *sk, int len)
159 {
160         struct data_callback* job;
161         job = smb_kmalloc(sizeof(struct data_callback),GFP_ATOMIC);
162         if(job == 0) {
163                 printk("smb_data_ready: lost SESSION KEEPALIVE due to OOM.\n");
164                 found_data(sk);
165                 return;
166         }
167         INIT_LIST_HEAD(&job->cb.list);
168         job->cb.sync = 0;
169         job->cb.routine = smb_data_callback;
170         job->cb.data = job;
171         job->sk = sk;
172         schedule_task(&job->cb);
173 }
174
175 int
176 smb_valid_socket(struct inode * inode)
177 {
178         return (inode && S_ISSOCK(inode->i_mode) && 
179                 SOCKET_I(inode)->type == SOCK_STREAM);
180 }
181
182 static struct socket *
183 server_sock(struct smb_sb_info *server)
184 {
185         struct file *file;
186
187         if (server && (file = server->sock_file))
188         {
189 #ifdef SMBFS_PARANOIA
190                 if (!smb_valid_socket(file->f_dentry->d_inode))
191                         PARANOIA("bad socket!\n");
192 #endif
193                 return SOCKET_I(file->f_dentry->d_inode);
194         }
195         return NULL;
196 }
197
198 int
199 smb_catch_keepalive(struct smb_sb_info *server)
200 {
201         struct socket *socket;
202         struct sock *sk;
203         void *data_ready;
204         int error;
205
206         error = -EINVAL;
207         socket = server_sock(server);
208         if (!socket)
209         {
210                 printk(KERN_DEBUG "smb_catch_keepalive: did not get valid server!\n");
211                 server->data_ready = NULL;
212                 goto out;
213         }
214
215         sk = socket->sk;
216         if (sk == NULL)
217         {
218                 DEBUG1("sk == NULL");
219                 server->data_ready = NULL;
220                 goto out;
221         }
222         DEBUG1("sk->d_r = %x, server->d_r = %x\n",
223                  (unsigned int) (sk->data_ready),
224                  (unsigned int) (server->data_ready));
225
226         /*
227          * Install the callback atomically to avoid races ...
228          */
229         data_ready = xchg(&sk->data_ready, smb_data_ready);
230         if (data_ready != smb_data_ready) {
231                 server->data_ready = data_ready;
232                 error = 0;
233         } else
234                 printk(KERN_ERR "smb_catch_keepalive: already done\n");
235 out:
236         return error;
237 }
238
239 int
240 smb_dont_catch_keepalive(struct smb_sb_info *server)
241 {
242         struct socket *socket;
243         struct sock *sk;
244         void * data_ready;
245         int error;
246
247         error = -EINVAL;
248         socket = server_sock(server);
249         if (!socket)
250         {
251                 printk(KERN_DEBUG "smb_dont_catch_keepalive: did not get valid server!\n");
252                 goto out;
253         }
254
255         sk = socket->sk;
256         if (sk == NULL)
257         {
258                 DEBUG1("sk == NULL");
259                 goto out;
260         }
261
262         /* Is this really an error?? */
263         if (server->data_ready == NULL)
264         {
265                 printk(KERN_DEBUG "smb_dont_catch_keepalive: "
266                        "server->data_ready == NULL\n");
267                 goto out;
268         }
269         DEBUG1("smb_dont_catch_keepalive: sk->d_r = %x, server->d_r = %x\n",
270                (unsigned int) (sk->data_ready),
271                (unsigned int) (server->data_ready));
272
273         /*
274          * Restore the original callback atomically to avoid races ...
275          */
276         data_ready = xchg(&sk->data_ready, server->data_ready);
277         server->data_ready = NULL;
278         if (data_ready != smb_data_ready)
279         {
280                 printk(KERN_ERR "smb_dont_catch_keepalive: "
281                        "sk->data_ready != smb_data_ready\n");
282         }
283         error = 0;
284 out:
285         return error;
286 }
287
288 /*
289  * Called with the server locked.
290  */
291 void
292 smb_close_socket(struct smb_sb_info *server)
293 {
294         struct file * file = server->sock_file;
295
296         if (file)
297         {
298                 VERBOSE("closing socket %p\n", server_sock(server));
299 #ifdef SMBFS_PARANOIA
300                 if (server_sock(server)->sk->data_ready == smb_data_ready)
301                         PARANOIA("still catching keepalives!\n");
302 #endif
303                 server->sock_file = NULL;
304                 fput(file);
305         }
306 }
307
308 static int
309 smb_send_raw(struct socket *socket, unsigned char *source, int length)
310 {
311         int result;
312         int already_sent = 0;
313
314         while (already_sent < length)
315         {
316                 result = _send(socket,
317                                (void *) (source + already_sent),
318                                length - already_sent);
319
320                 if (result == 0)
321                 {
322                         return -EIO;
323                 }
324                 if (result < 0)
325                 {
326                         DEBUG1("smb_send_raw: sendto error = %d\n", -result);
327                         return result;
328                 }
329                 already_sent += result;
330         }
331         return already_sent;
332 }
333
334 static int
335 smb_receive_raw(struct socket *socket, unsigned char *target, int length)
336 {
337         int result;
338         int already_read = 0;
339
340         while (already_read < length)
341         {
342                 result = _recvfrom(socket,
343                                    (void *) (target + already_read),
344                                    length - already_read, 0);
345
346                 if (result == 0)
347                 {
348                         return -EIO;
349                 }
350                 if (result < 0)
351                 {
352                         DEBUG1("recvfrom error = %d\n", -result);
353                         return result;
354                 }
355                 already_read += result;
356         }
357         return already_read;
358 }
359
360 static int
361 smb_get_length(struct socket *socket, unsigned char *header)
362 {
363         int result;
364         unsigned char peek_buf[4];
365         mm_segment_t fs;
366
367       re_recv:
368         fs = get_fs();
369         set_fs(get_ds());
370         result = smb_receive_raw(socket, peek_buf, 4);
371         set_fs(fs);
372
373         if (result < 0)
374         {
375                 PARANOIA("recv error = %d\n", -result);
376                 return result;
377         }
378         switch (peek_buf[0])
379         {
380         case 0x00:
381         case 0x82:
382                 break;
383
384         case 0x85:
385                 DEBUG1("Got SESSION KEEP ALIVE\n");
386                 goto re_recv;
387
388         default:
389                 PARANOIA("Invalid NBT packet, code=%x\n", peek_buf[0]);
390                 return -EIO;
391         }
392
393         if (header != NULL)
394         {
395                 memcpy(header, peek_buf, 4);
396         }
397         /* The length in the RFC NB header is the raw data length */
398         return smb_len(peek_buf);
399 }
400
401 /*
402  * Since we allocate memory in increments of PAGE_SIZE,
403  * round up the packet length to the next multiple.
404  */
405 int
406 smb_round_length(int len)
407 {
408         return (len + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
409 }
410  
411 /*
412  * smb_receive
413  * fs points to the correct segment
414  */
415 static int
416 smb_receive(struct smb_sb_info *server)
417 {
418         struct socket *socket = server_sock(server);
419         unsigned char * packet = server->packet;
420         int len, result;
421         unsigned char peek_buf[4];
422
423         result = smb_get_length(socket, peek_buf);
424         if (result < 0)
425                 goto out;
426         len = result;
427         /*
428          * Some servers do not respect our max_xmit and send
429          * larger packets.  Try to allocate a new packet,
430          * but don't free the old one unless we succeed.
431          */
432         if (len + 4 > server->packet_size)
433         {
434                 int new_len = smb_round_length(len + 4);
435
436                 result = -ENOMEM;
437                 packet = smb_vmalloc(new_len);
438                 if (packet == NULL)
439                         goto out;
440                 smb_vfree(server->packet);
441                 server->packet = packet;
442                 server->packet_size = new_len;
443         }
444         memcpy(packet, peek_buf, 4);
445         result = smb_receive_raw(socket, packet + 4, len);
446         if (result < 0)
447         {
448                 VERBOSE("receive error: %d\n", result);
449                 goto out;
450         }
451         server->rcls = *(packet + smb_rcls);
452         server->err  = WVAL(packet, smb_err);
453
454 #ifdef SMBFS_DEBUG_VERBOSE
455         if (server->rcls != 0)
456                 VERBOSE("rcls=%d, err=%d\n", server->rcls, server->err);
457 #endif
458 out:
459         return result;
460 }
461
462 /*
463  * This routine checks first for "fast track" processing, as most
464  * packets won't need to be copied. Otherwise, it allocates a new
465  * packet to hold the incoming data.
466  *
467  * Note that the final server packet must be the larger of the two;
468  * server packets aren't allowed to shrink.
469  */
470 static int
471 smb_receive_trans2(struct smb_sb_info *server,
472                    int *ldata, unsigned char **data,
473                    int *lparm, unsigned char **parm)
474 {
475         unsigned char *inbuf, *base, *rcv_buf = NULL;
476         unsigned int parm_disp, parm_offset, parm_count, parm_tot, parm_len = 0;
477         unsigned int data_disp, data_offset, data_count, data_tot, data_len = 0;
478         unsigned int total_p = 0, total_d = 0, buf_len = 0;
479         int result;
480
481         while (1) {
482                 result = smb_receive(server);
483                 if (result < 0)
484                         goto out;
485                 inbuf = server->packet;
486                 if (server->rcls != 0) {
487                         *parm = *data = inbuf;
488                         *ldata = *lparm = 0;
489                         goto out;
490                 }
491                 /*
492                  * Extract the control data from the packet.
493                  */
494                 data_tot    = WVAL(inbuf, smb_tdrcnt);
495                 parm_tot    = WVAL(inbuf, smb_tprcnt);
496                 parm_disp   = WVAL(inbuf, smb_prdisp);
497                 parm_offset = WVAL(inbuf, smb_proff);
498                 parm_count  = WVAL(inbuf, smb_prcnt);
499                 data_disp   = WVAL(inbuf, smb_drdisp);
500                 data_offset = WVAL(inbuf, smb_droff);
501                 data_count  = WVAL(inbuf, smb_drcnt);
502                 base = smb_base(inbuf);
503
504                 /*
505                  * Assume success and increment lengths.
506                  */
507                 parm_len += parm_count;
508                 data_len += data_count;
509
510                 if (!rcv_buf) {
511                         /*
512                          * Check for fast track processing ... just this packet.
513                          */
514                         if (parm_count == parm_tot && data_count == data_tot) {
515                                 VERBOSE("fast track, parm=%u %u %u, data=%u %u %u\n",
516                                         parm_disp, parm_offset, parm_count,
517                                         data_disp, data_offset, data_count);
518                                 *parm  = base + parm_offset;
519                                 *data  = base + data_offset;
520                                 goto success;
521                         }
522
523                         /*
524                          * Save the total parameter and data length.
525                          */
526                         total_d = data_tot;
527                         total_p = parm_tot;
528
529                         buf_len = total_d + total_p;
530                         if (server->packet_size > buf_len)
531                                 buf_len = server->packet_size;
532                         buf_len = smb_round_length(buf_len);
533                         if (buf_len > SMB_MAX_PACKET_SIZE)
534                                 goto out_too_long;
535
536                         rcv_buf = smb_vmalloc(buf_len);
537                         if (!rcv_buf)
538                                 goto out_no_mem;
539                         *parm = rcv_buf;
540                         *data = rcv_buf + total_p;
541                 } else if (data_tot > total_d || parm_tot > total_p)
542                         goto out_data_grew;
543
544                 if (parm_disp + parm_count > total_p)
545                         goto out_bad_parm;
546                 if (data_disp + data_count > total_d)
547                         goto out_bad_data;
548                 memcpy(*parm + parm_disp, base + parm_offset, parm_count);
549                 memcpy(*data + data_disp, base + data_offset, data_count);
550
551                 PARANOIA("copied, parm=%u of %u, data=%u of %u\n",
552                          parm_len, parm_tot, data_len, data_tot);
553
554                 /*
555                  * Check whether we've received all of the data. Note that
556                  * we use the packet totals -- total lengths might shrink!
557                  */
558                 if (data_len >= data_tot && parm_len >= parm_tot)
559                         break;
560         }
561
562         /*
563          * Install the new packet.  Note that it's possible, though
564          * unlikely, that the new packet could be smaller than the
565          * old one, in which case we just copy the data.
566          */
567         inbuf = server->packet;
568         if (buf_len >= server->packet_size) {
569                 server->packet_size = buf_len;
570                 server->packet = rcv_buf;
571                 rcv_buf = inbuf;
572         } else {
573                 PARANOIA("copying data, old size=%d, new size=%u\n",
574                          server->packet_size, buf_len);
575                 memcpy(inbuf, rcv_buf, parm_len + data_len);
576         }
577
578 success:
579         *ldata = data_len;
580         *lparm = parm_len;
581 out:
582         if (rcv_buf)
583                 smb_vfree(rcv_buf);
584         return result;
585
586 out_no_mem:
587         PARANOIA("couldn't allocate data area\n");
588         result = -ENOMEM;
589         goto out;
590 out_too_long:
591         printk(KERN_ERR "smb_receive_trans2: data/param too long, data=%d, parm=%d\n",
592                 data_tot, parm_tot);
593         goto out_error;
594 out_data_grew:
595         printk(KERN_ERR "smb_receive_trans2: data/params grew!\n");
596         goto out_error;
597 out_bad_parm:
598         printk(KERN_ERR "smb_receive_trans2: invalid parms, disp=%d, cnt=%d, tot=%d\n",
599                 parm_disp, parm_count, parm_tot);
600         goto out_error;
601 out_bad_data:
602         printk(KERN_ERR "smb_receive_trans2: invalid data, disp=%d, cnt=%d, tot=%d\n",
603                 data_disp, data_count, data_tot);
604 out_error:
605         result = -EIO;
606         goto out;
607 }
608
609 /*
610  * Called with the server locked
611  */
612 int
613 smb_request(struct smb_sb_info *server)
614 {
615         unsigned long flags, sigpipe;
616         mm_segment_t fs;
617         sigset_t old_set;
618         int len, result;
619         unsigned char *buffer;
620
621         result = -EBADF;
622         buffer = server->packet;
623         if (!buffer)
624                 goto bad_no_packet;
625
626         result = -EIO;
627         if (server->state != CONN_VALID)
628                 goto bad_no_conn;
629
630         if ((result = smb_dont_catch_keepalive(server)) != 0)
631                 goto bad_conn;
632
633         len = smb_len(buffer) + 4;
634         DEBUG1("len = %d cmd = 0x%X\n", len, buffer[8]);
635
636         spin_lock_irqsave(&current->sigmask_lock, flags);
637         sigpipe = sigismember(&current->pending.signal, SIGPIPE);
638         old_set = current->blocked;
639         siginitsetinv(&current->blocked, sigmask(SIGKILL)|sigmask(SIGSTOP));
640         recalc_sigpending(current);
641         spin_unlock_irqrestore(&current->sigmask_lock, flags);
642
643         fs = get_fs();
644         set_fs(get_ds());
645
646         result = smb_send_raw(server_sock(server), (void *) buffer, len);
647         if (result > 0)
648         {
649                 result = smb_receive(server);
650         }
651
652         /* read/write errors are handled by errno */
653         spin_lock_irqsave(&current->sigmask_lock, flags);
654         if (result == -EPIPE && !sigpipe)
655                 sigdelset(&current->pending.signal, SIGPIPE);
656         current->blocked = old_set;
657         recalc_sigpending(current);
658         spin_unlock_irqrestore(&current->sigmask_lock, flags);
659
660         set_fs(fs);
661
662         if (result >= 0)
663         {
664                 int result2 = smb_catch_keepalive(server);
665                 if (result2 < 0)
666                 {
667                         printk(KERN_ERR "smb_request: catch keepalive failed\n");
668                         result = result2;
669                 }
670         }
671         if (result < 0)
672                 goto bad_conn;
673         /*
674          * Check for fatal server errors ...
675          */
676         if (server->rcls) {
677                 int error = smb_errno(server);
678                 if (error == -EBADSLT) {
679                         printk(KERN_ERR "smb_request: tree ID invalid\n");
680                         result = error;
681                         goto bad_conn;
682                 }
683         }
684
685 out:
686         DEBUG1("result = %d\n", result);
687         return result;
688         
689 bad_conn:
690         PARANOIA("result %d, setting invalid\n", result);
691         server->state = CONN_INVALID;
692         smb_invalidate_inodes(server);
693         goto out;               
694 bad_no_packet:
695         printk(KERN_ERR "smb_request: no packet!\n");
696         goto out;
697 bad_no_conn:
698         printk(KERN_ERR "smb_request: connection %d not valid!\n",
699                server->state);
700         goto out;
701 }
702
703 #define ROUND_UP(x) (((x)+3) & ~3)
704 static int
705 smb_send_trans2(struct smb_sb_info *server, __u16 trans2_command,
706                 int ldata, unsigned char *data,
707                 int lparam, unsigned char *param)
708 {
709         struct socket *sock = server_sock(server);
710         struct scm_cookie scm;
711         int err;
712         int mparam, mdata;
713
714         /* I know the following is very ugly, but I want to build the
715            smb packet as efficiently as possible. */
716
717         const int smb_parameters = 15;
718         const int oparam =
719                 ROUND_UP(SMB_HEADER_LEN + 2 * smb_parameters + 2 + 3);
720         const int odata =
721                 ROUND_UP(oparam + lparam);
722         const int bcc =
723                 odata + ldata - (SMB_HEADER_LEN + 2 * smb_parameters + 2);
724         const int packet_length =
725                 SMB_HEADER_LEN + 2 * smb_parameters + bcc + 2;
726
727         unsigned char padding[4] =
728         {0,};
729         char *p;
730
731         struct iovec iov[4];
732         struct msghdr msg;
733
734         /* FIXME! this test needs to include SMB overhead too, I think ... */
735         if ((bcc + oparam) > server->opt.max_xmit)
736                 return -ENOMEM;
737         p = smb_setup_header(server, SMBtrans2, smb_parameters, bcc);
738
739         /*
740          * max parameters + max data + max setup == max_xmit to make NT4 happy
741          * and not abort the transfer or split into multiple responses.
742          *
743          * -100 is to make room for headers, which OS/2 seems to include in the
744          * size calculation while NT4 does not?
745          */
746         mparam = SMB_TRANS2_MAX_PARAM;
747         mdata = server->opt.max_xmit - mparam - 100;
748         if (mdata < 1024) {
749                 mdata = 1024;
750                 mparam = 20;
751         }
752
753         WSET(server->packet, smb_tpscnt, lparam);
754         WSET(server->packet, smb_tdscnt, ldata);
755         WSET(server->packet, smb_mprcnt, mparam);
756         WSET(server->packet, smb_mdrcnt, mdata);
757         WSET(server->packet, smb_msrcnt, 0);    /* max setup always 0 ? */
758         WSET(server->packet, smb_flags, 0);
759         DSET(server->packet, smb_timeout, 0);
760         WSET(server->packet, smb_pscnt, lparam);
761         WSET(server->packet, smb_psoff, oparam - 4);
762         WSET(server->packet, smb_dscnt, ldata);
763         WSET(server->packet, smb_dsoff, odata - 4);
764         WSET(server->packet, smb_suwcnt, 1);
765         WSET(server->packet, smb_setup0, trans2_command);
766         *p++ = 0;               /* null smb_name for trans2 */
767         *p++ = 'D';             /* this was added because OS/2 does it */
768         *p++ = ' ';
769
770
771         msg.msg_name = NULL;
772         msg.msg_namelen = 0;
773         msg.msg_control = NULL;
774         msg.msg_controllen = 0;
775         msg.msg_iov = iov;
776         msg.msg_iovlen = 4;
777         msg.msg_flags = 0;
778         
779         iov[0].iov_base = (void *) server->packet;
780         iov[0].iov_len = oparam;
781         iov[1].iov_base = (param == NULL) ? padding : param;
782         iov[1].iov_len = lparam;
783         iov[2].iov_base = padding;
784         iov[2].iov_len = odata - oparam - lparam;
785         iov[3].iov_base = (data == NULL) ? padding : data;
786         iov[3].iov_len = ldata;
787
788         err = scm_send(sock, &msg, &scm);
789         if (err >= 0) {
790                 err = sock->ops->sendmsg(sock, &msg, packet_length, &scm);
791                 scm_destroy(&scm);
792         }
793         return err;
794 }
795
796 /*
797  * This is not really a trans2 request, we assume that you only have
798  * one packet to send.
799  */
800 int
801 smb_trans2_request(struct smb_sb_info *server, __u16 trans2_command,
802                    int ldata, unsigned char *data,
803                    int lparam, unsigned char *param,
804                    int *lrdata, unsigned char **rdata,
805                    int *lrparam, unsigned char **rparam)
806 {
807         sigset_t old_set;
808         unsigned long flags, sigpipe;
809         mm_segment_t fs;
810         int result;
811
812         DEBUG1("com=%d, ld=%d, lp=%d\n", trans2_command, ldata, lparam);
813
814         /*
815          * These are initialized in smb_request_ok, but not here??
816          */
817         server->rcls = 0;
818         server->err = 0;
819
820         result = -EIO;
821         if (server->state != CONN_VALID)
822                 goto out;
823
824         if ((result = smb_dont_catch_keepalive(server)) != 0)
825                 goto bad_conn;
826
827         spin_lock_irqsave(&current->sigmask_lock, flags);
828         sigpipe = sigismember(&current->pending.signal, SIGPIPE);
829         old_set = current->blocked;
830         siginitsetinv(&current->blocked, sigmask(SIGKILL)|sigmask(SIGSTOP));
831         recalc_sigpending(current);
832         spin_unlock_irqrestore(&current->sigmask_lock, flags);
833
834         fs = get_fs();
835         set_fs(get_ds());
836
837         result = smb_send_trans2(server, trans2_command,
838                                  ldata, data, lparam, param);
839         if (result >= 0)
840         {
841                 result = smb_receive_trans2(server,
842                                             lrdata, rdata, lrparam, rparam);
843         }
844
845         /* read/write errors are handled by errno */
846         spin_lock_irqsave(&current->sigmask_lock, flags);
847         if (result == -EPIPE && !sigpipe)
848                 sigdelset(&current->pending.signal, SIGPIPE);
849         current->blocked = old_set;
850         recalc_sigpending(current);
851         spin_unlock_irqrestore(&current->sigmask_lock, flags);
852
853         set_fs(fs);
854
855         if (result >= 0)
856         {
857                 int result2 = smb_catch_keepalive(server);
858                 if (result2 < 0)
859                 {
860                         result = result2;
861                 }
862         }
863         if (result < 0)
864                 goto bad_conn;
865         /*
866          * Check for fatal server errors ...
867          */
868         if (server->rcls) {
869                 int error = smb_errno(server);
870                 if (error == -EBADSLT) {
871                         printk(KERN_ERR "smb_request: tree ID invalid\n");
872                         result = error;
873                         goto bad_conn;
874                 }
875         }
876
877 out:
878         return result;
879
880 bad_conn:
881         PARANOIA("result=%d, setting invalid\n", result);
882         server->state = CONN_INVALID;
883         smb_invalidate_inodes(server);
884         goto out;
885 }