src/core/ngx_file.h - nginx source code

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_FILE_H_INCLUDED_
  6. #define _NGX_FILE_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>


  9. struct ngx_file_s {
  10.     ngx_fd_t                   fd;
  11.     ngx_str_t                  name;
  12.     ngx_file_info_t            info;

  13.     off_t                      offset;
  14.     off_t                      sys_offset;

  15.     ngx_log_t                 *log;

  16. #if (NGX_THREADS || NGX_COMPAT)
  17.     ngx_int_t                (*thread_handler)(ngx_thread_task_t *task,
  18.                                                ngx_file_t *file);
  19.     void                      *thread_ctx;
  20.     ngx_thread_task_t         *thread_task;
  21. #endif

  22. #if (NGX_HAVE_FILE_AIO || NGX_COMPAT)
  23.     ngx_event_aio_t           *aio;
  24. #endif

  25.     unsigned                   valid_info:1;
  26.     unsigned                   directio:1;
  27. };


  28. #define NGX_MAX_PATH_LEVEL  3


  29. typedef ngx_msec_t (*ngx_path_manager_pt) (void *data);
  30. typedef ngx_msec_t (*ngx_path_purger_pt) (void *data);
  31. typedef void (*ngx_path_loader_pt) (void *data);


  32. typedef struct {
  33.     ngx_str_t                  name;
  34.     size_t                     len;
  35.     size_t                     level[NGX_MAX_PATH_LEVEL];

  36.     ngx_path_manager_pt        manager;
  37.     ngx_path_purger_pt         purger;
  38.     ngx_path_loader_pt         loader;
  39.     void                      *data;

  40.     u_char                    *conf_file;
  41.     ngx_uint_t                 line;
  42. } ngx_path_t;


  43. typedef struct {
  44.     ngx_str_t                  name;
  45.     size_t                     level[NGX_MAX_PATH_LEVEL];
  46. } ngx_path_init_t;


  47. typedef struct {
  48.     ngx_file_t                 file;
  49.     off_t                      offset;
  50.     ngx_path_t                *path;
  51.     ngx_pool_t                *pool;
  52.     char                      *warn;

  53.     ngx_uint_t                 access;

  54.     unsigned                   log_level:8;
  55.     unsigned                   persistent:1;
  56.     unsigned                   clean:1;
  57.     unsigned                   thread_write:1;
  58. } ngx_temp_file_t;


  59. typedef struct {
  60.     ngx_uint_t                 access;
  61.     ngx_uint_t                 path_access;
  62.     time_t                     time;
  63.     ngx_fd_t                   fd;

  64.     unsigned                   create_path:1;
  65.     unsigned                   delete_file:1;

  66.     ngx_log_t                 *log;
  67. } ngx_ext_rename_file_t;


  68. typedef struct {
  69.     off_t                      size;
  70.     size_t                     buf_size;

  71.     ngx_uint_t                 access;
  72.     time_t                     time;

  73.     ngx_log_t                 *log;
  74. } ngx_copy_file_t;


  75. typedef struct ngx_tree_ctx_s  ngx_tree_ctx_t;

  76. typedef ngx_int_t (*ngx_tree_init_handler_pt) (void *ctx, void *prev);
  77. typedef ngx_int_t (*ngx_tree_handler_pt) (ngx_tree_ctx_t *ctx, ngx_str_t *name);

  78. struct ngx_tree_ctx_s {
  79.     off_t                      size;
  80.     off_t                      fs_size;
  81.     ngx_uint_t                 access;
  82.     time_t                     mtime;

  83.     ngx_tree_init_handler_pt   init_handler;
  84.     ngx_tree_handler_pt        file_handler;
  85.     ngx_tree_handler_pt        pre_tree_handler;
  86.     ngx_tree_handler_pt        post_tree_handler;
  87.     ngx_tree_handler_pt        spec_handler;

  88.     void                      *data;
  89.     size_t                     alloc;

  90.     ngx_log_t                 *log;
  91. };


  92. ngx_int_t ngx_get_full_name(ngx_pool_t *pool, ngx_str_t *prefix,
  93.     ngx_str_t *name);

  94. ssize_t ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain);
  95. ngx_int_t ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
  96.     ngx_pool_t *pool, ngx_uint_t persistent, ngx_uint_t clean,
  97.     ngx_uint_t access);
  98. void ngx_create_hashed_filename(ngx_path_t *path, u_char *file, size_t len);
  99. ngx_int_t ngx_create_path(ngx_file_t *file, ngx_path_t *path);
  100. ngx_err_t ngx_create_full_path(u_char *dir, ngx_uint_t access);
  101. ngx_int_t ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot);
  102. ngx_int_t ngx_create_paths(ngx_cycle_t *cycle, ngx_uid_t user);
  103. ngx_int_t ngx_ext_rename_file(ngx_str_t *src, ngx_str_t *to,
  104.     ngx_ext_rename_file_t *ext);
  105. ngx_int_t ngx_copy_file(u_char *from, u_char *to, ngx_copy_file_t *cf);
  106. ngx_int_t ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree);

  107. ngx_atomic_uint_t ngx_next_temp_number(ngx_uint_t collision);

  108. char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
  109. char *ngx_conf_merge_path_value(ngx_conf_t *cf, ngx_path_t **path,
  110.     ngx_path_t *prev, ngx_path_init_t *init);
  111. char *ngx_conf_set_access_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);


  112. extern ngx_atomic_t      *ngx_temp_number;
  113. extern ngx_atomic_int_t   ngx_random_number;


  114. #endif /* _NGX_FILE_H_INCLUDED_ */