From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 82A403864825; Tue, 28 Nov 2023 10:02:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82A403864825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1701165775; bh=x2pxFJ2kP/iSn69zPgBEHRft/f+rt14NDfS28st9sUk=; h=From:To:Subject:Date:From; b=xEnRWsq+VvJDhkAY6IPkLtBHe/yA14D3l/oKbo8fq2N7bie/+xNU8FHmarOdNgDki 1GVRtmk4cTZKDy3IIHHBUeVMMi6RNvBy/12yTzcxc4vfcMb7N8pVEKvmzWBxpRYjyi ZaMypD3jGbpB94UI52PtLBNTaZ4wJabOHe4kLvrg= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: fhandler: rename ftruncate method to fallocate X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: fedd7fae77303ee3caf7c87510a03a9157deb06f X-Git-Newrev: f3554bf8905bfca5fbe54e57a452196bd9499cea Message-Id: <20231128100255.82A403864825@sourceware.org> Date: Tue, 28 Nov 2023 10:02:55 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Df3554bf8905= bfca5fbe54e57a452196bd9499cea commit f3554bf8905bfca5fbe54e57a452196bd9499cea Author: Corinna Vinschen AuthorDate: Sun Nov 26 12:50:38 2023 +0100 Commit: Corinna Vinschen CommitDate: Tue Nov 28 10:52:05 2023 +0100 Cygwin: fhandler: rename ftruncate method to fallocate =20 also, take mode flags parameter instead of just a bool. Introduce __FALLOC_FL_TRUNCATE mode flag as internal flag to indictae being called from ftruncate(2). =20 This is in preparation of an upcoming change introducing the Linx-specific fallocate(2) call. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler/base.cc | 2 +- winsup/cygwin/fhandler/disk_file.cc | 16 +++++++++------- winsup/cygwin/fhandler/pipe.cc | 4 ++-- winsup/cygwin/include/fcntl.h | 3 +++ winsup/cygwin/local_includes/fhandler.h | 8 ++++---- winsup/cygwin/syscalls.cc | 4 ++-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc index 3f0dc5f69847..d859870cb40d 100644 --- a/winsup/cygwin/fhandler/base.cc +++ b/winsup/cygwin/fhandler/base.cc @@ -1795,7 +1795,7 @@ fhandler_base::fadvise (off_t offset, off_t length, i= nt advice) } =20 int -fhandler_base::ftruncate (off_t length, bool allow_truncate) +fhandler_base::fallocate (int mode, off_t offset, off_t length) { return ENODEV; } diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/d= isk_file.cc index 245e9bb75dc8..51602f30f10a 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -25,6 +25,7 @@ details. */ #include "devices.h" #include "ldap.h" #include +#include #include =20 #define _LIBC @@ -1130,7 +1131,7 @@ fhandler_disk_file::fadvise (off_t offset, off_t leng= th, int advice) } =20 int -fhandler_disk_file::ftruncate (off_t length, bool allow_truncate) +fhandler_disk_file::fallocate (int mode, off_t offset, off_t length) { int res =3D 0; =20 @@ -1152,17 +1153,18 @@ fhandler_disk_file::ftruncate (off_t length, bool a= llow_truncate) if (!NT_SUCCESS (status)) return geterrno_from_nt_status (status); =20 - /* If called through posix_fallocate, silently succeed if length - is less than the file's actual length. */ - if (!allow_truncate && length < fsi.EndOfFile.QuadPart) + /* If called through posix_fallocate, silently succeed if + offset + length is less than the file's actual length. */ + if (mode =3D=3D 0 && offset + length < fsi.EndOfFile.QuadPart) return 0; =20 - feofi.EndOfFile.QuadPart =3D length; + feofi.EndOfFile.QuadPart =3D offset + length; /* Create sparse files only when called through ftruncate, not when called through posix_fallocate. */ - if (allow_truncate && pc.support_sparse () + if ((mode & __FALLOC_FL_TRUNCATE) && !has_attribute (FILE_ATTRIBUTE_SPARSE_FILE) - && length >=3D fsi.EndOfFile.QuadPart + (128 * 1024)) + && pc.support_sparse () + && offset + length >=3D fsi.EndOfFile.QuadPart + (128 * 1024)) { status =3D NtFsControlFile (get_handle (), NULL, NULL, NULL, &io, FSCTL_SET_SPARSE, NULL, 0, NULL, 0); diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index e72ee65ca80a..1a97108b5d62 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -247,9 +247,9 @@ fhandler_pipe::fadvise (off_t offset, off_t length, int= advice) } =20 int -fhandler_pipe::ftruncate (off_t length, bool allow_truncate) +fhandler_pipe::fallocate (int mode, off_t offset, off_t length) { - return allow_truncate ? EINVAL : ESPIPE; + return (mode & __FALLOC_FL_TRUNCATE) ? EINVAL : ESPIPE; } =20 char * diff --git a/winsup/cygwin/include/fcntl.h b/winsup/cygwin/include/fcntl.h index ed396eab64bd..de64d4f7c010 100644 --- a/winsup/cygwin/include/fcntl.h +++ b/winsup/cygwin/include/fcntl.h @@ -40,9 +40,12 @@ details. */ #define POSIX_FADV_DONTNEED 4 #define POSIX_FADV_NOREUSE 5 =20 +#define __FALLOC_FL_TRUNCATE 0x0001 /* internal */ + #ifdef __cplusplus extern "C" { #endif + extern int posix_fadvise (int, off_t, off_t, int); extern int posix_fallocate (int, off_t, off_t); #ifdef __cplusplus diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_= includes/fhandler.h index ca685a627642..54e0c6e804c8 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -389,7 +389,7 @@ public: virtual ssize_t fgetxattr (const char *, void *, size_t); virtual int fsetxattr (const char *, const void *, size_t, int); virtual int fadvise (off_t, off_t, int); - virtual int ftruncate (off_t, bool); + virtual int fallocate (int, off_t, off_t); virtual int link (const char *); virtual int utimens (const struct timespec *); virtual int fsync (); @@ -1222,7 +1222,7 @@ public: int fstat (struct stat *buf); int fstatvfs (struct statvfs *buf); int fadvise (off_t, off_t, int); - int ftruncate (off_t, bool); + int fallocate (int, off_t, off_t); int init (HANDLE, DWORD, mode_t, int64_t); static int create (fhandler_pipe *[2], unsigned, int); static DWORD create (LPSECURITY_ATTRIBUTES, HANDLE *, HANDLE *, DWORD, @@ -1727,7 +1727,7 @@ class fhandler_disk_file: public fhandler_base ssize_t fgetxattr (const char *, void *, size_t); int fsetxattr (const char *, const void *, size_t, int); int fadvise (off_t, off_t, int); - int ftruncate (off_t, bool); + int fallocate (int, off_t, off_t); int link (const char *); int utimens (const struct timespec *); int fstatvfs (struct statvfs *buf); @@ -3413,7 +3413,7 @@ public: ssize_t fgetxattr (const char *, void *, size_t) NO_IMPL; int fsetxattr (const char *, const void *, size_t, int) NO_IMPL; int fadvise (off_t, off_t, int) NO_IMPL; - int ftruncate (off_t, bool) NO_IMPL; + int fallocate (int, off_t, off_t) NO_IMPL; int link (const char *) NO_IMPL; int mkdir (mode_t) NO_IMPL; ssize_t pread (void *, size_t, off_t, void *aio =3D NULL) NO_IMPL; diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index c3c17d604af3..b2e6ba16ca04 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -2997,7 +2997,7 @@ posix_fallocate (int fd, off_t offset, off_t len) { cygheap_fdget cfd (fd); if (cfd >=3D 0) - res =3D cfd->ftruncate (offset + len, false); + res =3D cfd->fallocate (0, offset, len); else res =3D EBADF; if (res =3D=3D EISDIR) @@ -3014,7 +3014,7 @@ ftruncate (int fd, off_t length) cygheap_fdget cfd (fd); if (cfd >=3D 0) { - res =3D cfd->ftruncate (length, true); + res =3D cfd->fallocate (__FALLOC_FL_TRUNCATE, 0, length); if (res) { if (res =3D=3D ENODEV)