summaryrefslogtreecommitdiffhomepage
path: root/src/fs
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-12-23 04:18:04 -0500
committermidipix <writeonce@midipix.org>2016-12-23 04:36:59 -0500
commit921d0b1fefd3e44a3109bb03a15ad6511dd21b32 (patch)
tree453168b80379f3d442fe428d5bbe1cc640db8163 /src/fs
parent0cd9efed201a9e7ac7dd263977d8b045c82f2c35 (diff)
downloadntapi-921d0b1fefd3e44a3109bb03a15ad6511dd21b32.tar.bz2
ntapi-921d0b1fefd3e44a3109bb03a15ad6511dd21b32.tar.xz
__ntapi_tt_stat(): clean-up, simplify logic.
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/ntapi_tt_stat.c86
1 files changed, 42 insertions, 44 deletions
diff --git a/src/fs/ntapi_tt_stat.c b/src/fs/ntapi_tt_stat.c
index 9ad9975..f6b5849 100644
--- a/src/fs/ntapi_tt_stat.c
+++ b/src/fs/ntapi_tt_stat.c
@@ -32,10 +32,12 @@ int32_t __stdcall __ntapi_tt_stat(
/* validation */
if (!hfile && !path)
- return NT_STATUS_INVALID_HANDLE;
+ return NT_STATUS_INVALID_PARAMETER;
/* hfile */
- if (!hfile) {
+ if (hfile) {
+ stat->flags = 0;
+ } else {
/* oa */
oa.len = sizeof(nt_oa);
oa.root_dir = hroot;
@@ -45,55 +47,50 @@ int32_t __stdcall __ntapi_tt_stat(
oa.sec_qos = 0;
/* open file/folder */
- 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);
-
- if (status != NT_STATUS_SUCCESS)
+ 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_out = NT_STAT_NEW_HANDLE;
+ stat->flags = NT_STAT_NEW_HANDLE;
}
- stat->hfile = hfile;
- stat->flags_in = flags;
+ stat->hfile = hfile;
/* system-unique device name */
- status = __ntapi->zw_query_information_file(
- hfile,
- &iosb,
- buffer,
- buffer_size,
- NT_FILE_ALL_INFORMATION);
-
- if (status != NT_STATUS_SUCCESS)
+ if ((status = __ntapi->zw_query_information_file(
+ hfile,
+ &iosb,
+ buffer,
+ buffer_size,
+ NT_FILE_ALL_INFORMATION)))
return status;
/* copy file info minus name */
- fai = (nt_fai *)buffer;
__ntapi->tt_aligned_block_memcpy(
(uintptr_t *)stat,
- (uintptr_t *)fai,
+ (uintptr_t *)buffer,
((size_t)(&((nt_fai *)0)->name_info)));
/* record the file name length, but do not hash */
+ fai = (nt_fai *)buffer;
stat->file_name_length = fai->name_info.file_name_length;
stat->file_name_hash = 0;
/* file system size information */
- status = __ntapi->zw_query_volume_information_file(
- hfile,
- &iosb,
- &(stat->fssi),
- sizeof(stat->fssi),
- NT_FILE_FS_SIZE_INFORMATION);
-
- if (status != NT_STATUS_SUCCESS)
+ if ((status = __ntapi->zw_query_volume_information_file(
+ hfile,
+ &iosb,
+ &(stat->fssi),
+ sizeof(stat->fssi),
+ NT_FILE_FS_SIZE_INFORMATION)))
return status;
/* system-unique device name */
@@ -126,9 +123,9 @@ int32_t __stdcall __ntapi_tt_stat(
&& (wch[9]=='u')
&& (wch[10]=='p')
&& (wch[11]=='\\')) {
- stat->flags_out |= NT_STAT_MUP_DEVICE;
wch_mark = &wch[12];
hash = __DEVICE_MUP_PREFIX_HASH;
+ stat->flags |= NT_STAT_MUP_DEVICE;
} else {
wch_mark = &wch[8];
hash = __DEVICE_PATH_PREFIX_HASH;
@@ -142,17 +139,18 @@ int32_t __stdcall __ntapi_tt_stat(
hash,wch_mark,
sizeof(wchar16_t)*(wch-wch_mark));
- if (flags & NT_STAT_DEV_NAME_COPY) {
- if (stat->dev_name_maxlen < sdev->strlen)
- /* does not justify failure */
- *stat->dev_name = 0;
- else
- __ntapi->tt_memcpy_utf16(
- (wchar16_t *)stat->dev_name,
- (wchar16_t *)sdev->buffer,
- stat->dev_name_strlen);
- } else
+ if (!(flags & NT_STAT_DEV_NAME_COPY)) {
*stat->dev_name = 0;
+ return NT_STATUS_SUCCESS;
+ } else if (stat->dev_name_maxlen < sdev->strlen) {
+ *stat->dev_name = 0;
+ return NT_STATUS_BUFFER_TOO_SMALL;
+ }
+
+ __ntapi->tt_memcpy_utf16(
+ (wchar16_t *)stat->dev_name,
+ (wchar16_t *)sdev->buffer,
+ stat->dev_name_strlen);
- return status;
+ return NT_STATUS_SUCCESS;
}