summaryrefslogtreecommitdiffhomepage
path: root/src/fs/ntapi_tt_istat.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-06-29 16:44:16 -0400
committermidipix <writeonce@midipix.org>2016-06-29 19:16:44 -0400
commit90028919e4ca20cc6ff04fc2d1114c928d6f0260 (patch)
tree1250209e0d4f723454581fcd209ddf3bdb69f343 /src/fs/ntapi_tt_istat.c
parent3119b6aafde26342b3f4a64d3aa3fced107b95c0 (diff)
downloadntapi-90028919e4ca20cc6ff04fc2d1114c928d6f0260.tar.bz2
ntapi-90028919e4ca20cc6ff04fc2d1114c928d6f0260.tar.xz
__ntapi_tt_istat: refactor, explicit string comparison.
Diffstat (limited to 'src/fs/ntapi_tt_istat.c')
-rw-r--r--src/fs/ntapi_tt_istat.c92
1 files changed, 44 insertions, 48 deletions
diff --git a/src/fs/ntapi_tt_istat.c b/src/fs/ntapi_tt_istat.c
index bd1b92d..bdfa09f 100644
--- a/src/fs/ntapi_tt_istat.c
+++ b/src/fs/ntapi_tt_istat.c
@@ -26,7 +26,6 @@ int32_t __stdcall __ntapi_tt_istat(
nt_oa oa;
nt_iosb iosb;
nt_unicode_string * sdev;
- uint32_t hash;
wchar16_t * wch;
wchar16_t * wch_mark;
@@ -45,15 +44,15 @@ int32_t __stdcall __ntapi_tt_istat(
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;
istat->flags_out = NT_STAT_NEW_HANDLE;
@@ -63,60 +62,57 @@ int32_t __stdcall __ntapi_tt_istat(
istat->flags_in = flags;
/* file index number */
- status = __ntapi->zw_query_information_file(
- hfile,
- &iosb,
- &istat->fii,
- sizeof(istat->fii),
- NT_FILE_INTERNAL_INFORMATION);
-
- if (status != NT_STATUS_SUCCESS)
+ if ((status = __ntapi->zw_query_information_file(
+ hfile,
+ &iosb,
+ &istat->fii,
+ sizeof(istat->fii),
+ NT_FILE_INTERNAL_INFORMATION)))
return status;
/* attributes & reparse tag information */
- status = __ntapi->zw_query_information_file(
- hfile,
- &iosb,
- &istat->ftagi,
- sizeof(istat->ftagi),
- NT_FILE_ATTRIBUTE_TAG_INFORMATION);
-
- if (status != NT_STATUS_SUCCESS)
+ if ((status = __ntapi->zw_query_information_file(
+ hfile,
+ &iosb,
+ &istat->ftagi,
+ sizeof(istat->ftagi),
+ NT_FILE_ATTRIBUTE_TAG_INFORMATION)))
return status;
- /* TODO: consolidate with statfs */
/* system-unique device name */
- iosb.info = 0;
- status = __ntapi->zw_query_object(
- hfile,
- NT_OBJECT_NAME_INFORMATION,
- buffer,
- buffer_size,
- (uint32_t *)&iosb.info);
-
- if (status != NT_STATUS_SUCCESS)
+ if ((status = __ntapi->zw_query_object(
+ hfile,
+ NT_OBJECT_NAME_INFORMATION,
+ buffer,
+ buffer_size,
+ (uint32_t *)&iosb.info)))
return status;
sdev = (nt_unicode_string *)buffer;
+ wch = sdev->buffer;
if (sdev->strlen < __DEVICE_PATH_PREFIX_LEN)
return NT_STATUS_INVALID_HANDLE;
- hash = __ntapi->tt_buffer_crc32(
- 0,
- sdev->buffer,
- __DEVICE_PATH_PREFIX_LEN);
-
- if (hash != __DEVICE_PATH_PREFIX_HASH)
+ if ((wch[0] != '\\')
+ || (wch[1] != 'D')
+ || (wch[2] != 'e')
+ || (wch[3] != 'v')
+ || (wch[4] != 'i')
+ || (wch[5] != 'c')
+ || (wch[6] != 'e')
+ || (wch[7] != '\\'))
return NT_STATUS_INVALID_HANDLE;
- wch_mark = sdev->buffer + __DEVICE_PATH_PREFIX_LEN/sizeof(wchar16_t);
- wch = wch_mark;
- while (*wch != '\\') wch++;
- istat->dev_name_strlen = (uint16_t)((wch - sdev->buffer) * sizeof(uint16_t));
+ wch_mark = &wch[8];
+ wch = wch_mark;
- istat->dev_name_hash = __ntapi->tt_buffer_crc32(
- hash,
+ while (*wch != '\\')
+ wch++;
+
+ istat->dev_name_strlen = (uint16_t)((wch - sdev->buffer) * sizeof(uint16_t));
+ istat->dev_name_hash = __ntapi->tt_buffer_crc32(
+ __DEVICE_PATH_PREFIX_HASH,
wch_mark,
(uintptr_t)wch - (uintptr_t)wch_mark);