summaryrefslogtreecommitdiffstats
path: root/src/lib/nt/ntstat.h
blob: 52e41f39f40af1ffc75ce849f3267a975fb3e4af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* $Id: ntstat.h 3485 2020-09-21 12:25:08Z bird $ */
/** @file
 * MSC + NT stat, lstat and fstat implementation and wrappers.
 */

/*
 * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Alternatively, the content of this file may be used under the terms of the
 * GPL version 2 or later, or LGPL version 2.1 or later.
 */

#ifndef ___nt_ntstat_h
#define ___nt_ntstat_h

#include "nttypes.h"

#include <sys/stat.h>
#include <io.h>
#include <direct.h>

#undef stat
#undef lstat
#undef fstat


/** The distance between the NT and unix epochs given in NT time (units of 100
 *  ns). */
#define BIRD_NT_EPOCH_OFFSET_UNIX_100NS 116444736000000000LL

typedef struct BirdStat
{
    unsigned __int16    st_mode;
    unsigned __int8     st_isdirsymlink; /**< Set if directory symlink. */
    unsigned __int8     st_ismountpoint; /**< Set if mount point; 1 if not followed, 2 if followed (lstat & readdir only). */
    unsigned __int16    st_padding0[2];
    __int64             st_size;
    BirdTimeSpec_T      st_atim;
    BirdTimeSpec_T      st_mtim;
    BirdTimeSpec_T      st_ctim;
    BirdTimeSpec_T      st_birthtim;
    unsigned __int64    st_ino;
    unsigned __int64    st_dev;
    unsigned __int32    st_nlink;
    unsigned __int16    st_rdev;
    __int16             st_uid;
    __int16             st_gid;
    unsigned __int16    st_padding1;
    unsigned __int32    st_attribs;
    unsigned __int32    st_blksize;
    __int64             st_blocks;
} BirdStat_T;

#define BIRD_STAT_BLOCK_SIZE    512

#define st_atime        st_atim.tv_sec
#define st_ctime        st_ctim.tv_sec
#define st_mtime        st_mtim.tv_sec
#define st_birthtime    st_birthtim.tv_sec

int birdStatFollowLink(const char *pszPath, BirdStat_T *pStat);
int birdStatFollowLinkW(const wchar_t *pwszPath, BirdStat_T *pStat);
int birdStatOnLink(const char *pszPath, BirdStat_T *pStat);
int birdStatOnLinkW(const wchar_t *pwszPath, BirdStat_T *pStat);
int birdStatAt(void *hRoot, const char *pszPath, BirdStat_T *pStat, int fFollowLink);
int birdStatAtW(void *hRoot, const wchar_t *pwszPath, BirdStat_T *pStat, int fFollowLink);
int birdStatOnFd(int fd, BirdStat_T *pStat);
int birdStatOnFdJustSize(int fd, __int64 *pcbFile);
int birdStatModTimeOnly(const char *pszPath, BirdTimeSpec_T *pTimeSpec, int fFollowLink);
int birdStatModeOnly(const char *pszPath, unsigned __int16 *pMode, int fFollowLink);
#ifdef ___nt_ntstuff_h
int  birdStatHandle(HANDLE hFile, BirdStat_T *pStat, const char *pszPath);
void birdStatFillFromFileIdFullDirInfo(BirdStat_T *pStat, MY_FILE_ID_FULL_DIR_INFORMATION const *pBuf);
void birdStatFillFromFileIdBothDirInfo(BirdStat_T *pStat, MY_FILE_ID_BOTH_DIR_INFORMATION const *pBuf);
void birdStatFillFromFileBothDirInfo(BirdStat_T *pStat, MY_FILE_BOTH_DIR_INFORMATION const *pBuf);
MY_NTSTATUS birdQueryVolumeDeviceNumber(HANDLE hFile, MY_FILE_FS_VOLUME_INFORMATION *pVolInfo, size_t cbVolInfo,
                                        unsigned __int64 *puDevNo);
unsigned __int64 birdVolumeInfoToDeviceNumber(MY_FILE_FS_VOLUME_INFORMATION const *pVolInfo);
#endif

#define STAT_REDEFINED_ALREADY

#define stat                            BirdStat
#define BirdStat(a_pszPath, a_pStat)    birdStatFollowLink(a_pszPath, a_pStat)
#define lstat(a_pszPath, a_pStat)       birdStatOnLink(a_pszPath, a_pStat)
#define fstat(a_fd, a_pStat)            birdStatOnFd(a_fd, a_pStat)


#ifndef _S_IFLNK
# define _S_IFLNK       0xa000
#endif
#ifndef S_IFLNK
# define S_IFLNK        _S_IFLNK
#endif
#ifndef S_IFIFO
# define S_IFIFO        _S_IFIFO
#endif

#ifndef S_ISLNK
# define S_ISLNK(m)     (((m) & _S_IFMT) == _S_IFLNK)
#endif
#ifndef S_ISDIR
# define S_ISDIR(m)     (((m) & _S_IFMT) == _S_IFDIR)
#endif
#ifndef S_ISREG
# define S_ISREG(m)     (((m) & _S_IFMT) == _S_IFREG)
#endif

#define	S_IRWXU         (_S_IREAD | _S_IWRITE | _S_IEXEC)
#define	S_IXUSR         _S_IEXEC
#define	S_IWUSR         _S_IWRITE
#define	S_IRUSR         _S_IREAD
#define S_IRWXG         0000070
#define S_IRGRP	        0000040
#define S_IWGRP	        0000020
#define S_IXGRP         0000010
#define S_IRWXO         0000007
#define S_IROTH	        0000004
#define S_IWOTH	        0000002
#define S_IXOTH         0000001
#define	S_ISUID         0004000
#define	S_ISGID         0002000
#define ALLPERMS        0000777

#endif