ftp.nice.ch/pub/next/tools/disk/ejectForNS3_0.s.tar.gz#/eject.src/eject.c

This is eject.c in view mode; [Download] [Up]

/*  eject.c

    Eric Smeesters: 15/06/1994
    Laboratoire de Telecommunications de Louvain (Belgique)

    Small program to eject (and unmount!), from ANY shell, the internal floppy
    disk of a NeXTstation.
*/


/***************************************** Preprocessing ********************/
#include 	<stdio.h>
#include 	<mntent.h>
#include	<strings.h>


/***************************************** main() ***************************/
int main( int argc, char *argv[])
{				  
    char 		umountCommand[100];
    FILE		*mtabFile;
    struct mntent 	*mnt;
    int			cmp;


					// Floppy path has to be specified
    if( argc<2)
    {  	fprintf( stderr, "Usage: %s <floppy name (path)>\n", argv[0]);
	return( -1);
    }
					// ... but cannot end with a '/'.
    if( (int )argv[1][strlen(argv[1])-1]=='/')
    {  	fprintf( stderr, "*** Floppy path cannot end with a '/'\n");
	return( -1);
    }

					// First tests the presence of the
					// internal floppy in the mount table
    cmp = 1; 
    mtabFile = fopen( "/etc/mtab", "r");
    while( (cmp!=0) && ((mnt=getmntent(mtabFile))!=NULL))
    {	cmp = strncmp( "/dev/fd0a", mnt->mnt_fsname, 9);
    }
    fclose( mtabFile);
					// ... and aborts if nothing.
    if( mnt==NULL)
    {	fprintf( stderr, "*** No /dev/rfd0a in the mount table\n");
	return( -1);
    }


					// Unmounts the internal floppy.
    sprintf( umountCommand, "/usr/etc/umount -v %s", argv[1]);
    system( umountCommand);
    
					// Tests if the internal floppy really
					// has been unmounted
    cmp=1;
    mtabFile = fopen( "/etc/mtab", "r");
    while( (cmp!=0) && ((mnt=getmntent(mtabFile))!=NULL))
    {	cmp = strncmp( "/dev/fd0a", mnt->mnt_fsname, 9);
    }
    fclose( mtabFile);
					// ... and ejects floppy disk only if
					// /dev/rfd0a isn't in the mount table.
    if( mnt==NULL)
    {	system( "/usr/etc/disk -e /dev/rfd0a");
	printf( "disk: floppy ejected from /dev/rfd0a\n"); 
    }
    else
    { 	fprintf( stderr, "*** Floppy not ejected (because still mounted)!\n");
    }


    return( 0);
}


/****************************************************************************/

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.