Skip to content

Commit

Permalink
Address AllocationSize
Browse files Browse the repository at this point in the history
Turns out that FileHeader.AllocationSize is not
the AllocationSize asked for in file-standard-info
etc. We should reply based on filesize, except when
asked to prealloc in create.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Oct 18, 2023
1 parent 78e3fbc commit 9ede992
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
12 changes: 11 additions & 1 deletion include/os/windows/zfs/sys/zfs_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,18 @@ extern uint64_t zfs_blksz(znode_t *zp);
inline static uint64_t
allocationsize(struct znode *zp)
{
if (zp->z_size == 0)
if (S_ISDIR(zp->z_mode))
return (0ULL);

if (zp->z_size == 0) {
// Did they prealloc?
struct vnode *vp = ZTOV(zp);
if ((vp != NULL) &&
(vp->FileHeader.AllocationSize.QuadPart > 0ULL))
return (vp->FileHeader.AllocationSize.QuadPart);
return (0ULL);
}

return (P2ROUNDUP(zp->z_size, zfs_blksz(zp)));
}

Expand Down
42 changes: 14 additions & 28 deletions module/os/windows/zfs/zfs_vnops_windows_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,9 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,
if (tzp->z_pflags & ZFS_REPARSE)
reparse_tag = get_reparse_tag(tzp);

uint64_t AllocationSize;
AllocationSize = allocationsize(tzp);

structsize = 0; /* size of win struct desired */
/* bufptr : output memory area, incrementing */
/* outcount : amount written to output, incrementing */
Expand All @@ -892,9 +895,7 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,

eodp->FileIndex = ctx->offset;
eodp->AllocationSize.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
P2ROUNDUP(tzp->z_size,
zfs_blksz(tzp));
AllocationSize;
eodp->EndOfFile.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
tzp->z_size;
Expand Down Expand Up @@ -931,9 +932,7 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,
next_offset = &fibdi->NextEntryOffset;

fibdi->AllocationSize.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
P2ROUNDUP(tzp->z_size,
zfs_blksz(tzp));
AllocationSize;
fibdi->EndOfFile.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
tzp->z_size;
Expand Down Expand Up @@ -971,9 +970,7 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,
next_offset = &fbdi->NextEntryOffset;

fbdi->AllocationSize.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
P2ROUNDUP(tzp->z_size,
zfs_blksz(tzp));
AllocationSize;
fbdi->EndOfFile.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
tzp->z_size;
Expand Down Expand Up @@ -1011,9 +1008,7 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,
next_offset = &fdi->NextEntryOffset;

fdi->AllocationSize.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
P2ROUNDUP(tzp->z_size,
zfs_blksz(tzp));
AllocationSize;
fdi->EndOfFile.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
tzp->z_size;
Expand Down Expand Up @@ -1062,9 +1057,7 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,

fifdi->FileIndex = ctx->offset;
fifdi->AllocationSize.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
P2ROUNDUP(tzp->z_size,
zfs_blksz(tzp));
AllocationSize;
fifdi->EndOfFile.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
tzp->z_size;
Expand Down Expand Up @@ -1101,9 +1094,7 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,

fiedi->FileIndex = ctx->offset;
fiedi->AllocationSize.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
P2ROUNDUP(tzp->z_size,
zfs_blksz(tzp));
AllocationSize;
fiedi->EndOfFile.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
tzp->z_size;
Expand Down Expand Up @@ -1143,9 +1134,7 @@ zfs_readdir_emitdir(zfsvfs_t *zfsvfs, const char *name, emitdir_ptr_t *ctx,

fiebdi->FileIndex = ctx->offset;
fiebdi->AllocationSize.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
P2ROUNDUP(tzp->z_size,
zfs_blksz(tzp));
AllocationSize;
fiebdi->EndOfFile.QuadPart =
S_ISDIR(tzp->z_mode) ? 0 :
tzp->z_size;
Expand Down Expand Up @@ -4406,12 +4395,9 @@ file_standard_information_impl(PDEVICE_OBJECT DeviceObject,
if (zp != NULL) {
fsi->Directory = vnode_isdir(vp) ? TRUE : FALSE;
// sa_object_size(zp->z_sa_hdl, &blksize, &nblks);
uint64_t blk = zfs_blksz(zp);
// space taken on disk, multiples of block size

// fsi->AllocationSize.QuadPart = allocationsize(zp);
fsi->AllocationSize.QuadPart =
vp->FileHeader.AllocationSize.QuadPart;
fsi->AllocationSize.QuadPart = allocationsize(zp);
fsi->EndOfFile.QuadPart = vnode_isdir(vp) ? 0 : zp->z_size;
fsi->NumberOfLinks = zp->z_links;
fsi->DeletePending = zccb &&
Expand Down Expand Up @@ -4578,7 +4564,7 @@ file_network_open_information_impl(PDEVICE_OBJECT DeviceObject,
netopen->LastAccessTime.QuadPart);
}
netopen->AllocationSize.QuadPart =
P2ROUNDUP(zp->z_size, zfs_blksz(zp));
allocationsize(zp);
netopen->EndOfFile.QuadPart = vnode_isdir(vp) ? 0 : zp->z_size;
netopen->FileAttributes =
zfs_getwinflags(zp->z_pflags, vnode_isdir(vp));
Expand Down Expand Up @@ -4748,7 +4734,7 @@ file_stat_information(PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
fsi->FileId.QuadPart = zp->z_id;
fsi->AllocationSize.QuadPart =
P2ROUNDUP(zp->z_size, zfs_blksz(zp));
allocationsize(zp);
fsi->EndOfFile.QuadPart = zp->z_size;
fsi->FileAttributes =
zfs_getwinflags(zp->z_pflags, vnode_isdir(vp));
Expand Down Expand Up @@ -4824,7 +4810,7 @@ file_stat_lx_information(PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
fsli->FileId.QuadPart = zp->z_id;
fsli->AllocationSize.QuadPart =
P2ROUNDUP(zp->z_size, zfs_blksz(zp));
allocationsize(zp);
fsli->EndOfFile.QuadPart = zp->z_size;
fsli->FileAttributes =
zfs_getwinflags(zp->z_pflags, vnode_isdir(vp));
Expand Down

0 comments on commit 9ede992

Please sign in to comment.