From d08636bdad4f36431bfdf07e8400d7188a2df781 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Fri, 25 Oct 2024 11:32:12 +0200 Subject: Rework file copy/open-read-write-close data handling Stick to the POSIX open(2), read(2), write(2), close(2) return values semantics, apply on the VFS interface. Also handle short reads and writes that are common for some gvfs backends. This makes cross-VFS copy work. --- vfs/uVFSprototypes.pas | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'vfs') diff --git a/vfs/uVFSprototypes.pas b/vfs/uVFSprototypes.pas index 9ed0844..6fbe65d 100644 --- a/vfs/uVFSprototypes.pas +++ b/vfs/uVFSprototypes.pas @@ -224,7 +224,7 @@ type // Changes times for the file/directory - mtime and atime are __time_t parameters (glibc) TVFSChangeTimes = function (g:TVFSGlobs; const APath: PChar; mtime, atime: guint32; Error: PPGError): gboolean; cdecl; - + // Performs the copy process from inside of module to local filesystem // (thus sSrcName is a path from inside of module and sDstName is path in the local filesystem where the file should be copied) // Note: if you need to transfer a file between two VFS modules, you need to do it manually - @@ -242,20 +242,19 @@ type TVFSPack = function (g:TVFSGlobs; const sSrcName, sDstName: PChar; CompressionLevel: integer; const Password: PChar; Error: PPGError): gboolean; cdecl; - // TODO: not implemented at all - // This is the set of basic functions which can manipulate with data - // There is a TVFSFileDes object which identifies the processed file (filedescriptor) - // All these functions needs a pointer to an int variable to store the error code + // Low-level open-read-write-close, used for e.g. cross-VFS copy + // An abstract TVFSFileDes object serves as a file descriptor/handle // NOTE: not all modules could support this set of functions due to its design (unable to set a solid block size) TVFSOpenFile = function (g:TVFSGlobs; const APath: PChar; Mode: integer; Error: PPGError): TVFSFileDes; cdecl; // Opens a file or creates new (the values for the Mode parameter are described above) and returns the assigned filedescriptor - TVFSReadFile = function (g:TVFSGlobs; const FileDescriptor: TVFSFileDes; Buffer: Pointer; ABlockSize: integer; Error: PPGError): integer; cdecl; - // Returns number of bytes read; the buffer needs to be allocated by a blocksize (set it by VFSSetBlockSize function) - TVFSWriteFile = function (g:TVFSGlobs; const FileDescriptor: TVFSFileDes; Buffer: Pointer; BytesCount: integer; Error: PPGError): integer; cdecl; - // Returns number of bytes written + TVFSReadFile = function (g:TVFSGlobs; const FileDescriptor: TVFSFileDes; Buffer: Pointer; ABlockSize: guint64; Error: PPGError): gint64; cdecl; + // Returns number of bytes read that may be smaller than requested number of bytes. Returns 0 typically at EOF or -1 in case of an error. + // The buffer needs to be allocated for a blocksize (set it by VFSSetBlockSize function) + TVFSWriteFile = function (g:TVFSGlobs; const FileDescriptor: TVFSFileDes; Buffer: Pointer; BytesCount: guint64; Error: PPGError): gint64; cdecl; + // Returns number of bytes written that may be smaller than requested number of bytes. Returns -1 in case of an error. TVFSCloseFile = function (g:TVFSGlobs; const FileDescriptor: TVFSFileDes; Error: PPGError): gboolean; cdecl; TVFSFileSeek = function (g:TVFSGlobs; const FileDescriptor: TVFSFileDes; const AbsoluteOffset: Int64; Error: PPGError): Int64; cdecl; - // Sets the position in the file from the start and returns real current position + // Sets the position in the file from the start and returns real current position. Returns -1 in case of an error. // Archive-specific routines: -- cgit v1.2.3