pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


[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

  1. From de94936a38d949be66e1c86762850ce78e1c6e14 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Wed, 12 Mar 2025 13:01:02 +0100
  4. Subject: [PATCH 1/2] daemon,sys: Writes should automatically update
  5.  AllocationSize+EndOfFile data based on NFS attributes
  6.  
  7. Writes should update |FILE_STANDARD_INFORMATION.AllocationSize| and
  8. |FILE_STANDARD_INFORMATION.EndOfFile| data based on NFS attributes
  9. |FATTR4_WORD0_SIZE| and |FATTR4_WORD1_SPACE_USED|.
  10.  
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13. daemon/readwrite.c       | 15 +++++++++++++--
  14.  daemon/upcall.h          |  2 ++
  15.  sys/nfs41sys_driver.h    |  2 ++
  16.  sys/nfs41sys_readwrite.c | 14 ++++++++++++--
  17.  4 files changed, 29 insertions(+), 4 deletions(-)
  18.  
  19. diff --git a/daemon/readwrite.c b/daemon/readwrite.c
  20. index a474904..9cf93b8 100644
  21. --- a/daemon/readwrite.c
  22. +++ b/daemon/readwrite.c
  23. @@ -305,11 +305,14 @@ retry_write:
  24.                 status = nfs41_getattr(session, file, &attr_request, &info);
  25.                 if (status)
  26.                         goto out;
  27. -       }
  28. +        EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_SIZE));
  29. +    }
  30.  
  31.      EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_CHANGE));
  32. +    EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_SIZE));
  33.      args->ctime = info.change;
  34. -
  35. +    args->file_size = info.size;
  36. +    args->file_space_used = info.space_used;
  37.  out:
  38.      args->out_len = len;
  39.      return nfs_to_windows_error(status, ERROR_NET_WRITE_FAULT);
  40. @@ -384,6 +387,14 @@ static int marshall_rw(unsigned char *buffer, uint32_t *length, nfs41_upcall *up
  41.      status = safe_write(&buffer, length, &args->out_len, sizeof(args->out_len));
  42.      if (status) goto out;
  43.      status = safe_write(&buffer, length, &args->ctime, sizeof(args->ctime));
  44. +    if (upcall->opcode == NFS41_SYSOP_WRITE) {
  45. +        status = safe_write(&buffer, length,
  46. +            &args->file_size, sizeof(args->file_size));
  47. +        if (status) goto out;
  48. +        status = safe_write(&buffer, length,
  49. +            &args->file_space_used, sizeof(args->file_space_used));
  50. +        if (status) goto out;
  51. +    }
  52.  out:
  53.      return status;
  54.  }
  55. diff --git a/daemon/upcall.h b/daemon/upcall.h
  56. index fbed276..d611069 100644
  57. --- a/daemon/upcall.h
  58. +++ b/daemon/upcall.h
  59. @@ -84,6 +84,8 @@ typedef struct __readwrite_upcall_args {
  60.      ULONG len;
  61.      ULONG out_len;
  62.      ULONGLONG ctime;
  63. +    ULONGLONG file_size;
  64. +    ULONGLONG file_space_used;
  65.  } readwrite_upcall_args;
  66.  
  67.  typedef struct __lock_upcall_args {
  68. diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
  69. index 496387c..b1a289c 100644
  70. --- a/sys/nfs41sys_driver.h
  71. +++ b/sys/nfs41sys_driver.h
  72. @@ -199,6 +199,8 @@ typedef struct _updowncall_entry {
  73.              PMDL MdlAddress;
  74.              ULONGLONG offset;
  75.              PRX_CONTEXT rxcontext;
  76. +            ULONGLONG file_size;
  77. +            ULONGLONG file_space_used;
  78.          } ReadWrite;
  79.          struct {
  80.              LONGLONG offset;
  81. diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
  82. index 4afa8e4..960f29b 100644
  83. --- a/sys/nfs41sys_readwrite.c
  84. +++ b/sys/nfs41sys_readwrite.c
  85. @@ -168,6 +168,16 @@ NTSTATUS unmarshal_nfs41_rw(
  86.      RtlCopyMemory(&cur->buf_len, *buf, sizeof(cur->buf_len));
  87.      *buf += sizeof(cur->buf_len);
  88.      RtlCopyMemory(&cur->ChangeTime, *buf, sizeof(ULONGLONG));
  89. +    *buf += sizeof(ULONGLONG);
  90. +
  91. +    if (cur->opcode == NFS41_SYSOP_WRITE) {
  92. +        RtlCopyMemory(&cur->u.ReadWrite.file_size,
  93. +            *buf, sizeof(ULONGLONG));
  94. +        *buf += sizeof(ULONGLONG);
  95. +        RtlCopyMemory(&cur->u.ReadWrite.file_space_used,
  96. +            *buf, sizeof(ULONGLONG));
  97. +    }
  98. +
  99.  #ifdef DEBUG_MARSHAL_DETAIL_RW
  100.      DbgP("unmarshal_nfs41_rw: returned len %lu ChangeTime %llu\n",
  101.          cur->buf_len, cur->ChangeTime);
  102. @@ -402,8 +412,8 @@ NTSTATUS nfs41_Write(
  103.          InterlockedIncrement(&write.sops);
  104.          InterlockedAdd64(&write.size, entry->u.ReadWrite.len);
  105.  #endif
  106. -        nfs41_fcb->StandardInfo.EndOfFile.QuadPart = entry->buf_len +
  107. -            entry->u.ReadWrite.offset;
  108. +        nfs41_fcb->StandardInfo.AllocationSize.QuadPart = entry->u.ReadWrite.file_space_used;
  109. +        nfs41_fcb->StandardInfo.EndOfFile.QuadPart = entry->u.ReadWrite.file_size;
  110.          status = RxContext->CurrentIrp->IoStatus.Status = STATUS_SUCCESS;
  111.          RxContext->IoStatusBlock.Information = entry->buf_len;
  112.          nfs41_fcb->changeattr = entry->ChangeTime;
  113. --
  114. 2.45.1

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at