|
|
dd89bb |
/********************************************************/
|
|
|
dd89bb |
/* ntapi: Native API core library */
|
|
|
4256e2 |
/* Copyright (C) 2013--2016 Z. Gilboa */
|
|
|
dd89bb |
/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
|
|
|
dd89bb |
/********************************************************/
|
|
|
dd89bb |
|
|
|
dd89bb |
#include <ntapi/ntapi.h>
|
|
|
dd89bb |
#include <ntapi/nt_file.h>
|
|
|
dd89bb |
#include <ntapi/nt_fsctl.h>
|
|
|
dd89bb |
#include <ntapi/nt_mount.h>
|
|
|
dd89bb |
#include <ntapi/nt_stat.h>
|
|
|
dd89bb |
#include "ntapi_impl.h"
|
|
|
dd89bb |
|
|
|
dd89bb |
int32_t __stdcall __ntapi_tt_stat(
|
|
|
dd89bb |
__in void * hfile,
|
|
|
dd89bb |
__in void * hroot __optional,
|
|
|
dd89bb |
__in nt_unicode_string * path,
|
|
|
dd89bb |
__out nt_stat * stat,
|
|
|
dd89bb |
__out uintptr_t * buffer,
|
|
|
dd89bb |
__in uint32_t buffer_size,
|
|
|
dd89bb |
__in uint32_t open_options,
|
|
|
dd89bb |
__in uint32_t flags)
|
|
|
dd89bb |
{
|
|
|
dd89bb |
int32_t status;
|
|
|
dd89bb |
nt_oa oa;
|
|
|
dd89bb |
nt_iosb iosb;
|
|
|
dd89bb |
nt_unicode_string * sdev;
|
|
|
dd89bb |
nt_fai * fai;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* validation */
|
|
|
dd89bb |
if (!hfile && !path)
|
|
|
dd89bb |
return NT_STATUS_INVALID_HANDLE;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* hfile */
|
|
|
dd89bb |
if (!hfile) {
|
|
|
dd89bb |
/* oa */
|
|
|
dd89bb |
oa.len = sizeof(nt_oa);
|
|
|
dd89bb |
oa.root_dir = hroot;
|
|
|
dd89bb |
oa.obj_name = path;
|
|
|
dd89bb |
oa.obj_attr = 0;
|
|
|
dd89bb |
oa.sec_desc = 0;
|
|
|
dd89bb |
oa.sec_qos = 0;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* open file/folder */
|
|
|
dd89bb |
status = __ntapi->zw_open_file(
|
|
|
dd89bb |
&hfile,
|
|
|
dd89bb |
NT_SEC_SYNCHRONIZE | NT_FILE_READ_ATTRIBUTES | NT_FILE_READ_ACCESS,
|
|
|
dd89bb |
&oa,
|
|
|
dd89bb |
&iosb,
|
|
|
dd89bb |
NT_FILE_SHARE_READ | NT_FILE_SHARE_WRITE,
|
|
|
dd89bb |
open_options | NT_FILE_SYNCHRONOUS_IO_ALERT);
|
|
|
dd89bb |
|
|
|
dd89bb |
if (status != NT_STATUS_SUCCESS)
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
|
|
|
dd89bb |
stat->flags_out = NT_STAT_NEW_HANDLE;
|
|
|
dd89bb |
}
|
|
|
dd89bb |
|
|
|
dd89bb |
stat->hfile = hfile;
|
|
|
dd89bb |
stat->flags_in = flags;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* system-unique device name */
|
|
|
dd89bb |
status = __ntapi->zw_query_information_file(
|
|
|
dd89bb |
hfile,
|
|
|
dd89bb |
&iosb,
|
|
|
dd89bb |
buffer,
|
|
|
dd89bb |
buffer_size,
|
|
|
dd89bb |
NT_FILE_ALL_INFORMATION);
|
|
|
dd89bb |
|
|
|
dd89bb |
if (status != NT_STATUS_SUCCESS)
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* copy file info minus name */
|
|
|
dd89bb |
fai = (nt_fai *)buffer;
|
|
|
dd89bb |
__ntapi->tt_aligned_block_memcpy(
|
|
|
dd89bb |
(uintptr_t *)stat,
|
|
|
dd89bb |
(uintptr_t *)fai,
|
|
|
dd89bb |
((size_t)(&((nt_fai *)0)->name_info)));
|
|
|
dd89bb |
|
|
|
dd89bb |
/* record the file name length, but do not hash */
|
|
|
dd89bb |
stat->file_name_length = fai->name_info.file_name_length;
|
|
|
dd89bb |
stat->file_name_hash = 0;
|
|
|
dd89bb |
|
|
|
dd89bb |
|
|
|
dd89bb |
/* file system size information */
|
|
|
dd89bb |
status = __ntapi->zw_query_volume_information_file(
|
|
|
dd89bb |
hfile,
|
|
|
dd89bb |
&iosb,
|
|
|
dd89bb |
&(stat->fssi),
|
|
|
dd89bb |
sizeof(stat->fssi),
|
|
|
dd89bb |
NT_FILE_FS_SIZE_INFORMATION);
|
|
|
dd89bb |
|
|
|
dd89bb |
if (status != NT_STATUS_SUCCESS)
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* system-unique device name (simpler than statfs) */
|
|
|
dd89bb |
iosb.info = 0;
|
|
|
dd89bb |
status = __ntapi->zw_query_object(
|
|
|
dd89bb |
hfile,
|
|
|
dd89bb |
NT_OBJECT_NAME_INFORMATION,
|
|
|
dd89bb |
buffer,
|
|
|
dd89bb |
buffer_size,
|
|
|
dd89bb |
(uint32_t *)&iosb.info);
|
|
|
dd89bb |
|
|
|
dd89bb |
if (status != NT_STATUS_SUCCESS)
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
|
|
|
dd89bb |
sdev = (nt_unicode_string *)buffer;
|
|
|
dd89bb |
stat->dev_name_strlen = sdev->strlen - (uint16_t)stat->file_name_length;
|
|
|
dd89bb |
|
|
|
dd89bb |
stat->dev_name_hash = __ntapi->tt_buffer_crc32(
|
|
|
dd89bb |
0,
|
|
|
dd89bb |
sdev->buffer,
|
|
|
dd89bb |
stat->dev_name_strlen);
|
|
|
dd89bb |
|
|
|
dd89bb |
if (flags & NT_STAT_DEV_NAME_COPY) {
|
|
|
dd89bb |
if (stat->dev_name_maxlen < sdev->strlen)
|
|
|
dd89bb |
/* does not justify failure */
|
|
|
dd89bb |
*stat->dev_name = 0;
|
|
|
dd89bb |
else
|
|
|
dd89bb |
__ntapi->tt_memcpy_utf16(
|
|
|
dd89bb |
(wchar16_t *)stat->dev_name,
|
|
|
dd89bb |
(wchar16_t *)sdev->buffer,
|
|
|
dd89bb |
stat->dev_name_strlen);
|
|
|
dd89bb |
} else
|
|
|
dd89bb |
*stat->dev_name = 0;
|
|
|
dd89bb |
|
|
|
dd89bb |
return status;
|
|
|
dd89bb |
}
|