[2702] | 1 | /* $Id: ntstat.h 3485 2020-09-21 12:25:08Z bird $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * MSC + NT stat, lstat and fstat implementation and wrappers.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
---|
| 8 | *
|
---|
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
| 10 | * copy of this software and associated documentation files (the "Software"),
|
---|
| 11 | * to deal in the Software without restriction, including without limitation
|
---|
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
| 13 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
| 14 | * Software is furnished to do so, subject to the following conditions:
|
---|
| 15 | *
|
---|
| 16 | * The above copyright notice and this permission notice shall be included
|
---|
| 17 | * in all copies or substantial portions of the Software.
|
---|
| 18 | *
|
---|
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
---|
| 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
---|
| 25 | * IN THE SOFTWARE.
|
---|
| 26 | *
|
---|
| 27 | * Alternatively, the content of this file may be used under the terms of the
|
---|
| 28 | * GPL version 2 or later, or LGPL version 2.1 or later.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | #ifndef ___nt_ntstat_h
|
---|
| 32 | #define ___nt_ntstat_h
|
---|
| 33 |
|
---|
| 34 | #include "nttypes.h"
|
---|
| 35 |
|
---|
| 36 | #include <sys/stat.h>
|
---|
| 37 | #include <io.h>
|
---|
| 38 | #include <direct.h>
|
---|
| 39 |
|
---|
| 40 | #undef stat
|
---|
| 41 | #undef lstat
|
---|
| 42 | #undef fstat
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | /** The distance between the NT and unix epochs given in NT time (units of 100
|
---|
| 46 | * ns). */
|
---|
| 47 | #define BIRD_NT_EPOCH_OFFSET_UNIX_100NS 116444736000000000LL
|
---|
| 48 |
|
---|
| 49 | typedef struct BirdStat
|
---|
| 50 | {
|
---|
| 51 | unsigned __int16 st_mode;
|
---|
[3007] | 52 | unsigned __int8 st_isdirsymlink; /**< Set if directory symlink. */
|
---|
| 53 | unsigned __int8 st_ismountpoint; /**< Set if mount point; 1 if not followed, 2 if followed (lstat & readdir only). */
|
---|
[2702] | 54 | unsigned __int16 st_padding0[2];
|
---|
| 55 | __int64 st_size;
|
---|
| 56 | BirdTimeSpec_T st_atim;
|
---|
| 57 | BirdTimeSpec_T st_mtim;
|
---|
| 58 | BirdTimeSpec_T st_ctim;
|
---|
| 59 | BirdTimeSpec_T st_birthtim;
|
---|
| 60 | unsigned __int64 st_ino;
|
---|
| 61 | unsigned __int64 st_dev;
|
---|
| 62 | unsigned __int32 st_nlink;
|
---|
| 63 | unsigned __int16 st_rdev;
|
---|
| 64 | __int16 st_uid;
|
---|
| 65 | __int16 st_gid;
|
---|
[2858] | 66 | unsigned __int16 st_padding1;
|
---|
| 67 | unsigned __int32 st_attribs;
|
---|
[2702] | 68 | unsigned __int32 st_blksize;
|
---|
| 69 | __int64 st_blocks;
|
---|
| 70 | } BirdStat_T;
|
---|
| 71 |
|
---|
| 72 | #define BIRD_STAT_BLOCK_SIZE 512
|
---|
| 73 |
|
---|
| 74 | #define st_atime st_atim.tv_sec
|
---|
| 75 | #define st_ctime st_ctim.tv_sec
|
---|
| 76 | #define st_mtime st_mtim.tv_sec
|
---|
| 77 | #define st_birthtime st_birthtim.tv_sec
|
---|
| 78 |
|
---|
| 79 | int birdStatFollowLink(const char *pszPath, BirdStat_T *pStat);
|
---|
[2985] | 80 | int birdStatFollowLinkW(const wchar_t *pwszPath, BirdStat_T *pStat);
|
---|
[2702] | 81 | int birdStatOnLink(const char *pszPath, BirdStat_T *pStat);
|
---|
[2985] | 82 | int birdStatOnLinkW(const wchar_t *pwszPath, BirdStat_T *pStat);
|
---|
| 83 | int birdStatAt(void *hRoot, const char *pszPath, BirdStat_T *pStat, int fFollowLink);
|
---|
| 84 | int birdStatAtW(void *hRoot, const wchar_t *pwszPath, BirdStat_T *pStat, int fFollowLink);
|
---|
[2702] | 85 | int birdStatOnFd(int fd, BirdStat_T *pStat);
|
---|
[2850] | 86 | int birdStatOnFdJustSize(int fd, __int64 *pcbFile);
|
---|
[2702] | 87 | int birdStatModTimeOnly(const char *pszPath, BirdTimeSpec_T *pTimeSpec, int fFollowLink);
|
---|
[3485] | 88 | int birdStatModeOnly(const char *pszPath, unsigned __int16 *pMode, int fFollowLink);
|
---|
[2708] | 89 | #ifdef ___nt_ntstuff_h
|
---|
[2856] | 90 | int birdStatHandle(HANDLE hFile, BirdStat_T *pStat, const char *pszPath);
|
---|
[3007] | 91 | void birdStatFillFromFileIdFullDirInfo(BirdStat_T *pStat, MY_FILE_ID_FULL_DIR_INFORMATION const *pBuf);
|
---|
| 92 | void birdStatFillFromFileIdBothDirInfo(BirdStat_T *pStat, MY_FILE_ID_BOTH_DIR_INFORMATION const *pBuf);
|
---|
| 93 | void birdStatFillFromFileBothDirInfo(BirdStat_T *pStat, MY_FILE_BOTH_DIR_INFORMATION const *pBuf);
|
---|
[2851] | 94 | MY_NTSTATUS birdQueryVolumeDeviceNumber(HANDLE hFile, MY_FILE_FS_VOLUME_INFORMATION *pVolInfo, size_t cbVolInfo,
|
---|
| 95 | unsigned __int64 *puDevNo);
|
---|
| 96 | unsigned __int64 birdVolumeInfoToDeviceNumber(MY_FILE_FS_VOLUME_INFORMATION const *pVolInfo);
|
---|
[2708] | 97 | #endif
|
---|
[2702] | 98 |
|
---|
| 99 | #define STAT_REDEFINED_ALREADY
|
---|
| 100 |
|
---|
| 101 | #define stat BirdStat
|
---|
| 102 | #define BirdStat(a_pszPath, a_pStat) birdStatFollowLink(a_pszPath, a_pStat)
|
---|
| 103 | #define lstat(a_pszPath, a_pStat) birdStatOnLink(a_pszPath, a_pStat)
|
---|
| 104 | #define fstat(a_fd, a_pStat) birdStatOnFd(a_fd, a_pStat)
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | #ifndef _S_IFLNK
|
---|
| 108 | # define _S_IFLNK 0xa000
|
---|
| 109 | #endif
|
---|
| 110 | #ifndef S_IFLNK
|
---|
| 111 | # define S_IFLNK _S_IFLNK
|
---|
| 112 | #endif
|
---|
[2707] | 113 | #ifndef S_IFIFO
|
---|
| 114 | # define S_IFIFO _S_IFIFO
|
---|
| 115 | #endif
|
---|
[2702] | 116 |
|
---|
| 117 | #ifndef S_ISLNK
|
---|
| 118 | # define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
|
---|
| 119 | #endif
|
---|
| 120 | #ifndef S_ISDIR
|
---|
| 121 | # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
|
---|
| 122 | #endif
|
---|
| 123 | #ifndef S_ISREG
|
---|
| 124 | # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
---|
| 125 | #endif
|
---|
| 126 |
|
---|
[2707] | 127 | #define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
|
---|
| 128 | #define S_IXUSR _S_IEXEC
|
---|
| 129 | #define S_IWUSR _S_IWRITE
|
---|
| 130 | #define S_IRUSR _S_IREAD
|
---|
| 131 | #define S_IRWXG 0000070
|
---|
| 132 | #define S_IRGRP 0000040
|
---|
| 133 | #define S_IWGRP 0000020
|
---|
| 134 | #define S_IXGRP 0000010
|
---|
| 135 | #define S_IRWXO 0000007
|
---|
| 136 | #define S_IROTH 0000004
|
---|
| 137 | #define S_IWOTH 0000002
|
---|
| 138 | #define S_IXOTH 0000001
|
---|
| 139 | #define S_ISUID 0004000
|
---|
| 140 | #define S_ISGID 0002000
|
---|
| 141 | #define ALLPERMS 0000777
|
---|
[2702] | 142 |
|
---|
| 143 | #endif
|
---|
| 144 |
|
---|