]> git.kaiwu.me - nginx.git/commitdiff
ngx_fs_bsize()
authorIgor Sysoev <igor@sysoev.ru>
Mon, 30 Mar 2009 07:43:06 +0000 (07:43 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 30 Mar 2009 07:43:06 +0000 (07:43 +0000)
auto/headers
auto/os/features
auto/os/linux
src/os/unix/ngx_files.c
src/os/unix/ngx_files.h
src/os/unix/ngx_freebsd_config.h
src/os/unix/ngx_linux_config.h
src/os/unix/ngx_posix_config.h
src/os/unix/ngx_solaris_config.h
src/os/win32/ngx_files.c
src/os/win32/ngx_files.h

index 542b757c1391f2cb18e9bc82d1d2ef15322ffac6..cdd5d294bef8114ddd8044ab523c8430182429a2 100644 (file)
@@ -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
index ecb210da6a418d43b95f9502b6296bf201c7a845..f00663c8879cd03b5652c0c7a65c9be507278219 100644 (file)
@@ -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 <sys/types.h>
+                  #include <sys/statvfs.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="struct statvfs  fs;
+                  statvfs(NULL, &fs);"
+. auto/feature
index 698886fa846b8e451a19bf1a330beca695635eed..43ff3c9e2e25252ddb6bbfe16532e68fdf5f1ac1 100644 (file)
@@ -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
index 1203989b64422f4fa20fc2461f240ba7221d92ea..98ed0822966316806748148711870ace9edae86d 100644 (file)
@@ -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
index 21e5ff45c6d2ec347563c694851a86da6ddcc6b7..dcd14c35f248a112bdc43d981937c4f5212fc0f1 100644 (file)
@@ -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_ */
index 24dcdcb468ea076f9cca89b47f1b2f6338711e81..377148602963107aed68419a9d1108c490973177 100644 (file)
@@ -22,6 +22,7 @@
 #include <grp.h>
 #include <dirent.h>
 #include <glob.h>
+#include <sys/mount.h>          /* statfs() */
 
 #include <sys/filio.h>          /* FIONBIO */
 #include <sys/uio.h>
index bf2eae89276a516b94397642188185306b84785d..abeda08af87e806eb6517c4c5f17d435c876e21c 100644 (file)
@@ -28,6 +28,7 @@
 #include <grp.h>
 #include <dirent.h>
 #include <glob.h>
+#include <sys/vfs.h>            /* statfs() */
 
 #include <sys/uio.h>
 #include <sys/stat.h>
index ec7ee944f0b27a67103105736fe2bc19df481d3b..152e23238c1af088914f4f9e7f8160d7fac274f1 100644 (file)
 #include <grp.h>
 #include <dirent.h>
 #include <glob.h>
+#if (NGX_HAVE_SYS_MOUNT_H)
+#include <sys/mount.h>          /* statfs() */
+#endif
+#if (NGX_HAVE_SYS_STATVFS_H)
+#include <sys/statvfs.h>        /* statvfs() */
+#endif
 
 #if (NGX_HAVE_SYS_FILIO_H)
 #include <sys/filio.h>          /* FIONBIO */
index 989a30e2c6374146d5f16e84d43ffe7874b9053a..663f26570623a57a1185bc04c8c8d292a1dea828 100644 (file)
@@ -28,6 +28,7 @@
 #include <grp.h>
 #include <dirent.h>
 #include <glob.h>
+#include <sys/statvfs.h>        /* statvfs() */
 
 #include <sys/filio.h>          /* FIONBIO */
 #include <sys/uio.h>
index eff843ab79836ec84572eac3e1c02ce5b86b5bbb..afe31b9a086723155c8c01e565530963fdbd6937 100644 (file)
@@ -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;
+}
index b8487920ff389ac3e7b0ff7ba94155ba5a824ecd..47a76611b230f58f931cd4d19cbeb27020c07d57 100644 (file)
@@ -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_ */