comparison src/os/win32/ngx_files.c @ 3651:515d50917016

ngx_create_file_mapping()
author Igor Sysoev <igor@sysoev.ru>
date Tue, 29 Jun 2010 15:18:50 +0000
parents 4b4385492f2a
children 4f4086cf1a07
comparison
equal deleted inserted replaced
3650:c12b0dd5bd1c 3651:515d50917016
330 330
331 return NGX_ERROR; 331 return NGX_ERROR;
332 } 332 }
333 333
334 334
335 ngx_int_t
336 ngx_create_file_mapping(ngx_file_mapping_t *fm)
337 {
338 LARGE_INTEGER size;
339
340 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE,
341 NGX_FILE_DEFAULT_ACCESS);
342 if (fm->fd == NGX_INVALID_FILE) {
343 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
344 ngx_open_file_n " \"%s\" failed", fm->name);
345 return NGX_ERROR;
346 }
347
348 fm->handle = NULL;
349
350 size.QuadPart = fm->size;
351
352 if (SetFilePointerEx(fm->fd, size, NULL, FILE_BEGIN) == 0) {
353 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
354 "SetFilePointerEx(\"%s\", %uz) failed",
355 fm->name, fm->size);
356 goto failed;
357 }
358
359 if (SetEndOfFile(fm->fd) == 0) {
360 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
361 "SetEndOfFile() \"%s\" failed", fm->name);
362 goto failed;
363 }
364
365 fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE,
366 (u_long) ((off_t) fm->size >> 32),
367 (u_long) ((off_t) fm->size & 0xffffffff),
368 NULL);
369 if (fm->handle == NULL) {
370 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
371 "CreateFileMapping(%s, %uz) failed",
372 fm->name, fm->size);
373 goto failed;
374 }
375
376 fm->addr = MapViewOfFile(fm->handle, FILE_MAP_WRITE, 0, 0, 0);
377
378 if (fm->addr != NULL) {
379 return NGX_OK;
380 }
381
382 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
383 "MapViewOfFile(%uz) of file mapping \"%s\" failed",
384 fm->size, fm->name);
385
386 failed:
387
388 if (fm->handle) {
389 if (CloseHandle(fm->handle) == 0) {
390 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
391 "CloseHandle() of file mapping \"%s\" failed",
392 fm->name);
393 }
394 }
395
396 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
397 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
398 ngx_close_file_n " \"%s\" failed", fm->name);
399 }
400
401 return NGX_ERROR;
402 }
403
404
405 void
406 ngx_close_file_mapping(ngx_file_mapping_t *fm)
407 {
408 if (UnmapViewOfFile(fm->addr) == 0) {
409 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
410 "UnmapViewOfFile(%p) of file mapping \"%s\" failed",
411 fm->addr, &fm->name);
412 }
413
414 if (CloseHandle(fm->handle) == 0) {
415 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
416 "CloseHandle() of file mapping \"%s\" failed",
417 &fm->name);
418 }
419
420 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
421 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
422 ngx_close_file_n " \"%s\" failed", fm->name);
423 }
424 }
425
426
335 char * 427 char *
336 ngx_realpath(u_char *path, u_char *resolved) 428 ngx_realpath(u_char *path, u_char *resolved)
337 { 429 {
338 /* STUB */ 430 /* STUB */
339 return (char *) path; 431 return (char *) path;