# HG changeset patch # User Igor Sysoev # Date 1238398986 0 # Node ID ceef364208c8c2325e675c9e74346e787a3ff337 # Parent 02fb50962b11a9172a96daed740c4118ada69972 ngx_fs_bsize() diff --git a/auto/headers b/auto/headers --- a/auto/headers +++ b/auto/headers @@ -2,8 +2,10 @@ # Copyright (C) Igor Sysoev -ngx_include="unistd.h"; . auto/include -ngx_include="inttypes.h"; . auto/include -ngx_include="limits.h"; . auto/include -ngx_include="sys/filio.h"; . auto/include -ngx_include="crypt.h"; . auto/include +ngx_include="unistd.h"; . auto/include +ngx_include="inttypes.h"; . auto/include +ngx_include="limits.h"; . auto/include +ngx_include="sys/filio.h"; . auto/include +ngx_include="sys/mount.h"; . auto/include +ngx_include="sys/statvfs.h"; . auto/include +ngx_include="crypt.h"; . auto/include diff --git a/auto/os/features b/auto/os/features --- a/auto/os/features +++ b/auto/os/features @@ -205,3 +205,27 @@ ngx_feature_path= ngx_feature_libs= ngx_feature_test="directio(0, DIRECTIO_ON);" . auto/feature + + +ngx_feature="statfs()" +ngx_feature_name="NGX_HAVE_STATFS" +ngx_feature_run=no +ngx_feature_incs="$NGX_INCLUDE_SYS_MOUNT_H + $NGX_INCLUDE_SYS_VFS_H" +ngx_feature_path= +ngx_feature_libs= +ngx_feature_test="struct statfs fs; + statfs(NULL, &fs);" +. auto/feature + + +ngx_feature="statvfs()" +ngx_feature_name="NGX_HAVE_STATVFS" +ngx_feature_run=no +ngx_feature_incs="#include + #include " +ngx_feature_path= +ngx_feature_libs= +ngx_feature_test="struct statvfs fs; + statvfs(NULL, &fs);" +. auto/feature diff --git a/auto/os/linux b/auto/os/linux --- a/auto/os/linux +++ b/auto/os/linux @@ -124,4 +124,7 @@ ngx_feature_test="long mask = 0; . auto/feature +ngx_include="sys/vfs.h"; . auto/include + + CC_AUX_FLAGS=$cc_aux_flags diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c --- a/src/os/unix/ngx_files.c +++ b/src/os/unix/ngx_files.c @@ -416,3 +416,50 @@ ngx_directio_off(ngx_fd_t fd) } #endif + + +#if (NGX_HAVE_STATFS) + +size_t +ngx_fs_bsize(u_char *name) +{ + struct statfs fs; + + if (statfs((char *) name, &fs) == -1) { + return 512; + } + + if ((fs.f_bsize % 512) != 0) { + return 512; + } + + return (size_t) fs.f_bsize; +} + +#elif (NGX_HAVE_STATVFS) + +size_t +ngx_fs_bsize(u_char *name) +{ + struct statvfs fs; + + if (statvfs((char *) name, &fs) == -1) { + return 512; + } + + if ((fs.f_frsize % 512) != 0) { + return 512; + } + + return (size_t) fs.f_frsize; +} + +#else + +size_t +ngx_fs_bsize(u_char *name) +{ + return 512; +} + +#endif diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h --- a/src/os/unix/ngx_files.h +++ b/src/os/unix/ngx_files.h @@ -274,4 +274,7 @@ ngx_int_t ngx_directio_off(ngx_fd_t fd); #endif +size_t ngx_fs_bsize(u_char *name); + + #endif /* _NGX_FILES_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h --- a/src/os/unix/ngx_freebsd_config.h +++ b/src/os/unix/ngx_freebsd_config.h @@ -22,6 +22,7 @@ #include #include #include +#include /* statfs() */ #include /* FIONBIO */ #include diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -28,6 +28,7 @@ #include #include #include +#include /* statfs() */ #include #include diff --git a/src/os/unix/ngx_posix_config.h b/src/os/unix/ngx_posix_config.h --- a/src/os/unix/ngx_posix_config.h +++ b/src/os/unix/ngx_posix_config.h @@ -44,6 +44,12 @@ #include #include #include +#if (NGX_HAVE_SYS_MOUNT_H) +#include /* statfs() */ +#endif +#if (NGX_HAVE_SYS_STATVFS_H) +#include /* statvfs() */ +#endif #if (NGX_HAVE_SYS_FILIO_H) #include /* FIONBIO */ diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h --- a/src/os/unix/ngx_solaris_config.h +++ b/src/os/unix/ngx_solaris_config.h @@ -28,6 +28,7 @@ #include #include #include +#include /* statvfs() */ #include /* FIONBIO */ #include diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c @@ -504,8 +504,28 @@ ngx_directio_on(ngx_fd_t fd) return 0; } + ngx_int_t ngx_directio_off(ngx_fd_t fd) { return 0; } + + +size_t +ngx_fs_bsize(u_char *name) +{ + u_char root[4]; + u_long sc, bs, nfree, ncl; + + if (name[2] == ':') { + ngx_cpystrn(root, name, 4); + name = root; + } + + if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) { + return 512; + } + + return sc * bs; +} diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h --- a/src/os/win32/ngx_files.h +++ b/src/os/win32/ngx_files.h @@ -243,5 +243,7 @@ ngx_int_t ngx_directio_on(ngx_fd_t fd); ngx_int_t ngx_directio_off(ngx_fd_t fd); #define ngx_directio_off_n "ngx_directio_off_n" +size_t ngx_fs_bsize(u_char *name); + #endif /* _NGX_FILES_H_INCLUDED_ */