summaryrefslogtreecommitdiffhomepage
path: root/src/fs/ntapi_tt_stat.c
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 /src/fs/ntapi_tt_stat.c
parent1d3e991a03ff78741f801f88a7bd4ec541bdc99e (diff)
downloadntapi-d8b4079264a3139f35d784b873d3490b40ffbeff.tar.bz2
ntapi-d8b4079264a3139f35d784b873d3490b40ffbeff.tar.xz
{i}stat{fs} interfaces: remove fluff, require valid handle, simplify logic.
Diffstat (limited to 'src/fs/ntapi_tt_stat.c')
-rw-r--r--src/fs/ntapi_tt_stat.c64
1 files changed, 21 insertions, 43 deletions
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;