mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-19 04:49:25 +08:00
Cygwin: fhandler: rename ftruncate method to fallocate
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). This is in preparation of an upcoming change introducing the Linx-specific fallocate(2) call. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
fedd7fae77
commit
f3554bf890
@ -1795,7 +1795,7 @@ fhandler_base::fadvise (off_t offset, off_t length, int advice)
|
||||
}
|
||||
|
||||
int
|
||||
fhandler_base::ftruncate (off_t length, bool allow_truncate)
|
||||
fhandler_base::fallocate (int mode, off_t offset, off_t length)
|
||||
{
|
||||
return ENODEV;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ details. */
|
||||
#include "devices.h"
|
||||
#include "ldap.h"
|
||||
#include <aio.h>
|
||||
#include <fcntl.h>
|
||||
#include <cygwin/fs.h>
|
||||
|
||||
#define _LIBC
|
||||
@ -1130,7 +1131,7 @@ fhandler_disk_file::fadvise (off_t offset, off_t length, int advice)
|
||||
}
|
||||
|
||||
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 = 0;
|
||||
|
||||
@ -1152,17 +1153,18 @@ fhandler_disk_file::ftruncate (off_t length, bool allow_truncate)
|
||||
if (!NT_SUCCESS (status))
|
||||
return geterrno_from_nt_status (status);
|
||||
|
||||
/* 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 == 0 && offset + length < fsi.EndOfFile.QuadPart)
|
||||
return 0;
|
||||
|
||||
feofi.EndOfFile.QuadPart = length;
|
||||
feofi.EndOfFile.QuadPart = 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 >= fsi.EndOfFile.QuadPart + (128 * 1024))
|
||||
&& pc.support_sparse ()
|
||||
&& offset + length >= fsi.EndOfFile.QuadPart + (128 * 1024))
|
||||
{
|
||||
status = NtFsControlFile (get_handle (), NULL, NULL, NULL, &io,
|
||||
FSCTL_SET_SPARSE, NULL, 0, NULL, 0);
|
||||
|
@ -247,9 +247,9 @@ fhandler_pipe::fadvise (off_t offset, off_t length, int advice)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -40,9 +40,12 @@ details. */
|
||||
#define POSIX_FADV_DONTNEED 4
|
||||
#define POSIX_FADV_NOREUSE 5
|
||||
|
||||
#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
|
||||
|
@ -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 = NULL) NO_IMPL;
|
||||
|
@ -2997,7 +2997,7 @@ posix_fallocate (int fd, off_t offset, off_t len)
|
||||
{
|
||||
cygheap_fdget cfd (fd);
|
||||
if (cfd >= 0)
|
||||
res = cfd->ftruncate (offset + len, false);
|
||||
res = cfd->fallocate (0, offset, len);
|
||||
else
|
||||
res = EBADF;
|
||||
if (res == EISDIR)
|
||||
@ -3014,7 +3014,7 @@ ftruncate (int fd, off_t length)
|
||||
cygheap_fdget cfd (fd);
|
||||
if (cfd >= 0)
|
||||
{
|
||||
res = cfd->ftruncate (length, true);
|
||||
res = cfd->fallocate (__FALLOC_FL_TRUNCATE, 0, length);
|
||||
if (res)
|
||||
{
|
||||
if (res == ENODEV)
|
||||
|
Loading…
x
Reference in New Issue
Block a user