[Glibc-bsd-commits] r1378 - in trunk/libfreebsd: . debian include/freebsd

Robert Millan rmh at costa.debian.org
Mon Mar 20 15:55:16 UTC 2006


Author: rmh
Date: 2006-03-20 15:55:15 +0000 (Mon, 20 Mar 2006)
New Revision: 1378

Added:
   trunk/libfreebsd/devname.c
   trunk/libfreebsd/sysctlbyname.c
   trunk/libfreebsd/sysctlnametomib.c
Modified:
   trunk/libfreebsd/Makefile
   trunk/libfreebsd/Versions
   trunk/libfreebsd/debian/changelog
   trunk/libfreebsd/include/freebsd/paths.h
   trunk/libfreebsd/nlist.c
Log:
  * paths.h: Define _PATH_SYSPATH.
  * Add devname{,_r}, sysctlnametomib and sysctlbyname.

Modified: trunk/libfreebsd/Makefile
===================================================================
--- trunk/libfreebsd/Makefile	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/Makefile	2006-03-20 15:55:15 UTC (rev 1378)
@@ -4,7 +4,7 @@
 # $Id: Makefile 905 2005-12-20 20:29:47Z aurel32 $
 #
 
-LIB_SRCS = nlist.c getbootfile.c
+LIB_SRCS = nlist.c getbootfile.c devname.c sysctlnametomib.c sysctlbyname.c
 
 LIB_FREEBSDINCLUDES = include/freebsd/paths.h
 LIB_INCLUDES = include/nlist.h
@@ -66,4 +66,3 @@
 	rm -f $(LIB_STATIC)
 	rm -f $(LIB_SHARED_OBJS)
 	rm -f $(LIB_SHARED) $(LIB_SONAME) $(LIB_SHARED_SO)
-

Modified: trunk/libfreebsd/Versions
===================================================================
--- trunk/libfreebsd/Versions	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/Versions	2006-03-20 15:55:15 UTC (rev 1378)
@@ -1,6 +1,8 @@
 LIBFREEBSD_0.0 {
   global:
+    devname; devname_r;
     getboofile;
+    sysctlbyname; sysctlnametomib;
     __aout_fdnlist;
     __elf_fdnlist;
     __fdnlist;

Modified: trunk/libfreebsd/debian/changelog
===================================================================
--- trunk/libfreebsd/debian/changelog	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/debian/changelog	2006-03-20 15:55:15 UTC (rev 1378)
@@ -1,8 +1,10 @@
 libfreebsd (0.0-2) UNRELEASED; urgency=low
 
   * Add kfreebsd-amd64.
+  * paths.h: Define _PATH_SYSPATH.
+  * Add devname{,_r}, sysctlnametomib and sysctlbyname.
 
- -- Robert Millan <rmh at aybabtu.com>  Sat,  4 Mar 2006 20:35:26 +0100
+ -- Robert Millan <rmh at aybabtu.com>  Mon, 20 Mar 2006 16:54:51 +0100
 
 libfreebsd (0.0-1) unreleased; urgency=low
 

Added: trunk/libfreebsd/devname.c
===================================================================
--- trunk/libfreebsd/devname.c	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/devname.c	2006-03-20 15:55:15 UTC (rev 1378)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 1989, 1993
+ *	The Regents of the University of California.  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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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>
+#include <sys/sysctl.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+char *
+devname_r(dev_t dev, mode_t type, char *buf, int len)
+{
+	int i;
+	size_t j;
+	char *r;
+
+	if ((type & S_IFMT) == S_IFCHR) {
+		j = len;
+		i = sysctlbyname("kern.devname", buf, &j, &dev, sizeof (dev));
+		if (i == 0)
+		    return (buf);
+	}
+
+	/* Finally just format it */
+	if (dev == NODEV)
+		r = "#NODEV";
+	else 
+		r = "#%c:%d:0x%x";
+	snprintf(buf, len, r,
+	    (type & S_IFMT) == S_IFCHR ? 'C' : 'B', major(dev), minor(dev));
+	return (buf);
+}
+
+char *
+devname(dev_t dev, mode_t type)
+{
+	static char buf[SPECNAMELEN + 1];
+
+	return(devname_r(dev, type, buf, sizeof(buf)));
+}

Modified: trunk/libfreebsd/include/freebsd/paths.h
===================================================================
--- trunk/libfreebsd/include/freebsd/paths.h	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/include/freebsd/paths.h	2006-03-20 15:55:15 UTC (rev 1378)
@@ -38,7 +38,10 @@
 #define	LIBFREEBSD_PATHS_H
 
 #include <sys/cdefs.h>
+#include <paths.h>
 
+/* Locate system binaries */
+#define _PATH_SYSPATH	"/sbin:/usr/sbin"
 
 /* How to get the correct name of the kernel. */
 __BEGIN_DECLS

Modified: trunk/libfreebsd/nlist.c
===================================================================
--- trunk/libfreebsd/nlist.c	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/nlist.c	2006-03-20 15:55:15 UTC (rev 1378)
@@ -53,7 +53,6 @@
 
 #ifdef _NLIST_DO_ELF
 #include <machine/elf.h>
-#include <elf-hints.h>
 #endif
 
 #define SIZE_T_MAX 0xffffffffU

Added: trunk/libfreebsd/sysctlbyname.c
===================================================================
--- trunk/libfreebsd/sysctlbyname.c	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/sysctlbyname.c	2006-03-20 15:55:15 UTC (rev 1378)
@@ -0,0 +1,36 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk at FreeBSD.org> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <string.h>
+
+int
+sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
+	     size_t newlen)
+{
+	int name2oid_oid[2];
+	int real_oid[CTL_MAXNAME+2];
+	int error;
+	size_t oidlen;
+
+	name2oid_oid[0] = 0;	/* This is magic & undocumented! */
+	name2oid_oid[1] = 3;
+
+	oidlen = sizeof(real_oid);
+	error = sysctl(name2oid_oid, 2, real_oid, &oidlen, (void *)name,
+		       strlen(name));
+	if (error < 0) 
+		return error;
+	oidlen /= sizeof (int);
+	error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen);
+	return (error);
+}
+

Added: trunk/libfreebsd/sysctlnametomib.c
===================================================================
--- trunk/libfreebsd/sysctlnametomib.c	2006-03-20 15:29:13 UTC (rev 1377)
+++ trunk/libfreebsd/sysctlnametomib.c	2006-03-20 15:55:15 UTC (rev 1378)
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2001 The FreeBSD Project. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``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 FREEBSD PROJECT 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>
+#include <sys/sysctl.h>
+#include <string.h>
+
+/*
+ * This function uses a presently undocumented interface to the kernel
+ * to walk the tree and get the type so it can print the value.
+ * This interface is under work and consideration, and should probably
+ * be killed with a big axe by the first person who can find the time.
+ * (be aware though, that the proper interface isn't as obvious as it
+ * may seem, there are various conflicting requirements.
+ */
+int
+sysctlnametomib(const char *name, int *mibp, size_t *sizep)
+{
+	int oid[2];
+	int error;
+
+	oid[0] = 0;
+	oid[1] = 3;
+
+	*sizep *= sizeof (int);
+	error = sysctl(oid, 2, mibp, sizep, (void *)name, strlen(name));
+	*sizep /= sizeof (int);
+	return (error);
+}




More information about the Glibc-bsd-commits mailing list