Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_files.c @ 5739:6e4bb1d6679d
Configure: style.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 26 Jun 2014 03:34:02 +0400 |
parents | 1e2d5d3f9f6b |
children | 1fdba317ee6d |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
6 |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
33
b2e039840718
nginx-0.0.1-2002-12-19-20:49:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
8 #include <ngx_config.h> |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
9 #include <ngx_core.h> |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
10 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
11 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
12 #if (NGX_HAVE_FILE_AIO) |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
13 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
14 ngx_uint_t ngx_file_aio = 1; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
15 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
16 #endif |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
17 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
18 |
561 | 19 ssize_t |
20 ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
21 { |
561 | 22 ssize_t n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
24 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
461 | 25 "read: %d, %p, %uz, %O", file->fd, buf, size, offset); |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
26 |
469 | 27 #if (NGX_HAVE_PREAD) |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
28 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
29 n = pread(file->fd, buf, size, offset); |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
30 |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
31 if (n == -1) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
32 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
33 "pread() \"%s\" failed", file->name.data); |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
34 return NGX_ERROR; |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
35 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
36 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
37 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
38 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
39 if (file->sys_offset != offset) { |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
40 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
41 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
42 "lseek() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
43 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
44 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
45 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
46 file->sys_offset = offset; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
47 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
48 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
49 n = read(file->fd, buf, size); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
50 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
51 if (n == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
52 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
53 "read() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
54 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
55 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
56 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
57 file->sys_offset += n; |
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
58 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
59 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
60 |
35
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
61 file->offset += n; |
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
62 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
63 return n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 } |
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
66 |
561 | 67 ssize_t |
68 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
69 { |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
70 ssize_t n, written; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
71 |
461 | 72 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
73 "write: %d, %p, %uz, %O", file->fd, buf, size, offset); | |
74 | |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
75 written = 0; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
76 |
469 | 77 #if (NGX_HAVE_PWRITE) |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
78 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
79 for ( ;; ) { |
3657 | 80 n = pwrite(file->fd, buf + written, size, offset); |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
81 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
82 if (n == -1) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
83 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
84 "pwrite() \"%s\" failed", file->name.data); |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
85 return NGX_ERROR; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
86 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
87 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
88 file->offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
89 written += n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
90 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
91 if ((size_t) n == size) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
92 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
93 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
94 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
95 offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
96 size -= n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
97 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
98 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
99 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
100 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
101 if (file->sys_offset != offset) { |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
102 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
103 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
104 "lseek() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
105 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
106 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
107 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
108 file->sys_offset = offset; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
109 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
110 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
111 for ( ;; ) { |
3657 | 112 n = write(file->fd, buf + written, size); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
113 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
114 if (n == -1) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
115 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
116 "write() \"%s\" failed", file->name.data); |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
117 return NGX_ERROR; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
118 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
119 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
120 file->offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
121 written += n; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
122 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
123 if ((size_t) n == size) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
124 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
125 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
126 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
127 size -= n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
128 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
129 #endif |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
130 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
131 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
132 |
561 | 133 ngx_fd_t |
1046 | 134 ngx_open_tempfile(u_char *name, ngx_uint_t persistent, ngx_uint_t access) |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
135 { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
136 ngx_fd_t fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
137 |
1046 | 138 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, |
139 access ? access : 0600); | |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
140 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
141 if (fd != -1 && !persistent) { |
4794
4163fb9dcfcb
Explicitly ignore returned value from unlink() in ngx_open_tempfile().
Andrey Belov <defan@nginx.com>
parents:
4737
diff
changeset
|
142 (void) unlink((const char *) name); |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
143 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
144 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
145 return fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
146 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
147 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
148 |
461 | 149 #define NGX_IOVS 8 |
150 | |
561 | 151 ssize_t |
152 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
153 ngx_pool_t *pool) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
154 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
155 u_char *prev; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
156 size_t size; |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
157 ssize_t total, n; |
461 | 158 ngx_array_t vec; |
159 struct iovec *iov, iovs[NGX_IOVS]; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
160 |
461 | 161 /* use pwrite() if there is the only buf in a chain */ |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
162 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
163 if (cl->next == NULL) { |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
164 return ngx_write_file(file, cl->buf->pos, |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
165 (size_t) (cl->buf->last - cl->buf->pos), |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
191
diff
changeset
|
166 offset); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
167 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
168 |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
169 total = 0; |
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
170 |
461 | 171 vec.elts = iovs; |
172 vec.size = sizeof(struct iovec); | |
577 | 173 vec.nalloc = NGX_IOVS; |
461 | 174 vec.pool = pool; |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
175 |
461 | 176 do { |
177 prev = NULL; | |
178 iov = NULL; | |
179 size = 0; | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
180 |
461 | 181 vec.nelts = 0; |
182 | |
183 /* create the iovec and coalesce the neighbouring bufs */ | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
184 |
461 | 185 while (cl && vec.nelts < IOV_MAX) { |
186 if (prev == cl->buf->pos) { | |
187 iov->iov_len += cl->buf->last - cl->buf->pos; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
188 |
461 | 189 } else { |
501 | 190 iov = ngx_array_push(&vec); |
191 if (iov == NULL) { | |
461 | 192 return NGX_ERROR; |
193 } | |
194 | |
195 iov->iov_base = (void *) cl->buf->pos; | |
196 iov->iov_len = cl->buf->last - cl->buf->pos; | |
197 } | |
198 | |
199 size += cl->buf->last - cl->buf->pos; | |
200 prev = cl->buf->last; | |
201 cl = cl->next; | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
202 } |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
203 |
461 | 204 /* use pwrite() if there is the only iovec buffer */ |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
205 |
461 | 206 if (vec.nelts == 1) { |
207 iov = vec.elts; | |
4221
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
208 |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
209 n = ngx_write_file(file, (u_char *) iov[0].iov_base, |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
210 iov[0].iov_len, offset); |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
211 |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
212 if (n == NGX_ERROR) { |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
213 return n; |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
214 } |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
215 |
3203ddb78279
Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4220
diff
changeset
|
216 return total + n; |
461 | 217 } |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
218 |
461 | 219 if (file->sys_offset != offset) { |
220 if (lseek(file->fd, offset, SEEK_SET) == -1) { | |
221 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
222 "lseek() \"%s\" failed", file->name.data); |
461 | 223 return NGX_ERROR; |
224 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
225 |
461 | 226 file->sys_offset = offset; |
227 } | |
228 | |
229 n = writev(file->fd, vec.elts, vec.nelts); | |
230 | |
231 if (n == -1) { | |
232 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
233 "writev() \"%s\" failed", file->name.data); |
154
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
234 return NGX_ERROR; |
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
235 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
236 |
461 | 237 if ((size_t) n != size) { |
238 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
239 "writev() \"%s\" has written only %z of %uz", |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
240 file->name.data, n, size); |
461 | 241 return NGX_ERROR; |
242 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
243 |
4919
bd6299189b49
Core: added debug logging of writev() in ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4794
diff
changeset
|
244 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0, |
bd6299189b49
Core: added debug logging of writev() in ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4794
diff
changeset
|
245 "writev: %d, %z", file->fd, n); |
bd6299189b49
Core: added debug logging of writev() in ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents:
4794
diff
changeset
|
246 |
461 | 247 file->sys_offset += n; |
248 file->offset += n; | |
4938
64ffc28850bb
Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4919
diff
changeset
|
249 offset += n; |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
250 total += n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
251 |
461 | 252 } while (cl); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
253 |
4220
4be8dd8dd547
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3861
diff
changeset
|
254 return total; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
255 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
256 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
257 |
561 | 258 ngx_int_t |
681 | 259 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
260 { | |
261 struct timeval tv[2]; | |
262 | |
3861
cf80c0b0109a
set current atime while setting mtime
Igor Sysoev <igor@sysoev.ru>
parents:
3657
diff
changeset
|
263 tv[0].tv_sec = ngx_time(); |
681 | 264 tv[0].tv_usec = 0; |
265 tv[1].tv_sec = s; | |
266 tv[1].tv_usec = 0; | |
267 | |
268 if (utimes((char *) name, tv) != -1) { | |
269 return NGX_OK; | |
270 } | |
271 | |
272 return NGX_ERROR; | |
273 } | |
274 | |
275 | |
276 ngx_int_t | |
3651 | 277 ngx_create_file_mapping(ngx_file_mapping_t *fm) |
278 { | |
279 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
280 NGX_FILE_DEFAULT_ACCESS); | |
281 if (fm->fd == NGX_INVALID_FILE) { | |
282 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
283 ngx_open_file_n " \"%s\" failed", fm->name); | |
284 return NGX_ERROR; | |
285 } | |
286 | |
287 if (ftruncate(fm->fd, fm->size) == -1) { | |
288 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
289 "ftruncate() \"%s\" failed", fm->name); | |
290 goto failed; | |
291 } | |
292 | |
293 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED, | |
294 fm->fd, 0); | |
295 if (fm->addr != MAP_FAILED) { | |
296 return NGX_OK; | |
297 } | |
298 | |
299 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
300 "mmap(%uz) \"%s\" failed", fm->size, fm->name); | |
301 | |
302 failed: | |
303 | |
304 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
305 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
306 ngx_close_file_n " \"%s\" failed", fm->name); | |
307 } | |
308 | |
309 return NGX_ERROR; | |
310 } | |
311 | |
312 | |
313 void | |
314 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
315 { | |
316 if (munmap(fm->addr, fm->size) == -1) { | |
317 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
318 "munmap(%uz) \"%s\" failed", fm->size, fm->name); | |
319 } | |
320 | |
321 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
322 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
323 ngx_close_file_n " \"%s\" failed", fm->name); | |
324 } | |
325 } | |
326 | |
327 | |
328 ngx_int_t | |
561 | 329 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
330 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
331 dir->dir = opendir((const char *) name->data); |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
332 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
333 if (dir->dir == NULL) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
334 return NGX_ERROR; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
335 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
336 |
457 | 337 dir->valid_info = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
338 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
339 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
340 } |
561 | 341 |
342 | |
727 | 343 ngx_int_t |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
344 ngx_read_dir(ngx_dir_t *dir) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
345 { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
346 dir->de = readdir(dir->dir); |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
347 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
348 if (dir->de) { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
349 #if (NGX_HAVE_D_TYPE) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
350 dir->type = dir->de->d_type; |
2550
5e87ddb4764f
XFS on Linux does not set dirent.d_type,
Igor Sysoev <igor@sysoev.ru>
parents:
2248
diff
changeset
|
351 #else |
3200
26784c34e8be
*) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents:
3164
diff
changeset
|
352 dir->type = 0; |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
353 #endif |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
354 return NGX_OK; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
355 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
356 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
357 return NGX_ERROR; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
358 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
359 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
360 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
361 ngx_int_t |
727 | 362 ngx_open_glob(ngx_glob_t *gl) |
363 { | |
1980 | 364 int n; |
365 | |
4943
1e2d5d3f9f6b
Core: removed GLOB_NOSORT glob option.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4938
diff
changeset
|
366 n = glob((char *) gl->pattern, 0, NULL, &gl->pglob); |
1980 | 367 |
368 if (n == 0) { | |
369 return NGX_OK; | |
370 } | |
371 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
372 #ifdef GLOB_NOMATCH |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
373 |
1980 | 374 if (n == GLOB_NOMATCH && gl->test) { |
727 | 375 return NGX_OK; |
376 } | |
377 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
378 #endif |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
379 |
727 | 380 return NGX_ERROR; |
381 } | |
382 | |
383 | |
384 ngx_int_t | |
385 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
386 { | |
2210
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
387 size_t count; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
388 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
389 #ifdef GLOB_NOMATCH |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
390 count = (size_t) gl->pglob.gl_pathc; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
391 #else |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
392 count = (size_t) gl->pglob.gl_matchc; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
393 #endif |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
394 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
395 if (gl->n < count) { |
727 | 396 |
397 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]); | |
398 name->data = (u_char *) gl->pglob.gl_pathv[gl->n]; | |
399 gl->n++; | |
400 | |
401 return NGX_OK; | |
402 } | |
403 | |
404 return NGX_DONE; | |
405 } | |
406 | |
407 | |
408 void | |
409 ngx_close_glob(ngx_glob_t *gl) | |
410 { | |
411 globfree(&gl->pglob); | |
412 } | |
413 | |
414 | |
611 | 415 ngx_err_t |
416 ngx_trylock_fd(ngx_fd_t fd) | |
561 | 417 { |
418 struct flock fl; | |
419 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
420 ngx_memzero(&fl, sizeof(struct flock)); |
611 | 421 fl.l_type = F_WRLCK; |
561 | 422 fl.l_whence = SEEK_SET; |
611 | 423 |
424 if (fcntl(fd, F_SETLK, &fl) == -1) { | |
425 return ngx_errno; | |
426 } | |
427 | |
428 return 0; | |
429 } | |
430 | |
431 | |
432 ngx_err_t | |
433 ngx_lock_fd(ngx_fd_t fd) | |
434 { | |
435 struct flock fl; | |
436 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
437 ngx_memzero(&fl, sizeof(struct flock)); |
561 | 438 fl.l_type = F_WRLCK; |
611 | 439 fl.l_whence = SEEK_SET; |
561 | 440 |
611 | 441 if (fcntl(fd, F_SETLKW, &fl) == -1) { |
442 return ngx_errno; | |
561 | 443 } |
444 | |
611 | 445 return 0; |
561 | 446 } |
447 | |
448 | |
611 | 449 ngx_err_t |
450 ngx_unlock_fd(ngx_fd_t fd) | |
561 | 451 { |
452 struct flock fl; | |
453 | |
4737
9acc1a5a5b9a
Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
454 ngx_memzero(&fl, sizeof(struct flock)); |
561 | 455 fl.l_type = F_UNLCK; |
611 | 456 fl.l_whence = SEEK_SET; |
561 | 457 |
611 | 458 if (fcntl(fd, F_SETLK, &fl) == -1) { |
459 return ngx_errno; | |
561 | 460 } |
461 | |
611 | 462 return 0; |
561 | 463 } |
2129 | 464 |
465 | |
4299
11e47bf300db
FreeBSD 10-current has recently gotten POSIX_FADV_* macros.
Maxim Konovalov <maxim@nginx.com>
parents:
4221
diff
changeset
|
466 #if (NGX_HAVE_POSIX_FADVISE) && !(NGX_HAVE_F_READAHEAD) |
3322
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
467 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
468 ngx_int_t |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
469 ngx_read_ahead(ngx_fd_t fd, size_t n) |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
470 { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
471 int err; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
472 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
473 err = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
474 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
475 if (err == 0) { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
476 return 0; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
477 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
478 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
479 ngx_set_errno(err); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
480 return NGX_FILE_ERROR; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
481 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
482 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
483 #endif |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
484 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
485 |
2129 | 486 #if (NGX_HAVE_O_DIRECT) |
487 | |
488 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
489 ngx_directio_on(ngx_fd_t fd) |
2129 | 490 { |
491 int flags; | |
492 | |
493 flags = fcntl(fd, F_GETFL); | |
494 | |
495 if (flags == -1) { | |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
496 return NGX_FILE_ERROR; |
2129 | 497 } |
498 | |
499 return fcntl(fd, F_SETFL, flags | O_DIRECT); | |
500 } | |
501 | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
502 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
503 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
504 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
505 { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
506 int flags; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
507 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
508 flags = fcntl(fd, F_GETFL); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
509 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
510 if (flags == -1) { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
511 return NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
512 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
513 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
514 return fcntl(fd, F_SETFL, flags & ~O_DIRECT); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
515 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
516 |
2129 | 517 #endif |
2615 | 518 |
519 | |
520 #if (NGX_HAVE_STATFS) | |
521 | |
522 size_t | |
523 ngx_fs_bsize(u_char *name) | |
524 { | |
525 struct statfs fs; | |
526 | |
527 if (statfs((char *) name, &fs) == -1) { | |
528 return 512; | |
529 } | |
530 | |
531 if ((fs.f_bsize % 512) != 0) { | |
532 return 512; | |
533 } | |
534 | |
535 return (size_t) fs.f_bsize; | |
536 } | |
537 | |
538 #elif (NGX_HAVE_STATVFS) | |
539 | |
540 size_t | |
541 ngx_fs_bsize(u_char *name) | |
542 { | |
543 struct statvfs fs; | |
544 | |
545 if (statvfs((char *) name, &fs) == -1) { | |
546 return 512; | |
547 } | |
548 | |
549 if ((fs.f_frsize % 512) != 0) { | |
550 return 512; | |
551 } | |
552 | |
553 return (size_t) fs.f_frsize; | |
554 } | |
555 | |
556 #else | |
557 | |
558 size_t | |
559 ngx_fs_bsize(u_char *name) | |
560 { | |
561 return 512; | |
562 } | |
563 | |
564 #endif |