From beeae73c7964d7b7f3e5adfdcbbd794e11e69ee5 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Fri, 10 Jun 2016 23:36:19 -0700 Subject: [PATCH] dll: fuse_intf: Write implementation --- src/dll/fuse/fuse_intf.c | 58 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/dll/fuse/fuse_intf.c b/src/dll/fuse/fuse_intf.c index 486a5163..d9831790 100644 --- a/src/dll/fuse/fuse_intf.c +++ b/src/dll/fuse/fuse_intf.c @@ -718,7 +718,63 @@ static NTSTATUS fsp_fuse_intf_Write(FSP_FILE_SYSTEM *FileSystem, BOOLEAN WriteToEndOfFile, BOOLEAN ConstrainedIo, PULONG PBytesTransferred, FSP_FSCTL_FILE_INFO *FileInfo) { - return STATUS_INVALID_DEVICE_REQUEST; + struct fuse *f = FileSystem->UserContext; + struct fsp_fuse_file_desc *filedesc = + (PVOID)(UINT_PTR)Request->Req.Write.UserContext2; + UINT32 Uid, Gid, Mode; + struct fuse_file_info fi; + FSP_FSCTL_FILE_INFO FileInfoBuf; + UINT64 EndOffset, AllocationUnit; + int bytes; + NTSTATUS Result; + + if (0 == f->ops.write) + return STATUS_INVALID_DEVICE_REQUEST; + + memset(&fi, 0, sizeof fi); + fi.flags = filedesc->OpenFlags; + fi.fh = filedesc->FileHandle; + + Result = fsp_fuse_intf_GetFileInfoEx(FileSystem, filedesc->PosixPath, &fi, + &Uid, &Gid, &Mode, &FileInfoBuf); + if (!NT_SUCCESS(Result)) + return Result; + + if (ConstrainedIo) + { + if (Offset >= FileInfoBuf.FileSize) + goto success; + EndOffset = Offset + Length; + if (EndOffset > FileInfoBuf.FileSize) + EndOffset = FileInfoBuf.FileSize; + } + else + { + if (WriteToEndOfFile) + Offset = FileInfoBuf.FileSize; + EndOffset = Offset + Length; + } + + bytes = f->ops.write(filedesc->PosixPath, Buffer, (size_t)(EndOffset - Offset), Offset, &fi); + if (0 <= bytes) + { + *PBytesTransferred = bytes; + Result = STATUS_SUCCESS; + } + else + Result = fsp_fuse_ntstatus_from_errno(f->env, bytes); + if (!NT_SUCCESS(Result)) + return Result; + +success: + AllocationUnit = f->VolumeParams.SectorSize * f->VolumeParams.SectorsPerAllocationUnit; + FileInfoBuf.FileSize = Offset + bytes; + FileInfo->AllocationSize = + (FileInfoBuf.FileSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit; + + memcpy(FileInfo, &FileInfoBuf, sizeof FileInfoBuf); + + return STATUS_SUCCESS; } static NTSTATUS fsp_fuse_intf_Flush(FSP_FILE_SYSTEM *FileSystem,