Merge pull request #163 from atong-tcs/master

map fs error codes
This commit is contained in:
Marc-André Moreau 2011-10-19 06:47:09 -07:00
commit 4c6b273639
3 changed files with 59 additions and 3 deletions

View 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;

View File

@ -31,6 +31,7 @@ struct _DISK_FILE
uint32 id;
boolean is_dir;
int fd;
int err;
DIR* dir;
char* fullpath;
char* filename;

View 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);