aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-03-30 07:43:06 +0000
committerIgor Sysoev <igor@sysoev.ru>2009-03-30 07:43:06 +0000
commit1be7419d10a4c2226783f280af9e2aa7ff48b738 (patch)
treeab1c63ea9b9edb9c1eddcc93c5c572230694ce4e /src
parenta1e9bfbc859490e25f4fff07ddc5441c9a91abcc (diff)
downloadnginx-1be7419d10a4c2226783f280af9e2aa7ff48b738.tar.gz
nginx-1be7419d10a4c2226783f280af9e2aa7ff48b738.zip
ngx_fs_bsize()
Diffstat (limited to 'src')
-rw-r--r--src/os/unix/ngx_files.c47
-rw-r--r--src/os/unix/ngx_files.h3
-rw-r--r--src/os/unix/ngx_freebsd_config.h1
-rw-r--r--src/os/unix/ngx_linux_config.h1
-rw-r--r--src/os/unix/ngx_posix_config.h6
-rw-r--r--src/os/unix/ngx_solaris_config.h1
-rw-r--r--src/os/win32/ngx_files.c20
-rw-r--r--src/os/win32/ngx_files.h2
8 files changed, 81 insertions, 0 deletions
diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c
index 1203989b6..98ed08229 100644
--- 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
index 21e5ff45c..dcd14c35f 100644
--- 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
index 24dcdcb46..377148602 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -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>
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index bf2eae892..abeda08af 100644
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -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>
diff --git a/src/os/unix/ngx_posix_config.h b/src/os/unix/ngx_posix_config.h
index ec7ee944f..152e23238 100644
--- a/src/os/unix/ngx_posix_config.h
+++ b/src/os/unix/ngx_posix_config.h
@@ -44,6 +44,12 @@
#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 */
diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h
index 989a30e2c..663f26570 100644
--- a/src/os/unix/ngx_solaris_config.h
+++ b/src/os/unix/ngx_solaris_config.h
@@ -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>
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index eff843ab7..afe31b9a0 100644
--- 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
index b8487920f..47a76611b 100644
--- 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_ */