channels/drive: attempt at migrating LIST util to ListDictionary
This commit is contained in:
parent
490f18a7aa
commit
359c31b360
@ -40,8 +40,8 @@
|
|||||||
#include <winpr/thread.h>
|
#include <winpr/thread.h>
|
||||||
#include <winpr/stream.h>
|
#include <winpr/stream.h>
|
||||||
#include <winpr/interlocked.h>
|
#include <winpr/interlocked.h>
|
||||||
|
#include <winpr/collections.h>
|
||||||
|
|
||||||
#include <freerdp/utils/list.h>
|
|
||||||
#include <freerdp/channels/rdpdr.h>
|
#include <freerdp/channels/rdpdr.h>
|
||||||
|
|
||||||
#include "drive_file.h"
|
#include "drive_file.h"
|
||||||
@ -53,7 +53,7 @@ struct _DRIVE_DEVICE
|
|||||||
DEVICE device;
|
DEVICE device;
|
||||||
|
|
||||||
char* path;
|
char* path;
|
||||||
LIST* files;
|
wListDictionary* files;
|
||||||
|
|
||||||
HANDLE thread;
|
HANDLE thread;
|
||||||
HANDLE irpEvent;
|
HANDLE irpEvent;
|
||||||
@ -98,24 +98,20 @@ static UINT32 drive_map_posix_err(int fs_errno)
|
|||||||
|
|
||||||
static DRIVE_FILE* drive_get_file_by_id(DRIVE_DEVICE* disk, UINT32 id)
|
static DRIVE_FILE* drive_get_file_by_id(DRIVE_DEVICE* disk, UINT32 id)
|
||||||
{
|
{
|
||||||
LIST_ITEM* item;
|
DRIVE_FILE* file = NULL;
|
||||||
DRIVE_FILE* file;
|
void* key = (void*) (size_t) id;
|
||||||
|
|
||||||
for (item = disk->files->head; item; item = item->next)
|
file = (DRIVE_FILE*) ListDictionary_GetItemValue(disk->files, key);
|
||||||
{
|
|
||||||
file = (DRIVE_FILE*) item->data;
|
|
||||||
|
|
||||||
if (file->id == id)
|
fprintf(stderr, "drive_get_file_by_id: %d / %p\n", id, file);
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
|
static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
|
||||||
{
|
{
|
||||||
char* path = NULL;
|
|
||||||
int status;
|
int status;
|
||||||
|
void* key;
|
||||||
UINT32 FileId;
|
UINT32 FileId;
|
||||||
DRIVE_FILE* file;
|
DRIVE_FILE* file;
|
||||||
BYTE Information;
|
BYTE Information;
|
||||||
@ -123,6 +119,7 @@ static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
|
|||||||
UINT32 CreateDisposition;
|
UINT32 CreateDisposition;
|
||||||
UINT32 CreateOptions;
|
UINT32 CreateOptions;
|
||||||
UINT32 PathLength;
|
UINT32 PathLength;
|
||||||
|
char* path = NULL;
|
||||||
|
|
||||||
Stream_Read_UINT32(irp->input, DesiredAccess);
|
Stream_Read_UINT32(irp->input, DesiredAccess);
|
||||||
Stream_Seek(irp->input, 16); /* AllocationSize(8), FileAttributes(4), SharedAccess(4) */
|
Stream_Seek(irp->input, 16); /* AllocationSize(8), FileAttributes(4), SharedAccess(4) */
|
||||||
@ -141,7 +138,7 @@ static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
|
|||||||
file = drive_file_new(disk->path, path, FileId,
|
file = drive_file_new(disk->path, path, FileId,
|
||||||
DesiredAccess, CreateDisposition, CreateOptions);
|
DesiredAccess, CreateDisposition, CreateOptions);
|
||||||
|
|
||||||
if (file == NULL)
|
if (!file)
|
||||||
{
|
{
|
||||||
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
||||||
FileId = 0;
|
FileId = 0;
|
||||||
@ -158,7 +155,10 @@ static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list_enqueue(disk->files, file);
|
key = (void*) (size_t) file->id;
|
||||||
|
ListDictionary_Add(disk->files, key, file);
|
||||||
|
|
||||||
|
fprintf(stderr, "drive_file_new: %d / %p\n", file->id, file);
|
||||||
|
|
||||||
switch (CreateDisposition)
|
switch (CreateDisposition)
|
||||||
{
|
{
|
||||||
@ -190,17 +190,21 @@ static void drive_process_irp_create(DRIVE_DEVICE* disk, IRP* irp)
|
|||||||
|
|
||||||
static void drive_process_irp_close(DRIVE_DEVICE* disk, IRP* irp)
|
static void drive_process_irp_close(DRIVE_DEVICE* disk, IRP* irp)
|
||||||
{
|
{
|
||||||
|
void* key;
|
||||||
DRIVE_FILE* file;
|
DRIVE_FILE* file;
|
||||||
|
|
||||||
file = drive_get_file_by_id(disk, irp->FileId);
|
file = drive_get_file_by_id(disk, irp->FileId);
|
||||||
|
|
||||||
if (file == NULL)
|
key = (void*) (size_t) irp->FileId;
|
||||||
|
fprintf(stderr, "drive_process_irp_close: %d / %p / %d\n", irp->FileId, file, file->id);
|
||||||
|
|
||||||
|
if (!file)
|
||||||
{
|
{
|
||||||
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list_remove(disk->files, file);
|
ListDictionary_Remove(disk->files, key);
|
||||||
drive_file_free(file);
|
drive_file_free(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +225,7 @@ static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp)
|
|||||||
|
|
||||||
file = drive_get_file_by_id(disk, irp->FileId);
|
file = drive_get_file_by_id(disk, irp->FileId);
|
||||||
|
|
||||||
if (file == NULL)
|
if (!file)
|
||||||
{
|
{
|
||||||
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
||||||
Length = 0;
|
Length = 0;
|
||||||
@ -234,6 +238,7 @@ static void drive_process_irp_read(DRIVE_DEVICE* disk, IRP* irp)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer = (BYTE*) malloc(Length);
|
buffer = (BYTE*) malloc(Length);
|
||||||
|
|
||||||
if (!drive_file_read(file, buffer, &Length))
|
if (!drive_file_read(file, buffer, &Length))
|
||||||
{
|
{
|
||||||
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
irp->IoStatus = STATUS_UNSUCCESSFUL;
|
||||||
@ -625,7 +630,6 @@ static void drive_irp_request(DEVICE* device, IRP* irp)
|
|||||||
static void drive_free(DEVICE* device)
|
static void drive_free(DEVICE* device)
|
||||||
{
|
{
|
||||||
IRP* irp;
|
IRP* irp;
|
||||||
DRIVE_FILE* file;
|
|
||||||
DRIVE_DEVICE* disk = (DRIVE_DEVICE*) device;
|
DRIVE_DEVICE* disk = (DRIVE_DEVICE*) device;
|
||||||
|
|
||||||
SetEvent(disk->stopEvent);
|
SetEvent(disk->stopEvent);
|
||||||
@ -639,10 +643,7 @@ static void drive_free(DEVICE* device)
|
|||||||
|
|
||||||
_aligned_free(disk->pIrpList);
|
_aligned_free(disk->pIrpList);
|
||||||
|
|
||||||
while ((file = (DRIVE_FILE*) list_dequeue(disk->files)) != NULL)
|
ListDictionary_Free(disk->files);
|
||||||
drive_file_free(file);
|
|
||||||
|
|
||||||
list_free(disk->files);
|
|
||||||
|
|
||||||
free(disk);
|
free(disk);
|
||||||
}
|
}
|
||||||
@ -683,7 +684,9 @@ void drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char*
|
|||||||
Stream_Write_UINT8(disk->device.data, name[i] < 0 ? '_' : name[i]);
|
Stream_Write_UINT8(disk->device.data, name[i] < 0 ? '_' : name[i]);
|
||||||
|
|
||||||
disk->path = path;
|
disk->path = path;
|
||||||
disk->files = list_new();
|
|
||||||
|
disk->files = ListDictionary_New(TRUE);
|
||||||
|
ListDictionary_Object(disk->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free;
|
||||||
|
|
||||||
disk->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT);
|
disk->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT);
|
||||||
InitializeSListHead(disk->pIrpList);
|
InitializeSListHead(disk->pIrpList);
|
||||||
|
Loading…
Reference in New Issue
Block a user