volume: daemon handles new generic volume size upcall
added FS_INFORMATION_CLASS, FILE_FS_SIZE_INFORMATION, FILE_FS_FULL_SIZE_INFORMATION to from_kernel.h moved get_volume_size_info() and byte->unit conversion up to the daemon Signed-off-by: Casey Bodley <cbodley@umich.edu>
This commit is contained in:
parent
b9e8c7f8b2
commit
c13ed30b9a
3 changed files with 104 additions and 17 deletions
|
|
@ -192,4 +192,35 @@ typedef struct _FILE_LINK_INFORMATION {
|
||||||
WCHAR FileName[1];
|
WCHAR FileName[1];
|
||||||
} FILE_LINK_INFORMATION, *PFILE_LINK_INFORMATION;
|
} FILE_LINK_INFORMATION, *PFILE_LINK_INFORMATION;
|
||||||
|
|
||||||
|
/* wdm.h */
|
||||||
|
typedef enum _FSINFOCLASS {
|
||||||
|
FileFsVolumeInformation = 1,
|
||||||
|
FileFsLabelInformation, // 2
|
||||||
|
FileFsSizeInformation, // 3
|
||||||
|
FileFsDeviceInformation, // 4
|
||||||
|
FileFsAttributeInformation, // 5
|
||||||
|
FileFsControlInformation, // 6
|
||||||
|
FileFsFullSizeInformation, // 7
|
||||||
|
FileFsObjectIdInformation, // 8
|
||||||
|
FileFsDriverPathInformation, // 9
|
||||||
|
FileFsVolumeFlagsInformation,// 10
|
||||||
|
FileFsMaximumInformation
|
||||||
|
} FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
|
||||||
|
|
||||||
|
/* ntddk.h */
|
||||||
|
typedef struct _FILE_FS_SIZE_INFORMATION {
|
||||||
|
LARGE_INTEGER TotalAllocationUnits;
|
||||||
|
LARGE_INTEGER AvailableAllocationUnits;
|
||||||
|
ULONG SectorsPerAllocationUnit;
|
||||||
|
ULONG BytesPerSector;
|
||||||
|
} FILE_FS_SIZE_INFORMATION, *PFILE_FS_SIZE_INFORMATION;
|
||||||
|
|
||||||
|
typedef struct _FILE_FS_FULL_SIZE_INFORMATION {
|
||||||
|
LARGE_INTEGER TotalAllocationUnits;
|
||||||
|
LARGE_INTEGER CallerAvailableAllocationUnits;
|
||||||
|
LARGE_INTEGER ActualAvailableAllocationUnits;
|
||||||
|
ULONG SectorsPerAllocationUnit;
|
||||||
|
ULONG BytesPerSector;
|
||||||
|
} FILE_FS_FULL_SIZE_INFORMATION, *PFILE_FS_FULL_SIZE_INFORMATION;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#define __NFS41_DAEMON_UPCALL_H__
|
#define __NFS41_DAEMON_UPCALL_H__
|
||||||
|
|
||||||
#include "nfs41_ops.h"
|
#include "nfs41_ops.h"
|
||||||
|
#include "from_kernel.h"
|
||||||
|
|
||||||
|
|
||||||
/* structures for upcall arguments */
|
/* structures for upcall arguments */
|
||||||
|
|
@ -134,9 +135,12 @@ typedef struct __readdir_upcall_args {
|
||||||
|
|
||||||
typedef struct __volume_upcall_args {
|
typedef struct __volume_upcall_args {
|
||||||
nfs41_root *root;
|
nfs41_root *root;
|
||||||
ULONGLONG total;
|
FS_INFORMATION_CLASS query;
|
||||||
ULONGLONG user;
|
int len;
|
||||||
ULONGLONG avail;
|
union {
|
||||||
|
FILE_FS_SIZE_INFORMATION size;
|
||||||
|
FILE_FS_FULL_SIZE_INFORMATION fullsize;
|
||||||
|
} info;
|
||||||
} volume_upcall_args;
|
} volume_upcall_args;
|
||||||
|
|
||||||
typedef union __upcall_args {
|
typedef union __upcall_args {
|
||||||
|
|
|
||||||
|
|
@ -31,30 +31,46 @@
|
||||||
#include "daemon_debug.h"
|
#include "daemon_debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* windows volume queries want size in 'units', so we have to
|
||||||
|
* convert the nfs space_* attributes from bytes to units */
|
||||||
|
#define SECTORS_PER_UNIT 8
|
||||||
|
#define BYTES_PER_SECTOR 512
|
||||||
|
#define BYTES_PER_UNIT (SECTORS_PER_UNIT * BYTES_PER_SECTOR)
|
||||||
|
|
||||||
|
#define TO_UNITS(bytes) (bytes / BYTES_PER_UNIT)
|
||||||
|
|
||||||
|
|
||||||
int parse_volume(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
|
int parse_volume(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
volume_upcall_args *args = &upcall->args.volume;
|
volume_upcall_args *args = &upcall->args.volume;
|
||||||
status = safe_read(&buffer, &length, &args->root, sizeof(HANDLE));
|
status = safe_read(&buffer, &length, &args->root, sizeof(HANDLE));
|
||||||
|
if (status) goto out;
|
||||||
|
status = safe_read(&buffer, &length, &args->query, sizeof(FS_INFORMATION_CLASS));
|
||||||
|
out:
|
||||||
if (status)
|
if (status)
|
||||||
eprintf("parsing NFS41_VOLUME_QUERY failed with %d\n",
|
eprintf("parsing NFS41_VOLUME_QUERY failed with %d\n",
|
||||||
status);
|
status);
|
||||||
else
|
else
|
||||||
dprintf(1, "parsing NFS41_VOLUME_QUERY: root=0x%p\n", args->root);
|
dprintf(1, "parsing NFS41_VOLUME_QUERY: root=0x%p, query=%d\n",
|
||||||
|
args->root, args->query);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_volume(nfs41_upcall *upcall)
|
static int get_volume_size_info(
|
||||||
|
IN nfs41_session *session,
|
||||||
|
IN const char *query,
|
||||||
|
OUT OPTIONAL PLONGLONG total_out,
|
||||||
|
OUT OPTIONAL PLONGLONG user_out,
|
||||||
|
OUT OPTIONAL PLONGLONG avail_out)
|
||||||
{
|
{
|
||||||
nfs41_file_info info = { 0 };
|
nfs41_file_info info = { 0 };
|
||||||
bitmap4 attr_request = { 2, { 0, FATTR4_WORD1_SPACE_AVAIL |
|
bitmap4 attr_request = { 2, { 0, FATTR4_WORD1_SPACE_AVAIL |
|
||||||
FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL } };
|
FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL } };
|
||||||
volume_upcall_args *args = &upcall->args.volume;
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
/* query the space_ attributes of the root filesystem */
|
/* query the space_ attributes of the root filesystem */
|
||||||
status = nfs41_getattr(nfs41_root_session(args->root),
|
status = nfs41_getattr(session, NULL, &attr_request, &info);
|
||||||
NULL, &attr_request, &info);
|
|
||||||
if (status) {
|
if (status) {
|
||||||
eprintf("nfs41_getattr() failed with %s\n",
|
eprintf("nfs41_getattr() failed with %s\n",
|
||||||
nfs_error_string(status));
|
nfs_error_string(status));
|
||||||
|
|
@ -62,25 +78,61 @@ int handle_volume(nfs41_upcall *upcall)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
args->total = info.space_total; /* total disk space in bytes */
|
dprintf(2, "%s: %llu user, %llu free of %llu total\n", query,
|
||||||
args->user = info.space_avail; /* bytes available to this user */
|
info.space_avail, info.space_free, info.space_total);
|
||||||
args->avail = info.space_free; /* free disk space in bytes */
|
|
||||||
dprintf(2, "Volume: %llu user, %llu free of %llu total\n",
|
if (total_out) *total_out = TO_UNITS(info.space_total);
|
||||||
args->user, args->avail, args->total);
|
if (user_out) *user_out = TO_UNITS(info.space_avail);
|
||||||
|
if (avail_out) *avail_out = TO_UNITS(info.space_free);
|
||||||
out:
|
out:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int handle_volume(nfs41_upcall *upcall)
|
||||||
|
{
|
||||||
|
volume_upcall_args *args = &upcall->args.volume;
|
||||||
|
nfs41_session *session = nfs41_root_session(args->root);
|
||||||
|
int status;
|
||||||
|
|
||||||
|
switch (args->query) {
|
||||||
|
case FileFsSizeInformation:
|
||||||
|
args->len = sizeof(args->info.size);
|
||||||
|
args->info.size.SectorsPerAllocationUnit = SECTORS_PER_UNIT;
|
||||||
|
args->info.size.BytesPerSector = BYTES_PER_SECTOR;
|
||||||
|
|
||||||
|
status = get_volume_size_info(session, "FileFsSizeInformation",
|
||||||
|
&args->info.size.TotalAllocationUnits.QuadPart,
|
||||||
|
&args->info.size.AvailableAllocationUnits.QuadPart,
|
||||||
|
NULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FileFsFullSizeInformation:
|
||||||
|
args->len = sizeof(args->info.fullsize);
|
||||||
|
args->info.fullsize.SectorsPerAllocationUnit = SECTORS_PER_UNIT;
|
||||||
|
args->info.fullsize.BytesPerSector = BYTES_PER_SECTOR;
|
||||||
|
|
||||||
|
status = get_volume_size_info(session, "FileFsFullSizeInformation",
|
||||||
|
&args->info.fullsize.TotalAllocationUnits.QuadPart,
|
||||||
|
&args->info.fullsize.CallerAvailableAllocationUnits.QuadPart,
|
||||||
|
&args->info.fullsize.ActualAvailableAllocationUnits.QuadPart);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
eprintf("unhandled fs query class %d\n", args->query);
|
||||||
|
status = ERROR_INVALID_PARAMETER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
int marshall_volume(unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
|
int marshall_volume(unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
volume_upcall_args *args = &upcall->args.volume;
|
volume_upcall_args *args = &upcall->args.volume;
|
||||||
|
|
||||||
status = safe_write(&buffer, length, &args->total, sizeof(args->total));
|
status = safe_write(&buffer, length, &args->len, sizeof(args->len));
|
||||||
if (status) goto out;
|
if (status) goto out;
|
||||||
status = safe_write(&buffer, length, &args->user, sizeof(args->user));
|
status = safe_write(&buffer, length, &args->info, args->len);
|
||||||
if (status) goto out;
|
|
||||||
status = safe_write(&buffer, length, &args->avail, sizeof(args->avail));
|
|
||||||
out:
|
out:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue