Usenet comp.os.linux.announce (1993-2013)
 help / color / mirror / Atom feed
From: gregg@bismarck.gatech.edu
Subject: New version of mkswap with optional size argument
Date: 30 Aug 1993 20:42:52 GMT	[thread overview]
Message-ID: <25tooc$q6s@samba.oit.unc.edu> (raw)

I have modified Linus' mkswap program so that the size argument is now
optional.  The modifications are trivial.  I got the source mkswap.c from
tsx-11.mit.edu:/pub/linux/sources/sbin/utile-1.5.tar.Z.  I added two
functions valid_offset and count_blocks written by Remy Card.  I got these
from his tsx-11.mit.edu:/pub/linux/BETA/ext2fs/e2fsprogs-0.3.tar.Z in the
file mke2fs.c.  The patch to Linus' source follows.

I will send mail to Rick Faith and see if I can get this added to his utile
package.

I am using this new mkswap together with mke2fs in an installation script.
It sure is handy not to have to prompt the user for a size which he/she
might screw up.

Greg Galloway
gregg@discovery.gatech.edu

11c11
<  * Usage: mkswap [-c] device size-in-blocks
---
>  * Usage: mkswap [-c] device [blocks]
16a17,20
>  *
>  * 30.8.93	Modified by Greg Galloway (gregg@discovery.gatech.edu)
>  *		to make size argument optional.  The functions valid_offset()
>  *		and count_blocks() are from Remy Card's mke2fs V0.3.
72c76
< #define usage() fatal_error("Usage: %s [-c] /dev/name blocks\n")
---
> #define usage() fatal_error("Usage: %s [-c] /dev/name [blocks]\n")
100a105,143
> int valid_offset (int fd, int offset)
> {
> 	char ch;
> 
> 	if (lseek (fd, offset, 0) < 0 )
> 		return 0;
> 	if (read (fd, &ch, 1) < 1 )
> 		return 0;
> 	return 1;
> }
> 
> int count_blocks (char *filename)
> {
> 	unsigned long high, low;
> 	int fd;
> 
> 	if ((fd = open (filename, O_RDONLY)) < 0 )
> 	{
> 		perror (filename);
> 		exit (1);
> 	}
> 	low = 0;
> 
> 	for (high = 1; valid_offset (fd, high); high *= 2 )
> 		low = high;
> 	while (low < high - 1)
> 	{
> 		const int mid = (low + high) / 2;
> 
> 		if (valid_offset (fd, mid))
> 			low = mid;
> 		else
> 			high = mid;
> 	}
> 	valid_offset (fd, 0);
> 	close (fd);
> 	return (low+1) / 1024 ;
> }
> 
124a168,169
> 	if (device_name && PAGES == 0)
> 		PAGES = count_blocks(device_name)>>2;

-- 
Send submissions for comp.os.linux.announce to: linux-announce@tc.cornell.edu


                 reply	other threads:[~1993-08-30 20:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox