1 |
#include <unistd.h> |
#include <unistd.h> |
2 |
#include <sys/types.h> |
#include <sys/types.h> |
3 |
|
#include <sys/time.h> |
4 |
|
#include <dirent.h> /* opendir, closedir, readdir */ |
5 |
#include <time.h> |
#include <time.h> |
6 |
#include "rdesktop.h" |
#include "rdesktop.h" |
7 |
|
|
|
#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 |
|
|
|
|
8 |
#define IRP_MJ_CREATE 0x00 |
#define IRP_MJ_CREATE 0x00 |
9 |
#define IRP_MJ_CLOSE 0x02 |
#define IRP_MJ_CLOSE 0x02 |
10 |
#define IRP_MJ_READ 0x03 |
#define IRP_MJ_READ 0x03 |
14 |
#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a |
#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a |
15 |
#define IRP_MJ_DIRECTORY_CONTROL 0x0c |
#define IRP_MJ_DIRECTORY_CONTROL 0x0c |
16 |
#define IRP_MJ_DEVICE_CONTROL 0x0e |
#define IRP_MJ_DEVICE_CONTROL 0x0e |
17 |
|
#define IRP_MJ_LOCK_CONTROL 0x11 |
18 |
|
|
19 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
20 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
21 |
|
|
|
#define MAX_ASYNC_IO_REQUESTS 10 |
|
|
|
|
22 |
extern char hostname[16]; |
extern char hostname[16]; |
23 |
extern DEVICE_FNS serial_fns; |
extern DEVICE_FNS serial_fns; |
24 |
extern DEVICE_FNS printer_fns; |
extern DEVICE_FNS printer_fns; |
25 |
extern DEVICE_FNS parallel_fns; |
extern DEVICE_FNS parallel_fns; |
26 |
extern DEVICE_FNS disk_fns; |
extern DEVICE_FNS disk_fns; |
27 |
|
extern FILEINFO g_fileinfo[]; |
28 |
|
|
29 |
static VCHANNEL *rdpdr_channel; |
static VCHANNEL *rdpdr_channel; |
30 |
|
|
34 |
|
|
35 |
/* Table with information about rdpdr devices */ |
/* Table with information about rdpdr devices */ |
36 |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
37 |
|
char * g_rdpdr_clientname = NULL; |
38 |
|
|
39 |
/* 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 */ |
40 |
|
/* using a linked list ensures that they are processed in the right order, */ |
41 |
|
/* if multiple ios are being done on the same fd */ |
42 |
struct async_iorequest |
struct async_iorequest |
43 |
{ |
{ |
44 |
uint32 fd, major, minor, offset, device, id, length; |
uint32 fd, major, minor, offset, device, id, length, partial_len; |
45 |
long timeout, /* Total timeout */ |
long timeout, /* Total timeout */ |
46 |
itv_timeout; /* Interval timeout (between serial characters) */ |
itv_timeout; /* Interval timeout (between serial characters) */ |
47 |
uint8 *buffer; |
uint8 *buffer; |
48 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
49 |
} g_iorequest[MAX_ASYNC_IO_REQUESTS]; |
|
50 |
|
struct async_iorequest *next; /* next element in list */ |
51 |
|
}; |
52 |
|
|
53 |
|
struct async_iorequest *g_iorequest; |
54 |
|
|
55 |
/* Return device_id for a given handle */ |
/* Return device_id for a given handle */ |
56 |
int |
int |
77 |
} |
} |
78 |
} |
} |
79 |
|
|
80 |
|
BOOL |
81 |
|
rdpdr_handle_ok(int device, int handle) |
82 |
|
{ |
83 |
|
switch (g_rdpdr_device[device].device_type) |
84 |
|
{ |
85 |
|
case DEVICE_TYPE_PARALLEL: |
86 |
|
case DEVICE_TYPE_SERIAL: |
87 |
|
case DEVICE_TYPE_PRINTER: |
88 |
|
case DEVICE_TYPE_SCARD: |
89 |
|
if (g_rdpdr_device[device].handle != handle) |
90 |
|
return False; |
91 |
|
break; |
92 |
|
case DEVICE_TYPE_DISK: |
93 |
|
if (g_fileinfo[handle].device_id != device) |
94 |
|
return False; |
95 |
|
break; |
96 |
|
} |
97 |
|
return True; |
98 |
|
} |
99 |
|
|
100 |
/* 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 */ |
101 |
BOOL |
BOOL |
102 |
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, |
103 |
DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer) |
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer, |
104 |
|
uint32 offset) |
105 |
{ |
{ |
|
int i; |
|
106 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
107 |
|
|
108 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
if (g_iorequest == NULL) |
109 |
{ |
{ |
110 |
iorq = &g_iorequest[i]; |
g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
111 |
|
if (!g_iorequest) |
112 |
if (iorq->fd == 0) |
return False; |
113 |
{ |
g_iorequest->fd = 0; |
114 |
iorq->device = device; |
g_iorequest->next = NULL; |
115 |
iorq->fd = file; |
} |
116 |
iorq->id = id; |
|
117 |
iorq->major = major; |
iorq = g_iorequest; |
118 |
iorq->length = length; |
|
119 |
iorq->fns = fns; |
while (iorq->fd != 0) |
120 |
iorq->timeout = total_timeout; |
{ |
121 |
iorq->itv_timeout = interval_timeout; |
// create new element if needed |
122 |
iorq->buffer = buffer; |
if (iorq->next == NULL) |
123 |
return True; |
{ |
124 |
} |
iorq->next = |
125 |
} |
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
126 |
error("IO request table full. Increase MAX_ASYNC_IO_REQUESTS in rdpdr.c!\n"); |
if (!iorq->next) |
127 |
return False; |
return False; |
128 |
|
iorq->next->fd = 0; |
129 |
|
iorq->next->next = NULL; |
130 |
|
} |
131 |
|
iorq = iorq->next; |
132 |
|
} |
133 |
|
iorq->device = device; |
134 |
|
iorq->fd = file; |
135 |
|
iorq->id = id; |
136 |
|
iorq->major = major; |
137 |
|
iorq->length = length; |
138 |
|
iorq->partial_len = 0; |
139 |
|
iorq->fns = fns; |
140 |
|
iorq->timeout = total_timeout; |
141 |
|
iorq->itv_timeout = interval_timeout; |
142 |
|
iorq->buffer = buffer; |
143 |
|
iorq->offset = offset; |
144 |
|
return True; |
145 |
} |
} |
146 |
|
|
|
|
|
147 |
void |
void |
148 |
rdpdr_send_connect(void) |
rdpdr_send_connect(void) |
149 |
{ |
{ |
164 |
rdpdr_send_name(void) |
rdpdr_send_name(void) |
165 |
{ |
{ |
166 |
uint8 magic[4] = "rDNC"; |
uint8 magic[4] = "rDNC"; |
|
uint32 hostlen = (strlen(hostname) + 1) * 2; |
|
167 |
STREAM s; |
STREAM s; |
168 |
|
uint32 hostlen; |
169 |
|
|
170 |
|
if (NULL == g_rdpdr_clientname) { |
171 |
|
g_rdpdr_clientname = hostname; |
172 |
|
} |
173 |
|
hostlen = (strlen(g_rdpdr_clientname) + 1) * 2; |
174 |
|
|
175 |
s = channel_init(rdpdr_channel, 16 + hostlen); |
s = channel_init(rdpdr_channel, 16 + hostlen); |
176 |
out_uint8a(s, magic, 4); |
out_uint8a(s, magic, 4); |
178 |
out_uint16_le(s, 0x72); |
out_uint16_le(s, 0x72); |
179 |
out_uint32(s, 0); |
out_uint32(s, 0); |
180 |
out_uint32_le(s, hostlen); |
out_uint32_le(s, hostlen); |
181 |
rdp_out_unistr(s, hostname, hostlen - 2); |
rdp_out_unistr(s, g_rdpdr_clientname, hostlen - 2); |
182 |
s_mark_end(s); |
s_mark_end(s); |
183 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
184 |
} |
} |
250 |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
251 |
out_uint8a(s, printerinfo->blob, bloblen); |
out_uint8a(s, printerinfo->blob, bloblen); |
252 |
|
|
253 |
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
if (printerinfo->blob) |
254 |
|
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
255 |
break; |
break; |
256 |
default: |
default: |
257 |
out_uint32(s, 0); |
out_uint32(s, 0); |
326 |
buffer = (uint8 *) xmalloc(1024); |
buffer = (uint8 *) xmalloc(1024); |
327 |
buffer[0] = 0; |
buffer[0] = 0; |
328 |
|
|
|
|
|
329 |
switch (g_rdpdr_device[device].device_type) |
switch (g_rdpdr_device[device].device_type) |
330 |
{ |
{ |
331 |
case DEVICE_TYPE_SERIAL: |
case DEVICE_TYPE_SERIAL: |
332 |
|
|
333 |
fns = &serial_fns; |
fns = &serial_fns; |
334 |
/* should be async when aio is finished */ |
rw_blocking = False; |
|
/*rw_blocking = False; */ |
|
335 |
break; |
break; |
336 |
|
|
337 |
case DEVICE_TYPE_PARALLEL: |
case DEVICE_TYPE_PARALLEL: |
338 |
|
|
339 |
fns = ¶llel_fns; |
fns = ¶llel_fns; |
340 |
/* should be async when aio is finished */ |
rw_blocking = False; |
|
/*rw_blocking = False; */ |
|
341 |
break; |
break; |
342 |
|
|
343 |
case DEVICE_TYPE_PRINTER: |
case DEVICE_TYPE_PRINTER: |
348 |
case DEVICE_TYPE_DISK: |
case DEVICE_TYPE_DISK: |
349 |
|
|
350 |
fns = &disk_fns; |
fns = &disk_fns; |
351 |
|
rw_blocking = False; |
352 |
break; |
break; |
353 |
|
|
354 |
case DEVICE_TYPE_SCARD: |
case DEVICE_TYPE_SCARD: |
414 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
415 |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
416 |
#endif |
#endif |
417 |
|
if (!rdpdr_handle_ok(device, file)) |
418 |
|
{ |
419 |
|
status = STATUS_INVALID_HANDLE; |
420 |
|
break; |
421 |
|
} |
422 |
|
|
423 |
if (rw_blocking) // Complete read immediately |
if (rw_blocking) // Complete read immediately |
424 |
{ |
{ |
425 |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
426 |
|
if (!buffer) |
427 |
|
{ |
428 |
|
status = STATUS_CANCELLED; |
429 |
|
break; |
430 |
|
} |
431 |
status = fns->read(file, buffer, length, offset, &result); |
status = fns->read(file, buffer, length, offset, &result); |
432 |
buffer_len = result; |
buffer_len = result; |
433 |
break; |
break; |
435 |
|
|
436 |
// Add request to table |
// Add request to table |
437 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
438 |
|
if (!pst_buf) |
439 |
|
{ |
440 |
|
status = STATUS_CANCELLED; |
441 |
|
break; |
442 |
|
} |
443 |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
444 |
if (add_async_iorequest |
if (add_async_iorequest |
445 |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
446 |
pst_buf)) |
pst_buf, offset)) |
447 |
{ |
{ |
448 |
status = STATUS_PENDING; |
status = STATUS_PENDING; |
449 |
break; |
break; |
451 |
|
|
452 |
status = STATUS_CANCELLED; |
status = STATUS_CANCELLED; |
453 |
break; |
break; |
|
|
|
454 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
455 |
|
|
456 |
buffer_len = 1; |
buffer_len = 1; |
467 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
468 |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
469 |
#endif |
#endif |
470 |
|
if (!rdpdr_handle_ok(device, file)) |
471 |
|
{ |
472 |
|
status = STATUS_INVALID_HANDLE; |
473 |
|
break; |
474 |
|
} |
475 |
|
|
476 |
if (rw_blocking) // Complete immediately |
if (rw_blocking) // Complete immediately |
477 |
{ |
{ |
478 |
status = fns->write(file, s->p, length, offset, &result); |
status = fns->write(file, s->p, length, offset, &result); |
481 |
|
|
482 |
// Add to table |
// Add to table |
483 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
484 |
|
if (!pst_buf) |
485 |
|
{ |
486 |
|
status = STATUS_CANCELLED; |
487 |
|
break; |
488 |
|
} |
489 |
|
|
490 |
in_uint8a(s, pst_buf, length); |
in_uint8a(s, pst_buf, length); |
491 |
|
|
492 |
if (add_async_iorequest |
if (add_async_iorequest |
493 |
(device, file, id, major, length, fns, 0, 0, pst_buf)) |
(device, file, id, major, length, fns, 0, 0, pst_buf, offset)) |
494 |
{ |
{ |
495 |
status = STATUS_PENDING; |
status = STATUS_PENDING; |
496 |
break; |
break; |
610 |
in_uint8s(s, 0x14); |
in_uint8s(s, 0x14); |
611 |
|
|
612 |
buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14); |
buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14); |
613 |
|
if (!buffer) |
614 |
|
{ |
615 |
|
status = STATUS_CANCELLED; |
616 |
|
break; |
617 |
|
} |
618 |
|
|
619 |
out.data = out.p = buffer; |
out.data = out.p = buffer; |
620 |
out.size = sizeof(buffer); |
out.size = sizeof(buffer); |
621 |
status = fns->device_control(file, request, s, &out); |
status = fns->device_control(file, request, s, &out); |
631 |
{ |
{ |
632 |
rdpdr_send_completion(device, id, status, result, buffer, buffer_len); |
rdpdr_send_completion(device, id, status, result, buffer, buffer_len); |
633 |
} |
} |
634 |
xfree(buffer); |
if (buffer) |
635 |
|
xfree(buffer); |
636 |
|
buffer = NULL; |
637 |
} |
} |
638 |
|
|
639 |
void |
void |
752 |
void |
void |
753 |
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) |
754 |
{ |
{ |
755 |
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). |
|
756 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
757 |
|
|
758 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
iorq = g_iorequest; |
759 |
|
while (iorq != NULL) |
760 |
{ |
{ |
761 |
iorq = &g_iorequest[i]; |
if (iorq->fd != 0) |
|
|
|
|
if (iorq->fd != 0) // Found a pending io request |
|
762 |
{ |
{ |
763 |
switch (iorq->major) |
switch (iorq->major) |
764 |
{ |
{ |
781 |
break; |
break; |
782 |
|
|
783 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
|
|
|
784 |
FD_SET(iorq->fd, wfds); |
FD_SET(iorq->fd, wfds); |
785 |
break; |
break; |
786 |
|
|
787 |
} |
} |
788 |
*n = MAX(*n, iorq->fd); |
*n = MAX(*n, iorq->fd); |
789 |
} |
} |
790 |
|
|
791 |
|
iorq = iorq->next; |
792 |
|
} |
793 |
|
} |
794 |
|
|
795 |
|
struct async_iorequest * |
796 |
|
rdpdr_remove_iorequest(struct async_iorequest *prev, struct async_iorequest *iorq) |
797 |
|
{ |
798 |
|
if (!iorq) |
799 |
|
return NULL; |
800 |
|
|
801 |
|
if (iorq->buffer) |
802 |
|
xfree(iorq->buffer); |
803 |
|
if (prev) |
804 |
|
{ |
805 |
|
prev->next = iorq->next; |
806 |
|
xfree(iorq); |
807 |
|
iorq = prev->next; |
808 |
|
} |
809 |
|
else |
810 |
|
{ |
811 |
|
// Even if NULL |
812 |
|
g_iorequest = iorq->next; |
813 |
|
xfree(iorq); |
814 |
|
iorq = NULL; |
815 |
} |
} |
816 |
|
return iorq; |
817 |
} |
} |
818 |
|
|
819 |
/* 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 */ |
820 |
void |
void |
821 |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
822 |
{ |
{ |
|
int i; |
|
823 |
NTSTATUS status; |
NTSTATUS status; |
824 |
uint32 result = 0, buffer_len = 0; |
uint32 result = 0; |
825 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
826 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
827 |
|
struct async_iorequest *prev; |
828 |
|
uint32 req_size = 0; |
829 |
|
|
830 |
if (timed_out) |
if (timed_out) |
831 |
{ |
{ |
833 |
return; |
return; |
834 |
} |
} |
835 |
|
|
836 |
// Walk through array of pending io_rq's |
iorq = g_iorequest; |
837 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
prev = NULL; |
838 |
|
while (iorq != NULL) |
839 |
{ |
{ |
|
iorq = &g_iorequest[i]; |
|
|
|
|
840 |
if (iorq->fd != 0) |
if (iorq->fd != 0) |
841 |
{ |
{ |
842 |
switch (iorq->major) |
switch (iorq->major) |
843 |
{ |
{ |
|
|
|
844 |
case IRP_MJ_READ: |
case IRP_MJ_READ: |
|
|
|
845 |
if (FD_ISSET(iorq->fd, rfds)) |
if (FD_ISSET(iorq->fd, rfds)) |
846 |
{ |
{ |
847 |
// Read, and send data. |
/* Read the data */ |
848 |
fns = iorq->fns; |
fns = iorq->fns; |
849 |
status = fns->read(iorq->fd, iorq->buffer, |
|
850 |
iorq->length, 0, &result); |
req_size = |
851 |
buffer_len = result; |
(iorq->length - iorq->partial_len) > |
852 |
|
8192 ? 8192 : (iorq->length - |
853 |
rdpdr_send_completion(iorq->device, iorq->id, |
iorq->partial_len); |
854 |
status, result, iorq->buffer, |
/* never read larger chunks than 8k - chances are that it will block */ |
855 |
buffer_len); |
status = fns->read(iorq->fd, |
856 |
|
iorq->buffer + iorq->partial_len, |
857 |
|
req_size, iorq->offset, &result); |
858 |
|
|
859 |
|
if (result > 0) |
860 |
|
{ |
861 |
|
iorq->partial_len += result; |
862 |
|
iorq->offset += result; |
863 |
|
} |
864 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
865 |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
866 |
#endif |
#endif |
867 |
xfree(iorq->buffer); |
/* only delete link if all data has been transfered */ |
868 |
iorq->fd = 0; |
/* or if result was 0 and status success - EOF */ |
869 |
|
if ((iorq->partial_len == iorq->length) || |
870 |
|
(result == 0)) |
871 |
|
{ |
872 |
|
#if WITH_DEBUG_RDP5 |
873 |
|
DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length)); |
874 |
|
#endif |
875 |
|
rdpdr_send_completion(iorq->device, |
876 |
|
iorq->id, status, |
877 |
|
iorq->partial_len, |
878 |
|
iorq->buffer, |
879 |
|
iorq->partial_len); |
880 |
|
iorq = rdpdr_remove_iorequest(prev, iorq); |
881 |
|
} |
882 |
} |
} |
883 |
break; |
break; |
|
|
|
884 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
|
|
|
885 |
if (FD_ISSET(iorq->fd, wfds)) |
if (FD_ISSET(iorq->fd, wfds)) |
886 |
{ |
{ |
887 |
// Write data and send completion. |
/* Write data. */ |
888 |
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); |
|
889 |
|
|
890 |
xfree(iorq->buffer); |
req_size = |
891 |
iorq->fd = 0; |
(iorq->length - iorq->partial_len) > |
892 |
|
8192 ? 8192 : (iorq->length - |
893 |
|
iorq->partial_len); |
894 |
|
|
895 |
|
/* never write larger chunks than 8k - chances are that it will block */ |
896 |
|
status = fns->write(iorq->fd, |
897 |
|
iorq->buffer + |
898 |
|
iorq->partial_len, req_size, |
899 |
|
iorq->offset, &result); |
900 |
|
|
901 |
|
if (result > 0) |
902 |
|
{ |
903 |
|
iorq->partial_len += result; |
904 |
|
iorq->offset += result; |
905 |
|
} |
906 |
|
|
907 |
|
#if WITH_DEBUG_RDP5 |
908 |
|
DEBUG(("RDPDR: %d bytes of data written\n", |
909 |
|
result)); |
910 |
|
#endif |
911 |
|
/* only delete link if all data has been transfered */ |
912 |
|
/* or we couldn't write */ |
913 |
|
if ((iorq->partial_len == iorq->length) |
914 |
|
|| (result == 0)) |
915 |
|
{ |
916 |
|
#if WITH_DEBUG_RDP5 |
917 |
|
DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length)); |
918 |
|
#endif |
919 |
|
rdpdr_send_completion(iorq->device, |
920 |
|
iorq->id, status, |
921 |
|
iorq->partial_len, |
922 |
|
(uint8 *) "", 1); |
923 |
|
|
924 |
|
iorq = rdpdr_remove_iorequest(prev, iorq); |
925 |
|
} |
926 |
} |
} |
927 |
break; |
break; |
928 |
} |
} |
929 |
|
|
930 |
} |
} |
931 |
|
prev = iorq; |
932 |
|
if (iorq) |
933 |
|
iorq = iorq->next; |
934 |
} |
} |
935 |
|
|
936 |
} |
} |
937 |
|
|
938 |
/* Abort a pending io request for a given handle and major */ |
/* Abort a pending io request for a given handle and major */ |
940 |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
941 |
{ |
{ |
942 |
uint32 result; |
uint32 result; |
|
int i; |
|
943 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
944 |
|
struct async_iorequest *prev; |
945 |
|
|
946 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
iorq = g_iorequest; |
947 |
|
prev = NULL; |
948 |
|
while (iorq != NULL) |
949 |
{ |
{ |
|
iorq = &g_iorequest[i]; |
|
|
|
|
950 |
// 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. |
951 |
// Abort read should not abort a write io request. |
// Abort read should not abort a write io request. |
952 |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
953 |
{ |
{ |
954 |
result = 0; |
result = 0; |
955 |
rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1); |
rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "", |
956 |
xfree(iorq->buffer); |
1); |
957 |
iorq->fd = 0; |
|
958 |
|
iorq = rdpdr_remove_iorequest(prev, iorq); |
959 |
return True; |
return True; |
960 |
} |
} |
961 |
|
|
962 |
|
prev = iorq; |
963 |
|
iorq = iorq->next; |
964 |
} |
} |
965 |
|
|
966 |
return False; |
return False; |
967 |
} |
} |