summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-12-25 02:21:53 -0500
committermidipix <writeonce@midipix.org>2016-12-25 02:21:53 -0500
commitd8b4079264a3139f35d784b873d3490b40ffbeff (patch)
tree9d9f7e51f06167c950ca41e1c4626a37fd9b9061
parent1d3e991a03ff78741f801f88a7bd4ec541bdc99e (diff)
downloadntapi-d8b4079264a3139f35d784b873d3490b40ffbeff.tar.bz2
ntapi-d8b4079264a3139f35d784b873d3490b40ffbeff.tar.xz
{i}stat{fs} interfaces: remove fluff, require valid handle, simplify logic.
-rw-r--r--include/ntapi/nt_istat.h9
-rw-r--r--include/ntapi/nt_stat.h9
-rw-r--r--include/ntapi/nt_statfs.h9
-rw-r--r--src/fs/ntapi_tt_istat.c72
-rw-r--r--src/fs/ntapi_tt_stat.c64
-rw-r--r--src/fs/ntapi_tt_statfs.c67
-rw-r--r--src/system/ntapi_tt_get_system_directory.c7
7 files changed, 76 insertions, 161 deletions
diff --git a/include/ntapi/nt_istat.h b/include/ntapi/nt_istat.h
index 49e0f24..ade7404 100644
--- a/include/ntapi/nt_istat.h
+++ b/include/ntapi/nt_istat.h
@@ -11,7 +11,6 @@
#define NT_ISTAT_DEV_NAME_COPY 0x00000002
#define NT_ISTAT_DEV_NAME_ONLY 0x08000000
#define NT_ISTAT_MUP_DEVICE 0x20000000
-#define NT_ISTAT_NEW_HANDLE 0x80000000
typedef struct _nt_istat {
void * hfile;
@@ -28,13 +27,11 @@ typedef struct _nt_istat {
typedef int32_t __stdcall ntapi_tt_istat(
- __in void * hfile __optional,
- __in void * hroot __optional,
- __in nt_unicode_string * path __optional,
- __out nt_istat * istat,
+ __in void * hfile,
+ __out nt_istat * info,
+ __in uint32_t infolen,
__out uintptr_t * buffer,
__in uint32_t buffer_size,
- __in uint32_t open_options,
__in uint32_t flags);
diff --git a/include/ntapi/nt_stat.h b/include/ntapi/nt_stat.h
index 755ea2a..8d0fd8b 100644
--- a/include/ntapi/nt_stat.h
+++ b/include/ntapi/nt_stat.h
@@ -10,7 +10,6 @@
#define NT_STAT_COMMON (0x00000001)
#define NT_STAT_DEV_NAME_COPY (0x00000002)
#define NT_STAT_MUP_DEVICE (0x20000000)
-#define NT_STAT_NEW_HANDLE (0x80000000)
typedef struct _nt_stat {
nt_fbi fbi;
@@ -35,13 +34,11 @@ typedef struct _nt_stat {
typedef int32_t __stdcall ntapi_tt_stat(
- __in void * hfile __optional,
- __in void * hroot __optional,
- __in nt_unicode_string * path __optional,
- __out nt_stat * stat,
+ __in void * hfile,
+ __out nt_stat * info,
+ __in uint32_t infolen,
__out uintptr_t * buffer,
__in uint32_t buffer_size,
- __in uint32_t open_options,
__in uint32_t flags);
#endif
diff --git a/include/ntapi/nt_statfs.h b/include/ntapi/nt_statfs.h
index 659bffe..8ea48ee 100644
--- a/include/ntapi/nt_statfs.h
+++ b/include/ntapi/nt_statfs.h
@@ -11,7 +11,6 @@
#define NT_STATFS_VOLUME_GUID (0x00000004)
#define NT_STATFS_DOS_DRIVE_LETTER NT_STATFS_VOLUME_GUID
#define NT_STATFS_MUP_DEVICE (0x20000000)
-#define NT_STATFS_NEW_HANDLE (0x80000000)
#define NT_FS_TYPE_FAT16_NAME_HASH (0x00000000)
@@ -56,13 +55,11 @@ typedef struct _nt_statfs {
typedef int32_t __stdcall ntapi_tt_statfs(
- __in void * hfile __optional,
- __in void * hroot __optional,
- __in nt_unicode_string * path __optional,
- __out nt_statfs * statfs,
+ __in void * hfile,
+ __out nt_statfs * info,
+ __in uint32_t infolen,
__out uintptr_t * buffer,
__in uint32_t buffer_size,
__in uint32_t flags);
-
#endif
diff --git a/src/fs/ntapi_tt_istat.c b/src/fs/ntapi_tt_istat.c
index f54f8ea..83c7f9a 100644
--- a/src/fs/ntapi_tt_istat.c
+++ b/src/fs/ntapi_tt_istat.c
@@ -13,57 +13,31 @@
int32_t __stdcall __ntapi_tt_istat(
__in void * hfile,
- __in void * hroot __optional,
- __in nt_unicode_string * path,
__out nt_istat * istat,
+ __in uint32_t infolen,
__out uintptr_t * buffer,
__in uint32_t buffer_size,
- __in uint32_t open_options,
__in uint32_t flags)
{
int32_t status;
- nt_oa oa;
nt_iosb iosb;
nt_unicode_string * sdev;
wchar16_t * wch;
wchar16_t * wch_mark;
uint32_t hash;
-
- (void)flags;
+ uint32_t written;
/* validaton */
- if (!hfile && !path)
- return NT_STATUS_INVALID_PARAMETER;
-
- /* hfile */
- if (hfile) {
- istat->flags = 0;
- } else {
- /* oa */
- oa.len = sizeof(nt_oa);
- oa.root_dir = hroot;
- oa.obj_name = path;
- oa.obj_attr = 0;
- oa.sec_desc = 0;
- oa.sec_qos = 0;
-
- /* open file/folder */
- if ((status = __ntapi->zw_open_file(
- &hfile,
- NT_SEC_SYNCHRONIZE
- | NT_FILE_READ_ATTRIBUTES
- | NT_FILE_READ_ACCESS,
- &oa,
- &iosb,
- NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
- open_options | NT_FILE_SYNCHRONOUS_IO_ALERT)))
- return status;
+ if (infolen < sizeof(*istat))
+ return NT_STATUS_INFO_LENGTH_MISMATCH;
- istat->flags = NT_STAT_NEW_HANDLE;
- }
+ /* init */
+ __ntapi->tt_aligned_block_memset(
+ istat,0,sizeof(*istat));
- istat->hfile = hfile;
+ istat->hfile = hfile;
+ istat->dev_name_maxlen = infolen - sizeof(*istat);
/* file index number */
if (!(flags & NT_ISTAT_DEV_NAME_ONLY))
@@ -91,14 +65,14 @@ int32_t __stdcall __ntapi_tt_istat(
NT_OBJECT_NAME_INFORMATION,
buffer,
buffer_size,
- (uint32_t *)&iosb.info)))
+ &written)))
return status;
sdev = (nt_unicode_string *)buffer;
wch = sdev->buffer;
if (sdev->strlen < __DEVICE_PATH_PREFIX_LEN)
- return NT_STATUS_INVALID_HANDLE;
+ return NT_STATUS_NOT_SUPPORTED;
if ((wch[0] != '\\')
|| (wch[1] != 'D')
@@ -108,19 +82,21 @@ int32_t __stdcall __ntapi_tt_istat(
|| (wch[5] != 'c')
|| (wch[6] != 'e')
|| (wch[7] != '\\'))
- return NT_STATUS_INVALID_HANDLE;
+ return NT_STATUS_NOT_SUPPORTED;
if ((sdev->strlen >= __DEVICE_MUP_PREFIX_LEN)
&& (wch[8]=='M')
&& (wch[9]=='u')
&& (wch[10]=='p')
&& (wch[11]=='\\')) {
- wch_mark = &wch[12];
- hash = __DEVICE_MUP_PREFIX_HASH;
+ hash = __DEVICE_MUP_PREFIX_HASH;
istat->flags |= NT_STATFS_MUP_DEVICE;
- for (wch=wch_mark; *wch!='\\'; wch++)
- (void)0;
+ wch_mark = &wch[12];
+ wch = wch_mark;
+
+ for (; *wch!='\\'; )
+ wch++;
wch++;
} else {
wch_mark = &wch[8];
@@ -133,10 +109,10 @@ int32_t __stdcall __ntapi_tt_istat(
istat->obj_name_strlen = sdev->strlen;
istat->obj_name_maxlen = istat->dev_name_maxlen;
- istat->dev_name_strlen = (uint16_t)((wch - sdev->buffer) * sizeof(uint16_t));
+ istat->dev_name_strlen = sizeof(uint16_t) * (uint16_t)(wch - sdev->buffer);
istat->dev_name_hash = __ntapi->tt_buffer_crc32(
hash,wch_mark,
- sizeof(wchar16_t)*(wch-wch_mark));
+ sizeof(wchar16_t) * (wch - wch_mark));
if (!(flags & NT_ISTAT_DEV_NAME_COPY))
return NT_STATUS_SUCCESS;
@@ -164,12 +140,8 @@ int32_t __stdcall __ntapi_tt_validate_fs_handle(
status = __ntapi->tt_istat(
hfile,
- (void *)0,
- (nt_unicode_string *)0,
- &istat,
- buffer,
- buffer_size,
- 0,
+ &istat,sizeof(istat),
+ buffer,buffer_size,
NT_ISTAT_DEFAULT);
if (status) return status;
diff --git a/src/fs/ntapi_tt_stat.c b/src/fs/ntapi_tt_stat.c
index b7ad52d..4937067 100644
--- a/src/fs/ntapi_tt_stat.c
+++ b/src/fs/ntapi_tt_stat.c
@@ -13,55 +13,31 @@
int32_t __stdcall __ntapi_tt_stat(
__in void * hfile,
- __in void * hroot __optional,
- __in nt_unicode_string * path,
__out nt_stat * stat,
+ __in uint32_t infolen,
__out uintptr_t * buffer,
__in uint32_t buffer_size,
- __in uint32_t open_options,
__in uint32_t flags)
{
int32_t status;
- nt_oa oa;
nt_iosb iosb;
nt_unicode_string * sdev;
nt_fai * fai;
wchar16_t * wch;
wchar16_t * wch_mark;
uint32_t hash;
+ uint32_t written;
/* validation */
- if (!hfile && !path)
- return NT_STATUS_INVALID_PARAMETER;
+ if (infolen < sizeof(*stat))
+ return NT_STATUS_INFO_LENGTH_MISMATCH;
- /* hfile */
- if (hfile) {
- stat->flags = 0;
- } else {
- /* oa */
- oa.len = sizeof(nt_oa);
- oa.root_dir = hroot;
- oa.obj_name = path;
- oa.obj_attr = 0;
- oa.sec_desc = 0;
- oa.sec_qos = 0;
-
- /* open file/folder */
- if ((status = __ntapi->zw_open_file(
- &hfile,
- NT_SEC_SYNCHRONIZE
- | NT_FILE_READ_ATTRIBUTES
- | NT_FILE_READ_ACCESS,
- &oa,
- &iosb,
- NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
- open_options | NT_FILE_SYNCHRONOUS_IO_ALERT)))
- return status;
-
- stat->flags = NT_STAT_NEW_HANDLE;
- }
+ /* init */
+ __ntapi->tt_aligned_block_memset(
+ stat,0,sizeof(*stat));
- stat->hfile = hfile;
+ stat->hfile = hfile;
+ stat->dev_name_maxlen = infolen - sizeof(*stat);
/* system-unique device name */
if ((status = __ntapi->zw_query_information_file(
@@ -78,7 +54,7 @@ int32_t __stdcall __ntapi_tt_stat(
(uintptr_t *)buffer,
((size_t)(&((nt_fai *)0)->name_info)));
- /* record the file name length, but do not hash */
+ /* record volume-relative file name length */
fai = (nt_fai *)buffer;
stat->file_name_length = fai->name_info.file_name_length;
@@ -97,14 +73,14 @@ int32_t __stdcall __ntapi_tt_stat(
NT_OBJECT_NAME_INFORMATION,
buffer,
buffer_size,
- (uint32_t *)&iosb.info)))
+ &written)))
return status;
sdev = (nt_unicode_string *)buffer;
wch = sdev->buffer;
if (sdev->strlen < __DEVICE_PATH_PREFIX_LEN)
- return NT_STATUS_INVALID_HANDLE;
+ return NT_STATUS_NOT_SUPPORTED;
if ((wch[0] != '\\')
|| (wch[1] != 'D')
@@ -114,19 +90,21 @@ int32_t __stdcall __ntapi_tt_stat(
|| (wch[5] != 'c')
|| (wch[6] != 'e')
|| (wch[7] != '\\'))
- return NT_STATUS_INVALID_HANDLE;
+ return NT_STATUS_NOT_SUPPORTED;
if ((sdev->strlen >= __DEVICE_MUP_PREFIX_LEN)
&& (wch[8]=='M')
&& (wch[9]=='u')
&& (wch[10]=='p')
&& (wch[11]=='\\')) {
- wch_mark = &wch[12];
- hash = __DEVICE_MUP_PREFIX_HASH;
+ hash = __DEVICE_MUP_PREFIX_HASH;
stat->flags |= NT_STAT_MUP_DEVICE;
- for (wch=wch_mark; *wch!='\\'; wch++)
- (void)0;
+ wch_mark = &wch[12];
+ wch = wch_mark;
+
+ for (; *wch!='\\'; )
+ wch++;
wch++;
} else {
wch_mark = &wch[8];
@@ -139,10 +117,10 @@ int32_t __stdcall __ntapi_tt_stat(
stat->obj_name_strlen = sdev->strlen;
stat->obj_name_maxlen = stat->dev_name_maxlen;
- stat->dev_name_strlen = (uint16_t)((wch - sdev->buffer) * sizeof(uint16_t));
+ stat->dev_name_strlen = sizeof(uint16_t) * (uint16_t)(wch - sdev->buffer);
stat->dev_name_hash = __ntapi->tt_buffer_crc32(
hash,wch_mark,
- sizeof(wchar16_t)*(wch-wch_mark));
+ sizeof(wchar16_t) * (wch - wch_mark));
if (!(flags & NT_STAT_DEV_NAME_COPY))
return NT_STATUS_SUCCESS;
diff --git a/src/fs/ntapi_tt_statfs.c b/src/fs/ntapi_tt_statfs.c
index 450d2bc..21785fd 100644
--- a/src/fs/ntapi_tt_statfs.c
+++ b/src/fs/ntapi_tt_statfs.c
@@ -12,15 +12,13 @@
int32_t __stdcall __ntapi_tt_statfs(
__in void * hfile,
- __in void * hroot __optional,
- __in nt_unicode_string * path,
__out nt_statfs * statfs,
+ __in uint32_t infolen,
__out uintptr_t * buffer,
__in uint32_t buffer_size,
__in uint32_t flags)
{
int32_t status;
- nt_oa oa;
nt_iosb iosb;
nt_unicode_string * sdev;
wchar16_t * wch;
@@ -33,39 +31,18 @@ int32_t __stdcall __ntapi_tt_statfs(
nt_fsfsi * fsfsi;
uint32_t * fsid;
uint64_t * pguid;
+ uint32_t written;
/* validation */
- if (!hfile && !path)
- return NT_STATUS_INVALID_HANDLE;
+ if (infolen < sizeof(*statfs))
+ return NT_STATUS_INFO_LENGTH_MISMATCH;
- /* hfile */
- if (hfile) {
- statfs->flags = 0;
- } else {
- /* oa */
- oa.len = sizeof(nt_oa);
- oa.root_dir = hroot;
- oa.obj_name = path;
- oa.obj_attr = 0;
- oa.sec_desc = 0;
- oa.sec_qos = 0;
-
- /* open file/folder */
- if ((status = __ntapi->zw_open_file(
- &hfile,
- NT_SEC_SYNCHRONIZE
- | NT_FILE_READ_ATTRIBUTES
- | NT_FILE_READ_ACCESS,
- &oa,
- &iosb,
- NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
- NT_FILE_SYNCHRONOUS_IO_ALERT)))
- return status;
-
- statfs->flags = NT_STATFS_NEW_HANDLE;
- }
+ /* init */
+ __ntapi->tt_aligned_block_memset(
+ statfs,0,sizeof(*statfs));
- statfs->hfile = hfile;
+ statfs->hfile = hfile;
+ statfs->dev_name_maxlen = infolen - sizeof(*statfs);
/* maximum component length, file system type */
if ((status = __ntapi->zw_query_volume_information_file(
@@ -81,8 +58,7 @@ int32_t __stdcall __ntapi_tt_statfs(
statfs->f_namelen = fsai->maximum_component_name_length;
statfs->nt_fstype_hash = __ntapi->tt_buffer_crc32(
- 0,
- &fsai->file_system_name,
+ 0,&fsai->file_system_name,
fsai->file_system_name_length);
/* max files per volume */
@@ -121,7 +97,7 @@ int32_t __stdcall __ntapi_tt_statfs(
NT_FILE_FS_FULL_SIZE_INFORMATION)))
return status;
- fsfsi = (nt_fsfsi *)buffer;
+ fsfsi = (nt_fsfsi *)buffer;
statfs->f_blocks = fsfsi->total_allocation_units.quad;
statfs->f_bfree = fsfsi->actual_available_allocation_units.quad;
statfs->f_bavail = fsfsi->caller_available_allocation_units.quad;
@@ -134,14 +110,14 @@ int32_t __stdcall __ntapi_tt_statfs(
NT_OBJECT_NAME_INFORMATION,
buffer,
buffer_size,
- (uint32_t *)&iosb.info)))
+ &written)))
return status;
sdev = (nt_unicode_string *)buffer;
wch = sdev->buffer;
if (sdev->strlen < __DEVICE_PATH_PREFIX_LEN)
- return NT_STATUS_INVALID_HANDLE;
+ return NT_STATUS_NOT_SUPPORTED;
if ((wch[0] != '\\')
|| (wch[1] != 'D')
@@ -151,7 +127,7 @@ int32_t __stdcall __ntapi_tt_statfs(
|| (wch[5] != 'c')
|| (wch[6] != 'e')
|| (wch[7] != '\\'))
- return NT_STATUS_INVALID_HANDLE;
+ return NT_STATUS_NOT_SUPPORTED;
if (sdev->strlen < __DEVICE_MUP_PREFIX_LEN)
return NT_STATUS_INVALID_HANDLE;
@@ -160,15 +136,16 @@ int32_t __stdcall __ntapi_tt_statfs(
&& (wch[9]=='u')
&& (wch[10]=='p')
&& (wch[11]=='\\')) {
- flags &= ~NT_STATFS_VOLUME_GUID;
+ statfs->nt_drive_letter = 0;
+ hash = __DEVICE_MUP_PREFIX_HASH;
+ flags &= ~NT_STATFS_VOLUME_GUID;
statfs->flags |= NT_STATFS_MUP_DEVICE;
- hash = __DEVICE_MUP_PREFIX_HASH;
wch_mark = &wch[12];
- statfs->nt_drive_letter = 0;
+ wch = wch_mark;
- for (wch=wch_mark; *wch!='\\'; wch++)
- (void)0;
+ for (; *wch!='\\'; )
+ wch++;
wch++;
} else {
wch_mark = &wch[8];
@@ -181,10 +158,10 @@ int32_t __stdcall __ntapi_tt_statfs(
statfs->obj_name_strlen = sdev->strlen;
statfs->obj_name_maxlen = statfs->dev_name_maxlen;
- statfs->dev_name_strlen = (uint16_t)((wch - sdev->buffer) * sizeof(uint16_t));
+ statfs->dev_name_strlen = sizeof(uint16_t) * (uint16_t)(wch - sdev->buffer);
statfs->dev_name_hash = __ntapi->tt_buffer_crc32(
hash,wch_mark,
- sizeof(wchar16_t)*(wch-wch_mark));
+ sizeof(wchar16_t) * (wch - wch_mark));
/* device name */
if (!(flags & NT_STATFS_DEV_NAME_COPY))
diff --git a/src/system/ntapi_tt_get_system_directory.c b/src/system/ntapi_tt_get_system_directory.c
index 713826e..4242815 100644
--- a/src/system/ntapi_tt_get_system_directory.c
+++ b/src/system/ntapi_tt_get_system_directory.c
@@ -181,11 +181,8 @@ int32_t __stdcall __ntapi_tt_get_system_directory_dos_path(
/* statfs */
status = __ntapi->tt_statfs(
hsysdir,
- (void *)0,
- (nt_unicode_string *)0,
- &statfs,
- (uintptr_t *)buffer,
- buffer_size,
+ &statfs,sizeof(statfs),
+ (uintptr_t *)buffer,buffer_size,
NT_STATFS_DOS_DRIVE_LETTER);
if (status != NT_STATUS_SUCCESS)