ReactOS  0.4.12-dev-14-gd0c8636
volume.c File Reference
#include <windows.h>
#include <strsafe.h>
#include <stdio.h>
#include <time.h>
#include "nfs41_ops.h"
#include "from_kernel.h"
#include "upcall.h"
#include "util.h"
#include "daemon_debug.h"
Include dependency graph for volume.c:

Go to the source code of this file.

Macros

#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)
 
#define VOLUME_CACHE_EXPIRATION   20
 

Functions

static int parse_volume (unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
 
static int get_volume_size_info (IN nfs41_open_state *state, IN const char *query, OUT OPTIONAL PLONGLONG total_out, OUT OPTIONAL PLONGLONG user_out, OUT OPTIONAL PLONGLONG avail_out)
 
static int handle_volume (nfs41_upcall *upcall)
 
static int marshall_volume (unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
 

Variables

const nfs41_upcall_op nfs41_op_volume
 

Macro Definition Documentation

◆ BYTES_PER_SECTOR

#define BYTES_PER_SECTOR   512

Definition at line 37 of file volume.c.

Referenced by handle_volume().

◆ BYTES_PER_UNIT

#define BYTES_PER_UNIT   (SECTORS_PER_UNIT * BYTES_PER_SECTOR)

Definition at line 38 of file volume.c.

◆ SECTORS_PER_UNIT

#define SECTORS_PER_UNIT   8

Definition at line 36 of file volume.c.

Referenced by handle_volume().

◆ TO_UNITS

#define TO_UNITS (   bytes)    (bytes / BYTES_PER_UNIT)

Definition at line 40 of file volume.c.

Referenced by get_volume_size_info().

◆ VOLUME_CACHE_EXPIRATION

#define VOLUME_CACHE_EXPIRATION   20

Definition at line 42 of file volume.c.

Referenced by get_volume_size_info().

Function Documentation

◆ get_volume_size_info()

static int get_volume_size_info ( IN nfs41_open_state state,
IN const char query,
OUT OPTIONAL PLONGLONG  total_out,
OUT OPTIONAL PLONGLONG  user_out,
OUT OPTIONAL PLONGLONG  avail_out 
)
static

Definition at line 59 of file volume.c.

Referenced by handle_volume().

65 {
66  nfs41_file_info info = { 0 };
67  nfs41_superblock *superblock = state->file.fh.superblock;
68  int status = ERROR_NOT_FOUND;
69 
70  AcquireSRWLockShared(&superblock->lock);
71  /* check superblock for cached attributes */
72  if (time(NULL) <= superblock->cache_expiration) {
73  info.space_total = superblock->space_total;
74  info.space_avail = superblock->space_avail;
75  info.space_free = superblock->space_free;
76  status = NO_ERROR;
77 
78  dprintf(2, "%s cached: %llu user, %llu free of %llu total\n",
79  query, info.space_avail, info.space_free, info.space_total);
80  }
81  ReleaseSRWLockShared(&superblock->lock);
82 
83  if (status) {
84  bitmap4 attr_request = { 2, { 0, FATTR4_WORD1_SPACE_AVAIL |
86 
87  /* query the space_ attributes of the filesystem */
88  status = nfs41_getattr(state->session, &state->file,
89  &attr_request, &info);
90  if (status) {
91  eprintf("nfs41_getattr() failed with %s\n",
92  nfs_error_string(status));
93  status = nfs_to_windows_error(status, ERROR_BAD_NET_RESP);
94  goto out;
95  }
96 
97  AcquireSRWLockExclusive(&superblock->lock);
98  superblock->space_total = info.space_total;
99  superblock->space_avail = info.space_avail;
100  superblock->space_free = info.space_free;
102  ReleaseSRWLockExclusive(&superblock->lock);
103 
104  dprintf(2, "%s: %llu user, %llu free of %llu total\n",
105  query, info.space_avail, info.space_free, info.space_total);
106  }
107 
108  if (total_out) *total_out = TO_UNITS(info.space_total);
109  if (user_out) *user_out = TO_UNITS(info.space_avail);
110  if (avail_out) *avail_out = TO_UNITS(info.space_free);
111 out:
112  return status;
113 }
VOID WINAPI AcquireSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:54
uint64_t space_avail
Definition: nfs41_types.h:224
#define TO_UNITS(bytes)
Definition: volume.c:40
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
#define VOLUME_CACHE_EXPIRATION
Definition: volume.c:42
SRWLOCK lock
Definition: nfs41.h:65
uint64_t space_free
Definition: nfs41.h:61
uint64_t space_total
Definition: nfs41.h:62
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
__u16 time
Definition: mkdosfs.c:366
#define NO_ERROR
Definition: dderror.h:5
uint64_t space_free
Definition: nfs41_types.h:225
#define ERROR_BAD_NET_RESP
Definition: winerror.h:150
#define dprintf
Definition: regdump.c:33
smooth NULL
Definition: ftsmooth.c:416
int nfs41_getattr(IN nfs41_session *session, IN OPTIONAL nfs41_path_fh *file, IN bitmap4 *attr_request, OUT nfs41_file_info *info)
Definition: nfs41_ops.c:1063
static FILE * out
Definition: regtests2xml.c:44
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
uint64_t space_total
Definition: nfs41_types.h:226
static int state
Definition: maze.c:121
VOID WINAPI ReleaseSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:82
#define ERROR_NOT_FOUND
Definition: winerror.h:690
time_t cache_expiration
Definition: nfs41.h:63
uint64_t space_avail
Definition: nfs41.h:60
static SERVICE_STATUS status
Definition: service.c:31
VOID WINAPI AcquireSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:61
VOID WINAPI ReleaseSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:89
Definition: ps.c:97

◆ handle_volume()

static int handle_volume ( nfs41_upcall upcall)
static

Definition at line 115 of file volume.c.

116 {
117  volume_upcall_args *args = &upcall->args.volume;
118  int status = NO_ERROR;
119 
120  switch (args->query) {
122  args->len = sizeof(args->info.size);
125 
126  status = get_volume_size_info(upcall->state_ref,
127  "FileFsSizeInformation",
130  NULL);
131  break;
132 
134  args->len = sizeof(args->info.fullsize);
137 
138  status = get_volume_size_info(upcall->state_ref,
139  "FileFsFullSizeInformation",
143  break;
144 
146  args->len = sizeof(args->info.attribute);
148  &args->info.attribute);
149  break;
150 
151  default:
152  eprintf("unhandled fs query class %d\n", args->query);
153  status = ERROR_INVALID_PARAMETER;
154  break;
155  }
156  return status;
157 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:263
volume_upcall_args volume
Definition: upcall.h:188
struct __nfs41_superblock * superblock
Definition: nfs41_types.h:56
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
union __volume_upcall_args::@45 info
#define NO_ERROR
Definition: dderror.h:5
Definition: match.c:390
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
static int get_volume_size_info(IN nfs41_open_state *state, IN const char *query, OUT OPTIONAL PLONGLONG total_out, OUT OPTIONAL PLONGLONG user_out, OUT OPTIONAL PLONGLONG avail_out)
Definition: volume.c:59
nfs41_open_state * state_ref
Definition: upcall.h:207
FILE_FS_SIZE_INFORMATION size
Definition: upcall.h:157
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
smooth NULL
Definition: ftsmooth.c:416
#define BYTES_PER_SECTOR
Definition: volume.c:37
upcall_args args
Definition: upcall.h:198
#define SECTORS_PER_UNIT
Definition: volume.c:36
nfs41_path_fh file
Definition: nfs41.h:130
FS_INFORMATION_CLASS query
Definition: upcall.h:154
FILE_FS_ATTRIBUTE_INFORMATION attribute
Definition: upcall.h:159
void nfs41_superblock_fs_attributes(IN const nfs41_superblock *superblock, OUT struct _FILE_FS_ATTRIBUTE_INFORMATION *FsAttrs)
static SERVICE_STATUS status
Definition: service.c:31
LARGE_INTEGER CallerAvailableAllocationUnits
Definition: from_kernel.h:271
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:270
LONGLONG QuadPart
Definition: typedefs.h:112
FILE_FS_FULL_SIZE_INFORMATION fullsize
Definition: upcall.h:158
Definition: ps.c:97

◆ marshall_volume()

static int marshall_volume ( unsigned char buffer,
uint32_t length,
nfs41_upcall upcall 
)
static

Definition at line 159 of file volume.c.

160 {
161  int status;
162  volume_upcall_args *args = &upcall->args.volume;
163 
164  status = safe_write(&buffer, length, &args->len, sizeof(args->len));
165  if (status) goto out;
166  status = safe_write(&buffer, length, &args->info, args->len);
167 out:
168  return status;
169 }
volume_upcall_args volume
Definition: upcall.h:188
GLuint buffer
Definition: glext.h:5915
union __volume_upcall_args::@45 info
Definition: match.c:390
upcall_args args
Definition: upcall.h:198
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static FILE * out
Definition: regtests2xml.c:44
int safe_write(unsigned char **pos, uint32_t *remaining, void *src, uint32_t src_len)
Definition: util.c:44
static SERVICE_STATUS status
Definition: service.c:31

◆ parse_volume()

static int parse_volume ( unsigned char buffer,
uint32_t  length,
nfs41_upcall upcall 
)
static

Definition at line 46 of file volume.c.

47 {
48  int status;
49  volume_upcall_args *args = &upcall->args.volume;
50 
51  status = safe_read(&buffer, &length, &args->query, sizeof(FS_INFORMATION_CLASS));
52  if (status) goto out;
53 
54  dprintf(1, "parsing NFS41_VOLUME_QUERY: query=%d\n", args->query);
55 out:
56  return status;
57 }
volume_upcall_args volume
Definition: upcall.h:188
GLuint buffer
Definition: glext.h:5915
Definition: match.c:390
#define dprintf
Definition: regdump.c:33
enum _FSINFOCLASS FS_INFORMATION_CLASS
upcall_args args
Definition: upcall.h:198
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static FILE * out
Definition: regtests2xml.c:44
FS_INFORMATION_CLASS query
Definition: upcall.h:154
int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
Definition: util.c:33
static SERVICE_STATUS status
Definition: service.c:31

Variable Documentation

◆ nfs41_op_volume

const nfs41_upcall_op nfs41_op_volume
Initial value:
= {
}
static int handle_volume(nfs41_upcall *upcall)
Definition: volume.c:115
static int marshall_volume(unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
Definition: volume.c:159
static int parse_volume(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
Definition: volume.c:46

Definition at line 172 of file volume.c.