newlib/winsup/cygwin/fhandler_dev.cc

230 lines
5.1 KiB
C++
Raw Normal View History

/* fhandler_dev.cc, Implement /dev.
Copyright 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. */
#include "winsup.h"
#include <stdlib.h>
#include <sys/statvfs.h>
#include "path.h"
#include "fhandler.h"
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
#include "dtable.h"
#include "cygheap.h"
#include "devices.h"
#define _COMPILING_NEWLIB
#include <dirent.h>
#define dev_prefix_len (sizeof ("/dev"))
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
#define dev_storage_scan_start (dev_storage + 1)
#define dev_storage_size (dev_storage_end - dev_storage_scan_start)
static int
device_cmp (const void *a, const void *b)
{
return strcmp (((const device *) a)->name,
((const device *) b)->name + dev_prefix_len);
}
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
fhandler_dev::fhandler_dev () :
fhandler_disk_file (), devidx (NULL), dir_exists (true)
{
}
int
fhandler_dev::open (int flags, mode_t mode)
{
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
{
set_errno (EEXIST);
return 0;
}
if (flags & O_WRONLY)
{
set_errno (EISDIR);
return 0;
}
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
/* Filter O_CREAT flag to avoid creating a file called /dev accidentally. */
int ret = fhandler_disk_file::open (flags & ~O_CREAT, mode);
if (!ret)
{
/* Open a fake handle to \\Device\\Null */
ret = open_null (flags);
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
dir_exists = false;
}
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
return ret;
}
int
fhandler_dev::close ()
{
return fhandler_disk_file::close ();
}
int __reg2
2013-04-23 11:44:36 +02:00
fhandler_dev::fstat (struct stat *st)
{
/* If /dev really exists on disk, return correct disk information. */
if (pc.fs_got_fs ())
return fhandler_disk_file::fstat (st);
/* Otherwise fake virtual filesystem. */
fhandler_base::fstat (st);
st->st_ino = 2;
st->st_mode = S_IFDIR | STD_RBITS | STD_XBITS;
st->st_nlink = 1;
return 0;
}
int __reg2
fhandler_dev::fstatvfs (struct statvfs *sfs)
{
int ret = -1, opened = 0;
HANDLE fh = get_handle ();
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
if (!fh)
{
if (!open (O_RDONLY, 0))
return -1;
opened = 1;
}
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
if (pc.fs_got_fs ())
ret = fhandler_disk_file::fstatvfs (sfs);
else
{
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
/* Virtual file system. Just return an empty buffer with a few values
set to something useful similar to Linux. */
memset (sfs, 0, sizeof (*sfs));
sfs->f_bsize = sfs->f_frsize = 4096;
sfs->f_flag = ST_RDONLY;
sfs->f_namemax = NAME_MAX;
ret = 0;
}
if (opened)
close ();
return ret;
}
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
DIR *
fhandler_dev::opendir (int fd)
{
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
DIR *dir = fhandler_disk_file::opendir (fd);
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
if (dir)
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
dir_exists = true;
else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
set_errno (ENOMEM);
else if ((dir->__d_dirent =
(struct dirent *) malloc (sizeof (struct dirent))) == NULL)
{
set_errno (ENOMEM);
goto free_dir;
}
else
{
cygheap_fdnew cfd;
if (cfd < 0 && fd < 0)
goto free_dirent;
dir->__d_dirname = NULL;
dir->__d_dirent->__d_version = __DIRENT_VERSION;
dir->__d_cookie = __DIRENT_COOKIE;
dir->__handle = INVALID_HANDLE_VALUE;
dir->__d_position = 0;
dir->__flags = 0;
dir->__d_internal = 0;
if (fd >= 0)
dir->__d_fd = fd;
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
else if (!open (O_RDONLY, 0))
goto free_dirent;
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
else
{
cfd = this;
dir->__d_fd = cfd;
}
set_close_on_exec (true);
dir->__fh = this;
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
dir_exists = false;
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
}
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
devidx = dir_exists ? NULL : dev_storage_scan_start;
syscall_printf ("%p = opendir (%s)", dir, get_name ());
return dir;
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
free_dirent:
free (dir->__d_dirent);
free_dir:
free (dir);
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
return NULL;
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
}
int
fhandler_dev::readdir (DIR *dir, dirent *de)
{
int ret;
const device *curdev;
device dev;
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
if (!devidx)
{
while ((ret = fhandler_disk_file::readdir (dir, de)) == 0)
{
/* Avoid to print devices for which users have created files under
/dev already, for instance by using the old script from Igor
Peshansky. */
dev.name = de->d_name;
if (!bsearch (&dev, dev_storage_scan_start, dev_storage_size,
sizeof dev, device_cmp))
break;
}
if (ret != ENMFILE)
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
goto out;
devidx = dev_storage_scan_start;
}
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
/* Now start processing our internal dev table. */
ret = ENMFILE;
while ((curdev = devidx++) < dev_storage_end)
{
/* If exists returns < 0 it means that the device can be used by a
program but its use is deprecated and, so, it is not returned
by readdir((). */
if (curdev->exists () <= 0)
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
continue;
++dir->__d_position;
strcpy (de->d_name, curdev->name + dev_prefix_len);
if (curdev->get_major () == DEV_TTY_MAJOR
&& (curdev->is_device (FH_CONIN)
|| curdev->is_device (FH_CONOUT)
|| curdev->is_device (FH_CONSOLE)))
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
{
/* Make sure conin, conout, and console have the same inode number
as the current consX. */
de->d_ino = myself->ctty;
}
else
de->d_ino = curdev->get_device ();
de->d_type = curdev->type ();
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
ret = 0;
break;
}
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
out:
debug_printf ("returning %d", ret);
return ret;
}
void
fhandler_dev::rewinddir (DIR *dir)
{
(Interim checkin while we work on this) * devices.cc: Regenerate. * devices.h (device::noexpose): New field. (device::dev_on_fs): Make a bit field. (get_major): Use proper type for declaration. (expose): New field. (ext_dev_storage): Delete declaration. (dev_storage_size): Ditto. (dev_storage): New declaration. (dev_storage_end): Ditto. * devices.in: Mark /dev/ptym*, /dev/com*, /dev/pipe, /dev/fifo, and "/dev" as "no expose". * fhandler.h (fhandler_dev::lastrealpos): Delete declaration. (fhandler_dev::devidx): Declare new field. * fhandler_disk_file.cc: Move fhandler_dev functions into fhandler_dev.cc. * fhandler_dev.cc: Add includes needed for functions moved from fhandler_disk_file.cc. (dev_storage_scan_start): Define place to start listing devices. (dev_storage_size): Define size of array to scan. (fhandler_dev::fhandler_dev): Move here from fhandler_disk_file.cc. (fhandler_dev::opendir): Ditto. (fhandler_dev::readdir): Just check devidx for non-NULL to determine when to go to disk for /dev content. Use dev_storage rather than ext_dev_storage. Iterate over dev_storage using devidx pointer. Use accessor functions rather than raw references to the device struct. Only increment dir->__d_position when we are actually going to be returning something. Add debug_printf for exit. (fhandler_dev::rewinddir): Set devidx as appropriate depending on whether there's a /dev on disk or not. * gendevices: Don't mark dev_storage static but do put it in the _RDATA section. * path.cc (path_conv::check): Use new "device::expose()" function to decide to forbid programs from referencing internal device types.
2012-03-31 19:38:00 +02:00
devidx = dir_exists ? NULL : dev_storage_scan_start;
* devices.in (dev_cygdrive_storage): Map to \Device\Null. (dev_storage): Map /dev and /dev/windows to \Device\Null. * devices.cc: Regenerate. * dir.cc (opendir): Create unique id. Explain why. * fhandler.h (fhandler_dev::get_dev): Implement inline. (fhandler_cygdrive::close): Drop declaration. (fhandler_cygdrive::get_dev): Implement inline. (fhandler_windows::get_hwnd): Ditto. (fhandler_windows::set_close_on_exec): Drop declaration. (fhandler_windows::fixup_after_fork): Ditto. * fhandler_dev.cc (fhandler_dev::open): Call fhandler_disk_file::open without O_CREAT flag. Explain why. Create \Device\Null handle if /dev/ doesn't actually exist. (fhandler_dev::close): Drop nohandle case. (fhandler_dev::fstatvfs): Drop nohandle check. Test for fs_got_fs instead. Set ST_RDONLY fs flag for simulated /dev. (fhandler_dev::opendir): If /dev doesn't exist, call open() to create fake \Device\Null handle. Don't set nohandle. Set dir_exists correctly. (fhandler_dev::rewinddir): Call fhandler_disk_file::rewinddir only if /dev is a real directory. * fhandler_disk_file.cc (fhandler_disk_file::opendir): If called for the cygdrive dir, call open() to create fake \Device\Null handle. Only attach __DIR_mounts buffer to dir if not called for cygdrive dir. Don't set nohandle. (fhandler_cygdrive::open): Create \Device\Null handle. (fhandler_cygdrive::close): Remove. (fhandler_cygdrive::fstatvfs): Set ST_RDONLY fs flag. * fhandler_windows.cc (fhandler_windows::open): Create \Device\Null handle. (fhandler_windows::read): Don't add io_handle to WFMO handle array. Change subsequent test for return value accordingly. Fix test for "message arrived". (fhandler_windows::set_close_on_exec): Remove. (fhandler_windows::fixup_after_fork): Remove. * path.h (path_conv::set_path): Make sure wide_path is NULL when setting a new path. * select.cc (peek_windows): Use correct hWnd value, not io_handle. (fhandler_windows::select_read): Don't use io_handle as wait object. (fhandler_windows::select_write): Ditto. (fhandler_windows::select_except): Ditto.
2013-10-30 10:44:47 +01:00
dir->__d_position = 0;
if (dir_exists)
fhandler_disk_file::rewinddir (dir);
}