Mercurial > hg > nginx
annotate src/os/unix/ngx_files.c @ 2631:73571521c2eb
add debug logging
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 01 Apr 2009 13:01:50 +0000 |
parents | ceef364208c8 |
children | a2c1b4f74ea7 6b8284fc958d |
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 |
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
|
4 */ |
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 |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
33
b2e039840718
nginx-0.0.1-2002-12-19-20:49:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
7 #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
|
8 #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
|
9 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
10 |
561 | 11 ssize_t |
12 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
|
13 { |
561 | 14 ssize_t n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
16 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
461 | 17 "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
|
18 |
469 | 19 #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
|
20 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
21 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
|
22 |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
23 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
|
24 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
25 "pread() failed, file \"%s\"", 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
|
26 return NGX_ERROR; |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
27 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
28 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
29 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
30 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
31 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
|
32 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
33 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "lseek() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
34 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
35 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
36 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
37 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
|
38 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
39 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
40 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
|
41 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
42 if (n == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
43 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "read() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
44 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
45 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
46 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
47 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
|
48 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
49 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
50 |
35
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
51 file->offset += n; |
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
52 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
53 return n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 } |
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
56 |
561 | 57 ssize_t |
58 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
|
59 { |
561 | 60 ssize_t n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
61 |
461 | 62 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
63 "write: %d, %p, %uz, %O", file->fd, buf, size, offset); | |
64 | |
469 | 65 #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
|
66 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
67 n = pwrite(file->fd, buf, size, offset); |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
68 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
69 if (n == -1) { |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
70 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "pwrite() failed"); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
71 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
72 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
73 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
74 if ((size_t) n != size) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
75 ngx_log_error(NGX_LOG_CRIT, file->log, 0, |
461 | 76 "pwrite() has written only %z of %uz", n, size); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
77 return NGX_ERROR; |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
78 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
79 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
80 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
81 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
82 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
|
83 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
84 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "lseek() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
85 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
86 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
87 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
88 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
|
89 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
90 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
91 n = write(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
|
92 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
93 if (n == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
94 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "write() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
95 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
96 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
97 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
98 if ((size_t) n != size) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
99 ngx_log_error(NGX_LOG_CRIT, file->log, 0, |
461 | 100 "write() has written only %z of %uz", n, size); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
101 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
102 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
103 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
104 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
|
105 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
106 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
107 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
108 file->offset += n; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
109 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
110 return n; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
111 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
112 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
113 |
561 | 114 ngx_fd_t |
1046 | 115 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
|
116 { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
117 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
|
118 |
1046 | 119 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, |
120 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
|
121 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
122 if (fd != -1 && !persistent) { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
123 unlink((const char *) name); |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
124 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
125 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
126 return fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
127 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
128 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
129 |
461 | 130 #define NGX_IOVS 8 |
131 | |
561 | 132 ssize_t |
133 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
134 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
|
135 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
136 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
|
137 size_t size; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
138 ssize_t n; |
461 | 139 ngx_array_t vec; |
140 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
|
141 |
461 | 142 /* 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
|
143 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
144 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
|
145 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
|
146 (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
|
147 offset); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
148 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
149 |
461 | 150 vec.elts = iovs; |
151 vec.size = sizeof(struct iovec); | |
577 | 152 vec.nalloc = NGX_IOVS; |
461 | 153 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
|
154 |
461 | 155 do { |
156 prev = NULL; | |
157 iov = NULL; | |
158 size = 0; | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
159 |
461 | 160 vec.nelts = 0; |
161 | |
162 /* 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
|
163 |
461 | 164 while (cl && vec.nelts < IOV_MAX) { |
165 if (prev == cl->buf->pos) { | |
166 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
|
167 |
461 | 168 } else { |
501 | 169 iov = ngx_array_push(&vec); |
170 if (iov == NULL) { | |
461 | 171 return NGX_ERROR; |
172 } | |
173 | |
174 iov->iov_base = (void *) cl->buf->pos; | |
175 iov->iov_len = cl->buf->last - cl->buf->pos; | |
176 } | |
177 | |
178 size += cl->buf->last - cl->buf->pos; | |
179 prev = cl->buf->last; | |
180 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
|
181 } |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
182 |
461 | 183 /* 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
|
184 |
461 | 185 if (vec.nelts == 1) { |
186 iov = vec.elts; | |
187 return ngx_write_file(file, (u_char *) iov[0].iov_base, | |
188 iov[0].iov_len, offset); | |
189 } | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
190 |
461 | 191 if (file->sys_offset != offset) { |
192 if (lseek(file->fd, offset, SEEK_SET) == -1) { | |
193 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
194 "lseek() failed"); | |
195 return NGX_ERROR; | |
196 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
197 |
461 | 198 file->sys_offset = offset; |
199 } | |
200 | |
201 n = writev(file->fd, vec.elts, vec.nelts); | |
202 | |
203 if (n == -1) { | |
204 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
205 "writev() failed"); | |
154
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
206 return NGX_ERROR; |
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
207 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
208 |
461 | 209 if ((size_t) n != size) { |
210 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
211 "writev() has written only %z of %uz", n, size); | |
212 return NGX_ERROR; | |
213 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
214 |
461 | 215 file->sys_offset += n; |
216 file->offset += n; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
217 |
461 | 218 } while (cl); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
219 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
220 return n; |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
221 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
222 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
223 |
561 | 224 ngx_int_t |
681 | 225 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
226 { | |
227 struct timeval tv[2]; | |
228 | |
229 tv[0].tv_sec = s; | |
230 tv[0].tv_usec = 0; | |
231 tv[1].tv_sec = s; | |
232 tv[1].tv_usec = 0; | |
233 | |
234 if (utimes((char *) name, tv) != -1) { | |
235 return NGX_OK; | |
236 } | |
237 | |
238 return NGX_ERROR; | |
239 } | |
240 | |
241 | |
242 ngx_int_t | |
561 | 243 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
|
244 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
245 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
|
246 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
247 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
|
248 return NGX_ERROR; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
249 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
250 |
457 | 251 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
|
252 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
253 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
254 } |
561 | 255 |
256 | |
727 | 257 ngx_int_t |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
258 ngx_read_dir(ngx_dir_t *dir) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
259 { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
260 dir->de = readdir(dir->dir); |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
261 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
262 if (dir->de) { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
263 #if (NGX_HAVE_D_TYPE) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
264 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
|
265 dir->valid_type = dir->type ? 1 : 0; |
5e87ddb4764f
XFS on Linux does not set dirent.d_type,
Igor Sysoev <igor@sysoev.ru>
parents:
2248
diff
changeset
|
266 #else |
5e87ddb4764f
XFS on Linux does not set dirent.d_type,
Igor Sysoev <igor@sysoev.ru>
parents:
2248
diff
changeset
|
267 dir->valid_type = 0; |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
268 #endif |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
269 return NGX_OK; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
270 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
271 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
272 return NGX_ERROR; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
273 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
274 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
275 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
276 ngx_int_t |
727 | 277 ngx_open_glob(ngx_glob_t *gl) |
278 { | |
1980 | 279 int n; |
280 | |
281 n = glob((char *) gl->pattern, GLOB_NOSORT, NULL, &gl->pglob); | |
282 | |
283 if (n == 0) { | |
284 return NGX_OK; | |
285 } | |
286 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
287 #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
|
288 |
1980 | 289 if (n == GLOB_NOMATCH && gl->test) { |
727 | 290 return NGX_OK; |
291 } | |
292 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
293 #endif |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
294 |
727 | 295 return NGX_ERROR; |
296 } | |
297 | |
298 | |
299 ngx_int_t | |
300 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
301 { | |
2210
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
302 size_t count; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
303 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
304 #ifdef GLOB_NOMATCH |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
305 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
|
306 #else |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
307 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
|
308 #endif |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
309 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
310 if (gl->n < count) { |
727 | 311 |
312 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]); | |
313 name->data = (u_char *) gl->pglob.gl_pathv[gl->n]; | |
314 gl->n++; | |
315 | |
316 return NGX_OK; | |
317 } | |
318 | |
319 return NGX_DONE; | |
320 } | |
321 | |
322 | |
323 void | |
324 ngx_close_glob(ngx_glob_t *gl) | |
325 { | |
326 globfree(&gl->pglob); | |
327 } | |
328 | |
329 | |
611 | 330 ngx_err_t |
331 ngx_trylock_fd(ngx_fd_t fd) | |
561 | 332 { |
333 struct flock fl; | |
334 | |
611 | 335 fl.l_start = 0; |
336 fl.l_len = 0; | |
337 fl.l_pid = 0; | |
338 fl.l_type = F_WRLCK; | |
561 | 339 fl.l_whence = SEEK_SET; |
611 | 340 |
341 if (fcntl(fd, F_SETLK, &fl) == -1) { | |
342 return ngx_errno; | |
343 } | |
344 | |
345 return 0; | |
346 } | |
347 | |
348 | |
349 ngx_err_t | |
350 ngx_lock_fd(ngx_fd_t fd) | |
351 { | |
352 struct flock fl; | |
353 | |
354 fl.l_start = 0; | |
561 | 355 fl.l_len = 0; |
356 fl.l_pid = 0; | |
357 fl.l_type = F_WRLCK; | |
611 | 358 fl.l_whence = SEEK_SET; |
561 | 359 |
611 | 360 if (fcntl(fd, F_SETLKW, &fl) == -1) { |
361 return ngx_errno; | |
561 | 362 } |
363 | |
611 | 364 return 0; |
561 | 365 } |
366 | |
367 | |
611 | 368 ngx_err_t |
369 ngx_unlock_fd(ngx_fd_t fd) | |
561 | 370 { |
371 struct flock fl; | |
372 | |
611 | 373 fl.l_start = 0; |
561 | 374 fl.l_len = 0; |
375 fl.l_pid = 0; | |
376 fl.l_type = F_UNLCK; | |
611 | 377 fl.l_whence = SEEK_SET; |
561 | 378 |
611 | 379 if (fcntl(fd, F_SETLK, &fl) == -1) { |
380 return ngx_errno; | |
561 | 381 } |
382 | |
611 | 383 return 0; |
561 | 384 } |
2129 | 385 |
386 | |
387 #if (NGX_HAVE_O_DIRECT) | |
388 | |
389 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
390 ngx_directio_on(ngx_fd_t fd) |
2129 | 391 { |
392 int flags; | |
393 | |
394 flags = fcntl(fd, F_GETFL); | |
395 | |
396 if (flags == -1) { | |
397 return -1; | |
398 } | |
399 | |
400 return fcntl(fd, F_SETFL, flags | O_DIRECT); | |
401 } | |
402 | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
403 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
404 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
405 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
406 { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
407 int flags; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
408 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
409 flags = fcntl(fd, F_GETFL); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
410 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
411 if (flags == -1) { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
412 return -1; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
413 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
414 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
415 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
|
416 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
417 |
2129 | 418 #endif |
2615 | 419 |
420 | |
421 #if (NGX_HAVE_STATFS) | |
422 | |
423 size_t | |
424 ngx_fs_bsize(u_char *name) | |
425 { | |
426 struct statfs fs; | |
427 | |
428 if (statfs((char *) name, &fs) == -1) { | |
429 return 512; | |
430 } | |
431 | |
432 if ((fs.f_bsize % 512) != 0) { | |
433 return 512; | |
434 } | |
435 | |
436 return (size_t) fs.f_bsize; | |
437 } | |
438 | |
439 #elif (NGX_HAVE_STATVFS) | |
440 | |
441 size_t | |
442 ngx_fs_bsize(u_char *name) | |
443 { | |
444 struct statvfs fs; | |
445 | |
446 if (statvfs((char *) name, &fs) == -1) { | |
447 return 512; | |
448 } | |
449 | |
450 if ((fs.f_frsize % 512) != 0) { | |
451 return 512; | |
452 } | |
453 | |
454 return (size_t) fs.f_frsize; | |
455 } | |
456 | |
457 #else | |
458 | |
459 size_t | |
460 ngx_fs_bsize(u_char *name) | |
461 { | |
462 return 512; | |
463 } | |
464 | |
465 #endif |