summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2023-02-23 20:50:03 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2023-02-23 20:50:03 +0300
commit4ace957c4e08bcbf9ef5e9f83b8e43458bead77f (patch)
tree60ad405a704880d349ab2d819dc8a3640df42234
parent6c5fe80bc69b12cc2bd0e8ed7bc67b240795f66b (diff)
downloadnginx-4ace957c4e08bcbf9ef5e9f83b8e43458bead77f.tar.gz
Win32: non-ASCII names in ngx_fs_bsize(), ngx_fs_available().
This fixes potentially incorrect cache size calculations and non-working "min_free" when using cache in directories with non-ASCII names.
-rw-r--r--src/os/win32/ngx_files.c46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index 3e0037859..90644ad9c 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -967,12 +967,31 @@ ngx_directio_off(ngx_fd_t fd)
size_t
ngx_fs_bsize(u_char *name)
{
- u_long sc, bs, nfree, ncl;
+ u_long sc, bs, nfree, ncl;
+ size_t len;
+ u_short *u;
+ u_short utf16[NGX_UTF16_BUFLEN];
+
+ len = NGX_UTF16_BUFLEN;
+ u = ngx_utf8_to_utf16(utf16, name, &len, 0);
+
+ if (u == NULL) {
+ return 512;
+ }
+
+ if (GetDiskFreeSpaceW(u, &sc, &bs, &nfree, &ncl) == 0) {
+
+ if (u != utf16) {
+ ngx_free(u);
+ }
- if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) {
return 512;
}
+ if (u != utf16) {
+ ngx_free(u);
+ }
+
return sc * bs;
}
@@ -980,12 +999,31 @@ ngx_fs_bsize(u_char *name)
off_t
ngx_fs_available(u_char *name)
{
- ULARGE_INTEGER navail;
+ size_t len;
+ u_short *u;
+ ULARGE_INTEGER navail;
+ u_short utf16[NGX_UTF16_BUFLEN];
+
+ len = NGX_UTF16_BUFLEN;
+ u = ngx_utf8_to_utf16(utf16, name, &len, 0);
+
+ if (u == NULL) {
+ return NGX_MAX_OFF_T_VALUE;
+ }
+
+ if (GetDiskFreeSpaceExW(u, &navail, NULL, NULL) == 0) {
+
+ if (u != utf16) {
+ ngx_free(u);
+ }
- if (GetDiskFreeSpaceEx((const char *) name, &navail, NULL, NULL) == 0) {
return NGX_MAX_OFF_T_VALUE;
}
+ if (u != utf16) {
+ ngx_free(u);
+ }
+
return (off_t) navail.QuadPart;
}