2011-08-12 13:20:12 -04:00
|
|
|
/* Copyright (c) 2010, 2011
|
2010-10-11 14:59:26 -04:00
|
|
|
* The Regents of the University of Michigan
|
|
|
|
|
* All Rights Reserved
|
2011-08-12 13:20:12 -04:00
|
|
|
*
|
|
|
|
|
* Olga Kornievskaia <aglo@umich.edu>
|
|
|
|
|
* Casey Bodley <cbodley@umich.edu>
|
2010-10-11 14:59:26 -04:00
|
|
|
*
|
|
|
|
|
* Permission is granted to use, copy and redistribute this software
|
|
|
|
|
* for noncommercial education and research purposes, so long as no
|
|
|
|
|
* fee is charged, and so long as the name of the University of Michigan
|
|
|
|
|
* is not used in any advertising or publicity pertaining to the use
|
|
|
|
|
* or distribution of this software without specific, written prior
|
|
|
|
|
* authorization. Permission to modify or otherwise create derivative
|
|
|
|
|
* works of this software is not granted.
|
|
|
|
|
*
|
|
|
|
|
* This software is provided as is, without representation or warranty
|
|
|
|
|
* of any kind either express or implied, including without limitation
|
|
|
|
|
* the implied warranties of merchantability, fitness for a particular
|
|
|
|
|
* purpose, or noninfringement. The Regents of the University of
|
|
|
|
|
* Michigan shall not be liable for any damages, including special,
|
|
|
|
|
* indirect, incidental, or consequential damages, with respect to any
|
|
|
|
|
* claim arising out of or in connection with the use of the software,
|
|
|
|
|
* even if it has been or is hereafter advised of the possibility of
|
|
|
|
|
* such damages.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Windows.h>
|
2010-10-11 16:12:20 -04:00
|
|
|
#include <strsafe.h>
|
2010-10-11 14:59:26 -04:00
|
|
|
#include <stdio.h>
|
2011-06-16 08:05:13 -04:00
|
|
|
#include <time.h>
|
2010-10-11 14:59:26 -04:00
|
|
|
|
|
|
|
|
#include "nfs41_ops.h"
|
|
|
|
|
#include "from_kernel.h"
|
|
|
|
|
#include "upcall.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "daemon_debug.h"
|
|
|
|
|
|
|
|
|
|
|
2010-10-11 16:11:27 -04:00
|
|
|
/* 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)
|
|
|
|
|
|
2011-06-16 08:05:13 -04:00
|
|
|
#define VOLUME_CACHE_EXPIRATION 20
|
|
|
|
|
|
2010-10-11 16:11:27 -04:00
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
/* NFS41_VOLUME_QUERY */
|
|
|
|
|
static int parse_volume(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
volume_upcall_args *args = &upcall->args.volume;
|
2011-04-13 20:07:37 -04:00
|
|
|
|
2010-10-11 16:11:27 -04:00
|
|
|
status = safe_read(&buffer, &length, &args->query, sizeof(FS_INFORMATION_CLASS));
|
2010-10-12 10:03:03 -04:00
|
|
|
if (status) goto out;
|
|
|
|
|
|
2011-04-13 20:07:37 -04:00
|
|
|
dprintf(1, "parsing NFS41_VOLUME_QUERY: query=%d\n", args->query);
|
2010-10-11 16:11:27 -04:00
|
|
|
out:
|
2010-10-11 14:59:26 -04:00
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-11 16:11:27 -04:00
|
|
|
static int get_volume_size_info(
|
2011-02-24 17:39:42 -08:00
|
|
|
IN nfs41_open_state *state,
|
2010-10-11 16:11:27 -04:00
|
|
|
IN const char *query,
|
|
|
|
|
OUT OPTIONAL PLONGLONG total_out,
|
|
|
|
|
OUT OPTIONAL PLONGLONG user_out,
|
|
|
|
|
OUT OPTIONAL PLONGLONG avail_out)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
nfs41_file_info info = { 0 };
|
2011-06-16 08:05:13 -04:00
|
|
|
nfs41_superblock *superblock = state->file.fh.superblock;
|
|
|
|
|
int status = ERROR_NOT_FOUND;
|
|
|
|
|
|
|
|
|
|
AcquireSRWLockShared(&superblock->lock);
|
|
|
|
|
/* check superblock for cached attributes */
|
|
|
|
|
if (time(NULL) <= superblock->cache_expiration) {
|
|
|
|
|
info.space_total = superblock->space_total;
|
|
|
|
|
info.space_avail = superblock->space_avail;
|
|
|
|
|
info.space_free = superblock->space_free;
|
|
|
|
|
status = NO_ERROR;
|
|
|
|
|
|
|
|
|
|
dprintf(2, "%s cached: %llu user, %llu free of %llu total\n",
|
|
|
|
|
query, info.space_avail, info.space_free, info.space_total);
|
|
|
|
|
}
|
|
|
|
|
ReleaseSRWLockShared(&superblock->lock);
|
2010-10-11 14:59:26 -04:00
|
|
|
|
|
|
|
|
if (status) {
|
2011-06-16 08:05:13 -04:00
|
|
|
bitmap4 attr_request = { 2, { 0, FATTR4_WORD1_SPACE_AVAIL |
|
|
|
|
|
FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL } };
|
|
|
|
|
|
|
|
|
|
/* query the space_ attributes of the filesystem */
|
|
|
|
|
status = nfs41_getattr(state->session, &state->file,
|
|
|
|
|
&attr_request, &info);
|
|
|
|
|
if (status) {
|
|
|
|
|
eprintf("nfs41_getattr() failed with %s\n",
|
|
|
|
|
nfs_error_string(status));
|
|
|
|
|
status = nfs_to_windows_error(status, ERROR_BAD_NET_RESP);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AcquireSRWLockExclusive(&superblock->lock);
|
|
|
|
|
superblock->space_total = info.space_total;
|
|
|
|
|
superblock->space_avail = info.space_avail;
|
|
|
|
|
superblock->space_free = info.space_free;
|
|
|
|
|
superblock->cache_expiration = time(NULL) + VOLUME_CACHE_EXPIRATION;
|
|
|
|
|
ReleaseSRWLockExclusive(&superblock->lock);
|
|
|
|
|
|
|
|
|
|
dprintf(2, "%s: %llu user, %llu free of %llu total\n",
|
|
|
|
|
query, info.space_avail, info.space_free, info.space_total);
|
2010-10-11 14:59:26 -04:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 16:11:27 -04:00
|
|
|
if (total_out) *total_out = TO_UNITS(info.space_total);
|
|
|
|
|
if (user_out) *user_out = TO_UNITS(info.space_avail);
|
|
|
|
|
if (avail_out) *avail_out = TO_UNITS(info.space_free);
|
2010-10-11 14:59:26 -04:00
|
|
|
out:
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-24 16:17:06 -04:00
|
|
|
static void handle_volume_attributes(
|
2011-04-13 20:07:37 -04:00
|
|
|
IN volume_upcall_args *args,
|
|
|
|
|
IN nfs41_open_state *state)
|
2010-10-11 16:12:20 -04:00
|
|
|
{
|
|
|
|
|
PFILE_FS_ATTRIBUTE_INFORMATION attr = &args->info.attribute;
|
2011-06-16 08:05:13 -04:00
|
|
|
const nfs41_superblock *superblock = state->file.fh.superblock;
|
2010-10-11 16:12:20 -04:00
|
|
|
|
2010-11-02 14:21:06 -04:00
|
|
|
attr->FileSystemAttributes = FILE_SUPPORTS_REMOTE_STORAGE;
|
2011-06-16 08:05:13 -04:00
|
|
|
if (superblock->link_support)
|
2010-11-04 11:51:26 -04:00
|
|
|
attr->FileSystemAttributes |= FILE_SUPPORTS_HARD_LINKS;
|
2011-06-16 08:05:13 -04:00
|
|
|
if (superblock->symlink_support)
|
2010-11-02 14:21:06 -04:00
|
|
|
attr->FileSystemAttributes |= FILE_SUPPORTS_REPARSE_POINTS;
|
2011-06-16 08:05:13 -04:00
|
|
|
if (superblock->case_preserving)
|
2010-10-11 16:12:20 -04:00
|
|
|
attr->FileSystemAttributes |= FILE_CASE_PRESERVED_NAMES;
|
2011-06-16 08:05:13 -04:00
|
|
|
if (!superblock->case_insensitive)
|
2010-10-11 16:12:20 -04:00
|
|
|
attr->FileSystemAttributes |= FILE_CASE_SENSITIVE_SEARCH;
|
2011-06-16 08:05:13 -04:00
|
|
|
if (superblock->aclsupport)
|
2011-03-10 12:00:22 -05:00
|
|
|
attr->FileSystemAttributes |= FILE_PERSISTENT_ACLS;
|
2010-10-11 16:12:20 -04:00
|
|
|
|
|
|
|
|
attr->MaximumComponentNameLength = NFS41_MAX_COMPONENT_LEN;
|
|
|
|
|
|
2010-10-12 09:51:06 -04:00
|
|
|
/* let the driver fill in FileSystemName/Len */
|
2010-10-11 16:12:20 -04:00
|
|
|
|
2010-10-12 09:51:06 -04:00
|
|
|
args->len = sizeof(args->info.attribute);
|
2010-10-11 16:12:20 -04:00
|
|
|
|
|
|
|
|
dprintf(2, "FileFsAttributeInformation: case_preserving %u, "
|
2010-10-12 09:51:06 -04:00
|
|
|
"case_insensitive %u, max component %u\n",
|
2011-06-16 08:05:13 -04:00
|
|
|
superblock->case_preserving, superblock->case_insensitive,
|
2010-10-12 09:51:06 -04:00
|
|
|
attr->MaximumComponentNameLength);
|
2010-10-11 16:12:20 -04:00
|
|
|
}
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
static int handle_volume(nfs41_upcall *upcall)
|
2010-10-11 16:11:27 -04:00
|
|
|
{
|
|
|
|
|
volume_upcall_args *args = &upcall->args.volume;
|
2011-08-24 16:17:06 -04:00
|
|
|
int status = NO_ERROR;
|
2010-10-11 16:11:27 -04:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2011-04-29 15:26:44 -04:00
|
|
|
status = get_volume_size_info(upcall->state_ref,
|
2011-02-24 17:39:42 -08:00
|
|
|
"FileFsSizeInformation",
|
2010-10-11 16:11:27 -04:00
|
|
|
&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;
|
|
|
|
|
|
2011-04-29 15:26:44 -04:00
|
|
|
status = get_volume_size_info(upcall->state_ref,
|
2011-02-24 17:39:42 -08:00
|
|
|
"FileFsFullSizeInformation",
|
2010-10-11 16:11:27 -04:00
|
|
|
&args->info.fullsize.TotalAllocationUnits.QuadPart,
|
|
|
|
|
&args->info.fullsize.CallerAvailableAllocationUnits.QuadPart,
|
|
|
|
|
&args->info.fullsize.ActualAvailableAllocationUnits.QuadPart);
|
|
|
|
|
break;
|
|
|
|
|
|
2010-10-11 16:12:20 -04:00
|
|
|
case FileFsAttributeInformation:
|
2011-08-24 16:17:06 -04:00
|
|
|
handle_volume_attributes(args, upcall->state_ref);
|
2010-10-11 16:12:20 -04:00
|
|
|
break;
|
|
|
|
|
|
2010-10-11 16:11:27 -04:00
|
|
|
default:
|
|
|
|
|
eprintf("unhandled fs query class %d\n", args->query);
|
|
|
|
|
status = ERROR_INVALID_PARAMETER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
static int marshall_volume(unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
volume_upcall_args *args = &upcall->args.volume;
|
|
|
|
|
|
2010-10-11 16:11:27 -04:00
|
|
|
status = safe_write(&buffer, length, &args->len, sizeof(args->len));
|
2010-10-11 14:59:26 -04:00
|
|
|
if (status) goto out;
|
2010-10-11 16:11:27 -04:00
|
|
|
status = safe_write(&buffer, length, &args->info, args->len);
|
2010-10-11 14:59:26 -04:00
|
|
|
out:
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2010-10-27 09:22:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const nfs41_upcall_op nfs41_op_volume = {
|
|
|
|
|
parse_volume,
|
|
|
|
|
handle_volume,
|
|
|
|
|
marshall_volume
|
|
|
|
|
};
|