* fhandler_dev.cc (fhandler_dev::readdir): Fix formatting. Simplify

code.  Use device::type() to fetch dirent compatible device type.
	Add comment.
This commit is contained in:
Corinna Vinschen 2012-04-01 10:38:07 +00:00
parent 727a81f4d9
commit c4ee9311c2
2 changed files with 25 additions and 41 deletions

View File

@ -1,3 +1,9 @@
2012-04-01 Corinna Vinschen <corinna@vinschen.de>
* fhandler_dev.cc (fhandler_dev::readdir): Fix formatting. Simplify
code. Use device::type() to fetch dirent compatible device type.
Add comment.
2012-03-31 Christopher Faylor <me.cygwin2012@cgf.cx> 2012-03-31 Christopher Faylor <me.cygwin2012@cgf.cx>
* devices.h (device::exists_func): Redefine field. * devices.h (device::exists_func): Redefine field.

View File

@ -94,6 +94,7 @@ int
fhandler_dev::readdir (DIR *dir, dirent *de) fhandler_dev::readdir (DIR *dir, dirent *de)
{ {
int ret; int ret;
const device *curdev;
device dev; device dev;
if (!devidx) if (!devidx)
@ -104,62 +105,39 @@ fhandler_dev::readdir (DIR *dir, dirent *de)
/dev already, for instance by using the old script from Igor /dev already, for instance by using the old script from Igor
Peshansky. */ Peshansky. */
dev.name = de->d_name; dev.name = de->d_name;
if (!bsearch (&dev, dev_storage_scan_start, dev_storage_size, sizeof dev, if (!bsearch (&dev, dev_storage_scan_start, dev_storage_size,
device_cmp)) sizeof dev, device_cmp))
break; break;
} }
if (ret == ENMFILE) if (ret != ENMFILE)
devidx = dev_storage_scan_start;
else
goto out; goto out;
devidx = dev_storage_scan_start;
} }
/* Now start processing our internal dev table. */ /* Now start processing our internal dev table. */
ret = ENMFILE; ret = ENMFILE;
while (devidx < dev_storage_end) while ((curdev = devidx++) < dev_storage_end)
{ {
const device& thisdev = *devidx++;
/* If exists returns < 0 it means that the device can be used by a /* 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 program but its use is deprecated and, so, it is not returned
by readdir((). */ by readdir((). */
if (thisdev.exists () <= 0) if (curdev->exists () <= 0)
continue; continue;
++dir->__d_position; ++dir->__d_position;
strcpy (de->d_name, thisdev.name + dev_prefix_len); strcpy (de->d_name, curdev->name + dev_prefix_len);
de->d_ino = hash_path_name (0, thisdev.native); if (curdev->get_major () == DEV_TTY_MAJOR
switch (thisdev.get_major ()) && (curdev->is_device (FH_CONIN)
|| curdev->is_device (FH_CONOUT)
|| curdev->is_device (FH_CONSOLE)))
{ {
case DEV_FLOPPY_MAJOR: /* Make sure conin, conout, and console have the same inode number
case DEV_TAPE_MAJOR: as the current consX. */
case DEV_CDROM_MAJOR: dev.parse (myself->ctty);
case DEV_SD_MAJOR: de->d_ino = hash_path_name (0, dev.native);
case DEV_SD1_MAJOR:
case DEV_SD2_MAJOR:
case DEV_SD3_MAJOR:
case DEV_SD4_MAJOR:
case DEV_SD5_MAJOR:
case DEV_SD6_MAJOR:
case DEV_SD7_MAJOR:
de->d_type = DT_BLK;
break;
case DEV_TTY_MAJOR:
{
int devn = *const_cast<device *> (&thisdev);
switch (devn)
{
case FH_CONIN:
case FH_CONOUT:
case FH_CONSOLE:
dev.parse (myself->ctty);
de->d_ino = hash_path_name (0, dev.native);
break;
}
}
/*FALLTHRU*/
default:
de->d_type = DT_CHR;
break;
} }
else
de->d_ino = hash_path_name (0, curdev->native);
de->d_type = curdev->type ();
ret = 0; ret = 0;
break; break;
} }