diff options
Diffstat (limited to 'winsup/cygwin/devices.h')
-rw-r--r-- | winsup/cygwin/devices.h | 157 |
1 files changed, 111 insertions, 46 deletions
diff --git a/winsup/cygwin/devices.h b/winsup/cygwin/devices.h index 991fd0538..8d2b3edce 100644 --- a/winsup/cygwin/devices.h +++ b/winsup/cygwin/devices.h @@ -20,6 +20,7 @@ typedef unsigned short _minor_t; #include <sys/stat.h> #include <dirent.h> +#include "cygheap_malloc.h" #define MAX_CONSOLES 63 enum fh_devices @@ -93,6 +94,8 @@ enum fh_devices DEV_SD5_MAJOR = 69, DEV_SD6_MAJOR = 70, DEV_SD7_MAJOR = 71, + DEV_SD_HIGHPART_START = 259, /* partition # > 15 */ + DEV_SD_HIGHPART_END = 284, FH_SD = FHDEV (DEV_SD_MAJOR, 0), FH_SD1 = FHDEV (DEV_SD1_MAJOR, 0), FH_SD2 = FHDEV (DEV_SD2_MAJOR, 0), @@ -253,14 +256,21 @@ enum fh_devices FH_ERROR = FHDEV (255, 255) /* Set by fh constructor when error detected */ }; -struct device +/* struct _device is required to allow the code in devices.cc autogenerated + from devices.in continuing to work, even with a proper class device. + We need to keep up with this as long as we use shilka to build a device + table. + + Do not add members to device. Always add it to _device. */ + +class device; + +struct _device { - const char *name; + const char *_name; union __cygwin_dev { dev_t devn; - DWORD devn_dword; - int devn_int; fh_devices devn_fh_devices; struct { @@ -268,16 +278,58 @@ struct device _major_t major; }; } d; - const char *native; + const char *_native; int (*exists_func) (const device&); - __mode_t mode; - bool lives_in_dev:4; - bool dev_on_fs:4; - static const device *lookup (const char *, unsigned int = UINT32_MAX); + __mode_t _mode; + bool lives_in_dev; + bool dev_on_fs; + bool name_allocated; + bool native_allocated; +}; + +class device : private _device +{ + void parsedisk (int, int); + void name (const char *n, bool a) + { + _name = (!(name_allocated = a)) ? n : cstrdup (n); + } + void native (const char *n, bool a) + { + _native = (!(native_allocated = a)) ? n : cstrdup (n); + } + +public: + device () { memset (this, 0, sizeof *this); } + device (int drive, int part) + { + memset (this, 0, sizeof *this); + parsedisk (drive, part); + } + ~device () + { + if (name_allocated) + cfree ((void *) _name); + if (native_allocated) + cfree ((void *) _native); + } + + const char *name () const { return _name; } + const char *native () const { return _native; } + __mode_t mode () const { return _mode; } + void mode (__mode_t m) { _mode = m; } + + void name (const char *n) { name (n, false); } + void native (const char *n) { native (n, false); } + void dup () + { + name (_name, name_allocated); + native (_native, native_allocated); + } + void parse (const char *); void parse (_major_t major, _minor_t minor); void parse (dev_t dev); - void parsedisk (int, int); inline bool setunit (unsigned n) { d.minor = n; @@ -308,8 +360,21 @@ struct device dev_t get_device () const {return d.devn;} inline operator fh_devices () {return d.devn_fh_devices;} - inline operator bool () {return !!d.devn_int;} + inline operator bool () {return !!d.devn;} inline operator dev_t& () {return d.devn;} + device &operator = (_device _d) + { + memcpy (this, &_d, sizeof _d); + dev_on_fs = name_allocated = native_allocated = false; + return *this; + } + device &operator = (device &_d) + { + memcpy (this, &_d, sizeof _d); + name (_d.name (), _d.name_allocated); + native (_d.native (), _d.native_allocated); + return *this; + } fh_devices operator = (fh_devices n) {return d.devn_fh_devices = n;} inline void setfs (bool x) {dev_on_fs = x;} inline bool isfs () const {return dev_on_fs || d.devn == FH_FS;} @@ -318,45 +383,45 @@ struct device inline int exists () const {return exists_func (*this);} unsigned char type () const { - if (S_ISBLK (mode)) + if (S_ISBLK (_mode)) return DT_BLK; - return mode >> 12; + return _mode >> 12; } }; -extern const device dev_storage[]; -extern const device *dev_storage_end; - -extern const device *console_dev; -extern const device *ptmx_dev; -extern const device *ptys_dev; -extern const device *urandom_dev; - -extern const device dev_dgram_storage; -#define dgram_dev (&dev_dgram_storage) -extern const device dev_stream_storage; -#define stream_dev (&dev_stream_storage) -extern const device dev_tcp_storage; -#define tcp_dev (&dev_tcp_storage) -extern const device dev_udp_storage; -#define udp_dev (&dev_udp_storage) - -extern const device dev_piper_storage; -#define piper_dev (&dev_piper_storage) -extern const device dev_pipew_storage; -#define pipew_dev (&dev_pipew_storage) -extern const device dev_proc_storage; -#define proc_dev (&dev_proc_storage) -extern const device dev_dev_storage; -#define dev_dev (&dev_dev_storage) -extern const device dev_netdrive_storage; -#define netdrive_dev (&dev_netdrive_storage) -extern const device dev_cygdrive_storage; -#define cygdrive_dev (&dev_cygdrive_storage) -extern const device dev_fh_storage; -#define fh_dev (&dev_fh_storage) -extern const device dev_fs_storage; -#define fs_dev (&dev_fs_storage) +extern const _device dev_storage[]; +extern const _device *dev_storage_end; + +extern const _device *console_dev; +extern const _device *ptmx_dev; +extern const _device *ptys_dev; +extern const _device *urandom_dev; + +extern const _device dev_dgram_storage; +#define dgram_dev ((device *) &dev_dgram_storage) +extern const _device dev_stream_storage; +#define stream_dev ((device *) &dev_stream_storage) +extern const _device dev_tcp_storage; +#define tcp_dev ((device *) &dev_tcp_storage) +extern const _device dev_udp_storage; +#define udp_dev ((device *) &dev_udp_storage) + +extern const _device dev_piper_storage; +#define piper_dev ((device *) &dev_piper_storage) +extern const _device dev_pipew_storage; +#define pipew_dev ((device *) &dev_pipew_storage) +extern const _device dev_proc_storage; +#define proc_dev ((device *) &dev_proc_storage) +extern const _device dev_dev_storage; +#define dev_dev ((device *) &dev_dev_storage) +extern const _device dev_netdrive_storage; +#define netdrive_dev ((device *) &dev_netdrive_storage) +extern const _device dev_cygdrive_storage; +#define cygdrive_dev ((device *) &dev_cygdrive_storage) +extern const _device dev_fh_storage; +#define fh_dev ((device *) &dev_fh_storage) +extern const _device dev_fs_storage; +#define fs_dev ((device *) &dev_fs_storage) #define isproc_dev(devn) \ (devn >= FH_PROC_MIN_MINOR && devn <= FH_PROC_MAX_MINOR) |