From d9ad7a9c4edb8d5b8cadd7d1f0599c5f45635940 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 20 Jan 2009 18:04:32 +0000 Subject: [PATCH] * fhandler_procnet.cc: Reorganize global procnet content data into a new struct virt_tab_t. Accommodate throughout. * fhandler.h: Fix copyright dates. * fhandler_process.cc: Ditto. * fhandler_registry.cc: Ditto. --- winsup/cygwin/ChangeLog | 9 ++++ winsup/cygwin/fhandler.h | 2 +- winsup/cygwin/fhandler_process.cc | 2 +- winsup/cygwin/fhandler_procnet.cc | 67 ++++++++++++++---------------- winsup/cygwin/fhandler_registry.cc | 2 +- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index dd9e45fd3..36939198a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2009-01-20 Corinna Vinschen + + * fhandler_procnet.cc: Reorganize global procnet content data into a + new struct virt_tab_t. Accommodate throughout. + + * fhandler.h: Fix copyright dates. + * fhandler_process.cc: Ditto. + * fhandler_registry.cc: Ditto. + 2009-01-20 Corinna Vinschen * devices.h (FH_PROCESSFD): New device type. diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 66f90a058..b737c481b 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1,7 +1,7 @@ /* fhandler.h Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008 Red Hat, Inc. + 2005, 2006, 2007, 2008, 2009 Red Hat, Inc. This file is part of Cygwin. diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index 1f0198a82..710fbe72d 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -1,6 +1,6 @@ /* fhandler_process.cc: fhandler for /proc/ virtual filesystem - Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc. + Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Red Hat, Inc. This file is part of Cygwin. diff --git a/winsup/cygwin/fhandler_procnet.cc b/winsup/cygwin/fhandler_procnet.cc index e151555d4..3cf29dd6c 100644 --- a/winsup/cygwin/fhandler_procnet.cc +++ b/winsup/cygwin/fhandler_procnet.cc @@ -1,6 +1,6 @@ /* fhandler_procnet.cc: fhandler for /proc/net virtual filesystem - Copyright 2007 Red Hat, Inc. + Copyright 2007, 2008, 2009 Red Hat, Inc. This file is part of Cygwin. @@ -15,6 +15,7 @@ details. */ #include "security.h" #include "path.h" #include "fhandler.h" +#include "fhandler_virtual.h" #include "dtable.h" #include "cygheap.h" @@ -34,20 +35,18 @@ extern "C" int ip_addr_prefix (PIP_ADAPTER_UNICAST_ADDRESS pua, PIP_ADAPTER_PREFIX pap); bool get_adapters_addresses (PIP_ADAPTER_ADDRESSES *pa0, ULONG family); -static const int PROCNET_IFINET6 = 2; +static _off64_t format_procnet_ifinet6 (void *, char *&); -static const char * const process_listing[] = +static const virt_tab_t procnet_tab[] = { - ".", - "..", - "if_inet6", - NULL + { ".", FH_PROCNET, virt_directory, NULL }, + { "..", FH_PROCNET, virt_directory, NULL }, + { "if_inet6", FH_PROCNET, virt_file, format_procnet_ifinet6 }, + { NULL, 0, virt_none, NULL } }; -static const int PROCESS_LINK_COUNT = - (sizeof (process_listing) / sizeof (const char *)) - 1; - -static _off64_t format_procnet_ifinet6 (char *&filebuf); +static const int PROCNET_LINK_COUNT = + (sizeof (procnet_tab) / sizeof (virt_tab_t)) - 1; /* Returns 0 if path doesn't exist, >0 if path is a directory, * -1 if path is a file, -2 if path is a symlink, -3 if path is a pipe, @@ -64,19 +63,19 @@ fhandler_procnet::exists () if (*path == 0) return 1; - for (int i = 0; process_listing[i]; i++) - if (!strcmp (path + 1, process_listing[i])) + for (int i = 0; procnet_tab[i].name; i++) + if (!strcmp (path + 1, procnet_tab[i].name)) { - if (i == PROCNET_IFINET6) + if (procnet_tab[i].type == virt_file) { if (!wincap.has_gaa_prefixes () || !get_adapters_addresses (NULL, AF_INET6)) - return 0; + return virt_none; } fileid = i; - return -1; + return procnet_tab[i].type; } - return 0; + return virt_none; } fhandler_procnet::fhandler_procnet (): @@ -92,15 +91,15 @@ fhandler_procnet::fstat (struct __stat64 *buf) int file_type = exists (); switch (file_type) { - case 0: + case virt_none: set_errno (ENOENT); return -1; - case 1: - case 2: + case virt_directory: + case virt_rootdir: buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; buf->st_nlink = 2; return 0; - case -1: + case virt_file: default: buf->st_mode |= S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; return 0; @@ -111,15 +110,15 @@ int fhandler_procnet::readdir (DIR *dir, dirent *de) { int res = ENMFILE; - if (dir->__d_position >= PROCESS_LINK_COUNT) + if (dir->__d_position >= PROCNET_LINK_COUNT) goto out; - if (dir->__d_position == PROCNET_IFINET6) + if (procnet_tab[dir->__d_position].type == virt_file) { if (!wincap.has_gaa_prefixes () || !get_adapters_addresses (NULL, AF_INET6)) goto out; } - strcpy (de->d_name, process_listing[dir->__d_position++]); + strcpy (de->d_name, procnet_tab[dir->__d_position++].name); dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot; res = 0; out: @@ -165,10 +164,10 @@ fhandler_procnet::open (int flags, mode_t mode) } process_file_no = -1; - for (int i = 0; process_listing[i]; i++) + for (int i = 0; procnet_tab[i].name; i++) { - if (path_prefix_p (process_listing[i], path + 1, - strlen (process_listing[i]), false)) + if (path_prefix_p (procnet_tab[i].name, path + 1, + strlen (procnet_tab[i].name), false)) process_file_no = i; } if (process_file_no == -1) @@ -217,16 +216,12 @@ out: bool fhandler_procnet::fill_filebuf () { - switch (fileid) + if (procnet_tab[fileid].format_func) { - case PROCNET_IFINET6: - { - filesize = format_procnet_ifinet6 (filebuf); - break; - } + filesize = procnet_tab[fileid].format_func (NULL, filebuf); + return true; } - - return true; + return false; } /* Return the same scope values as Linux. */ @@ -255,7 +250,7 @@ static unsigned int dad_to_flags[] = }; static _off64_t -format_procnet_ifinet6 (char *&filebuf) +format_procnet_ifinet6 (void *, char *&filebuf) { PIP_ADAPTER_ADDRESSES pa0 = NULL, pap; PIP_ADAPTER_UNICAST_ADDRESS pua; diff --git a/winsup/cygwin/fhandler_registry.cc b/winsup/cygwin/fhandler_registry.cc index fa9d4c7a5..904184e63 100644 --- a/winsup/cygwin/fhandler_registry.cc +++ b/winsup/cygwin/fhandler_registry.cc @@ -1,6 +1,6 @@ /* fhandler_registry.cc: fhandler for /proc/registry virtual filesystem - Copyright 2002, 2003, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc. + Copyright 2002, 2003, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Red Hat, Inc. This file is part of Cygwin. -- 2.43.5