/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpdr.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdpdr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 580 by astrand, Fri Jan 23 08:35:52 2004 UTC revision 657 by astrand, Fri Apr 16 11:28:34 2004 UTC
# Line 1  Line 1 
1    /* -*- c-basic-offset: 8 -*-
2       rdesktop: A Remote Desktop Protocol client.
3       Copyright (C) Matthew Chapman 1999-2004
4    
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9    
10       This program is distributed in the hope that it will be useful,
11       but WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13       GNU General Public License for more details.
14    
15       You should have received a copy of the GNU General Public License
16       along with this program; if not, write to the Free Software
17       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18    */
19    
20    /*
21      Here are some resources, for your IRP hacking pleasure:
22    
23      http://cvs.sourceforge.net/viewcvs.py/mingw/w32api/include/ddk/winddk.h?view=markup
24    
25      http://win32.mvps.org/ntfs/streams.cpp
26    
27      http://www.acc.umu.se/~bosse/ntifs.h
28    
29      http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/File/
30    
31      http://us1.samba.org/samba/ftp/specs/smb-nt01.txt
32    
33      http://www.osronline.com/
34    */
35    
36  #include <unistd.h>  #include <unistd.h>
37  #include <sys/types.h>  #include <sys/types.h>
38    #include <sys/time.h>
39    #include <dirent.h>             /* opendir, closedir, readdir */
40  #include <time.h>  #include <time.h>
41  #include "rdesktop.h"  #include "rdesktop.h"
42    
 #define IRP_MJ_CREATE           0x00  
 #define IRP_MJ_CLOSE            0x02  
 #define IRP_MJ_READ             0x03  
 #define IRP_MJ_WRITE            0x04  
 #define IRP_MJ_DEVICE_CONTROL   0x0e  
   
43  #define IRP_MJ_CREATE                   0x00  #define IRP_MJ_CREATE                   0x00
44  #define IRP_MJ_CLOSE                    0x02  #define IRP_MJ_CLOSE                    0x02
45  #define IRP_MJ_READ                     0x03  #define IRP_MJ_READ                     0x03
# Line 18  Line 49 
49  #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a  #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
50  #define IRP_MJ_DIRECTORY_CONTROL        0x0c  #define IRP_MJ_DIRECTORY_CONTROL        0x0c
51  #define IRP_MJ_DEVICE_CONTROL           0x0e  #define IRP_MJ_DEVICE_CONTROL           0x0e
52    #define IRP_MJ_LOCK_CONTROL             0x11
53    
54  #define IRP_MN_QUERY_DIRECTORY          0x01  #define IRP_MN_QUERY_DIRECTORY          0x01
55  #define IRP_MN_NOTIFY_CHANGE_DIRECTORY  0x02  #define IRP_MN_NOTIFY_CHANGE_DIRECTORY  0x02
56    
 #define MAX_ASYNC_IO_REQUESTS   10  
   
57  extern char hostname[16];  extern char hostname[16];
58  extern DEVICE_FNS serial_fns;  extern DEVICE_FNS serial_fns;
59  extern DEVICE_FNS printer_fns;  extern DEVICE_FNS printer_fns;
60  extern DEVICE_FNS parallel_fns;  extern DEVICE_FNS parallel_fns;
61  extern DEVICE_FNS disk_fns;  extern DEVICE_FNS disk_fns;
62    extern FILEINFO g_fileinfo[];
63    
64  static VCHANNEL *rdpdr_channel;  static VCHANNEL *rdpdr_channel;
65    
# Line 39  uint32 g_num_devices; Line 69  uint32 g_num_devices;
69    
70  /* Table with information about rdpdr devices */  /* Table with information about rdpdr devices */
71  RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES];  RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES];
72    char *g_rdpdr_clientname = NULL;
73    
74  /* Used to store incoming io request, until they are ready to be completed */  /* Used to store incoming io request, until they are ready to be completed */
75    /* using a linked list ensures that they are processed in the right order, */
76    /* if multiple ios are being done on the same fd */
77  struct async_iorequest  struct async_iorequest
78  {  {
79          uint32 fd, major, minor, offset, device, id, length;          uint32 fd, major, minor, offset, device, id, length, partial_len;
80          long timeout,           /* Total timeout */          long timeout,           /* Total timeout */
81            itv_timeout;          /* Interval timeout (between serial characters) */            itv_timeout;          /* Interval timeout (between serial characters) */
82          uint8 *buffer;          uint8 *buffer;
83          DEVICE_FNS *fns;          DEVICE_FNS *fns;
84  } g_iorequest[MAX_ASYNC_IO_REQUESTS];  
85            struct async_iorequest *next;   /* next element in list */
86    };
87    
88    struct async_iorequest *g_iorequest;
89    
90  /* Return device_id for a given handle */  /* Return device_id for a given handle */
91  int  int
# Line 75  convert_to_unix_filename(char *filename) Line 112  convert_to_unix_filename(char *filename)
112          }          }
113  }  }
114    
115    BOOL
116    rdpdr_handle_ok(int device, int handle)
117    {
118            switch (g_rdpdr_device[device].device_type)
119            {
120                    case DEVICE_TYPE_PARALLEL:
121                    case DEVICE_TYPE_SERIAL:
122                    case DEVICE_TYPE_PRINTER:
123                    case DEVICE_TYPE_SCARD:
124                            if (g_rdpdr_device[device].handle != handle)
125                                    return False;
126                            break;
127                    case DEVICE_TYPE_DISK:
128                            if (g_fileinfo[handle].device_id != device)
129                                    return False;
130                            break;
131            }
132            return True;
133    }
134    
135  /* Add a new io request to the table containing pending io requests so it won't block rdesktop */  /* Add a new io request to the table containing pending io requests so it won't block rdesktop */
136  BOOL  BOOL
137  add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,  add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,
138                      DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer)                      DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer,
139                        uint32 offset)
140  {  {
         int i;  
141          struct async_iorequest *iorq;          struct async_iorequest *iorq;
142    
143          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          if (g_iorequest == NULL)
144          {          {
145                  iorq = &g_iorequest[i];                  g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
146                    if (!g_iorequest)
147                  if (iorq->fd == 0)                          return False;
148                  {                  g_iorequest->fd = 0;
149                          iorq->device = device;                  g_iorequest->next = NULL;
150                          iorq->fd = file;          }
151                          iorq->id = id;  
152                          iorq->major = major;          iorq = g_iorequest;
153                          iorq->length = length;  
154                          iorq->fns = fns;          while (iorq->fd != 0)
155                          iorq->timeout = total_timeout;          {
156                          iorq->itv_timeout = interval_timeout;                  // create new element if needed
157                          iorq->buffer = buffer;                  if (iorq->next == NULL)
158                          return True;                  {
159                  }                          iorq->next =
160          }                                  (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest));
161          error("IO request table full. Increase MAX_ASYNC_IO_REQUESTS in rdpdr.c!\n");                          if (!iorq->next)
162          return False;                                  return False;
163                            iorq->next->fd = 0;
164                            iorq->next->next = NULL;
165                    }
166                    iorq = iorq->next;
167            }
168            iorq->device = device;
169            iorq->fd = file;
170            iorq->id = id;
171            iorq->major = major;
172            iorq->length = length;
173            iorq->partial_len = 0;
174            iorq->fns = fns;
175            iorq->timeout = total_timeout;
176            iorq->itv_timeout = interval_timeout;
177            iorq->buffer = buffer;
178            iorq->offset = offset;
179            return True;
180  }  }
181    
   
182  void  void
183  rdpdr_send_connect(void)  rdpdr_send_connect(void)
184  {  {
# Line 126  void Line 199  void
199  rdpdr_send_name(void)  rdpdr_send_name(void)
200  {  {
201          uint8 magic[4] = "rDNC";          uint8 magic[4] = "rDNC";
         uint32 hostlen = (strlen(hostname) + 1) * 2;  
202          STREAM s;          STREAM s;
203            uint32 hostlen;
204    
205            if (NULL == g_rdpdr_clientname)
206            {
207                    g_rdpdr_clientname = hostname;
208            }
209            hostlen = (strlen(g_rdpdr_clientname) + 1) * 2;
210    
211          s = channel_init(rdpdr_channel, 16 + hostlen);          s = channel_init(rdpdr_channel, 16 + hostlen);
212          out_uint8a(s, magic, 4);          out_uint8a(s, magic, 4);
# Line 135  rdpdr_send_name(void) Line 214  rdpdr_send_name(void)
214          out_uint16_le(s, 0x72);          out_uint16_le(s, 0x72);
215          out_uint32(s, 0);          out_uint32(s, 0);
216          out_uint32_le(s, hostlen);          out_uint32_le(s, hostlen);
217          rdp_out_unistr(s, hostname, hostlen - 2);          rdp_out_unistr(s, g_rdpdr_clientname, hostlen - 2);
218          s_mark_end(s);          s_mark_end(s);
219          channel_send(s, rdpdr_channel);          channel_send(s, rdpdr_channel);
220  }  }
# Line 188  rdpdr_send_available(void) Line 267  rdpdr_send_available(void)
267                  out_uint32_le(s, i);    /* RDP Device ID */                  out_uint32_le(s, i);    /* RDP Device ID */
268                  out_uint8p(s, g_rdpdr_device[i].name, 8);                  out_uint8p(s, g_rdpdr_device[i].name, 8);
269    
270                  if (g_rdpdr_device[i].device_type == DEVICE_TYPE_PRINTER)                  switch (g_rdpdr_device[i].device_type)
271                  {                  {
272                          printerinfo = (PRINTER *) g_rdpdr_device[i].pdevice_data;                          case DEVICE_TYPE_PRINTER:
273                                    printerinfo = (PRINTER *) g_rdpdr_device[i].pdevice_data;
274    
275                          driverlen = 2 * strlen(printerinfo->driver) + 2;                                  driverlen = 2 * strlen(printerinfo->driver) + 2;
276                          printerlen = 2 * strlen(printerinfo->printer) + 2;                                  printerlen = 2 * strlen(printerinfo->printer) + 2;
277                          bloblen = printerinfo->bloblen;                                  bloblen = printerinfo->bloblen;
278    
279                          out_uint32_le(s, 24 + driverlen + printerlen + bloblen);        /* length of extra info */                                  out_uint32_le(s, 24 + driverlen + printerlen + bloblen);        /* length of extra info */
280                          out_uint32_le(s, printerinfo->default_printer ? 2 : 0);                                  out_uint32_le(s, printerinfo->default_printer ? 2 : 0);
281                          out_uint8s(s, 8);       /* unknown */                                  out_uint8s(s, 8);       /* unknown */
282                          out_uint32_le(s, driverlen);                                  out_uint32_le(s, driverlen);
283                          out_uint32_le(s, printerlen);                                  out_uint32_le(s, printerlen);
284                          out_uint32_le(s, bloblen);                                  out_uint32_le(s, bloblen);
285                          rdp_out_unistr(s, printerinfo->driver, driverlen - 2);                                  rdp_out_unistr(s, printerinfo->driver, driverlen - 2);
286                          rdp_out_unistr(s, printerinfo->printer, printerlen - 2);                                  rdp_out_unistr(s, printerinfo->printer, printerlen - 2);
287                          out_uint8a(s, printerinfo->blob, bloblen);                                  out_uint8a(s, printerinfo->blob, bloblen);
288    
289                          xfree(printerinfo->blob);       /* Blob is sent twice if reconnecting */                                  if (printerinfo->blob)
290                  }                                          xfree(printerinfo->blob);       /* Blob is sent twice if reconnecting */
291                  else                                  break;
292                  {                          default:
293                          out_uint32(s, 0);                                  out_uint32(s, 0);
294                  }                  }
295          }          }
296  #if 0  #if 0
# Line 282  rdpdr_process_irp(STREAM s) Line 362  rdpdr_process_irp(STREAM s)
362          buffer = (uint8 *) xmalloc(1024);          buffer = (uint8 *) xmalloc(1024);
363          buffer[0] = 0;          buffer[0] = 0;
364    
   
365          switch (g_rdpdr_device[device].device_type)          switch (g_rdpdr_device[device].device_type)
366          {          {
367                  case DEVICE_TYPE_SERIAL:                  case DEVICE_TYPE_SERIAL:
# Line 305  rdpdr_process_irp(STREAM s) Line 384  rdpdr_process_irp(STREAM s)
384                  case DEVICE_TYPE_DISK:                  case DEVICE_TYPE_DISK:
385    
386                          fns = &disk_fns;                          fns = &disk_fns;
387                            rw_blocking = False;
388                          break;                          break;
389    
390                  case DEVICE_TYPE_SCARD:                  case DEVICE_TYPE_SCARD:
# Line 370  rdpdr_process_irp(STREAM s) Line 450  rdpdr_process_irp(STREAM s)
450  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
451                          DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset));                          DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset));
452  #endif  #endif
453                            if (!rdpdr_handle_ok(device, file))
454                            {
455                                    status = STATUS_INVALID_HANDLE;
456                                    break;
457                            }
458    
459                          if (rw_blocking)        // Complete read immediately                          if (rw_blocking)        // Complete read immediately
460                          {                          {
461                                  buffer = (uint8 *) xrealloc((void *) buffer, length);                                  buffer = (uint8 *) xrealloc((void *) buffer, length);
462                                    if (!buffer)
463                                    {
464                                            status = STATUS_CANCELLED;
465                                            break;
466                                    }
467                                  status = fns->read(file, buffer, length, offset, &result);                                  status = fns->read(file, buffer, length, offset, &result);
468                                  buffer_len = result;                                  buffer_len = result;
469                                  break;                                  break;
# Line 380  rdpdr_process_irp(STREAM s) Line 471  rdpdr_process_irp(STREAM s)
471    
472                          // Add request to table                          // Add request to table
473                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
474                            if (!pst_buf)
475                            {
476                                    status = STATUS_CANCELLED;
477                                    break;
478                            }
479                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);
480                          if (add_async_iorequest                          if (add_async_iorequest
481                              (device, file, id, major, length, fns, total_timeout, interval_timeout,                              (device, file, id, major, length, fns, total_timeout, interval_timeout,
482                               pst_buf))                               pst_buf, offset))
483                          {                          {
484                                  status = STATUS_PENDING;                                  status = STATUS_PENDING;
485                                  break;                                  break;
# Line 391  rdpdr_process_irp(STREAM s) Line 487  rdpdr_process_irp(STREAM s)
487    
488                          status = STATUS_CANCELLED;                          status = STATUS_CANCELLED;
489                          break;                          break;
   
490                  case IRP_MJ_WRITE:                  case IRP_MJ_WRITE:
491    
492                          buffer_len = 1;                          buffer_len = 1;
# Line 408  rdpdr_process_irp(STREAM s) Line 503  rdpdr_process_irp(STREAM s)
503  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
504                          DEBUG(("RDPDR IRP Write (length: %d)\n", result));                          DEBUG(("RDPDR IRP Write (length: %d)\n", result));
505  #endif  #endif
506                            if (!rdpdr_handle_ok(device, file))
507                            {
508                                    status = STATUS_INVALID_HANDLE;
509                                    break;
510                            }
511    
512                          if (rw_blocking)        // Complete immediately                          if (rw_blocking)        // Complete immediately
513                          {                          {
514                                  status = fns->write(file, s->p, length, offset, &result);                                  status = fns->write(file, s->p, length, offset, &result);
# Line 416  rdpdr_process_irp(STREAM s) Line 517  rdpdr_process_irp(STREAM s)
517    
518                          // Add to table                          // Add to table
519                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
520                            if (!pst_buf)
521                            {
522                                    status = STATUS_CANCELLED;
523                                    break;
524                            }
525    
526                          in_uint8a(s, pst_buf, length);                          in_uint8a(s, pst_buf, length);
527    
528                          if (add_async_iorequest                          if (add_async_iorequest
529                              (device, file, id, major, length, fns, 0, 0, pst_buf))                              (device, file, id, major, length, fns, 0, 0, pst_buf, offset))
530                          {                          {
531                                  status = STATUS_PENDING;                                  status = STATUS_PENDING;
532                                  break;                                  break;
# Line 539  rdpdr_process_irp(STREAM s) Line 646  rdpdr_process_irp(STREAM s)
646                          in_uint8s(s, 0x14);                          in_uint8s(s, 0x14);
647    
648                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);
649                            if (!buffer)
650                            {
651                                    status = STATUS_CANCELLED;
652                                    break;
653                            }
654    
655                          out.data = out.p = buffer;                          out.data = out.p = buffer;
656                          out.size = sizeof(buffer);                          out.size = sizeof(buffer);
657                          status = fns->device_control(file, request, s, &out);                          status = fns->device_control(file, request, s, &out);
# Line 554  rdpdr_process_irp(STREAM s) Line 667  rdpdr_process_irp(STREAM s)
667          {          {
668                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);
669          }          }
670          xfree(buffer);          if (buffer)
671                    xfree(buffer);
672            buffer = NULL;
673  }  }
674    
675  void  void
# Line 674  rdpdr_init() Line 788  rdpdr_init()
788  void  void
789  rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * timeout)  rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * timeout)
790  {  {
791          int i;          uint32 select_timeout = 0;      // Timeout value to be used for select() (in millisecons).
         long select_timeout = 0;        // Timeout value to be used for select() (in millisecons).  
792          struct async_iorequest *iorq;          struct async_iorequest *iorq;
793    
794          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          iorq = g_iorequest;
795            while (iorq != NULL)
796          {          {
797                  iorq = &g_iorequest[i];                  if (iorq->fd != 0)
   
                 if (iorq->fd != 0)      // Found a pending io request  
798                  {                  {
799                          switch (iorq->major)                          switch (iorq->major)
800                          {                          {
# Line 705  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 817  rdpdr_add_fds(int *n, fd_set * rfds, fd_
817                                          break;                                          break;
818    
819                                  case IRP_MJ_WRITE:                                  case IRP_MJ_WRITE:
   
820                                          FD_SET(iorq->fd, wfds);                                          FD_SET(iorq->fd, wfds);
821                                          break;                                          break;
822    
823                          }                          }
824                          *n = MAX(*n, iorq->fd);                          *n = MAX(*n, iorq->fd);
825                  }                  }
826    
827                    iorq = iorq->next;
828          }          }
829  }  }
830    
831    struct async_iorequest *
832    rdpdr_remove_iorequest(struct async_iorequest *prev, struct async_iorequest *iorq)
833    {
834            if (!iorq)
835                    return NULL;
836    
837            if (iorq->buffer)
838                    xfree(iorq->buffer);
839            if (prev)
840            {
841                    prev->next = iorq->next;
842                    xfree(iorq);
843                    iorq = prev->next;
844            }
845            else
846            {
847                    // Even if NULL
848                    g_iorequest = iorq->next;
849                    xfree(iorq);
850                    iorq = NULL;
851            }
852            return iorq;
853    }
854    
855  /* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */  /* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */
856  void  void
857  rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)  rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)
858  {  {
         int i;  
859          NTSTATUS status;          NTSTATUS status;
860          uint32 result = 0, buffer_len = 0;          uint32 result = 0;
861          DEVICE_FNS *fns;          DEVICE_FNS *fns;
862          struct async_iorequest *iorq;          struct async_iorequest *iorq;
863            struct async_iorequest *prev;
864            uint32 req_size = 0;
865    
866          if (timed_out)          if (timed_out)
867          {          {
# Line 731  rdpdr_check_fds(fd_set * rfds, fd_set * Line 869  rdpdr_check_fds(fd_set * rfds, fd_set *
869                  return;                  return;
870          }          }
871    
872          // Walk through array of pending io_rq's          iorq = g_iorequest;
873          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          prev = NULL;
874            while (iorq != NULL)
875          {          {
                 iorq = &g_iorequest[i];  
   
876                  if (iorq->fd != 0)                  if (iorq->fd != 0)
877                  {                  {
878                          switch (iorq->major)                          switch (iorq->major)
879                          {                          {
   
880                                  case IRP_MJ_READ:                                  case IRP_MJ_READ:
   
881                                          if (FD_ISSET(iorq->fd, rfds))                                          if (FD_ISSET(iorq->fd, rfds))
882                                          {                                          {
883                                                  // Read, and send data.                                                  /* Read the data */
884                                                  fns = iorq->fns;                                                  fns = iorq->fns;
885                                                  status = fns->read(iorq->fd, iorq->buffer,  
886                                                                     iorq->length, 0, &result);                                                  req_size =
887                                                  buffer_len = result;                                                          (iorq->length - iorq->partial_len) >
888                                                            8192 ? 8192 : (iorq->length -
889                                                  rdpdr_send_completion(iorq->device, iorq->id,                                                                         iorq->partial_len);
890                                                                        status, result, iorq->buffer,                                                  /* never read larger chunks than 8k - chances are that it will block */
891                                                                        buffer_len);                                                  status = fns->read(iorq->fd,
892                                                                       iorq->buffer + iorq->partial_len,
893                                                                       req_size, iorq->offset, &result);
894    
895                                                    if (result > 0)
896                                                    {
897                                                            iorq->partial_len += result;
898                                                            iorq->offset += result;
899                                                    }
900  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
901                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));
902  #endif  #endif
903                                                  xfree(iorq->buffer);                                                  /* only delete link if all data has been transfered */
904                                                  iorq->fd = 0;                                                  /* or if result was 0 and status success - EOF      */
905                                                    if ((iorq->partial_len == iorq->length) ||
906                                                        (result == 0))
907                                                    {
908    #if WITH_DEBUG_RDP5
909                                                            DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));
910    #endif
911                                                            rdpdr_send_completion(iorq->device,
912                                                                                  iorq->id, status,
913                                                                                  iorq->partial_len,
914                                                                                  iorq->buffer,
915                                                                                  iorq->partial_len);
916                                                            iorq = rdpdr_remove_iorequest(prev, iorq);
917                                                    }
918                                          }                                          }
919                                          break;                                          break;
   
920                                  case IRP_MJ_WRITE:                                  case IRP_MJ_WRITE:
   
921                                          if (FD_ISSET(iorq->fd, wfds))                                          if (FD_ISSET(iorq->fd, wfds))
922                                          {                                          {
923                                                  // Write data and send completion.                                                  /* Write data. */
924                                                  fns = iorq->fns;                                                  fns = iorq->fns;
                                                 status = fns->write(iorq->fd, iorq->buffer,  
                                                                     iorq->length, 0, &result);  
                                                 rdpdr_send_completion(iorq->device, iorq->id,  
                                                                       status, result, "", 1);  
925    
926                                                  xfree(iorq->buffer);                                                  req_size =
927                                                  iorq->fd = 0;                                                          (iorq->length - iorq->partial_len) >
928                                                            8192 ? 8192 : (iorq->length -
929                                                                           iorq->partial_len);
930    
931                                                    /* never write larger chunks than 8k - chances are that it will block */
932                                                    status = fns->write(iorq->fd,
933                                                                        iorq->buffer +
934                                                                        iorq->partial_len, req_size,
935                                                                        iorq->offset, &result);
936    
937                                                    if (result > 0)
938                                                    {
939                                                            iorq->partial_len += result;
940                                                            iorq->offset += result;
941                                                    }
942    
943    #if WITH_DEBUG_RDP5
944                                                    DEBUG(("RDPDR: %d bytes of data written\n",
945                                                           result));
946    #endif
947                                                    /* only delete link if all data has been transfered */
948                                                    /* or we couldn't write */
949                                                    if ((iorq->partial_len == iorq->length)
950                                                        || (result == 0))
951                                                    {
952    #if WITH_DEBUG_RDP5
953                                                            DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length));
954    #endif
955                                                            rdpdr_send_completion(iorq->device,
956                                                                                  iorq->id, status,
957                                                                                  iorq->partial_len,
958                                                                                  (uint8 *) "", 1);
959    
960                                                            iorq = rdpdr_remove_iorequest(prev, iorq);
961                                                    }
962                                          }                                          }
963                                          break;                                          break;
964                          }                          }
965    
966                  }                  }
967                    prev = iorq;
968                    if (iorq)
969                            iorq = iorq->next;
970          }          }
971    
972  }  }
973    
974  /* Abort a pending io request for a given handle and major */  /* Abort a pending io request for a given handle and major */
# Line 787  BOOL Line 976  BOOL
976  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)
977  {  {
978          uint32 result;          uint32 result;
         int i;  
979          struct async_iorequest *iorq;          struct async_iorequest *iorq;
980            struct async_iorequest *prev;
981    
982          for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++)          iorq = g_iorequest;
983            prev = NULL;
984            while (iorq != NULL)
985          {          {
                 iorq = &g_iorequest[i];  
   
986                  // Only remove from table when major is not set, or when correct major is supplied.                  // Only remove from table when major is not set, or when correct major is supplied.
987                  // Abort read should not abort a write io request.                  // Abort read should not abort a write io request.
988                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))                  if ((iorq->fd == fd) && (major == 0 || iorq->major == major))
989                  {                  {
990                          result = 0;                          result = 0;
991                          rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1);                          rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "",
992                          xfree(iorq->buffer);                                                1);
993                          iorq->fd = 0;  
994                            iorq = rdpdr_remove_iorequest(prev, iorq);
995                          return True;                          return True;
996                  }                  }
997    
998                    prev = iorq;
999                    iorq = iorq->next;
1000          }          }
1001    
1002          return False;          return False;
1003  }  }

Legend:
Removed from v.580  
changed lines
  Added in v.657

  ViewVC Help
Powered by ViewVC 1.1.26