ngx_files.h revision e18a033b
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#ifndef _NGX_FILES_H_INCLUDED_
9#define _NGX_FILES_H_INCLUDED_
10
11
12#include <ngx_config.h>
13#include <ngx_core.h>
14
15
16typedef HANDLE                      ngx_fd_t;
17typedef BY_HANDLE_FILE_INFORMATION  ngx_file_info_t;
18typedef uint64_t                    ngx_file_uniq_t;
19
20
21typedef struct {
22    u_char                         *name;
23    size_t                          size;
24    void                           *addr;
25    ngx_fd_t                        fd;
26    HANDLE                          handle;
27    ngx_log_t                      *log;
28} ngx_file_mapping_t;
29
30
31typedef struct {
32    HANDLE                          dir;
33    WIN32_FIND_DATA                 finddata;
34
35    unsigned                        valid_info:1;
36    unsigned                        type:1;
37    unsigned                        ready:1;
38} ngx_dir_t;
39
40
41typedef struct {
42    HANDLE                          dir;
43    WIN32_FIND_DATA                 finddata;
44
45    unsigned                        ready:1;
46    unsigned                        test:1;
47    unsigned                        no_match:1;
48
49    u_char                         *pattern;
50    ngx_str_t                       name;
51    size_t                          last;
52    ngx_log_t                      *log;
53} ngx_glob_t;
54
55
56
57/* INVALID_FILE_ATTRIBUTES is specified but not defined at least in MSVC6SP2 */
58#ifndef INVALID_FILE_ATTRIBUTES
59#define INVALID_FILE_ATTRIBUTES     0xffffffff
60#endif
61
62/* INVALID_SET_FILE_POINTER is not defined at least in MSVC6SP2 */
63#ifndef INVALID_SET_FILE_POINTER
64#define INVALID_SET_FILE_POINTER    0xffffffff
65#endif
66
67
68#define NGX_INVALID_FILE            INVALID_HANDLE_VALUE
69#define NGX_FILE_ERROR              0
70
71
72ngx_fd_t ngx_open_file(u_char *name, u_long mode, u_long create, u_long access);
73#define ngx_open_file_n             "CreateFile()"
74
75#define NGX_FILE_RDONLY             GENERIC_READ
76#define NGX_FILE_WRONLY             GENERIC_WRITE
77#define NGX_FILE_RDWR               GENERIC_READ|GENERIC_WRITE
78#define NGX_FILE_APPEND             FILE_APPEND_DATA|SYNCHRONIZE
79#define NGX_FILE_NONBLOCK           0
80
81#define NGX_FILE_CREATE_OR_OPEN     OPEN_ALWAYS
82#define NGX_FILE_OPEN               OPEN_EXISTING
83#define NGX_FILE_TRUNCATE           CREATE_ALWAYS
84
85#define NGX_FILE_DEFAULT_ACCESS     0
86#define NGX_FILE_OWNER_ACCESS       0
87
88
89#define ngx_open_tempfile(name, persistent, access)                          \
90    CreateFile((const char *) name,                                          \
91               GENERIC_READ|GENERIC_WRITE,                                   \
92               FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,           \
93               NULL,                                                         \
94               CREATE_NEW,                                                   \
95               persistent ? 0:                                               \
96                   FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE,       \
97               NULL);
98
99#define ngx_open_tempfile_n         "CreateFile()"
100
101
102#define ngx_close_file              CloseHandle
103#define ngx_close_file_n            "CloseHandle()"
104
105
106ssize_t ngx_read_fd(ngx_fd_t fd, void *buf, size_t size);
107#define ngx_read_fd_n               "ReadFile()"
108
109
110ssize_t ngx_write_fd(ngx_fd_t fd, void *buf, size_t size);
111#define ngx_write_fd_n              "WriteFile()"
112
113
114ssize_t ngx_write_console(ngx_fd_t fd, void *buf, size_t size);
115
116
117#define ngx_linefeed(p)             *p++ = CR; *p++ = LF;
118#define NGX_LINEFEED_SIZE           2
119#define NGX_LINEFEED                CRLF
120
121
122#define ngx_delete_file(name)       DeleteFile((const char *) name)
123#define ngx_delete_file_n           "DeleteFile()"
124
125
126#define ngx_rename_file(o, n)       MoveFile((const char *) o, (const char *) n)
127#define ngx_rename_file_n           "MoveFile()"
128ngx_err_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log);
129
130
131
132ngx_int_t ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s);
133#define ngx_set_file_time_n         "SetFileTime()"
134
135
136ngx_int_t ngx_file_info(u_char *filename, ngx_file_info_t *fi);
137#define ngx_file_info_n             "GetFileAttributesEx()"
138
139
140#define ngx_fd_info(fd, fi)         GetFileInformationByHandle(fd, fi)
141#define ngx_fd_info_n               "GetFileInformationByHandle()"
142
143
144#define ngx_link_info(name, fi)     ngx_file_info(name, fi)
145#define ngx_link_info_n             "GetFileAttributesEx()"
146
147
148#define ngx_is_dir(fi)                                                       \
149    (((fi)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
150#define ngx_is_file(fi)                                                      \
151    (((fi)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
152#define ngx_is_link(fi)     0
153#define ngx_is_exec(fi)     0
154
155#define ngx_file_access(fi) 0
156
157#define ngx_file_size(fi)                                                    \
158    (((off_t) (fi)->nFileSizeHigh << 32) | (fi)->nFileSizeLow)
159#define ngx_file_fs_size(fi)        ngx_file_size(fi)
160
161#define ngx_file_uniq(fi)   (*(ngx_file_uniq_t *) &(fi)->nFileIndexHigh)
162
163
164/* 116444736000000000 is commented in src/os/win32/ngx_time.c */
165
166#define ngx_file_mtime(fi)                                                   \
167 (time_t) (((((unsigned __int64) (fi)->ftLastWriteTime.dwHighDateTime << 32) \
168                               | (fi)->ftLastWriteTime.dwLowDateTime)        \
169                                          - 116444736000000000) / 10000000)
170
171ngx_int_t ngx_create_file_mapping(ngx_file_mapping_t *fm);
172void ngx_close_file_mapping(ngx_file_mapping_t *fm);
173
174
175u_char *ngx_realpath(u_char *path, u_char *resolved);
176#define ngx_realpath_n              ""
177#define ngx_getcwd(buf, size)       GetCurrentDirectory(size, (char *) buf)
178#define ngx_getcwd_n                "GetCurrentDirectory()"
179#define ngx_path_separator(c)       ((c) == '/' || (c) == '\\')
180
181#define NGX_HAVE_MAX_PATH           1
182#define NGX_MAX_PATH                MAX_PATH
183
184#define NGX_DIR_MASK                (u_char *) "/*"
185#define NGX_DIR_MASK_LEN            2
186
187
188ngx_int_t ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir);
189#define ngx_open_dir_n              "FindFirstFile()"
190
191
192ngx_int_t ngx_read_dir(ngx_dir_t *dir);
193#define ngx_read_dir_n              "FindNextFile()"
194
195
196ngx_int_t ngx_close_dir(ngx_dir_t *dir);
197#define ngx_close_dir_n             "FindClose()"
198
199
200#define ngx_create_dir(name, access) CreateDirectory((const char *) name, NULL)
201#define ngx_create_dir_n            "CreateDirectory()"
202
203
204#define ngx_delete_dir(name)        RemoveDirectory((const char *) name)
205#define ngx_delete_dir_n            "RemoveDirectory()"
206
207
208#define ngx_dir_access(a)           (a)
209
210
211#define ngx_de_name(dir)            ((u_char *) (dir)->finddata.cFileName)
212#define ngx_de_namelen(dir)         ngx_strlen((dir)->finddata.cFileName)
213
214ngx_int_t ngx_de_info(u_char *name, ngx_dir_t *dir);
215#define ngx_de_info_n               "dummy()"
216
217ngx_int_t ngx_de_link_info(u_char *name, ngx_dir_t *dir);
218#define ngx_de_link_info_n          "dummy()"
219
220#define ngx_de_is_dir(dir)                                                   \
221    (((dir)->finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
222#define ngx_de_is_file(dir)                                                  \
223    (((dir)->finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
224#define ngx_de_is_link(dir)         0
225#define ngx_de_access(dir)          0
226#define ngx_de_size(dir)                                                     \
227  (((off_t) (dir)->finddata.nFileSizeHigh << 32) | (dir)->finddata.nFileSizeLow)
228#define ngx_de_fs_size(dir)         ngx_de_size(dir)
229
230/* 116444736000000000 is commented in src/os/win32/ngx_time.c */
231
232#define ngx_de_mtime(dir)                                                    \
233    (time_t) (((((unsigned __int64)                                          \
234                     (dir)->finddata.ftLastWriteTime.dwHighDateTime << 32)   \
235                      | (dir)->finddata.ftLastWriteTime.dwLowDateTime)       \
236                                          - 116444736000000000) / 10000000)
237
238
239ngx_int_t ngx_open_glob(ngx_glob_t *gl);
240#define ngx_open_glob_n             "FindFirstFile()"
241
242ngx_int_t ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name);
243void ngx_close_glob(ngx_glob_t *gl);
244
245
246ssize_t ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset);
247#define ngx_read_file_n             "ReadFile()"
248
249ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size,
250    off_t offset);
251
252ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *ce,
253    off_t offset, ngx_pool_t *pool);
254
255ngx_int_t ngx_read_ahead(ngx_fd_t fd, size_t n);
256#define ngx_read_ahead_n            "ngx_read_ahead_n"
257
258ngx_int_t ngx_directio_on(ngx_fd_t fd);
259#define ngx_directio_on_n           "ngx_directio_on_n"
260
261ngx_int_t ngx_directio_off(ngx_fd_t fd);
262#define ngx_directio_off_n          "ngx_directio_off_n"
263
264size_t ngx_fs_bsize(u_char *name);
265
266
267#define ngx_stdout               GetStdHandle(STD_OUTPUT_HANDLE)
268#define ngx_stderr               GetStdHandle(STD_ERROR_HANDLE)
269#define ngx_set_stderr(fd)       SetStdHandle(STD_ERROR_HANDLE, fd)
270#define ngx_set_stderr_n         "SetStdHandle(STD_ERROR_HANDLE)"
271
272
273#endif /* _NGX_FILES_H_INCLUDED_ */
274