ivfix: program to patch iv(1M) on UNIX pc to allow >1024 cyls
Lenny Tropiano
lenny at icus.islp.ny.us
Sun Jul 30 05:50:19 AEST 1989
See program comments for more information ...
--- cut here --- --- cut here --- --- cut here --- --- cut here ---
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: Makefile ivfix.c
# Wrapped by lenny at icus on Sat Jul 29 15:49:16 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(346 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile to compile ivfix.c (iv(1M) >1024 cylinders binary patch)
X# By Lenny Tropiano
X# (c)1989 ICUS Software Systems UUCP: ...icus!lenny -or- lenny at icus.islp.ny.us
X#
XCFLAGS=-v -O
XLDFLAGS=-s
XLIBS=/lib/crt0s.o /lib/shlib.ifile
X#
Xivfix: ivfix.o
X @echo "Loading ..."
X $(LD) $(LDFLAGS) -o ivfix ivfix.o $(LIBS)
X#
Xclean:
X rm -f ivfix *.o core
END_OF_Makefile
if test 346 -ne `wc -c <Makefile`; then
echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f ivfix.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"ivfix.c\"
else
echo shar: Extracting \"ivfix.c\" \(6078 characters\)
sed "s/^X//" >ivfix.c <<'END_OF_ivfix.c'
X/************************************************************************\
X** **
X** Program name: ivfix.c (Fix iv to allow it to format >1024 cyls) **
X** Programmer: Lenny Tropiano **
X** E-Mail address: ...!icus!lenny -or- lenny at icus.islp.ny.us **
X** Organization: ICUS Software Systems (c)1989 **
X** Date: July 29, 1989 **
X** **
X**************************************************************************
X** **
X** Program use: Run this program only once, it will convert /etc/iv **
X** so that it will allow you to format >1024 cylinders **
X** **
X** Hopefully this fix will be put in the forthcoming **
X** fixdisk by AT&T. Right now it checks to see if the **
X** cylinder field is between 0 and 1024, I increased it **
X** to 0 and 1400 (HDMAXCYL from <sys/gdisk.h>) **
X** **
X** If you rather not use this program, and binary edit **
X** /etc/iv yourself, then change the string of octal **
X** digits: 014 150 004 000 000 010 143 to: **
X** 014 150 005 170 000 010 143 **
X** **
X** After it is run, the new iv program is in /etc/iv.new. **
X** It is up to you whether you want to rename the old one **
X** to /etc/iv.old, and the new one to /etc/iv. I'd **
X** suggest you keep the old one around, just in case **
X** someone finds this doesn't work. **
X** **
X** Disclaimer: If someone wants to donate a Maxtor XT2190 (or another **
X** drive with >1024 cylinders), I'd be perfectly willing **
X** to TEST this myself. Right now this is an UNTESTED **
X** binary patch. If someone does try this, USE AT YOUR **
X** OWN RISK. Make sure you have a backup, or don't care **
X** about the data on the drive (I assume you if you are **
X** about to format, you don't care about the data) **
X** I don't take responsibility for anything this patch **
X** does to your machine. **
X** **
X** Derived from: dstconvert, previously released to the net. **
X**************************************************************************
X** Permission is granted to distribute this program by any means as **
X** long as credit is given for my work. I would also like to see **
X** any modifications or enhancements to this program. **
X\************************************************************************/
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X
Xchar *progname; /* program name */
X
X#undef TRUE
X#define TRUE 1
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X char *infile = "/etc/iv",
X *outfile = "/etc/iv.new";
X FILE *infp,
X *outfp,
X *fopen();
X int fix_iv(), changed_flag;
X
X progname = argv[0];
X
X if ((infp = fopen(infile,"r")) == NULL) {
X fprintf(stderr,"%s: cannot open %s for read\n",
X progname, infile);
X perror(progname);
X exit(1);
X }
X
X if ((outfp = fopen(outfile,"w")) == NULL) {
X fprintf(stderr,"%s: cannot open %s for write\n",
X progname, outfile);
X perror(progname);
X exit(1);
X }
X
X changed_flag = fix_iv(infp, outfp);
X
X fclose(infp);
X
X if (changed_flag == 1) {
X printf("%s: %s fixed to allow >1024 cylinders, see %s.\n",
X progname, infile, outfile);
X fclose(outfp);
X change_file_stats(infile, outfile);
X } else if (changed_flag == -1) {
X fprintf(stderr,"%s: %s already fixed.\n",
X progname, infile);
X fclose(outfp);
X unlink(outfile);
X exit(1);
X } else {
X fprintf(stderr,"%s: binary pattern not found in %s, incorrect version.\n",
X progname, infile);
X fclose(outfp);
X unlink(outfile);
X exit(1);
X }
X
X exit(0);
X
X}
X
Xint fix_iv(infp, outfp)
XFILE *infp, *outfp;
X{
X int fgetc(), ch1, ch2, ch3, ch4, changed_flag;
X long offset;
X
X changed_flag = 0;
X ch1 = fgetc(infp); /* read four bytes to make sure it's in */
X ch2 = fgetc(infp); /* the correct area when patching the */
X ch3 = fgetc(infp); /* binary, and not at some other */
X ch4 = fgetc(infp); /* with those same byte values */
X while (TRUE) {
X if (ch1 == EOF || ch2 == EOF || ch3 == EOF || ch4 == EOF) {
X if (ch1 != EOF)
X fputc(ch1, outfp);
X if (ch2 != EOF)
X fputc(ch2, outfp);
X if (ch3 != EOF)
X fputc(ch3, outfp);
X if (ch4 != EOF)
X fputc(ch4, outfp);
X return changed_flag;
X } else {
X if (ch1 == 0150 &&
X ch2 == 04 &&
X ch3 == 00 &&
X ch4 == 00) {
X ch2 = 05;
X ch3 = 0170;
X changed_flag = 1;
X } else if (ch1 == 0150 &&
X ch2 == 05 &&
X ch3 == 0170 &&
X ch4 == 00)
X changed_flag = -1;
X
X fputc(ch1, outfp);
X ch1 = ch2;
X ch2 = ch3;
X ch3 = ch4;
X ch4 = fgetc(infp);
X }
X }
X}
X
Xchange_file_stats(infile, outfile)
Xchar *infile, *outfile;
X{
X struct stat statbuf; /* file modes */
X ushort owner, group; /* owner and group */
X ushort mode; /* permission */
X
X if (stat(infile, &statbuf) == -1) {
X perror("Can't stat(2)");
X exit(1);
X }
X owner = statbuf.st_uid;
X group = statbuf.st_gid;
X mode = statbuf.st_mode;
X
X if (chmod(outfile, mode) == -1) {
X perror("Can't chmod(2)");
X exit(1);
X }
X
X if (chown(outfile, owner, group) == -1) {
X perror("Can't chown(2)");
X exit(1);
X }
X}
END_OF_ivfix.c
if test 6078 -ne `wc -c <ivfix.c`; then
echo shar: \"ivfix.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
--
Lenny Tropiano ICUS Software Systems [w] +1 (516) 589-7930
lenny at icus.islp.ny.us Telex; 154232428 ICUS [h] +1 (516) 968-8576
{ames,talcott,decuac,hombre,pacbell,sbcs}!icus!lenny attmail!icus!lenny
ICUS Software Systems -- PO Box 1; Islip Terrace, NY 11752
More information about the Unix-pc.sources
mailing list