Commits

Adam Hoka  committed e573a26

fix detection

  • Participants
  • Parent commits 7f1438e

Comments (0)

Files changed (1)

File os_cmd/NetBSD/ossdetect/ossdetect.c

 #include <sys/drvctlio.h>
 //#include <dev/pci/pcireg.h>
 
+dev_t default_dev = 0;
+
 #define PCI_PASS	0
 #define USB_PASS	1
 #define PSEUDO_PASS	2
   return 0;
 }
 
+static void
+create_node (char *drvname, char *name, int devno, mode_t node_m)
+{
+  struct stat st;
+  char tmp[64], *s, *p;
+  char cmd[128];
+  dev_t dev;
+
+  sprintf (tmp, "/dev/%s", drvname);
+
+  if (stat (tmp, &st) == -1)
+    dev = default_dev;
+  else
+    {
+      if (!S_ISCHR (st.st_mode))
+	return;
+      dev = st.st_rdev;
+    }
+
+  if (dev == 0)
+    return;
+
+/*
+ * Check if the device is located in a subdirectory (say /dev/oss/sblive0/pcm0).
+ */
+  sprintf (tmp, "/dev/%s", name);
+
+  s = tmp + 5;
+  p = s;
+  while (*s)
+    {
+      if (*s == '/')
+	p = s;
+      s++;
+    }
+
+  if (*p == '/')
+    {
+      *p = 0;			/* Extract the directory name part */
+      mkdir (tmp, 0755);
+    }
+
+  sprintf (tmp, "/dev/%s", name);
+  dev += devno;
+//  if (verbose)
+//    printf ("mknod %s c %d %d -m %o\n", tmp, major, minor, node_m);
+  unlink (tmp);
+
+  if (mknod (tmp, node_m, dev) == -1)
+    perror (tmp);
+}
+
 #if 0
 static int
 remove_devlinks (const char * dirname)
 }
 #endif
 
+#if 1
+static void
+create_devlinks (mode_t node_m)
+{
+  FILE *drvf, *f;
+  struct stat st;
+  char drvname[32], name[32], line[64], *s, tmp[256], instfname[2*OSSLIBDIRLEN];
+  mode_t perm;
+
+  snprintf (instfname, sizeof (instfname), "%s/%s", osslibdir,
+ 	    "etc/installed_drivers");
+
+  if ((drvf = fopen (instfname, "r")) == NULL)
+    {
+      perror (instfname);
+      return;
+    }
+
+  perm = umask (0);
+  mkdir ("/dev/oss", 0755);
+
+  while (fgets (drvname, sizeof (drvname), drvf) != NULL)
+    {
+      s = strchr (drvname, '\n');
+      if (s) *s = '\0';			/* Remove the LF character */
+
+      /* Remove the device full name (comment) field from the line */
+      s = drvname;
+      while (*s && *s != ' ' && *s != '#')
+	s++;
+      *s = '\0';
+      if (*drvname == '\0') continue;
+
+      sprintf (name, "/dev/%s0", drvname);
+
+      if (stat (name, &st) == -1)
+	continue;
+      default_dev = st.st_rdev;
+
+      if ((f = fopen (name, "r")) == NULL)
+	{
+	  perror (name);
+	  continue;
+	}
+
+      while (fgets (line, sizeof (line), f) != NULL)
+	{
+	  int minor;
+
+	  if (sscanf (line, "%s %s %d", name, drvname, &minor) != 3)
+	    {
+	      fprintf (stderr,
+		       "ossdetect: Unexpected line in the drvinfo file %s\n",
+		       name);
+	      fprintf (stderr, "'%s'\n", line);
+	      exit (-1);
+	    }
+
+	  create_node (drvname, name, minor, node_m);
+	}
+
+      fclose (f);
+      break;
+    }
+
+  umask (perm);
+  fclose (drvf);
+}
+#else
 static void
 create_devlinks (mode_t node_m)
 {
   umask (perm);
   fclose (f);
 }
+#endif
 
 static void
 pci_detect (void)
   int children, i, busnum;
   char busname[5];
   int fd;
-  
+
   if ((fd = open (DRVCTLDEV, O_RDONLY, 0)) == -1)
     {
       perror (DRVCTLDEV);
       //  sprintf (name, "pcs%x,%x", p->pc_subvendor, p->pc_subdevice);
       for (i = 0; i < l.l_children; i++)
 	{
+	  /* strip numbers, eg.: oss_sblive0 -> oss_sblive */
+	  char *name = strtok(l.l_childname[i], "0123456789");
 	  if (verbose > 2)
-	    fprintf(stderr, "add_drv pci -> %s\n", l.l_childname[i]);
-	  add_drv (l.l_childname[i], PCI_PASS);
+	    fprintf(stderr, "add_drv pci -> %s\n", name);
+	  add_drv (name, PCI_PASS);
 	}
   
       //  sprintf (name, "pci%x,%x", p->pc_vendor, p->pc_device);