95ff6fc6da
* devices.cc: Regenerate. * dtable.h (struct dtable): Make fhandler_base friend, rather than fhandler_disk_file. * fhandler.cc (fhandler_base::open_with_arch): Create unique id. (fhandler_base::cleanup): Call del_my_locks. (fhandler_base::fcntl): Handle F_GETLK, F_SETLK and F_SETLKW. * fhandler.h (fhandler_base::get_dev): Return real device number. (fhandler_base::set_unique_id): New inline method. (fhandler_disk_file::lock): Drop declaration. (fhandler_disk_file::get_dev): New method, return pc.fs_serial_number. (fhandler_dev_zero::open): Drop declaration. * fhandler_disk_file.cc (fhandler_disk_file::close): Move del_my_locks call to fhandler_base::open_with_arch. (fhandler_disk_file::fcntl): Move handling of locking commands to fhandler_base::fcntl. (fhandler_base::open_fs): Drop call to NtAllocateLocallyUniqueId. * fhandler_zero.cc (fhandler_dev_zero::open): Remove so that default fhandler_base::open is used to open \Device\Null. * flock.cc (fixup_lockf_after_exec): Finding a single fhandler is enough here. (fhandler_base::lock): Replace fhandler_disk_file::lock. Refuse to lock nohandle devices. Handle read/write test using POSIX flags. Explain why. Never fail on SEEK_CUR or SEEK_END, rather assume position 0, just as Linux. * net.cc (fdsock): Create unique id.
111 lines
3.3 KiB
C++
111 lines
3.3 KiB
C++
/* dtable.h: fd table definition.
|
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
|
2011, 2012, 2013 Red Hat, Inc.
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#pragma once
|
|
|
|
/* Initial and increment values for cygwin's fd table */
|
|
#define NOFILE_INCR 32
|
|
/* Maximum size we allow expanding to. */
|
|
#define OPEN_MAX_MAX (100 * NOFILE_INCR)
|
|
|
|
#include "thread.h"
|
|
#include "sync.h"
|
|
|
|
class suffix_info;
|
|
|
|
#define BFH_OPTS (PC_NULLEMPTY | PC_FULL | PC_POSIX)
|
|
class dtable
|
|
{
|
|
fhandler_base **fds;
|
|
#ifdef NEWVFORK
|
|
fhandler_base **fds_on_hold;
|
|
#endif
|
|
fhandler_base **archetypes;
|
|
unsigned narchetypes;
|
|
unsigned farchetype;
|
|
static const int initial_archetype_size = 8;
|
|
int first_fd_for_open;
|
|
int cnt_need_fixup_before;
|
|
void lock () {lock_process::locker.acquire ();}
|
|
void unlock () {lock_process::locker.release ();}
|
|
public:
|
|
size_t size;
|
|
|
|
dtable () : archetypes (NULL), narchetypes (0), farchetype (0), first_fd_for_open(3), cnt_need_fixup_before(0) {}
|
|
void init () {first_fd_for_open = 3;}
|
|
|
|
void dec_need_fixup_before ()
|
|
{ if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
|
|
void inc_need_fixup_before ()
|
|
{ cnt_need_fixup_before++; }
|
|
bool need_fixup_before ()
|
|
{ return cnt_need_fixup_before > 0; }
|
|
|
|
void move_fd (int, int);
|
|
int vfork_child_dup ();
|
|
void vfork_parent_restore ();
|
|
void vfork_child_fixup ();
|
|
fhandler_base *dup_worker (fhandler_base *oldfh, int flags);
|
|
int extend (int howmuch);
|
|
void fixup_after_fork (HANDLE);
|
|
void fixup_close (size_t, fhandler_base *);
|
|
|
|
inline int not_open (int fd)
|
|
{
|
|
lock ();
|
|
int res = fd < 0 || fd >= (int) size || fds[fd] == NULL;
|
|
unlock ();
|
|
return res;
|
|
}
|
|
int find_unused_handle (int start);
|
|
int find_unused_handle () { return find_unused_handle (first_fd_for_open);}
|
|
void __reg2 release (int fd);
|
|
void init_std_file_from_handle (int fd, HANDLE handle);
|
|
int dup3 (int oldfd, int newfd, int flags);
|
|
void fixup_after_exec ();
|
|
inline fhandler_base *&operator [](int fd) const { return fds[fd]; }
|
|
bool select_read (int fd, select_stuff *);
|
|
bool select_write (int fd, select_stuff *);
|
|
bool select_except (int fd, select_stuff *);
|
|
operator fhandler_base **() {return fds;}
|
|
void stdio_init ();
|
|
void get_debugger_info ();
|
|
void set_file_pointers_for_exec ();
|
|
#ifdef NEWVFORK
|
|
bool in_vfork_cleanup () {return fds_on_hold == fds;}
|
|
#endif
|
|
fhandler_base *find_archetype (device& dev);
|
|
fhandler_base **add_archetype ();
|
|
void delete_archetype (fhandler_base *);
|
|
void fixup_before_exec (DWORD win_proc_id);
|
|
void fixup_before_fork (DWORD win_proc_id);
|
|
friend void dtable_init ();
|
|
friend void __stdcall close_all_files (bool);
|
|
friend int dup_finish (int, int, int);
|
|
friend class fhandler_base;
|
|
friend class cygheap_fdmanip;
|
|
friend class cygheap_fdget;
|
|
friend class cygheap_fdnew;
|
|
friend class cygheap_fdenum;
|
|
friend class lock_process;
|
|
};
|
|
|
|
fhandler_base *build_fh_dev (const device&, const char * = NULL);
|
|
fhandler_base *build_fh_name (const char *, unsigned = 0, suffix_info * = NULL);
|
|
fhandler_base *build_fh_pc (path_conv& pc);
|
|
|
|
void dtable_init ();
|
|
void stdio_init ();
|
|
extern dtable fdtab;
|
|
|
|
extern "C" int getfdtabsize ();
|
|
extern "C" void setfdtabsize (int);
|