Subject: Re: [need review] pax(1) fast list/extract on raw disk device
To: None <tech-userlevel@netbsd.org>
From: David Brownlee <abs@netbsd.org>
List: tech-kern
Date: 02/10/2000 02:21:37
	Do you need to check for sockets as well as pipes?
	Does it make more sense to have the lseek() case automatically
	fall back to read(), just in case?

		David/absolute

On Thu, 10 Feb 2000, ITOH Yasufumi wrote:

> I'd like to make this modification to accelerate pax(1) listing on
> raw disk devices.  Please review.
> 
> 
> I have a disk drive of removable media:
> 
> sd2 at scsibus0 targ 3 lun 0: <FUJITSU, M2513EL, 0020> SCSI2 7/optical removable
> 606 MB, 151 cyl, 64 head, 32 sec, 2048 bytes/sect x 310352 sectors
> 
> I use tar (or pax) on the raw device since NetBSD doesn't support
> block devices (or filesystems) on non 512bytes/sectore disks.
> 
> Here, the listing on the device such as
> 	% pax -v -f /dev/rsd0c
> is very slow, since pax uses read(2), not lseek(2), to
> seek the next position on the device.
> 
> By the following changes, pax uses lseek() on devices
> if the device is not a tape drive.
> 
> Is this OK?
> 
> Regards,
> -- 
> ITOH, Yasufumi <itoh@netbsd.org>
> 
> diff -uF^[a-zA-Z_][a-z 	A-Z0-9_]*(.*[^;]$ ar_io.c.orig ar_io.c
> --- ar_io.c.orig	Mon Oct 25 08:16:15 1999
> +++ ar_io.c	Wed Feb  9 21:13:52 2000
> @@ -865,7 +865,7 @@ ar_fow(sksz, skipped)
>  	 * number of physical blocks to skip (we do not know physical block
>  	 * size at this point), so we must only read foward on tapes!
>  	 */
> -	if (artyp != ISREG) 
> +	if (artyp == ISTAPE || artyp == ISPIPE)
>  		return(0);
>  
>  	/*
> @@ -878,13 +878,16 @@ ar_fow(sksz, skipped)
>  		 * deal with the end of file (it will go to next volume by
>  		 * itself)
>  	 	 */
> -		if ((mpos = cpos + sksz) > arsb.st_size) {
> -			*skipped = arsb.st_size - cpos;
> +		mpos = cpos + sksz;
> +		if (artyp == ISREG && mpos > arsb.st_size)
>  			mpos = arsb.st_size;
> -		} else
> -			*skipped = sksz;
> -		if (lseek(arfd, mpos, SEEK_SET) >= 0)
> +		if ((mpos = lseek(arfd, mpos, SEEK_SET)) >= 0) {
> +			*skipped = mpos - cpos;
>  			return(0);
> +		}
> +	} else {
> +		if (artyp != ISREG)
> +			return(0);		/* non-seekable device */
>  	}
>  	syswarn(1, errno, "Foward positioning operation on archive failed");
>  	lstrval = -1;
>