annotate src/os/unix/ngx_files.c @ 6421:3832b608dc8d

Introduced the ngx_chain_to_iovec() function. It's similar to ngx_output_chain_to_iovec() and uses only preallocated memory.
author Valentin Bartenev <vbart@nginx.com>
date Thu, 03 Mar 2016 18:41:05 +0300
parents b5a87b51be24
children 9fd738b85fad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4299
diff changeset
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
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
12 #if (NGX_THREADS)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
13 #include <ngx_thread_pool.h>
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
14 static void ngx_thread_read_handler(void *data, ngx_log_t *log);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
15 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
16
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
17 static ngx_chain_t *ngx_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *cl);
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
18 static ssize_t ngx_writev_file(ngx_file_t *file, ngx_iovec_t *vec,
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
19 off_t offset);
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
20
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
21
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
22 #if (NGX_HAVE_FILE_AIO)
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
23
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
24 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
25
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
26 #endif
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
27
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
28
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
29 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
30 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
31 {
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
32 ssize_t n;
5
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 196
diff changeset
34 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
35 "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
36
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
37 #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
38
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
39 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
40
9
6f58641241bb nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
41 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
42 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
43 "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
44 return NGX_ERROR;
6f58641241bb nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
45 }
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
46
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
47 #else
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
48
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
49 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
50 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
51 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
52 "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
53 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
54 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
55
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
56 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
57 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
58
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
59 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
60
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
61 if (n == -1) {
3157
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
62 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
63 "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
64 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
65 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
66
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
67 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
68
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
69 #endif
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
70
35
79c1fce18e71 nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 33
diff changeset
71 file->offset += n;
79c1fce18e71 nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 33
diff changeset
72
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
73 return n;
5
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 }
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
76
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
77 #if (NGX_THREADS)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
78
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
79 typedef struct {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
80 ngx_fd_t fd;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
81 u_char *buf;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
82 size_t size;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
83 off_t offset;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
84
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
85 size_t read;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
86 ngx_err_t err;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
87 } ngx_thread_read_ctx_t;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
88
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
89
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
90 ssize_t
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
91 ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
92 size_t size, off_t offset, ngx_pool_t *pool)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
93 {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
94 ngx_thread_task_t *task;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
95 ngx_thread_read_ctx_t *ctx;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
96
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
97 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
98 "thread read: %d, %p, %uz, %O",
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
99 file->fd, buf, size, offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
100
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
101 task = *taskp;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
102
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
103 if (task == NULL) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
104 task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t));
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
105 if (task == NULL) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
106 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
107 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
108
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
109 task->handler = ngx_thread_read_handler;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
110
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
111 *taskp = task;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
112 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
113
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
114 ctx = task->ctx;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
115
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
116 if (task->event.complete) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
117 task->event.complete = 0;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
118
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
119 if (ctx->err) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
120 ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
121 "pread() \"%s\" failed", file->name.data);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
122 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
123 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
124
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
125 return ctx->read;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
126 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
127
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
128 ctx->fd = file->fd;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
129 ctx->buf = buf;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
130 ctx->size = size;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
131 ctx->offset = offset;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
132
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
133 if (file->thread_handler(task, file) != NGX_OK) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
134 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
135 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
136
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
137 return NGX_AGAIN;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
138 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
139
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
140
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
141 #if (NGX_HAVE_PREAD)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
142
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
143 static void
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
144 ngx_thread_read_handler(void *data, ngx_log_t *log)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
145 {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
146 ngx_thread_read_ctx_t *ctx = data;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
147
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
148 ssize_t n;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
149
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
150 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "thread read handler");
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
151
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
152 n = pread(ctx->fd, ctx->buf, ctx->size, ctx->offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
153
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
154 if (n == -1) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
155 ctx->err = ngx_errno;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
156
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
157 } else {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
158 ctx->read = n;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
159 ctx->err = 0;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
160 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
161
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
162 #if 0
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
163 ngx_time_update();
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
164 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
165
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
166 ngx_log_debug4(NGX_LOG_DEBUG_CORE, log, 0,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
167 "pread: %z (err: %i) of %uz @%O",
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
168 n, ctx->err, ctx->size, ctx->offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
169 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
170
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
171 #else
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
172
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
173 #error pread() is required!
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
174
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
175 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
176
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
177 #endif /* NGX_THREADS */
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
178
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
179
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
180 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
181 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
182 {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
183 ssize_t n, written;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
184 ngx_err_t err;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
185
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
186 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
187 "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
188
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
189 written = 0;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
190
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
191 #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
192
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
193 for ( ;; ) {
3657
fbd7dad43a4e fix ngx_write_file() buf
Igor Sysoev <igor@sysoev.ru>
parents: 3651
diff changeset
194 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
195
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
196 if (n == -1) {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
197 err = ngx_errno;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
198
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
199 if (err == NGX_EINTR) {
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
200 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
201 "pwrite() was interrupted");
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
202 continue;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
203 }
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
204
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
205 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
206 "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
207 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
208 }
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
209
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
210 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
211 written += n;
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
212
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
213 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
214 return written;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
215 }
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
216
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
217 offset += n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
218 size -= n;
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
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
221 #else
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
222
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
223 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
224 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
225 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
226 "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
227 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
228 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
229
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
230 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
231 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
232
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
233 for ( ;; ) {
3657
fbd7dad43a4e fix ngx_write_file() buf
Igor Sysoev <igor@sysoev.ru>
parents: 3651
diff changeset
234 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
235
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
236 if (n == -1) {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
237 err = ngx_errno;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
238
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
239 if (err == NGX_EINTR) {
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
240 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
241 "write() was interrupted");
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
242 continue;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
243 }
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
244
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
245 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
246 "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
247 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
248 }
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
249
6298
8f6d753c1953 Adjusted file->sys_offset after the write() syscall.
Valentin Bartenev <vbart@nginx.com>
parents: 6241
diff changeset
250 file->sys_offset += n;
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
251 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
252 written += n;
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
253
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
254 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
255 return written;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
256 }
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
257
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
258 size -= n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
259 }
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
260 #endif
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
261 }
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
262
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
263
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
264 ngx_fd_t
1046
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
265 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
266 {
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
267 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
268
1046
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
269 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR,
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
270 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
271
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
272 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
273 (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
274 }
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
275
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
276 return fd;
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
277 }
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
278
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
279
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
280 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
281 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
282 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
283 {
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
284 ssize_t total, n;
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
285 ngx_iovec_t vec;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
286 struct iovec iovs[NGX_IOVS_PREALLOCATE];
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
287
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
288 /* 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
289
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
290 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
291 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
292 (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
293 offset);
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
294 }
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
295
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
296 total = 0;
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
297
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
298 vec.iovs = iovs;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
299 vec.nalloc = NGX_IOVS_PREALLOCATE;
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
300
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
301 do {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
302 /* create the iovec and coalesce the neighbouring bufs */
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
303 cl = ngx_chain_to_iovec(&vec, cl);
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
304
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
305 /* 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
306
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
307 if (vec.count == 1) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
308 n = ngx_write_file(file, (u_char *) iovs[0].iov_base,
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
309 iovs[0].iov_len, offset);
4221
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
310
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
311 if (n == NGX_ERROR) {
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
312 return n;
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
313 }
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
314
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
315 return total + n;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
316 }
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
317
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
318 n = ngx_writev_file(file, &vec, offset);
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
319
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
320 if (n == NGX_ERROR) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
321 return n;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
322 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
323
4938
64ffc28850bb Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4919
diff changeset
324 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
325 total += n;
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
326
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
327 } while (cl);
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
328
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
329 return total;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
330 }
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
331
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
332
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
333 static ngx_chain_t *
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
334 ngx_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *cl)
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
335 {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
336 size_t total, size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
337 u_char *prev;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
338 ngx_uint_t n;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
339 struct iovec *iov;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
340
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
341 iov = NULL;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
342 prev = NULL;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
343 total = 0;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
344 n = 0;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
345
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
346 for ( /* void */ ; cl; cl = cl->next) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
347 size = cl->buf->last - cl->buf->pos;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
348
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
349 if (prev == cl->buf->pos) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
350 iov->iov_len += size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
351
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
352 } else {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
353 if (n == vec->nalloc) {
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
354 break;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
355 }
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
356
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
357 iov = &vec->iovs[n++];
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
358
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
359 iov->iov_base = (void *) cl->buf->pos;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
360 iov->iov_len = size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
361 }
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
362
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
363 prev = cl->buf->pos + size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
364 total += size;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
365 }
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
366
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
367 vec->count = n;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
368 vec->size = total;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
369
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
370 return cl;
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
371 }
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
372
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
373
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
374 static ssize_t
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
375 ngx_writev_file(ngx_file_t *file, ngx_iovec_t *vec, off_t offset)
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
376 {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
377 ssize_t n;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
378 ngx_err_t err;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
379
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
380 ngx_log_debug3(NGX_LOG_DEBUG_CORE, file->log, 0,
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
381 "writev: %d, %uz, %O", file->fd, vec->size, offset);
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
382
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
383 #if (NGX_HAVE_PWRITEV)
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
384
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
385 eintr:
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
386
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
387 n = pwritev(file->fd, vec->iovs, vec->count, offset);
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
388
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
389 if (n == -1) {
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
390 err = ngx_errno;
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
391
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
392 if (err == NGX_EINTR) {
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
393 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
394 "pwritev() was interrupted");
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
395 goto eintr;
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
396 }
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
397
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
398 ngx_log_error(NGX_LOG_CRIT, file->log, err,
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
399 "pwritev() \"%s\" failed", file->name.data);
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
400 return NGX_ERROR;
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
401 }
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
402
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
403 if ((size_t) n != vec->size) {
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
404 ngx_log_error(NGX_LOG_CRIT, file->log, 0,
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
405 "pwritev() \"%s\" has written only %z of %uz",
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
406 file->name.data, n, vec->size);
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
407 return NGX_ERROR;
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
408 }
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
409
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
410 #else
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
411
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
412 if (file->sys_offset != offset) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
413 if (lseek(file->fd, offset, SEEK_SET) == -1) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
414 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
415 "lseek() \"%s\" failed", file->name.data);
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
416 return NGX_ERROR;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
417 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
418
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
419 file->sys_offset = offset;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
420 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
421
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
422 eintr:
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
423
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
424 n = writev(file->fd, vec->iovs, vec->count);
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
425
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
426 if (n == -1) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
427 err = ngx_errno;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
428
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
429 if (err == NGX_EINTR) {
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
430 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
431 "writev() was interrupted");
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
432 goto eintr;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
433 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
434
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
435 ngx_log_error(NGX_LOG_CRIT, file->log, err,
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
436 "writev() \"%s\" failed", file->name.data);
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
437 return NGX_ERROR;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
438 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
439
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
440 if ((size_t) n != vec->size) {
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
441 ngx_log_error(NGX_LOG_CRIT, file->log, 0,
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
442 "writev() \"%s\" has written only %z of %uz",
6421
3832b608dc8d Introduced the ngx_chain_to_iovec() function.
Valentin Bartenev <vbart@nginx.com>
parents: 6301
diff changeset
443 file->name.data, n, vec->size);
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
444 return NGX_ERROR;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
445 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
446
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
447 file->sys_offset += n;
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
448
6301
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
449 #endif
b5a87b51be24 Used the pwritev() syscall for writing files where possible.
Valentin Bartenev <vbart@nginx.com>
parents: 6300
diff changeset
450
6300
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
451 file->offset += n;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
452
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
453 return n;
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
454 }
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
455
be6af0906a4d Moved file writev() handling code to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 6299
diff changeset
456
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
457 ngx_int_t
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
458 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s)
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
459 {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
460 struct timeval tv[2];
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
461
3861
cf80c0b0109a set current atime while setting mtime
Igor Sysoev <igor@sysoev.ru>
parents: 3657
diff changeset
462 tv[0].tv_sec = ngx_time();
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
463 tv[0].tv_usec = 0;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
464 tv[1].tv_sec = s;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
465 tv[1].tv_usec = 0;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
466
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
467 if (utimes((char *) name, tv) != -1) {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
468 return NGX_OK;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
469 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
470
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
471 return NGX_ERROR;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
472 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
473
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
474
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
475 ngx_int_t
3651
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
476 ngx_create_file_mapping(ngx_file_mapping_t *fm)
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
477 {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
478 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
479 NGX_FILE_DEFAULT_ACCESS);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
480 if (fm->fd == NGX_INVALID_FILE) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
481 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
482 ngx_open_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
483 return NGX_ERROR;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
484 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
485
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
486 if (ftruncate(fm->fd, fm->size) == -1) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
487 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
488 "ftruncate() \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
489 goto failed;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
490 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
491
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
492 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
493 fm->fd, 0);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
494 if (fm->addr != MAP_FAILED) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
495 return NGX_OK;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
496 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
497
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
498 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
499 "mmap(%uz) \"%s\" failed", fm->size, fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
500
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
501 failed:
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
502
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
503 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
504 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
505 ngx_close_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
506 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
507
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
508 return NGX_ERROR;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
509 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
510
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
511
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
512 void
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
513 ngx_close_file_mapping(ngx_file_mapping_t *fm)
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
514 {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
515 if (munmap(fm->addr, fm->size) == -1) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
516 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
517 "munmap(%uz) \"%s\" failed", fm->size, fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
518 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
519
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
520 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
521 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
522 ngx_close_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
523 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
524 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
525
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
526
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
527 ngx_int_t
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
528 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
529 {
290
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 278
diff changeset
530 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
531
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
532 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
533 return NGX_ERROR;
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
534 }
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
535
457
ded1284520cc nginx-0.1.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
536 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
537
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
538 return NGX_OK;
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
539 }
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
540
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
541
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
542 ngx_int_t
2234
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
543 ngx_read_dir(ngx_dir_t *dir)
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
544 {
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
545 dir->de = readdir(dir->dir);
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
546
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
547 if (dir->de) {
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
548 #if (NGX_HAVE_D_TYPE)
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
549 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
550 #else
3200
26784c34e8be *) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents: 3164
diff changeset
551 dir->type = 0;
2234
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
552 #endif
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
553 return NGX_OK;
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
554 }
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
555
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
556 return NGX_ERROR;
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
557 }
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
558
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
559
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
560 ngx_int_t
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
561 ngx_open_glob(ngx_glob_t *gl)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
562 {
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
563 int n;
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
564
4943
1e2d5d3f9f6b Core: removed GLOB_NOSORT glob option.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4938
diff changeset
565 n = glob((char *) gl->pattern, 0, NULL, &gl->pglob);
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
566
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
567 if (n == 0) {
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
568 return NGX_OK;
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
569 }
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
570
2199
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
571 #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
572
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
573 if (n == GLOB_NOMATCH && gl->test) {
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
574 return NGX_OK;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
575 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
576
2199
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
577 #endif
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
578
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
579 return NGX_ERROR;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
580 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
581
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
582
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
583 ngx_int_t
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
584 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
585 {
2210
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
586 size_t count;
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
587
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
588 #ifdef GLOB_NOMATCH
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
589 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
590 #else
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
591 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
592 #endif
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
593
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
594 if (gl->n < count) {
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
595
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
596 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]);
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
597 name->data = (u_char *) gl->pglob.gl_pathv[gl->n];
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
598 gl->n++;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
599
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
600 return NGX_OK;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
601 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
602
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
603 return NGX_DONE;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
604 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
605
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
606
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
607 void
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
608 ngx_close_glob(ngx_glob_t *gl)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
609 {
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
610 globfree(&gl->pglob);
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
611 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
612
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
613
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
614 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
615 ngx_trylock_fd(ngx_fd_t fd)
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
616 {
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
617 struct flock fl;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
618
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
619 ngx_memzero(&fl, sizeof(struct flock));
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
620 fl.l_type = F_WRLCK;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
621 fl.l_whence = SEEK_SET;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
622
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
623 if (fcntl(fd, F_SETLK, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
624 return ngx_errno;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
625 }
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
626
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
627 return 0;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
628 }
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
629
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
630
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
631 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
632 ngx_lock_fd(ngx_fd_t fd)
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
633 {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
634 struct flock fl;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
635
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
636 ngx_memzero(&fl, sizeof(struct flock));
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
637 fl.l_type = F_WRLCK;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
638 fl.l_whence = SEEK_SET;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
639
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
640 if (fcntl(fd, F_SETLKW, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
641 return ngx_errno;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
642 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
643
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
644 return 0;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
645 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
646
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
647
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
648 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
649 ngx_unlock_fd(ngx_fd_t fd)
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
650 {
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
651 struct flock fl;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
652
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
653 ngx_memzero(&fl, sizeof(struct flock));
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
654 fl.l_type = F_UNLCK;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
655 fl.l_whence = SEEK_SET;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
656
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
657 if (fcntl(fd, F_SETLK, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
658 return ngx_errno;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
659 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
660
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
661 return 0;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
662 }
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
663
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
664
4299
11e47bf300db FreeBSD 10-current has recently gotten POSIX_FADV_* macros.
Maxim Konovalov <maxim@nginx.com>
parents: 4221
diff changeset
665 #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
666
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
667 ngx_int_t
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
668 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
669 {
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
670 int err;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
671
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
672 err = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
673
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
674 if (err == 0) {
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
675 return 0;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
676 }
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
677
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
678 ngx_set_errno(err);
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
679 return NGX_FILE_ERROR;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
680 }
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
681
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
682 #endif
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
683
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
684
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
685 #if (NGX_HAVE_O_DIRECT)
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
686
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
687 ngx_int_t
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
688 ngx_directio_on(ngx_fd_t fd)
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
689 {
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
690 int flags;
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
691
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
692 flags = fcntl(fd, F_GETFL);
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
693
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
694 if (flags == -1) {
3164
b1b1775698d5 uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents: 3163
diff changeset
695 return NGX_FILE_ERROR;
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
696 }
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
697
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
698 return fcntl(fd, F_SETFL, flags | O_DIRECT);
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
699 }
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
700
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
701
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
702 ngx_int_t
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
703 ngx_directio_off(ngx_fd_t fd)
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
704 {
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
705 int flags;
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
706
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
707 flags = fcntl(fd, F_GETFL);
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
708
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
709 if (flags == -1) {
3164
b1b1775698d5 uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents: 3163
diff changeset
710 return NGX_FILE_ERROR;
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
711 }
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
712
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
713 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
714 }
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
715
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
716 #endif
2615
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
717
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
718
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
719 #if (NGX_HAVE_STATFS)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
720
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
721 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
722 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
723 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
724 struct statfs fs;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
725
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
726 if (statfs((char *) name, &fs) == -1) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
727 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
728 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
729
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
730 if ((fs.f_bsize % 512) != 0) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
731 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
732 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
733
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
734 return (size_t) fs.f_bsize;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
735 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
736
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
737 #elif (NGX_HAVE_STATVFS)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
738
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
739 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
740 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
741 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
742 struct statvfs fs;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
743
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
744 if (statvfs((char *) name, &fs) == -1) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
745 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
746 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
747
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
748 if ((fs.f_frsize % 512) != 0) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
749 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
750 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
751
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
752 return (size_t) fs.f_frsize;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
753 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
754
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
755 #else
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
756
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
757 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
758 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
759 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
760 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
761 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
762
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
763 #endif