
/*

From casper@fwi.uva.nl Tue Jun 14 11:15:43 EDT 1994
Article: 16814 of comp.unix.solaris
Path: babbage.ece.uc.edu!news.kei.com!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!sun4nl!fwi.uva.nl!casper
From: casper@fwi.uva.nl (Casper H.S. Dik)
Newsgroups: comp.unix.solaris
Subject: Re: UFS Format between Solaris 1.1 & 2.3
Date: 14 Jun 1994 14:42:03 GMT
Organization: FWI, University of Amsterdam
Lines: 121
Distribution: world
Message-ID: <2tkfjr$pti@mail.fwi.uva.nl>
References: <S_FITCH.13.000E92FD@open.ac.uk> <2teoma$o0v@mail.fwi.uva.nl> <S_FITCH.15.000D2FB1@open.ac.uk> <2thrsf$apf@mail.fwi.uva.nl> <S_FITCH.16.0008C185@open.ac.uk>
NNTP-Posting-Host: adam.fwi.uva.nl

S_FITCH@open.ac.uk (Stephen Fitch) writes:


>This is all very well for new code, but how could we apply these ioctl's
>to 'dump/restore' ? Apologies if I should have consulted the FAQ on this
>one. The long restore waits I mentioned in a previous posting are when we
>have to sit around waiting for 'ufsrestore' to drag files back from our
>8200/8500 exabyte decks. Do these ioctls have an application in this case ?

Yes.  You ioctl the filesystem you want to restore on.

Here's a program once posted by someone whose name I can't
find back.  I since made it compile on Solaris 2.x as well.
Requires SunOS 4.1.2 or later.

What you do is this:

	# cd /dir/you/want/to/restore/to
	# fastfs . fast
	# retore rf <tape>

And see the bytes fly.

Casper
*/
/* 
 * This programs turns on/off delayed I/O on a filesystem.
 * 
 * Usage:   fastfs filesystem fast|slow|status
 *
 * Note that it is intended for use with restore(8)
 * to speed up full filesystem restores. Remember
 * that if a filesystem is running with delayed I/O
 * enabled when the system crashes it can result in
 * fsck being unable to "fix" the filesystem on reboot
 * without manual intervention.
 *
 * Typical use is
 *
 * fastfs /home fast
 * cd /home; restore rf /dev/rst5
 * fastfs /home slow
 *
 * The above gives about a 500% increase in the speed of
 * the restore (your milage may vary).
 *
 * Its also good for /tmp giving most of the benifits of tmpfs
 * without the problems.
 *
 * In rc.local
 *
 * fastfs /tmp fast
 *
 * but you may need to add fsck -y /tmp into /etc/rc.boot
 * before the real fsck to ensure the machine always boots
 * (I have not done this yet).
*/

#include <stdio.h> 
#include <sys/ioctl.h>
#include <sys/filio.h>
#include <fcntl.h>
#include <errno.h>
#ifndef FIODIO
#define FIODIO _FIOSDIO
#define FIODIOS _FIOGDIO
#endif

extern char *sys_errlist[];


int
main(argc, argv)
int argc;
char	**argv;
{
    int fd;
    int flag;
    
    if (geteuid() != 0)
    {
	fprintf(stderr,"%s: Must run as root.\n", argv[0]);
	exit(1);
    }

    if (argc != 3)
    {
	fprintf(stderr,"Usage: %s path {fast|slow|status}\n",argv[0]);
	exit(2);
    }
    
    if ((fd = open(argv[1], O_RDONLY)) < 0)
    {
	fprintf(stderr,"%s: Unable to open \"%s\"\n%s\n", argv[0], argv[1], sys_errlist[errno]);
	exit(3);
    }
    
    if (!strcasecmp(argv[2], "status"))
    {
	if (ioctl(fd, FIODIOS, &flag) != 0)
	{
	    fprintf(stderr,"%s: ioctl failed%s\n", argv[0], sys_errlist[errno]);
	    exit(4);
	}
	if (flag == 0) printf("%s is slow.\n", argv[1]);
	else printf("%s is fast\n", argv[1]);
	exit(0);
    }
    
    flag = (strcasecmp(argv[2], "fast") == 0) ? 1 : 0;
    
    if (ioctl(fd, FIODIO, &flag) != 0)
    {
	fprintf(stderr,"%s: ioctl failed\n%s\n", argv[0], sys_errlist[errno]);
	exit(5);
    }
    
    printf("%s is now %s\n",argv[1], flag ? "fast" : "slow");
    exit(0);

}


