rdpdr disk: map error codes, starting with create irp
authorAnthony Tong <atong@trustedcs.com>
Wed, 19 Oct 2011 13:43:04 +0000 (09:43 -0400)
committerAnthony Tong <atong@trustedcs.com>
Wed, 19 Oct 2011 13:43:04 +0000 (09:43 -0400)
channels/rdpdr/disk/disk_file.c
channels/rdpdr/disk/disk_file.h
channels/rdpdr/disk/disk_main.c

index 04bb613..bf6e0eb 100644 (file)
@@ -23,6 +23,7 @@
 #endif
 
 #include "config.h"
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -170,7 +171,10 @@ static boolean disk_file_init(DISK_FILE* file, uint32 DesiredAccess, uint32 Crea
                if (file->is_dir)
                {
                        if (mkdir(file->fullpath, mode) != 0)
-                               return False;
+                       {
+                               file->err = errno;
+                               return True;
+                       }
                }
                exists = False;
        }
@@ -178,7 +182,10 @@ static boolean disk_file_init(DISK_FILE* file, uint32 DesiredAccess, uint32 Crea
        {
                file->dir = opendir(file->fullpath);
                if (file->dir == NULL)
-                       return False;
+               {
+                       file->err = errno;
+                       return True;
+               }
        }
        else
        {
@@ -221,7 +228,10 @@ static boolean disk_file_init(DISK_FILE* file, uint32 DesiredAccess, uint32 Crea
 
                file->fd = open(file->fullpath, oflag, mode);
                if (file->fd == -1)
-                       return False;
+               {
+                       file->err = errno;
+                       return True;
+               }
        }
 
        return True;
index 950fa36..8857451 100644 (file)
@@ -31,6 +31,7 @@ struct _DISK_FILE
        uint32 id;
        boolean is_dir;
        int fd;
+       int err;
        DIR* dir;
        char* fullpath;
        char* filename;
index d0496b1..5f820c6 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include "config.h"
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -45,6 +46,40 @@ struct _DISK_DEVICE
        freerdp_thread* thread;
 };
 
+
+static uint32
+disk_map_posix_err(int fs_errno)
+{
+       uint32 rc;
+
+       /* try to return NTSTATUS version of error code */
+       switch (fs_errno)
+       {
+               case EPERM:
+               case EACCES:
+                       rc = STATUS_ACCESS_DENIED;
+                       break;
+               case ENOENT:
+                       rc = STATUS_NO_SUCH_FILE;
+                       break;
+               case EBUSY:
+                       rc = STATUS_DEVICE_BUSY;
+                       break;
+               case EEXIST:
+                       rc  = STATUS_OBJECT_NAME_COLLISION;
+                       break;
+               case EISDIR:
+                       rc = STATUS_FILE_IS_A_DIRECTORY;
+                       break;
+
+               default:
+                       rc = STATUS_UNSUCCESSFUL;
+                       break;
+       }
+       DEBUG_SVC("errno 0x%x mapped to 0x%x\n", fs_errno, rc);
+       return rc;
+}
+
 static DISK_FILE* disk_get_file_by_id(DISK_DEVICE* disk, uint32 id)
 {
        LIST_ITEM* item;
@@ -93,6 +128,16 @@ static void disk_process_irp_create(DISK_DEVICE* disk, IRP* irp)
 
                DEBUG_WARN("failed to create %s.", path);
        }
+       else if (file->err)
+       {
+               FileId = 0;
+               Information = 0;
+
+               /* map errno to windows result*/
+               irp->IoStatus = disk_map_posix_err(file->err);
+
+               disk_file_free(file);
+       }
        else
        {
                list_enqueue(disk->files, file);