[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

cdrtools-2.01.01a45 patches from NetBSD pkgsrc



Hi Joerg, hi everyone!

Some time ago I've taken over the task of keeping cdrtools in NetBSD
pkgsrc up-to-date. In this function I've inherited quite a few patches
and also wrote some of my own.

The current pkgsrc version is 2.01.01a45, the patches apply cleanly
against it.

I'll describe shortly what I know about them. Perhaps some of them can
be integrated, or you can suggest improvements on them that I can take
over into pkgsrc.

patch-aa, patch-ab, patch-ad: cdda2wav and cdrecord use realtime
functions (e.g. sched_setscheduler), which, on NetBSD, live in librt.
These patches are part of the support for this in the package. The
pkgsrc infrastructure passes in the correct value of $librt via the
build environment.
Instead, the build framework should test, if the symbol lives in librt
and link against it automatically. However, I'm not quite sure how you
want this test integrated into the build framework.

patch-ac:
NetBSD has machine/endian.h (and also sys/endian.h, which is the
same), which defines BIG_ENDIAN, LITTLE_ENDIAN and BYTE_ORDER.

patch-ah, patch-ba, patch-bb:
I'm not quite sure why they are here.

patch-ai, patch-ch, patch-ci:
Code to find the cd devices on NetBSD. Judging by the name in the
patch, it was written by frueauf@NetBSD.org, perhaps he can answer any
questions about it. util.h and libutil are needed for getrawpartition().

patch-aj:
The comment says it all: REQUEST SENSE was already done by the
kernel and the result just needs to be fetched.

patch-cf, patch-cg:
They were added with the message "Support files over 2 GB size." by
martin@NetBSD.org.

patch-cj:
A comment from dsainty@NetBSD.org says:
isoinfo extracts files at the painful rate of 1 sector at a time.
This patch speeds up file extraction significantly by using a much
larger buffer.

Two additional notes:
In pkgsrc exist rules that symlink 
DEFAULTS/Defaults.dragonfly and DEFAULTS_ENG/Defaults.dragonfly
to the resp. Defaults.freebsd file -- for cdrtools purposes, DragonFly
behaves exactly the same as FreeBSD.

And I have a problem with 2.01.01a46:
gmake[1]: Entering directory
`/scratch/sysutils/cdrtools/work/cdrtools-2.01.01/m
kisofs'
        ==> LINKING "OBJ/x86_64-netbsd-cc/mkisofs"
../libs/x86_64-netbsd-cc/libfind.a(find.o): In function `find_usage':
find.c:(.text+0x188): undefined reference to `gettext'
find.c:(.text+0x1a2): undefined reference to `gettext'
find.c:(.text+0x1b9): undefined reference to `gettext'
find.c:(.text+0x1d0): undefined reference to `gettext'
find.c:(.text+0x1e7): undefined reference to `gettext'
../libs/x86_64-netbsd-cc/libfind.a(find.o):find.c:(.text+0x1fe): more
undefined
references to `gettext' follow
gmake[1]: *** [OBJ/x86_64-netbsd-cc/mkisofs] Error 1

lib_intl is set to "" by the configure script, but it should be
"-lintl". I haven't debugged this further yet, so just FYI.

Please take a look at the patches, integrate them if possible, and
give feedback.

Thanks!
 Thomas

P.S.: Both schilling@fokus.fhg.de and
joerg@schily.isdn.cs.tu-berlin.de (the two addresses I first found on
the web) give me "User unknown" resp. "Domain not found" errors.
Both addresses are included in 2.01.01a46 in various places.
$NetBSD: patch-aa,v 1.7 2008/08/12 21:07:05 wiz Exp $

--- autoconf/configure.orig	2008-03-27 18:58:21.000000000 +0000
+++ autoconf/configure
@@ -14702,6 +14702,7 @@ fi
 
 if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
   echo "$ac_t""yes" 1>&6
+    lib_rt="$librt"
     ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
   cat >> confdefs.h <<EOF
 #define $ac_tr_func 1
$NetBSD: patch-ab,v 1.4 2008/07/29 22:05:31 wiz Exp $

--- cdda2wav/Makefile.orig	2008-06-24 20:19:39.000000000 +0000
+++ cdda2wav/Makefile
@@ -24,7 +24,7 @@ HFILES=		cdda2wav.h interface.h semshm.h
 		sndconfig.h scsi_cmds.h lowlevel.h byteorder.h mycdrom.h \
 		base64.h sha.h mmsystem.h cd_text.c cd_extra.c \
 		parse.h defaults.h version.h
-LIBS=		-lrscg -lscg $(LIB_VOLMGT) -lparanoia -ldeflt -lschily $(SCSILIB) $(EXTRALIB) $(LIB_SOCKET)
+LIBS=		-lrscg -lscg $(LIB_VOLMGT) -lparanoia -ldeflt -lschily $(SCSILIB) $(EXTRALIB) $(LIB_SOCKET) $(LIB_RT)
 XMK_FILE=	Makefile.man Makefile.rd cdda2ogg.mk1
 # cdda2ogg.mk1 fehlt noch f�e rel
 
$NetBSD: patch-ac,v 1.2 2007/03/16 22:04:53 bad Exp $

--- include/schily/btorder.h.orig	2007-01-16 15:19:12.000000000 +0100
+++ include/schily/btorder.h
@@ -27,6 +27,9 @@
 #ifndef	_SCHILY_TYPES_H
 #include <schily/types.h>		/* try to load isa_defs.h on Solaris */
 #endif
+#ifdef __NetBSD__
+#include <machine/endian.h>
+#endif
 
 /*
  * Convert bit-order definitions from xconfig.h into our values
@@ -103,7 +106,7 @@ error  Only one of _BIT_FIELDS_LTOH or _
 #	if defined(__ppc__) || defined(ppc) || defined(__ppc) || \
 	    defined(__PPC) || defined(powerpc) || defined(__powerpc__)
 
-#		if	defined(__BIG_ENDIAN__)
+#		if	defined(__BIG_ENDIAN__) || BYTE_ORDER == BIG_ENDIAN
 #			define _BIT_FIELDS_HTOL
 #		else
 #			define _BIT_FIELDS_LTOH
$NetBSD: patch-ad,v 1.4 2008/08/12 21:07:05 wiz Exp $

--- cdrecord/Makefile.orig	2008-08-03 15:28:16.000000000 +0000
+++ cdrecord/Makefile
@@ -44,7 +44,7 @@ HFILES=		cdrecord.h iso9660.h auheader.h
 HFILES_TAG=	../include/scg/scgio.h ../include/scg/scsidefs.h \
 		../include/scg/scsireg.h ../include/scg/scsitransp.h
 #LIBS=		-lschily $(LIB_SOCKET)
-LIBS=		-lrscg -lscg $(LIB_VOLMGT) -ledc_ecc -ldeflt -lschily $(SCSILIB) $(LIB_SOCKET)
+LIBS=		-lrscg -lscg $(LIB_VOLMGT) -ledc_ecc -ldeflt -lschily $(SCSILIB) $(LIB_SOCKET) $(LIB_RT)
 XMK_FILE=	Makefile.man Makefile.dfl Makefile.doc
 
 
$NetBSD: patch-ah,v 1.3 2007/03/16 22:04:54 bad Exp $

--- cdda2wav/setuid.c.orig	2006-11-11 22:40:01.000000000 +0100
+++ cdda2wav/setuid.c
@@ -116,7 +116,7 @@ needroot(necessary)
 	if (geteuid() == 0)
 		return; /* nothing to do */
 
-#if defined _POSIX_SAVED_IDS && defined(HAVE_SETEUID)
+#if defined(HAVE_SETEUID)
 	if (seteuid(effective_uid)) {
 		errmsg("Error with seteuid in needroot().\n");
 		exit(PERM_ERROR);
@@ -162,7 +162,7 @@ dontneedroot()
 	if (geteuid() != 0)
 		return; /* nothing to do */
 
-#if defined _POSIX_SAVED_IDS && defined(HAVE_SETEUID)
+#if defined(HAVE_SETEUID)
 	if (seteuid(real_uid)) {
 		errmsg("Error with seteuid in dontneedroot().\n");
 		exit(PERM_ERROR);
@@ -264,7 +264,7 @@ needgroup(necessary)
 	if (getegid() == effective_gid)
 		return; /* nothing to do */
 
-#if defined _POSIX_SAVED_IDS && defined(HAVE_SETEGID)
+#if defined(HAVE_SETEGID)
 	if (setegid(effective_gid)) {
 		errmsg("Error with setegid in needgroup().\n");
 		exit(PERM_ERROR);
@@ -302,7 +302,7 @@ dontneedgroup()
 	}
 	if (getegid() != effective_gid)
 		return; /* nothing to do */
-#if defined _POSIX_SAVED_IDS && defined(HAVE_SETEGID)
+#if defined(HAVE_SETEGID)
 	if (setegid(real_gid)) {
 		errmsg("Error with setegid in dontneedgroup().\n");
 		exit(PERM_ERROR);
$NetBSD: patch-ai,v 1.5 2007/09/18 23:07:26 wiz Exp $

--- libscg/scsi-bsd.c.orig	2007-03-25 20:18:56.000000000 +0000
+++ libscg/scsi-bsd.c
@@ -44,6 +44,7 @@ static	char __sccsid[] =
 
 #undef	sense
 #include <sys/scsiio.h>
+#include <util.h>
 
 /*
  *	Warning: you may change this source, but if you do that
@@ -52,7 +53,7 @@ static	char __sccsid[] =
  *	Choose your name instead of "schily" and make clear that the version
  *	string is related to a modified source.
  */
-LOCAL	char	_scg_trans_version[] = "scsi-bsd.c-1.44";	/* The version for this transport*/
+LOCAL	char	_scg_trans_version[] = "scsi-bsd.c-1.44nb1";	/* The version for this transport */
 
 #define	MAX_SCG		16	/* Max # of SCSI controllers */
 #define	MAX_TGT		16
@@ -112,7 +113,7 @@ scgo_version(scgp, what)
 		 * return "schily" for the SCG_AUTHOR request.
 		 */
 		case SCG_AUTHOR:
-			return (_scg_auth_schily);
+			return ("frueauf");
 		case SCG_SCCS_ID:
 			return (__sccsid);
 		}
@@ -144,6 +145,10 @@ scgo_open(scgp, device)
 	register int	l;
 	register int	nopen = 0;
 	char		devname[64];
+#if defined(__NetBSD__)
+	struct scsi_addr mysaddr;
+	int		myslicename = getrawpartition();
+#endif
 
 	if (busno >= MAX_SCG || tgt >= MAX_TGT || tlun >= MAX_LUN) {
 		errno = EINVAL;
@@ -170,6 +175,60 @@ scgo_open(scgp, device)
 	if ((device != NULL && *device != '\0') || (busno == -2 && tgt == -2))
 		goto openbydev;
 
+
+/*
+ * I know of no method in NetBSD to probe the scsibus and get the mapping
+ * busnumber,target,lun --> devicename.
+ *
+ * Because of this implement a true bruteforce hack to find
+ * out what cdroms there are.
+ *
+ * Note that this method only finds cd0-cd7. Anything higher
+ * than this needs additional tweaks.
+ *
+ * Feel free to implement this cleanly if you have better knowledge.
+ * Until then this helps to get -scanbus und thus xcdroast working :-)
+ *
+ */
+#if defined(__NetBSD__)
+	if (busno >= 0 && tgt >= 0 && tlun >= 0) {
+		for (l=0; l < MAX_LUN ; l++) {
+			sprintf(devname, "/dev/rcd%d%c", l, 'a' + myslicename);
+			f = open(devname, O_RDWR);
+			if (f >= 0) {
+				if (ioctl(f, SCIOCIDENTIFY, &mysaddr) < 0) {
+					close(f);
+					errno = EINVAL;
+					return (0);
+				}
+				if (busno == SADDR_BUS(mysaddr) && tgt == SADDR_TARGET(mysaddr) && tlun == SADDR_LUN(mysaddr)) {
+					scglocal(scgp)->scgfiles[busno][tgt][tlun] = f;
+					return(1);
+				}
+			}
+		}
+	} else for (l=0; l < MAX_LUN ; l++) {
+			sprintf(devname, "/dev/rcd%d%c", l, 'a' + myslicename);
+			f = open(devname, O_RDWR);
+			if (f >= 0) {
+				if (ioctl(f, SCIOCIDENTIFY, &mysaddr) < 0) {
+					close(f);
+					errno = EINVAL;
+					return (0);
+				}
+				scg_scsibus(scgp) = busno   = SADDR_BUS(mysaddr);
+				scg_target(scgp)  = tgt     = SADDR_TARGET(mysaddr);
+				if ((tlun >= 0) && (tlun != SADDR_LUN(mysaddr))) {
+					close(f);
+					errno = EINVAL;
+					return (0);
+				}
+				scg_lun(scgp)     = tlun    = SADDR_LUN(mysaddr);
+				if (scg_setup(scgp, f, busno, tgt, tlun))
+					nopen++;
+			}
+		}
+#else /* not __NetBSD__ */
 	if (busno >= 0 && tgt >= 0 && tlun >= 0) {
 
 		js_snprintf(devname, sizeof (devname),
@@ -206,6 +265,7 @@ scgo_open(scgp, device)
 			}
 		}
 	}
+#endif /* end of not __NetBSD__ */
 	/*
 	 * Could not open /dev/su-* or got dev=devname:b,l,l / dev=devname:@,l
 	 * We do the apropriate tests and try our best.
$NetBSD: patch-aj,v 1.3 2007/09/18 23:07:26 wiz Exp $

--- cdrecord/scsi_cdr.c.orig	2007-09-01 12:09:48.000000000 +0000
+++ cdrecord/scsi_cdr.c
@@ -340,7 +340,11 @@ request_sense_b(scgp, bp, cnt)
 {
 	register struct	scg_cmd	*scmd = scgp->scmd;
 
-
+#ifdef __NetBSD__
+	/* request sense already done by kernel */
+	memcpy(bp, scgp->scmd->u_sense.cmd_sense,
+	    (scgp->scmd->sense_count < cnt ? scgp->scmd->sense_count : cnt));
+#else
 	fillbytes((caddr_t)scmd, sizeof (*scmd), '\0');
 	scmd->addr = bp;
 	scmd->size = cnt;
@@ -355,6 +359,7 @@ request_sense_b(scgp, bp, cnt)
 
 	if (scg_cmd(scgp) < 0)
 		return (-1);
+#endif
 	return (0);
 }
 
$NetBSD: patch-ba,v 1.3 2007/09/18 23:07:26 wiz Exp $

--- readcd/readcd.c.orig	2007-08-12 20:45:39.000000000 +0000
+++ readcd/readcd.c
@@ -497,12 +497,12 @@ main(ac, av)
 	/*
 	 * We don't need root privilleges anymore.
 	 */
-#ifdef	HAVE_SETREUID
-	if (setreuid(-1, getuid()) < 0)
-#else
 #ifdef	HAVE_SETEUID
 	if (seteuid(getuid()) < 0)
 #else
+#ifdef	HAVE_SETREUID
+	if (setreuid(-1, getuid()) < 0)
+#else
 	if (setuid(getuid()) < 0)
 #endif
 #endif
$NetBSD: patch-bb,v 1.3 2007/09/18 23:07:27 wiz Exp $

--- mkisofs/mkisofs.c.orig	2007-08-20 16:18:07.000000000 +0000
+++ mkisofs/mkisofs.c
@@ -2239,12 +2239,12 @@ setcharset:
 		}
 	}
 	/* We don't need root privilleges anymore. */
-#ifdef	HAVE_SETREUID
-	if (setreuid(-1, getuid()) < 0)
-#else
 #ifdef	HAVE_SETEUID
 	if (seteuid(getuid()) < 0)
 #else
+#ifdef	HAVE_SETREUID
+	if (setreuid(-1, getuid()) < 0)
+#else
 	if (setuid(getuid()) < 0)
 #endif
 #endif
$NetBSD: patch-cf,v 1.3 2007/09/18 23:07:27 wiz Exp $

--- mkisofs/tree.c.orig	2007-08-20 16:34:53.000000000 +0000
+++ mkisofs/tree.c
@@ -1632,7 +1632,7 @@ insert_file_entry(this_dir, whole_path, 
 	/*
 	 * >= is required by the large file summit standard.
 	 */
-	if (S_ISREG(lstatbuf.st_mode) && (lstatbuf.st_size >= (off_t)0x7FFFFFFF)) {
+	if (S_ISREG(lstatbuf.st_mode) && (lstatbuf.st_size >= (off_t)0x0FFFFFFFF)) {
 #endif
 #ifdef	EOVERFLOW
 		errno = EOVERFLOW;
$NetBSD: patch-cg,v 1.4 2007/09/18 23:07:27 wiz Exp $

--- mkisofs/write.c.orig	2007-08-20 16:35:48.000000000 +0000
+++ mkisofs/write.c
@@ -372,7 +372,7 @@ write_one_file(filename, size, outfile)
 static	char		buffer[SECTOR_SIZE * NSECT];
 	FILE		*infile;
 	off_t		remain;
-	int	use;
+	off_t	use;
 	int	unroundeduse;
 	int	bytestowrite = 0;	/* Dummy init. to serve GCC bug */
 	int	correctedsize = 0;
@@ -499,7 +499,10 @@ static	char		buffer[SECTOR_SIZE * NSECT]
 			fflush(stderr);
 		}
 #endif
-		remain -= use;
+		if (use > remain)
+			remain = 0;
+		else
+			remain -= use;
 	}
 #ifdef APPLE_HYB
 #if defined(INSERTMACRESFORK) && defined(UDF)
$NetBSD: patch-ch,v 1.3 2007/06/21 18:16:16 wiz Exp $

--- RULES/i386-netbsd-cc.rul.orig	2007-05-09 12:25:30.000000000 +0000
+++ RULES/i386-netbsd-cc.rul
@@ -37,5 +37,6 @@ LIB_KVM=	
 
 #LDOPTS=		$(LIBS_PATH) $(LDPATH) $(RUNPATH:-R%=-Wl,-R%)
 LDOPTS=		$(LIBS_PATH) $(LDPATH)
+LDLIBS=		$(LIBS) $(LIBX) -lutil
 
 RANLIB=		@echo "	==> RANDOMIZING ARCHIVE \"$@\""; ranlib
$NetBSD: patch-ci,v 1.3 2007/06/21 18:16:16 wiz Exp $

--- RULES/i386-netbsd-gcc.rul.orig	2007-05-09 12:25:30.000000000 +0000
+++ RULES/i386-netbsd-gcc.rul
@@ -37,5 +37,6 @@ LIB_KVM=	
 
 #LDOPTS=		$(LIBS_PATH) $(LDPATH) $(RUNPATH:-R%=-Wl,-R%)
 LDOPTS=		$(LIBS_PATH) $(LDPATH)
+LDLIBS=		$(LIBS) $(LIBX) -lutil
 
 RANLIB=		@echo "	==> RANDOMIZING ARCHIVE \"$@\""; ranlib
$NetBSD: patch-cj,v 1.3 2007/09/18 23:07:27 wiz Exp $

isoinfo extracts files at the painful rate of 1 sector at a time.  This patch
speeds up file extraction significantly by using a much larger buffer.

--- mkisofs/diag/isoinfo.c.orig	2007-07-29 22:33:21.000000000 +0000
+++ mkisofs/diag/isoinfo.c
@@ -648,7 +648,7 @@ extract_file(idr)
 	struct iso_directory_record *idr;
 {
 	int		extent, len, tlen;
-	unsigned char	buff[2048];
+	unsigned char	buff[204800];
 
 #if	defined(__CYGWIN32__) || defined(__CYGWIN__) || defined(__EMX__) || defined(__DJGPP__)
 	setmode(fileno(stdout), O_BINARY);
@@ -658,16 +658,15 @@ extract_file(idr)
 	len = isonum_733((unsigned char *)idr->size);
 
 	while (len > 0) {
-#ifdef	USE_SCG
-		readsecs(extent - sector_offset, buff, ISO_BLOCKS(sizeof (buff)));
 		tlen = (len > sizeof (buff) ? sizeof (buff) : len);
+#ifdef	USE_SCG
+		readsecs(extent - sector_offset, buff, ISO_BLOCKS(tlen));
 #else
 		lseek(fileno(infile), ((off_t)(extent - sector_offset)) << 11, SEEK_SET);
-		tlen = (len > sizeof (buff) ? sizeof (buff) : len);
 		read(fileno(infile), buff, tlen);
 #endif
 		len -= tlen;
-		extent++;
+		extent += ISO_BLOCKS(tlen);
 		write(STDOUT_FILENO, buff, tlen);
 	}
 }

Reply to: