* fhandler_proc.cc (fhandler_proc::readdir): Set dirent d_type.

* fhandler_process.cc (fhandler_process::readdir): Ditto.
	* fhandler_procnet.cc (fhandler_procnet::readdir): Ditto.
	* fhandler_procsys.cc (fhandler_procsys::readdir): Ditto.
	* fhandler_procsysvipc.cc (fhandler_procsysvipc::readdir): Ditto.
	*  fhandler_virtual.h (virt_ftype_to_dtype): Define new inline function
	to generate dirent d_type from virtual_ftype_t.
This commit is contained in:
Corinna Vinschen 2014-10-09 13:24:37 +00:00
parent 633cf9b5dd
commit 54338f169f
7 changed files with 61 additions and 8 deletions

View File

@ -1,3 +1,13 @@
2014-10-09 Corinna Vinschen <corinna@vinschen.de>
* fhandler_proc.cc (fhandler_proc::readdir): Set dirent d_type.
* fhandler_process.cc (fhandler_process::readdir): Ditto.
* fhandler_procnet.cc (fhandler_procnet::readdir): Ditto.
* fhandler_procsys.cc (fhandler_procsys::readdir): Ditto.
* fhandler_procsysvipc.cc (fhandler_procsysvipc::readdir): Ditto.
* fhandler_virtual.h (virt_ftype_to_dtype): Define new inline function
to generate dirent d_type from virtual_ftype_t.
2014-10-08 Corinna Vinschen <corinna@vinschen.de> 2014-10-08 Corinna Vinschen <corinna@vinschen.de>
* common.din (ffsl): Export. * common.din (ffsl): Export.

View File

@ -254,7 +254,9 @@ fhandler_proc::readdir (DIR *dir, dirent *de)
int res; int res;
if (dir->__d_position < PROC_LINK_COUNT) if (dir->__d_position < PROC_LINK_COUNT)
{ {
strcpy (de->d_name, proc_tab[dir->__d_position++].name); strcpy (de->d_name, proc_tab[dir->__d_position].name);
de->d_type = virt_ftype_to_dtype (proc_tab[dir->__d_position].type);
dir->__d_position++;
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot; dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
res = 0; res = 0;
} }
@ -267,6 +269,7 @@ fhandler_proc::readdir (DIR *dir, dirent *de)
if (found++ == dir->__d_position - PROC_LINK_COUNT) if (found++ == dir->__d_position - PROC_LINK_COUNT)
{ {
__small_sprintf (de->d_name, "%d", pids[i]->pid); __small_sprintf (de->d_name, "%d", pids[i]->pid);
de->d_type = DT_DIR;
dir->__d_position++; dir->__d_position++;
res = 0; res = 0;
break; break;

View File

@ -230,9 +230,14 @@ fhandler_process::readdir (DIR *dir, dirent *de)
{ {
int *p = (int *) filebuf; int *p = (int *) filebuf;
__small_sprintf (de->d_name, "%d", p[dir->__d_position++ - 2]); __small_sprintf (de->d_name, "%d", p[dir->__d_position++ - 2]);
de->d_type = DT_LNK;
} }
else else
strcpy (de->d_name, process_tab[dir->__d_position++].name); {
strcpy (de->d_name, process_tab[dir->__d_position].name);
de->d_type = virt_ftype_to_dtype (process_tab[dir->__d_position].type);
dir->__d_position++;
}
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot; dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
res = 0; res = 0;
out: out:

View File

@ -1,6 +1,6 @@
/* fhandler_procnet.cc: fhandler for /proc/net virtual filesystem /* fhandler_procnet.cc: fhandler for /proc/net virtual filesystem
Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013 Red Hat, Inc. Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -115,7 +115,9 @@ fhandler_procnet::readdir (DIR *dir, dirent *de)
if (procnet_tab[dir->__d_position].type == virt_file if (procnet_tab[dir->__d_position].type == virt_file
&& !get_adapters_addresses (NULL, AF_INET6)) && !get_adapters_addresses (NULL, AF_INET6))
goto out; goto out;
strcpy (de->d_name, procnet_tab[dir->__d_position++].name); strcpy (de->d_name, procnet_tab[dir->__d_position].name);
de->d_type = virt_ftype_to_dtype (procnet_tab[dir->__d_position].type);
dir->__d_position++;
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot; dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
res = 0; res = 0;
out: out:

View File

@ -1,6 +1,6 @@
/* fhandler_procsys.cc: fhandler for native NT namespace. /* fhandler_procsys.cc: fhandler for native NT namespace.
Copyright 2010, 2011, 2012, 2013 Red Hat, Inc. Copyright 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -346,6 +346,7 @@ fhandler_procsys::readdir (DIR *dir, dirent *de)
WCHAR buf[2][NAME_MAX + 1]; WCHAR buf[2][NAME_MAX + 1];
} f; } f;
int res = EBADF; int res = EBADF;
tmp_pathbuf tp;
if (dir->__handle != INVALID_HANDLE_VALUE) if (dir->__handle != INVALID_HANDLE_VALUE)
{ {
@ -357,10 +358,17 @@ fhandler_procsys::readdir (DIR *dir, dirent *de)
res = ENMFILE; res = ENMFILE;
else else
{ {
struct stat st;
char *file = tp.c_get ();
sys_wcstombs (de->d_name, NAME_MAX + 1, f.dbi.ObjectName.Buffer, sys_wcstombs (de->d_name, NAME_MAX + 1, f.dbi.ObjectName.Buffer,
f.dbi.ObjectName.Length / sizeof (WCHAR)); f.dbi.ObjectName.Length / sizeof (WCHAR));
de->d_ino = hash_path_name (get_ino (), de->d_name); de->d_ino = hash_path_name (get_ino (), de->d_name);
de->d_type = 0; stpcpy (stpcpy (stpcpy (file, get_name ()), "/"), de->d_name);
if (!lstat64 (file, &st))
de->d_type = IFTODT (st.st_mode);
else
de->d_type = DT_UNKNOWN;
res = 0; res = 0;
} }
} }

View File

@ -125,7 +125,9 @@ fhandler_procsysvipc::readdir (DIR *dir, dirent *de)
if (cygserver_running != CYGSERVER_OK) if (cygserver_running != CYGSERVER_OK)
goto out; goto out;
} }
strcpy (de->d_name, procsysvipc_tab[dir->__d_position++].name); strcpy (de->d_name, procsysvipc_tab[dir->__d_position].name);
de->d_type = virt_ftype_to_dtype (procsysvipc_tab[dir->__d_position].type);
dir->__d_position++;
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot; dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
res = 0; res = 0;
out: out:

View File

@ -1,6 +1,6 @@
/* fhandler_virtual.h: Header for virtual fhandlers /* fhandler_virtual.h: Header for virtual fhandlers
Copyright 2009, 2010, 2011 Red Hat, Inc. Copyright 2009, 2010, 2011, 2014 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -20,3 +20,26 @@ struct virt_tab_t {
extern virt_tab_t *virt_tab_search (const char *, bool, const virt_tab_t *, extern virt_tab_t *virt_tab_search (const char *, bool, const virt_tab_t *,
size_t); size_t);
static inline unsigned char
virt_ftype_to_dtype (virtual_ftype_t type)
{
unsigned char d_type;
switch (type)
{
case virt_directory:
d_type = DT_DIR;
break;
case virt_symlink:
d_type = DT_LNK;
break;
case virt_file:
d_type = DT_REG;
break;
default:
d_type = DT_UNKNOWN;
break;
}
return d_type;
}