- From de94936a38d949be66e1c86762850ce78e1c6e14 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Wed, 12 Mar 2025 13:01:02 +0100
- Subject: [PATCH 1/2] daemon,sys: Writes should automatically update
- AllocationSize+EndOfFile data based on NFS attributes
- Writes should update |FILE_STANDARD_INFORMATION.AllocationSize| and
- |FILE_STANDARD_INFORMATION.EndOfFile| data based on NFS attributes
- |FATTR4_WORD0_SIZE| and |FATTR4_WORD1_SPACE_USED|.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/readwrite.c | 15 +++++++++++++--
- daemon/upcall.h | 2 ++
- sys/nfs41sys_driver.h | 2 ++
- sys/nfs41sys_readwrite.c | 14 ++++++++++++--
- 4 files changed, 29 insertions(+), 4 deletions(-)
- diff --git a/daemon/readwrite.c b/daemon/readwrite.c
- index a474904..9cf93b8 100644
- --- a/daemon/readwrite.c
- +++ b/daemon/readwrite.c
- @@ -305,11 +305,14 @@ retry_write:
- status = nfs41_getattr(session, file, &attr_request, &info);
- if (status)
- goto out;
- - }
- + EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_SIZE));
- + }
- EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_CHANGE));
- + EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_SIZE));
- args->ctime = info.change;
- -
- + args->file_size = info.size;
- + args->file_space_used = info.space_used;
- out:
- args->out_len = len;
- return nfs_to_windows_error(status, ERROR_NET_WRITE_FAULT);
- @@ -384,6 +387,14 @@ static int marshall_rw(unsigned char *buffer, uint32_t *length, nfs41_upcall *up
- status = safe_write(&buffer, length, &args->out_len, sizeof(args->out_len));
- if (status) goto out;
- status = safe_write(&buffer, length, &args->ctime, sizeof(args->ctime));
- + if (upcall->opcode == NFS41_SYSOP_WRITE) {
- + status = safe_write(&buffer, length,
- + &args->file_size, sizeof(args->file_size));
- + if (status) goto out;
- + status = safe_write(&buffer, length,
- + &args->file_space_used, sizeof(args->file_space_used));
- + if (status) goto out;
- + }
- out:
- return status;
- }
- diff --git a/daemon/upcall.h b/daemon/upcall.h
- index fbed276..d611069 100644
- --- a/daemon/upcall.h
- +++ b/daemon/upcall.h
- @@ -84,6 +84,8 @@ typedef struct __readwrite_upcall_args {
- ULONG len;
- ULONG out_len;
- ULONGLONG ctime;
- + ULONGLONG file_size;
- + ULONGLONG file_space_used;
- } readwrite_upcall_args;
- typedef struct __lock_upcall_args {
- diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
- index 496387c..b1a289c 100644
- --- a/sys/nfs41sys_driver.h
- +++ b/sys/nfs41sys_driver.h
- @@ -199,6 +199,8 @@ typedef struct _updowncall_entry {
- PMDL MdlAddress;
- ULONGLONG offset;
- PRX_CONTEXT rxcontext;
- + ULONGLONG file_size;
- + ULONGLONG file_space_used;
- } ReadWrite;
- struct {
- LONGLONG offset;
- diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
- index 4afa8e4..960f29b 100644
- --- a/sys/nfs41sys_readwrite.c
- +++ b/sys/nfs41sys_readwrite.c
- @@ -168,6 +168,16 @@ NTSTATUS unmarshal_nfs41_rw(
- RtlCopyMemory(&cur->buf_len, *buf, sizeof(cur->buf_len));
- *buf += sizeof(cur->buf_len);
- RtlCopyMemory(&cur->ChangeTime, *buf, sizeof(ULONGLONG));
- + *buf += sizeof(ULONGLONG);
- +
- + if (cur->opcode == NFS41_SYSOP_WRITE) {
- + RtlCopyMemory(&cur->u.ReadWrite.file_size,
- + *buf, sizeof(ULONGLONG));
- + *buf += sizeof(ULONGLONG);
- + RtlCopyMemory(&cur->u.ReadWrite.file_space_used,
- + *buf, sizeof(ULONGLONG));
- + }
- +
- #ifdef DEBUG_MARSHAL_DETAIL_RW
- DbgP("unmarshal_nfs41_rw: returned len %lu ChangeTime %llu\n",
- cur->buf_len, cur->ChangeTime);
- @@ -402,8 +412,8 @@ NTSTATUS nfs41_Write(
- InterlockedIncrement(&write.sops);
- InterlockedAdd64(&write.size, entry->u.ReadWrite.len);
- #endif
- - nfs41_fcb->StandardInfo.EndOfFile.QuadPart = entry->buf_len +
- - entry->u.ReadWrite.offset;
- + nfs41_fcb->StandardInfo.AllocationSize.QuadPart = entry->u.ReadWrite.file_space_used;
- + nfs41_fcb->StandardInfo.EndOfFile.QuadPart = entry->u.ReadWrite.file_size;
- status = RxContext->CurrentIrp->IoStatus.Status = STATUS_SUCCESS;
- RxContext->IoStatusBlock.Information = entry->buf_len;
- nfs41_fcb->changeattr = entry->ChangeTime;
- --
- 2.45.1
[patch] Writes should automatically update AllocationSize+EndOfFile data based on NFS attributes
Posted by Anonymous on Fri 14th Mar 2025 12:52
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.