From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4db,f9cf1b17a3f434b6,start X-Google-Attributes: gid10d4db,public X-Google-ArrivalTime: 1993-08-30 14:03:48 PST Path: gmd.de!newsserver.jvnc.net!udel!gatech!concert!samba.oit.unc.edu!bounce-bounce From: gregg@bismarck.gatech.edu Newsgroups: comp.os.linux.announce Subject: New version of mkswap with optional size argument Followup-To: comp.os.linux.misc Date: 30 Aug 1993 20:42:52 GMT Organization: None Message-ID: <25tooc$q6s@samba.oit.unc.edu> Reply-To: gregg@bismarck.gatech.edu NNTP-Posting-Host: calypso.oit.unc.edu Keywords: mkswap, swap space Originator: mdw@sunSITE 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