diff -urN oss-v4.1test0-070624-src-gpl.org/devlists/BeOS oss-v4.1test0-070624-src-gpl/devlists/BeOS
--- oss-v4.1test0-070624-src-gpl.org/devlists/BeOS	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/devlists/BeOS	Tue Jun 26 22:19:33 2007
@@ -0,0 +1,119 @@
+ali5455	pci10b9,5455	ALI M5455
+allegro	pci125d,1988	ESS Allegro ES1988
+allegro	pci125d,1990	ESS Canyon 3D ES1990
+allegro	pci125d,1992	ESS Canyon 3D-2 ES1992
+allegro	pci125d,1998	ESS Maestro3 ES1998
+allegro	pci125d,199a	ESS Maestro3 ES199A
+als300	pci4005,300	Avance Logic ALS300
+als300	pci4005,308	Avance Logic ALS300+
+als4000	pci4005,4000	Avance Logic ALS4000
+apci97	pci1102,8938	Creative Ectiva EV1938
+apci97	pci1274,1371	Creative AudioPCI97 (ES1371/ES1373)
+apci97	pci1274,5880	Creative Sound Blaster PCI128 (5880B)
+apci97	pci1274,8001	Creative Sound Blaster PCI128 (CT5880)
+apci97	pci1274,8002	Creative Sound Blaster PCI128 (5880A)
+atiaudio	pci1002,4341	ATI IXP200
+atiaudio	pci1002,4361	ATI IXP300
+atiaudio	pci1002,4370	ATI IXP400
+audigyls	pci1102,7	Sound Blaster Audigy LS / Live7.1
+audioloop	AUDIOLOOP	OSS loopback audio driver (BETA)
+audiopci	pci1274,5000	Creative AudioPCI (ES1370)
+cmi8788	pci13f6,8788	CMedia CMI8788
+cmpci	pci13f6,100	CMedia CM8338A
+cmpci	pci13f6,100	MIDIMan DiO 2448
+cmpci	pci13f6,101	CMedia CM8338B
+cmpci	pci13f6,111	CMedia CM8738/CM8768
+cmpci	pci14af,20	Guillemot Maxi Sound MUSE
+cs4280	pci1013,6001	Crystal CS4610
+cs4280	pci1013,6003	Crystal CS4280 
+cs4280	pci1013,6004	Crystal CS4615
+cs4280	pcs153b,112e	Terratec DMX Xfire 1024
+cs4280	pcs1681,50	Hercules Game Theater XP
+cs4280	pcs1681,51	Hercules Game Theater XP+
+cs4280	pcs5053,3357	TurtleBeach SantaCruz / VideoLogic SonicFury
+cs4281	pci1013,6005	Crystal CS4281
+digi32	pciea60,9896	RME Digi32
+digi32	pciea60,9897	RME Digi32 Pro
+digi32	pciea60,9898	RME Digi32/8
+digi96	pci10ee,3fc0	RME Digi96
+digi96	pci10ee,3fc1	RME Digi96/8
+digi96	pci10ee,3fc2	RME Digi96/8 PRO
+digi96	pci10ee,3fc3	RME Digi96/8 PAD
+emu10k1x	pci1102,6	Creative Sound Blaster 5.1 (Dell)
+fm801	pci1319,801	ForteMedia FM 801
+fm801	pcs1489,7008	Genius Sound Maker Live
+geode	pci100b,503	National Semiconductor Geode SC1200
+geode	pci1078,103	National Semiconductor Geode CS5530
+hdaudio	pci8086,2668	Intel High Definition Audio (ICH6)
+hdaudio	pci8086,27d8	Intel High Definition Audio (ICH7)
+hdaudio	pci8086,269a	Intel High Definition Audio (ESB2)
+hdaudio	pci8086,284b	Intel High Definition Audio (ICH8)
+hdaudio	pci8086,293f	Intel High Definition Audio (ICH9)
+hdaudio	pci10de,26c	Nvidia High Definition Audio (MCP51)
+hdaudio	pci10de,371	Nvidia High Definition Audio (MCP55)
+hdaudio	pci10de,3e4	Nvidia High Definition Audio (MCP61)
+hdaudio	pci10de,3f0	Nvidia High Definition Audio (MCP61)
+hdaudio	pci10de,44a	Nvidia High Definition Audio (MCP65)
+hdaudio	pci10de,55c	Nvidia High Definition Audio (MCP67)
+hdaudio	pci1002,437b	ATI High Definition Audio (SB450)
+hdaudio	pci1002,4383	ATI High Definition Audio (SB600)
+hdaudio	pci1106,3288	VIA High Definition Audio
+hdaudio	pci1039,7502	SiS High Definition Audio
+hdaudio	pci10b9,5461	ULI High Definition Audio
+ich	pci1022,7445	AMD 786
+ich	pci1022,746d	AMD 8111 
+ich	pci1039,7012	SiS 7012 
+ich	pci10de,1b1	Nvidia nForce
+ich	pci10de,6a	Nvidia nForce2
+ich	pci10de,8a	Nvidia CK8
+ich	pci10de,da	Nvidia nForce3
+ich	pci10de,ea	Nvidia CK8S
+ich	pci10de,59	Nvidia nForce4
+ich	pci10de,26b	Nvidia MCP51
+ich	pci8086,2415	Intel AC97 (ICH)
+ich	pci8086,2425	Intel AC97 (ICH1)
+ich	pci8086,2445	Intel AC97 (ICH2)
+ich	pci8086,2485	Intel AC97 (ICH3)
+ich	pci8086,24c5	Intel AC97 (ICH4)
+ich	pci8086,24d5	Intel AC97 (ICH5)
+ich	pci8086,25a6	Intel AC97 (ESB)
+ich	pci8086,266e	Intel AC97 (ICH6)
+ich	pci8086,27de	Intel AC97 (ICH7)
+ich	pci8086,7195	Intel 440MX (440MX)
+imux	IMUX	OSS Input Multiplexer 
+maestro	pci125d,1968	ESS Maestro-2 
+maestro	pci125d,1978	ESS Maestro-2E 
+maestro	pci1285,100	ESS Maestro-1 
+neomagic	pci10c8,8005	Neomagic NM2200AV
+s3vibes	pci5333,ca00	S3 Sonic Vibes
+sblive	pcs1102,21	Creative Sound Blaster Live
+sblive	pci1102,2	Creative Sound Blaster Live family
+sblive	pcs1102,8040	Creative Sound Blaster Live 1024/Platinum
+sblive	pcs1102,8061	Creative Sound Blaster Live 5.1/Platinum IR
+sblive	pci1102,4	Creative Sound Blaster Audigy/Audigy2
+sblive	pcs1102,51	Creative Sound Blaster Audigy Platinum
+sblive	pci1102,8	Creative Sound Blaster Audigy2 Value/Audigy4
+sblive	pci1102,2001	Creative Sound Blaster Audigy2 ZS Notebook
+softoss	SOFTOSS	OSS Virtual mixer/synth driver
+solo	pci125d,1969	ESS Solo-1 
+trident	pci1023,2000	Trident 4DWave-DX
+trident	pci1023,2001	Trident 4DWave-NX
+trident	pci1023,2002	Trident 4DWave-CX
+trident	pci1039,7018	SiS 7018 
+trident	pci10b9,5451	ALI M5451
+via8233	pci1106,3059	VIA VT8233/8235/8237 
+via8233	pci1106,4551	VIA VT5432B 
+via8233	pci1106,7059	VIA VT8233A 
+via8233	pcs1462,3800	MSI K7T266
+via8233	pcs1462,4720	MSI KT3 Ultra 
+via97	pci1106,3058	VIA VT82C686 
+vortex	pci12eb,1	Aureal Vortex (AU8820)
+vortex	pci12eb,2	Aureal Vortex2 (AU8830)
+vortex	AU8810		Aureal Vortex Advantage (AU8810)  *** NOT SUPPORTED ***
+ymf7xx	pci1073,10	Yamaha DS-XG YMF744 
+ymf7xx	pci1073,12	Yamaha DS-XG YMF754
+ymf7xx	pci1073,4	Yamaha DS-XG YMF724
+ymf7xx	pci1073,5	Yamaha DS-XG YMF734
+ymf7xx	pci1073,a	Yamaha DS-XG YMF740
+ymf7xx	pci1073,c	Yamaha DS-XG YMF740C
+ymf7xx	pci1073,d	Yamaha DS-XG YMF724F
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/.config oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/.config
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/.config	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/.config	Tue Jun 26 22:19:33 2007
@@ -0,0 +1 @@
+mode=kernel
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/core.inc oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/core.inc
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/core.inc	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/core.inc	Tue Jun 26 22:19:33 2007
@@ -0,0 +1,315 @@
+/* -*- c -*-
+ * Purpose: OSS module wrapper for BeOS/Haiku
+ *
+ * This file will be included from the auto-generated drv_cfg.c files. Under
+ * UnixWare and OpenServer this will will be compiled during the initial build
+ * of OSS (in the development system).
+ */
+/*
+ *
+ * This file is part of Open Sound System.
+ *
+ * Copyright (C) 4Front Technologies 1996-2007.
+ *
+ * This this source file is released under GPL v2 license (no other versions).
+ * See the COPYING file included in the main directory of this source
+ * distribution. Please contact sales@opensound.com for further info.
+ *
+ */
+
+#include <PCI.h>
+
+pci_module_info *gPCI = NULL;
+
+//#if DRIVER_TYPE==DRV_PCI ?
+
+status_t
+init_hardware(void)
+{
+	status_t err;
+	err = get_module(B_PCI_MODULE_NAME, &gPCI);
+	if (err < B_OK)
+		return err;
+	
+	put_module(B_PCI_MODULE_NAME);
+	return B_OK;
+}
+
+status_t
+init_driver(void)
+{
+	status_t err;
+	err = get_module(B_PCI_MODULE_NAME, &gPCI);
+	if (err < B_OK)
+		return err;
+	
+	
+	return B_OK;
+}
+
+void
+uninit_driver(void)
+{
+	status_t err;
+	
+	put_module(B_PCI_MODULE_NAME);
+}
+
+#ifdef SCO
+static int ossdrv_config (cfg_func_t func, void *idata, rm_key_t key);
+#if DRIVER_TYPE==DRV_VIRTUAL
+oss_device_t *osdev = NULL;
+#endif
+/*
+ * Driver information structures, for drv_attach().
+ */
+static const drvops_t oss_ops = {
+  ossdrv_config,
+  oss_open,
+  oss_close,
+  oss_devinfo,
+  oss_biostart,
+  oss_ioctl,
+  NULL,				/* drvctl */
+  NULL				/* mmap */
+};
+
+static const drvinfo_t oss_drvinfo = {
+  &oss_ops,
+  DRIVER_NICK,
+  D_MP,				/* MP-safe */
+  NULL,				/* Not a STREAMS driver */
+  256				/* Must match $maxchan in Node file */
+};
+
+static int
+rd_hex (char *s)
+{
+/*
+ * Convert a 4 digit hexadecimal string to integer value 
+ */
+  int v = 0;
+  int i;
+
+  for (i = 0; i < 4; i++)
+    {
+      char c = *s++;
+
+      if (c >= '0' && c <= '9')
+	{
+	  v = (v << 4) | (c - '0');
+	  continue;
+	}
+
+      if (c >= 'A' && c <= 'F')
+	{
+	  v = (v << 4) | (c - 'A' + 10);
+	  continue;
+	}
+
+      if (c >= 'a' && c <= 'f')
+	{
+	  v = (v << 4) | (c - 'a' + 10);
+	  continue;
+	}
+    }
+
+  return v;
+}
+
+static int
+cfg_add (void *idata, rm_key_t key)
+{
+  int err;
+  cm_args_t cma;
+  cm_num_t btype;
+  char id[32];
+  int vendor, product;
+  static int instance = 0;
+  oss_device_t *osdev;
+
+  cm_begin_trans (key, RM_READ);
+  cma.cm_key = key;
+  cma.cm_param = CM_BRDBUSTYPE;
+  cma.cm_val = &btype;
+  cma.cm_vallen = sizeof (btype);
+  cma.cm_n = 0;
+  err = cm_getval (&cma);
+  cm_end_trans (key);
+
+  if (err != 0 || btype != CM_BUS_PCI)
+    {
+      cmn_err (CE_WARN, "Bad BUS type %d\n", btype);
+      return ENODEV;
+    }
+
+  if ((osdev =
+       osdev_create (&key, DRIVER_TYPE, instance, DRIVER_NICK, NULL)) == NULL)
+    {
+      return EIO;
+    }
+
+  cm_begin_trans (key, RM_READ);
+  cma.cm_key = key;
+  cma.cm_param = CM_BRDID;
+  cma.cm_val = id;
+  cma.cm_vallen = sizeof (id);
+  cma.cm_n = 0;
+  err = cm_getval (&cma);
+  cm_end_trans (key);
+
+  vendor = rd_hex (id + 2);
+  product = rd_hex (id + 6);
+
+  osdev->vendor = vendor;
+  osdev->product = product;
+  osdev->drvinfo = (drvinfo_t *) & oss_drvinfo;
+  osdev->key = key;
+
+  if (!DRIVER_ATTACH (osdev))
+    {
+      cmn_err (CE_WARN, "Attach failed\n");
+      osdev_delete (osdev);
+      return EIO;
+    }
+
+  *(void **) idata = osdev;
+  oss_audio_delayed_attach ();
+
+  instance++;
+
+  return 0;
+}
+
+static int
+cfg_remove (void *idata)
+{
+  oss_device_t *osdev = idata;
+
+  if (idata == NULL)
+    {
+      cmn_err (CE_WARN, DRIVER_NICK ": ossdrv_detach: dip==NULL\n");
+      return EIO;
+    }
+
+  if (osdev == NULL)
+    {
+      cmn_err (CE_WARN, DRIVER_NICK ": Bad idatata\n");
+      return 0;
+    }
+
+  if (DRIVER_DETACH (osdev) <= 0)
+    {
+      DDB (cmn_err (CE_WARN, "Driver busy - cannot detach\n"));
+      return EBUSY;
+    }
+
+  osdev_delete (osdev);
+
+  DDB (cmn_err (CE_CONT, "Detach done " DRIVER_NICK, "\n"));
+  return 0;
+}
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+static int
+attach_virtual (void)
+{
+  DDB (cmn_err (CE_CONT, "Attach started " DRIVER_NICK "\n"));
+  if ((osdev =
+       osdev_create (NULL, DRIVER_TYPE, 0, DRIVER_NICK, NULL)) == NULL)
+    {
+      return EIO;
+    }
+
+  osdev->drvinfo = &oss_drvinfo;
+
+  if (!DRIVER_ATTACH (osdev))
+    {
+      cmn_err (CE_WARN, "Attach failed\n");
+      osdev_delete (osdev);
+      return EIO;
+    }
+
+  return 0;
+}
+
+static int
+detach_virtual (void)
+{
+  if (osdev == NULL)
+    {
+      return 0;
+    }
+
+  if (DRIVER_DETACH (osdev) <= 0)
+    {
+      DDB (cmn_err (CE_WARN, "Driver busy - cannot detach\n"));
+      return EBUSY;
+    }
+
+  osdev_delete (osdev);
+
+  return 0;
+}
+#endif
+
+static int
+ossdrv_config (cfg_func_t func, void *idata, rm_key_t key)
+{
+  switch (func)
+    {
+    case CFG_ADD:
+      return cfg_add (idata, key);
+      break;
+
+    case CFG_REMOVE:
+      return cfg_remove (idata);
+      break;
+
+    case CFG_VERIFY:
+      return 0;
+      break;
+
+    }
+
+  return EOPNOTSUPP;
+}
+
+/*
+ * Driver entry point routines
+ */
+
+int
+_load ()
+{
+  int err;
+
+  if ((err = drv_attach (&oss_drvinfo)) != 0)
+    {
+      cmn_err (CE_WARN, "drv_attach failed %d\n", err);
+      return err;
+    }
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+  attach_virtual ();
+#endif
+
+  return 0;
+}
+
+int
+_unload ()
+{
+  extern volatile int oss_open_devices;
+
+  if (oss_open_devices > 0)
+    return EBUSY;
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+  detach_virtual ();
+#endif
+
+  drv_detach (&oss_drvinfo);
+  return 0;
+}
+#endif
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/driver_beos.c oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/driver_beos.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/driver_beos.c	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/driver_beos.c	Tue Jun 26 22:19:33 2007
@@ -0,0 +1,103 @@
+/*
+ * Purpose: devfs interface for BeOS/Haiku
+ */
+/*
+ *
+ * This file is part of Open Sound System.
+ *
+ * Copyright (C) 4Front Technologies 1996-2007.
+ *
+ * This this source file is released under GPL v2 license (no other versions).
+ * See the COPYING file included in the main directory of this source
+ * distribution. Please contact sales@opensound.com for further info.
+ *
+ */
+
+#include "oss_config.h"
+#include "midi_core.h"
+#include <oss_pci.h>
+#include <KernelExport.h>
+#include <Drivers.h>
+
+#define DRIVER_NAME "ossdrv"
+
+int32 api_version = B_CUR_DRIVER_API_VERSION;
+
+oss_core_module_info *gOSSCore = NULL;
+
+//	#pragma mark -
+
+// XXX: malloc it + update it from device list
+
+const char **
+publish_devices(void)
+{
+	return gOSSCore->oss_publish_devices();
+}
+
+
+device_hooks *
+find_device(const char *name)
+{
+	FENTRYA("%s", name);
+
+	FEXIT();
+	return gOSSCore->oss_get_driver_hooks();
+}
+
+//	#pragma mark -
+
+status_t
+init_hardware(void)
+{
+	status_t err;
+	FENTRY();
+
+	err = get_module(OSS_CORE_MODULE_NAME, (module_info **)&gOSSCore);
+	if (err < B_OK) {
+		FEXIT();
+		return err;
+	}
+	
+	put_module(OSS_CORE_MODULE_NAME);
+	FEXIT();
+	return B_OK;
+}
+
+status_t
+init_driver(void)
+{
+	status_t err = ENOMEM;
+	FENTRY();
+
+	err = get_module(OSS_CORE_MODULE_NAME, (module_info **)&gOSSCore);
+	if (err < B_OK)
+		goto err1;
+	err = gOSSCore->init_osscore();
+	dprintf("oss:init_osscore: 0x%08lx\n", err);
+	if (err < B_OK)
+		goto err2;
+	err = gOSSCore->oss_load_drivers();
+	err = B_OK;
+	FEXITR(err);
+	return err;
+	
+err2:
+	put_module(OSS_CORE_MODULE_NAME);
+err1:
+	FEXITR(err);
+	return err;
+}
+
+void
+uninit_driver(void)
+{
+	status_t err;
+	FENTRY();
+	
+	err = gOSSCore->oss_unload_all_drivers();
+	err = gOSSCore->uninit_osscore();
+	dprintf("oss:uninit_osscore: 0x%08lx\n", err);
+	put_module(OSS_CORE_MODULE_NAME);
+	FEXIT();
+}
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/module.inc oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/module.inc
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/module.inc	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/module.inc	Tue Jun 26 23:02:21 2007
@@ -0,0 +1,445 @@
+/* -*- c -*-
+ * Purpose: OSS module wrapper for BeOS/Haiku
+ *
+ * This file will be included from the auto-generated drv_cfg.c files. Under
+ * UnixWare and OpenServer this will will be compiled during the initial build
+ * of OSS (in the development system).
+ */
+/*
+ *
+ * This file is part of Open Sound System.
+ *
+ * Copyright (C) 4Front Technologies 1996-2007.
+ *
+ * This this source file is released under GPL v2 license (no other versions).
+ * See the COPYING file included in the main directory of this source
+ * distribution. Please contact sales@opensound.com for further info.
+ *
+ */
+
+#include <PCI.h>
+
+//pci_module_info *gPCI = NULL;
+extern pci_module_info *gPCI;
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+static oss_device_t *osdev = NULL;
+#endif
+
+#if DRIVER_TYPE==DRV_PCI
+int DRIVER_PROBE()
+{
+  oss_device_t *osdev;
+  pci_info pcii;
+  uint32 pci_index = 0;
+  uint32 count = 0;
+  int err = ENOENT;
+  static int instance = 0;
+  FENTRY();
+  
+  /* while there are more pci devices */
+  while ((*gPCI->get_nth_pci_info)(pci_index, &pcii) == B_NO_ERROR)
+    {
+      int vendor = 0;
+
+      /* if we match a supported vendor */
+      while (id_table[vendor].vendor)
+        {
+          if (id_table[vendor].vendor == pcii.vendor_id &&
+              id_table[vendor].product == pcii.device_id)
+            {
+              dev_info_t *di;
+              dprintf("oss: matching pci %04x,%04x\n", pcii.vendor_id, pcii.device_id);
+              di = PMALLOC(NULL, sizeof(dev_info_t));
+              if (!di)
+                break;
+              memcpy(di, &pcii, sizeof(pcii));
+              if ((osdev =
+                   osdev_create (di, DRIVER_TYPE, instance, DRIVER_NICK, NULL)) == NULL)
+                {
+                  break;
+                }
+              
+              if (!DRIVER_ATTACH (osdev))
+                {
+                  cmn_err (CE_WARN, "Attach failed\n");
+                  osdev_delete (osdev);
+                  break;
+                }
+
+              instance++;
+              count++;
+              break;
+            }
+          vendor++;
+        }
+      /* next pci_info struct, please */
+      pci_index++;
+    }
+
+  oss_audio_delayed_attach ();
+
+  if (count)
+    err = 0;
+err:
+  FEXITR(err);
+  return err;
+}
+#endif
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+int DRIVER_PROBE()
+{
+  int err = EIO;
+  FENTRY();
+  if ((osdev =
+       osdev_create (NULL, DRIVER_TYPE, 0, DRIVER_NICK, NULL)) == NULL)
+    {
+      goto err;
+    }
+
+  if (!DRIVER_ATTACH (osdev))
+    {
+      cmn_err (CE_WARN, "Attach failed\n");
+      osdev_delete (osdev);
+      goto err;
+    }
+
+  err = 0;
+err:
+  FEXITR(err);
+  return err;
+}
+#endif
+
+
+
+
+
+
+static status_t
+stdops(int32 op, ...)
+{
+  status_t err;
+  switch (op)
+    {
+    case B_MODULE_INIT:
+      err = get_module(B_PCI_MODULE_NAME, (module_info **)&gPCI);
+      return err;
+
+    case B_MODULE_UNINIT:
+      //err = unload_driver(DRIVER_NICK);
+      //if (err < B_OK)
+      //  return err;
+      put_module(B_PCI_MODULE_NAME);
+      return B_OK;
+
+    }
+  return B_ERROR;
+}
+
+oss_drv_module_info DRIVER_MODULE_OBJECT = {
+	{
+		OSS_MAKE_DRV_MOD_NAME(DRIVER_NICK),
+		0,
+		stdops,
+	},
+	DRIVER_PROBE,
+	DRIVER_ATTACH,
+	DRIVER_DETACH
+};
+
+
+//#if DRIVER_TYPE==DRV_PCI ?
+#if 0
+status_t
+init_hardware(void)
+{
+	status_t err;
+	err = get_module(B_PCI_MODULE_NAME, &gPCI);
+	if (err < B_OK)
+		return err;
+	
+	put_module(B_PCI_MODULE_NAME);
+	return B_OK;
+}
+
+status_t
+init_driver(void)
+{
+	status_t err;
+	err = get_module(B_PCI_MODULE_NAME, &gPCI);
+	if (err < B_OK)
+		return err;
+	
+	
+	return B_OK;
+}
+
+void
+uninit_driver(void)
+{
+	status_t err;
+	
+	put_module(B_PCI_MODULE_NAME);
+}
+#endif
+
+#ifdef SCO
+static int ossdrv_config (cfg_func_t func, void *idata, rm_key_t key);
+#if DRIVER_TYPE==DRV_VIRTUAL
+oss_device_t *osdev = NULL;
+#endif
+/*
+ * Driver information structures, for drv_attach().
+ */
+static const drvops_t oss_ops = {
+  ossdrv_config,
+  oss_open,
+  oss_close,
+  oss_devinfo,
+  oss_biostart,
+  oss_ioctl,
+  NULL,				/* drvctl */
+  NULL				/* mmap */
+};
+
+static const drvinfo_t oss_drvinfo = {
+  &oss_ops,
+  DRIVER_NICK,
+  D_MP,				/* MP-safe */
+  NULL,				/* Not a STREAMS driver */
+  256				/* Must match $maxchan in Node file */
+};
+
+static int
+rd_hex (char *s)
+{
+/*
+ * Convert a 4 digit hexadecimal string to integer value 
+ */
+  int v = 0;
+  int i;
+
+  for (i = 0; i < 4; i++)
+    {
+      char c = *s++;
+
+      if (c >= '0' && c <= '9')
+	{
+	  v = (v << 4) | (c - '0');
+	  continue;
+	}
+
+      if (c >= 'A' && c <= 'F')
+	{
+	  v = (v << 4) | (c - 'A' + 10);
+	  continue;
+	}
+
+      if (c >= 'a' && c <= 'f')
+	{
+	  v = (v << 4) | (c - 'a' + 10);
+	  continue;
+	}
+    }
+
+  return v;
+}
+
+static int
+cfg_add (void *idata, rm_key_t key)
+{
+  int err;
+  cm_args_t cma;
+  cm_num_t btype;
+  char id[32];
+  int vendor, product;
+  static int instance = 0;
+  oss_device_t *osdev;
+
+  cm_begin_trans (key, RM_READ);
+  cma.cm_key = key;
+  cma.cm_param = CM_BRDBUSTYPE;
+  cma.cm_val = &btype;
+  cma.cm_vallen = sizeof (btype);
+  cma.cm_n = 0;
+  err = cm_getval (&cma);
+  cm_end_trans (key);
+
+  if (err != 0 || btype != CM_BUS_PCI)
+    {
+      cmn_err (CE_WARN, "Bad BUS type %d\n", btype);
+      return ENODEV;
+    }
+
+  if ((osdev =
+       osdev_create (&key, DRIVER_TYPE, instance, DRIVER_NICK, NULL)) == NULL)
+    {
+      return EIO;
+    }
+
+  cm_begin_trans (key, RM_READ);
+  cma.cm_key = key;
+  cma.cm_param = CM_BRDID;
+  cma.cm_val = id;
+  cma.cm_vallen = sizeof (id);
+  cma.cm_n = 0;
+  err = cm_getval (&cma);
+  cm_end_trans (key);
+
+  vendor = rd_hex (id + 2);
+  product = rd_hex (id + 6);
+
+  osdev->vendor = vendor;
+  osdev->product = product;
+  osdev->drvinfo = (drvinfo_t *) & oss_drvinfo;
+  osdev->key = key;
+
+  if (!DRIVER_ATTACH (osdev))
+    {
+      cmn_err (CE_WARN, "Attach failed\n");
+      osdev_delete (osdev);
+      return EIO;
+    }
+
+  *(void **) idata = osdev;
+  oss_audio_delayed_attach ();
+
+  instance++;
+
+  return 0;
+}
+
+static int
+cfg_remove (void *idata)
+{
+  oss_device_t *osdev = idata;
+
+  if (idata == NULL)
+    {
+      cmn_err (CE_WARN, DRIVER_NICK ": ossdrv_detach: dip==NULL\n");
+      return EIO;
+    }
+
+  if (osdev == NULL)
+    {
+      cmn_err (CE_WARN, DRIVER_NICK ": Bad idatata\n");
+      return 0;
+    }
+
+  if (DRIVER_DETACH (osdev) <= 0)
+    {
+      DDB (cmn_err (CE_WARN, "Driver busy - cannot detach\n"));
+      return EBUSY;
+    }
+
+  osdev_delete (osdev);
+
+  DDB (cmn_err (CE_CONT, "Detach done " DRIVER_NICK, "\n"));
+  return 0;
+}
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+static int
+attach_virtual (void)
+{
+  DDB (cmn_err (CE_CONT, "Attach started " DRIVER_NICK "\n"));
+  if ((osdev =
+       osdev_create (NULL, DRIVER_TYPE, 0, DRIVER_NICK, NULL)) == NULL)
+    {
+      return EIO;
+    }
+
+  osdev->drvinfo = &oss_drvinfo;
+
+  if (!DRIVER_ATTACH (osdev))
+    {
+      cmn_err (CE_WARN, "Attach failed\n");
+      osdev_delete (osdev);
+      return EIO;
+    }
+
+  return 0;
+}
+
+static int
+detach_virtual (void)
+{
+  if (osdev == NULL)
+    {
+      return 0;
+    }
+
+  if (DRIVER_DETACH (osdev) <= 0)
+    {
+      DDB (cmn_err (CE_WARN, "Driver busy - cannot detach\n"));
+      return EBUSY;
+    }
+
+  osdev_delete (osdev);
+
+  return 0;
+}
+#endif
+
+static int
+ossdrv_config (cfg_func_t func, void *idata, rm_key_t key)
+{
+  switch (func)
+    {
+    case CFG_ADD:
+      return cfg_add (idata, key);
+      break;
+
+    case CFG_REMOVE:
+      return cfg_remove (idata);
+      break;
+
+    case CFG_VERIFY:
+      return 0;
+      break;
+
+    }
+
+  return EOPNOTSUPP;
+}
+
+/*
+ * Driver entry point routines
+ */
+
+int
+_load ()
+{
+  int err;
+
+  if ((err = drv_attach (&oss_drvinfo)) != 0)
+    {
+      cmn_err (CE_WARN, "drv_attach failed %d\n", err);
+      return err;
+    }
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+  attach_virtual ();
+#endif
+
+  return 0;
+}
+
+int
+_unload ()
+{
+  extern volatile int oss_open_devices;
+
+  if (oss_open_devices > 0)
+    return EBUSY;
+
+#if DRIVER_TYPE==DRV_VIRTUAL
+  detach_virtual ();
+#endif
+
+  drv_detach (&oss_drvinfo);
+  return 0;
+}
+#endif
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/os_beos.c oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/os_beos.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/os_beos.c	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/os_beos.c	Wed Jun 27 03:10:02 2007
@@ -0,0 +1,1836 @@
+/*
+ * Purpose: Operating system abstraction functions for BeOS/Haiku
+ */
+/*
+ *
+ * This file is part of Open Sound System.
+ *
+ * Copyright (C) 4Front Technologies 1996-2007.
+ *
+ * This this source file is released under GPL v2 license (no other versions).
+ * See the COPYING file included in the main directory of this source
+ * distribution. Please contact sales@opensound.com for further info.
+ *
+ */
+
+#include "oss_config.h"
+#include "midi_core.h"
+#include <oss_pci.h>
+#include <Drivers.h>
+#include <KernelExport.h>
+
+volatile int oss_open_devices = 0;
+#define MAX_CARDS	16
+int oss_num_cards = 0;
+static oss_device_t *cards[MAX_CARDS];
+static int oss_expired = 0;
+
+static oss_mutex_t osscore_mutex;
+
+//static struct fileinfo files[OSS_MAX_CDEVS];
+static volatile int open_count[OSS_MAX_CDEVS] = { 0 };
+static volatile int open_devices = 0;
+
+pci_module_info *gPCI = NULL;
+
+static char *gDevnames; // buffer for all names
+
+device_hooks oss_driver_hooks;
+
+/*
+ * Table for permanently allocated memory (to be freed by std_op(UNLOAD))
+ */
+#define MAX_MEMBLOCKS	4096
+static void *memblocks[MAX_MEMBLOCKS];
+static int nmemblocks = 0;
+
+void *
+oss_contig_malloc (oss_device_t * osdev, int size, oss_uint64_t memlimit,
+		   oss_native_word * phaddr)
+{
+  status_t err;
+  area_id id;
+  void *p = NULL;
+  uint32 lock = B_CONTIGUOUS;
+  physical_entry pent[1];
+
+  *phaddr = 0;
+
+  switch (memlimit)
+    {
+    case MEMLIMIT_ISA:
+    case MEMLIMIT_28BITS:
+    case MEMLIMIT_30BITS:
+    case MEMLIMIT_31BITS:
+      /* no known way to force a physical address limit other than <16M */
+      lock = B_LOMEM;
+      break;
+    case MEMLIMIT_32BITS:
+      lock = B_CONTIGUOUS;
+      break;
+
+    default:
+      cmn_err (CE_WARN, "Bad DMA memlimit for %s\n", osdev->nick);
+    }
+
+  /* round up to page size */
+  size += B_PAGE_SIZE - 1;
+  size &= ~(B_PAGE_SIZE - 1);
+
+  if ((err = id = create_area(OSS_CONTIG_AREA_NAME, &p, B_ANY_KERNEL_ADDRESS,
+                         size, lock, 0)) < B_OK)
+    {
+      cmn_err (CE_WARN, "create_area() failed\n");
+      return NULL;
+    }
+
+  if ((err = get_memory_map(p, size, pent, 1)) < B_OK)
+    {
+      cmn_err (CE_WARN, "get_memory_map() failed\n");
+      delete_area(id);
+      return NULL;
+    }
+  *phaddr = (oss_native_word)pent[0].address;
+  return p;
+}
+
+void
+oss_contig_free (oss_device_t * osdev, void *p, int sz)
+{
+  area_id id;
+  if (p == NULL)
+    return;
+  id = area_for(p);
+  if (id < B_OK)
+    return;
+#ifdef MEMDEBUG
+  {
+    area_info ai;
+    if ((get_area_info(id, &ai) < B_OK) || strncmp(ai.name, OSS_CONTIG_AREA_NAME))
+      {
+        cmn_err (CE_NOTE, "oss_contig_free: bad area (%ld)!\n", id);
+        return;
+      }
+  }
+#endif
+  delete_area(id);
+}
+
+int
+__oss_alloc_dmabuf (int dev, dmap_p dmap, unsigned int alloc_flags,
+		    oss_uint64_t maxaddr, int direction)
+{
+  void *tmpbuf;
+  oss_native_word phaddr;
+  int size = 64 * 1024;
+  extern int dma_buffsize;
+
+  if (dma_buffsize > 16 && dma_buffsize <= 128)
+    size = dma_buffsize * 1024;
+
+  if (dmap->dmabuf != NULL)
+    return 0;
+
+/*
+ * Some applications and virtual drivers need shorter buffer.
+ */
+  if (dmap->flags & DMAP_SMALLBUF)
+    {
+      size = SMALL_DMABUF_SIZE;
+    }
+  else if (dmap->flags & DMAP_MEDIUMBUF)
+    {
+      size = MEDIUM_DMABUF_SIZE;
+    }
+
+  if ((alloc_flags & DMABUF_SIZE_16BITS) && size > 32 * 1024)
+    size = 32 * 1024;
+
+  tmpbuf = CONTIG_MALLOC (dmap->osdev, size, maxaddr, &phaddr);
+  if (tmpbuf == NULL)
+    return RETERR(ENOMEM);
+  dmap->dmabuf = tmpbuf;
+  dmap->buffsize = size;
+  dmap->dmabuf_phys = phaddr;
+
+  return 0;
+}
+
+void
+oss_free_dmabuf (int dev, dmap_p dmap)
+{
+  if (dmap->dmabuf == NULL)
+    return;
+
+  CONTIG_FREE (dmap->osdev, dmap->dmabuf, dmap->buffsize);
+  dmap->dmabuf = NULL;
+  dmap->buffsize = 0;
+  dmap->dmabuf_phys = 0;
+}
+
+
+oss_native_word
+oss_virt_to_bus (void *addr)
+{
+  physical_entry pent[2];
+  status_t err;
+
+  if (addr == NULL)
+    return 0;
+
+  /* XXX: ROUNDUP(B_PAGE_SIZE) ? */
+  if ((err = get_memory_map(addr, 1, pent, 2)) < 1)
+    {
+      cmn_err (CE_WARN, "Virtual address %x not mapped\n", (int) addr);
+      return 0;
+    }
+  //XXX:which???
+  //return (oss_native_word)pent[0].address;
+  return (oss_native_word)(gPCI->ram_address(pent[0].address));
+}
+
+
+void *
+oss_pmalloc (size_t sz)
+{
+  void *tmp;
+
+  tmp = KERNEL_MALLOC (sz);
+
+  if (nmemblocks < MAX_MEMBLOCKS)
+    memblocks[nmemblocks++] = tmp;
+
+  return tmp;
+}
+
+int
+oss_create_uio (uio_t * uio, char *buf, size_t count, uio_rw_t rw,
+		int is_kernel)
+{
+  memset (uio, 0, sizeof (*uio));
+
+  if (is_kernel)
+    {
+      oss_cmn_err (CE_CONT,
+		   "oss_create_uio: Kernel space buffers not supported\n");
+      return RETERR(EIO);
+    }
+
+  uio->ptr = buf;
+  uio->resid = count;
+  uio->kernel_space = is_kernel;
+  uio->rw = rw;
+
+  return 0;
+}
+
+int
+oss_uiomove (void *address, size_t nbytes, enum uio_rw rwflag, uio_t * uio)
+{
+  int err = EFAULT;
+  FENTRY();
+
+  if (rwflag != uio->rw)
+    {
+      oss_cmn_err (CE_WARN, "uiomove: Bad direction\n");
+      goto err;
+    }
+
+  if (uio->resid < nbytes)
+    {
+      oss_cmn_err (CE_WARN, "uiomove: Bad count %d (%d)\n", nbytes,
+		   uio->resid);
+      goto err;
+    }
+
+  if (uio->kernel_space)
+    goto err;
+
+  switch (rwflag)
+    {
+    case UIO_READ:
+      //XXX:user_memcpy...
+      memcpy (uio->ptr, address, nbytes);
+      break;
+
+    case UIO_WRITE:
+      //XXX:user_memcpy...
+      memcpy (address, uio->ptr, nbytes);
+      break;
+    }
+
+  uio->resid -= nbytes;
+  uio->ptr += nbytes;
+
+  err = B_OK;
+err:
+  FEXITR(err);
+  return err;
+}
+
+
+void
+oss_cmn_err (int level, char *s, ...)
+{
+  char tmp[1024], *a[6];
+  va_list ap;
+  int i, n = 0;
+
+  va_start (ap, s);
+
+  for (i = 0; i < strlen (s); i++)
+    if (s[i] == '%')
+      n++;
+
+  for (i = 0; i < n && i < 6; i++)
+    a[i] = va_arg (ap, char *);
+
+  for (i = n; i < 6; i++)
+    a[i] = NULL;
+
+  if (level == CE_CONT)
+    {
+      sprintf (tmp, s, a[0], a[1], a[2], a[3], a[4], a[5], NULL,
+	       NULL, NULL, NULL);
+      dprintf ("%s", tmp);
+    }
+  else
+    {
+      strcpy (tmp, "osscore: ");
+      sprintf (tmp + strlen (tmp), s, a[0], a[1], a[2], a[3], a[4], a[5],
+	       NULL, NULL, NULL, NULL);
+      if (level == CE_PANIC)
+	panic (tmp);
+
+      dprintf ("%s", tmp);
+    }
+  va_end (ap);
+}
+
+
+/*
+ * Sleep/wakeup
+ */
+
+struct oss_wait_queue *
+oss_create_wait_queue (oss_device_t * osdev, const char *name)
+{
+  struct oss_wait_queue *wq;
+  status_t err;
+  FENTRYA(", %s", name);
+
+  if ((wq = malloc (sizeof (*wq))) == NULL)
+    {
+      oss_cmn_err (CE_WARN, "malloc(%d) failed (wq)\n", sizeof (*wq));
+      return NULL;
+    }
+  sprintf(wq->name, OSS_WQ_SEM_NAME "%.20s", name);
+  err = wq->sem = create_sem(0, wq->name);
+  if (err < B_OK)
+    {
+      free(wq);
+      oss_cmn_err (CE_WARN, "create_sem() failed (wq)\n");
+      return NULL;
+    }
+
+  return wq;
+}
+
+void
+oss_reset_wait_queue (struct oss_wait_queue *wq)
+{
+  sem_info si;
+  status_t err;
+  FENTRY();
+  
+  wq->flags = 0;
+  err = create_sem(0, wq->name);
+  if (err >= 0) {
+    /* replace with the new one */
+    delete_sem(wq->sem);
+    wq->sem = err;
+  }
+  
+  FEXIT();
+}
+
+void
+oss_remove_wait_queue (struct oss_wait_queue *wq)
+{
+  FENTRY();
+  delete_sem(wq->sem);
+  free (wq);
+}
+
+int
+oss_sleep (struct oss_wait_queue *wq, oss_mutex_t * mutex, int ticks,
+	   oss_native_word * flags, unsigned int *status)
+{
+  bigtime_t timeout = B_INFINITE_TIMEOUT;
+  uint32 semflags = B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT;
+  int result = 0;
+  FENTRYA("(%s), , %d, , ", wq->name, ticks);
+  *status = 0;
+
+  if (wq == NULL)
+    return 0;
+
+#ifdef B_WAKE_ON_TIMEOUT
+  // Dano only; sure it's what we want ?
+  if (wq->flags & WK_WAKEUP)
+    flags |= B_WAKE_ON_TIMEOUT;
+#endif
+
+  wq->flags = 0;
+  MUTEX_EXIT_IRQRESTORE(*mutex, *flags);
+
+  if (ticks > 0)
+    timeout = ticks * 1000000LL / OSS_HZ;
+  result = acquire_sem_etc (wq->sem, 1, semflags, timeout);
+  //dprintf("oss_sleep:acquire_sem(s:%ld, 1, %x, %Ld): 0x%08lx\n", wq->sem, semflags, timeout, result);
+
+  MUTEX_ENTER_IRQDISABLE (*mutex, *flags);
+
+  if (result == EINTR)		/* Signal received */
+    {
+      *status |= WK_SIGNAL;
+      return 1;
+    }
+
+//if (result == B_TIMED_OUT)
+  if (!(wq->flags & WK_WAKEUP))	/* Timeout */
+    {
+      return 0;
+    }
+
+  return 1;
+}
+
+int
+oss_register_poll (struct oss_wait_queue *wq, oss_mutex_t * mutex,
+		   oss_native_word * flags, oss_poll_event_t * ev)
+{
+  FENTRYA("(%s), , , , ", wq->name);
+  dprintf("oss:UNIMPLEMENTED:%s\n", __FUNCTION__);
+  MUTEX_EXIT_IRQRESTORE(*mutex, *flags);
+  //poll_wait ((struct file *) ev->file, &wq->wq, (struct wait *) ev->wait);
+  MUTEX_ENTER_IRQDISABLE (*mutex, *flags);
+  return 0;
+}
+
+void
+oss_wakeup (struct oss_wait_queue *wq, oss_mutex_t * mutex,
+	    oss_native_word * flags, short events)
+{
+  FENTRYA("(%s), , %x, , ", wq->name, events);
+  if (wq == NULL)
+    return;
+
+  wq->flags |= WK_WAKEUP;
+  MUTEX_EXIT_IRQRESTORE(*mutex, *flags);
+  
+  //dprintf("oss_wakeup:release_sem(s:%ld)\n", wq->sem);
+  release_sem_etc (wq->sem, 1, B_DO_NOT_RESCHEDULE);
+  //XXX:handle select here
+  
+  MUTEX_ENTER_IRQDISABLE (*mutex, *flags);
+}
+
+unsigned long
+oss_get_time (void)
+{
+  return (unsigned long) (system_time() / (1000000 / OSS_HZ));
+}
+
+typedef struct tmout_desc
+{
+  struct timer timer; /* MUST be first */
+
+  volatile int active;
+  int timestamp;
+  void (*func) (void *);
+  void *arg;
+} tmout_desc_t;
+
+static volatile int next_id = 0;
+#define MAX_TMOUTS 128
+
+tmout_desc_t tmouts[MAX_TMOUTS] = { {0} };
+
+int timeout_random = 0x12123400;
+
+int32
+oss_timer_callback (struct timer *timer)
+{
+  tmout_desc_t *tmout = (tmout_desc_t *)timer;
+  int ix;
+  void *arg;
+
+  timeout_random++;
+
+  if (!tmout->active)
+    return;
+
+  arg = tmout->arg;
+  tmout->active = 0;
+  tmout->timestamp = 0;
+
+  tmout->func (arg);
+  return B_HANDLED_INTERRUPT;//B_INVOKE_SCHEDULER ?;
+}
+
+timeout_id_t
+oss_timeout (void (*func) (void *), void *arg, unsigned long long ticks)
+{
+  tmout_desc_t *tmout = NULL;
+  bigtime_t period;
+  int id, n;
+
+  timeout_random++;
+
+  n = 0;
+  id = -1;
+
+  while (id == -1 && n < MAX_TMOUTS)
+    {
+      if (!tmouts[next_id].active)
+	{
+	  tmouts[next_id].active = 1;
+	  id = next_id++;
+	  tmout = &tmouts[id];
+	  break;
+	}
+
+      next_id = (next_id + 1) % MAX_TMOUTS;
+    }
+
+  if (id == -1)			/* No timer slots available */
+    {
+      oss_cmn_err (CE_WARN, "Timeout table full\n");
+      return 0;
+    }
+
+  tmout->func = func;
+  tmout->arg = arg;
+  tmout->timestamp = id | (timeout_random & ~0xff);
+
+  period = ticks * 1000000LL / OSS_HZ;
+  add_timer (&tmout->timer, oss_timer_callback, period, B_ONE_SHOT_RELATIVE_TIMER);
+
+  return id | (timeout_random & ~0xff);
+}
+
+void
+oss_untimeout (timeout_id_t id)
+{
+  tmout_desc_t *tmout;
+  int ix;
+
+  ix = id & 0xff;
+  if (ix < 0 || ix >= MAX_TMOUTS)
+    return;
+
+  timeout_random++;
+  tmout = &tmouts[ix];
+
+  if (tmout->timestamp != id)	/* Expired timer */
+    return;
+  if (tmout->active)
+    cancel_timer (&tmout->timer);
+  tmout->active = 0;
+  tmout->timestamp = 0;
+}
+
+
+caddr_t
+oss_map_pci_mem (oss_device_t * osdev, int nr, int phaddr, int size)
+{
+  status_t err;
+  void *va = NULL;
+  FENTRYA("%p,%d,%d,%d", osdev, nr, phaddr, size);
+  //XXX:align phaddr ?
+  /* round up to page size */
+  size += B_PAGE_SIZE - 1;
+  size &= ~(B_PAGE_SIZE - 1);
+  
+  err = map_physical_memory(OSS_PCI_AREA_NAME, (void *)phaddr, size, 
+                            B_ANY_KERNEL_BLOCK_ADDRESS, 0, &va);
+  if (err < B_OK)
+    va = NULL;
+  FEXITR((uint32)va);
+  return (caddr_t)va;
+}
+
+void
+oss_unmap_pci_mem (void *addr)
+{
+  area_id id;
+  if (addr == NULL)
+    return;
+  id = area_for(addr);
+  if (id < B_OK)
+    return;
+#ifdef MEMDEBUG
+  {
+    area_info ai;
+    if ((get_area_info(id, &ai) < B_OK) || strncmp(ai.name, OSS_PCI_AREA_NAME))
+      {
+        cmn_err (CE_NOTE, "oss_unmap_pci_mem: bad area (%ld)!\n", id);
+        return;
+      }
+  }
+#endif
+  delete_area(id);
+}
+
+void
+oss_pci_byteswap (oss_device_t * osdev, int mode)
+{
+  // NOP
+}
+
+int
+pci_read_config_byte (oss_device_t * osdev, offset_t where,
+		      unsigned char *val)
+{
+  if (osdev->dev_type != DRV_PCI || osdev->dip == NULL)
+    return PCIBIOS_FAILED;
+  *val = (unsigned char)gPCI->read_pci_config (osdev->dip->pciinfo.bus,
+                                               osdev->dip->pciinfo.device,
+                                               osdev->dip->pciinfo.function,
+                                               (uchar)where, 1);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+int
+pci_read_config_irq (oss_device_t * osdev, offset_t where, unsigned char *val)
+{
+  int ret;
+
+  if (osdev->dev_type != DRV_PCI)
+    return PCIBIOS_FAILED;
+  ret = pci_read_config_byte (osdev, where, val);
+  return ret;
+}
+
+
+int
+pci_read_config_word (oss_device_t * osdev, offset_t where,
+		      unsigned short *val)
+{
+  if (osdev->dev_type != DRV_PCI || osdev->dip == NULL)
+    return PCIBIOS_FAILED;
+  *val = (unsigned short)gPCI->read_pci_config (osdev->dip->pciinfo.bus,
+                                                osdev->dip->pciinfo.device,
+                                                osdev->dip->pciinfo.function,
+                                                (uchar)where, 2);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+int
+pci_read_config_dword (oss_device_t * osdev, offset_t where,
+		       unsigned int *val)
+{
+  if (osdev->dev_type != DRV_PCI || osdev->dip == NULL)
+    return PCIBIOS_FAILED;
+  *val = (unsigned int)gPCI->read_pci_config (osdev->dip->pciinfo.bus,
+                                              osdev->dip->pciinfo.device,
+                                              osdev->dip->pciinfo.function,
+                                              (uchar)where, 4);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+int
+pci_write_config_byte (oss_device_t * osdev, offset_t where,
+		       unsigned char val)
+{
+  if (osdev->dev_type != DRV_PCI || osdev->dip == NULL)
+    return PCIBIOS_FAILED;
+  gPCI->write_pci_config (osdev->dip->pciinfo.bus,
+                          osdev->dip->pciinfo.device,
+                          osdev->dip->pciinfo.function,
+                          (uchar)where, 1, val);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+int
+pci_write_config_word (oss_device_t * osdev, offset_t where,
+		       unsigned short val)
+{
+  if (osdev->dev_type != DRV_PCI || osdev->dip == NULL)
+    return PCIBIOS_FAILED;
+  gPCI->write_pci_config (osdev->dip->pciinfo.bus,
+                          osdev->dip->pciinfo.device,
+                          osdev->dip->pciinfo.function,
+                          (uchar)where, 2, val);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+int
+pci_write_config_dword (oss_device_t * osdev, offset_t where,
+			unsigned int val)
+{
+  if (osdev->dev_type != DRV_PCI || osdev->dip == NULL)
+    return PCIBIOS_FAILED;
+  gPCI->write_pci_config (osdev->dip->pciinfo.bus,
+                          osdev->dip->pciinfo.device,
+                          osdev->dip->pciinfo.function,
+                          (uchar)where, 4, val);
+  return PCIBIOS_SUCCESSFUL;
+}
+
+
+
+#ifdef MUTEX_CHECKS
+static int oss_context = 0;	/* 0=user context, 1=interrupt context */
+#endif
+
+static int32
+ossintr (void *idata)
+{
+  oss_device_t *osdev = idata;
+  oss_native_word flags;
+  //dprintf("oss:intr(%ld)!\n", osdev->irq);
+#ifdef MUTEX_CHECKS
+  int saved_context;
+  saved_context = oss_context;
+  if (oss_context == 1)
+    cmn_err (CE_WARN, "Recursive interrupt\n");
+  oss_context = 1;
+#endif
+
+  MUTEX_ENTER_IRQDISABLE (osdev->mutex, flags);
+
+  if (!osdev->tophalf_handler (osdev))
+    {
+      MUTEX_EXIT_IRQRESTORE (osdev->mutex, flags);
+#ifdef MUTEX_CHECKS
+      oss_context = saved_context;
+#endif
+      return B_UNHANDLED_INTERRUPT;
+    }
+
+  if (osdev->bottomhalf_handler != NULL)
+    osdev->bottomhalf_handler (osdev);
+
+  MUTEX_EXIT_IRQRESTORE (osdev->mutex, flags);
+#ifdef MUTEX_CHECKS
+  oss_context = saved_context;
+#endif
+
+  return B_HANDLED_INTERRUPT;
+}
+
+int
+oss_register_interrupts (oss_device_t * osdev, int intrnum,
+			 oss_tophalf_handler_t top,
+			 oss_bottomhalf_handler_t bottom)
+{
+  unsigned char pci_irq_line;
+  int err;
+  FENTRYA(", %d, , ", intrnum);
+
+  if (intrnum != 0)
+    {
+      cmn_err (CE_WARN, "Bad interrupt index (%d) for %s\n", intrnum,
+	       osdev->name);
+      return RETERR(EINVAL);
+    }
+
+  if (osdev == NULL)
+    {
+      cmn_err (CE_WARN, "oss_register_interrupts: Bad osdev\n");
+      return RETERR(EINVAL);
+    }
+
+  if (osdev->tophalf_handler != NULL || osdev->bottomhalf_handler != NULL)
+    {
+      cmn_err (CE_WARN, "Interrupts already registered for %s\n",
+	       osdev->name);
+      return RETERR(EINVAL);
+    }
+
+  if (top == NULL)
+    {
+      cmn_err (CE_WARN, "Bad interrupt handler for %s\n", osdev->name);
+      return RETERR(EINVAL);
+    }
+
+  // could probably use osdev->dip->pciinfo...
+  if (pci_read_config_irq (osdev, PCI_INTERRUPT_LINE, &pci_irq_line) > 0)
+    return RETERR(EIO);
+
+  osdev->irq = pci_irq_line;
+  osdev->tophalf_handler = top;
+  osdev->bottomhalf_handler = bottom;
+  err = install_io_interrupt_handler (pci_irq_line, ossintr, osdev, 0);
+  if (err < B_OK)
+    {
+      cmn_err (CE_WARN, "install_io_interrupt_handler failed for %s\n", osdev->nick);
+      osdev->irq = -1;
+      osdev->tophalf_handler = NULL;
+      osdev->bottomhalf_handler = NULL;
+      return RETERR(err);
+    }
+
+  return 0;
+}
+
+void
+oss_unregister_interrupts (oss_device_t * osdev)
+{
+  FENTRY();
+  if (osdev->irq >= 0)
+    remove_io_interrupt_handler (osdev->irq, ossintr, osdev);
+  osdev->irq = -1;
+}
+
+int
+oss_register_device (oss_device_t * osdev, const char *name)
+{
+  static int dev_instance = 0;
+  FENTRYA(", %s", name);
+
+  DDB (cmn_err (CE_CONT, "OSS device %d is %s\n", dev_instance++, name));
+
+  if ((osdev->name = PMALLOC (NULL, strlen (name) + 1)) == NULL)
+    {
+      cmn_err (CE_WARN, "Cannot allocate memory for device name\n");
+      osdev->name = "Unknown device";
+    }
+  strcpy (osdev->name, name);
+  FEXITR(0);
+  return 0;
+}
+
+int
+oss_disable_device (oss_device_t * osdev)
+{
+  int i;
+  FENTRY();
+/*
+ * This routine should check if the device is ready to be unloaded (no devices are in use).
+ * If the device cannot be unloaded this routine must return RETERR(EBUSY).
+ *
+ * If the device can be unloaded then disable any timers or other features that may cause the
+ * device to be called. Also mark the audio/midi/mixer/etc devices of this device to be disabled.
+ * However the interrupt handler should still stay enabled. The low level driver will call
+ * oss_unregister_interrupts() after it has cleared the interrupt enable register.
+ */
+  if (osdev->refcount > 0 || oss_open_devices > 0)
+    {
+      cmn_err (CE_CONT, "Refcount %d, open_devices %d\n", osdev->refcount,
+	       oss_open_devices);
+      return RETERR(EBUSY);
+    }
+
+/*
+ * Now mark all devices unavailable (for the time being)
+ */
+
+  for (i = 0; i < num_mixers; i++)
+    if (mixer_devs[i]->osdev == osdev)
+      {
+	mixer_devs[i]->unloaded = 1;
+      }
+
+  for (i = 0; i < num_mididevs; i++)
+    {
+      if (midi_devs[i]->osdev == osdev)
+	{
+	  midi_devs[i]->unloaded = 1;
+	  if (midi_devs[i]->converter != NULL)
+	    midi_devs[i]->converter->enabled = 0;
+	}
+    }
+
+  for (i = 0; i < num_audio_engines; i++)
+    if (audio_engines[i]->osdev == osdev)
+      {
+	audio_uninit_device (i);
+      }
+
+  FEXIT();
+  return 0;
+}
+
+void
+oss_unregister_device (oss_device_t * osdev)
+{
+  FENTRY();
+/*
+ * Notice! The driver calling this routine (the owner of the osdev parameter)
+ * has already uninitialized itself. Do not do any actions that may call this
+ * driver directly or indirectly.
+ */
+
+/*
+ * Force reload of all drivers if any application tries to open any
+ * of the devices.
+ */
+  //do_forceload = 1;
+  FEXIT();
+}
+
+void
+oss_reserve_device (oss_device_t * osdev)
+{
+  osdev->refcount++;
+}
+
+void
+oss_unreserve_device (oss_device_t * osdev)
+{
+  osdev->refcount--;
+  if (osdev->refcount < 0)
+    osdev->refcount = 0;
+}
+
+void *
+oss_get_osid (oss_device_t * osdev)
+{
+//  return osdev->osid;
+//  return osdev->dip;
+  return NULL; // XXX:TODO
+}
+
+
+oss_device_t *
+osdev_create (dev_info_t * dip, int dev_type, int instance, const char *nick,
+	      const char *handle)
+{
+  oss_device_t *osdev = NULL;
+  int i, err;
+  caddr_t addr;
+  off_t region_size;
+  FENTRYA(", %d, %d, %s, %s", dev_type, instance, nick, handle);
+
+  if (handle == NULL)
+    handle = nick;
+
+  /*
+   * Don't accept any more drivers if expired
+   */
+  if (oss_expired && oss_num_cards > 0)
+    return NULL;
+
+  for (i = 0; dip && (i < oss_num_cards); i++)
+    {
+      if (cards[i] == NULL)
+        continue;
+      if (cards[i]->dip == dip)
+	{
+	  osdev = cards[i];
+	  break;
+	}
+    }
+
+  if (osdev == NULL)
+    {
+      if (oss_num_cards >= MAX_CARDS)
+	cmn_err (CE_PANIC, "Too many OSS devices. At most %d permitted.\n",
+		 MAX_CARDS);
+      if ((osdev = PMALLOC (NULL, sizeof (*osdev))) == NULL)
+	{
+	  cmn_err (CE_WARN, "osdev_create: Out of memory\n");
+	  return NULL;
+	}
+      memset (osdev, 0, sizeof (*osdev));
+
+      osdev->cardnum = oss_num_cards;
+      cards[oss_num_cards++] = osdev;
+    }
+
+  osdev->dip = dip;
+  //osdev->osid = dip;
+  osdev->unloaded = 0;
+  osdev->instance = instance;
+  osdev->dev_type = dev_type;
+  osdev->devc = NULL;
+  MUTEX_INIT (osdev, osdev->mutex, MH_GLOBAL);
+  sprintf (osdev->nick, "%s%d", nick, instance);
+  strcpy (osdev->modname, nick);
+
+  switch (dev_type)
+    {
+    case DRV_PCI:
+      /* NOP */
+      break;
+
+    case DRV_VIRTUAL:
+    case DRV_STREAMS:
+      /* NOP */
+      break;
+
+    case DRV_USB:
+      /* NOP */
+      break;
+
+    default:
+      cmn_err (CE_WARN, "Bad device type\n");
+      return NULL;
+    }
+
+/*
+ * Create the device handle
+ */
+  switch (dev_type)
+    {
+    case DRV_PCI:
+      {
+	unsigned int subvendor;
+	pci_read_config_dword (osdev, 0x2c, &subvendor);
+
+	sprintf (osdev->handle, "PCI%08x-%d", subvendor, instance);
+      }
+      break;
+
+    case DRV_USB:
+      /* TODO: Get the vendor information */
+      sprintf (osdev->handle, "USB-%s%d", handle, instance);
+      break;
+
+    default:
+      sprintf (osdev->handle, "%s%d", handle, instance);
+    }
+
+  FEXIT();
+  return osdev;
+}
+
+oss_device_t *
+osdev_clone (oss_device_t * orig_osdev, int new_instance)
+{
+  oss_device_t *osdev;
+  FENTRYA(", %d", new_instance);
+
+  osdev = PMALLOC (NULL, sizeof (*osdev));
+  if (osdev == NULL)
+    {
+      cmn_err (CE_WARN, "osdev_create: Out of memory\n");
+      return NULL;
+    }
+  memcpy (osdev, orig_osdev, sizeof (*osdev));
+  osdev->dev_type = DRV_CLONE;
+  osdev->instance = new_instance;
+  sprintf (osdev->nick, "%s%d", orig_osdev->modname, new_instance);
+  sprintf (osdev->handle, "%s%d", orig_osdev->modname, new_instance);
+
+  FEXIT();
+  return osdev;
+}
+
+void
+osdev_delete (oss_device_t * osdev)
+{
+  int i;
+
+  FENTRY();
+  if (osdev == NULL)
+    return;
+
+  switch (osdev->dev_type)
+    {
+    case DRV_PCI:
+      /* NOP */
+      //pci_config_teardown (&osdev->pci_config_handle);
+      //osdev->pci_config_handle = NULL;
+      break;
+    }
+
+/*
+ * Mark all minor nodes for this module as invalid.
+ */
+  for (i = 0; i < oss_num_cdevs; i++)
+    if (oss_cdevs[i]->osdev == osdev)
+      {
+	oss_cdevs[i]->d = NULL;
+	oss_cdevs[i]->osdev = NULL;
+	strcpy (oss_cdevs[i]->name, "Removed device");
+      }
+  MUTEX_CLEANUP (osdev->mutex);
+  osdev->unloaded = 1;
+  FEXIT();
+}
+
+void
+oss_install_chrdev (oss_device_t * osdev, char *name, int dev_class,
+		    int instance, oss_cdev_drv_t * drv, int flags)
+{
+/*
+ * oss_install_chrdev creates a character device (minor). However if
+ * name==NULL the device will not be exported (made visible to userland
+ * clients).
+ */
+
+  int i, num;
+  oss_cdev_t *cdev = NULL;
+  FENTRYA(", %s, %d, %d, , %d", name, dev_class, instance, flags);
+
+  if (dev_class != OSS_DEV_STATUS)
+    if (oss_expired && instance > 0)
+      return;
+/*
+ * Find if this dev_class&instance already exists (after previous module
+ * detach).
+ */
+
+  for (num = 0; num < oss_num_cdevs; num++)
+    if (oss_cdevs[num]->d == NULL)	/* Unloaded driver */
+      if (oss_cdevs[num]->dev_class == dev_class
+	  && oss_cdevs[num]->instance == instance)
+	{
+	  cdev = oss_cdevs[num];
+	  //dprintf("oss:reusing cdev[%d]\n", num);
+	  break;
+	}
+
+  if (cdev == NULL)
+    {
+      num = oss_num_cdevs++;
+      if (oss_num_cdevs >= OSS_MAX_CDEVS)
+	{
+	  cmn_err (CE_WARN, "Out of minor numbers.\n");
+	  return;
+	}
+
+      if ((cdev = PMALLOC (NULL, sizeof (*cdev))) == NULL)
+	{
+	  cmn_err (CE_WARN, "Cannot allocate character device desc.\n");
+	  return;
+	}
+	  //dprintf("oss:reusing cdev[%d]: @%p\n", num, cdev);
+    }
+
+  memset (cdev, 0, sizeof (*cdev));
+  cdev->dev_class = dev_class;
+  cdev->instance = instance;
+  cdev->d = drv;
+  cdev->osdev = osdev;
+  if (name != NULL)
+    strncpy (cdev->name, name, sizeof (cdev->name) - 1);
+  else
+    strcpy (cdev->name, "NONE");
+  cdev->name[sizeof (cdev->name) - 1] = 0;
+  oss_cdevs[num] = cdev;
+
+/*
+ * Export the device only if name != NULL
+ */
+  if (name != NULL)
+    {
+      char tmp[64], *s;
+      char *dev_type = "oss_sysdev";
+
+//XXX: maybe do something ??
+    }
+  FEXIT();
+}
+
+int
+oss_get_cardinfo (int cardnum, oss_card_info * ci)
+{
+/*
+ * Print information about a 'card' in a format suitable for /dev/sndstat
+ */
+
+  if (cardnum < 0 || cardnum >= oss_num_cards)
+    return RETERR(ENXIO);
+
+  if (cards[cardnum]->name != NULL)
+    strncpy (ci->longname, cards[cardnum]->name, 128);
+  ci->shortname[127] = 0;
+
+  if (cards[cardnum]->nick != NULL)
+    strncpy (ci->shortname, cards[cardnum]->nick, 16);
+  ci->shortname[15] = 0;
+
+  return 0;
+}
+
+/* XXX: major/minors don't exist in BeOS, WTF */
+int
+oss_find_minor (int dev_class, int instance)
+{
+  int i;
+
+  for (i = 0; i < oss_num_cdevs; i++)
+    if (oss_cdevs[i]->d != NULL && oss_cdevs[i]->dev_class == dev_class
+	&& oss_cdevs[i]->instance == instance)
+      return i;
+
+  return -1;
+}
+
+
+#ifdef MUTEX_CHECKS
+void
+debug_mutex_init (oss_mutex_t * mutex, char *file, int line)
+{
+  memset (mutex, 0, sizeof (mutex));
+  mutex->lock = 0;
+  mutex->owner = -1;
+}
+
+void
+debug_mutex_destroy (oss_mutex_t * mutex, char *file, int line)
+{
+  if (find_thread(NULL) == mutex->owner)
+    {
+      cmn_err (CE_NOTE, "%s:%d: mutex still owned (%d)\n", file, line, mutex->owner);
+    }
+  if (mutex->lock)
+    {
+      cmn_err (CE_NOTE, "%s:%d: mutex still locked (%d)\n", file, line, mutex->lock);
+    }
+}
+
+void
+debug_mutex_enter (oss_mutex_t * mutex, char *file, int line, oss_native_word *flags)
+{
+  if (find_thread(NULL) == mutex->owner)
+    {
+      cmn_err (CE_NOTE, "%s:%d: Re-entrant mutex (%s:%d %d)\n", file, line,
+	       mutex->file, mutex->line, mutex->busy_flags);
+      return;
+    }
+
+  mutex->file = file;
+  mutex->line = line;
+  mutex->busy_flags = flags ? CNTX_INTR : CNTX_USER;
+  if (flags)
+    *flags = (oss_native_word) disable_interrupts();
+  acquire_spinlock (&mutex->lock);
+  
+}
+
+void
+debug_mutex_exit (oss_mutex_t * mutex, char *file, int line, oss_native_word *flags)
+{
+  if (find_thread(NULL) != mutex->owner)
+    {
+      cmn_err (CE_NOTE, "Mutex not owned %s:%d\n", file, line);
+    }
+  else
+    {
+      release_spinlock(&mutex->lock);
+      if (flags)
+        restore_interrupts((cpu_status)*flags);
+    }
+
+  mutex->owner = -1;
+  mutex->file = NULL;
+  mutex->line = 0;
+  mutex->busy_flags = 0;
+}
+#endif
+
+/*
+ * Driver entry point routines
+ */
+
+status_t
+init_osscore (void)
+{
+  int err = 0;
+  oss_device_t *osdev;
+  FENTRY();
+
+#ifdef LICENSED_VERSION
+/*WRITEME*/
+#endif
+
+  if ((osdev = osdev_create (NULL, DRV_VIRTUAL, 0, "oss", NULL)) == NULL)
+    {
+      cmn_err (CE_WARN, "Creating osdev failed\n");
+      FEXITR(ENOMEM);
+      return RETERR(ENOMEM);
+    }
+
+
+  MUTEX_INIT (osdev, osscore_mutex, MH_TOP);
+  
+  //install_drvinfo (osdev);
+  oss_common_init (osdev);
+
+  oss_register_device (osdev, "OSS core services");
+
+  FEXIT();
+  return 0;
+}
+
+status_t
+uninit_osscore (void)
+{
+  int i;
+  static int already_unloaded = 0;
+  FENTRY();
+
+  if (oss_open_devices > 0)
+    return EBUSY;
+
+  if (already_unloaded)
+    return 0;
+  already_unloaded = 1;
+
+  oss_unload_drivers ();
+
+  for (i = 0; i < nmemblocks; i++)
+    KERNEL_FREE (memblocks[i]);
+  nmemblocks = 0;
+
+  MUTEX_CLEANUP (osscore_mutex);
+
+  return 0;
+}
+
+const char **
+oss_publish_devices(void)
+{
+	int i, j;
+	static const char *devices[OSS_MAX_CDEVS] = {
+		NULL
+	};
+
+	FENTRY();
+
+	// XXX:any locking ??
+	for (i = 0; i < OSS_MAX_CDEVS; i++)
+		devices[i] = NULL;
+	dprintf("oss_num_cdevs = %d\n", oss_num_cdevs);
+	for (i = 0, j = 0; i < oss_num_cdevs; i++) {
+		oss_cdev_t *cdev = oss_cdevs[i];
+		if (cdev && cdev->d) {
+			char *name = &gDevnames[i*DEVICE_NAME_LEN];
+			strcpy(name, DEVICE_PREFIX);
+			strncat(name, cdev->name, 32-1);
+			dprintf("oss: publishing %s\n", name);
+			devices[j++] = name;
+		}
+	}
+
+	FEXIT();
+  return devices;
+}
+
+device_hooks *oss_get_driver_hooks (void)
+{
+  return &oss_driver_hooks;
+}
+
+//XXX:hack: testing testing!
+extern int atiaudio_probe(void);
+extern int ali5455_probe(void);
+
+status_t
+oss_load_drivers (void)
+{
+  oss_drv_module_info *drv;
+  char module[256];
+  size_t modulesz = sizeof(module);
+  void *cookie;
+  status_t err = ENOENT;
+  FENTRY();
+  cookie = open_module_list(OSS_MODULES_PREFIX);
+  if (cookie == NULL)
+    goto err1;
+  while (read_next_module_name(cookie, module, &modulesz) >= B_OK)
+    {
+      err = get_module(module, (module_info **)&drv);
+      if (err >= B_OK)
+        {
+          if (drv->driver_probe() < B_OK)
+            put_module(module);
+        }
+      modulesz = sizeof(module);
+    }
+  err = B_OK;
+err2:
+  close_module_list(cookie);
+err1:
+  FEXITR(err);
+  return B_OK;
+}
+
+status_t
+oss_probe_pci (void)
+{
+  FENTRY();
+  ali5455_probe();
+  atiaudio_probe();
+  FEXIT();
+  return B_OK;
+}
+
+
+static status_t
+unload_driver (const char *nick)
+{
+  oss_drv_module_info *drv;
+  char module[256];
+  status_t err = B_OK;
+  int i;
+  FENTRYA("%s", nick);
+
+  /* skip ourselves */
+  if (!strcmp(nick, "oss"))
+    goto err1;
+
+  sprintf(module, "%s%s%s", OSS_MODULES_PREFIX, nick, OSS_MODULES_SUFFIX);
+  err = get_module(module, (module_info **)&drv);
+  if (err < B_OK)
+    goto err1;
+
+  err = EBUSY;
+  /* detach all osdevs for this driver */
+  for (i = 0; i < oss_num_cards; i++)
+    {
+      if (!cards[i])
+        continue;
+      if (strncmp(cards[i]->modname, nick, 32))
+        continue;
+      err = drv->driver_detach(cards[i]);
+      if (err < B_OK)
+        goto err2;
+      //cards[i] = NULL; // XXX: not sure...
+    }
+  err = B_OK;
+  put_module(module);
+  /* twice */
+err2:
+  put_module(module);
+err1:
+  FEXITR(err);
+  return err;
+}
+
+status_t
+oss_unload_all_drivers(void)
+{
+  char module[256];
+  status_t err = B_OK;
+  int i;
+  FENTRY();
+
+  /* for each osdev still around, unload the module it came from,
+   * which should delete them.
+   */
+  for (i = 0; i < oss_num_cards; i++)
+    {
+      if (!cards[i])
+        continue;
+      if (cards[i]->unloaded)
+        continue;
+      err = unload_driver(cards[i]->modname);
+      if (err < B_OK)
+        break;
+    }
+  FEXITR(err);
+  return err;
+}
+
+
+static status_t
+oss_stdops(int32 op, ...)
+{
+  status_t err;
+  switch (op)
+    {
+    case B_MODULE_INIT:
+      gDevnames = malloc(OSS_MAX_CDEVS*DEVICE_NAME_LEN);
+	  if (!gDevnames)
+        break;
+      err = get_module(B_PCI_MODULE_NAME, (module_info **)&gPCI);
+      if (err >= B_OK)
+        {
+          //XXX:call init_osscore() here
+          return err;
+          put_module(B_PCI_MODULE_NAME);
+        }
+      free(gDevnames);
+      return err;
+    case B_MODULE_UNINIT:
+      free(gDevnames);
+      put_module(B_PCI_MODULE_NAME);
+      return B_OK;
+
+    }
+  return B_ERROR;
+}
+
+oss_core_module_info gOSSCoreModule = {
+  {
+    OSS_CORE_MODULE_NAME,
+    0,
+    oss_stdops,
+  },
+  init_osscore,
+  uninit_osscore,
+  oss_publish_devices,
+  oss_get_driver_hooks,
+  oss_probe_pci,
+  oss_load_drivers,
+  oss_unload_all_drivers,
+};
+
+extern oss_drv_module_info gModule_ali5455;
+extern oss_drv_module_info gModule_allegro;
+extern oss_drv_module_info gModule_als300;
+extern oss_drv_module_info gModule_als4000;
+extern oss_drv_module_info gModule_apci97;
+extern oss_drv_module_info gModule_atiaudio;
+extern oss_drv_module_info gModule_audigyls;
+extern oss_drv_module_info gModule_audioloop;
+extern oss_drv_module_info gModule_audiopci;
+extern oss_drv_module_info gModule_cmi8788;
+extern oss_drv_module_info gModule_cmpci;
+extern oss_drv_module_info gModule_cs4280;
+extern oss_drv_module_info gModule_cs4281;
+extern oss_drv_module_info gModule_digi32;
+extern oss_drv_module_info gModule_digi96;
+extern oss_drv_module_info gModule_emu10k1x;
+extern oss_drv_module_info gModule_fm801;
+extern oss_drv_module_info gModule_geode;
+extern oss_drv_module_info gModule_hdaudio;
+extern oss_drv_module_info gModule_ich;
+extern oss_drv_module_info gModule_imux;
+extern oss_drv_module_info gModule_maestro;
+extern oss_drv_module_info gModule_neomagic;
+extern oss_drv_module_info gModule_s3vibes;
+extern oss_drv_module_info gModule_sblive;
+extern oss_drv_module_info gModule_softoss;
+extern oss_drv_module_info gModule_solo;
+extern oss_drv_module_info gModule_trident;
+extern oss_drv_module_info gModule_via8233;
+extern oss_drv_module_info gModule_via97;
+extern oss_drv_module_info gModule_vortex;
+extern oss_drv_module_info gModule_ymf7xx;
+module_info *modules[] = {
+
+  (module_info *)&gOSSCoreModule,
+
+  (module_info *)&gModule_ali5455,
+  
+  (module_info *)&gModule_allegro,
+  (module_info *)&gModule_als300,
+  (module_info *)&gModule_als4000,
+  (module_info *)&gModule_apci97,
+  
+  (module_info *)&gModule_atiaudio,
+  
+  (module_info *)&gModule_audigyls,
+  //(module_info *)&gModule_audioloop,
+  (module_info *)&gModule_audiopci,
+  (module_info *)&gModule_cmi8788,
+  (module_info *)&gModule_cmpci,
+  (module_info *)&gModule_cs4280,
+  (module_info *)&gModule_cs4281,
+  (module_info *)&gModule_digi32,
+  (module_info *)&gModule_digi96,
+  (module_info *)&gModule_emu10k1x,
+  (module_info *)&gModule_fm801,
+  (module_info *)&gModule_geode,
+  (module_info *)&gModule_hdaudio,
+  
+  (module_info *)&gModule_ich,
+  
+  //(module_info *)&gModule_imux,
+  (module_info *)&gModule_maestro,
+  (module_info *)&gModule_neomagic,
+  (module_info *)&gModule_s3vibes,
+  (module_info *)&gModule_sblive,
+  //(module_info *)&gModule_softoss,
+  (module_info *)&gModule_solo,
+  (module_info *)&gModule_trident,
+  (module_info *)&gModule_via8233,
+  (module_info *)&gModule_via97,
+  (module_info *)&gModule_vortex,
+  (module_info *)&gModule_ymf7xx,
+  
+  NULL
+};
+
+/*
+ * Driver hooks
+ */
+
+
+typedef struct ossdev_cookie {
+  int minor; /* index into cdevs[] */
+  oss_cdev_t *cdev;
+  struct fileinfo file;
+} ossdev_cookie_t;
+
+static int find_cdev(const char *name)
+{
+  int i;
+//  if (strlen(name) < strlen(DEVICE_PREFIX))
+//    return -1;
+  name += strlen(DEVICE_PREFIX);
+  // XXX:locking ?
+  for (i = 0; i < oss_num_cdevs; i++)
+    {
+      oss_cdev_t *cdev = oss_cdevs[i];
+      //dprintf("oss:find_cdev: cdev %p, ->d %p, %s <> %s\n", cdev, cdev?cdev->d:NULL, cdev?cdev->name:"-", name);
+      if (cdev && cdev->d && !strncmp(cdev->name, name, 32))
+        return i;
+    }
+  return -1;
+}
+
+static status_t
+ossdrv_open(const char *name, uint32 oflags, void **cookie)
+{
+  ossdev_cookie_t *c;
+  status_t err;
+  int dev, tmpdev;
+  oss_cdev_t *cdev;
+  oss_native_word flags;
+  FENTRYA("%s, %ld, ", name, oflags);
+
+  dev = find_cdev(name);
+  err = ENOENT;
+  if (dev < 0)
+    goto err1;
+  err = ENXIO;
+  if (dev > oss_num_cdevs)
+    goto err1;
+  if ((cdev = oss_cdevs[dev]) == NULL || cdev->d == NULL)
+    goto err1;
+
+  DDB (cmn_err
+       (CE_CONT, "oss_cdev_open(%d): %s, class=%d, instance=%d\n", dev,
+	cdev->name, cdev->dev_class, cdev->instance));
+
+  err = ENODEV;
+  if (cdev->d->open == NULL)
+    goto err1;
+
+  err = ENOMEM;
+  c = malloc(sizeof(ossdev_cookie_t));
+  if (!c)
+    goto err1;
+  
+  switch (oflags & O_RWMASK)
+    {
+    case O_RDONLY:
+      c->file.mode = OPEN_READ;
+      break;
+    case O_WRONLY:
+      c->file.mode = OPEN_WRITE;
+      break;
+    case O_RDWR:
+      c->file.mode = OPEN_READWRITE;
+      break;
+    default:
+      err = EINVAL;
+      goto err2;
+    }
+  c->file.flags = oflags;
+
+  tmpdev = dev;
+  err =
+    cdev->d->open (cdev->instance, cdev->dev_class, &c->file, 0, 0, &tmpdev);
+  if (err)
+    goto err3;
+  
+  c->minor = dev = tmpdev;
+  c->cdev = cdev = oss_cdevs[dev];
+  
+  //XXX:locking
+  MUTEX_ENTER_IRQDISABLE (osscore_mutex, flags);
+  oss_open_devices++;
+  open_count[dev]++;
+  MUTEX_EXIT_IRQRESTORE (osscore_mutex, flags);
+
+  *cookie = c;
+  FEXITR(B_OK);
+  return B_OK;
+
+err3:
+err2:
+  free(c);
+err1:
+  FEXITR(err);
+  return err;
+}
+
+
+static status_t
+ossdrv_close(void *cookie)
+{
+  FENTRY();
+  FEXIT();
+  return B_OK;
+}
+
+
+static status_t
+ossdrv_freecookie(ossdev_cookie_t *cookie)
+{
+  oss_cdev_t *cdev = cookie->cdev;
+  int dev = cookie->minor;
+  oss_native_word flags;
+  status_t err;
+  FENTRY();
+
+  err = ENXIO;
+  if (dev >= OSS_MAX_CDEVS)
+    goto err;
+
+  err = B_OK;
+  if (open_count[dev] == 0)	/* Not opened */
+    goto err;
+
+  err = ENXIO;
+  if (cdev != oss_cdevs[dev])
+    goto err;
+
+  //in close or free ??
+  cdev->d->close (cdev->instance, &cookie->file);
+
+  MUTEX_ENTER_IRQDISABLE (osscore_mutex, flags);
+  oss_open_devices--;
+  open_count[dev]--;
+  MUTEX_EXIT_IRQRESTORE (osscore_mutex, flags);
+  
+  free(cookie);
+  err = B_OK;
+err:
+  FEXITR(err);
+  return B_OK;
+}
+
+/* note: IOC stuff seems to not collide with the base ioctls from Drivers.h
+ * as long as the type field is printable ascii (>32). Lucky are we.
+ */
+static status_t
+ossdrv_ioctl(ossdev_cookie_t *cookie, uint32 op, void *buffer, size_t length)
+{
+  oss_cdev_t *cdev = cookie->cdev;
+  status_t err = ENXIO;
+  uint32 cmd = op;
+  int len = 0;
+  char buf[4096];
+  FENTRYA(", %lx, , %ld", op, length);
+  
+  if ((cdev != oss_cdevs[cookie->minor]) || cdev->d->ioctl == NULL)
+    goto err1;
+
+  if (cmd & (SIOC_OUT | SIOC_IN))
+    {
+
+      len = (cmd >> 16) & SIOCPARM_MASK;
+      if (len < 0)
+	len = 0;
+      if (len > sizeof (buf))
+	{
+	  cmn_err (CE_WARN, "Bad ioctl buffer size %d\n", len);
+	  err = EFAULT;
+	  goto err1;
+	}
+
+      if ((cmd & SIOC_IN) && len > 0)
+	{
+	  memcpy (buf, buffer, len);
+	    //return EFAULT;
+	}
+
+    }
+
+  err = cdev->d->ioctl (cdev->instance, &cookie->file, cmd, (ioctl_arg) buf);
+
+  if ((cmd & SIOC_OUT) && len > 0)
+    {
+      memcpy (buffer, buf, len);
+	//return EFAULT;
+    }
+
+
+err1:
+  FEXITR(err);
+  return err;
+}
+
+
+static status_t
+ossdrv_read(ossdev_cookie_t *cookie, off_t pos, void *buffer, size_t *_length)
+{
+  oss_cdev_t *cdev = cookie->cdev;
+  uio_t uio;
+  int count = *_length;
+  int err;
+  FENTRYA(", %Ld, , %ld", pos, *_length);
+
+  err = ENXIO;
+  if ((cdev != oss_cdevs[cookie->minor]) || cdev->d->read == NULL)
+    goto err;
+  //files[dev].acc_flags = uiop->uio_fmode;
+  if ((err = oss_create_uio (&uio, buffer, count, UIO_READ, 0)) < 0)
+    goto err;
+
+  err = cdev->d->read (cdev->instance, &cookie->file, &uio, count);
+  *_length = (err > 0) ? err : 0;
+  if (err < 0)
+    goto err;
+  
+  *_length = err;
+  err = B_OK;
+  FEXITR(err);
+  return err;
+
+err:
+  *_length = 0;
+  FEXITR(err);
+  return err;
+}
+
+
+static status_t
+ossdrv_write(ossdev_cookie_t *cookie, off_t pos, const void *buffer, size_t *_length)
+{
+  oss_cdev_t *cdev = cookie->cdev;
+  uio_t uio;
+  int count = *_length;
+  int err;
+  FENTRYA(", %Ld, , %ld", pos, *_length);
+
+  err = ENXIO;
+  if ((cdev != oss_cdevs[cookie->minor]) || cdev->d->write == NULL)
+    goto err;
+  //files[dev].acc_flags = uiop->uio_fmode;
+  if ((err = oss_create_uio (&uio, (void *)buffer, count, UIO_WRITE, 0)) < 0)
+    goto err;
+
+  err = cdev->d->write (cdev->instance, &cookie->file, &uio, count);
+  *_length = (err > 0) ? err : 0;
+  if (err < 0)
+    goto err;
+  
+  *_length = err;
+  err = B_OK;
+  FEXITR(err);
+  return err;
+
+err:
+  *_length = 0;
+  FEXITR(err);
+  return err;
+}
+
+
+device_hooks oss_driver_hooks = {
+  &ossdrv_open,
+  &ossdrv_close,
+  (device_free_hook)&ossdrv_freecookie,
+  (device_control_hook)&ossdrv_ioctl,
+  (device_read_hook)&ossdrv_read,
+  (device_write_hook)&ossdrv_write,
+  /* Leave select/deselect/readv/writev undefined. The kernel will
+   * use its own default implementation. The basic hooks above this
+   * line MUST be defined, however. */
+  NULL,
+  NULL,
+  NULL,
+  NULL
+};
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/os_beos.h oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/os_beos.h
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/BeOS/os_beos.h	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/BeOS/os_beos.h	Wed Jun 27 02:57:36 2007
@@ -0,0 +1,456 @@
+#ifndef _OS_H_
+#define _OS_H_
+
+/*
+ * Purpose: OS specific definitions for BeOS/Haiku
+ *
+ */
+/*
+ *
+ * This file is part of Open Sound System.
+ *
+ * Copyright (C) 4Front Technologies 1996-2007.
+ *
+ * This this source file is released under GPL v2 license (no other versions).
+ * See the COPYING file included in the main directory of this source
+ * distribution. Please contact sales@opensound.com for further info.
+ *
+ */
+#define OS_VERSION "5"
+#define __inline__ inline
+#define __inline inline
+#define EXTERN_C extern "C"
+
+/*
+ * Debugging and misc settings
+ */
+#undef DO_TIMINGS
+#undef  MUTEX_CHECKS
+#undef  MEMDEBUG
+/* very verbose */
+//#define DO_DEBUG_FUNC_CALLS
+
+/*
+ * Disable support for per-application features such as /dev/dsp device
+ * selection based on command name. Requires working GET_PROCESS_NAME
+ * macro implementation.
+ */
+//Disable??
+#define APPLIST_SUPPORT
+#define USE_DEVICE_SUBDIRS
+
+#include <OS.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <errno.h>
+#include <sys/uio.h>
+#include <sys/fcntl.h>
+#ifdef __HAIKU__
+#include <poll.h>
+#endif
+//#include <sys/malloc.h>
+#include <malloc.h>
+
+
+#include <KernelExport.h>
+#include <Drivers.h>
+#include <PCI.h>
+
+#ifndef ENOTSUP
+#define ENOTSUP ENOSYS
+#endif
+
+#define OSS_CONTIG_AREA_NAME "OSS CONTIG MEM"
+#define OSS_PCI_AREA_NAME "OSS PCI MEM"
+#define OSS_WQ_SEM_NAME "OSS WAITQ: "
+
+//#define DEVICE_PREFIX "audio/oss/"
+#define DEVICE_PREFIX ""
+#define DEVICE_NAME_LEN (32+sizeof(DEVICE_PREFIX))
+
+#ifdef _KERNEL_MODE
+
+/* references to modules */
+extern pci_module_info *gPCI;
+
+#endif /* _KERNEL_MODE */
+
+/*
+ * Some integer types
+ */
+#if defined(amd64) || defined(sparc) // 64bit ? not yet
+typedef uint64 oss_native_word;	/* Same as the address and status register size */
+#else
+typedef uint32 oss_native_word;	/* Same as the address and status register size */
+#endif
+
+typedef uint64 oss_uint64_t;	/* Unsigned 64 bit integer */
+typedef unsigned long offset_t;
+
+
+extern void oss_cmn_err (int level, char *format, ...);
+#define CE_CONT		0
+#define CE_NOTE		1
+#define CE_WARN		2
+#define CE_PANIC	3
+#define cmn_err oss_cmn_err
+
+//snooze(1000000); \
+
+#ifdef DO_DEBUG_FUNC_CALLS
+/* verbose debugging */
+#define FENTRY() \
+dprintf("oss>%s()\n", __FUNCTION__)
+#define FENTRYA(f,a...) \
+dprintf("oss>%s(" f ")\n", __FUNCTION__, a)
+#define FEXIT() \
+dprintf("oss<%s\n", __FUNCTION__)
+#define FEXITR(e) \
+dprintf("oss<%s returned 0x%08lx\n", __FUNCTION__, (uint32)e)
+#else
+#define FENTRY() {}
+#define FENTRYA(f,a...) {}
+#define FEXIT() {}
+#define FEXITR(e) {}
+#endif
+
+struct _dev_info_t
+{
+  //struct pci_dev *pcidev;
+  struct pci_info pciinfo; //XXX: ptr or not ???
+};
+typedef struct _dev_info_t dev_info_t;
+
+
+/*
+ * timeout wrappers
+ */
+#undef timeout
+#define timeout oss_timeout
+#undef untimeout
+#define untimeout oss_untimeout
+typedef int timeout_id_t;
+extern timeout_id_t oss_timeout (void (*func) (void *), void *arg,
+				 unsigned long long ticks);
+extern void oss_untimeout (timeout_id_t id);
+
+#define uiomove oss_uiomove
+typedef enum uio_rw
+{ UIO_READ, UIO_WRITE } uio_rw_t;
+struct uio
+{
+  char *ptr;
+  int resid;
+  int kernel_space;		/* Set if this uio points to a kernel space buffer */
+  uio_rw_t rw;
+};
+typedef struct uio uio_t;
+extern int oss_uiomove (void *address, size_t nbytes, enum uio_rw rwflag,
+			uio_t * uio);
+extern int oss_create_uio (uio_t * uiop, char *buf, size_t count, uio_rw_t rw,
+			   int is_kernel);
+
+
+
+/*
+ * Mutexes
+ */
+
+#ifdef MUTEX_CHECKS
+/* Debugging version */
+struct _oss_mutex_t
+{
+  spinlock lock;
+  thread_id owner;
+  char *file;
+  int line;
+  int busy_flags;
+#define CNTX_INTR		1
+#define CNTX_USER		2
+};
+
+typedef struct _oss_mutex_t oss_mutex_t;
+extern void debug_mutex_init (oss_mutex_t * mutex, char *file, int line);
+extern void debug_mutex_destroy (oss_mutex_t * mutex, char *file, int line);
+extern void debug_mutex_enter (oss_mutex_t * mutex, char *file, int line, oss_native_word *flags);
+extern void debug_mutex_exit (oss_mutex_t * mutex, char *file, int line, oss_native_word *flags);
+
+#define MUTEX_INIT(osdev, mutex, hier)			debug_mutex_init(&mutex, NULL, __FILE__, __LINE__)
+#define MUTEX_CLEANUP(mutex)			debug_mutex_destroy(&mutex, __FILE__, __LINE__)
+#define MUTEX_ENTER_IRQDISABLE(mutex, flags)	debug_mutex_enter(&mutex, __FILE__, __LINE__, &flags)
+#define MUTEX_ENTER(mutex, flags)			debug_mutex_enter(&mutex, __FILE__, __LINE__, NULL)
+#define MUTEX_EXIT_IRQRESTORE(mutex, flags)	debug_mutex_exit(&mutex, __FILE__, __LINE__, &flags)
+#define MUTEX_EXIT(mutex, flags)			debug_mutex_exit(&mutex, __FILE__, __LINE__, NULL)
+#else
+typedef spinlock oss_mutex_t;
+#define MUTEX_INIT(osdev, mutex, hier)			{ mutex = 0; }
+#define MUTEX_CLEANUP(mutex)			
+#define MUTEX_ENTER_IRQDISABLE(mutex, flags)	\
+{ \
+	flags = (oss_native_word) disable_interrupts(); \
+	acquire_spinlock(&(mutex)); \
+}
+#define MUTEX_ENTER(mutex, flags)			acquire_spinlock(&(mutex))
+#define MUTEX_EXIT_IRQRESTORE(mutex, flags)	\
+{ \
+	release_spinlock(&(mutex)); \
+	restore_interrupts((cpu_status)(flags)); \
+}
+#define MUTEX_EXIT(mutex, flags)			release_spinlock(&(mutex))
+#endif
+
+/* The soundcard.h could be in a nonstandard place so include it here. */
+#include "soundcard.h"
+
+typedef struct udi_usb_devc udi_usb_devc;
+struct _oss_device_t
+{
+#ifdef NEEDED_FOR_DRIVERS
+  int instance;
+  void *devc;
+  char *name;
+#endif
+
+  int cardnum;
+  int dev_type;
+  int instance;
+  dev_info_t *dip;
+  int unloaded;
+  void *osid;
+  void *devc;
+  char *name;
+  char nick[16];
+  char modname[32];
+  char handle[32];
+  int num_audio_engines;
+  int num_audioplay, num_audiorec, num_audioduplex;
+  int num_mididevs;
+  int num_mixerdevs;
+  
+  volatile int refcount;	/* Nonzero means that the device is needed by some other (virtual) driver. */
+
+/* Interrupts */
+
+  long irq; //XXX:init =-1
+  oss_tophalf_handler_t tophalf_handler;
+  oss_bottomhalf_handler_t bottomhalf_handler;
+  oss_mutex_t mutex;
+
+};
+
+/* XXX we'll deal with select() later */
+#undef ALLOW_SELECT
+/* BeOS doesn't support mmap. Haiku does, so FIXME someday */
+#undef ALLOW_BUFFER_MAPPING
+
+/*
+ * Sleep/wakeup
+ */
+
+#ifdef _KERNEL
+struct oss_wait_queue
+{
+//XXX:
+//  oss_mutex_t mutex;
+  char name[32];
+  sem_id sem;
+  unsigned long flags;
+//  struct selinfo poll_info;
+};
+#endif
+
+/* Busy wait routine */
+#define oss_udelay(d) spin((bigtime_t)d)
+
+
+/* usec time base */
+#undef HZ
+/* XXX: might need to be lower to handle casts to long */
+#define OSS_HZ 1000000
+
+/* System wall timer access */
+extern unsigned long oss_get_time (void);
+#define GET_JIFFIES()	oss_get_time()
+
+
+/*
+ * INB() and OUTB() should be obvious. NOTE! The order of
+ * paratemeters of OUTB() is different than on some other
+ * operating systems.
+ */
+
+/* I/O Mapped devices */
+#define INB(o, p)	gPCI->read_io_8(p)
+#define INW(o, p)	gPCI->read_io_16(p)
+#define INL(o, p)	gPCI->read_io_32(p)
+
+#define OUTB(o, v, p)	gPCI->write_io_8(p,v)
+#define OUTW(o, v, p)	gPCI->write_io_16(p,v)
+#define OUTL(o, v, p)	gPCI->write_io_32(p,v)
+
+/* Memory Mapped devices */
+#define PCI_READB(osdev, addr)		*(volatile unsigned char *)(addr)
+#define PCI_READW(osdev, addr)		*(volatile unsigned short *)(addr)
+#define PCI_READL(osdev, addr)		*(volatile unsigned int *)(addr)
+
+#define PCI_WRITEB(osdev, addr, data)	*(volatile unsigned char *)(addr)=data
+#define PCI_WRITEW(osdev, addr, data)	*(volatile unsigned short *)(addr)=data
+#define PCI_WRITEL(osdev, addr, data)	*(volatile unsigned int *)(addr)=data
+
+/*
+ * When a error (such as EINVAL) is returned by a function,
+ * the following macro is used. The driver assumes that a
+ * error is signalled by returning a negative value.
+ */
+
+/* 
+   KERNEL_MALLOC() allocates requested number of memory  and 
+   KERNEL_FREE is used to free it. 
+   These macros are never called from interrupt, in addition the
+   nbytes will never be more than 4096 bytes. Generally the driver
+   will allocate memory in blocks of 4k. If the kernel has just a
+   page level memory allocation, 4K can be safely used as the size
+   (the nbytes parameter can be ignored).
+*/
+#define	KERNEL_MALLOC(nbytes)	malloc(nbytes)
+#define	KERNEL_FREE(addr)	{if (addr)free(addr);addr=NULL;}
+
+extern void *oss_contig_malloc (oss_device_t * osdev, int sz,
+				oss_uint64_t memlimit,
+				oss_native_word * phaddr);
+extern void oss_contig_free (oss_device_t * osdev, void *p, int sz);
+extern oss_native_word oss_virt_to_bus (void *addr);
+#define CONTIG_MALLOC(osdev, sz, memlimit, phaddr)	oss_contig_malloc(osdev, sz, memlimit, phaddr)
+#define CONTIG_FREE(osdev, p, sz)	oss_contig_free(osdev, p, sz)
+
+/*
+ * PMALLOC is used to allocate memory that will get automatically freed when
+ * OSS unloads. Usable for per-instance structures allocated when OSS modules
+ * are being loaded.
+ */
+extern void *oss_pmalloc (size_t sz);
+
+#define PMALLOC(osdev, sz) oss_pmalloc(sz)
+
+/*
+ * Timer macros
+ *
+ * These macros are obsolete and should not be used in any new code.
+ * Use the timeout mechanism (see the timeout(9F) Solaris man page).
+ */
+#define DEFINE_TIMER(name, proc)	static timeout_id_t name = 0
+#define REMOVE_TIMER(name, proc)	{if (name != 0) untimeout(name);}
+#define INIT_TIMER(name,proc)
+typedef void (*timeout_func_t) (void *);
+#define ACTIVATE_TIMER(name, proc, time) \
+	name=timeout((timeout_func_t)proc, (void*)&name, time)
+#endif
+
+struct fileinfo
+{
+  int mode;			/* Open mode */
+  int flags;
+  int acc_flags;
+};
+#define ISSET_FILE_FLAG(fileinfo, flag)  (fileinfo->acc_flags & (flag) ? 1:0)
+
+#define OSS_OS "BeOS"
+#define OSS_OS_LONGNAME "BeOS R" OS_VERSION
+
+typedef void (*softintr_func_t) (int);
+
+struct oss_softintr
+{
+  int id;
+  softintr_func_t func;
+  volatile int armed, running;
+};
+
+struct _oss_poll_event_t
+{
+  short events, revents;
+  struct thread *p;
+  struct cdev *bsd_dev;
+};
+typedef struct _oss_poll_event_t oss_poll_event_t;
+#ifndef POLLIN
+/* events & revents - compatible with the B_SELECT_xxx definitions in Drivers.h */
+#define POLLIN          0x0001          /* any readable data available */
+#define POLLOUT         0x0002          /* file descriptor is writeable */
+#define POLLRDNORM      POLLIN
+#define POLLWRNORM      POLLOUT
+#define POLLRDBAND      0x0008          /* priority readable data */
+#define POLLWRBAND      0x0010          /* priority data can be written */
+#define POLLPRI         0x0020          /* high priority readable data */
+#endif
+
+extern int detect_trace;
+#define DDB(x) if (detect_trace) x
+
+extern caddr_t oss_map_pci_mem (oss_device_t * osdev, int nr, int phaddr,
+				int size);
+extern void oss_unmap_pci_mem (void *addr);
+#define MAP_PCI_IOADDR(osdev, nr, io) (oss_native_word)io
+#define MAP_PCI_MEM(osdev, ix, phaddr, size) 	oss_map_pci_mem(osdev, ix, phaddr, size)
+#define UNMAP_PCI_MEM(osdev, ph, virt, size)	oss_unmap_pci_mem(virt)
+
+#define GET_PROCESS_PID(f)  find_thread(NULL)
+#define GET_PROCESS_NAME(f) NULL
+
+#define abs(x)                  ((x) >= 0 ? (x) : -(x))
+
+/*
+ * PCI config space access (in os.c)
+ */
+extern char *oss_pci_read_devpath (dev_info_t * dip);
+
+
+/*
+ * Interface with the front-end driver
+ */
+extern status_t init_osscore (void);
+extern status_t uninit_osscore (void);
+extern status_t oss_probe_pci (void);
+extern status_t oss_load_drivers (void);
+extern status_t oss_unload_all_drivers (void);
+
+/*
+ * osscore module for use by low-level driver
+ */
+#define OSS_CORE_MODULE_NAME "media/oss/osscore/v1"
+#define OSS_MODULES_PREFIX "media/oss/drivers/"
+#define OSS_MODULES_SUFFIX "/v1"
+#define OSS_MAKE_DRV_MOD_NAME(nick) OSS_MODULES_PREFIX nick OSS_MODULES_SUFFIX
+typedef struct oss_drv_module_info {
+  module_info minfo;
+  int (*driver_probe)(void);
+  int (*driver_attach)(oss_device_t *osdev);
+  int (*driver_detach)(oss_device_t *osdev);
+} oss_drv_module_info;
+
+typedef struct oss_core_module_info {
+  module_info minfo;
+  status_t (*init_osscore) (void);
+  status_t (*uninit_osscore) (void);
+  const char **(*oss_publish_devices) (void);
+  device_hooks *(*oss_get_driver_hooks) (void);
+  status_t (*oss_probe_pci) (void);
+  status_t (*oss_load_drivers) (void);
+  status_t (*oss_unload_all_drivers) (void);
+} oss_core_module_info;
+extern oss_core_module_info *gOSSCore;
+
+//XXX: not yet
+#ifdef ASMODULES
+
+struct oss_core_module {
+  module_info minfo;
+  void (*oss_foo)(void);
+};
+extern struct oss_core_info *gOSSCore;
+#ifdef BUILDING_DRIVER
+  #define oss_foo gOSSCore->oss_foo
+#endif
+#endif /* ASMODULES */
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/FreeBSD/os_freebsd.c oss-v4.1test0-070624-src-gpl/kernel/OS/FreeBSD/os_freebsd.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/FreeBSD/os_freebsd.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/FreeBSD/os_freebsd.c	Tue Jun 26 22:19:34 2007
@@ -89,7 +89,7 @@
 
   tmpbuf = CONTIG_MALLOC (dmap->osdev, size, maxaddr, &phaddr);
   if (tmpbuf == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   dmap->dmabuf = tmpbuf;
   dmap->buffsize = size;
   dmap->dmabuf_phys = phaddr;
@@ -213,7 +213,7 @@
   strcpy (osdev->name, name);
   if (osdev->dip != NULL)
     device_set_desc (osdev->dip, name);
-  return -ENXIO;
+  return RETERR(ENXIO);
 }
 
 void
@@ -256,10 +256,10 @@
   int i;
 
   if (osdev->refcount > 0)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   if (open_devices > 0)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   for (i = 0; i < num_mixers; i++)
     if (mixer_devs[i]->osdev == osdev)
@@ -293,7 +293,7 @@
  */
 
   if (cardnum < 0 || cardnum >= oss_num_cards)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cards[cardnum]->name != NULL)
     strncpy (ci->longname, cards[cardnum]->name, 128);
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/Linux/os_linux.c oss-v4.1test0-070624-src-gpl/kernel/OS/Linux/os_linux.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/Linux/os_linux.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/Linux/os_linux.c	Tue Jun 26 22:19:34 2007
@@ -298,7 +298,7 @@
  */
   if (osdev->refcount > 0)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   for (i = 0; i < num_mixers; i++)
@@ -374,7 +374,7 @@
  */
 
   if (cardnum < 0 || cardnum >= oss_num_cards)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cards[cardnum]->name != NULL)
     strncpy (ci->longname, cards[cardnum]->name, 128);
@@ -406,7 +406,7 @@
   if (dmap == NULL)
     {
       cmn_err (CE_WARN, "oss_alloc_dmabuf: dmap==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
 /*
@@ -436,7 +436,7 @@
 			      &phaddr)) == NULL)
 	{
 	  if ((dmap->buffsize = (dmap->buffsize / 2)) < 8 * 1024)
-	    return -ENOMEM;
+	    return RETERR(ENOMEM);
 	  cmn_err (CE_CONT, "Dropping DMA buffer size to %d bytes.\n",
 		   dmap->buffsize);
 	  continue;
@@ -448,7 +448,7 @@
       return 0;
     }
 
-  return -ENOMEM;
+  return RETERR(ENOMEM);
 }
 
 void
@@ -493,9 +493,9 @@
   oss_cdev_t *cdev;
 
   if (dev > oss_num_cdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
   if ((cdev = oss_cdevs[dev]) == NULL || cdev->d == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   DDB (cmn_err
        (CE_CONT, "oss_cdev_open(%d): %s, class=%d, instance=%d\n", dev,
@@ -503,7 +503,7 @@
 
   if (cdev->d->open == NULL)
     {
-      return -ENODEV;
+      return RETERR(ENODEV);
     }
 
   dev_class = cdev->dev_class;
@@ -566,10 +566,10 @@
   cpy_file (file, &fi);
 
   if (dev > oss_num_cdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
   if ((cdev = oss_cdevs[dev]) == NULL || cdev->d->read == NULL)
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   if ((err = oss_create_uio (&uio, buf, count, UIO_READ, 0)) < 0)
@@ -596,10 +596,10 @@
   cpy_file (file, &fi);
 
   if (dev > oss_num_cdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
   if ((cdev = oss_cdevs[dev]) == NULL || cdev->d->write == NULL)
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   if ((err = oss_create_uio (&uio, buf, count, UIO_WRITE, 0)) < 0)
@@ -630,10 +630,10 @@
   cpy_file (file, &fi);
 
   if (dev > oss_num_cdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
   if ((cdev = oss_cdevs[dev]) == NULL || cdev->d->ioctl == NULL)
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   if (__SIOC_DIR (cmd) != __SIOC_NONE && __SIOC_DIR (cmd) != 0)
@@ -642,7 +642,7 @@
       if (len < 1 || len > 65536 || arg == 0)
 	{
 	  cmn_err (CE_WARN, "Bad ioctl command %x, %d, %x\n", cmd, len, arg);
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 	}
 
       /* Use statically allocated buffer for short arguments */
@@ -656,7 +656,7 @@
 
       if (ptr == NULL || arg == 0)
 	{
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 	}
 
       if (__SIOC_DIR (cmd) & __SIOC_WRITE)
@@ -665,7 +665,7 @@
 	    {
 	      if (alloced)
 		KERNEL_FREE (ptr);
-	      return -EFAULT;
+	      return RETERR(EFAULT);
 	    }
 	}
     }
@@ -683,7 +683,7 @@
 	{
 	  if (alloced)
 	    KERNEL_FREE (ptr);
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 	}
     }
 
@@ -709,10 +709,10 @@
   cpy_file (file, &fi);
 
   if (dev > oss_num_cdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
   if ((cdev = oss_cdevs[dev]) == NULL || cdev->d->chpoll == NULL)
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   ev.wait = wait;
@@ -738,21 +738,21 @@
   int err;
 
   if (dev > oss_num_cdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if ((cdev = oss_cdevs[dev]) == NULL)
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   if (cdev->dev_class != OSS_DEV_DSP && cdev->dev_class != OSS_DEV_DSP_ENGINE)	/* Only mmap audio devices */
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   dev = cdev->instance;
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (oss_vma_get_flags (vma) & VM_WRITE)	/* Map write and read/write to the output buf */
     {
@@ -765,38 +765,38 @@
   else
     {
       cmn_err (CE_WARN, "Undefined mmap() access\n");
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (dmap == NULL)
     {
       cmn_err (CE_WARN, "mmap() error. dmap == NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (dmap->dmabuf == NULL)
     {
       cmn_err (CE_WARN, "mmap() called when raw_buf == NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (dmap->dmabuf_phys == 0)
     {
       cmn_err (CE_WARN, "mmap() not supported by device /dev/dsp%d.\n", dev);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (dmap->mapping_flags)
     {
       cmn_err (CE_WARN, "mmap() called twice for the same DMA buffer\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (dmap->flags & DMAP_COOKED)
     {
       cmn_err (CE_WARN,
 	       "mmap() not possible with currently selected sample format.\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if ((err = oss_do_mmap (vma, dmap->dmabuf_phys, dmap->bytes_in_use)) < 0)
@@ -930,7 +930,7 @@
     {
       cmn_err (CE_WARN, "Failed to allocate character major number %d\n",
 	       osscore_major);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   osdev->major = osscore_major;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/SCO_SV/os_sco.c oss-v4.1test0-070624-src-gpl/kernel/OS/SCO_SV/os_sco.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/SCO_SV/os_sco.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/SCO_SV/os_sco.c	Tue Jun 26 22:19:34 2007
@@ -236,7 +236,7 @@
   if ((p =
        oss_contig_malloc (audio_engines[dev]->osdev, size, maxaddr,
 			  &phaddr)) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   dmap->dmabuf = p;
   dmap->dmabuf_phys = phaddr;
@@ -493,7 +493,7 @@
  */
 
   if (cardnum < 0 || cardnum >= oss_num_cards)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cards[cardnum]->name != NULL)
     strncpy (ci->longname, cards[cardnum]->name, 128);
@@ -722,7 +722,7 @@
   int i;
 /*
  * This routine should check if the device is ready to be unloaded (no devices are in use).
- * If the device cannot be unloaded this routine must return -EBUSY.
+ * If the device cannot be unloaded this routine must return RETERR(EBUSY).
  *
  * If the device can be unloaded then disable any timers or other features that may cause the
  * device to be called. Also mark the audio/midi/mixer/etc devices of this device to be disabled.
@@ -731,7 +731,7 @@
  */
   if (osdev->refcount > 0)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
 /*
@@ -818,26 +818,26 @@
     {
       cmn_err (CE_WARN, "Bad interrupt index (%d) for %s\n", intrnum,
 	       osdev->name);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (osdev == NULL)
     {
       cmn_err (CE_WARN, "oss_register_interrupts: Bad osdev\n");
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (osdev->tophalf_handler != NULL || osdev->bottomhalf_handler != NULL)
     {
       cmn_err (CE_WARN, "Interrupts already registered for %s\n",
 	       osdev->name);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (top == NULL)
     {
       cmn_err (CE_WARN, "Bad interrupt handler for %s\n", osdev->name);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   osdev->tophalf_handler = top;
@@ -1013,13 +1013,13 @@
   int i;
 
   if (drvinfo_busy)
-    return -EBUSY;
+    return RETERR(EBUSY);
   drvinfo_busy = 1;
 
   if ((drvinfo_buf = KERNEL_MALLOC (DRVINFO_SIZE)) == NULL)
     {
       cmn_err (CE_WARN, "Cannot allocate drvinfo buffer\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   drvinfo_len = 0;
@@ -1067,7 +1067,7 @@
     return 0;
 
   if (uiomove (&drvinfo_buf[drvinfo_ptr], l, UIO_READ, buf) != 0)
-    return -EFAULT;
+    return RETERR(EFAULT);
   drvinfo_ptr += l;
 
   return l;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/SunOS/os_solaris.c oss-v4.1test0-070624-src-gpl/kernel/OS/SunOS/os_solaris.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/SunOS/os_solaris.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/SunOS/os_solaris.c	Tue Jun 26 22:19:34 2007
@@ -1499,7 +1499,7 @@
  */
 
   if (cardnum < 0 || cardnum >= oss_num_cards)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cards[cardnum]->name != NULL)
     strncpy (ci->longname, cards[cardnum]->name, 128);
@@ -1668,19 +1668,19 @@
   if (osdev == NULL)
     {
       cmn_err (CE_WARN, "oss_alloc_dmabuf: osdev==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (osdev->dip == NULL)
     {
       cmn_err (CE_WARN, "oss_alloc_dmabuf: osdev->dip==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (dmap == NULL)
     {
       cmn_err (CE_WARN, "oss_alloc_dmabuf: dmap==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if ((err = ddi_dma_alloc_handle (osdev->dip,
@@ -1690,7 +1690,7 @@
 				   &dmap->dma_parms.dhandle)) != DDI_SUCCESS)
     {
       cmn_err (CE_WARN, "Failed to allocate DMA handle (error %d)\n", err);
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   dmap->dmabuf = NULL;
@@ -1722,7 +1722,7 @@
       if (!(alloc_flags & DMABUF_QUIET))
 	cmn_err (CE_WARN, "Can't allocate a DMA buffer for device %d\n", dev);
       ddi_dma_free_handle (&dmap->dma_parms.dhandle);
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   dmap->buffsize = len;
@@ -1743,7 +1743,7 @@
     {
       cmn_err (CE_WARN, "DMA address setup failed (%d)\n", err);
 
-      return -EIO;
+      return RETERR(EIO);
     }
 
   dmap->dmabuf =
@@ -1752,7 +1752,7 @@
 
   desc = PMALLOC (osdev, sizeof (contig_desc));
   if (desc == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   desc->osdev = osdev;
   desc->next = NULL;
@@ -1843,26 +1843,26 @@
     {
       cmn_err (CE_WARN, "Bad interrupt index (%d) for %s\n", intrnum,
 	       osdev->name);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (osdev == NULL)
     {
       cmn_err (CE_WARN, "oss_register_interrupts: Bad osdev\n");
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (osdev->tophalf_handler != NULL || osdev->bottomhalf_handler != NULL)
     {
       cmn_err (CE_WARN, "Interrupts already registered for %s\n",
 	       osdev->name);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (top == NULL)
     {
       cmn_err (CE_WARN, "Bad interrupt handler for %s\n", osdev->name);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   osdev->tophalf_handler = top;
@@ -1875,14 +1875,14 @@
 	  cmn_err (CE_WARN,
 		   "The driver for %s doesn't support hilevel interrupts\n",
 		   osdev->name);
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       DDB (cmn_err (CE_NOTE, "Using hilevel intr for %s\n", osdev->name));
 
       /* TODO: Fix hilevel intr handling */
       cmn_err (CE_WARN, "Hilevel interrupts are not supported yet.\n");
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
   else
     {
@@ -1894,7 +1894,7 @@
 			   oss_intr, (caddr_t) osdev)) != DDI_SUCCESS)
     {
       cmn_err (CE_WARN, "ddi_add_intr() failed, error=%d\n", err);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return 0;
@@ -1930,7 +1930,7 @@
   int i;
 /*
  * This routine should check if the device is ready to be unloaded (no devices are in use).
- * If the device cannot be unloaded this routine must return -EBUSY.
+ * If the device cannot be unloaded this routine must return RETERR(EBUSY).
  *
  * If the device can be unloaded then disable any timers or other features that may cause the
  * device to be called. Also mark the audio/midi/mixer/etc devices of this device to be disabled.
@@ -1941,7 +1941,7 @@
     {
       cmn_err (CE_CONT, "Refcount %d, open_devices %d\n", osdev->refcount,
 	       open_devices);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
 /*
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/OS/SunOS/udi.c oss-v4.1test0-070624-src-gpl/kernel/OS/SunOS/udi.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/OS/SunOS/udi.c	Tue Jun 12 14:22:35 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/OS/SunOS/udi.c	Tue Jun 26 22:19:34 2007
@@ -391,7 +391,7 @@
        usb_set_alt_if (usbdev->osdev->dip, inum, altset, USB_FLAGS_SLEEP,
 		       NULL, 0)) != USB_SUCCESS)
     {
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return 0;
@@ -532,7 +532,7 @@
   if (usbdev == NULL)
     {
       cmn_err (CE_CONT, "udi_usb_snd_control_msg: usbdev==NULL\n");
-      return -EFAULT;
+      return RETERR(EFAULT);
     }
 
   data = allocb_wait (len + 1, BPRI_HI, STR_NOSIG, NULL);
@@ -558,7 +558,7 @@
       cmn_err (CE_CONT, "bRq %x, wIx %x, wVal %x, wLen %d\n", rq, index,
 	       value, len);
       freemsg (data);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   freemsg (data);
@@ -583,7 +583,7 @@
   if (usbdev == NULL)
     {
       cmn_err (CE_CONT, "udi_usb_rcv_control_msg: usbdev==NULL\n");
-      return -EFAULT;
+      return RETERR(EFAULT);
     }
 
   setup.bmRequestType = rqtype | USB_DEV_REQ_DEV_TO_HOST;
@@ -602,7 +602,7 @@
       cmn_err (CE_NOTE, "usb_pipe_ctrl_xfer_wait read failed: %s (%s)\n",
 	       usb_errstr (err), usb_cb_err (completion_reason));
       freemsg (data);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   l = data->b_wptr - data->b_rptr;
@@ -944,7 +944,7 @@
 	      {
 		cmn_err (CE_WARN, "allocb_wait (isoc) failed\n");
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 
 	    if ((isoc_req = usb_alloc_isoc_req (req->dip, 1, 0, 0)) == NULL)
@@ -952,7 +952,7 @@
 		cmn_err (CE_WARN, "usb_alloc_isoc_req failed\n");
 		freemsg (req->data);
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 	    req->isoc_req = isoc_req;
 	  }
@@ -960,7 +960,7 @@
 	if (isoc_req == NULL)
 	  {
 	    cmn_err (CE_WARN, "req->isoc==NULL\n");
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 
 	memcpy (req->data->b_wptr, data, len);
@@ -982,7 +982,7 @@
 	  {
 	    cmn_err (CE_WARN, "usb_pipe_isoc_xfer failed (%s)\n",
 		     usb_errstr (err));
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 	req->active = 1;
       }
@@ -1002,7 +1002,7 @@
 	      {
 		cmn_err (CE_WARN, "usb_alloc_isoc_req failed\n");
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 	    req->isoc_req = isoc_req;
 	  }
@@ -1010,7 +1010,7 @@
 	if (isoc_req == NULL)
 	  {
 	    cmn_err (CE_WARN, "req->isoc==NULL\n");
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 
 	isoc_req->isoc_attributes = USB_ATTRS_ISOC_XFER_ASAP;
@@ -1028,7 +1028,7 @@
 	  {
 	    cmn_err (CE_WARN, "usb_pipe_isoc_xfer failed (%s)\n",
 		     usb_errstr (err));
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
       }
       break;
@@ -1046,7 +1046,7 @@
 	      {
 		cmn_err (CE_WARN, "allocb_wait (bulk) failed\n");
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 
 	    if ((bulk_req = usb_alloc_bulk_req (req->dip, len, 0)) == NULL)
@@ -1054,7 +1054,7 @@
 		cmn_err (CE_WARN, "usb_alloc_bulk_req failed\n");
 		freemsg (req->data);
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 	    req->bulk_req = bulk_req;
 	  }
@@ -1062,7 +1062,7 @@
 	if (bulk_req == NULL)
 	  {
 	    cmn_err (CE_WARN, "req->bulk==NULL\n");
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 
 	memcpy (req->data->b_wptr, data, len);
@@ -1082,7 +1082,7 @@
 	  {
 	    cmn_err (CE_WARN, "usb_pipe_bulk_xfer failed (%s)\n",
 		     usb_errstr (err));
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 	req->active = 1;
       }
@@ -1102,7 +1102,7 @@
 	      {
 		cmn_err (CE_WARN, "allocb_wait (bulk) failed\n");
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 #endif
 
@@ -1112,7 +1112,7 @@
 		cmn_err (CE_WARN, "usb_alloc_bulk_req failed\n");
 		freemsg (req->data);
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 	    req->bulk_req = bulk_req;
 	  }
@@ -1120,7 +1120,7 @@
 	if (bulk_req == NULL)
 	  {
 	    cmn_err (CE_WARN, "req->bulk==NULL\n");
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 
 	bulk_req->bulk_attributes = USB_ATTRS_SHORT_XFER_OK;
@@ -1138,7 +1138,7 @@
 	  {
 	    cmn_err (CE_WARN, "usb_pipe_bulk_xfer failed (%s)\n",
 		     usb_errstr (err));
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
       }
       break;
@@ -1157,7 +1157,7 @@
 	      {
 		cmn_err (CE_WARN, "allocb_wait (intr) failed\n");
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 #endif
 
@@ -1167,7 +1167,7 @@
 		cmn_err (CE_WARN, "usb_alloc_intr_req failed\n");
 		freemsg (req->data);
 		KERNEL_FREE (req);
-		return -ENOMEM;
+		return RETERR(ENOMEM);
 	      }
 	    req->intr_req = intr_req;
 	  }
@@ -1175,7 +1175,7 @@
 	if (intr_req == NULL)
 	  {
 	    cmn_err (CE_WARN, "req->intr==NULL\n");
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 
 	intr_req->intr_attributes =
@@ -1194,14 +1194,14 @@
 	  {
 	    cmn_err (CE_WARN, "usb_pipe_intr_xfer failed (%s)\n",
 		     usb_errstr (err));
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
       }
       break;
 
     default:
       cmn_err (CE_WARN, "Unimplemented transfer type %d\n", xfer_type);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return 0;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ali5455/ali5455.c oss-v4.1test0-070624-src-gpl/kernel/drv/ali5455/ali5455.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ali5455/ali5455.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ali5455/ali5455.c	Tue Jun 26 22:19:34 2007
@@ -380,7 +380,7 @@
 static int
 ALI_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void ALI_audio_trigger (int dev, int state);
@@ -416,7 +416,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (portc->port_type == DF_SPDIF)
@@ -426,7 +426,7 @@
 	  cmn_err (CE_WARN,
 		   "ICH: The S/PDIF device supports only playback\n");
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
     }
   else
@@ -434,7 +434,7 @@
       if (devc->open_mode & mode)
 	{
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EBUSY;
+	  return RETERR(EBUSY);
 	}
 
       devc->open_mode |= mode;
@@ -704,14 +704,14 @@
 ALI_check_input (int dev)
 {
   cmn_err (CE_WARN, "OSS ALI: Input timed out.\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 ALI_check_output (int dev)
 {
   cmn_err (CE_WARN, "OSS ALI: Output timed out\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static const audiodrv_t ALI_audio_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/allegro/allegro.c oss-v4.1test0-070624-src-gpl/kernel/drv/allegro/allegro.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/allegro/allegro.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/allegro/allegro.c	Tue Jun 26 22:19:35 2007
@@ -367,7 +367,7 @@
 static int
 allegro_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void allegro_audio_trigger (int dev, int state);
@@ -403,13 +403,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -690,7 +690,7 @@
 	}
 
       if (!db->rawbuf)
-	return -ENOMEM;
+	return RETERR(ENOMEM);
 
 #ifdef linux
       /* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */
@@ -726,7 +726,7 @@
       db->rawbuf = NULL;
       return 0;
     }
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static audiodrv_t allegro_audio_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/als300/als300.c oss-v4.1test0-070624-src-gpl/kernel/drv/als300/als300.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/als300/als300.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/als300/als300.c	Tue Jun 26 22:19:35 2007
@@ -286,7 +286,7 @@
 static int
 als300_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void als300_audio_trigger (int dev, int state);
@@ -322,13 +322,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/als4000/als4000.c oss-v4.1test0-070624-src-gpl/kernel/drv/als4000/als4000.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/als4000/als4000.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/als4000/als4000.c	Tue Jun 26 22:19:35 2007
@@ -255,17 +255,17 @@
     right = 100;
 
   if (dev > 31)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (!(ALS4000_MIXER_DEVICES & (1 << dev)))	/*
 						 * Not supported
 						 */
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   regoffs = als4000_mix[dev][LEFT_CHN].regno;
 
   if (regoffs == 0)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   val = als4000_getmixer (devc, regoffs);
   change_bits (devc, &val, dev, LEFT_CHN, left);
@@ -351,7 +351,7 @@
 	  }
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 
@@ -550,7 +550,7 @@
 static int
 als4000_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -609,13 +609,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/apci97/apci97.c oss-v4.1test0-070624-src-gpl/kernel/drv/apci97/apci97.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/apci97/apci97.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/apci97/apci97.c	Tue Jun 26 22:19:35 2007
@@ -541,7 +541,7 @@
 static int
 apci97_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void apci97_audio_trigger (int dev, int state);
@@ -577,7 +577,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   portc->open_mode = mode;
   portc->audio_enabled = ~mode;
@@ -962,7 +962,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->midi_input_intr = inputbyte;
@@ -1013,7 +1013,7 @@
 static int
 apci97_midi_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t apci97_midi_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/atiaudio/atiaudio.c oss-v4.1test0-070624-src-gpl/kernel/drv/atiaudio/atiaudio.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/atiaudio/atiaudio.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/atiaudio/atiaudio.c	Tue Jun 26 22:19:35 2007
@@ -98,7 +98,7 @@
       if (!timeout--)
 	{
 	  cmn_err (CE_WARN, "ATIIXP: codec ready timed out\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
       oss_udelay (10);
     }
@@ -121,7 +121,7 @@
     {
       cmn_err (CE_WARN, "ATI: ac97 not ready\n");
       MUTEX_EXIT_IRQRESTORE (devc->low_mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   addr = (unsigned int) (reg << 9) | (1 << 8) | (1 << 2);
@@ -131,7 +131,7 @@
     {
       cmn_err (CE_WARN, "ATI: ac97 not ready\n");
       MUTEX_EXIT_IRQRESTORE (devc->low_mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   timeout = 1000;
@@ -374,7 +374,7 @@
 static int
 ATI_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void ATI_audio_trigger (int dev, int state);
@@ -410,7 +410,7 @@
   if (portc->open_mode || (devc->open_mode & mode))
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -612,7 +612,7 @@
   if (n > BDL_SIZE)
     {
       cmn_err (CE_WARN, "oss: Internal error - BDL too small\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   for (i = 0; i < n; i++)
@@ -708,7 +708,7 @@
       if (n > BDL_SIZE)
 	{
 	  cmn_err (CE_WARN, "oss: Internal error - BDL too small\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       for (i = 0; i < n; i++)
@@ -734,14 +734,14 @@
 ATI_check_input (int dev)
 {
   cmn_err (CE_WARN, "OSS ATI: Input timed out.\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 ATI_check_output (int dev)
 {
   cmn_err (CE_WARN, "OSS ATI: Output timed out\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 
@@ -1024,7 +1024,11 @@
   devc->membar_virt =
     (char *) MAP_PCI_MEM (devc->osdev, 0, devc->membar_addr, 256);
 
-
+  if (devc->membar_virt == NULL)
+    {
+      cmn_err (CE_WARN, "ATIIXP: Cannot map pci mem\n");
+      return 0;
+    }
 
   pci_command |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
   pci_write_config_word (osdev, PCI_COMMAND, pci_command);
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/audigyls/audigyls.c oss-v4.1test0-070624-src-gpl/kernel/drv/audigyls/audigyls.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/audigyls/audigyls.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/audigyls/audigyls.c	Tue Jun 26 22:19:36 2007
@@ -240,7 +240,7 @@
   if (i == 10000)
     {
       MUTEX_EXIT_IRQRESTORE (devc->low_mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
     }
   dtemp = INW (devc->osdev, devc->base + 0x1c);
   MUTEX_EXIT_IRQRESTORE (devc->low_mutex, flags);
@@ -263,7 +263,7 @@
   if (i == 10000)
     {
       MUTEX_EXIT_IRQRESTORE (devc->low_mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
     }
   OUTW (devc->osdev, wData, devc->base + 0x1c);
   MUTEX_EXIT_IRQRESTORE (devc->low_mutex, flags);
@@ -441,7 +441,7 @@
 static int
 audigyls_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void audigyls_trigger (int dev, int state);
@@ -463,13 +463,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -1001,7 +1001,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   while (input_avail (devc))
@@ -1069,7 +1069,7 @@
 static int
 audigylsuart_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t audigyls_midi_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/audioloop/audioloop.c oss-v4.1test0-070624-src-gpl/kernel/drv/audioloop/audioloop.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/audioloop/audioloop.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/audioloop/audioloop.c	Tue Jun 26 22:19:36 2007
@@ -174,7 +174,7 @@
   audioloop_portc_t *portc = audio_engines[dev]->portc;
   if (!portc->peer->output_triggered)
     {
-      return -ECONNRESET;
+      return RETERR(ECONNRESET);
     }
   return 0;
 }
@@ -186,11 +186,11 @@
 
   if (!portc->peer->input_triggered)
     {
-      return -ECONNRESET;
+      return RETERR(ECONNRESET);
     }
 
   if (portc->peer->open_mode == 0)
-    return -EIO;
+    return RETERR(EIO);
   return 0;
 }
 
@@ -347,17 +347,17 @@
   adev_t *adev;
 
   if ((mode & OPEN_READ) && (mode & OPEN_WRITE))
-    return -EACCES;
+    return RETERR(EACCES);
 
   if (portc == NULL || portc->peer == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
 
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -387,14 +387,14 @@
   oss_native_word flags;
 
   if (portc == NULL || portc->peer == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
 
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -443,7 +443,7 @@
 static int
 audioloop_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void
@@ -526,7 +526,7 @@
       if (status & WK_SIGNAL)
 	{
 	  MUTEX_EXIT_IRQRESTORE (portc->mutex, flags);
-	  return -EINTR;
+	  return RETERR(EINTR);
 	}
     }
   MUTEX_EXIT_IRQRESTORE (portc->mutex, flags);
@@ -558,7 +558,7 @@
       if (status & WK_SIGNAL)
 	{
 	  MUTEX_EXIT_IRQRESTORE (portc->mutex, flags);
-	  return -EINTR;
+	  return RETERR(EINTR);
 	}
     }
   MUTEX_EXIT_IRQRESTORE (portc->mutex, flags);
@@ -623,7 +623,7 @@
   dmap->dmabuf_phys = 0;	/* Not mmap() capable */
   dmap->dmabuf = KERNEL_MALLOC (MY_BUFFSIZE);
   if (dmap->dmabuf == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   dmap->buffsize = MY_BUFFSIZE;
 
   return 0;
@@ -716,7 +716,7 @@
     ADEV_FIXEDRATE | ADEV_SPECIAL;
 
   if ((portc = PMALLOC (devc->osdev, sizeof (*portc))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   memset (portc, 0, sizeof (*portc));
 
   portc->devc = devc;
@@ -724,7 +724,7 @@
   if ((portc->wq = oss_create_wait_queue (devc->osdev, "audioloop")) == NULL)
     {
       cmn_err (CE_WARN, "Cannot create audioloop wait queue\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   portc->instance = num;
@@ -777,14 +777,14 @@
     ADEV_FIXEDRATE | ADEV_SPECIAL | ADEV_LOOP;
 
   if ((portc = PMALLOC (devc->osdev, sizeof (*portc))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   memset (portc, 0, sizeof (*portc));
 
   portc->devc = devc;
   if ((portc->wq = oss_create_wait_queue (devc->osdev, "audioloop")) == NULL)
     {
       cmn_err (CE_WARN, "Cannot create audioloop wait queue\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   portc->instance = num;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/audiopci/audiopci.c oss-v4.1test0-070624-src-gpl/kernel/drv/audiopci/audiopci.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/audiopci/audiopci.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/audiopci/audiopci.c	Tue Jun 26 22:19:36 2007
@@ -230,7 +230,7 @@
 apci_mixer_get (apci_devc * devc, int dev)
 {
   if (!((1 << dev) & MIXER_DEVS))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   return devc->levels[dev];
 }
@@ -246,10 +246,10 @@
   unsigned char val;
 
   if (dev > 31)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (!(MIXER_DEVS & (1 << dev)))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (left > 100)
     left = 100;
@@ -272,7 +272,7 @@
 #endif
 
   if (ak_mix_devices[dev][LEFT_CHN].regno == 0xff)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   devc->levels[dev] = retvol;
 
@@ -365,7 +365,7 @@
 	  }
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 static int
@@ -460,7 +460,7 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       return value;
@@ -530,13 +530,13 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       return value;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -800,7 +800,7 @@
 static int
 apci_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void apci_audio_trigger (int dev, int state);
@@ -836,7 +836,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -1216,7 +1216,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->midi_input_intr = inputbyte;
@@ -1272,7 +1272,7 @@
 static int
 apci_midi_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t apci_midi_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/cmi8788/cmi8788.c oss-v4.1test0-070624-src-gpl/kernel/drv/cmi8788/cmi8788.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/cmi8788/cmi8788.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/cmi8788/cmi8788.c	Tue Jun 26 22:19:36 2007
@@ -291,7 +291,7 @@
   if (status & 0x1)
     {
       cmn_err (CE_WARN, "Two-Wire interface busy\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   /* first write the Register Address into the MAP register */
@@ -452,7 +452,7 @@
 static int
 cmi8788_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 
@@ -489,13 +489,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -1066,14 +1066,14 @@
 cmi8788_check_input (int dev)
 {
   cmn_err (CE_WARN, "Input timed out on %s.\n", audio_engines[dev]->devnode);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 cmi8788_check_output (int dev)
 {
   cmn_err (CE_WARN, "Output timed out on %s.\n", audio_engines[dev]->devnode);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 
@@ -1217,7 +1217,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   while (input_avail (devc))
@@ -1285,7 +1285,7 @@
 static int
 cmi8788uart_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t cmi8788_midi_driver = {
@@ -1544,7 +1544,7 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       return value;
@@ -1602,11 +1602,11 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
       return (value);
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 
@@ -1817,7 +1817,7 @@
       return (value);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/cmpci/cmpci.c oss-v4.1test0-070624-src-gpl/kernel/drv/cmpci/cmpci.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/cmpci/cmpci.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/cmpci/cmpci.c	Tue Jun 26 22:19:37 2007
@@ -414,17 +414,17 @@
     right = 100;
 
   if (chan > 31)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (!(CMEDIA_MIXER_DEVICES & (1 << chan)))	/*
 						 * Not supported
 						 */
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   regoffs = cmpci_mix[chan][LEFT_CHN].regno;
 
   if (regoffs == 0)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   val = cmpci_getmixer (devc, regoffs);
   change_bits (devc, &val, chan, LEFT_CHN, left);
@@ -524,7 +524,7 @@
 	  }
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 static int
@@ -653,7 +653,7 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       return value;
@@ -925,12 +925,12 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       return (value);
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -1220,7 +1220,7 @@
 static int
 cmpci_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 
@@ -1257,7 +1257,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (!(devc->dev_mode & DUALDAC_MODE))
@@ -1265,7 +1265,7 @@
       if (devc->open_mode & mode)
 	{
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EBUSY;
+	  return RETERR(EBUSY);
 	}
 
       devc->open_mode |= mode;
@@ -1753,7 +1753,7 @@
     case DUALDAC_MODE:
       cmn_err (CE_WARN, "CMPCI: Cannot record because DUALDAC mode is ON.\n");
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
 
     case SPDIFIN_MODE:
       if (portc->speed < 44100)
@@ -1761,7 +1761,7 @@
 	  cmn_err (CE_WARN,
 		   "CMPCI: Cannot record spdif at sampling rate less than 44.1Khz.\n");
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
       set_adc_rate (dev, CHAN1);
       set_adc_fmt (dev, CHAN1);
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/cs4280/cs4280.c oss-v4.1test0-070624-src-gpl/kernel/drv/cs4280/cs4280.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/cs4280/cs4280.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/cs4280/cs4280.c	Tue Jun 26 22:19:37 2007
@@ -699,7 +699,7 @@
 static int
 cs4280_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void cs4280_audio_trigger (int dev, int state);
@@ -736,13 +736,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -1293,7 +1293,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
   devc->midi_input_intr = inputbyte;
@@ -1359,7 +1359,7 @@
 static int
 cs4280_midi_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t cs4280_midi_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/cs4281/cs4281.c oss-v4.1test0-070624-src-gpl/kernel/drv/cs4281/cs4281.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/cs4281/cs4281.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/cs4281/cs4281.c	Tue Jun 26 22:19:37 2007
@@ -327,7 +327,7 @@
 static int
 cs4281_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void cs4281_audio_trigger (int dev, int state);
@@ -361,13 +361,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -633,7 +633,7 @@
   cs4281_devc *devc = (cs4281_devc *) midi_devs[dev]->devc;
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->midi_input_intr = inputbyte;
@@ -682,7 +682,7 @@
 static int
 cs4281_midi_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t cs4281_midi_driver = {
@@ -715,14 +715,14 @@
 	  if (tmp1 != 0x4281)
 	    {
 	      cmn_err (CE_WARN, "Resetting AC97 failed\n");
-	      return -EIO;
+	      return RETERR(EIO);
 	    }
 	  WRITEL (BA0_CFLR, 0x1);
 	  tmp1 = READL (BA0_CFLR);
 	  if (tmp1 != 0x1)
 	    {
 	      cmn_err (CE_WARN, "Resetting AC97 still fails\n");
-	      return -EIO;
+	      return RETERR(EIO);
 	    }
 	}
     }
@@ -740,7 +740,7 @@
   if ((tmp1 = READL (BA0_SERC1)) != (SERC1_SO1EN | SERC1_SO1F_AC97))
     {
       cmn_err (CE_WARN, "CS4281: SERC1: AC97 check failed\n");
-      return -EIO;
+      return RETERR(EIO);
     }
   /* setup power management to full power */
   WRITEL (BA0_SSPM, 0x7E);
@@ -777,7 +777,7 @@
   if (!(READL (BA0_CLKCR1) & CLKCR1_DLLRDY))
     {
       cmn_err (CE_WARN, "CS4281: DLLRDY Clock not ready\n");
-      return -EIO;
+      return RETERR(EIO);
     }
   /* (6) Enable ASYNC generation. */
   WRITEL (BA0_ACCTL, ACCTL_ESYN);	/* (460h) */
@@ -796,7 +796,7 @@
   if (!(READL (BA0_ACSTS) & ACSTS_CRDY))	/* If never came ready, */
     {
       cmn_err (CE_WARN, "CS4281: AC97 not ready\n");
-      return -EIO;		/*   exit initialization. */
+      return RETERR(EIO);		/*   exit initialization. */
     }
   /* (8) Assert the 'valid frame' signal so we can */
   /* begin sending commands to the AC97 codec. */
@@ -818,7 +818,7 @@
       (ACISV_ISV3 | ACISV_ISV4))
     {
       cmn_err (CE_WARN, "CS4281: AC97 Slot not valid\n");
-      return -EIO;		/* If no valid data, exit initialization. */
+      return RETERR(EIO);		/* If no valid data, exit initialization. */
     }
   /* (12) Start digital data transfer of audio data to the codec. */
   WRITEL (BA0_ACOSV, ACOSV_SLV3 | ACOSV_SLV4);	/* (468h) */
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/digi32/digi32.c oss-v4.1test0-070624-src-gpl/kernel/drv/digi32/digi32.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/digi32/digi32.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/digi32/digi32.c	Tue Jun 26 22:19:37 2007
@@ -294,7 +294,7 @@
 static int
 digi32_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void digi32_trigger (int dev, int state);
@@ -334,7 +334,7 @@
   if (portc->open_mode != 0)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -493,7 +493,7 @@
   if (bsize != 8 * 1024)
     {
       cmn_err (CE_CONT, "Illegal fragment size %d\n", bsize);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   prev_dblbit = cmd & C_DS;
@@ -550,7 +550,7 @@
   if (i >= 1000)
     {
       cmn_err (CE_WARN, "Digi32: No input signal detected\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   devc->speed_locked = 1;
@@ -566,7 +566,7 @@
   if (bsize != 8 * 1024)
     {
       cmn_err (CE_CONT, "Illegal fragment size %d\n", bsize);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   prev_dblbit = cmd & C_DS;
@@ -610,7 +610,7 @@
   dmap->dmabuf_phys = 0;	/* Not mmap() capable */
   dmap->dmabuf = KERNEL_MALLOC (digi32_buffsize);
   if (dmap->dmabuf == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   dmap->buffsize = digi32_buffsize;
 
   return 0;
@@ -733,7 +733,7 @@
     return *arg = 100 | (100 << 8);
   if (cmd == SOUND_MIXER_WRITE_VOLUME || cmd == SOUND_MIXER_WRITE_PCM)
     return *arg = 100 | (100 << 8);
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static mixer_driver_t digi32_mixer_driver = {
@@ -748,7 +748,7 @@
   unsigned int data;
 
   if (ctrl < 0)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   offs = (ctrl >> 4) & 0x0f;	/* # of bits in the field */
   nbits = ctrl & 0x0f;		/* Shift amount */
@@ -762,14 +762,14 @@
   if (cmd == SNDCTL_MIX_WRITE)
     {
       if (value < 0 || value >= (1 << nbits))
-	return -EINVAL;
+	return RETERR(EINVAL);
       data = devc->cmd & ~(((1 << nbits) - 1) << offs);
       data |= (value & ((1 << nbits) - 1)) << offs;
       devc->cmd = data;
       return value;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/digi96/digi96.c oss-v4.1test0-070624-src-gpl/kernel/drv/digi96/digi96.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/digi96/digi96.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/digi96/digi96.c	Tue Jun 26 22:19:37 2007
@@ -265,7 +265,7 @@
 static int
 digi96_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void digi96_trigger (int dev, int state);
@@ -371,7 +371,7 @@
   if (portc->open_mode != 0 || (devc->open_mode & mode))	/* Busy? */
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -496,7 +496,7 @@
   if (!devc->master)
     {
       if (!verify_input (devc, portc))
-	return -EIO;
+	return RETERR(EIO);
     }
 
   cmd = devc->ctrl1_bits;
@@ -551,7 +551,7 @@
   write_ctrl1 (devc, cmd);
 
   if (!verify_input (devc, portc))
-    return -EIO;
+    return RETERR(EIO);
   PCI_WRITEL (devc->osdev, devc->pRESETREC, 0);
 
   return 0;
@@ -645,7 +645,7 @@
     return *arg = 100 | (100 << 8);
   if (cmd == SOUND_MIXER_WRITE_VOLUME || cmd == SOUND_MIXER_WRITE_PCM)
     return *arg = 100 | (100 << 8);
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static mixer_driver_t digi96_mixer_driver = {
@@ -659,7 +659,7 @@
   unsigned int tmp;
 
   if (ctrl < 0)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -698,7 +698,7 @@
 	  break;
 	}
 
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (cmd == SNDCTL_MIX_WRITE)
@@ -712,7 +712,7 @@
 
 	case 2:
 	  if (value < 0 || value > 3)
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 
 	  devc->input_source = value;
 	  return value;
@@ -733,7 +733,7 @@
 
 	case 4:
 	  if (value > 2 || (!devc->have_adat && value > 1))
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 
 	  devc->mode = value;
 	  return value;
@@ -783,10 +783,10 @@
 
 	}
 
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/emu10k1x/emu10k1x.c oss-v4.1test0-070624-src-gpl/kernel/drv/emu10k1x/emu10k1x.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/emu10k1x/emu10k1x.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/emu10k1x/emu10k1x.c	Tue Jun 26 22:19:38 2007
@@ -308,7 +308,7 @@
 static int
 emu10k1x_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void emu10k1x_trigger (int dev, int state);
@@ -345,7 +345,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -572,7 +572,7 @@
 	  portc->recbuf =
 	    CONTIG_MALLOC (devc->osdev, BUFSIZE, MEMLIMIT_32BITS, &phaddr);
 	  if (portc->recbuf == NULL)
-	    return -ENOMEM;
+	    return RETERR(ENOMEM);
 	  portc->recbuf_phys = phaddr;
 	}
     }
@@ -581,7 +581,7 @@
       portc->playbuf =
 	CONTIG_MALLOC (devc->osdev, BUFSIZE, MEMLIMIT_32BITS, &phaddr);
       if (portc->playbuf == NULL)
-	return -ENOMEM;
+	return RETERR(ENOMEM);
       portc->playbuf_phys = phaddr;
     }
   return 0;
@@ -729,7 +729,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   while (input_avail (devc))
@@ -797,7 +797,7 @@
 static int
 emu10k1xuart_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t emu10k1x_midi_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/fm801/fm801.c oss-v4.1test0-070624-src-gpl/kernel/drv/fm801/fm801.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/fm801/fm801.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/fm801/fm801.c	Tue Jun 26 22:19:38 2007
@@ -446,7 +446,7 @@
 static int
 fm801_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void fm801_audio_trigger (int dev, int state);
@@ -481,12 +481,12 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   devc->open_mode |= mode;
   portc->open_mode = mode;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/geode/geode.c oss-v4.1test0-070624-src-gpl/kernel/drv/geode/geode.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/geode/geode.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/geode/geode.c	Tue Jun 26 22:19:38 2007
@@ -350,7 +350,7 @@
 static int
 geode_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void geode_audio_trigger (int dev, int state);
@@ -386,13 +386,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio.c oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio.c	Tue Jun 26 22:19:38 2007
@@ -597,7 +597,7 @@
       case HDA_IOCTL_READ:
 	if (!do_corb_read_simple
 	    (devc, *(unsigned int *) arg, (unsigned int *) arg))
-	  return -EIO;
+	  return RETERR(EIO);
 
 	return 0;
 	break;
@@ -632,7 +632,7 @@
   if (portc->open_mode || portc->endpoint->busy)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (portc->port_type == PT_INPUT)
@@ -656,7 +656,7 @@
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
       cmn_err (CE_WARN, "hda: No free DMA engines.\nn");
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -913,7 +913,7 @@
        portc->bits, portc->endpoint->stream_number, &tmp) < 0)
     {
       cmn_err (CE_WARN, "Codec setup failed\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   PCI_WRITEW (devc->osdev, engine->base + HDA_SD_FORMAT, tmp);
@@ -932,7 +932,7 @@
   hda_engine_t *engine;
 
   if (portc->port_type != PT_INPUT)
-    return -ENOTSUP;
+    return RETERR(ENOTSUP);
 
   engine = portc->engine;
 
@@ -962,7 +962,7 @@
   oss_native_word flags;
 
   if (portc->port_type != PT_OUTPUT)
-    return -ENOTSUP;
+    return RETERR(ENOTSUP);
 
   engine = portc->engine;
 
@@ -986,7 +986,7 @@
 hda_check_input (int dev)
 {
   cmn_err (CE_WARN, "Input timed out on %s.\n", audio_engines[dev]->devnode);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -1003,7 +1003,7 @@
 								    0x03));
 #endif
   cmn_err (CE_WARN, "Output timed out on %s.\n", audio_engines[dev]->devnode);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -1315,7 +1315,7 @@
   hdaudio_endpointinfo_t *endpoint = devc->spdifout_endpoint;
 
   if (endpoint == NULL)
-    return -EIO;
+    return RETERR(EIO);
 
   MUTEX_ENTER_IRQDISABLE (devc->low_mutex, flags);
 
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio_codec.c oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio_codec.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio_codec.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio_codec.c	Tue Jun 26 22:19:39 2007
@@ -476,7 +476,7 @@
   if (size != sizeof (hdaudio_endpointinfo_t))
     {
       cmn_err (CE_WARN, "hdaudio: Bad endpoint size\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   *endpoints = (hdaudio_endpointinfo_t *) & mixer->outendpoints;
@@ -490,7 +490,7 @@
   if (size != sizeof (hdaudio_endpointinfo_t))
     {
       cmn_err (CE_WARN, "hdaudio: Bad endpoint size\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   *endpoints = (hdaudio_endpointinfo_t *) & mixer->inendpoints;
@@ -657,10 +657,10 @@
   cad = (ctrl >> 24) & 0xff;
 
   if (cad >= mixer->ncodecs)
-    return -EIO;
+    return RETERR(EIO);
 
   if (wid >= mixer->codecs[cad]->nwidgets)
-    return -EIO;
+    return RETERR(EIO);
 
   widget = &mixer->codecs[cad]->widgets[wid];
 
@@ -669,13 +669,13 @@
       {
       case CT_INGAINSEL:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (0, 0), ix, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	return a & 0x7f;	// TODO: Handle mute
 	break;
 
       case CT_INMONO:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (0, 0), ix, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	if (a & 0x80)
 	  left = 0;
 	else
@@ -685,13 +685,13 @@
 
       case CT_INSTEREO:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (0, 1), ix, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	if (a & 0x80)
 	  left = 0;
 	else
 	  left = scalein_vol (a, widget->inamp_caps);
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (0, 0), ix, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	if (a & 0x80)
 	  right = 0;
 	else
@@ -701,7 +701,7 @@
 
       case CT_INMUTE:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (0, 0), ix, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	return (a >> 7) & 0x01;
 	break;
 
@@ -711,13 +711,13 @@
 
       case CT_OUTGAINSEL:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (1, 1), 0, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	return a;		// TODO: Handle mute
 	break;
 
       case CT_OUTMONO:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (1, 1), 0, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	left = a & 0x7f;
 	if (a & 0x80)
 	  left = 0;
@@ -728,14 +728,14 @@
 
       case CT_OUTSTEREO:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (1, 1), 0, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	left = a & 0x7f;
 	if (a & 0x80)
 	  left = 0;
 	else
 	  left = scalein_vol (a, widget->outamp_caps);
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (1, 0), 0, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	right = a & 0x7f;
 	if (a & 0x80)
 	  right = 0;
@@ -746,12 +746,12 @@
 
       case CT_OUTMUTE:
 	if (!corb_read (mixer, cad, wid, 0, GET_GAIN (1, 0), 0, &a, &b))
-	  return -EIO;
+	  return RETERR(EIO);
 	return (a >> 7) & 0x01;
 	break;
 
       default:
-	return -EINVAL;
+	return RETERR(EINVAL);
       }
 
   if (cmd == SNDCTL_MIX_WRITE)
@@ -877,11 +877,11 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -1051,7 +1051,7 @@
 	if (codec->mixer_init != NULL)
 	  if ((err = codec->mixer_init (dev, mixer, cad, group)) < 0)
 	    {
-	      if (err != -EAGAIN)
+	      if (err != RETERR(EAGAIN))
 		return err;
 	      /*
 	       * We got EAGAIN whic means that we should fall
@@ -1262,7 +1262,7 @@
 		      GET_PARAMETER, HDA_OUTPUTAMP_CAPS, &outamp_caps, &b))
 	{
 	  cmn_err (CE_WARN, "GET_PARAMETER HDA_OUTPUTAMP_CAPS failed\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
       widget->outamp_caps = outamp_caps;
 
@@ -1270,7 +1270,7 @@
 		      GET_PARAMETER, HDA_INPUTAMP_CAPS, &inamp_caps, &b))
 	{
 	  cmn_err (CE_WARN, "GET_PARAMETER HDA_INPUTAMP_CAPS failed\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
       widget->inamp_caps = inamp_caps;
     }
@@ -1918,7 +1918,7 @@
   if (cad >= MAX_CODECS)
     {
       cmn_err (CE_WARN, "hdaudio_mixer_attach: Too many codecs %d\n", cad);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   mixer->ncodecs = cad + 1;
@@ -1926,7 +1926,7 @@
   if ((codec = PMALLOC (mixer->osdev, sizeof (*codec))) == NULL)
     {
       cmn_err (CE_CONT, "Cannot allocate codec descriptor\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   memset (codec, 0, sizeof (*codec));
@@ -1939,7 +1939,7 @@
     {
       cmn_err (CE_WARN, "hdaudio_mixer_attach: Codec #%d is not responding\n",
 	       cad);
-      return -EIO;
+      return RETERR(EIO);
     }
 
 /*
@@ -1989,7 +1989,7 @@
   if (!corb_read (mixer, cad, 0, 0, GET_PARAMETER, HDA_NODE_COUNT, &a, &b))
     {
       cmn_err (CE_WARN, "GET_PARAMETER HDA_NODE_COUNT3 failed\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   first_node = (a >> 16) & 0xff;
@@ -2037,7 +2037,7 @@
   for (i = first_node; i < first_node + num_nodes; i++)
     {
       if (!attach_group (mixer, cad, i, 0))
-	return -EIO;
+	return RETERR(EIO);
 
       /* power up the AFG! */
       corb_write (mixer, cad, i, 0, SET_POWER_STATE, 0);
@@ -2138,7 +2138,7 @@
       else
 	{
 	  cmn_err (CE_WARN, "hdaudio_codec: Bad bit size\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
       break;
 
@@ -2155,7 +2155,7 @@
 
     default:
       cmn_err (CE_WARN, "hdaudio_codec: Bad format %x\n", fmt);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   corb_write (mixer, endpoint->cad, endpoint->wid, 0, SET_SPDIF_CONTROL1,
@@ -2320,14 +2320,14 @@
     case SNDCTL_DSP_GET_RECSRC:
       if (!corb_read
 	  (mixer, widget->cad, widget->wid, 0, GET_SELECTOR, 0, &a, &b))
-	return -EIO;
+	return RETERR(EIO);
       return *arg = a;
       break;
 
     case SNDCTL_DSP_SET_RECSRC:
       a = *arg;
       if (a > widget->nconn)
-	return -EIO;
+	return RETERR(EIO);
 
       corb_write (mixer, widget->cad, widget->wid, 0, SET_SELECTOR, a);
       widget->current_selector = a;
@@ -2341,14 +2341,14 @@
 	nsteps = 1;
       if (!corb_read
 	  (mixer, widget->cad, widget->wid, 0, GET_GAIN (0, 1), 0, &a, &b))
-	return -EIO;
+	return RETERR(EIO);
       if (a & 0x80)		/* Muted */
 	left = 0;
       else
 	left = ((a & 0x7f) * 100) / nsteps;
       if (!corb_read
 	  (mixer, widget->cad, widget->wid, 0, GET_GAIN (0, 0), 0, &a, &b))
-	return -EIO;
+	return RETERR(EIO);
       if (a & 0x80)		/* Muted */
 	right = 0;
       else
@@ -2398,14 +2398,14 @@
 	nsteps = 1;
       if (!corb_read
 	  (mixer, widget->cad, widget->wid, 0, GET_GAIN (1, 1), 0, &a, &b))
-	return -EIO;
+	return RETERR(EIO);
       if (a & 0x80)		/* Muted */
 	left = 0;
       else
 	left = ((a & 0x7f) * 100) / nsteps;
       if (!corb_read
 	  (mixer, widget->cad, widget->wid, 0, GET_GAIN (1, 0), 0, &a, &b))
-	return -EIO;
+	return RETERR(EIO);
       if (a & 0x80)		/* Muted */
 	right = 0;
       else
@@ -2450,7 +2450,7 @@
       break;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 unsigned int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio_generic.c oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio_generic.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio_generic.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio_generic.c	Tue Jun 26 22:19:39 2007
@@ -485,7 +485,7 @@
   if (ext == NULL)
     {
       cmn_err (CE_WARN, "Cannot locate the mixer extension (a)\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   memset (ext->enum_present, 0, sizeof (ext->enum_present));
@@ -631,7 +631,7 @@
 	  if (ext == NULL)
 	    {
 	      cmn_err (CE_WARN, "Cannot locate the mixer extension (b)\n");
-	      return -EIO;
+	      return RETERR(EIO);
 	    }
 
 	  memset (ext->enum_present, 0, sizeof (ext->enum_present));
@@ -848,7 +848,7 @@
   if (mixer->codecs[cad] == NULL)
     {
       cmn_err (CE_WARN, "Bad codec %d\n", cad);
-      return -EIO;
+      return RETERR(EIO);
     }
   codec = mixer->codecs[cad];
 
@@ -875,7 +875,7 @@
   if (!corb_read (mixer, cad, 0, 0, GET_PARAMETER, HDA_VENDOR, &vendorid, &b))
     {
       cmn_err (CE_WARN, "Cannot get codec ID\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
 /*
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio_sigmatel.c oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio_sigmatel.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/hdaudio/hdaudio_sigmatel.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/hdaudio/hdaudio_sigmatel.c	Tue Jun 26 22:19:39 2007
@@ -84,5 +84,5 @@
       cmn_err (CE_WARN, "Unknown sigmatel codec ID 0x%08x\n", vendorid);
     }
 
-  return -EAGAIN;
+  return RETERR(EAGAIN);
 }
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ich/ich.c oss-v4.1test0-070624-src-gpl/kernel/drv/ich/ich.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ich/ich.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ich/ich.c	Tue Jun 26 22:19:39 2007
@@ -534,7 +534,7 @@
 static int
 ich_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void ich_audio_trigger (int dev, int state);
@@ -570,7 +570,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   if (portc->port_type == DF_SPDIF)
     {
@@ -578,7 +578,7 @@
 	{
 	  cmn_err (CE_NOTE, "The S/PDIF device supports only playback\n");
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
     }
   else
@@ -586,7 +586,7 @@
       if (devc->open_mode & mode)
 	{
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EBUSY;
+	  return RETERR(EBUSY);
 	}
       devc->open_mode |= mode;
     }
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/imux/imux.c oss-v4.1test0-070624-src-gpl/kernel/drv/imux/imux.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/imux/imux.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/imux/imux.c	Tue Jun 26 22:19:40 2007
@@ -104,7 +104,7 @@
   imux_portc *portc;
 
   if (ctrl != 100 && (ctrl < 0 || ctrl >= devc->imux_devices))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   portc = &devc->portc[ctrl];
 
@@ -137,7 +137,7 @@
       return left | (right << 8);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -153,7 +153,7 @@
       {
 	value = *arg;
 	if (value <= 0 || value >= devc->hw_channels - 1)
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	portc->ch_index = value;
       }
 
@@ -209,7 +209,7 @@
       return 0;
       break;
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void imux_trigger (int dev, int state);
@@ -422,7 +422,7 @@
   if (devc->hw_dev < 0 || devc->hw_dev >= num_audio_engines)
     {
       cmn_err (CE_WARN, "No audio hardware available\n");
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   if (devc->device_started)
@@ -442,7 +442,7 @@
       && devc->hw_dev <= devc->portc[devc->imux_devices - 1].audio_dev)
     {
       cmn_err (CE_WARN, "Bad master device %d\n", devc->hw_dev);
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   if (!(audio_engines[devc->hw_dev]->iformat_mask & SUPPORTED_FORMATS))
@@ -450,7 +450,7 @@
       cmn_err (CE_CONT,
 	       "Audio device %d doesn't support compatible sample formats.\n",
 	       devc->hw_dev);
-      return -EIO;
+      return RETERR(EIO);
     }
   if ((err =
        oss_audio_open_engine (devc->hw_dev, OSS_DEV_DSP, &devc->finfo, 1, 0,
@@ -490,7 +490,7 @@
       cmn_err (CE_WARN,
 	       "This device doesn't support any known sample formats (%x)\n",
 	       devc->hw_fmt);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   switch (devc->hw_fmt)
@@ -512,7 +512,7 @@
     {
       oss_audio_release (devc->hw_dev, &devc->finfo);
       cmn_err (CE_WARN, "A 2 channel soundcard (or better) is required\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   DDB (cmn_err (CE_CONT, "Started audio device %d, s=%d, c=%d, bits=%d\n",
@@ -569,7 +569,7 @@
   if (devc->hw_dev < 0)
     {
       cmn_err (CE_NOTE, "No master device allocated\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
@@ -577,7 +577,7 @@
   if (portc->is_opened)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->is_opened = 1;
@@ -668,7 +668,7 @@
 static int
 imux_prepare_for_output (int dev, int bsize, int bcount)
 {
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -680,7 +680,7 @@
   dmap->dmabuf_phys = 0;	/* Not mmap() capable */
   dmap->dmabuf = KERNEL_MALLOC (MY_BUFFSIZE);
   if (dmap->dmabuf == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   dmap->buffsize = MY_BUFFSIZE;
 
   return 0;
@@ -735,7 +735,7 @@
 static int
 imux_mixer_ioctl (int dev, int audiodev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static mixer_driver_t imux_mixer_driver = {
@@ -784,7 +784,7 @@
   imux_devc *devc = mixer_devs[dev]->devc;
 
   if (ctrl < 0 || ctrl >= devc->imux_devices)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -795,7 +795,7 @@
       return left | (right << 8);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/maestro/maestro.c oss-v4.1test0-070624-src-gpl/kernel/drv/maestro/maestro.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/maestro/maestro.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/maestro/maestro.c	Tue Jun 26 22:19:40 2007
@@ -350,7 +350,7 @@
 pt101_mixer_get (maestro_devc * devc, int dev)
 {
   if (!((1 << dev) & PT101_MIXER_DEVS))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   return devc->levels[dev];
 }
@@ -373,7 +373,7 @@
 
 
   if (!((1 << dev) & PT101_MIXER_DEVS))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (!((1 << dev) & PT101_MIXER_STEREODEVS))
     {
@@ -568,7 +568,7 @@
 	  }
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 /*
@@ -1274,7 +1274,7 @@
 static int
 maestro_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void maestro_audio_trigger (int dev, int state);
@@ -1310,7 +1310,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->lock, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 #if 1
   if ((mode & OPEN_READ))
@@ -1325,7 +1325,7 @@
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->lock, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -1471,7 +1471,7 @@
   if (portc->channels == 2)
     {
       cmn_err (CE_WARN, "Maestro: Stereo recording not yet supported\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 #endif
 
@@ -1733,14 +1733,14 @@
 maestro_check_input (int dev)
 {
   cmn_err (CE_WARN, "Maestro: Input timeout\n");
-  return -EIO;;
+  return RETERR(EIO);;
 }
 
 static int
 maestro_check_output (int dev)
 {
   cmn_err (CE_WARN, "Maestro: Output timeout\n");
-  return -EIO;;
+  return RETERR(EIO);;
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/neomagic/neomagic.c oss-v4.1test0-070624-src-gpl/kernel/drv/neomagic/neomagic.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/neomagic/neomagic.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/neomagic/neomagic.c	Tue Jun 26 22:19:40 2007
@@ -65,13 +65,13 @@
   else if (devc->dev[1] == dev)
     w = 1;
   else
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   targetrate = devc->portc[w].samplerate;
 
   if ((devc->portc[w].bits != 8 && devc->portc[w].bits != 16)
       || targetrate < samplerates[0] || targetrate > samplerates[7])
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   for (x = 0; x < 8; x++)
     if (targetrate < ((samplerates[x] + samplerates[x + 1]) / 2))
@@ -110,7 +110,7 @@
       return 0;
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 /* Start the play process going. */
@@ -463,7 +463,7 @@
   else
     {
       MUTEX_EXIT_IRQRESTORE (devc->low_mutex, flags);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
@@ -790,21 +790,21 @@
   int w;
 
   if (devc == NULL)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (devc->dev[0] == dev)
     w = 0;
   else if (devc->dev[1] == dev)
     w = 1;
   else
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (devc->opencnt[w] > 0)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   /* No bits set? Huh? */
   if (!((mode & OPEN_READ) || (mode & OPEN_WRITE)))
-    return -EIO;
+    return RETERR(EIO);
 
   /*
    * If it's open for both read and write, and the devc's currently
@@ -837,7 +837,7 @@
 	    ~(ADEV_FIXEDRATE | ADEV_16BITONLY | ADEV_STEREOONLY);
 	}
       else
-	return -EBUSY;
+	return RETERR(EBUSY);
     }
 
   if (mode & OPEN_READ)
@@ -853,7 +853,7 @@
 	    ADEV_FIXEDRATE | ADEV_16BITONLY | ADEV_STEREOONLY;
 	}
       else
-	return -EBUSY;
+	return RETERR(EBUSY);
     }
 
   devc->opencnt[w]++;
@@ -913,7 +913,7 @@
   int which;
 
   if (devc == NULL)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (devc->dev[0] == dev)
     which = 0;
@@ -945,7 +945,7 @@
   int which;
 
   if (devc == NULL)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (devc->dev[0] == dev)
     which = 0;
@@ -969,7 +969,7 @@
   int which;
 
   if (devc == NULL)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (devc->dev[0] == dev)
     which = 0;
@@ -990,7 +990,7 @@
 static int
 neomagic_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /*
@@ -1050,10 +1050,10 @@
   oss_native_word flags;
 
   if (devc == NULL)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (devc->is_open_record && devc->dev_for_record != dev)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
   /*
@@ -1091,10 +1091,10 @@
   oss_native_word flags;
 
   if (devc == NULL)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (devc->is_open_play && devc->dev_for_play != dev)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
   /*
@@ -1211,7 +1211,7 @@
   oss_native_word flags;
 
   if (devc == NULL)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   MUTEX_ENTER_IRQDISABLE (devc->low_mutex, flags);
   if (direction == PCM_ENABLE_OUTPUT)
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/ossusb.c oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/ossusb.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/ossusb.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/ossusb.c	Tue Jun 26 22:19:40 2007
@@ -438,7 +438,7 @@
       break;
 
     default:
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return value;
@@ -539,10 +539,10 @@
   usb_control_t *c;
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
   if (ctrl < 0 || ctrl >= devc->ncontrols)
-    return -EIO;
+    return RETERR(EIO);
 
   c = &devc->controls[ctrl];
 
@@ -552,7 +552,7 @@
     }
 
   if (cmd != SNDCTL_MIX_WRITE)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   value = c->value = write_current_value (devc, c, value);
 
@@ -1209,7 +1209,7 @@
   ossusb_devc *devc = mixer_devs[dev]->hw_devc;
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
   switch (cmd)
     {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usb_midisport.c oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usb_midisport.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usb_midisport.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usb_midisport.c	Tue Jun 26 22:19:40 2007
@@ -363,7 +363,7 @@
   if (midic->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (midic->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   midic->open_mode = mode;
@@ -386,7 +386,7 @@
       if (devc->recbuf == NULL)
 	{
 	  cmn_err (CE_CONT, "Failed to allocate the recording buffer\n");
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
 
       if ((devc->input_endpoint_handle =
@@ -395,20 +395,20 @@
 	  midic->open_mode = 0;
 	  midic->midi_input_intr = NULL;
 	  cmn_err (CE_WARN, "Cannot open audio pipe\n");
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
       if ((devc->input_pipe =
 	   udi_usb_alloc_request (devc->usbdev, devc->input_endpoint_handle,
 				  1, UDI_USBXFER_INTR_READ)) == NULL)
 	{
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       if ((err = midisport_start_input (devc)) < 0)
 	{
 	  cmn_err (CE_CONT, "oss midisport: Input error %d\n", err);
 	  midisport_close_input (dev, mode);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
     }
 
@@ -426,7 +426,7 @@
   if (queue_ix < 0 || queue_ix >= devc->num_queues)
     {
       cmn_err (CE_WARN, "Bad output queue index %d\n", queue_ix);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   q = &devc->out_queues[queue_ix];
@@ -450,7 +450,7 @@
 	  cmn_err (CE_WARN, "Failed to allocate output buffer (%d bytes)\n",
 		   QUEUE_SIZE);
 	  q->open_count--;
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
 
       if ((q->output_endpoint_handle =
@@ -458,7 +458,7 @@
 	{
 	  cmn_err (CE_WARN, "Failed to open output endpoint\n");
 	  q->open_count--;
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       if ((q->output_pipe =
@@ -467,7 +467,7 @@
 	{
 	  cmn_err (CE_WARN, "Failed to allocate output request\n");
 	  q->open_count--;
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
     }
@@ -541,7 +541,7 @@
   if (midic->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (midic->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   midic->open_mode = mode;
@@ -622,7 +622,7 @@
   if (midic->outqueue_ix < 0 || midic->outqueue_ix >= devc->num_queues)
     {
       cmn_err (CE_WARN, "Bad output queue index %d\n", midic->outqueue_ix);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   q = &devc->out_queues[midic->outqueue_ix];
@@ -677,7 +677,7 @@
 static int
 midisport_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t midisport_midi_input_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usb_ymhmidi.c oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usb_ymhmidi.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usb_ymhmidi.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usb_ymhmidi.c	Tue Jun 26 22:19:41 2007
@@ -218,7 +218,7 @@
   if (midic->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (midic->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   midic->open_mode = mode;
@@ -235,13 +235,13 @@
       midic->open_mode = 0;
       midic->midi_input_intr = NULL;
       cmn_err (CE_WARN, "Cannot open audio pipe\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
   if ((midic->datapipe =
        udi_usb_alloc_request (midic->usbdev, midic->endpoint_handle, 1,
 			      UDI_USBXFER_BULK_READ)) == NULL)
     {
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return ymhmidi_start_input (devc, midic);
@@ -450,7 +450,7 @@
   if (midic->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (midic->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   midic->open_mode = mode;
@@ -470,7 +470,7 @@
       midic->open_mode = 0;
       midic->midi_input_intr = NULL;
       cmn_err (CE_WARN, "Cannot create MIDI parser\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   if ((midic->endpoint_handle =
@@ -479,13 +479,13 @@
       midic->open_mode = 0;
       midic->midi_input_intr = NULL;
       cmn_err (CE_WARN, "Cannot open audio pipe\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
   if ((midic->datapipe =
        udi_usb_alloc_request (midic->usbdev, midic->endpoint_handle, 1,
 			      UDI_USBXFER_BULK_WRITE)) == NULL)
     {
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return 0;
@@ -512,7 +512,7 @@
 static int
 ymhusb_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t ymhusb_input_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usbaudio.c oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usbaudio.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usbaudio.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usbaudio.c	Tue Jun 26 22:19:41 2007
@@ -86,7 +86,7 @@
 
     default:
       cmn_err (CE_CONT, "oss usbaudio: Bad control size %d\n", l);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   len = udi_usb_snd_control_msg (devc->mixer_usbdev, 0,	// endpoint
@@ -99,7 +99,7 @@
   if (len < 0)
     {
       cmn_err (CE_CONT, "ossusb: Endpoint control write error %d\n", len);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return len;
@@ -136,7 +136,7 @@
   int i, x, diff, bestdiff, l;
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
   if (arg == 0)
     return portc->speed;
@@ -186,7 +186,7 @@
   ossusb_devc *devc = adev->devc;
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
   return adev->min_channels;	/* max_channels should be the same too */
 }
@@ -198,7 +198,7 @@
   ossusb_devc *devc = adev->devc;
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
   return adev->oformat_mask;	/* iformat_mask should be the same  too */
 }
@@ -208,9 +208,9 @@
 {
   ossusb_devc *devc = audio_engines[dev]->devc;
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -490,7 +490,7 @@
       cmn_err (CE_CONT, "oss usbaudio: Unsupported FORMAT II tag %04x\n",
 	       fmt);
       adev->enabled = 0;
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
   return 0;
 }
@@ -527,7 +527,7 @@
       portc->disabled = 1;
       adev->enabled = 0;
       portc->act_setting = devc->act_setting;
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   UDB (cmn_err
@@ -596,7 +596,7 @@
 			 "\noss usbaudio: Unsupported format type %d\n",
 			 d[3]);
 		adev->enabled = 0;
-		return -ENXIO;
+		return RETERR(ENXIO);
 	      }
 	    break;
 
@@ -617,7 +617,7 @@
   if (desc == NULL)
     {
       cmn_err (CE_CONT, "oss usbaudio: Bad endpoint\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   portc->endpoint_desc = desc;
@@ -647,13 +647,13 @@
   int i;
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
   if (portc->open_mode != 0)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   portc->open_mode = mode;
   MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
@@ -689,7 +689,7 @@
     {
       usbaudio_close (dev, mode);
       cmn_err (CE_WARN, "Cannot open audio pipe\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   for (i = 0; i < 2; i++)
@@ -700,7 +700,7 @@
 	{
 	  usbaudio_close (dev, mode);
 	  cmn_err (CE_WARN, "Cannot alloc isoc request\n");
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
     }
 
@@ -1081,11 +1081,11 @@
   adev_p adev = audio_engines[dev];
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
 
   if (adev->flags & ADEV_NOINPUT)
-    return -ENOTSUP;
+    return RETERR(ENOTSUP);
 
   portc->stopping = 0;
 
@@ -1094,7 +1094,7 @@
        portc->speed) < 0)
     {
       cmn_err (CE_CONT, "Failed to set %d Hz sampling rate\n", portc->speed);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   /*
@@ -1115,10 +1115,10 @@
   adev_p adev = audio_engines[dev];
 
   if (devc->disabled)
-    return -EPIPE;
+    return RETERR(EPIPE);
 
   if (adev->flags & ADEV_NOOUTPUT)
-    return -ENOTSUP;
+    return RETERR(ENOTSUP);
 
   portc->stopping = 0;
 
@@ -1127,7 +1127,7 @@
        portc->speed) < 0)
     {
       cmn_err (CE_CONT, "Failed to set %d Hz sampling rate\n", portc->speed);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   /*
@@ -1149,12 +1149,12 @@
       cmn_err (CE_CONT,
 	       "oss usbaudio: Audio device %d removed from the system.\n",
 	       dev);
-      return -EPIPE;
+      return RETERR(EPIPE);
     }
 
   cmn_err (CE_CONT, "oss usbaudio: Audio input timed out on device %d.\n",
 	   dev);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -1166,12 +1166,12 @@
       cmn_err (CE_CONT,
 	       "oss usbaudio: Audio device %d removed from the system.\n",
 	       dev);
-      return -EPIPE;
+      return RETERR(EPIPE);
     }
 
   cmn_err (CE_CONT, "oss usbaudio: Audio output timed out on device %d.\n",
 	   dev);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usbmidi.c oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usbmidi.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ossusb/usbmidi.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ossusb/usbmidi.c	Tue Jun 26 22:19:41 2007
@@ -180,7 +180,7 @@
   if (midic->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   midic->open_mode = mode;
@@ -196,7 +196,7 @@
 	{
 	  usb_midi_close (dev, mode);
 	  cmn_err (CE_WARN, "Cannot open midi output pipe\n");
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
 
       if ((devc->output_pipe =
@@ -223,7 +223,7 @@
 	{
 	  usb_midi_close (dev, mode);
 	  cmn_err (CE_WARN, "Cannot open midi input pipe\n");
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
       if ((devc->input_pipe =
 	   udi_usb_alloc_request (midic->usbdev, midic->in_endpoint_handle, 1,
@@ -238,7 +238,7 @@
 	{
 	  cmn_err (CE_CONT, "oss usbmidi: Input error %d\n", err);
 	  usb_midi_close (dev, mode);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
     }
 
@@ -279,7 +279,7 @@
 static int
 usb_midi_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/s3vibes/s3vibes.c oss-v4.1test0-070624-src-gpl/kernel/drv/s3vibes/s3vibes.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/s3vibes/s3vibes.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/s3vibes/s3vibes.c	Tue Jun 26 22:19:41 2007
@@ -210,7 +210,7 @@
 vibes_mixer_get (vibes_devc * devc, int dev)
 {
   if (!((1 << dev) & MIXER_DEVS))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   return devc->levels[dev];
 }
@@ -383,7 +383,7 @@
 	  }
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 static mixer_driver_t vibes_mixer_driver = {
@@ -436,7 +436,7 @@
 static int
 vibes_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void
@@ -495,7 +495,7 @@
   if (devc->audio_open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->audio_open_mode |= mode;
@@ -694,14 +694,14 @@
 
   cmn_err (CE_WARN, "S3 SonicVibes: Input timed out. Ptr %x, addr %x\n", tmp,
 	   addr);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 vibes_check_output (int dev)
 {
   cmn_err (CE_WARN, "S3 SonicVibes: Output timed out.\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 #if 0
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/sblive/sblive.c oss-v4.1test0-070624-src-gpl/kernel/drv/sblive/sblive.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/sblive/sblive.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/sblive/sblive.c	Tue Jun 26 22:19:41 2007
@@ -668,19 +668,19 @@
     case SBLIVE_WRITEPARMS:
       {
 	if (gpr->ngpr >= MAX_GPR_PARMS)
-	  return -EIO;
+	  return RETERR(EIO);
 
 	for (i = 0; i < gpr->ngpr; i++)
 	  {
 	    gpr->gpr[i].name[GPR_NAME_SIZE - 1] = 0;	/* Overflow protection */
 	    if (strlen (gpr->gpr[i].name) >= 32)	/* Name may be bad */
 	      {
-		return -EIO;
+		return RETERR(EIO);
 	      }
 
 	    if (gpr->gpr[i].num >= MAX_GPR)
 	      {
-		return -EIO;
+		return RETERR(EIO);
 	      }
 
 /* cmn_err(CE_CONT, "Gpr %d = %s (vol %x) type=%x\n", gpr->gpr[i].num, gpr->gpr[i].name, gpr->gpr[i].def, gpr->gpr[i].type); */
@@ -703,7 +703,7 @@
 	    if (devc->gpr == NULL)
 	      {
 		cmn_err (CE_CONT, "SB Live: Out of memory (gpr)\n");
-		return -ENOSPC;
+		return RETERR(ENOSPC);
 	      }
 	    memset (devc->gpr, 0, sizeof (gpr_info));
 	  }
@@ -716,13 +716,13 @@
     case SBLIVE_WRITECONST:
       {
 	if (consts->nconst >= MAX_CONST_PARMS)
-	  return -EIO;
+	  return RETERR(EIO);
 
 	for (i = 0; i < consts->nconst; i++)
 	  {
 	    if (consts->consts[i].gpr >= MAX_GPR)
 	      {
-		return -EIO;
+		return RETERR(EIO);
 	      }
 
 	    sblive_write_reg (devc, consts->consts[i].gpr + GPR0, 0,
@@ -763,7 +763,7 @@
       break;
 
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void sblive_audio_trigger (int dev, int state);
@@ -826,7 +826,7 @@
   if (portc->mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->mode = mode;
@@ -851,7 +851,7 @@
       if (!setup_passthrough (devc, portc, 1))
 	{
 	  portc->mode = 0;
-	  return -EBUSY;
+	  return RETERR(EBUSY);
 	}
     }
   else
@@ -1569,7 +1569,7 @@
   if (audio_engines[dev]->flags & ADEV_NOINPUT)
     {
       cmn_err (CE_CONT, "SB Live: Audio device %d is output only\n", dev);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (dmap->buffsize > 65536)
@@ -1606,7 +1606,7 @@
     default:
       cmn_err (CE_CONT, "SB Live error: Unsupported input buffer size %d\n",
 	       dmap->buffsize);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   if (portc->input_type == ITYPE_SPDIF)
@@ -1649,7 +1649,7 @@
   int voiceL = portc->voice_chn, voiceR = portc->voice_chn + 1;
 
   if (audio_engines[dev]->flags & ADEV_NOOUTPUT)
-    return -EIO;
+    return RETERR(EIO);
 
   /* AC3 needs stereo too */
   if (portc->format == AFMT_AC3 || portc->input_type == ITYPE_SPDIF)
@@ -1724,7 +1724,7 @@
 	oss_free_dmabuf (dev, dmap);
 	dmap->dmabuf = NULL;
 
-	return -ENOSPC;
+	return RETERR(ENOSPC);
       }
 
   if (direction == PCM_ENABLE_OUTPUT)
@@ -1759,14 +1759,14 @@
 sblive_check_input (int dev)
 {
   cmn_err (CE_CONT, "SBLive: Input timeout\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 sblive_check_output (int dev)
 {
   cmn_err (CE_CONT, "SBLive: Output timeout\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -2125,7 +2125,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   while (input_avail (devc))
@@ -2171,7 +2171,7 @@
 static int
 audigyuart_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t audigy_midi_driver = {
@@ -2915,7 +2915,7 @@
     }
 
   if (ctrl < 0 || ctrl >= MAX_GPR)
-    return -EIO;
+    return RETERR(EIO);
 
   typ = MIXT_SLIDER;
   for (i = 0; i < devc->gpr->ngpr; i++)
@@ -2924,7 +2924,7 @@
 
   if (typ == MIXT_GROUP)
     {
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (cmd == SNDCTL_MIX_READ)
@@ -3027,7 +3027,7 @@
       return value;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -3037,7 +3037,7 @@
   sblive_portc *portc;
 
   if (ctrl < 0 || ctrl >= devc->n_audiodevs)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   portc = &devc->portc[ctrl];
 
@@ -3112,7 +3112,7 @@
 #endif
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -3121,7 +3121,7 @@
   sblive_devc *devc = mixer_devs[dev]->hw_devc;
 
   if (ctrl < 0 || ctrl >= devc->n_audiodevs)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -3141,7 +3141,7 @@
       return peak_cnv[l] | (peak_cnv[r] << 8);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -3179,7 +3179,7 @@
 	}
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -3299,7 +3299,7 @@
   devc->mixer_group = -1;
 
   if (devc->gpr->ngpr >= MAX_GPR_PARMS)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   for (i = 0; i < devc->gpr->ngpr; i++)
     {
@@ -3324,7 +3324,7 @@
       if (!group_created)
 	{
 	  cmn_err (CE_CONT, "SB Live: Mixer initialization sequence error\n");
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 #endif
       mode = MIXF_READABLE;
@@ -3441,7 +3441,7 @@
 	      portc = &devc->portc[i];
 
 	  if (portc == NULL)
-	    return -EIO;
+	    return RETERR(EIO);
 
 	  return portc->playvol | (portc->playvol << 8);
 	}
@@ -3459,7 +3459,7 @@
 	      portc = &devc->portc[i];
 
 	  if (portc == NULL)
-	    return -EIO;
+	    return RETERR(EIO);
 
 	  left = val & 0xff;
 	  right = (val >> 8) & 0xff;
@@ -3735,7 +3735,7 @@
 	{
 	  cmn_err (CE_CONT, "SBLive: Audio memory block exhausted (%d/%d)\n",
 		   devc->audio_memptr, AUDIO_MEMSIZE);
-	  return -ENOSPC;
+	  return RETERR(ENOSPC);
 	}
 
       if (i == 0)
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/softoss/softoss.c oss-v4.1test0-070624-src-gpl/kernel/drv/softoss/softoss.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/softoss/softoss.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/softoss/softoss.c	Tue Jun 26 22:19:41 2007
@@ -875,7 +875,7 @@
       break;
 
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
 }
@@ -1246,7 +1246,7 @@
 	  cmn_err (CE_WARN, "Fatal error in setting up the sample format\n");
 	  oss_audio_release (devc->masterdev, &devc->finfo);
 	  stop_record_engine (devc);
-	  return -ENXIO;
+	  return RETERR(ENXIO);
 	}
 
   devc->masterdev_opened = 1;
@@ -1402,13 +1402,13 @@
   if (format != GUS_PATCH)
     {
       cmn_err (CE_WARN, "Invalid patch format (key) 0x%x\n", format);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (count < sizeof_patch)
     {
       cmn_err (CE_WARN, "Patch header too short\n");
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   count -= sizeof_patch;
@@ -1416,7 +1416,7 @@
   if (devc->nrsamples >= MAX_SAMPLE)
     {
       cmn_err (CE_WARN, "Sample table full\n");
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   /*
@@ -1429,7 +1429,7 @@
   if (patch == NULL)
     {
       cmn_err (CE_WARN, "Out of memory\n");
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   uiomove ((caddr_t) & patch[offs], sizeof_patch - offs, UIO_WRITE, addr);
@@ -1438,7 +1438,7 @@
     {
       KERNEL_FREE (patch);
       cmn_err (CE_WARN, "Unsupported ROM patch\n");
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   instr = patch->instr_no;
@@ -1447,7 +1447,7 @@
     {
       cmn_err (CE_WARN, "Invalid program number %d\n", instr);
       KERNEL_FREE (patch);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (count < patch->len)
@@ -1462,7 +1462,7 @@
       cmn_err (CE_WARN, "Invalid sample length %d\n", (int) patch->len);
       cmn_err (CE_WARN, "Possibly out of memory\n");
       KERNEL_FREE (patch);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (patch->mode & WAVE_LOOPING)
@@ -1471,7 +1471,7 @@
 	{
 	  cmn_err (CE_WARN, "Invalid loop start %d\n", patch->loop_start);
 	  KERNEL_FREE (patch);
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       if (patch->loop_end < patch->loop_start || patch->loop_end > patch->len)
@@ -1479,7 +1479,7 @@
 	  cmn_err (CE_WARN, "Invalid loop start or end point (%d, %d)\n",
 		   patch->loop_start, patch->loop_end);
 	  KERNEL_FREE (patch);
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
     }
 
@@ -1502,7 +1502,7 @@
       cmn_err (CE_WARN, "Can't allocate %d bytes of mem for a sample\n",
 	       memlen);
       KERNEL_FREE (patch);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   p = 0;
@@ -1923,7 +1923,7 @@
       break;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void
@@ -1969,7 +1969,7 @@
   if (portc->open_mode != 0)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   portc->open_mode = mode;
   if (mode & OPEN_READ)
@@ -2101,7 +2101,7 @@
   if (!devc->duplex_mode)
     {
       cmn_err (CE_WARN, "Audio device %d is playback only\n", dev);
-      return -ENOTSUP;
+      return RETERR(ENOTSUP);
     }
 
   v->channels = adev->hw_parms.channels;
@@ -2131,7 +2131,7 @@
   vmix_reset_output (dev);
 
   if (dmap->dmabuf == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   /* dmap->applic_profile = APF_CPUINTENS; */
 
   v = &softoss_avoices[voice];
@@ -2210,7 +2210,7 @@
   dmap->dmabuf_phys = 0;
   dmap->dmabuf = KERNEL_MALLOC (MY_BUFFSIZE);
   if (dmap->dmabuf == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   dmap->buffsize = MY_BUFFSIZE;
 
   return 0;
@@ -2410,7 +2410,7 @@
 softoss_mixer_get (softoss_devc * devc, int audiodev, int dev)
 {
   if (!((1 << dev) & MIXER_DEVS))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   switch (dev)
     {
@@ -2440,7 +2440,7 @@
       break;
 
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
@@ -2450,7 +2450,7 @@
   int left, right, voice;
 
   if (!((1 << dev) & MIXER_DEVS))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   left = value & 0x00ff;
   right = (value >> 8) & 0x00ff;
@@ -2514,7 +2514,7 @@
       break;
 
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   return value;
@@ -2571,7 +2571,7 @@
 	  }
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 static mixer_driver_t softoss_mixer_driver = {
@@ -2629,7 +2629,7 @@
   int left, right;
 
   if (ctrl < 0 || ctrl >= softoss_devices)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -2660,7 +2660,7 @@
       return left | (right << 8);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static const unsigned char peak_cnv[256] = {
@@ -2705,7 +2705,7 @@
   avoice_info *v;
 
   if (ctrl < 0 || ctrl >= softoss_devices)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -2716,7 +2716,7 @@
       return left | (right << 8);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -2728,7 +2728,7 @@
   int left, right;
 
   if (ctrl < 0 || ctrl >= softoss_devices)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     switch (ctrl)
@@ -2753,7 +2753,7 @@
 	break;
       }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 #ifdef USE_EQ
@@ -2761,7 +2761,7 @@
 softoss_eq (int dev, int ctrl, unsigned int cmd, int value)
 {
   if (ctrl < 0 || ctrl > 5)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -2792,7 +2792,7 @@
 	value = 255;
       return devc->eq_bands[ctrl] = value;
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 #endif
 
@@ -2964,7 +2964,7 @@
   effects_info_t *efc;
 
   if ((efc = devc->effects_info) == NULL)
-    return -EIO;
+    return RETERR(EIO);
 
   if (cmd == SNDCTL_MIX_READ)
     switch (ctrl)
@@ -3002,7 +3002,7 @@
 	break;
 
       default:
-	return -EINVAL;
+	return RETERR(EINVAL);
       }
 
   if (cmd == SNDCTL_MIX_WRITE)
@@ -3096,9 +3096,9 @@
 	break;
 
       default:
-	return -EINVAL;
+	return RETERR(EINVAL);
       }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/softoss/softoss_loop.c oss-v4.1test0-070624-src-gpl/kernel/drv/softoss/softoss_loop.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/softoss/softoss_loop.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/softoss/softoss_loop.c	Tue Jun 26 22:19:41 2007
@@ -46,7 +46,7 @@
 static int
 softloop_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void softloop_trigger (int dev, int state);
@@ -112,7 +112,7 @@
   if (portc->is_opened)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->is_opened = 1;
@@ -183,7 +183,7 @@
 static int
 softloop_prepare_for_output (int dev, int bsize, int bcount)
 {
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -195,7 +195,7 @@
   dmap->dmabuf_phys = 0;	/* Not mmap() capable */
   dmap->dmabuf = KERNEL_MALLOC (MY_BUFFSIZE);
   if (dmap->dmabuf == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   dmap->buffsize = MY_BUFFSIZE;
 
   return 0;
@@ -226,7 +226,7 @@
   dmap_p dmap = audio_engines[dev]->dmap_in;
 
   if (dmap == NULL)
-    return -EIO;
+    return RETERR(EIO);
 
   if (devc->engine_state != ES_STOPPED)
     {
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/solo/solo.c oss-v4.1test0-070624-src-gpl/kernel/drv/solo/solo.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/solo/solo.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/solo/solo.c	Tue Jun 26 22:19:42 2007
@@ -323,17 +323,17 @@
 #endif
 
   if (dev > 31)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (!(SOLO_MIXER_DEVICES & (1 << dev)))	/*
 						 * Not supported
 						 */
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   regoffs = solo_mix[dev][LEFT_CHN].regno;
 
   if (regoffs == 0)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   val = solo_getmixer (devc, regoffs);
   change_bits (devc, &val, dev, LEFT_CHN, left);
@@ -377,7 +377,7 @@
     {
       val = *arg;
       if (val != 0 && val != 1)
-	return (-EINVAL);
+	return (RETERR(EINVAL));
 
       if (val)
 	{
@@ -438,7 +438,7 @@
 	  }
     }
   else
-    return -EINVAL;
+    return RETERR(EINVAL);
 }
 
 static void
@@ -614,7 +614,7 @@
 static int
 solo_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void solo_audio_trigger (int dev, int state);
@@ -650,7 +650,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   portc->open_mode = mode;
   portc->audio_enabled = ~mode;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/trident/trident.c oss-v4.1test0-070624-src-gpl/kernel/drv/trident/trident.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/trident/trident.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/trident/trident.c	Tue Jun 26 22:19:42 2007
@@ -465,7 +465,7 @@
 static int
 trident_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void trident_audio_trigger (int dev, int state);
@@ -501,7 +501,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   portc->open_mode = mode;
   portc->audio_enabled = ~mode;
@@ -1022,14 +1022,14 @@
 trident_check_output (int dev)
 {
   cmn_err (CE_WARN, "Trident: Output Timed Out\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 trident_check_input (int dev)
 {
   cmn_err (CE_WARN, "Trident: Input Timed Out\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -1101,7 +1101,7 @@
       cmn_err (CE_WARN, "Trident: Got DMA buffer address beyond 2G limit.\n");
       oss_free_dmabuf (dev, dmap);
       dmap->dmabuf = NULL;
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
   return 0;
 }
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/via8233/via8233.c oss-v4.1test0-070624-src-gpl/kernel/drv/via8233/via8233.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/via8233/via8233.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/via8233/via8233.c	Tue Jun 26 22:19:42 2007
@@ -232,7 +232,7 @@
 static int
 via8233_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void via8233_audio_trigger (int dev, int state);
@@ -268,13 +268,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -424,7 +424,7 @@
   if (portc->rec_engine == NULL)
     {
       cmn_err (CE_WARN, "via8233: No rec engine (dev=%d)\n", dev);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
@@ -605,14 +605,14 @@
   if (portc->rec_engine == NULL)
     {
       cmn_err (CE_NOTE, "Input timed out\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   ptr = INL (devc->osdev, portc->rec_engine->base + 0x0c);
   if (ptr != 0)
     return 0;
   cmn_err (CE_NOTE, "Input timed out (%08x)\n", ptr);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -625,14 +625,14 @@
   if (portc->play_engine == NULL)
     {
       cmn_err (CE_NOTE, "Output timed out\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   ptr = INL (devc->osdev, portc->play_engine->base + 0x0c);
   if (ptr != 0)
     return 0;
   cmn_err (CE_NOTE, "Output timed out (%08x)\n", ptr);
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -816,7 +816,7 @@
 	  if (eng->sgd == NULL)
 	    {
 	      cmn_err (CE_WARN, "via8233: can't allocate SGD table\n");
-	      return -ENOSPC;
+	      return RETERR(ENOSPC);
 	    }
 	  eng->sgd_phys = phaddr;
 	}
@@ -837,7 +837,7 @@
   if (via8233_alloc_engines (devc) < 0)
     {
       cmn_err (CE_WARN, "Unable to allocate engines\n");
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   /*
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/via97/via97.c oss-v4.1test0-070624-src-gpl/kernel/drv/via97/via97.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/via97/via97.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/via97/via97.c	Tue Jun 26 22:19:42 2007
@@ -267,7 +267,7 @@
 static int
 via97_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void via97_audio_trigger (int dev, int state);
@@ -303,13 +303,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -423,7 +423,7 @@
   oss_native_word flags;
 
   if (audio_engines[dev]->dmap_out->dmabuf_phys == 0)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
   tmp = 0x81;			/* Auto start at EOL, interrupt on FLAG */
@@ -442,7 +442,7 @@
       if (sgd_ptr >= SGD_TOTAL_SIZE)
 	{
 	  cmn_err (CE_WARN, "VIA97: Out of Record SGD entries\n");
-	  return -ENOSPC;
+	  return RETERR(ENOSPC);
 	}
 
       devc->SGD_table[sgd_ptr].phaddr =
@@ -473,7 +473,7 @@
   oss_native_word flags;
 
   if (audio_engines[dev]->dmap_out->dmabuf_phys == 0)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
   tmp = 0x81;			/* Auto start at EOL, interrupt on FLAG */
@@ -493,7 +493,7 @@
       if (sgd_ptr >= SGD_TOTAL_SIZE)
 	{
 	  cmn_err (CE_WARN, "VIA97: Out of Playback SGD entries\n");
-	  return -ENOSPC;
+	  return RETERR(ENOSPC);
 	}
 
       devc->SGD_table[sgd_ptr].phaddr =
@@ -689,7 +689,7 @@
 	CONTIG_MALLOC (devc->osdev, SGD_ALLOC, MEMLIMIT_32BITS, &phaddr);
 
       if (devc->SGD_table == NULL)
-	return -ENOSPC;
+	return RETERR(ENOSPC);
       devc->SGD_table_phys = phaddr;
     }
 
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/vmix/.config oss-v4.1test0-070624-src-gpl/kernel/drv/vmix/.config
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/vmix/.config	Mon Nov 27 13:38:15 2006
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/vmix/.config	Tue Jun 26 22:19:42 2007
@@ -1,3 +1,4 @@
 bus=VIRTUAL
 cflags=-O
 platform=i86pc
+forgetos=BeOS
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/vmix/vmix.c oss-v4.1test0-070624-src-gpl/kernel/drv/vmix/vmix.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/vmix/vmix.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/vmix/vmix.c	Tue Jun 26 22:19:42 2007
@@ -65,7 +65,7 @@
   int vol;
 
   if (mixer == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -90,7 +90,7 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
     }
 
@@ -114,11 +114,11 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -128,7 +128,7 @@
   int vol;
 
   if (mixer == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -149,7 +149,7 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
     }
 
@@ -168,11 +168,11 @@
 	  break;
 
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -183,10 +183,10 @@
   int vol, rvol;
 
   if (mixer == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (ctrl < 0 || ctrl >= mixer->num_clientdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   portc = mixer->client_portc[ctrl];
 
@@ -209,7 +209,7 @@
       return vol | (vol << 16);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -220,13 +220,13 @@
   int val;
 
   if (mixer == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cmd != SNDCTL_MIX_READ)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (ctrl < 0 || ctrl >= mixer->num_clientdevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   portc = mixer->client_portc[ctrl];
 
@@ -465,9 +465,9 @@
     case SNDCTL_DSP_SET_PLAYTGT:
       val = (*arg) * 2;
       if (val < 0)
-	return -EIO;
+	return RETERR(EIO);
       if (val >= mixer->play_engine.channels)
-	return -EIO;
+	return RETERR(EIO);
       portc->play_choffs = val;
       return *arg = val / 2;
       break;
@@ -523,9 +523,9 @@
     case SNDCTL_DSP_SET_RECSRC:
       val = (*arg) * 2;
       if (val < 0)
-	return -EIO;
+	return RETERR(EIO);
       if (val >= mixer->record_engine.channels)
-	return -EIO;
+	return RETERR(EIO);
       portc->rec_choffs = val;
       return *arg = val / 2;
       break;
@@ -537,7 +537,7 @@
 	char *names = NULL;
 
 	if (mixer->inputdev == -1)
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	names = audio_engines[mixer->inputdev]->inch_names;
 
 	memset (ei, 0, sizeof (*ei));
@@ -576,7 +576,7 @@
       }
       break;
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void
@@ -768,14 +768,14 @@
   int start = 0;
 
   if (mode & portc->disabled_modes)
-    return -EACCES;
+    return RETERR(EACCES);
 
   MUTEX_ENTER_IRQDISABLE (mixer->mutex, flags);
 
   if (portc->open_mode != 0)
     {
       MUTEX_EXIT_IRQRESTORE (mixer->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -1040,7 +1040,7 @@
   dmap->dmabuf_phys = 0;
   dmap->dmabuf = KERNEL_MALLOC (MY_BUFFSIZE);
   if (dmap->dmabuf == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   dmap->buffsize = MY_BUFFSIZE;
 #endif
 
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/vortex/vortex.c oss-v4.1test0-070624-src-gpl/kernel/drv/vortex/vortex.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/vortex/vortex.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/vortex/vortex.c	Tue Jun 26 22:19:43 2007
@@ -733,7 +733,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->midi_input_intr = inputbyte;
@@ -781,7 +781,7 @@
 static int
 vortex_midi_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t vortex_midi_driver = {
@@ -883,7 +883,7 @@
     }
 
 #endif
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 #ifdef USE_SRC
@@ -929,13 +929,13 @@
   if (portc->open_mode != 0)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -1390,7 +1390,7 @@
       cmn_err (CE_WARN,
 	       "Aureal Vortex: Allocated DMA buffer smaller than 8k\n");
       vortex_free_buffer (dev, dmap, direction);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 #endif
 
@@ -1401,14 +1401,14 @@
 vortex_check_output (int dev)
 {
   cmn_err (CE_WARN, "Vortex: Input timed out\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 vortex_check_input (int dev)
 {
   cmn_err (CE_WARN, "Vortex: Input timed out\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/vortex/vortex2.c oss-v4.1test0-070624-src-gpl/kernel/drv/vortex/vortex2.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/vortex/vortex2.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/vortex/vortex2.c	Tue Jun 26 22:19:43 2007
@@ -856,7 +856,7 @@
 
   if (devc->midi_opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->midi_input_intr = inputbyte;
@@ -904,7 +904,7 @@
 static int
 vortex2_midi_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t vortex2_midi_driver = {
@@ -1140,7 +1140,7 @@
     }
 
 #endif
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void vortex2_trigger (int dev, int state);
@@ -1189,13 +1189,13 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (devc->open_mode & mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   devc->open_mode |= mode;
@@ -1529,14 +1529,14 @@
 {
   cmn_err (CE_WARN, "Vortex2: Output timed out\n");
 
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
 vortex2_check_input (int dev)
 {
   cmn_err (CE_WARN, "Vortex2: Input timed out\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/drv/ymf7xx/ymf7xx.c oss-v4.1test0-070624-src-gpl/kernel/drv/ymf7xx/ymf7xx.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/drv/ymf7xx/ymf7xx.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/drv/ymf7xx/ymf7xx.c	Tue Jun 26 22:19:43 2007
@@ -293,7 +293,7 @@
 static int
 ymf7xx_audio_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void ymf7xx_audio_trigger (int dev, int state);
@@ -329,7 +329,7 @@
   if (portc->open_mode)
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/ac97/ac97.c oss-v4.1test0-070624-src-gpl/kernel/framework/ac97/ac97.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/ac97/ac97.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/ac97/ac97.c	Tue Jun 26 22:19:43 2007
@@ -147,9 +147,9 @@
 ac97_mixer_get (ac97_devc * devc, int dev)
 {
   if (dev < 0 || dev >= SOUND_MIXER_NRDEVICES)
-    return -EINVAL;
+    return RETERR(EINVAL);
   if (!((1 << dev) & devc->devmask))
-    return -EINVAL;
+    return RETERR(EINVAL);
   return devc->levels[dev];
 }
 
@@ -187,9 +187,9 @@
   int left, right, lvl;
 
   if (dev < 0 || dev >= SOUND_MIXER_NRDEVICES)
-    return -EINVAL;
+    return RETERR(EINVAL);
   if (!((1 << dev) & devc->devmask))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (!((1 << dev) & STEREO_DEVS))
     {
@@ -299,7 +299,7 @@
       break;
 #endif
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   return devc->levels[dev] = value;
@@ -401,13 +401,13 @@
   int ret, ctrl;
 
   if (!devc->is_ok)
-    return -EIO;
+    return RETERR(EIO);
 
   ctrl = cmd & 0xff;
 
   if (ctrl < 0 || ctrl >= SOUND_MIXER_NRDEVICES
       || devc->overrides[ctrl] == NULL)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   ret = devc->overrides[ctrl] (devc->mixer_dev, audiodev, cmd, val);
   if (ret < 0)
@@ -469,7 +469,7 @@
 
 	value = *arg;
 	if (value != 0 && value != 1)
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	tmp = codec_read (devc, 0x0e);
 
@@ -500,7 +500,7 @@
 
 	  default:
 	    if ((cmd & 0xff) > SOUND_MIXER_NRDEVICES)
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 	    val = *arg;
 	    ctrl = cmd & 0xff;
 	    if (ctrl >= 0 && ctrl < SOUND_MIXER_NRDEVICES)
@@ -550,7 +550,7 @@
     }
   else
     {
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/ac97/ac97_ext.inc oss-v4.1test0-070624-src-gpl/kernel/framework/ac97/ac97_ext.inc
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/ac97/ac97_ext.inc	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/ac97/ac97_ext.inc	Tue Jun 26 22:19:43 2007
@@ -1178,7 +1178,7 @@
   ac97_devc *devc = mixer_devs[dev]->devc;
 
   if (ctrl < 0 || ctrl > 1)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   tmp = codec_read (devc, 0x1a);
 
@@ -1190,7 +1190,7 @@
   if (cmd == SNDCTL_MIX_WRITE)
     {
       if (value < 0 || value > 7)
-	return -EINVAL;
+	return RETERR(EINVAL);
 
       tmp &= ~(0x7 << (ctrl * 8));
       tmp |= (value << (ctrl * 8));
@@ -1198,7 +1198,7 @@
       return value;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/audio/audio.c oss-v4.1test0-070624-src-gpl/kernel/framework/audio/audio.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/audio/audio.c	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/audio/audio.c	Wed Jun 27 00:41:02 2007
@@ -269,11 +269,11 @@
   sync_seed++;
 
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   adev = audio_engines[dev];
   if (!adev->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (fmt == 0)
     return adev->user_parms.fmt;
@@ -443,11 +443,11 @@
   sync_seed++;
 
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   adev = audio_engines[dev];
   if (!adev->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (ch == 0)
     return adev->user_parms.channels;
@@ -459,7 +459,7 @@
       cmn_err (CE_WARN,
 	       "Audio engine %d: Internal error in channel setup, err=%d, ch=%d\n",
 	       dev, ret, ch);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (ch > 2 && ch > ret)	/* Requested multi channel mode not possible */
@@ -517,11 +517,11 @@
   sync_seed++;
 
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   adev = audio_engines[dev];
   if (!adev->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (rate == 0)
     return adev->user_parms.rate;
@@ -594,7 +594,7 @@
   if (adev == NULL)
     {
       cmn_err (CE_WARN, "oss_alloc_dmabuf: adev==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return __oss_alloc_dmabuf (dev, dmap, adev->dmabuf_alloc_flags,
@@ -639,7 +639,7 @@
   if (dmap->osdev == NULL)
     {
       cmn_err (CE_WARN, "dmap->osdev==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (dmap->dmabuf == NULL)
@@ -1325,18 +1325,18 @@
 #endif
 
   if (dev < 0 || dev >= num_audio_engines || audio_engines == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   adev = audio_engines[dev];
   if (adev->unloaded)
-    return -ENODEV;
+    return RETERR(ENODEV);
   if (!adev->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (adev->osdev == NULL)
     {
       cmn_err (CE_WARN, "adev->osdev==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   open_flags = get_open_flags (mode, open_flags, file);
@@ -1347,7 +1347,7 @@
     {
       MUTEX_EXIT_IRQRESTORE (adev->mutex, flags);
       oss_unreserve_device (adev->osdev);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   adev->open_mode = mode;
   MUTEX_EXIT_IRQRESTORE (adev->mutex, flags);
@@ -1609,7 +1609,7 @@
 
   if (dev < 0 || dev >= num_audio_devfiles)
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
   adev = audio_devfiles[dev];
 
@@ -1663,10 +1663,10 @@
     {
       DDB (cmn_err (CE_CONT, "Trying engine=%d\n", adev->engine_num));
       if (!adev->enabled)
-	return -EAGAIN;
+	return RETERR(EAGAIN);
 
       if (adev->unloaded)
-	return -EAGAIN;
+	return RETERR(EAGAIN);
 
       *newdev = adev->engine_num;
       if ((err =
@@ -1677,7 +1677,7 @@
 	   * Check if the device was busy and if it has a
 	   * shadow device.
 	   */
-	  if (err != -EBUSY || adev->next_out == NULL)
+	  if (err != RETERR(EBUSY) || adev->next_out == NULL)
 	    return err;
 	  adev = adev->next_out;
 	}
@@ -1689,7 +1689,7 @@
 	}
     }
 
-  return -EBUSY;
+  return RETERR(EBUSY);
 
 done:
 /*
@@ -2254,7 +2254,7 @@
 #ifdef DO_TIMINGS
       oss_do_timing ("GETOSPACE: Bad access mode - return EACCES");
 #endif
-      return -EACCES;
+      return RETERR(EACCES);
     }
 
   if (dmap->mapping_flags & DMA_MAP_MAPPED)
@@ -2274,7 +2274,7 @@
        * Applications that use mmap can call SNDCTL_DSP_GETOSPACE before calling
        * mmap to get the actual buffer size.
        */
-      return -EPERM;
+      return RETERR(EPERM);
     }
 
   if (!(dmap->flags & DMAP_STARTED))
@@ -2381,7 +2381,7 @@
       MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
       cmn_err (CE_WARN,
 	       "SNDCTL_DSP_GETISPACE cannot be called in write-only mode.\n");
-      return -EACCES;
+      return RETERR(EACCES);
     }
 
   if (dmap->mapping_flags & DMA_MAP_MAPPED)
@@ -2398,7 +2398,7 @@
        * Applications that use mmap can call SNDCTL_DSP_GETISPACE before calling
        * mmap to get the actual buffer size.
        */
-      return -EPERM;
+      return RETERR(EPERM);
     }
 
   if (!(dmap->flags & DMAP_STARTED))
@@ -2524,7 +2524,7 @@
 
   if (adev->sync_group != 0)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   if (group->id == 0)
@@ -2532,7 +2532,7 @@
       if (adev->engine_num > 0xff)
 	{
 	  cmn_err (CE_WARN, "Bad device number %d\n", adev->engine_num);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       id = xrand (sync_seed) & ~0xff;
@@ -2551,7 +2551,7 @@
   if (sync_dev < 0 || sync_dev >= num_audio_engines)
     {
       group->id = 0;
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   sync_adev = audio_engines[sync_dev];
@@ -2562,12 +2562,12 @@
     {
       if (!(sync_adev->sync_flags & SYNC_MASTER))
 	{
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       if (sync_adev->sync_group != id)
 	{
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       adev->sync_flags |= SYNC_SLAVE;
@@ -2578,7 +2578,7 @@
   if (group->mode == 0)
     {
       adev->sync_flags = 0;
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   adev->sync_mode = group->mode;
@@ -2603,12 +2603,12 @@
 
   master_dev = group & 0xff;
   if (master_dev < 0 || master_dev >= num_audio_engines)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   adev = audio_engines[master_dev];
 
   if (adev->sync_group != group)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   while (adev != NULL)
     {
@@ -2966,13 +2966,13 @@
   sync_seed++;
 
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   adev = audio_engines[dev];
   if (adev->unloaded)
-    return -ENODEV;
+    return RETERR(ENODEV);
   if (!adev->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
   dmapout = adev->dmap_out;
   dmapin = adev->dmap_in;
 
@@ -2983,7 +2983,7 @@
   if ((mixdev = adev->mixer_dev) != -1)
     {
       if (((cmd >> 8) & 0xff) == 'M' && num_mixers > 0)	/* Mixer ioctl */
-	if ((ret = oss_legacy_mixer_ioctl (mixdev, dev, cmd, arg)) != -EINVAL)
+	if ((ret = oss_legacy_mixer_ioctl (mixdev, dev, cmd, arg)) != RETERR(EINVAL))
 	  return ret;
 
       if (((cmd >> 8) & 0xff) == 'X')	/* Mixer extension API */
@@ -3076,7 +3076,7 @@
 				       "GETOSPACE called in read-only mode"),
 			       0);
 	  /* Errordesc: SNDCTL_DSP_GETOSPACE is not defined in read-only access mode */
-	  return -ENOTSUP;
+	  return RETERR(ENOTSUP);
 	}
       ret = get_ospace (adev, dmapout, arg);
 #ifdef DO_TIMINGS
@@ -3106,7 +3106,7 @@
 	   * Errordesc: SNDCTL_DSP_GETISPACE has no defined meaning when the audio
 	   * device is opened in write-only mode.
 	   */
-	  return -ENOTSUP;
+	  return RETERR(ENOTSUP);
 	}
 
       return get_ispace (adev, dmapin, arg);
@@ -3119,7 +3119,7 @@
 			       OSSERR (1005,
 				       "GETODELAY called in read-only mode"),
 			       0);
-	  return -ENOTSUP;
+	  return RETERR(ENOTSUP);
 	}
       return get_odelay (adev, dmapout, arg);
       break;
@@ -3131,19 +3131,19 @@
 			       OSSERR (1006,
 				       "SETDUPLEX called in non-read/write mode"),
 			       0);
-	  return -ENOTSUP;
+	  return RETERR(ENOTSUP);
 	}
       if (adev->flags & ADEV_DUPLEX)
 	{
 	  val = adev->d->ioctl (dev, cmd, arg);
-	  if (val == -EINVAL)
+	  if (val == RETERR(EINVAL))
 	    return 0;
 	  else
 	    return val;
 	}
       else
 	{
-	  return -ENOTSUP;
+	  return RETERR(ENOTSUP);
 	}
       break;
 
@@ -3232,7 +3232,7 @@
     case SNDCTL_DSP_GETCHANNELMASK:
     case SNDCTL_DSP_BIND_CHANNEL:
       if (adev->d->bind == NULL)
-	return -EINVAL;
+	return RETERR(EINVAL);
       return adev->d->bind (adev->engine_num, cmd, arg);
       break;
 
@@ -3244,7 +3244,7 @@
 	  {
 	    cmn_err (CE_NOTE, "Device %d doesn't have trigger capability\n",
 		     adev->engine_num);
-	    return -EIO;
+	    return RETERR(EIO);
 	  }
 
 	val = *arg;
@@ -3299,7 +3299,7 @@
 	{
 	  cmn_err (CE_NOTE, "Device %d doesn't have trigger capability\n",
 		   adev->engine_num);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
       return *arg = (adev->enable_bits & adev->open_mode);
       break;
@@ -3361,12 +3361,12 @@
 	    && mixdev < num_mixers)
 	  mixer_devs[mixdev]->modify_counter++;
 
-	if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)
+	if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))
 	  {
 	    /* Emulate these calls using mixer API */
 
 	    if (mixdev < 0 || mixdev >= num_mixers)
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 
 	    if (cmd == SNDCTL_DSP_GETPLAYVOL)
 	      cmd = SOUND_MIXER_READ_PCM;
@@ -3387,12 +3387,12 @@
 	if (cmd == SNDCTL_DSP_SETRECVOL && mixdev >= 0 && mixdev < num_mixers)
 	  mixer_devs[mixdev]->modify_counter++;
 
-	if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)
+	if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))
 	  {
 	    /* Emulate these calls using mixer API */
 
 	    if (mixdev < 0 || mixdev >= num_mixers)
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 
 	    /* Try with RECGAIN */
 	    if (cmd == SNDCTL_DSP_GETRECVOL)
@@ -3429,7 +3429,7 @@
 			       OSSERR (1007,
 				       "GETOPTR called in read-only mode"),
 			       0);
-	  return -ENOTSUP;
+	  return RETERR(ENOTSUP);
 	}
       return get_optr (adev, dmapout, arg);
       break;
@@ -3441,7 +3441,7 @@
 			       OSSERR (1008,
 				       "GETIPTR called in write-only mode"),
 			       0);
-	  return -ENOTSUP;
+	  return RETERR(ENOTSUP);
 	}
       return get_iptr (adev, dmapin, arg);
       break;
@@ -3449,13 +3449,13 @@
 #ifndef OSS_NO_LONG_LONG
     case SNDCTL_DSP_CURRENT_OPTR:
       if (!(adev->dmask & DMASK_OUT))
-	return -ENOTSUP;
+	return RETERR(ENOTSUP);
       return get_long_optr (adev, dmapout, arg);
       break;
 
     case SNDCTL_DSP_CURRENT_IPTR:
       if (!(adev->dmask & DMASK_IN))
-	return -ENOTSUP;
+	return RETERR(ENOTSUP);
       return get_long_iptr (adev, dmapin, arg);
       break;
 #endif
@@ -3463,7 +3463,7 @@
     case SNDCTL_DSP_POLICY:
       val = *arg;
       if (val < 0 || val > 10)
-	return -EIO;
+	return RETERR(EIO);
       adev->policy = val;
       return 0;
       break;
@@ -3518,11 +3518,11 @@
 	     * supports only mono (0) or stereo (1). For larger number of channels
 	     * you need to use SNDCTL_DSP_CHANNELS instead.
 	     */
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
 
 	if (n < 0)
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	v = oss_audio_set_channels (dev, n + 1);
 	return *arg = (v - 1);
@@ -3558,7 +3558,7 @@
       break;
 
     case SNDCTL_DSP_GET_RECSRC_NAMES:
-      if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)	/* Not handled */
+      if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))	/* Not handled */
 	{
 	  oss_mixer_enuminfo *ei = (oss_mixer_enuminfo *) arg;
 
@@ -3574,7 +3574,7 @@
       break;
 
     case SNDCTL_DSP_GET_RECSRC:
-      if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)	/* Not handled */
+      if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))	/* Not handled */
 	{
 	  return *arg = (get_legacy_recsrc (dev));
 	}
@@ -3582,7 +3582,7 @@
       break;
 
     case SNDCTL_DSP_SET_RECSRC:
-      if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)	/* Not handled */
+      if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))	/* Not handled */
 	{
 	  val = *arg;
 	  set_legacy_recsrc (dev, val);
@@ -3592,7 +3592,7 @@
       break;
 
     case SNDCTL_DSP_GET_PLAYTGT_NAMES:
-      if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)	/* Not handled */
+      if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))	/* Not handled */
 	{
 	  oss_mixer_enuminfo *ei = (oss_mixer_enuminfo *) arg;
 	  memset (ei, 0, sizeof (*ei));
@@ -3604,7 +3604,7 @@
       break;
 
     case SNDCTL_DSP_GET_PLAYTGT:
-      if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)	/* Not handled */
+      if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))	/* Not handled */
 	{
 	  return *arg = (0);
 	}
@@ -3612,7 +3612,7 @@
       break;
 
     case SNDCTL_DSP_SET_PLAYTGT:
-      if ((err = adev->d->ioctl (dev, cmd, arg)) == -EINVAL)	/* Not handled */
+      if ((err = adev->d->ioctl (dev, cmd, arg)) == RETERR(EINVAL))	/* Not handled */
 	{
 	  return *arg = (0);
 	}
@@ -3642,7 +3642,7 @@
     default:
       return adev->d->ioctl (dev, cmd, arg);
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 
@@ -3933,7 +3933,7 @@
   if (!(dmap->flags & DMAP_PREPARED))
     {
       cmn_err (CE_WARN, "launch_input while not prepared.\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
 #ifdef DO_TIMINGS
@@ -3989,7 +3989,7 @@
 #ifdef DO_TIMINGS
 	  oss_do_timing ("*** EAGAIN ***");
 #endif
-	  return -EAGAIN;
+	  return RETERR(EAGAIN);
 	}
 
       if (n++ > 100)
@@ -3998,7 +3998,7 @@
 		   adev->engine_num);
 	  cmn_err (CE_CONT, "Counters %d / %d\n", count, lim);
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       tmout = (dmap->fragment_size * OSS_HZ) / dmap->data_rate;
@@ -4030,7 +4030,7 @@
 		   "Input timed out on audio engine %d (count=%lld)\n",
 		   adev->engine_num, dmap->byte_counter);
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}			/* Timed out */
 
 #ifdef DO_TIMINGS
@@ -4041,7 +4041,7 @@
       if (status & WK_SIGNAL)
 	{
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
-	  return -EINTR;
+	  return RETERR(EINTR);
 	}
       count = (int) (dmap->byte_counter - dmap->user_counter);
 #ifdef DO_TIMINGS
@@ -4170,7 +4170,7 @@
     }
 
   cmn_err (CE_NOTE, "oss: Why here?\n");
-  return -EIO;
+  return RETERR(EIO);
 }
 
 int
@@ -4191,17 +4191,17 @@
   sync_seed++;
 
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   adev = audio_engines[dev];
   if (!adev->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
   if (adev->flags & ADEV_NOINPUT)
-    return -EACCES;
+    return RETERR(EACCES);
   dmap = adev->dmap_in;
 
   if (!(adev->open_mode & OPEN_READ))
-    return -ENOTSUP;
+    return RETERR(ENOTSUP);
   if (dmap->dma_mode == PCM_ENABLE_OUTPUT)
     {
       audio_reset_output (adev);
@@ -4240,7 +4240,7 @@
   if (!(dmap->flags & DMAP_PREPARED))
     {				/* Not prepared. Why??? */
       cmn_err (CE_WARN, "Intenal error (not prepared)\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   c = count;
@@ -4251,16 +4251,16 @@
     {
       if ((l = find_input_space (adev, dmap, &dmabuf)) < 0)
 	{
-	  if (l == -EINTR)
+	  if (l == RETERR(EINTR))
 	    {
 	      if (c == count)	/* Nothing read yet */
-		return -EINTR;
+		return RETERR(EINTR);
 	      return count - c;
 	    }
-	  if (l == -EAGAIN)
+	  if (l == RETERR(EAGAIN))
 	    {
 	      if (c == count)	/* Nothing read yet */
-		return -EAGAIN;
+		return RETERR(EAGAIN);
 	      return count - c;
 	    }
 	  return l;
@@ -4272,7 +4272,7 @@
       if (uiomove (dmabuf, l, UIO_READ, buf) != 0)
 	{
 	  cmn_err (CE_WARN, "audio: uiomove(UIO_READ) failed\n");
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 	}
       if ((ret = move_rdpointer (adev, dmap, l)) < 0)
 	{
@@ -4352,7 +4352,7 @@
   if (dmap == NULL)
     {
       cmn_err (CE_WARN, "Internal error - dmap==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   MUTEX_ENTER_IRQDISABLE (dmap->mutex, flags);
@@ -4365,7 +4365,7 @@
 	{
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
 	  cmn_err (CE_WARN, "Internal timeout error B\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       if (adev->nonblock || !(adev->enable_bits & PCM_ENABLE_OUTPUT))
@@ -4396,7 +4396,7 @@
 	   * One possible error causing this is that the application has
 	   * triggered only recording on a duplex device.
 	   */
-	  return -EAGAIN;
+	  return RETERR(EAGAIN);
 	}
       if (n++ > dmap->nfrags * 2)
 	{
@@ -4410,7 +4410,7 @@
 #endif
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
 	  audio_reset_output (adev);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       tmout = (dmap->fragment_size * OSS_HZ) / dmap->data_rate;
@@ -4423,7 +4423,7 @@
       if (adev->go == 0)
 	{
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
-	  return -EAGAIN;
+	  return RETERR(EAGAIN);
 	}
 #ifdef DO_TIMINGS
       {
@@ -4460,7 +4460,7 @@
 		       adev->engine_num, adev->name, dmap->byte_counter);
 	    }
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}			/* Timed out */
       DOWN_STATUS (STS_SLEEP);
 
@@ -4479,7 +4479,7 @@
 	  oss_do_timing ("Signal caught");
 #endif
 	  MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
-	  return -EINTR;
+	  return RETERR(EINTR);
 	}
 
       len = audio_space_in_queue (adev, dmap, count);
@@ -4517,7 +4517,7 @@
   if (offs < 0 || (offs + len) > dmap->bytes_in_use)
     {
       cmn_err (CE_WARN, "Bad audio output buffer %d/%d\n", offs, len);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return offs;
@@ -4545,7 +4545,7 @@
   if (!(dmap->flags & DMAP_PREPARED))
     {
       cmn_err (CE_WARN, "launch_output while not prepared.\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
 #ifdef DO_TIMINGS
@@ -4597,7 +4597,7 @@
       cmn_err (CE_WARN, "Buffer overflow %lld+%d, %lld\n", dmap->user_counter,
 	       len, dmap->byte_counter);
       MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   dmap->user_counter += len;
@@ -4669,11 +4669,11 @@
 
       if ((offs = find_output_space (adev, dmap, &spc, l)) < 0)
 	{
-	  if (offs == -EAGAIN)
+	  if (offs == RETERR(EAGAIN))
 	    {
 	      store_tmp_data (adev, dmap, buf + p, count);
 	      launch_output (adev, dmap);
-	      return -EAGAIN;
+	      return RETERR(EAGAIN);
 	    }
 	  return offs;
 	}
@@ -4714,17 +4714,17 @@
   sync_seed++;
 
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   adev = audio_engines[dev];
   if (!adev->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
   if (adev->flags & ADEV_NOOUTPUT)
-    return -EACCES;
+    return RETERR(EACCES);
   dmap = adev->dmap_out;
 
   if (!(adev->open_mode & OPEN_WRITE))
-    return -ENOTSUP;
+    return RETERR(ENOTSUP);
 
   UP_STATUS (STS_WRITE);
 
@@ -4771,7 +4771,7 @@
       MUTEX_EXIT_IRQRESTORE (dmap->mutex, flags);
       DOWN_STATUS (STS_WRITE);
       cmn_err (CE_WARN, "Internal error (not prepared)\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 #if 1
   if (dmap->leftover_bytes > 0)
@@ -4822,7 +4822,7 @@
       if (tmout++ > 1000)
 	{
 	  cmn_err (CE_WARN, "Internal timeout error A (%d/%d)\n", c, count);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       l = c;
@@ -4831,19 +4831,19 @@
 
       if ((offs = find_output_space (adev, dmap, &spc, l)) < 0)
 	{
-	  if (offs == -EINTR)
+	  if (offs == RETERR(EINTR))
 	    {
 	      DOWN_STATUS (STS_WRITE);
 	      if (c == count)	/* Nothing written yet */
-		return -EINTR;
+		return RETERR(EINTR);
 	      return count - c;
 	    }
-	  if (offs == -EAGAIN)
+	  if (offs == RETERR(EAGAIN))
 	    {
 	      DOWN_STATUS (STS_WRITE);
 	      if (c == count)	/* Nothing written yet */
 		{
-		  return -EAGAIN;
+		  return RETERR(EAGAIN);
 		}
 	      return count - c;
 	    }
@@ -4874,7 +4874,7 @@
 		  cmn_err (CE_WARN,
 			   "audio: uiomove(UIO_WRITE) failed (noconv)\n");
 		  DOWN_STATUS (STS_WRITE);
-		  return -EFAULT;
+		  return RETERR(EFAULT);
 		}
 	      if ((err =
 		   dmap->device_write (adev, dmap, tmpbuf,
@@ -4898,7 +4898,7 @@
 		{
 		  cmn_err (CE_WARN,
 			   "audio: uiomove(UIO_WRITE) (noconv2) failed\n");
-		  return -EFAULT;
+		  return RETERR(EFAULT);
 		}
 	      if ((err = move_wrpointer (adev, dmap, l)) < 0)
 		{
@@ -4957,7 +4957,7 @@
 
 	  if ((err = write_copy (adev, dmap, p1, l2)) < 0)
 	    {
-	      if (err != -EAGAIN)
+	      if (err != RETERR(EAGAIN))
 		{
 		  DOWN_STATUS (STS_WRITE);
 		  return err;
@@ -4967,7 +4967,7 @@
 	      if (c == count)	/* Nothing written yet */
 		{
 		  DOWN_STATUS (STS_WRITE);
-		  return -EAGAIN;
+		  return RETERR(EAGAIN);
 		}
 
 	      DOWN_STATUS (STS_WRITE);
@@ -5044,7 +5044,7 @@
   if (audio_devfiles == NULL)
     {
       cmn_err (CE_NOTE, "No audio device files available\n");
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
   oss_combine_write_lists ();
 
@@ -5162,7 +5162,7 @@
 
   DDB (cmn_err (CE_CONT, " - got vdsp -> %d\n", dev));
   if (dev == -1)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
 done:
 /*
@@ -5277,6 +5277,17 @@
       adev->dmap_in->dmabuf = NULL;
     }
 
+  if (adev->in_wq)
+    {
+      oss_remove_wait_queue (adev->in_wq);
+      adev->in_wq = NULL;
+    }
+  if (adev->out_wq)
+    {
+      oss_remove_wait_queue (adev->out_wq);
+      adev->out_wq = NULL;
+    }
+
   MUTEX_CLEANUP (adev->mutex);
 
   MUTEX_CLEANUP (adev->dmap_out->mutex);
@@ -5592,7 +5603,7 @@
 #endif
 
   if (dev < 0 || dev >= num_audio_engines)
-    return -ENXIO;
+    return RETERR(ENXIO);
   adev = audio_engines[dev];
 
   if ((events & (POLLOUT | POLLWRNORM)) && (adev->open_mode & OPEN_WRITE))
@@ -5612,7 +5623,7 @@
 	   * The select() and poll() system calls are not defined for OSS devices
 	   * when the device is in mmap mode.
 	   */
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       if (dmap->dma_mode == PCM_ENABLE_INPUT)
@@ -5669,7 +5680,7 @@
 	   * The select() and poll() system calls are not defined for OSS devices
 	   * when the device is in mmap mode.
 	   */
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       if (dmap->dma_mode != PCM_ENABLE_INPUT)
@@ -5974,7 +5985,7 @@
   if (vers != OSS_AUDIO_DRIVER_VERSION)
     {
       cmn_err (CE_WARN, "Incompatible audio driver for %s\n", name);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (driver_size > sizeof (audiodrv_t))
@@ -6007,7 +6018,7 @@
       if (num_audio_engines >= MAX_PCM_DEV)
 	{
 	  cmn_err (CE_NOTE, "Too many audio engines\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
       d = PMALLOC (osdev, sizeof (audiodrv_t));
       op = PMALLOC (osdev, sizeof (adev_t));
@@ -6037,7 +6048,7 @@
   if (d == NULL || op == NULL)
     {
       cmn_err (CE_WARN, "Can't allocate driver for (%s)\n", name);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   if (d->get_input_pointer == NULL)
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/audio/audiofmt.c oss-v4.1test0-070624-src-gpl/kernel/framework/audio/audiofmt.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/audio/audiofmt.c	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/audio/audiofmt.c	Tue Jun 26 22:19:44 2007
@@ -272,7 +272,7 @@
 	{
 	  cmn_err (CE_WARN, "SRC failed (%d), bits=%d, ssize=%d\n", err, bits,
 		   ssize);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       *len = ((grc3state_t *) dmap->srcstate[ch])->outsz * ssize * channels;
@@ -325,7 +325,7 @@
   if (nch > 2)
     {
       cmn_err (CE_WARN, "Too many channels for SRC (%d)\n", nch);
-      return -EIO;
+      return RETERR(EIO);
     }
   {
     int val;
@@ -333,7 +333,7 @@
     if (src_open (&dmap->src, srate, trate, nch, 0) != 0)
       {
 	cmn_err (CE_CONT, "OSS audio: SRC open failed\n");
-	return -EIO;
+	return RETERR(EIO);
       }
   }
 #endif
@@ -341,7 +341,7 @@
   if (nch > OSS_MAX_CONVERT_CHANNELS)
     {
       cmn_err (CE_WARN, "Too many channels for SRC (%d)\n", nch);
-      return -EIO;
+      return RETERR(EIO);
     }
 #ifdef DO_TIMINGS
   {
@@ -611,7 +611,7 @@
       default:
 	cmn_err (CE_WARN, "Unsupported conversion source format %08x\n",
 		 source->fmt);
-	return -EIO;
+	return RETERR(EIO);
       }
 
   if (source->rate != target->rate && source->channels <= target->channels)
@@ -931,7 +931,7 @@
       default:
 	cmn_err (CE_WARN, "Unsupported conversion target format %08x\n",
 		 target->fmt);
-	return -EIO;
+	return RETERR(EIO);
       }
 
   VMEM_CHECK (p1, len);
@@ -958,7 +958,7 @@
   if ((fmt = oss_find_format (source->fmt)) == NULL)
     {
       cmn_err (CE_WARN, "Unknown audio format %x\n", source->fmt);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   switch (fmt->bits)
@@ -1131,13 +1131,13 @@
   if ((src_f = oss_find_format (source->fmt)) == NULL)
     {
       cmn_err (CE_CONT, "internal format error 1 (%x)\n", source->fmt);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if ((tgt_f = oss_find_format (target->fmt)) == NULL)
     {
       cmn_err (CE_CONT, "internal format error 2\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
 #ifdef DO_TIMINGS
@@ -1174,7 +1174,7 @@
 	 "Audio format conversions not supported with more than %d channels\n",
 	 OSS_MAX_CONVERT_CHANNELS);
       dmap->flags &= ~DMAP_COOKED;
-      return -EIO;
+      return RETERR(EIO);
     }
 
   expand = (expand * target->rate) / source->rate;
@@ -1277,7 +1277,7 @@
     }
 
   if (dmap->tmpbuf1 == NULL || dmap->tmpbuf2 == NULL)
-    return -ENOSPC;
+    return RETERR(ENOSPC);
 
   if (cnv & CNV_SRC)
     if (setup_src
@@ -1285,7 +1285,7 @@
 	 target->channels) < 0)
       {
 	cmn_err (CE_CONT, "internal format error 3\n");
-	return -EIO;
+	return RETERR(EIO);
       }
 
   return 0;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/audio/spdif.c oss-v4.1test0-070624-src-gpl/kernel/framework/audio/spdif.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/audio/spdif.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/audio/spdif.c	Tue Jun 26 22:19:44 2007
@@ -63,7 +63,7 @@
   if (d == NULL || driver_size != sizeof (spdif_driver_t))
     {
       cmn_err (CE_WARN, "spdif: Bad driver\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   memset (devc, 0, sizeof (*devc));
@@ -94,7 +94,7 @@
   if (!devc->is_ok)
     {
       cmn_err (CE_WARN, "spdif: Bad usage - open\n");
-      return -EIO;
+      return RETERR(EIO);
     }
   MUTEX_ENTER (devc->mutex, flags);
   devc->open_mode |= open_mode;
@@ -224,7 +224,7 @@
       else
 	{
 	  if (valid != 0)	/* Can't get input status */
-	    ret = -EIO;
+	    ret = RETERR(EIO);
 	}
     }
 
@@ -235,7 +235,7 @@
 static int
 handle_request (spdif_devc * devc, oss_digital_control * c)
 {
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -321,15 +321,15 @@
     {
     case SNDCTL_DSP_WRITECTL:
       if (!(open_mode & OPEN_WRITE))	/* Not opened for output */
-	return -ENOTSUP;
+	return RETERR(ENOTSUP);
       if (!(devc->flags & SPDF_OUT))
-	return -ENOTSUP;
+	return RETERR(ENOTSUP);
       return writectl (devc, (oss_digital_control *) arg);
       break;
 
     case SNDCTL_DSP_READCTL:
       if (!(devc->flags & (SPDF_OUT | SPDF_IN)))
-	return -ENOTSUP;
+	return RETERR(ENOTSUP);
       return readctl (devc, (oss_digital_control *) arg, open_mode);
       break;
     }
@@ -374,7 +374,7 @@
 	  return devc->ctl->emphasis_type;
 	}
 
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (cmd == SNDCTL_MIX_WRITE)
@@ -452,9 +452,9 @@
 	  break;
 	}
 
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -469,7 +469,7 @@
       devc = devc_list[i];
 
   if (devc == NULL)
-    return -EINVAL;
+    return RETERR(EINVAL);
   MUTEX_ENTER (devc->mutex, flags);
   ret = spdif_set_control (devc, ctrl, cmd, value);
   MUTEX_EXIT (devc->mutex, flags);
@@ -486,7 +486,7 @@
   if (!devc->is_ok)
     {
       cmn_err (CE_WARN, "spdif: Bad usage - mix_init\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (devc->group > 0)
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/include/oss_config.h oss-v4.1test0-070624-src-gpl/kernel/framework/include/oss_config.h
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/include/oss_config.h	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/include/oss_config.h	Wed Jun 27 17:21:06 2007
@@ -313,6 +313,12 @@
 extern void oss_audio_set_error (int dev, int mode, int err, int parm);
 #define OSSERR(cntx, msg) cntx
 
+#if EINVAL > 0
+#define RETERR(e) (-(e))
+#else
+#define RETERR(e) (e)
+#endif
+
 /*
  * Ensure that various obsolete OSS 3.x features are not used any more
  * in the drivers.
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/default_timer.c oss-v4.1test0-070624-src-gpl/kernel/framework/midi/default_timer.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/default_timer.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/midi/default_timer.c	Tue Jun 26 22:19:44 2007
@@ -32,7 +32,7 @@
   deftmr_timerc_t *timerc;
 
   if ((timerc = KERNEL_MALLOC (sizeof (*timerc))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   memset (timerc, 0, sizeof (*timerc));
 
@@ -68,7 +68,7 @@
 static int
 deftmr_ioctl (int timer_dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -98,7 +98,7 @@
   if (timerc == NULL)
     {
       cmn_err (CE_WARN, "deftmr_start: timerc==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   timerc->start_time = GET_JIFFIES ();
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/midi.c oss-v4.1test0-070624-src-gpl/kernel/framework/midi/midi.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/midi.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/midi/midi.c	Tue Jun 26 22:19:44 2007
@@ -576,13 +576,13 @@
  */
   oss_native_word flags;
   oss_midi_client_t *client;
-  int ok, err = -EBUSY;
+  int ok, err = RETERR(EBUSY);
   int mode = file->mode & O_ACCMODE;
 
   char *cmd;
 
   if (dev < 0 || dev >= num_mididevs)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   /* 
    * Don't allow read only access on playback only devices.
@@ -591,7 +591,7 @@
    */
   if ((mode == OPEN_READ) && !(midi_devs[dev]->flags & MFLAG_INPUT))
     {
-      return -EACCES;
+      return RETERR(EACCES);
     }
 
   /*
@@ -599,14 +599,14 @@
    */
   if ((mode & OPEN_WRITE) && !(midi_devs[dev]->flags & MFLAG_OUTPUT))
     {
-      return -EACCES;
+      return RETERR(EACCES);
     }
 
   if (!midi_devs[dev]->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (midi_devs[dev]->unloaded)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   MUTEX_ENTER_IRQDISABLE (midi_mutex, flags);
 
@@ -670,7 +670,7 @@
 	  midi_devs[dev]->open_mode = 0;
 	  client->open_mode = 0;
 	  client->mididev = NULL;
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
     }
 
@@ -689,7 +689,7 @@
 	  midi_devs[dev]->open_mode = 0;
 	  client->open_mode = 0;
 	  client->mididev = NULL;
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
 
 /*
@@ -943,7 +943,7 @@
   mididev = client->mididev;
 
   if (mididev == NULL)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   MUTEX_ENTER_IRQDISABLE (mididev->mutex, flags);
 
@@ -960,21 +960,21 @@
 	{
 	  MUTEX_EXIT_IRQRESTORE (mididev->mutex, flags);
 	  cmn_err (CE_WARN, "Too short MIDI write (no header)\n");
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
 
       MUTEX_EXIT_IRQRESTORE (mididev->mutex, flags);
       if (uiomove (&hdr, sizeof (midi_packet_header_t), UIO_WRITE, buf) != 0)
 	{
 	  cmn_err (CE_WARN, "uiomove (header) failed\n");
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 	}
 
       if (hdr.magic != MIDI_HDR_MAGIC)
 	{
 	  cmn_err (CE_WARN, "Bad MIDI write packet header (%04x)\n",
 		   hdr.magic);
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
       count -= sizeof (midi_packet_header_t);
       c += sizeof (midi_packet_header_t);
@@ -998,7 +998,7 @@
 	  MUTEX_EXIT_IRQRESTORE (mididev->mutex, flags);
 	  cmn_err (CE_CONT, "MIDI Output buffer %d doesn't drain %d/%d\n",
 		   mididev->dev, c, count);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       if (l > MIDI_PAYLOAD_SIZE)
@@ -1008,7 +1008,7 @@
 	   midi_queue_alloc_record (mididev->out_queue, &targetbuf, l,
 				    &hdr)) < 0)
 	{
-	  if (ret == -ENOSPC)	/* Buffers full */
+	  if (ret == RETERR(ENOSPC))	/* Buffers full */
 	    {
 	      MDB (cmn_err (CE_CONT, "*** Buffers full ***\n"));
 	      tmout =
@@ -1019,7 +1019,7 @@
 		  MUTEX_EXIT_IRQRESTORE (mididev->mutex, flags);
 		  if (c > 0)
 		    return c;
-		  return -EIO;	/* Timeout - why */
+		  return RETERR(EIO);	/* Timeout - why */
 		}
 	      else
 		loops = 0;	/* Restart loop limiter */
@@ -1028,7 +1028,7 @@
 		{
 		  mididev->is_killed = 1;
 		  MUTEX_EXIT_IRQRESTORE (mididev->mutex, flags);
-		  return -EINTR;
+		  return RETERR(EINTR);
 		}
 
 	      if (loops > 95)
@@ -1054,7 +1054,7 @@
 	  if (uiomove (targetbuf, l, UIO_WRITE, buf) != 0)
 	    {
 	      cmn_err (CE_WARN, "uiomove (write) failed\n");
-	      return -EFAULT;
+	      return RETERR(EFAULT);
 	    }
 
 	  count -= l;
@@ -1085,14 +1085,14 @@
       if (max_bytes <= sizeof (*hdr))
 	{
 	  cmn_err (CE_WARN, "MIDI read too small for packet header\n");
-	  return -E2BIG;
+	  return RETERR(E2BIG);
 	}
 
       hdr->magic = MIDI_HDR_MAGIC;
       if (uiomove (hdr, sizeof (*hdr), UIO_READ, buf) != 0)
 	{
 	  cmn_err (CE_WARN, "uiomove (read) failed\n");
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 	}
 
       l += sizeof (*hdr);
@@ -1102,12 +1102,12 @@
     c = max_bytes - l;
 
   if (c <= 0)
-    return -E2BIG;
+    return RETERR(E2BIG);
 
   if (uiomove (data, c, UIO_READ, buf) != 0)
     {
       cmn_err (CE_WARN, "uiomove (read) failed\n");
-      return -EFAULT;
+      return RETERR(EFAULT);
     }
 
   midi_queue_remove_chars (mididev->in_queue, c);
@@ -1138,7 +1138,7 @@
   mididev = client->mididev;
 
   if (mididev == NULL)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   MUTEX_ENTER_IRQDISABLE (mididev->mutex, flags);
 
@@ -1159,7 +1159,7 @@
   if (mididev->prech_timeout < 0)	/* Non blocking mode */
     {
       MUTEX_EXIT_IRQRESTORE (mididev->mutex, flags);
-      return -EWOULDBLOCK;
+      return RETERR(EWOULDBLOCK);
     }
 
   if (!oss_sleep
@@ -1176,7 +1176,7 @@
     {
       mididev->is_killed = 1;
       MUTEX_EXIT_IRQRESTORE (mididev->mutex, flags);
-      return -EINTR;
+      return RETERR(EINTR);
     }
 
   if ((c = midi_queue_get (mididev->in_queue, &data, count, &hdr)) < 0
@@ -1210,7 +1210,7 @@
 	{
 	  cmn_err (CE_WARN, "Invalid MIDI timer %d selected\n",
 		   mididev->timer_driver);
-	  return -ENXIO;
+	  return RETERR(ENXIO);
 	}
 
       if ((timer_dev =
@@ -1235,7 +1235,7 @@
       oss_timer_devs[timer_dev] == NULL)
     {
       cmn_err (CE_WARN, "Failed to allocate a timer instance\n");
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
 
@@ -1274,7 +1274,7 @@
       return err;
   mididev = client->mididev;
   if (mididev == NULL)
-    return -EBUSY;
+    return RETERR(EBUSY);
 
   dev = mididev->dev;
 
@@ -1283,7 +1283,7 @@
     case SNDCTL_MIDI_PRETIME:
       val = *arg;
       if (val < -1)
-	return -EINVAL;
+	return RETERR(EINVAL);
 
       if (val != -1)
 	val = (OSS_HZ * val) / 100;
@@ -1312,7 +1312,7 @@
 	  break;
 	  break;
 	default:
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 	}
       mididev->mtc_timebase = val;
       mididev->mtc_t0 = GET_JIFFIES ();
@@ -1330,7 +1330,7 @@
       val = *arg;
       if (val != MIDI_MODE_TRADITIONAL && val != MIDI_MODE_TIMED
 	  && val != MIDI_MODE_TIMED_ABS)
-	return -EINVAL;
+	return RETERR(EINVAL);
       mididev->working_mode = val;
       *arg = val;
       if ((err = setup_working_mode (mididev)) < 0)
@@ -1345,7 +1345,7 @@
     case SNDCTL_MIDI_TIMEBASE:
       val = *arg;
       if (val < 1 || val > 1000)
-	return -EINVAL;
+	return RETERR(EINVAL);
       mididev->timebase = val;
       return setup_timebase (mididev);
       break;
@@ -1353,7 +1353,7 @@
     case SNDCTL_MIDI_TEMPO:
       val = *arg;
       if (val < 1 || val > 200)
-	return -EINVAL;
+	return RETERR(EINVAL);
       mididev->tempo = val;
       return setup_tempo (mididev);
       break;
@@ -1374,14 +1374,14 @@
   int err;
 
   if (dev < 0 || dev >= oss_num_midi_clients)
-    return -ENXIO;
+    return RETERR(ENXIO);
   client = oss_midi_clients[dev];
   if (client->mididev == NULL)
     if ((err = midi_mapper_autobind (dev, client->open_mode)) < 0)
       return err;
   mididev = client->mididev;
   if (mididev == NULL)
-    return -EIO;
+    return RETERR(EIO);
 
   if ((events & (POLLOUT | POLLWRNORM)) && (mididev->open_mode & OPEN_WRITE))
     {
@@ -1459,7 +1459,7 @@
 
   oss_native_word flags;
   oss_midi_client_t *client = NULL;
-  int ok, err = -EBUSY, d;
+  int ok, err = RETERR(EBUSY), d;
   int mode = file->mode & O_ACCMODE;
 
   MUTEX_ENTER_IRQDISABLE (midi_mutex, flags);
@@ -1492,14 +1492,14 @@
 	{
 	  cmn_err (CE_WARN, "Too many MIDI clients\n");
 	  MUTEX_EXIT_IRQRESTORE (midi_mutex, flags);
-	  return -ENXIO;
+	  return RETERR(ENXIO);
 	}
 
       if (client == NULL)
 	{
 	  cmn_err (CE_WARN, "Out of memory\n");
 	  MUTEX_EXIT_IRQRESTORE (midi_mutex, flags);
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
 
       memset (client, 0, sizeof (*client));
@@ -1614,7 +1614,7 @@
   if (midi_devs == NULL)
     {
       cmn_err (CE_WARN, "oss_install_mididev: Out of memory\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   for (i = 0; i < num_mididevs; i++)
@@ -1632,7 +1632,7 @@
       if (num_mididevs >= MAX_MIDI_DEV - 1)
 	{
 	  cmn_err (CE_WARN, "Too many MIDI devices in the system\n");
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       op = midi_devs[num_mididevs] = PMALLOC (osdev, sizeof (mididev_t));
@@ -1640,7 +1640,7 @@
 	{
 	  cmn_err (CE_WARN,
 		   "oss_install_mididev: Failed to allocate memory\n");
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
       memset (op, 0, sizeof (*op));
       curr_midi_dev = num_mididevs++;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/midi_mapper.c oss-v4.1test0-070624-src-gpl/kernel/framework/midi/midi_mapper.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/midi_mapper.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/midi/midi_mapper.c	Tue Jun 26 22:19:44 2007
@@ -77,7 +77,7 @@
 			   "Failed to allocate MIDI input queue(2)\n");
 		  midi_devs[dev]->d->close (dev, mode);
 		  midi_devs[dev]->open_mode = 0;
-		  return -ENOMEM;
+		  return RETERR(ENOMEM);
 
 		}
 	    }
@@ -92,7 +92,7 @@
 			   "Failed to allocate MIDI output queue(2)\n");
 		  midi_devs[dev]->d->close (dev, mode);
 		  midi_devs[dev]->open_mode = 0;
-		  return -ENOMEM;
+		  return RETERR(ENOMEM);
 
 		}
 	    }
@@ -105,5 +105,5 @@
 	}
     }
 
-  return -EBUSY;
+  return RETERR(EBUSY);
 }
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/midi_queue.c oss-v4.1test0-070624-src-gpl/kernel/framework/midi/midi_queue.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/midi_queue.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/midi/midi_queue.c	Tue Jun 26 22:19:45 2007
@@ -189,13 +189,13 @@
   if (queue == NULL)
     {
       cmn_err (CE_WARN, "midi_queue_alloc_record: Queue==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (len < 1 && hdr == NULL)	/* Nothing was given */
     {
       cmn_err (CE_WARN, "midi_queue_alloc_record: No data\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (len > MIDI_PAYLOAD_SIZE)
@@ -211,13 +211,13 @@
   if (next == queue->q_tail)
     {
       MUTEX_EXIT_IRQRESTORE (queue->mutex, flags);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   if (queue->avail < BUF_PREFIX_SIZE + len)
     {
       MUTEX_EXIT_IRQRESTORE (queue->mutex, flags);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   n = queue->q_head - queue->q_tail;
@@ -227,7 +227,7 @@
   if (n < 1)
     {
       MUTEX_EXIT_IRQRESTORE (queue->mutex, flags);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   if (queue->buf_tail > queue->buf_head)
@@ -258,7 +258,7 @@
 #endif
 	{
 	  MUTEX_EXIT_IRQRESTORE (queue->mutex, flags);
-	  return -ENOSPC;
+	  return RETERR(ENOSPC);
 	}
     }
 
@@ -267,7 +267,7 @@
       cmn_err (CE_CONT, "MIDI queue damaged (%d/%d/alloc)\n", queue->buf_head,
 	       QUEUE_BYTES);
       MUTEX_EXIT_IRQRESTORE (queue->mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (queue->buf_head + BUF_PREFIX_SIZE + len > QUEUE_BYTES)
@@ -278,7 +278,7 @@
       cmn_err (CE_CONT, "Avail=%d\n", avail);
       cmn_err (CE_CONT, "Required=%d\n", len + BUF_PREFIX_SIZE);
       MUTEX_EXIT_IRQRESTORE (queue->mutex, flags);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   ptr = queue->buffer + queue->buf_head;
@@ -317,7 +317,7 @@
 
   if (queue == NULL)
     {
-      return -EIO;
+      return RETERR(EIO);
     }
 #if 0
   {
@@ -332,7 +332,7 @@
     return 0;
 
   if (len > MIDI_PAYLOAD_SIZE)
-    return -E2BIG;
+    return RETERR(E2BIG);
 
 #if 1
   if (len == 1)
@@ -354,7 +354,7 @@
     {
       cmn_err (CE_CONT, "MIDI queue damaged (%d/%d/%d/put)\n",
 	       queue->buf_head, queue->buf_tail, QUEUE_BYTES);
-      return -EIO;
+      return RETERR(EIO);
     }
   return len;
 }
@@ -370,13 +370,13 @@
   *data = NULL;
 
   if (queue == NULL)
-    return -EIO;
+    return RETERR(EIO);
 
   if (queue->buf_head >= QUEUE_BYTES || queue->buf_tail >= QUEUE_BYTES)
     {
       cmn_err (CE_CONT, "MIDI queue damaged (%d/%d/%d/get)\n",
 	       queue->buf_head, queue->buf_tail, QUEUE_BYTES);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   MUTEX_ENTER_IRQDISABLE (queue->mutex, flags);
@@ -420,7 +420,7 @@
   *data = NULL;
 
   if (queue == NULL)
-    return -EIO;
+    return RETERR(EIO);
 
   MUTEX_ENTER_IRQDISABLE (queue->mutex, flags);
   if (queue->q_head == queue->q_tail)
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/timers.c oss-v4.1test0-070624-src-gpl/kernel/framework/midi/timers.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/midi/timers.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/midi/timers.c	Tue Jun 26 22:19:45 2007
@@ -37,25 +37,25 @@
     {
       cmn_err (CE_WARN, "Incompatible timer driver version %d\n",
 	       driver_version);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (driver_size != sizeof (*op))
     {
       cmn_err (CE_WARN, "Incompatible timer driver size %d\n", driver_size);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   if (oss_num_timer_drivers >= MAX_TIMER_DEV)
     {
       cmn_err (CE_WARN, "Too many timer drivers\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   if ((op = PMALLOC (osdev, sizeof (*op))) == NULL)
     {
       cmn_err (CE_WARN, "Out of memory (oss_install_timer)\n");
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   memcpy (op, d, driver_size);
@@ -87,7 +87,7 @@
 /* TODO: Create a mutex for all timers */
 
   if (driver_dev < 0 || driver_dev >= oss_num_timer_drivers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   drv = oss_timer_drivers[driver_dev];
 
@@ -98,7 +98,7 @@
 	       driver_dev, drv->max_instances);
 
       MUTEX_EXIT_IRQRESTORE (drv->mutex, flags);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   drv->num_instances++;
   MUTEX_EXIT_IRQRESTORE (drv->mutex, flags);
@@ -108,7 +108,7 @@
       MUTEX_ENTER_IRQDISABLE (drv->mutex, flags);
       drv->num_instances--;
       MUTEX_EXIT_IRQRESTORE (drv->mutex, flags);
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
   memset (tmr, 0, sizeof (*tmr));
 
@@ -130,7 +130,7 @@
 	  MUTEX_ENTER_IRQDISABLE (drv->mutex, flags);
 	  drv->num_instances--;
 	  MUTEX_EXIT_IRQRESTORE (drv->mutex, flags);
-	  return -EBUSY;
+	  return RETERR(EBUSY);
 	}
       num = oss_num_timers++;
     }
@@ -175,18 +175,18 @@
   oss_native_word flags;
 
   if (timer_dev < 0 || timer_dev >= oss_num_timers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   tmr = oss_timer_devs[timer_dev];
   if (tmr == NULL)
     {
       cmn_err (CE_WARN, "tmr==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
   if (tmr->d == NULL)
     {
       cmn_err (CE_WARN, "tmr->d==NULL\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (tmr->d->attach_client != NULL)
@@ -350,11 +350,11 @@
   int err;
 
   if (timer_dev < 0 || timer_dev >= oss_num_timers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   tmr = oss_timer_devs[timer_dev];
   if (tmr == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
   tmr->pending_tempo = tempo;
 
   {
@@ -378,11 +378,11 @@
   int err;
 
   if (timer_dev < 0 || timer_dev >= oss_num_timers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   tmr = oss_timer_devs[timer_dev];
   if (tmr == NULL || tmr->d->set_timebase == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
   tmr->timebase = timebase;
   if ((err = tmr->d->set_timebase (timer_dev, timebase)) < 0)
     return err;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/mixer/mixer.c oss-v4.1test0-070624-src-gpl/kernel/framework/mixer/mixer.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/mixer/mixer.c	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/mixer/mixer.c	Tue Jun 26 22:19:45 2007
@@ -51,7 +51,7 @@
   mixer_info *info = (mixer_info *) arg;
 
   if (dev < 0 || dev >= num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   strcpy (info->id, mixer_devs[dev]->id);
   strncpy (info->name, mixer_devs[dev]->name, 31);
@@ -75,13 +75,13 @@
   int ret;
 
   if (!(cmd & SIOC_OUT) && !(cmd & SIOC_IN))
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (arg == 0)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (((cmd >> 8) & 0xff) != 'M')	/* Not a mixer ioctl */
-    return -EINVAL;
+    return RETERR(EINVAL);
 #ifdef DO_TIMINGS
   {
     char tmp[128];
@@ -94,11 +94,11 @@
   if (mixdev < 0 || mixdev >= num_mixers)
     {
       cmn_err (CE_WARN, "Bad mixer device %d\n", mixdev);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (!mixer_devs[mixdev]->enabled || mixer_devs[mixdev]->unloaded)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (cmd == SOUND_MIXER_INFO)
     return get_mixer_info (mixdev, arg);
@@ -197,7 +197,7 @@
 
   n = buf->num;
   if (n < 0 || n >= num_mixer_volumes)
-    err = -EINVAL;
+    err = RETERR(EINVAL);
   else
     {
       memcpy ((char *) buf, (char *) &mixer_vols[n], sizeof (*buf));
@@ -226,17 +226,17 @@
   int extnr;
 
   if (ent == NULL)
-    return -EFAULT;
+    return RETERR(EFAULT);
 
   if (ent->dev < 0 || ent->dev >= num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   dev = ent->dev;
   touch_mixer (dev);
 
   ctrl = ent->ctrl;
   if (ent->ctrl < 0 || ent->ctrl >= mixer_devs[dev]->nr_ext)
-    return -EIDRM;
+    return RETERR(EIDRM);
   extnr = ent->ctrl;
 
   memcpy ((char *) ent, (char *) &mixer_devs[dev]->extensions[extnr].ext,
@@ -263,7 +263,7 @@
   int dev, ctrl;
 
   if (ent == NULL)
-    return -EFAULT;
+    return RETERR(EFAULT);
 
   dev = ent->dev;
   ctrl = ent->ctrl;
@@ -271,19 +271,19 @@
 
   if (dev < 0 || dev >= num_mixers)
     {
-      return -ENXIO;
+      return RETERR(ENXIO);
     }
 
   touch_mixer (dev);
 
   if (ctrl < 0 || ctrl >= mixer_devs[dev]->nr_ext)
     {
-      return -EIDRM;
+      return RETERR(EIDRM);
     }
 
   if (mixer_devs[dev]->extensions[ctrl].enum_info == NULL)
     {
-      return -EIO;
+      return RETERR(EIO);
     }
 
   memcpy ((char *) ent,
@@ -344,17 +344,17 @@
   int extnr;
 
   if (ent == NULL)
-    return -EFAULT;
+    return RETERR(EFAULT);
 
   if (ent->dev < 0 || ent->dev >= num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   dev = ent->dev;
   touch_mixer (dev);
 
   ctrl = ent->ctrl;
   if (ent->ctrl < 0 || ent->ctrl >= mixer_devs[dev]->nr_ext)
-    return -EIDRM;
+    return RETERR(EIDRM);
   extnr = ent->ctrl;
 
   if (mixer_devs[dev]->extensions[extnr].enum_info == NULL)
@@ -362,7 +362,7 @@
       PMALLOC (mixer_devs[dev]->osdev, sizeof (*ent));
 
   if (mixer_devs[dev]->extensions[extnr].enum_info == NULL)
-    return -EIO;
+    return RETERR(EIO);
 
   memcpy ((char *) mixer_devs[dev]->extensions[extnr].enum_info,
 	  (char *) ent, sizeof (*ent));
@@ -375,7 +375,7 @@
   if (ent->nvalues >= OSS_ENUM_MAXVALUE)
     {
       mixer_devs[dev]->extensions[extnr].enum_info = NULL;
-      return -EIO;
+      return RETERR(EIO);
     }
 
   return 0;
@@ -392,19 +392,19 @@
   mixer_ext_fn func;
 
   if (val == NULL)
-    return -EFAULT;
+    return RETERR(EFAULT);
 
   if (val->dev < 0 || val->dev >= num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   dev = val->dev;
 
   if (!mixer_devs[dev]->enabled || mixer_devs[dev]->unloaded)
-    return -ENXIO;
+    return RETERR(ENXIO);
   touch_mixer (dev);
 
   if (val->ctrl < 0 || val->ctrl >= mixer_devs[dev]->nr_ext)
-    return -EIDRM;
+    return RETERR(EIDRM);
   extnr = val->ctrl;
 
   ext_desc = &mixer_devs[dev]->extensions[extnr];
@@ -412,11 +412,11 @@
 
   if (val->timestamp != ext->timestamp)
     {
-      return -EIDRM;
+      return RETERR(EIDRM);
     }
 
   if (ext_desc->handler == NULL || !(ext->flags & MIXF_READABLE))
-    return -EFAULT;
+    return RETERR(EFAULT);
 
   func = (mixer_ext_fn) ext_desc->handler;
   return (val->value = func (dev, ext->ctrl, SNDCTL_MIX_READ, val->value));
@@ -436,19 +436,19 @@
   if (val == NULL)
     {
       cmn_err (CE_WARN, "NULL argument in mixer call\n");
-      return -EFAULT;
+      return RETERR(EFAULT);
     }
 
   if (val->dev < 0 || val->dev >= num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   dev = val->dev;
   if (!mixer_devs[dev]->enabled || mixer_devs[dev]->unloaded)
-    return -ENXIO;
+    return RETERR(ENXIO);
   touch_mixer (dev);
 
   if (val->ctrl < 0 || val->ctrl >= mixer_devs[dev]->nr_ext)
-    return -EIDRM;
+    return RETERR(EIDRM);
   extnr = val->ctrl;
 
   ext_desc = &mixer_devs[dev]->extensions[extnr];
@@ -457,12 +457,12 @@
   if (ext_desc->handler == NULL || !(ext->flags & MIXF_WRITEABLE))
     {
       cmn_err (CE_WARN, "NULL handler or control not writeable\n");
-      return -EFAULT;
+      return RETERR(EFAULT);
     }
 
   if (val->timestamp != ext->timestamp)
     {
-      return -EIDRM;
+      return RETERR(EIDRM);
     }
 
   func = (mixer_ext_fn) ext_desc->handler;
@@ -489,7 +489,7 @@
   if (mixer_devs[dev]->max_ext != 0)
     {
       cmn_err (CE_WARN, "Mixer%d (ext) initialization order wrong\n", dev);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   mixext_desc =
@@ -498,7 +498,7 @@
   if (mixext_desc == NULL)
     {
       cmn_err (CE_CONT, "Not enough memory for mixer%d (ext)\n", dev);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   mixer_devs[dev]->extensions = mixext_desc;
@@ -544,14 +544,14 @@
     {
       cmn_err (CE_WARN, "Mixer extensions not initialized for device %d\n",
 	       dev);
-      return -EFAULT;
+      return RETERR(EFAULT);
     }
 
   if (mixer_devs[dev]->nr_ext >= mixer_devs[dev]->max_ext)
     {
       cmn_err (CE_WARN, "Out of mixer controls for device %d/%s (%d)\n", dev,
 	       mixer_devs[dev]->name, mixer_devs[dev]->max_ext);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   mixext_desc =
@@ -609,14 +609,14 @@
     {
       cmn_err (CE_WARN, "Mixer extensions not initialized for device %d\n",
 	       dev);
-      return -EFAULT;
+      return RETERR(EFAULT);
     }
 
   if (mixer_devs[dev]->nr_ext >= mixer_devs[dev]->max_ext)
     {
       cmn_err (CE_WARN, "Out of mixer controls for device %d/%s (%d)\n", dev,
 	       mixer_devs[dev]->name, mixer_devs[dev]->max_ext);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   if (func == NULL)		/* No access function */
@@ -728,7 +728,7 @@
       return value;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 int
@@ -1104,7 +1104,7 @@
  * extended mixer is actually used.
  */
   if (dev < 0 || dev >= num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   mixer_devs[dev]->nr_extra_ext = nextra;
   mixer_devs[dev]->create_controls = func;
@@ -1123,7 +1123,7 @@
  * extended mixer is actually used.
  */
   if (dev < 0 || dev >= num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   mixer_devs[dev]->nr_extra_ext += nextra;
   mixer_devs[dev]->create_vmix_controls = func;
@@ -1249,16 +1249,16 @@
     case SNDCTL_MIX_NREXT:	/* Return # of mixer extensions for device */
       val = *arg;
       if (val < 0 || val >= num_mixers)
-	return -ENXIO;
+	return RETERR(ENXIO);
       if (mixer_devs[val] == NULL || mixer_devs[val]->unloaded
 	  || !mixer_devs[val]->enabled)
 	{
-	  return -ENXIO;
+	  return RETERR(ENXIO);
 	}
 
 
       if (!mixer_devs[val]->enabled || mixer_devs[val]->unloaded)
-	return -ENXIO;
+	return RETERR(ENXIO);
       touch_mixer (val);
       return *arg = (mixer_devs[val]->nr_ext);
       break;
@@ -1294,13 +1294,13 @@
 	adev_p adev;
 
 	if (info == NULL)
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 
 	dev = info->dev;
 
 	if (dev < -1 || dev >= num_audio_devfiles)
 	  {
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
 
 	if (dev >= 0)
@@ -1327,7 +1327,7 @@
 	adev_p adev, next;
 
 	if (info == NULL)
-	  return -EFAULT;
+	  return RETERR(EFAULT);
 
 	dev = info->dev;
 
@@ -1340,12 +1340,12 @@
 	      break;
 
 	    default:
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 	    }
 
 	if (dev < 0 || dev >= num_audio_engines)
 	  {
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
 
 	memset ((char *) info, 0, sizeof (*info));
@@ -1354,7 +1354,7 @@
 	if (adev == NULL)
 	  {
 	    cmn_err (CE_WARN, "Internal error - adev==NULL (%d)\n", dev);
-	    return -ENXIO;
+	    return RETERR(ENXIO);
 	  }
 
 	if (!adev->unloaded && adev->enabled)
@@ -1406,11 +1406,11 @@
 	  {
 	    if (audio_engines[dev]->d->ioctl (dev, SNDCTL_GETSONG,
 					      (ioctl_arg) info->song_name) ==
-		-EINVAL)
+		RETERR(EINVAL))
 	      strcpy (info->song_name, adev->song_name);
 	    if (audio_engines[dev]->d->ioctl (dev, SNDCTL_GETLABEL,
 					      (ioctl_arg) info->label) ==
-		-EINVAL)
+		RETERR(EINVAL))
 	      strcpy (info->label, adev->label);
 	  }
 
@@ -1496,19 +1496,19 @@
 	       */
 	      dev = orig_dev;
 	      if (dev < 0 || dev >= oss_num_midi_clients)
-		return -ENXIO;
+		return RETERR(ENXIO);
 	      if (oss_midi_clients[dev]->mididev == NULL)
-		return -EBUSY;	/* No binding established (yet) */
+		return RETERR(EBUSY);	/* No binding established (yet) */
 	      dev = oss_midi_clients[dev]->mididev->dev;
 	      break;
 
 	    default:
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 	    }
 
 	if (dev < 0 || dev >= num_mididevs)
 	  {
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
 
 	memset ((char *) info, 0, sizeof (*info));
@@ -1574,7 +1574,7 @@
 
 	if (card < 0 || card >= oss_num_cards)
 	  {
-	    return -ENXIO;
+	    return RETERR(ENXIO);
 	  }
 
 	memset ((char *) info, 0, sizeof (*info));
@@ -1602,16 +1602,16 @@
 	      break;
 
 	    default:
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 	    }
 
 	if (dev < 0 || dev >= num_mixers)
 	  {
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
 
 	if (mixer_devs[dev] == NULL)
-	  return -ENXIO;
+	  return RETERR(ENXIO);
 
 	memset ((char *) info, 0, sizeof (*info));
 	touch_mixer (dev);
@@ -1642,13 +1642,13 @@
 	int i;
 
 	if (GET_PROCESS_UID () != 0)	/* Not root */
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	if (r->n != num_audio_devfiles)	/* Wrong map size? */
 	  {
 	    cmn_err (CE_NOTE, "Legacy audio map size mismatch %d/%d\n",
 		     r->n, num_audio_devfiles);
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
 
 	for (i = 0; i < r->n; i++)
@@ -1656,7 +1656,7 @@
 	    adev_p adev = audio_devfiles[i];
 
 	    if (r->map[i] >= OSS_MAX_CDEVS)	/* May be unnecessary check */
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 
 	    if (r->map[i] < -1)
 	      r->map[i] = -1;
@@ -1673,17 +1673,17 @@
 	int i;
 
 	if (GET_PROCESS_UID () != 0)	/* Not root */
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	if (r->n != num_mixers)	/* Wrong map size? */
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	for (i = 0; i < r->n; i++)
 	  {
 	    mixdev_p mdev = mixer_devs[i];
 
 	    if (r->map[i] >= OSS_MAX_CDEVS)	/* May be unnecessary check */
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 
 	    mdev->real_dev = r->map[i];
 	  }
@@ -1697,17 +1697,17 @@
 	int i;
 
 	if (GET_PROCESS_UID () != 0)	/* Not root */
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	if (r->n != num_mididevs)	/* Wrong map size? */
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	for (i = 0; i < r->n; i++)
 	  {
 	    mididev_p mdev = midi_devs[i];
 
 	    if (r->map[i] >= OSS_MAX_CDEVS)	/* May be unnecessary check */
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 
 	    mdev->real_dev = r->map[i];
 	  }
@@ -1721,7 +1721,7 @@
 
 	if (GET_PROCESS_UID () != 0)	/* Not root */
 	  {
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
 
 	switch (r->mode)
@@ -1742,7 +1742,7 @@
 	    break;
 
 	  default:
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
       }
       return 0;
@@ -1754,12 +1754,12 @@
 	int i, d;
 
 	if (GET_PROCESS_UID () != 0)	/* Not root */
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	for (i = 0; i < r->devlist.ndevs; i++)
 	  {
 	    if ((d = r->devlist.devices[i]) < 0 || d >= num_audio_devfiles)
-	      return -EINVAL;
+	      return RETERR(EINVAL);
 	  }
 
 	switch (r->mode)
@@ -1768,7 +1768,7 @@
 	    /* Refuse if number of devices has changed */
 	    if (!check_list (&r->devlist, &dspinlist))
 	      {
-		return -EINVAL;
+		return RETERR(EINVAL);
 	      }
 	    memcpy (&dspinlist, &r->devlist, sizeof (oss_devlist_t));
 	    break;
@@ -1780,7 +1780,7 @@
 	    /* Refuse if number of devices has changed */
 	    if (!check_list (&r->devlist, &dspoutlist))
 	      {
-		return -EINVAL;
+		return RETERR(EINVAL);
 	      }
 	    memcpy (&dspoutlist, &r->devlist, sizeof (oss_devlist_t));
 	    dspoutlist2.ndevs = 0;
@@ -1790,13 +1790,13 @@
 	    /* Refuse if number of devices has changed */
 	    if (!check_list (&r->devlist, &dspinoutlist))
 	      {
-		return -EINVAL;
+		return RETERR(EINVAL);
 	      }
 	    memcpy (&dspinoutlist, &r->devlist, sizeof (oss_devlist_t));
 	    break;
 
 	  default:
-	    return -EINVAL;
+	    return RETERR(EINVAL);
 	  }
       }
       return 0;
@@ -1805,7 +1805,7 @@
 #ifdef APPLIST_SUPPORT
     case OSSCTL_RESET_APPLIST:
       if (GET_PROCESS_UID () != 0)	/* Not root */
-	return -EINVAL;
+	return RETERR(EINVAL);
 
       oss_applist_size = 0;
       return 0;
@@ -1816,13 +1816,13 @@
 	app_routing_t *def, *parm = (app_routing_t *) arg;
 
 	if (GET_PROCESS_UID () != 0)	/* Not root */
-	  return -EINVAL;
+	  return RETERR(EINVAL);
 
 	if (oss_applist_size >= APPLIST_SIZE)
-	  return -ENOSPC;
+	  return RETERR(ENOSPC);
 
 	if (parm->dev < -1 || parm->dev >= num_audio_devfiles)
-	  return -ENXIO;
+	  return RETERR(ENXIO);
 
 	def = &oss_applist[oss_applist_size];
 
@@ -1839,7 +1839,7 @@
 #endif
 
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
@@ -1859,10 +1859,10 @@
     return 0;
 
   if (mixer_devs[dev]->unloaded)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (!mixer_devs[dev]->enabled)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   return 0;
 }
@@ -1879,15 +1879,15 @@
   int ret;
 
   if (dev < 0 || dev > num_mixers)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (mixer_devs == NULL)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
   if (!mixer_devs[dev]->enabled || mixer_devs[dev]->unloaded)
-    return -ENODEV;
+    return RETERR(ENODEV);
 
-  if ((ret = oss_legacy_mixer_ioctl (dev, -1, cmd, arg)) != -EINVAL)
+  if ((ret = oss_legacy_mixer_ioctl (dev, -1, cmd, arg)) != RETERR(EINVAL))
     return ret;
 
   return oss_mixer_ext (dev, OSS_DEV_MIXER, cmd, arg);
@@ -2152,13 +2152,13 @@
 	       num_mixers, MAX_MIXER_DEV, name);
       if (nnn > 10)
 	cmn_err (CE_PANIC, "Giving up\n");
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (vers != OSS_MIXER_DRIVER_VERSION)
     {
       cmn_err (CE_WARN, "Incompatible mixer driver for %s\n", name);
-      return -EIO;
+      return RETERR(EIO);
     }
 
   if (driver_size > sizeof (mixer_driver_t))
@@ -2182,7 +2182,7 @@
   if ((d = PMALLOC (osdev, sizeof (*d))) == NULL)
     {
       cmn_err (CE_WARN, "Can't allocate mixer driver for (%s)\n", name);
-      return -ENOSPC;
+      return RETERR(ENOSPC);
     }
 
   if (num == -1)
@@ -2191,7 +2191,7 @@
       if (op == NULL)
 	{
 	  cmn_err (CE_WARN, "Can't allocate mixer driver for (%s)\n", name);
-	  return -ENOSPC;
+	  return RETERR(ENOSPC);
 	}
 
       num = num_mixers++;
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/ossddk/ossddk.c oss-v4.1test0-070624-src-gpl/kernel/framework/ossddk/ossddk.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/ossddk/ossddk.c	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/ossddk/ossddk.c	Tue Jun 26 22:19:45 2007
@@ -453,7 +453,7 @@
   *handle = NULL;
 
   if ((h = KERNEL_MALLOC (sizeof (*h))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   if ((err =
        ac97_install (&h->devc, name, readfn, writefn, hostparms, osdev)) < 0)
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/remux/remux.c oss-v4.1test0-070624-src-gpl/kernel/framework/remux/remux.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/remux/remux.c	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/remux/remux.c	Tue Jun 26 22:19:45 2007
@@ -103,7 +103,7 @@
 static int
 remux_ioctl (int dev, unsigned int cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void remux_trigger (int dev, int state);
@@ -125,7 +125,7 @@
   if (mode & OPEN_READ)
     {
       cmn_err (CE_WARN, "Audio device %d cannot do recording\n", dev);
-      /* return -ENOTSUP; */
+      /* return RETERR(ENOTSUP); */
     }
 
   MUTEX_ENTER_IRQDISABLE (devc->mutex, flags);
@@ -134,7 +134,7 @@
     {
       MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
 
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
   devc->open_mode = mode;
   MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
@@ -303,7 +303,7 @@
 static int
 remux_prepare_for_input (int dev, int bsize, int bcount)
 {
-  return -EIO;
+  return RETERR(EIO);
 }
 
 static int
@@ -336,7 +336,7 @@
 	{
 	  cmn_err (CE_NOTE, "remux: Bad sample format %x\n", tmp);
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       tmp = pdev->d->set_channels (pd, 2);
@@ -344,7 +344,7 @@
 	{
 	  cmn_err (CE_NOTE, "remux: Bad number of channels %d\n", tmp);
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       tmp = pdev->d->set_rate (pd, devc->speed);
@@ -352,7 +352,7 @@
 	{
 	  cmn_err (CE_NOTE, "remux: Bad sample rate %d\n", tmp);
 	  MUTEX_EXIT_IRQRESTORE (devc->mutex, flags);
-	  return -EIO;
+	  return RETERR(EIO);
 	}
 
       if (pdev->min_block > 0 && bsize < pdev->min_block)
@@ -385,7 +385,7 @@
       if (dmap->dmabuf == NULL)
 	{
 	  cmn_err (CE_WARN, "dmabuf==NULL\n");
-	  return -ENOMEM;
+	  return RETERR(ENOMEM);
 	}
 
       memset (dmap->dmabuf, 0, dmap->buffsize);
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/sndstat/sndstat.c oss-v4.1test0-070624-src-gpl/kernel/framework/sndstat/sndstat.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/sndstat/sndstat.c	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/sndstat/sndstat.c	Tue Jun 26 22:19:45 2007
@@ -582,7 +582,7 @@
     return 0;
 
   if (uiomove (&sndstat_buf[sndstat_ptr], l, UIO_READ, buf) != 0)
-    return -EFAULT;
+    return RETERR(EFAULT);
   sndstat_ptr += l;
 
   return l;
@@ -594,13 +594,13 @@
 {
   /* TODO: Concurrency control */
   if (sndstat_busy)
-    return -EBUSY;
+    return RETERR(EBUSY);
   sndstat_busy = 1;
 
   if ((sndstat_buf = KERNEL_MALLOC (4096)) == NULL)
     {
       sndstat_busy = 0;
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
 
   sndstat_len = 0;
@@ -639,7 +639,7 @@
   oss_detach_enabled = 1;
   return count;
 #else
-  return -EIO;
+  return RETERR(EIO);
 #endif
 }
 
diff -urN oss-v4.1test0-070624-src-gpl.org/kernel/framework/uart401/uart401.c oss-v4.1test0-070624-src-gpl/kernel/framework/uart401/uart401.c
--- oss-v4.1test0-070624-src-gpl.org/kernel/framework/uart401/uart401.c	Sun Jun 24 18:09:42 2007
+++ oss-v4.1test0-070624-src-gpl/kernel/framework/uart401/uart401.c	Tue Jun 26 22:19:45 2007
@@ -124,7 +124,7 @@
 
   if (devc->opened)
     {
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   while (input_avail (devc))
@@ -189,7 +189,7 @@
 static int
 uart401_ioctl (int dev, unsigned cmd, ioctl_arg arg)
 {
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static midi_driver_t uart401_driver = {
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libOSSlib/compile.sh oss-v4.1test0-070624-src-gpl/lib/libOSSlib/compile.sh
--- oss-v4.1test0-070624-src-gpl.org/lib/libOSSlib/compile.sh	Thu Jun 29 00:08:43 2006
+++ oss-v4.1test0-070624-src-gpl/lib/libOSSlib/compile.sh	Tue Jun 26 22:19:45 2007
@@ -66,6 +66,10 @@
 	$MAKE libOSSlib.a CFLAGS=""
 	;;
 
+"BeOS"|"Haiku")
+	$MAKE libOSSlib.a CFLAGS=""
+	;;
+
 *)
       echo Can\'t recognize your operating system '('`uname`')'.
       echo;echo
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/main.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/main.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/main.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/main.c	Tue Jun 26 22:19:46 2007
@@ -43,13 +43,13 @@
   if (mixer_fd == -1)
     {
       if ((mixer_fd = open ("/dev/mixer", O_RDONLY, 0)) == -1)
-	return -errno;
+	return RETERR(errno);
     }
 
   if (ioctl (mixer_fd, SNDCTL_SYSINFO, &sysinfo) == -1)
     {
       perror ("SNDCTL_SYSINFO");
-      return -errno;
+      return RETERR(errno);
     }
 
   return 0;
@@ -214,7 +214,7 @@
 {
   ALIB_INIT ();
   if (!alib_appcheck ())
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if (*rcard == -1)
     *rcard = 0;
@@ -242,7 +242,7 @@
 snd_card_get_index (const char *string)
 {
   dbg_printf ("snd_card_get_index(%s)\n", string);
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -281,7 +281,7 @@
 
   ALIB_INIT ();
   if (!alib_appcheck ())
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   *ctlp = NULL;
 
@@ -290,18 +290,18 @@
   else
     {
       if (name[0] != 'h' && name[1] != 'w' && name[2] != ':')
-	return -ENOENT;
+	return RETERR(ENOENT);
 
       if (sscanf (name + 3, "%d", &num) != 1)
-	return -ENOENT;
+	return RETERR(ENOENT);
     }
 
   if (num < 0 || num >= sysinfo.numcards)
-    return -ENXIO;
+    return RETERR(ENXIO);
 
 
   if ((ctl = malloc (sizeof (*ctl))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   memset (ctl, 0, sizeof (*ctl));
   ctl->info.card = num;
@@ -309,7 +309,7 @@
     {
       perror ("SNDCTL_CARDINFO");
       fprintf (stderr, "Mixer fd was %d\n", mixer_fd);
-      return -errno;
+      return RETERR(errno);
     }
 
   *ctlp = ctl;
@@ -371,7 +371,7 @@
 
   ci.card = card;
   if (ioctl (mixer_fd, SNDCTL_CARDINFO, &ci) == -1)
-    return -errno;
+    return RETERR(errno);
 
   *name = strdup (ci.longname);
   return 0;
@@ -407,7 +407,7 @@
 
       ctl->ainfo.dev = *device;
       if (ioctl (mixer_fd, SNDCTL_AUDIOINFO, &ctl->ainfo) < 0)
-	return -errno;
+	return RETERR(errno);
 
       if (ctl->ainfo.card_number == ctl->info.card)
 	{
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/mix.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/mix.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/mix.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/mix.c	Tue Jun 26 22:19:47 2007
@@ -73,10 +73,10 @@
 
   ALIB_INIT ();
   if (!alib_appcheck ())
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   if ((mixer = malloc (sizeof (*mixer))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   memset (mixer, 0, sizeof (*mixer));
   *mixerp = mixer;
@@ -104,19 +104,19 @@
   else if (name[0] == 'h' && name[1] == 'w' && name[2] == ':')
     {
       if (sscanf (name + 3, "%d", &dev) != 1)
-	return -ENOENT;
+	return RETERR(ENOENT);
 
       if (dev < 0 || dev >= sysinfo.nummixers)
-	return -ENXIO;
+	return RETERR(ENXIO);
     }
   else
-    return -ENOENT;
+    return RETERR(ENOENT);
 
   mixer->mixdev = dev;
 
   mixer->info.dev = dev;
   if (ioctl (mixer_fd, SNDCTL_MIXERINFO, &mixer->info) == -1)
-    return -errno;
+    return RETERR(errno);
 
   mixer->nrext = mixer->info.nrext;
 
@@ -166,7 +166,7 @@
     return 0;
 
   if ((class = malloc (sizeof (*class))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   memset (class, 0, sizeof (*class));
   *classp = class;
@@ -273,7 +273,7 @@
   rec.value = vol | (vol << 8);
 
   if (ioctl (mixer_fd, SNDCTL_MIX_WRITE, &rec) == -1)
-    return -errno;
+    return RETERR(errno);
 
   return 0;
 }
@@ -363,7 +363,7 @@
   rec.timestamp = elem->ext.timestamp;
 
   if (ioctl (mixer_fd, SNDCTL_MIX_READ, &rec) == -1)
-    return -errno;
+    return RETERR(errno);
 
   left = rec.value & 0xff;
   right = (rec.value >> 8) & 0xff;
@@ -513,7 +513,7 @@
     free (mixer->elems);
 
   if ((elems = malloc (sizeof (*elems) * mixer->nrext)) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   memset (elems, 0, sizeof (*elems) * mixer->nrext);
 
@@ -660,7 +660,7 @@
   rec.timestamp = elem->ext.timestamp;
 
   if (ioctl (mixer_fd, SNDCTL_MIX_READ, &rec) == -1)
-    return -errno;
+    return RETERR(errno);
 
   *value = !!rec.value;
   return 0;
@@ -782,7 +782,7 @@
   rec.value = !!value;
 
   if (ioctl (mixer_fd, SNDCTL_MIX_WRITE, &rec) == -1)
-    return -errno;
+    return RETERR(errno);
 
   return 0;
 }
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/output.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/output.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/output.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/output.c	Tue Jun 26 22:19:47 2007
@@ -208,12 +208,12 @@
   assert (outputp && fp);
   stdio = calloc (1, sizeof (*stdio));
   if (!stdio)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   output = calloc (1, sizeof (*output));
   if (!output)
     {
       free (stdio);
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
   stdio->fp = fp;
   stdio->close = _close;
@@ -241,7 +241,7 @@
   if (!fp)
     {
       //SYSERR("fopen");
-      return -errno;
+      return RETERR(errno);
     }
   err = snd_output_stdio_attach (outputp, fp, 1);
   if (err < 0)
@@ -285,7 +285,7 @@
     alloc *= 2;
   buf = realloc (buffer->buf, alloc);
   if (!buf)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   buffer->buf = buf;
   buffer->alloc = alloc;
   return buffer->alloc - buffer->size;
@@ -393,12 +393,12 @@
   assert (outputp);
   buffer = calloc (1, sizeof (*buffer));
   if (!buffer)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   output = calloc (1, sizeof (*output));
   if (!output)
     {
       free (buffer);
-      return -ENOMEM;
+      return RETERR(ENOMEM);
     }
   buffer->buf = NULL;
   buffer->alloc = 0;
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/pcm.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/pcm.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/pcm.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/pcm.c	Tue Jun 26 22:19:47 2007
@@ -240,7 +240,7 @@
   ALIB_INIT ();
 
   if (!alib_appcheck ())
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   *pcmp = NULL;
 
@@ -257,7 +257,7 @@
 	{
 #if 0
 	  fprintf (stderr, "OSS asound - Bad PCM device '%s'\n", name);
-	  return -ENOENT;
+	  return RETERR(ENOENT);
 #else
 	  strcpy (dspname, "/dev/dsp");
 #endif
@@ -267,7 +267,7 @@
     }
 
   if ((pcm = malloc (sizeof (*pcm))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   switch (stream)
     {
@@ -279,7 +279,7 @@
       break;
     default:
       fprintf (stderr, "snd_pcm_open: Bad stream %d\n", stream);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 
   memset (pcm, 0, sizeof (*pcm));
@@ -296,7 +296,7 @@
     {
       int err = errno;
       free (pcm);
-      return -err;
+      return RETERR(err);
     }
 
   pcm->info.dev = -1;
@@ -305,7 +305,7 @@
       int err = errno;
       close (pcm->fd);
       free (pcm);
-      return -err;
+      return RETERR(err);
     }
 
   dbg_printf ("Opened %s='%s' = %d\n", name, pcm->info.name, pcm->fd);
@@ -364,7 +364,7 @@
  * \brief Stop a PCM preserving pending frames
  * \param pcm PCM handle
  * \return 0 on success otherwise a negative error code
- * \retval -ESTRPIPE a suspend event occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred
  *
  * For playback wait for all pending frames to be played and then stop
  * the PCM.
@@ -423,22 +423,22 @@
 
   tmp = params->oss_fmt;
   if (ioctl (pcm->fd, SNDCTL_DSP_SETFMT, &tmp) == -1)
-    return -errno;
+    return RETERR(errno);
   if (tmp != params->oss_fmt)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   tmp = params->channels;
   if (ioctl (pcm->fd, SNDCTL_DSP_CHANNELS, &tmp) == -1)
-    return -errno;
+    return RETERR(errno);
   if (tmp != params->channels)
-    return -EINVAL;
+    return RETERR(EINVAL);
   pcm->channels = tmp;
 
   tmp = params->speed;
   if (ioctl (pcm->fd, SNDCTL_DSP_SPEED, &tmp) == -1)
-    return -errno;
+    return RETERR(errno);
   if (tmp != params->speed)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   tmp = params->channels * params->sample_bits;
   pcm->frame_size = params->frame_size = tmp / 8;
@@ -460,12 +460,12 @@
 
   memset (params, 0, sizeof (params));
   if (ioctl (pcm->fd, SNDCTL_DSP_CHANNELS, &params->channels) == -1)
-    return -errno;
+    return RETERR(errno);
   pcm->channels = params->channels;
   if (ioctl (pcm->fd, SNDCTL_DSP_SETFMT, &params->oss_fmt) == -1)
-    return -errno;
+    return RETERR(errno);
   if (ioctl (pcm->fd, SNDCTL_DSP_SPEED, &params->speed) == -1)
-    return -errno;
+    return RETERR(errno);
   dbg_printf ("Rate %d, channels %d, fmt %x\n", params->speed,
 	      params->channels, params->oss_fmt);
 
@@ -496,7 +496,7 @@
     return 0;
   if (access == SND_PCM_ACCESS_MMAP_INTERLEAVED)
     return 0;
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -553,10 +553,10 @@
   params->channels = val;
 
   if (ioctl (pcm->fd, SNDCTL_DSP_CHANNELS, &params->channels) < 0)
-    return -errno;
+    return RETERR(errno);
 
   if (params->channels != val)
-    return -EINVAL;
+    return RETERR(EINVAL);
   pcm->channels = params->channels;
   return 0;
 }
@@ -571,7 +571,7 @@
   params->channels = *val;
 
   if (ioctl (pcm->fd, SNDCTL_DSP_CHANNELS, &params->channels) < 0)
-    return -errno;
+    return RETERR(errno);
 
   *val = params->channels;
   pcm->channels = params->channels;
@@ -589,7 +589,7 @@
 snd_pcm_hw_params_set_format (snd_pcm_t * pcm, snd_pcm_hw_params_t * params,
 			      snd_pcm_format_t format)
 {
-  int err = -EINVAL;
+  int err = RETERR(EINVAL);
   int tmp;
 
   dbg_printf2 ("snd_pcm_hw_params_set_format(%d)\n", format);
@@ -614,10 +614,10 @@
 
   tmp = params->oss_fmt;
   if (ioctl (pcm->fd, SNDCTL_DSP_SETFMT, &tmp) < 0)
-    return -errno;
+    return RETERR(errno);
 
   if (tmp != params->oss_fmt)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   return 0;
 }
@@ -654,7 +654,7 @@
   if (format == SND_PCM_FORMAT_S16_LE)
     return 0;
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -725,7 +725,7 @@
 {
   dbg_printf ("snd_pcm_hw_params_set_periods_max(%x, %x)\n", val, dir);
   return 0;
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -747,10 +747,10 @@
   params->speed = val;
 
   if (ioctl (pcm->fd, SNDCTL_DSP_SPEED, &params->speed) < 0)
-    return -errno;
+    return RETERR(errno);
 
   if (val != params->speed)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   return 0;
 }
@@ -794,7 +794,7 @@
   params->speed = *val;
 
   if (ioctl (pcm->fd, SNDCTL_DSP_SPEED, &params->speed) < 0)
-    return -errno;
+    return RETERR(errno);
 
   *val = params->speed;
   return 0;
@@ -824,7 +824,7 @@
   if (nonblock == 0)
     return 0;
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -846,10 +846,10 @@
  * \param size frames to be written
  * \return a positive number of frames actually read otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SN
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SN
 D_PCM_STATE_RUNNING)
- * \retval -EPIPE an overrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting f
+ * \retval RETERR(EPIPE) an overrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting f
 or an application recovery)
  *
  * If the blocking behaviour was selected, then routine waits until
@@ -870,7 +870,7 @@
   l = size * pcm->frame_size;
 
   if ((l = read (pcm->fd, buffer, l)) == -1)
-    return -errno;
+    return RETERR(errno);
   return l / pcm->frame_size;
 }
 
@@ -926,10 +926,10 @@
  * \param size frames to be written
  * \return a positive number of frames actually written otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SN
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SN
 D_PCM_STATE_RUNNING)
- * \retval -EPIPE an underrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting f
+ * \retval RETERR(EPIPE) an underrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting f
 or an application recovery)
  *
  * If the blocking behaviour is selected, then routine waits until
@@ -950,7 +950,7 @@
   l = size * pcm->frame_size;
 
   if ((l = write (pcm->fd, buffer, l)) == -1)
-    return -errno;
+    return RETERR(errno);
   return l / pcm->frame_size;
 }
 
@@ -958,13 +958,13 @@
  * \brief Resume from suspend, no samples are lost
  * \param pcm PCM handle
  * \return 0 on success otherwise a negative error code
- * \retval -EAGAIN resume can't be proceed immediately (audio hardware is probab
+ * \retval RETERR(EAGAIN) resume can't be proceed immediately (audio hardware is probab
 ly still suspended)
- * \retval -ENOSYS hardware doesn't support this feature
+ * \retval RETERR(ENOSYS) hardware doesn't support this feature
  *
  * This function can be used when the stream is in the suspend state
  * to do the fine resume from this state. Not all hardware supports
- * this feature, when an -ENOSYS error is returned, use the \link ::snd_pcm_prep
+ * this feature, when an RETERR(ENOSYS) error is returned, use the \link ::snd_pcm_prep
 are() \endlink
  * function to recovery.
  */
@@ -972,7 +972,7 @@
 snd_pcm_resume (snd_pcm_t * pcm)
 {
   dbg_printf ("snd_pcm_resume()\n");
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -986,7 +986,7 @@
   assert (ptr);
   *ptr = calloc (1, sizeof (snd_pcm_status_t));
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1011,7 +1011,7 @@
 snd_pcm_status (snd_pcm_t * pcm, snd_pcm_status_t * status)
 {
   dbg_printf ("snd_pcm_status()\n");
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -1022,7 +1022,7 @@
 snd_pcm_status_get_state (const snd_pcm_status_t * obj)
 {
   dbg_printf ("snd_pcm_status_get_state()\n");
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -1183,7 +1183,7 @@
   assert (ptr);
   *ptr = calloc (1, sizeof (snd_pcm_info_t));
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1322,12 +1322,12 @@
   if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
     {
       if (ioctl (pcm->fd, SNDCTL_DSP_GETOSPACE, &bi) == -1)
-	return -errno;
+	return RETERR(errno);
     }
   else
     {
       if (ioctl (pcm->fd, SNDCTL_DSP_GETISPACE, &bi) == -1)
-	return -errno;
+	return RETERR(errno);
     }
 
   dbg_printf3 ("snd_pcm_avail_update(pcm=%x)=%d\n", pcm,
@@ -1357,7 +1357,7 @@
   int tmp;
 
   if (ioctl (pcm->fd, SNDCTL_DSP_GETODELAY, &tmp) < 0)
-    return -errno;
+    return RETERR(errno);
 
   *delayp = tmp / pcm->frame_size;
   return 0;
@@ -1416,7 +1416,7 @@
     case SNDRV_PCM_FORMAT_IMA_ADPCM:
       return 4;
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
@@ -1474,11 +1474,11 @@
       return samples;
     case SNDRV_PCM_FORMAT_IMA_ADPCM:
       if (samples & 1)
-	return -EINVAL;
+	return RETERR(EINVAL);
       return samples / 2;
     default:
       assert (0);
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
@@ -1686,7 +1686,7 @@
     generate_sine(areas, offset, frames, &phase);
     commitres = snd_pcm_mmap_commit(pcm_handle, offset, frames);
     if (commitres < 0 || commitres != frames)
-      error(commitres >= 0 ? -EPIPE : commitres);
+      error(commitres >= 0 ? RETERR(EPIPE) : commitres);
       
     size -= frames;
   }
@@ -1708,7 +1708,7 @@
   if (pcm->stream == SND_PCM_STREAM_CAPTURE)
     return snd_pcm_readi (pcm, pcm->area[0].addr, frames);
 
-  return -EFAULT;
+  return RETERR(EFAULT);
 }
 
 /**
@@ -1743,7 +1743,7 @@
 snd_pcm_pause (snd_pcm_t * pcm, int enable)
 {
   dbg_printf ("snd_pcm_pause()\n");
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -1965,7 +1965,7 @@
 {
   *ptr = calloc (1, sizeof (snd_pcm_hw_params_t));
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1986,9 +1986,9 @@
  * \param size frames to be written
  * \return a positive number of frames actually written otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
- * \retval -EPIPE an underrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
+ * \retval RETERR(EPIPE) an underrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting for an application recovery)
  *
  * If the blocking behaviour is selected, then routine waits until
  * all requested bytes are played or put to the playback ring buffer.
@@ -2001,7 +2001,7 @@
 {
   dbg_printf ("snd_pcm_writen()\n");
   // Not supported
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -2011,9 +2011,9 @@
  * \param size frames to be written
  * \return a positive number of frames actually read otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
- * \retval -EPIPE an overrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
+ * \retval RETERR(EPIPE) an overrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting for an application recovery)
  *
  * If the blocking behaviour was selected, then routine waits until
  * all requested bytes are filled. The count of bytes can be less only
@@ -2026,7 +2026,7 @@
 {
   dbg_printf ("snd_pcm_readn()\n");
   // Not supported
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -2123,7 +2123,7 @@
  * \param pcm PCM handle
  * \param timeout maximum time in milliseconds to wait
  * \return a positive value on success otherwise a negative error code
- *         (-EPIPE for the xrun and -ESTRPIPE for the suspended status,
+ *         (RETERR(EPIPE) for the xrun and RETERR(ESTRPIPE) for the suspended status,
  *          others for general errors)
  * \retval 0 timeout occurred
  * \retval 1 PCM stream is ready for I/O
@@ -2154,7 +2154,7 @@
   dbg_printf ("select(%d, %x, %x, NULL, %x)\n",
 	      pcm->fd + 1, readfds, writefds, w);
   if (select (pcm->fd + 1, readfds, writefds, NULL, w) == -1)
-    return -errno;
+    return RETERR(errno);
 
   return FD_ISSET (pcm->fd, &fds);
 }
@@ -2169,7 +2169,7 @@
 {
   *ptr = calloc (1, sizeof (snd_pcm_sw_params_t));
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -2188,7 +2188,7 @@
 {
   dbg_printf ("snd_pcm_hw_params_get_period_time()\n");
   // TODO
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 int INTERNAL (snd_pcm_hw_params_get_buffer_time) (const snd_pcm_hw_params_t *
@@ -2197,7 +2197,7 @@
 {
   dbg_printf ("snd_pcm_hw_params_get_buffer_time()\n");
   // What's this?
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 struct _snd_mask
@@ -2270,9 +2270,9 @@
  * \param size frames to be written
  * \return a positive number of frames actually read otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
- * \retval -EPIPE an overrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
+ * \retval RETERR(EPIPE) an overrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting for an application recovery)
  *
  * If the blocking behaviour was selected, then routine waits until
  * all requested bytes are filled. The count of bytes can be less only
@@ -2294,9 +2294,9 @@
  * \param size frames to be written
  * \return a positive number of frames actually read otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
- * \retval -EPIPE an overrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
+ * \retval RETERR(EPIPE) an overrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting for an application recovery)
  *
  * If the blocking behaviour was selected, then routine waits until
  * all requested bytes are filled. The count of bytes can be less only
@@ -2318,9 +2318,9 @@
  * \param size frames to be written
  * \return a positive number of frames actually written otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
- * \retval -EPIPE an underrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
+ * \retval RETERR(EPIPE) an underrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting for an application recovery)
  *
  * If the blocking behaviour is selected, then routine waits until
  * all requested bytes are played or put to the playback ring buffer.
@@ -2344,9 +2344,9 @@
  * \param size frames to be written
  * \return a positive number of frames actually written otherwise a
  * negative error code
- * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
- * \retval -EPIPE an underrun occurred
- * \retval -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
+ * \retval RETERR(EBADFD) PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
+ * \retval RETERR(EPIPE) an underrun occurred
+ * \retval RETERR(ESTRPIPE) a suspend event occurred (stream is suspended and waiting for an application recovery)
  *
  * If the blocking behaviour is selected, then routine waits until
  * all requested bytes are played or put to the playback ring buffer.
@@ -2373,7 +2373,7 @@
 snd_pcm_link (snd_pcm_t * pcm1, snd_pcm_t * pcm2)
 {
   dbg_printf ("snd_pcm_link()\n");
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -2731,7 +2731,7 @@
     case SNDRV_PCM_FORMAT_IMA_ADPCM:
       return 4;
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
@@ -2752,7 +2752,7 @@
 {
   dbg_printf ("snd_async_add_pcm_handler()\n");
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 void *
@@ -2868,7 +2868,7 @@
 {
   dbg_printf ("snd_pcm_areas_copy()\n");
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/rawmidi.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/rawmidi.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/rawmidi.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/rawmidi.c	Tue Jun 26 22:19:47 2007
@@ -38,7 +38,7 @@
   ALIB_INIT ();
 
   if (!alib_appcheck ())
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   return 0;
 }
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/seq.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/seq.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/seq.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/seq.c	Tue Jun 26 22:19:47 2007
@@ -89,7 +89,7 @@
 	      mode);
 
   if (!alib_appcheck ())
-    return -ENODEV;
+    return RETERR(ENODEV);
 
   instance++;
 
@@ -104,12 +104,12 @@
     {
       fprintf (stderr, "salsa: snd_seq_open doesn't support streams=%d\n",
 	       streams);
-      return -EIO;
+      return RETERR(EIO);
     }
 #endif
 
   if ((seq = malloc (sizeof (*seq))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   dbg_printf ("Created sequencer seq=%x\n", seq);
 
@@ -132,7 +132,7 @@
 
     default:
       fprintf (stderr, "snd_seq_open: Unknown stream %x\n", streams);
-      return -ENODEV;
+      return RETERR(ENODEV);
     }
 
   if ((seq->fd = open (fname, oss_mode, 0)) == -1)
@@ -146,7 +146,7 @@
 		   "You can select another filename using environment variable %s_mididev%d\n",
 		   alib_appname, instance);
 	}
-      return -err;
+      return RETERR(err);
     }
 
   seq->streams = streams;
@@ -158,7 +158,7 @@
       if (seq->parser == NULL)
 	{
 	  fprintf (stderr, "libsalsa: Can't create MIDI parser\n");
-	  return -ENODEV;
+	  return RETERR(ENODEV);
 	}
     }
 
@@ -360,8 +360,8 @@
  *
  * If there is no input from sequencer, function falls into sleep
  * in blocking mode until an event is received,
- * or returns \c -EAGAIN error in non-blocking mode.
- * Occasionally, this function may return \c -ENOSPC error.
+ * or returns \c RETERR(EAGAIN) error in non-blocking mode.
+ * Occasionally, this function may return \c RETERR(ENOSPC) error.
  * This means that the input FIFO of sequencer overran, and some events are
  * lost.
  * Once this error is returned, the input FIFO is cleared automatically.
@@ -397,7 +397,7 @@
 
       // TODO Handling of nonblocking mode
       if ((l = read (seq->fd, buf, sizeof (buf))) == -1)
-	return -errno;
+	return RETERR(errno);
 
       midiparser_input_buf (seq->parser, buf, l);
 
@@ -489,7 +489,7 @@
 {
   dbg_printf ("snd_seq_query_next_port()\n");
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -526,7 +526,7 @@
 {
   dbg_printf ("snd_seq_subscribe_port()\n");
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 /**
@@ -842,7 +842,7 @@
 {
   dbg_printf ("snd_seq_port_info_get_port()\n");
 
-  return -EIO;
+  return RETERR(EIO);
 }
 
 /**
@@ -907,7 +907,7 @@
 {
   dbg_printf ("snd_seq_query_next_client()\n");
 
-  return -EIO;
+  return RETERR(EIO);
 }
 
 /**
@@ -1241,7 +1241,7 @@
   dbg_printf ("snd_seq_port_info_malloc()\n");
 
   if ((p = malloc (sizeof (*p))) == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   *ptr = p;
 
@@ -1270,7 +1270,7 @@
   *ptr = calloc (1, sizeof (snd_seq_queue_tempo_t));
   dbg_printf ("snd_seq_queue_tempo_malloc()=%x\n", *ptr);
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1337,7 +1337,7 @@
 {
   dbg_printf ("snd_seq_get_queue_timer(seq=%x, q=%d, timer=%X)\n", seq, q,
 	      timer);
-  return -ENXIO;		// TODO
+  return RETERR(ENXIO);		// TODO
 }
 
 
@@ -1355,7 +1355,7 @@
 snd_timer_query_open (snd_timer_query_t ** timer, const char *name, int mode)
 {
   dbg_printf ("snd_timer_query_open(name=%s, mode=%x)\n", name, mode);
-  return -ENXIO;		// TODO
+  return RETERR(ENXIO);		// TODO
 }
 
 /**
@@ -1389,7 +1389,7 @@
 
   *ptr = malloc (sizeof (snd_seq_client_info_t));
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1457,7 +1457,7 @@
 
   *ptr = malloc (sizeof (snd_seq_system_info_t));
   if (*ptr == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1740,7 +1740,7 @@
   *ptr = calloc (1, sizeof (snd_seq_queue_status_t));
   dbg_printf ("snd_seq_queue_status_malloc()=%x\n", *ptr);
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1793,7 +1793,7 @@
   *ptr = calloc (1, sizeof (snd_seq_remove_events_t));
   dbg_printf ("snd_seq_remove_events_malloc()=%x\n", *ptr);
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -1903,7 +1903,7 @@
 {
   dbg_printf ("snd_seq_extract_output(seq=%x)\n", seq);
 
-  return -EIO;
+  return RETERR(EIO);
 }
 
 /**
@@ -2051,7 +2051,7 @@
 
   dbg_printf ("snd_seq_query_subscribe_malloc()=%x\n", *ptr);
   if (!*ptr)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/seq_output.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/seq_output.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/seq_output.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/seq_output.c	Tue Jun 26 22:19:47 2007
@@ -25,11 +25,11 @@
   int l;
 
   if (msg < 0 || msg >= 0xff)
-    return -ERANGE;
+    return RETERR(ERANGE);
   if (parm1 < 0 || parm1 > 0x7f)
-    return -ERANGE;
+    return RETERR(ERANGE);
   if (parm2 < 0 || parm2 > 0x7f)
-    return -ERANGE;
+    return RETERR(ERANGE);
 
   buf[0] = msg;
   buf[1] = parm1;
@@ -38,9 +38,9 @@
   if ((l = write (seq->fd, buf, 3)) != 3)
     {
       if (l == -1)
-	return -errno;
+	return RETERR(errno);
 
-      return -EBADE;		/* Randomly selected error */
+      return RETERR(EBADE);		/* Randomly selected error */
     }
 
   return 0;
@@ -53,9 +53,9 @@
   int l;
 
   if (msg < 0 || msg >= 0xff)
-    return -ERANGE;
+    return RETERR(ERANGE);
   if (parm1 < 0 || parm1 > 0x7f)
-    return -ERANGE;
+    return RETERR(ERANGE);
 
   buf[0] = msg;
   buf[1] = parm1;
@@ -63,9 +63,9 @@
   if ((l = write (seq->fd, buf, 2)) != 2)
     {
       if (l == -1)
-	return -errno;
+	return RETERR(errno);
 
-      return -EBADE;		/* Randomly selected error */
+      return RETERR(EBADE);		/* Randomly selected error */
     }
 
   return 0;
@@ -87,7 +87,7 @@
 		   ev->data.control.channel,
 		   ev->data.control.param, ev->data.control.value);
       if (ev->data.control.channel > 15)
-	return -ERANGE;
+	return RETERR(ERANGE);
       return midi_out3 (seq, 0xB0 + ev->data.control.channel,
 			ev->data.control.param, ev->data.control.value);
       break;
@@ -97,7 +97,7 @@
 		   ev->data.control.channel,
 		   ev->data.control.param, ev->data.control.value);
       if (ev->data.control.channel > 15)
-	return -ERANGE;
+	return RETERR(ERANGE);
       return midi_out2 (seq, 0xC0 + ev->data.control.channel,
 			ev->data.control.value);
       break;
@@ -107,7 +107,7 @@
 		   ev->data.control.channel, ev->data.control.value);
       value = ev->data.control.value + 8192;
       if (ev->data.control.channel > 15)
-	return -ERANGE;
+	return RETERR(ERANGE);
       return midi_out3 (seq, 0xD0 + ev->data.control.channel,
 			value & 0x7f, (value >> 7) & 0x7f);
       break;
@@ -117,7 +117,7 @@
 		   ev->data.control.channel, ev->data.control.value);
       value = ev->data.control.value + 8192;
       if (ev->data.control.channel > 15)
-	return -ERANGE;
+	return RETERR(ERANGE);
       return midi_out3 (seq, 0xE0 + ev->data.control.channel,
 			value & 0x7f, (value >> 7) & 0x7f);
       break;
@@ -127,7 +127,7 @@
 		   ev->data.note.channel,
 		   ev->data.note.note, ev->data.note.velocity);
       if (ev->data.control.channel > 15)
-	return -ERANGE;
+	return RETERR(ERANGE);
       return midi_out3 (seq, 0x90 + ev->data.note.channel,
 			ev->data.note.note, ev->data.note.velocity);
       break;
@@ -137,7 +137,7 @@
 		   ev->data.note.channel,
 		   ev->data.note.note, ev->data.note.velocity);
       if (ev->data.control.channel > 15)
-	return -ERANGE;
+	return RETERR(ERANGE);
       return midi_out3 (seq, 0x80 + ev->data.note.channel,
 			ev->data.note.note, ev->data.note.velocity);
       break;
@@ -147,7 +147,7 @@
 		   ev->data.note.channel,
 		   ev->data.note.note, ev->data.note.velocity);
       if (ev->data.control.channel > 15)
-	return -ERANGE;
+	return RETERR(ERANGE);
       return midi_out3 (seq, 0xA0 + ev->data.note.channel,
 			ev->data.note.note, ev->data.note.velocity);
       break;
diff -urN oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/timer.c oss-v4.1test0-070624-src-gpl/lib/libsalsa/timer.c
--- oss-v4.1test0-070624-src-gpl.org/lib/libsalsa/timer.c	Tue Jun 12 14:24:22 2007
+++ oss-v4.1test0-070624-src-gpl/lib/libsalsa/timer.c	Tue Jun 26 22:19:47 2007
@@ -52,7 +52,7 @@
   if (!alib_appcheck ())
     {
       dbg_printf ("snd_timer_open(%s, %x) refused,\n", name, mode);
-      return -ENODEV;
+      return RETERR(ENODEV);
     }
 
   timer = malloc (sizeof (*timer));
@@ -60,7 +60,7 @@
   dbg_printf ("snd_timer_open(name='%s', mode=%x)=%x\n", name, mode, timer);
 
   if (timer == NULL)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
 
   *tmr = timer;
 
@@ -250,7 +250,7 @@
   *info = calloc (1, sizeof (snd_timer_info_t));
   dbg_printf ("snd_timer_info_malloc()=%x\n", *info);
   if (!*info)
-    return -ENOMEM;
+    return RETERR(ENOMEM);
   return 0;
 }
 
@@ -322,9 +322,9 @@
      name, timer_root, timer_conf, mode);
   ALIB_INIT ();
   if (!alib_appcheck ())
-    return -ENODEV;
+    return RETERR(ENODEV);
 
-  return -EIO;
+  return RETERR(EIO);
 }
 
 /**
diff -urN oss-v4.1test0-070624-src-gpl.org/misc/man9ossddk/ossddk_disable_device.9ossddk oss-v4.1test0-070624-src-gpl/misc/man9ossddk/ossddk_disable_device.9ossddk
--- oss-v4.1test0-070624-src-gpl.org/misc/man9ossddk/ossddk_disable_device.9ossddk	Wed Sep 14 12:01:05 2005
+++ oss-v4.1test0-070624-src-gpl/misc/man9ossddk/ossddk_disable_device.9ossddk	Tue Jun 26 22:19:47 2007
@@ -35,7 +35,7 @@
 OSS from accessing the driver any more.
 .PP
 .SH "RETURN VALUES"
-This function returns a negative value (-errno) if the device cannot be disabled at
+This function returns a negative value (RETERR(errno)) if the device cannot be disabled at
 this moment. In this case the driver should refuse to detach. Value of 0 means that
 the device was successfully disabled and the driver can proceed the detach operation.
 .PP
diff -urN oss-v4.1test0-070624-src-gpl.org/misc/man9ossddk/ossddk_install_audiodev.9ossddk oss-v4.1test0-070624-src-gpl/misc/man9ossddk/ossddk_install_audiodev.9ossddk
--- oss-v4.1test0-070624-src-gpl.org/misc/man9ossddk/ossddk_install_audiodev.9ossddk	Mon Feb 12 01:32:48 2007
+++ oss-v4.1test0-070624-src-gpl/misc/man9ossddk/ossddk_install_audiodev.9ossddk	Tue Jun 26 22:19:47 2007
@@ -233,7 +233,7 @@
 .PP
 .SH "RETURN VALUES"
 .PP
-Negative value is an error code (-errno). Zero or positive is the audio device
+Negative value is an error code (RETERR(errno)). Zero or positive is the audio device
 number created.
 .PP
 .SH "SEE ALSO"
diff -urN oss-v4.1test0-070624-src-gpl.org/misc/man9ossddk/ossddk_install_mixer.9ossddk oss-v4.1test0-070624-src-gpl/misc/man9ossddk/ossddk_install_mixer.9ossddk
--- oss-v4.1test0-070624-src-gpl.org/misc/man9ossddk/ossddk_install_mixer.9ossddk	Tue Sep 13 13:16:56 2005
+++ oss-v4.1test0-070624-src-gpl/misc/man9ossddk/ossddk_install_mixer.9ossddk	Tue Jun 26 22:19:48 2007
@@ -86,7 +86,7 @@
 .PP
 .SH "RETURN VALUES"
 .PP
-Negative value is an error code (-errno). Zero or positive is the mixer device
+Negative value is an error code (RETERR(errno)). Zero or positive is the mixer device
 number created.
 .PP
 .SH "SEE ALSO"
diff -urN oss-v4.1test0-070624-src-gpl.org/misc/samples/ddksample/ddksample_audio.c oss-v4.1test0-070624-src-gpl/misc/samples/ddksample/ddksample_audio.c
--- oss-v4.1test0-070624-src-gpl.org/misc/samples/ddksample/ddksample_audio.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/misc/samples/ddksample/ddksample_audio.c	Tue Jun 26 22:19:48 2007
@@ -171,7 +171,7 @@
 ddksample_ioctl (int dev, unsigned int cmd, int *arg)
 {
 // TODO 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static void ddksample_trigger (int dev, int state);
@@ -193,7 +193,7 @@
   if (portc->open_mode != 0)	/* Device busy */
     {
       mutex_exit (&devc->mutex);
-      return -EBUSY;
+      return RETERR(EBUSY);
     }
 
   portc->open_mode = mode;
@@ -348,7 +348,7 @@
   ossddk_dmap_set_phys (dmap, 0);	/* Not mmap() capable */
   ossddk_dmap_set_dmabuf (dmap, kmem_zalloc (MY_BUFFSIZE, KM_SLEEP));
   if (ossddk_dmap_get_dmabuf (dmap) == NULL)	/* Alloc failed */
-    return -ENOSPC;
+    return RETERR(ENOSPC);
   ossddk_dmap_set_buffsize (dmap, MY_BUFFSIZE);
 
   return 0;
diff -urN oss-v4.1test0-070624-src-gpl.org/misc/samples/ddksample/ddksample_mixer.c oss-v4.1test0-070624-src-gpl/misc/samples/ddksample/ddksample_mixer.c
--- oss-v4.1test0-070624-src-gpl.org/misc/samples/ddksample/ddksample_mixer.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/misc/samples/ddksample/ddksample_mixer.c	Tue Jun 26 22:19:48 2007
@@ -80,7 +80,7 @@
   ddksample_devc *devc = ossddk_mixer_get_devc (dev);
 
   if (ctl_id < 0 || ctl_id >= devc->num_portc)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_READ)
     {
@@ -112,7 +112,7 @@
     }
 
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -121,7 +121,7 @@
   ddksample_devc *devc = ossddk_mixer_get_devc (dev);
 
   if (ctl_id < 0 || ctl_id >= devc->num_portc)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_WRITE)
     {
@@ -137,7 +137,7 @@
       return portc->mute;
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -146,7 +146,7 @@
   ddksample_devc *devc = ossddk_mixer_get_devc (dev);
 
   if (ctl_id < 0 || ctl_id >= devc->num_portc)
-    return -EINVAL;
+    return RETERR(EINVAL);
 
   if (cmd == SNDCTL_MIX_WRITE)
     {
@@ -177,7 +177,7 @@
       return portc->left_volume | (portc->right_volume << 8);
     }
 
-  return -EINVAL;
+  return RETERR(EINVAL);
 }
 
 static int
@@ -324,7 +324,7 @@
       break;
 
     default:
-      return -EINVAL;
+      return RETERR(EINVAL);
     }
 }
 
diff -urN oss-v4.1test0-070624-src-gpl.org/oss/lib/flashsupport.c oss-v4.1test0-070624-src-gpl/oss/lib/flashsupport.c
--- oss-v4.1test0-070624-src-gpl.org/oss/lib/flashsupport.c	Tue Jun 12 14:22:35 2007
+++ oss-v4.1test0-070624-src-gpl/oss/lib/flashsupport.c	Tue Jun 26 22:19:48 2007
@@ -513,12 +513,12 @@
 		{
 		  switch (result)
 		    {
-		    case -EPIPE:
+		    case RETERR(EPIPE):
 		      {
 			snd_pcm_prepare (instance->handle);
 		      }
 		      break;
-		    case -ESTRPIPE:
+		    case RETERR(ESTRPIPE):
 		      {
 			err = snd_pcm_resume (instance->handle);
 			if (err < 0)
@@ -543,12 +543,12 @@
 	    {
 	      switch (avail)
 		{
-		case -EPIPE:
+		case RETERR(EPIPE):
 		  {
 		    snd_pcm_prepare (instance->handle);
 		  }
 		  break;
-		case -ESTRPIPE:
+		case RETERR(ESTRPIPE):
 		  {
 		    err = snd_pcm_resume (instance->handle);
 		    if (err < 0)
diff -urN oss-v4.1test0-070624-src-gpl.org/setup/BeOS/build.sh oss-v4.1test0-070624-src-gpl/setup/BeOS/build.sh
--- oss-v4.1test0-070624-src-gpl.org/setup/BeOS/build.sh	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/setup/BeOS/build.sh	Tue Jun 26 23:52:42 2007
@@ -0,0 +1,149 @@
+#!/bin/sh
+
+. ./.directories
+
+BEOS_SYSTEM=beos/system
+# to install as user addons
+#BEOS_SYSTEM=home/config
+
+DRVPREFIX=oss_
+
+rm -rf prototype
+
+mkdir prototype
+#mkdir prototype/etc
+#echo OSSLIBDIR=/usr/lib/oss > prototype/etc/oss.conf
+
+TXT2MAN=$SRCDIR/setup/txt2man
+
+if test ! -f /usr/local/bin/gawk
+then
+  # No gawk installed. Use the simple txt2man program instead of
+  # the fully featured shell script which depends on gawk.
+
+  rm -f txt2man
+  
+  cc -o txt2man $SRCDIR/setup/txt2man.c
+  
+  if test -f txt2man
+  then
+    TXT2MAN=./txt2man
+  fi
+fi
+
+mkdir -p prototype/$BEOS_SYSTEM/add-ons/kernel/drivers/bin
+mkdir -p prototype/$BEOS_SYSTEM/add-ons/kernel/drivers/dev/audio/multi
+mkdir -p prototype/home/config/settings/kernel/drivers
+
+#cp $SRCDIR/include/soundcard.h prototype/usr/include/sys
+
+#cp .version prototype/usr/lib/oss/version.dat
+
+#cp -R $SRCDIR/include/* prototype/usr/lib/oss/include/sys/
+#cp $SRCDIR/kernel/framework/include/midiparser.h prototype/usr/lib/oss/include/
+
+#cp -f target/bin/* prototype/usr/bin
+#cp -f target/sbin/* prototype/usr/sbin
+#cp -f $SRCDIR/setup/SCO_SV/sbin/* prototype/usr/sbin
+
+#cp -R $SRCDIR/oss prototype/usr/lib
+#cp -R $SRCDIR/setup/SCO_SV/oss prototype/usr/lib
+
+#ld -r -o prototype/usr/lib/oss/modules/osscore/Driver.o target/objects/*.o $SRCDIR/setup/SCO_SV/*.o $FPSUPPORT
+drv=prototype/$BEOS_SYSTEM/add-ons/kernel/drivers/bin/${DRVPREFIX}core
+#gcc -o $drv target/objects/*.o -nostdlib /boot/develop/lib/x86/_KERNEL_ || exit 1
+
+# try to build all in a single bin for now...
+gcc -o $drv target/objects/*.o target/modules/*.o -nostdlib /boot/develop/lib/x86/_KERNEL_ || exit 1
+exit 0
+##########
+
+#grep '^int' $SRCDIR/kernel/framework/osscore/options.c > prototype/usr/lib/oss/modules/osscore/Space.c
+
+rm -f devlist.txt
+
+for n in target/modules/*.o
+do
+	N=`basename $n .o`
+	#mkdir prototype/usr/lib/oss/modules/$N
+	#cp target/build/$N/* prototype/usr/lib/oss/modules/$N
+	#ld -r -o prototype/usr/lib/oss/modules/$N/Driver.o $n
+	drv=prototype/$BEOS_SYSTEM/add-ons/kernel/drivers/bin/${DRVPREFIX}$N
+	gcc -o $drv $n -nostdlib /boot/develop/lib/x86/_KERNEL_ || exit 1
+	longver="`cat .version`"
+	shortver="${longver%% *}"
+	appver="${shortver:0:1} ${shortver:0:1} 0 b ${shortver##*[a-z]}"
+	lic="`cat .license`"
+	copyright="`echo -n -e '\302\251'` 2007 4Front"
+	setversion $drv -app $appver -short $shortver -long "$longver $copyright $lic"
+	mimeset -f $drv
+
+# Now copy the man pages
+#	if test -f $SRCDIR/kernel/drv/$N/$N.man
+#        then
+#	     sed 's/CONFIGFILEPATH/\/usr\/lib\/oss\/conf/' < $SRCDIR/kernel/drv/$N/$N.man > /tmp/ossman.tmp
+#             $TXT2MAN -t "$N" -v "Devices" -s 7d /tmp/ossman.tmp > prototype/usr/man/man7/$N.7
+#	fi
+
+#        if test -f $SRCDIR/kernel/nonfree/drv/$N/$N.man
+#	then
+#	     sed 's/CONFIGFILEPATH/\/usr\/lib\/oss\/conf/' < $SRCDIR/kernel/nonfree/drv/$N/$N.man > /tmp/ossman.tmp
+#	     $TXT2MAN -t "$N" -v "Devices" -s 7d /tmp/ossman.tmp > prototype/usr/man/man7/$N.7
+#	fi
+
+echo Check devices for $N
+  	grep "^$N[ 	]" ./devices.list >> devlist.txt
+done
+
+#cp devlist.txt prototype/usr/lib/oss/etc/devices.list
+
+#sed 's/.*	//' <  devlist.txt|sort|uniq >$SRCDIR/devlists/OSR6
+cp devlist.txt $SRCDIR/devlists/BeOS
+
+# Generate Man pages for commands
+#for i in target/bin/*
+#do
+#CMD=`basename $i`
+#$TXT2MAN -t "$CMD" -v "User Commands" -s 1 cmd/$CMD/$CMD.man > prototype/usr/man/man1/$CMD.1
+#echo done $CMD
+#done
+
+#for i in target/sbin/*
+#do
+#  CMD=`basename $i`
+#  if test -f cmd/$CMD/$CMD.man
+#  then
+#	$TXT2MAN -t "$CMD" -v "System Administration Commands" -s 8 cmd/$CMD/$CMD.man > prototype/usr/man/man8/$CMD.8
+#	echo done $CMD
+#  fi
+#done
+
+#rm -f prototype/usr/man/man8/ossdetect.8
+#$TXT2MAN -t "ossdetect" -v "User Commands" -s 8 os_cmd/SCO_SV/ossdetect/ossdetect.man > prototype/usr/man/man8/ossdetect.8
+#echo done ossdetect
+
+## Licensing stuff
+#if test -f $SRCDIR/4front-private/osslic.c
+#then
+#	cc -o prototype/usr/sbin/osslic -Isetup -Ikernel/nonfree/include -Ikernel/framework/include -Iinclude -Ikernel/OS/SCO_SV -I$SRCDIR $SRCDIR/4front-private/osslic.c
+#	strip prototype/usr/sbin/osslic
+#	
+#	prototype/usr/sbin/osslic -q -u -3prototype/usr/lib/oss/modules/osscore/Driver.o
+#	
+#fi
+
+#if test -f 4front-private/ossupdate.c
+#then
+#  # ossupdate
+#  cc -I. 4front-private/ossupdate.c -s -o prototype/usr/sbin/ossupdate -lsocket -lbind
+#fi
+
+#chmod 700 prototype/usr/sbin/*
+#chmod 755 prototype/usr/bin/*
+
+#cp setup/SCO_SV/S89oss prototype/usr/lib/oss/etc
+#chmod 744 prototype/usr/lib/oss/etc/S89oss
+
+#exec sh $SRCDIR/setup/build_common.sh $SRCDIR
+
+exit 0
diff -urN oss-v4.1test0-070624-src-gpl.org/setup/BeOS/make.local oss-v4.1test0-070624-src-gpl/setup/BeOS/make.local
--- oss-v4.1test0-070624-src-gpl.org/setup/BeOS/make.local	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/setup/BeOS/make.local	Tue Jun 26 22:19:48 2007
@@ -0,0 +1,19 @@
+build: 	kernel/framework/include/buildid.h all
+	sh build.sh
+
+copy:	build
+	cp -R prototype/* /
+
+package:	build
+		cd setup/BeOS && sh mkpkg.sh
+
+tarball:	build
+		sh setup/BeOS/mktarball.sh
+
+deb:		package
+		alien --to-deb --scripts --keep-version oss-linux*.rpm
+
+install:	copy
+	cd /usr/lib/oss/build && sh install.sh
+	sync
+	soundoff && sync && soundon
diff -urN oss-v4.1test0-070624-src-gpl.org/setup/gen_driver_beos.inc oss-v4.1test0-070624-src-gpl/setup/gen_driver_beos.inc
--- oss-v4.1test0-070624-src-gpl.org/setup/gen_driver_beos.inc	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/setup/gen_driver_beos.inc	Tue Jun 26 22:19:48 2007
@@ -0,0 +1,178 @@
+static void
+generate_driver (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
+		 char *dirname, char *topdir)
+{
+
+  /* BeOS version */
+//XXX:WRITEME
+
+  FILE *f, *src;
+  char tmp[256], line[256], *p, *s;
+  int i, n = 0;
+  char *options[MAXOPTS];
+  int nopts = 0;
+
+  sprintf (tmp, "%s/%s", dirname, cfg_name);
+
+  if ((src = fopen (tmp, "w")) == NULL)
+    {
+      perror (tmp);
+      exit (-1);
+    }
+
+  fprintf (src, "/*\n");
+  fprintf (src, " * Automatically generated file - do not edit.\n");
+  fprintf (src, " */\n");
+
+
+/*
+ * Handle driver specific configuration options
+ */
+  sprintf (tmp, "%s/.params", dirname);
+  if ((f = fopen (tmp, "r")) != NULL)
+    {
+      while (fgets (line, sizeof (line) - 1, f) != NULL)
+	{
+	  p = line + strlen (line) - 1;
+	  if (*p == '\n')
+	    *p = 0;
+
+	  fprintf (src, "%s\n", line);
+	  if (strncmp (line, "int ", 4) == 0)
+	    {
+	      char *s = line + 4, *p = s;
+
+	      while (*p && *p != '=' && *p != ';')
+		p++;
+	      *p = 0;
+	      if (nopts >= MAXOPTS)
+		{
+		  fprintf (stderr, "Too many options for driver '%s' (%d)\n",
+			   name, nopts);
+		  exit (-1);
+		}
+
+	      options[nopts++] = strdup (s);
+	    }
+	}
+
+      fclose (f);
+    }
+
+  fprintf (src, "\n");
+  fprintf (src, "#include \"%s\"\n", cfg_header);
+  fprintf (src, "\n");
+
+  if ((f = fopen ("devices.list", "r")) == NULL)
+    {
+      perror ("devices.list");
+      exit (-1);
+    }
+
+  if (strcmp (conf->bus, "PCI") == 0)
+    {
+      fprintf (src, "static struct { uint32 vendor, product; } id_table[] = {\n");
+
+      while (fgets (line, sizeof (line) - 1, f) != NULL)
+	{
+	  int vendor, product;
+	  p = line + strlen (line) - 1;
+	  if (*p == '\n')
+	    *p = 0;
+
+	  p = line;
+	  while (*p && *p != '\t')
+	    p++;
+	  if (*p == '\t')
+	    *p++ = 0;
+
+	  if (strcmp (line, name) != 0)
+	    continue;
+
+	  n++;
+
+	  s = p;
+	  while (*p && *p != '\t')
+	    p++;
+	  if (*p == '\t')
+	    *p++ = 0;
+
+	  if (strncmp (s, "pci", 3) == 0)
+	    {
+	      if (sscanf (s + 3, "%x,%x", &vendor, &product) != 2)
+		{
+		  fprintf (stderr, "Bad PCI id %s\n", s);
+		}
+
+	      fprintf (src, "\t{0x%x,\t0x%x},\n", vendor, product);
+	    }
+
+	}
+
+      fclose (f);
+
+      fprintf (src, "\t{0}\n");
+      fprintf (src, "};\n");
+      fprintf (src, "\n");
+    }
+
+
+/*
+ * Create the driver specific option list
+ */
+  fprintf (src, "static oss_option_map_t local_driver_options[] =\n");
+  fprintf (src, "{\n");
+  for (i = 0; i < nopts; i++)
+    fprintf (src, "\t{\"%s\", &%s},\n", options[i], options[i]);
+  fprintf (src, "\t{NULL, NULL}\n");
+  fprintf (src, "};\n");
+  fprintf (src, "\n");
+
+  fprintf (src, "#include \"%s/%s/module.inc\"\n", topdir, this_os);
+
+  if (n == 0)
+    {
+      fprintf (stderr,
+	       "Warning: No device entries (devices.list) for driver %s\n",
+	       name);
+    }
+
+  fclose (src);
+
+  /* config header */
+
+  sprintf (tmp, "%s/%s", dirname, cfg_header);
+  if ((src = fopen (tmp, "w")) == NULL)
+    {
+      perror (tmp);
+      exit (-1);
+    }
+
+  fprintf (src, "/*\n");
+  fprintf (src, " * Automatically generated file - do not edit.\n");
+  fprintf (src, " */\n");
+
+  /* nudge all symbols to function pointers */
+  fprintf (src, "#define BUILDING_DRIVER\n");
+
+  fprintf (src, "#include <oss_config.h>\n");
+  fprintf (src, "\n");
+
+  fprintf (src, "#define DRIVER_NAME\t%s\n", name);
+  fprintf (src, "#define DRIVER_NICK\t\"%s\"\n", name);
+  fprintf (src, "#define DRIVER_STR_INFO\t%s_str_info\n", name);
+  fprintf (src, "#define DRIVER_PROBE\t%s_probe\n", name);
+  fprintf (src, "#define DRIVER_ATTACH\t%s_attach\n", name);
+  fprintf (src, "#define DRIVER_DETACH\t%s_detach\n", name);
+  fprintf (src, "#define DRIVER_TYPE\tDRV_%s\n", conf->bus);
+
+  fprintf (src, "#define DRIVER_MODULE_OBJECT\tgModule_%s\n", name);
+  fprintf (src, "\n");
+
+  fprintf (src, "extern int DRIVER_PROBE(void);\n");
+  fprintf (src, "extern int DRIVER_ATTACH(oss_device_t *ossdev);\n");
+  fprintf (src, "extern int DRIVER_DETACH(oss_device_t *ossdev);\n");
+
+  fclose (src);
+
+}
diff -urN oss-v4.1test0-070624-src-gpl.org/setup/setupdir.sh oss-v4.1test0-070624-src-gpl/setup/setupdir.sh
--- oss-v4.1test0-070624-src-gpl.org/setup/setupdir.sh	Sun Jun 24 18:05:22 2007
+++ oss-v4.1test0-070624-src-gpl/setup/setupdir.sh	Tue Jun 26 22:32:55 2007
@@ -21,7 +21,7 @@
 fi
 
 # pkg-config seems to crash in some systems so disable core dumps
-ulimit -c 0>/dev/null 2>&1
+ulimit -c 0 >/dev/null 2>&1
 
 if pkg-config gtk+-2.0 --cflags > /dev/null 2>&1
 then
diff -urN oss-v4.1test0-070624-src-gpl.org/setup/setupdir.sh~ oss-v4.1test0-070624-src-gpl/setup/setupdir.sh~
--- oss-v4.1test0-070624-src-gpl.org/setup/setupdir.sh~	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/setup/setupdir.sh~	Sun Jun 24 18:05:22 2007
@@ -0,0 +1,169 @@
+#!/bin/sh -e
+
+if test "$CONFIGURE " != "YES "
+then
+	echo
+	echo Error: Wrong usage
+	echo
+	echo You must run `dirname $0`/configure instead of $0
+	exit 1
+fi
+
+echo srcdir=$SRCDIR
+
+BLDDIR=`pwd`
+OS=`uname -s`
+
+# Use the same source directories for SCO UnixWare and SCO OSR
+if test "$OS " = "UnixWare "
+then
+	OS=SCO_SV
+fi
+
+# pkg-config seems to crash in some systems so disable core dumps
+ulimit -c 0>/dev/null 2>&1
+
+if pkg-config gtk+-2.0 --cflags > /dev/null 2>&1
+then
+  HAVE_GTK=y
+  export HAVE_GTK
+fi
+
+if gtk-config --cflags > /dev/null 2>&1
+then
+  HAVE_GTK=y
+  export HAVE_GTK
+fi
+
+if test "`ls .` " != " " && test "`ls .` " != ".makefile "
+then
+	echo Error: Current directory must be empty
+	exit 1
+fi
+
+if test -f $SRCDIR/setup/setupdir.sh
+then
+	echo Source directory is $SRCDIR
+	echo Build directory is $BLDDIR
+else
+	echo Error: Invalid source directory $SRCDIR
+	exit 2
+fi
+
+# Copy the ".devices" files for all drivers to devices.list
+cat `find $SRCDIR/kernel -name .devices`|grep -v '^#' > devices.list
+
+echo BLDDIR=$BLDDIR > .directories
+echo SRCDIR=$SRCDIR >> .directories
+
+cc -o dirsetup $SRCDIR/setup/dirsetup.c
+
+# Make sure the latest soundcard.h version is installed in the system
+#rm /usr/include/sys/soundcard.h
+#cp $SRCDIR/include/soundcard.h /usr/include/sys/soundcard.h
+
+if ./dirsetup "$SRCDIR" "$BLDDIR" $*
+then
+	echo Build tree created OK
+else
+	echo Cannot create the build tree
+	rm -f dirsetup
+	exit 3
+fi
+
+rm -f dirsetup
+
+cc -D`uname -s` -o srcconf $SRCDIR/setup/srcconf.c
+
+if ./srcconf $*
+then
+	echo Source configuration OK
+else
+	echo Source configuration failed
+fi
+
+if test ! -d target
+then
+	mkdir target
+fi
+
+mkdir target/bin
+mkdir target/sbin
+mkdir target/modules
+mkdir target/objects
+mkdir target/tmpobjects
+
+touch .depend
+
+if date -u +%Y%m%d%H%M > build.id.new 2>/dev/null
+then
+	rm -f build.id
+	mv build.id.new build.id
+	echo "#define OSS_COMPILE_DATE \""`cat build.id`"\"" >> kernel/framework/include/timestamp.h
+	echo "#define osdev_create osdev_create_`cat build.id`" >> kernel/framework/include/timestamp.h
+	echo
+	echo Build ID will become `cat build.id`
+else
+	echo Failed to create the build timestamp
+	exit 254
+fi
+
+if test -f $SRCDIR/.date
+then
+	# Use source package release date as the build ID
+
+	rm -f buildid.dat
+	cat $SRCDIR/.date > buildid.dat
+else
+	echo "#define LICENSED_VERSION" >> kernel/framework/include/timestamp.h
+fi
+
+if test -f $SRCDIR/buildid.dat
+then
+	echo '#define 'OSS_BUILD_ID \"`cat $SRCDIR/buildid.dat`\" > kernel/framework/include/buildid.h
+else
+	echo $SRCDIR/buildid.dat is missing
+	exit 10
+fi
+
+if test ! -d kernel/nonfree || test -f $SRCDIR/kernel/nonfree/.nomake
+then
+	echo '#define __OPENOSS__' >> kernel/framework/include/buildid.h
+	echo '#define OSS_LICENSE "/'`cat $SRCDIR/.license`'"' >> kernel/framework/include/buildid.h
+fi
+
+if test "$USE_REGPARM " = "1 "
+then
+	echo "1" > ./regparm
+fi
+
+if test "$NO_REGPARM " = "1 "
+then
+	echo "0" > ./regparm
+fi
+
+# Setup the link to the right os.h file for this operating system.
+(cd kernel/framework/include;ln -s ../../../kernel/OS/$OS/os_*.h os.h)
+
+cc -o ossvers -I./kernel/framework/include  setup/ossvers.c
+./ossvers > .version
+rm ./ossvers
+
+make dep
+
+ln -s $SRCDIR origdir
+if test -f setup/$OS/build.sh
+then
+	ln -s setup/$OS/build.sh .
+fi
+
+if test -f setup/$OS/make.local
+then
+	echo >> Makefile
+	echo include setup/$OS/make.local >> Makefile
+fi
+
+echo Directory preparation complete.
+echo Build ID will be `cat $SRCDIR/buildid.dat`
+
+exit 0
diff -urN oss-v4.1test0-070624-src-gpl.org/setup/srcconf.c oss-v4.1test0-070624-src-gpl/setup/srcconf.c
--- oss-v4.1test0-070624-src-gpl.org/setup/srcconf.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/setup/srcconf.c	Tue Jun 26 22:19:49 2007
@@ -329,6 +329,10 @@
 #include "gen_driver_sco.inc"
 #endif
 
+#if defined(__BEOS__)
+#include "gen_driver_beos.inc"
+#endif
+
 static int
 is_cplusplus (char *fname)
 {
@@ -671,6 +675,10 @@
 # endif
 #endif
 
+#if defined(__BEOS__)
+      fprintf (f, "CFLAGS=-O2 -D_KERNEL -D_KERNEL_MODE=1 -no-fpic\n");
+#endif
+
     }
 
   if (conf.mode != MD_KERNEL)
@@ -913,6 +921,10 @@
 
 #ifdef sun
 #include "srcconf_solaris.inc"
+#endif
+
+#ifdef __BEOS__
+#include "srcconf_beos.inc"
 #endif
 
 static void
diff -urN oss-v4.1test0-070624-src-gpl.org/setup/srcconf_beos.inc oss-v4.1test0-070624-src-gpl/setup/srcconf_beos.inc
--- oss-v4.1test0-070624-src-gpl.org/setup/srcconf_beos.inc	Thu Jan  1 01:00:00 1970
+++ oss-v4.1test0-070624-src-gpl/setup/srcconf_beos.inc	Tue Jun 26 22:19:49 2007
@@ -0,0 +1,39 @@
+#define HAVE_SYSDEP
+static void
+check_sysdep (conf_t * conf)
+{
+  struct utsname un;
+
+  if (uname (&un) == -1)
+    {
+      perror ("uname");
+      exit (-1);
+    }
+
+  if (strcmp (un.sysname, "Haiku") == 0)
+    strcpy (un.sysname, "BeOS");
+
+  strcpy (conf->cplusplus, "g++ -fno-rtti -fno-exceptions -I.");
+
+  /* fixup machine names */
+  if (strcmp (un.machine, "BePC") == 0)
+    {
+      strcpy (conf->arch, "i586");
+    }
+  if (strcmp (un.machine, "BePC") == 0 ||
+      strcmp (un.machine, "i386") == 0 ||
+      strcmp (un.machine, "i486") == 0 ||
+      strcmp (un.machine, "i586") == 0 || strcmp (un.machine, "i686") == 0)
+    {
+      strcpy (conf->platform, "i86pc");
+    }
+  if (strcmp (un.machine, "BeMac") == 0 ||
+      strcmp (un.machine, "BeBox") == 0)
+    {
+      /* XXX: those are PPC 
+      strcpy (conf->arch, "ppc");
+      strcpy (conf->platform, "ppc");*/
+      fprintf(stderr, "FIXME: convert arch/machine BeMac/BeBox\n");
+      exit(1);
+    }
+}
diff -urN oss-v4.1test0-070624-src-gpl.org/utils/snoopy.c oss-v4.1test0-070624-src-gpl/utils/snoopy.c
--- oss-v4.1test0-070624-src-gpl.org/utils/snoopy.c	Sun Jun 24 18:09:41 2007
+++ oss-v4.1test0-070624-src-gpl/utils/snoopy.c	Tue Jun 26 22:19:49 2007
@@ -880,7 +880,7 @@
  */
 
   if (!corb_read (mixer, cad, 0, 0, GET_PARAMETER, HDA_NODE_COUNT, &a, &b))
-    return -EIO;
+    return RETERR(EIO);
 
   first_node = (a >> 16) & 0xff;
   num_nodes = a & 0xff;
