summaryrefslogtreecommitdiff
path: root/gvfs/gvfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'gvfs/gvfs.c')
-rw-r--r--gvfs/gvfs.c163
1 files changed, 119 insertions, 44 deletions
diff --git a/gvfs/gvfs.c b/gvfs/gvfs.c
index bc708f8..069d910 100644
--- a/gvfs/gvfs.c
+++ b/gvfs/gvfs.c
@@ -28,8 +28,8 @@
#include "logutils.h"
-#define VERSION "0.2.3"
-#define BUILD_DATE "2024-10-15"
+#define VERSION "0.3"
+#define BUILD_DATE "2024-10-25"
#define DEFAULT_BLOCK_SIZE 0x10000 /* 64kB */
#define CONST_DEFAULT_QUERY_INFO_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK "," \
@@ -1146,44 +1146,6 @@ VFSBreakGetDirSize (struct TVFSGlobs *globs)
/**************************************************************************************************************************************/
/**************************************************************************************************************************************/
-#if 0
-TVFSFileDes
-VFSOpenFile (struct TVFSGlobs *globs, const char *APath, int Mode, int *Error)
-{
- printf("(WW) VFSOpenFile: Not supported in GVFS plugin.\n");
- return NULL;
-}
-
-TVFSResult
-VFSCloseFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor)
-{
- printf("(WW) VFSCloseFile: Not supported in GVFS plugin.\n");
- return cVFS_Not_Supported;
-}
-
-guint64
-VFSFileSeek (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, guint64 AbsoluteOffset, int *Error)
-{
- printf("(WW) VFSFileSeek: Not supported in GVFS plugin.\n");
- return 0;
-}
-
-int
-VFSReadFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, int ABlockSize, int *Error)
-{
- printf("(WW) VFSReadFile: Not supported in GVFS plugin.\n");
- return cVFS_Not_Supported;
-}
-
-int
-VFSWriteFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, int BytesCount, int *Error)
-{
- printf("(WW) VFSWriteFile: Not supported in GVFS plugin.\n");
- return cVFS_Not_Supported;
-}
-#endif
-
-
void
VFSSetBlockSize (struct TVFSGlobs *globs, guint32 Value)
{
@@ -1292,11 +1254,9 @@ vfs_copy_progress_callback (goffset current_num_bytes,
goffset total_num_bytes,
gpointer user_data)
{
- struct TVFSGlobs *globs;
+ struct TVFSGlobs *globs = user_data;
- if (! user_data)
- return;
- globs = (struct TVFSGlobs *)user_data;
+ g_return_if_fail (user_data != NULL);
if (globs->callback_progress) {
if (! globs->callback_progress (current_num_bytes, NULL, globs->callback_data))
@@ -1408,6 +1368,121 @@ VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDs
}
+/**************************************************************************************************************************************/
+/**************************************************************************************************************************************/
+
+TVFSFileDes
+VFSOpenFile (struct TVFSGlobs *globs, const char *APath, int Mode, GError **error)
+{
+ GFile *file;
+ GFileInputStream *input_stream;
+ GFileOutputStream *output_stream;
+
+ if (globs->file == NULL) {
+ log_error ("VFSOpenFile: globs->file == NULL!");
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "globs->file == NULL");
+ return NULL;
+ }
+
+ log_notice ("VFSOpenFile: Opening '%s'", APath);
+ file = g_file_resolve_relative_path (globs->file, APath);
+ if (file == NULL) {
+ log_error ("VFSOpenFile: g_file_resolve_relative_path() failed.");
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Cannot resolve relative path for source file.");
+ return NULL;
+ }
+
+ switch (Mode) {
+ case cVFS_OpenRead:
+ input_stream = g_file_read (file, NULL /* cancellable */, error);
+ g_object_unref (file);
+ return input_stream;
+ case cVFS_OpenWrite:
+ output_stream = g_file_create (file, G_FILE_CREATE_NONE, NULL /* cancellable */, error);
+ g_object_unref (file);
+ return output_stream;
+ case cVFS_OpenAppend:
+ output_stream = g_file_append_to (file, G_FILE_CREATE_NONE, NULL /* cancellable */, error);
+ g_object_unref (file);
+ return output_stream;
+ }
+
+ log_error ("VFSOpenFile: Invalid file open mode %d", Mode);
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid file open mode %d", Mode);
+ g_object_unref (file);
+ return NULL;
+}
+
+gboolean
+VFSCloseFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, GError **error)
+{
+ if (G_IS_FILE_INPUT_STREAM (FileDescriptor)) {
+ return g_input_stream_close (G_INPUT_STREAM (FileDescriptor),
+ NULL /* cancellable */,
+ error);
+ } else
+ if (G_IS_FILE_OUTPUT_STREAM (FileDescriptor)) {
+ return g_output_stream_close (G_OUTPUT_STREAM (FileDescriptor),
+ NULL /* cancellable */,
+ error);
+ }
+
+ log_error ("VFSCloseFile: Unknown file descriptor %p object type", FileDescriptor);
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor);
+ return FALSE;
+}
+
+gint64
+VFSReadFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, guint64 ABlockSize, GError **error)
+{
+ if (G_IS_FILE_INPUT_STREAM (FileDescriptor)) {
+ return g_input_stream_read (G_INPUT_STREAM (FileDescriptor),
+ Buffer,
+ ABlockSize,
+ NULL /* cancellable */,
+ error);
+ }
+
+ log_error ("VFSReadFile: Unknown file descriptor %p object type", FileDescriptor);
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor);
+ return 0;
+}
+
+gint64
+VFSWriteFile (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, gpointer Buffer, guint64 BytesCount, GError **error)
+{
+ if (G_IS_FILE_OUTPUT_STREAM (FileDescriptor)) {
+ return g_output_stream_write (G_OUTPUT_STREAM (FileDescriptor),
+ Buffer,
+ BytesCount,
+ NULL /* cancellable */,
+ error);
+ }
+
+ log_error ("VFSWriteFile: Unknown file descriptor %p object type", FileDescriptor);
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor);
+ return 0;
+}
+
+guint64
+VFSFileSeek (struct TVFSGlobs *globs, TVFSFileDes FileDescriptor, guint64 AbsoluteOffset, GError **error)
+{
+ if (G_IS_FILE_INPUT_STREAM (FileDescriptor) || G_IS_FILE_OUTPUT_STREAM (FileDescriptor)) {
+ if (!g_seekable_seek (G_SEEKABLE (FileDescriptor),
+ AbsoluteOffset,
+ G_SEEK_SET,
+ NULL /* cancellable */,
+ error))
+ return -1;
+ return g_seekable_tell (G_SEEKABLE (FileDescriptor));
+ }
+
+ log_error ("VFSFileSeek: Unknown file descriptor %p object type", FileDescriptor);
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Unknown file descriptor %p object type", FileDescriptor);
+ return FALSE;
+}
+
+
/**********
* TODO: