/*
* Copyright � 2007 Alistair Crooks. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
/* a device node describes the device that is printed in the dmesg */
typedef struct devicenode_t {
char *dev; /* device name */
int devlen; /* length of name */
char *parent; /* its parent device name */
int parentlen; /* length of parent name */
char *descr; /* description of the device itself */
int descrlen; /* length of description */
int p; /* device node subscript of parent */
int dir; /* nonzero if this is a directory */
} devicenode_t;
DEFINE_ARRAY(devices_t, devicenode_t);
static devices_t devices;
/* perform the stat operation */
/* if this is the root, then just synthesise the data */
static int
dmesgfs_getattr(const char *path, struct stat *st)
{
virt_dirent_t *ep;
/* save `n' chars of `s' in malloc'd memory */
static char *
strnsave(const char *s, int n)
{
char *cp;
if (n < 0) {
n = strlen(s);
}
NEWARRAY(char, cp, n + 1, "strnsave", exit(EXIT_FAILURE));
(void) memcpy(cp, s, n);
cp[n] = 0x0;
return cp;
}
/* find a device in the device node tree */
static int
finddev(const char *s, int len, int updir)
{
int i;
for (i = 0 ; i < devices.c ; i++) {
if (strncmp(devices.v[i].dev, s, len) == 0 &&
devices.v[i].devlen == len) {
if (updir) {
devices.v[i].dir = 1;
}
return i;
}
}
return -1;
}
/* add a device to the device node tree */
static void
add_dev(const char *dev, int len, const char *parent, int parentlen, const char *descr, int descrlen)
{
int d;
#define NEXUS_DESCRIPTION "Nexus - the root of everything"
/* build up a fuse_tree from the information in the database */
static int
build_tree(virtdir_t *tp, const char *nexus, char type)
{
struct stat dir;
struct stat f;
regmatch_t matchv[10];
regex_t r;
FILE *pp;
char buf[BUFSIZ];
int i;
int p;