Cygwin: fcntl.h: Define O_TMPFILE and implement it
Difference to Linux: We can't create files which don't show up in the filesystem due to OS restrictions. As a kludge, make a (half-hearted) attempt to hide the file in the filesystem. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
@@ -137,6 +137,11 @@ fhandler_base::set_name (path_conv &in_pc)
|
||||
|
||||
char *fhandler_base::get_proc_fd_name (char *buf)
|
||||
{
|
||||
/* If the file had been opened with O_TMPFILE | O_EXCL, don't
|
||||
expose the filename. linkat is supposed to return ENOENT in this
|
||||
case. See man 2 open on Linux. */
|
||||
if ((get_flags () & (O_TMPFILE | O_EXCL)) == (O_TMPFILE | O_EXCL))
|
||||
return strcpy (buf, "");
|
||||
if (get_name ())
|
||||
return strcpy (buf, get_name ());
|
||||
if (dev ().name ())
|
||||
@@ -582,7 +587,7 @@ fhandler_base::open (int flags, mode_t mode)
|
||||
|
||||
/* Don't use the FILE_OVERWRITE{_IF} flags here. See below for an
|
||||
explanation, why that's not such a good idea. */
|
||||
if ((flags & O_EXCL) && (flags & O_CREAT))
|
||||
if (((flags & O_EXCL) && (flags & O_CREAT)) || (flags & O_TMPFILE))
|
||||
create_disposition = FILE_CREATE;
|
||||
else
|
||||
create_disposition = (flags & O_CREAT) ? FILE_OPEN_IF : FILE_OPEN;
|
||||
@@ -594,6 +599,18 @@ fhandler_base::open (int flags, mode_t mode)
|
||||
if (pc.is_rep_symlink ())
|
||||
options |= FILE_OPEN_REPARSE_POINT;
|
||||
|
||||
/* O_TMPFILE files are created with delete-on-close semantics, as well
|
||||
as with FILE_ATTRIBUTE_TEMPORARY. The latter speeds up file access,
|
||||
because the OS tries to keep the file in memory as much as possible.
|
||||
In conjunction with FILE_DELETE_ON_CLOSE, ideally the OS never has
|
||||
to write to the disk at all. */
|
||||
if (flags & O_TMPFILE)
|
||||
{
|
||||
access |= DELETE;
|
||||
file_attributes |= FILE_ATTRIBUTE_TEMPORARY;
|
||||
options |= FILE_DELETE_ON_CLOSE;
|
||||
}
|
||||
|
||||
if (pc.fs_is_nfs ())
|
||||
{
|
||||
/* Make sure we can read EAs of files on an NFS share. Also make
|
||||
@@ -617,7 +634,7 @@ fhandler_base::open (int flags, mode_t mode)
|
||||
&& has_attribute (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM))
|
||||
file_attributes |= pc.file_attributes ();
|
||||
|
||||
if (flags & O_CREAT)
|
||||
if (flags & (O_CREAT | O_TMPFILE))
|
||||
{
|
||||
file_attributes |= FILE_ATTRIBUTE_NORMAL;
|
||||
|
||||
|
Reference in New Issue
Block a user