Generalized error conversion by the new captive_NTSTATUS_to_GnomeVFSResult().
authorshort <>
Sat, 1 Feb 2003 01:21:49 +0000 (01:21 +0000)
committershort <>
Sat, 1 Feb 2003 01:21:49 +0000 (01:21 +0000)
src/libcaptive/client/Makefile.am
src/libcaptive/client/directory.c
src/libcaptive/client/file.c
src/libcaptive/client/file_info.c
src/libcaptive/client/result.c [new file with mode: 0644]
src/libcaptive/client/result.h [new file with mode: 0644]

index 6fc288b..a9c2763 100644 (file)
@@ -23,6 +23,9 @@ noinst_LTLIBRARIES=libclient.la
 libclient_la_SOURCES= \
                init.c \
                lib.c \
+               lib.h \
                directory.c \
                file.c \
-               file_info.c
+               file_info.c \
+               result.c \
+               result.h
index 6877972..7007cdc 100644 (file)
@@ -27,6 +27,7 @@
 #include "reactos/ddk/iotypes.h"       /* for IO_STATUS_BLOCK */
 #include "reactos/ddk/iofuncs.h"       /* for IoCreateFile() */
 #include "captive/sandbox.h"
+#include "result.h"
 
 
 static gpointer captive_directory_object_parent_class=NULL;
@@ -287,8 +288,8 @@ GnomeVFSResult errvfsresult;
                        NULL,   /* FileName; wildcards possible; optional */
                        captive_directory_object->read_first);  /* RestartScan */
        captive_directory_object->read_first=FALSE;
-       if (err==STATUS_NO_MORE_FILES)
-               return GNOME_VFS_ERROR_EOF;
+       if (GNOME_VFS_OK!=(errvfsresult=captive_NTSTATUS_to_GnomeVFSResult(err)))
+               return errvfsresult;
        g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
 
        errvfsresult=FileIdBothDirInformation_to_GnomeVFSFileInfo(file_info,FileIdBothDirInformation,
index ebecee8..c5254e0 100644 (file)
@@ -27,6 +27,7 @@
 #include "reactos/ddk/iotypes.h"       /* for IO_STATUS_BLOCK */
 #include "reactos/ddk/iofuncs.h"       /* for IoCreateFile() */
 #include "captive/sandbox.h"
+#include "result.h"
 
 
 static gpointer captive_file_object_parent_class=NULL;
@@ -134,8 +135,8 @@ NTSTATUS err;
                        0);     /* Options */
        g_free(file_ObjectAttributes.ObjectName);       /* left from captive_file_uri_parent_init() */
        g_return_val_if_fail(NT_SUCCESS(err)==NT_SUCCESS(file_IoStatusBlock.Status),GNOME_VFS_ERROR_GENERIC);
-       if (err==STATUS_OBJECT_NAME_COLLISION)
-               return GNOME_VFS_ERROR_FILE_EXISTS;
+       if (GNOME_VFS_OK!=(errvfsresult=captive_NTSTATUS_to_GnomeVFSResult(err)))
+               return errvfsresult;
        g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
        g_return_val_if_fail(file_IoStatusBlock.Information
                                        ==(!create ? FILE_OPENED : FILE_CREATED),
@@ -205,6 +206,7 @@ GnomeVFSResult captive_file_read(CaptiveFileObject *captive_file_object,
 NTSTATUS err;
 IO_STATUS_BLOCK file_IoStatusBlock;
 LARGE_INTEGER file_offset;
+GnomeVFSResult errvfsresult;
 
        if (CAPTIVE_IS_SANDBOX_PARENT())
                return captive_sandbox_parent_file_read(captive_file_object,buffer,num_bytes,bytes_read_return);
@@ -232,6 +234,8 @@ LARGE_INTEGER file_offset;
                *bytes_read_return=0;
                return GNOME_VFS_ERROR_EOF;
                }
+       if (GNOME_VFS_OK!=(errvfsresult=captive_NTSTATUS_to_GnomeVFSResult(err)))
+               return errvfsresult;
        g_return_val_if_fail(NT_SUCCESS(err)==NT_SUCCESS(file_IoStatusBlock.Status),GNOME_VFS_ERROR_GENERIC);
        g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
        g_return_val_if_fail(file_IoStatusBlock.Information<=num_bytes,GNOME_VFS_ERROR_GENERIC);
index 040b4d2..d2d4e49 100644 (file)
@@ -27,6 +27,7 @@
 #include "reactos/ddk/iotypes.h"       /* for IO_STATUS_BLOCK */
 #include "reactos/ddk/iofuncs.h"       /* for IoCreateFile() */
 #include "captive/sandbox.h"
+#include "result.h"
 
 
 /* Use 'FileAllInformationStruct' identifier instead of the logical 'FileAllInformation'
@@ -161,12 +162,8 @@ char QueryFile_buf[sizeof(FILE_ALL_INFORMATION)
                        0);     /* Options */
        g_free(file_ObjectAttributes.ObjectName);       /* left from captive_gnomevfs_uri_parent_init() */
        g_return_val_if_fail(NT_SUCCESS(err)==NT_SUCCESS(file_IoStatusBlock.Status),GNOME_VFS_ERROR_GENERIC);
-       if (err==STATUS_OBJECT_NAME_NOT_FOUND)
-               return GNOME_VFS_ERROR_NOT_FOUND;
-       if (err==STATUS_UNRECOGNIZED_VOLUME)
-               return GNOME_VFS_ERROR_WRONG_FORMAT;
-       if (err==STATUS_OBJECT_NAME_INVALID)
-               return GNOME_VFS_ERROR_INVALID_URI;
+       if (GNOME_VFS_OK!=(errvfsresult=captive_NTSTATUS_to_GnomeVFSResult(err)))
+               return errvfsresult;
        g_return_val_if_fail(NT_SUCCESS(err),GNOME_VFS_ERROR_GENERIC);
        g_return_val_if_fail(file_IoStatusBlock.Information==FILE_OPENED,GNOME_VFS_ERROR_GENERIC);
 
diff --git a/src/libcaptive/client/result.c b/src/libcaptive/client/result.c
new file mode 100644 (file)
index 0000000..5c4a972
--- /dev/null
@@ -0,0 +1,40 @@
+/* $Id$
+ * captive vfs result code translation for Gnome-VFS-2.0
+ * Copyright (C) 2002-2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include "result.h"    /* self */
+#include <glib/gmessages.h>
+#include "reactos/ddk/status.h"        /* for STATUS_* */
+#include <libgnomevfs/gnome-vfs-result.h>      /* for GnomeVFSResult */
+
+
+GnomeVFSResult captive_NTSTATUS_to_GnomeVFSResult(NTSTATUS err)
+{
+       switch (err) {
+               case STATUS_NO_SUCH_FILE:          return GNOME_VFS_ERROR_EOF;  /* ==0 files found */
+               case STATUS_NO_MORE_FILES:         return GNOME_VFS_ERROR_EOF;  /* >=1 files found */
+               case STATUS_OBJECT_NAME_COLLISION: return GNOME_VFS_ERROR_FILE_EXISTS;
+               case STATUS_OBJECT_NAME_NOT_FOUND: return GNOME_VFS_ERROR_NOT_FOUND;
+               case STATUS_UNRECOGNIZED_VOLUME:   return GNOME_VFS_ERROR_WRONG_FORMAT;
+               case STATUS_OBJECT_NAME_INVALID:   return GNOME_VFS_ERROR_INVALID_URI;
+               default:; /* PASSTHRU */
+               }
+       return GNOME_VFS_OK;    /* undetected */
+}
diff --git a/src/libcaptive/client/result.h b/src/libcaptive/client/result.h
new file mode 100644 (file)
index 0000000..d77bf4a
--- /dev/null
@@ -0,0 +1,36 @@
+/* $Id$
+ * Include file for captive vfs result code translation for Gnome-VFS-2.0
+ * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_RESULT_H
+#define _CAPTIVE_CLIENT_RESULT_H 1
+
+
+#include <glib/gmacros.h>
+#include "reactos/napi/types.h"        /* for NTSTATUS */
+#include <libgnomevfs/gnome-vfs-result.h>
+
+
+G_BEGIN_DECLS
+
+GnomeVFSResult captive_NTSTATUS_to_GnomeVFSResult(NTSTATUS err);
+
+G_END_DECLS
+
+
+#endif /* _CAPTIVE_CLIENT_RESULT_H */