comparison src/os/win32/ngx_files.c @ 461:a88a3e4e158f release-0.1.5

nginx-0.1.5-RELEASE import *) Bugfix: on Solaris and Linux there may be too many "recvmsg() returned not enough data" alerts. *) Bugfix: there were the "writev() failed (22: Invalid argument)" errors on Solaris in proxy mode without sendfile. On other platforms that do not support sendfile at all the process got caught in an endless loop. *) Bugfix: segmentation fault on Solaris in proxy mode and using sendfile. *) Bugfix: segmentation fault on Solaris. *) Bugfix: on-line upgrade did not work on Linux. *) Bugfix: the ngx_http_autoindex_module module did not escape the spaces, the quotes, and the percent signs in the directory listing. *) Change: the decrease of the copy operations. *) Feature: the userid_p3p directive.
author Igor Sysoev <igor@sysoev.ru>
date Thu, 11 Nov 2004 14:07:14 +0000
parents ded1284520cc
children bbd6b0b4a2b1
comparison
equal deleted inserted replaced
460:5f8319142dfc 461:a88a3e4e158f
16 OVERLAPPED ovlp, *povlp; 16 OVERLAPPED ovlp, *povlp;
17 17
18 if (ngx_win32_version < NGX_WIN_NT) { 18 if (ngx_win32_version < NGX_WIN_NT) {
19 19
20 /* 20 /*
21 * in Win9X the overlapped pointer must be NULL 21 * under Win9X the overlapped pointer must be NULL
22 * so we need to use SetFilePointer() to set the offset 22 * so we have to use SetFilePointer() to set the offset
23 */ 23 */
24 24
25 if (file->offset != offset) { 25 if (file->offset != offset) {
26 26
27 /* 27 /*
28 * the maximum file size on FAT16 is 2G, but on FAT32 28 * the maximum file size on the FAT16 is 2G, but on the FAT32
29 * the size is 4G so we need to use high_offset 29 * the size is 4G so we have to use the high_offset
30 * because a single offset is signed value
31 */
32
33 high_offset = (long) (offset >> 32);
34
35 if (SetFilePointer(file->fd, (long) offset, &high_offset,
36 FILE_BEGIN) == INVALID_SET_FILE_POINTER)
37 {
38 /*
39 * INVALID_SET_FILE_POINTER is 0xffffffff and it can be valid
40 * value for large file so we need also to check GetLastError()
41 */
42
43 err = ngx_errno;
44 if (err != NO_ERROR) {
45 ngx_log_error(NGX_LOG_ERR, file->log, err,
46 "SeekFilePointer() failed");
47 return NGX_ERROR;
48 }
49 }
50 }
51
52 povlp = NULL;
53
54 } else {
55 ovlp.Internal = 0;
56 ovlp.InternalHigh = 0;
57 ovlp.Offset = (u_long) offset;
58 ovlp.OffsetHigh = (u_long) (offset >> 32);
59 ovlp.hEvent = NULL;
60
61 povlp = &ovlp;
62 }
63
64 if (ReadFile(file->fd, buf, size, &n, povlp) == 0) {
65 ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "ReadFile() failed");
66 return NGX_ERROR;
67 }
68
69 file->offset += n;
70
71 return n;
72 }
73
74
75 ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
76 {
77 long high_offset;
78 u_long n;
79 ngx_err_t err;
80 OVERLAPPED ovlp, *povlp;
81
82 if (ngx_win32_version < NGX_WIN_NT) {
83
84 /*
85 * under Win9X the overlapped pointer must be NULL
86 * so we have to use SetFilePointer() to set the offset
87 */
88
89 if (file->offset != offset) {
90
91 /*
92 * the maximum file size on the FAT16 is 2G, but on the FAT32
93 * the size is 4G so we have to use high_offset
30 * because a single offset is signed value 94 * because a single offset is signed value
31 */ 95 */
32 96
33 high_offset = (long) (offset >> 32); 97 high_offset = (long) (offset >> 32);
34 if (SetFilePointer(file->fd, (long) offset, &high_offset, 98 if (SetFilePointer(file->fd, (long) offset, &high_offset,
58 ovlp.hEvent = NULL; 122 ovlp.hEvent = NULL;
59 123
60 povlp = &ovlp; 124 povlp = &ovlp;
61 } 125 }
62 126
63 if (ReadFile(file->fd, buf, size, &n, povlp) == 0) {
64 ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "ReadFile() failed");
65 return NGX_ERROR;
66 }
67
68 file->offset += n;
69
70 return n;
71 }
72
73
74 ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
75 {
76 long high_offset;
77 u_long n;
78 ngx_err_t err;
79 OVERLAPPED ovlp, *povlp;
80
81 if (ngx_win32_version < NGX_WIN_NT) {
82
83 /*
84 * in Win9X the overlapped pointer must be NULL
85 * so we need to use SetFilePointer() to set the offset
86 */
87
88 if (file->offset != offset) {
89
90 /*
91 * the maximum file size on FAT16 is 2G, but on FAT32
92 * the size is 4G so we need to use high_offset
93 * because a single offset is signed value
94 */
95
96 high_offset = (long) (offset >> 32);
97 if (SetFilePointer(file->fd, (long) offset, &high_offset,
98 FILE_BEGIN) == INVALID_SET_FILE_POINTER)
99 {
100 /*
101 * INVALID_SET_FILE_POINTER is 0xffffffff and it can be valid
102 * value for large file so we need also to check GetLastError()
103 */
104
105 err = ngx_errno;
106 if (err != NO_ERROR) {
107 ngx_log_error(NGX_LOG_ERR, file->log, err,
108 "SeekFilePointer() failed");
109 return NGX_ERROR;
110 }
111 }
112 }
113
114 povlp = NULL;
115
116 } else {
117 ovlp.Internal = 0;
118 ovlp.InternalHigh = 0;
119 ovlp.Offset = (u_long) offset;
120 ovlp.OffsetHigh = (u_long) (offset >> 32);
121 ovlp.hEvent = NULL;
122
123 povlp = &ovlp;
124 }
125
126 if (WriteFile(file->fd, buf, size, &n, povlp) == 0) { 127 if (WriteFile(file->fd, buf, size, &n, povlp) == 0) {
127 ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "WriteFile() failed"); 128 ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, "WriteFile() failed");
128 return NGX_ERROR; 129 return NGX_ERROR;
129 } 130 }
130 131
187 /* mutex_lock() (per cache or single ?) */ 188 /* mutex_lock() (per cache or single ?) */
188 189
189 do { 190 do {
190 num = ngx_next_temp_number(collision); 191 num = ngx_next_temp_number(collision);
191 192
192 ngx_snprintf((char *) name + to->len, 1 + 10 + 1 + sizeof("DELETE"), 193 ngx_sprintf(name + to->len, ".%010u.DELETE", num);
193 ".%010u.DELETE", num);
194 194
195 if (MoveFile((const char *) to->data, (const char *) name) == 0) { 195 if (MoveFile((const char *) to->data, (const char *) name) == 0) {
196 collision = 1; 196 collision = 1;
197 ngx_log_error(NGX_LOG_ERR, pool->log, ngx_errno, 197 ngx_log_error(NGX_LOG_ERR, pool->log, ngx_errno,
198 "MoveFile() failed"); 198 "MoveFile() failed");