1996-01-29 06:20:12 +00:00
|
|
|
/*
|
|
|
|
* renram5
|
|
|
|
*
|
|
|
|
* This program is intended to be launched during boot time. It
|
|
|
|
* renames the volume /RAM5 to /tmp if /tmp does not already exist.
|
|
|
|
*
|
|
|
|
* It can also be invoked as a shell command (in which it should
|
|
|
|
* be changed to an exec file rather than a s16 file). As a shell
|
|
|
|
* command, its usage is:
|
|
|
|
* renram5 [-d] [ oldname [newname]]
|
|
|
|
*
|
|
|
|
* If <oldname> is not specified, it defaults to "/RAM5". If <newname> is
|
|
|
|
* not specified, it defaults to "/tmp". The -d flag enables debugging
|
|
|
|
* output.
|
|
|
|
*
|
|
|
|
* You probably need GNO/ME libraries in order to link this program.
|
|
|
|
*
|
|
|
|
* Written by Devin Reade <gdr@myrias.com> January 1996.
|
|
|
|
* This program is placed in the public domain.
|
|
|
|
*
|
1997-09-21 22:27:40 +00:00
|
|
|
* $Id: renram5.c,v 1.2 1997/09/21 22:27:40 gdr Exp $
|
|
|
|
*
|
|
|
|
* This file is formatted with tab tops every 8 columns.
|
1996-01-29 06:20:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <types.h>
|
|
|
|
#include <gsos.h>
|
|
|
|
#include <orca.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#ifndef P_tmpdir
|
|
|
|
#define P_tmpdir "/tmp"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define OLD_TMP "/RAM5"
|
|
|
|
#define NEW_TMP P_tmpdir
|
|
|
|
|
|
|
|
extern GSString255Ptr __C2GSMALLOC(char *);
|
|
|
|
extern int _mapErr(int);
|
|
|
|
|
|
|
|
void usage(char *progname) {
|
1997-09-21 22:27:40 +00:00
|
|
|
printf("Usage: %s [-d] [oldvolume [newvolume]]\n",progname);
|
1996-01-29 06:20:12 +00:00
|
|
|
printf("\toldvolume defaults to %s\n",OLD_TMP);
|
|
|
|
printf("\tnewvolume defaults to %s\n",NEW_TMP);
|
|
|
|
printf("\t-d\tproduce debug information\n\n");
|
|
|
|
printf("This program renames volumes. It was intended to rename\n");
|
|
|
|
printf("%s at boot time. As a side effect, it can also rename files.\n\n",
|
1997-09-21 22:27:40 +00:00
|
|
|
OLD_TMP);
|
|
|
|
printf("Version 1.0 by Devin Reade <gdr@myrias.com>\n");
|
1996-01-29 06:20:12 +00:00
|
|
|
printf("This program is in the public domain.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv) {
|
1997-09-21 22:27:40 +00:00
|
|
|
DevNumRecGS devrec;
|
1996-01-29 06:20:12 +00:00
|
|
|
ChangePathRecGS pathrec;
|
|
|
|
char *file1, *file2;
|
|
|
|
int i, filecount, debug;
|
1997-09-21 22:27:40 +00:00
|
|
|
|
1996-01-29 06:20:12 +00:00
|
|
|
filecount=0;
|
|
|
|
debug=0;
|
1997-09-21 22:27:40 +00:00
|
|
|
|
1996-01-29 06:20:12 +00:00
|
|
|
/* parse the command line, if any */
|
|
|
|
if (argc > 1) {
|
1997-09-21 22:27:40 +00:00
|
|
|
for (i=1; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i],"-d")) {
|
|
|
|
debug++;
|
|
|
|
} else if ((argv[i][0] == '-') || (filecount > 2)) {
|
|
|
|
usage(argv[0]);
|
|
|
|
} else if (filecount==0) {
|
|
|
|
file1 = argv[i];
|
|
|
|
filecount++;
|
|
|
|
} else if (filecount==1) {
|
|
|
|
file2 = argv[i];
|
|
|
|
filecount++;
|
|
|
|
} else assert(0);
|
|
|
|
}
|
1996-01-29 06:20:12 +00:00
|
|
|
}
|
|
|
|
switch (filecount) {
|
|
|
|
case 0:
|
1997-09-21 22:27:40 +00:00
|
|
|
file1 = OLD_TMP;
|
|
|
|
file2 = NEW_TMP;
|
|
|
|
break;
|
1996-01-29 06:20:12 +00:00
|
|
|
case 1:
|
1997-09-21 22:27:40 +00:00
|
|
|
file2 = NEW_TMP;
|
|
|
|
break;
|
1996-01-29 06:20:12 +00:00
|
|
|
case 2:
|
1997-09-21 22:27:40 +00:00
|
|
|
break;
|
1996-01-29 06:20:12 +00:00
|
|
|
default:
|
1997-09-21 22:27:40 +00:00
|
|
|
assert(0);
|
1996-01-29 06:20:12 +00:00
|
|
|
}
|
1997-09-21 22:27:40 +00:00
|
|
|
|
1996-01-29 06:20:12 +00:00
|
|
|
assert(file1);
|
|
|
|
assert(file2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if file2 is already around
|
|
|
|
*/
|
1997-09-21 22:27:40 +00:00
|
|
|
|
1996-01-29 06:20:12 +00:00
|
|
|
devrec.pCount = 2;
|
|
|
|
if ((devrec.devName = (GSString32Ptr) __C2GSMALLOC(file2)) == NULL) {
|
1997-09-21 22:27:40 +00:00
|
|
|
perror("couldn't duplicate destination volume name");
|
|
|
|
exit(1);
|
1996-01-29 06:20:12 +00:00
|
|
|
}
|
|
|
|
GetDevNumberGS(&devrec);
|
1997-09-21 22:27:40 +00:00
|
|
|
i=toolerror();
|
1996-01-29 06:20:12 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
1997-09-21 22:27:40 +00:00
|
|
|
if (debug) {
|
|
|
|
printf("volume %s already exists on device %d\n",file2,
|
|
|
|
devrec.devNum);
|
|
|
|
}
|
|
|
|
exit(1);
|
1996-01-29 06:20:12 +00:00
|
|
|
case devNotFound:
|
|
|
|
case volNotFound:
|
1997-09-21 22:27:40 +00:00
|
|
|
/* this is what we're normally expecting */
|
|
|
|
break;
|
1996-01-29 06:20:12 +00:00
|
|
|
default:
|
1997-09-21 22:27:40 +00:00
|
|
|
fprintf(stderr,"couldn't get %s device number: %s\n",file2,
|
1996-01-29 06:20:12 +00:00
|
|
|
strerror(_mapErr(i)));
|
1997-09-21 22:27:40 +00:00
|
|
|
exit(1);
|
1996-01-29 06:20:12 +00:00
|
|
|
}
|
|
|
|
|
1997-09-21 22:27:40 +00:00
|
|
|
/*
|
1996-01-29 06:20:12 +00:00
|
|
|
* rename the volume
|
|
|
|
*/
|
1997-09-21 22:27:40 +00:00
|
|
|
|
1996-01-29 06:20:12 +00:00
|
|
|
pathrec.pCount = 3;
|
1997-09-21 22:27:40 +00:00
|
|
|
pathrec.pathname = __C2GSMALLOC(file1);
|
1996-01-29 06:20:12 +00:00
|
|
|
pathrec.newPathname = __C2GSMALLOC(file2);
|
|
|
|
pathrec.flags = 0;
|
|
|
|
if (!pathrec.pathname || !pathrec.newPathname) {
|
1997-09-21 22:27:40 +00:00
|
|
|
perror("couldn't duplicate volume names");
|
|
|
|
exit(1);
|
1996-01-29 06:20:12 +00:00
|
|
|
}
|
|
|
|
ChangePathGS(&pathrec);
|
1997-09-21 22:27:40 +00:00
|
|
|
i=toolerror();
|
1996-01-29 06:20:12 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
1997-09-21 22:27:40 +00:00
|
|
|
if (debug) printf("device renamed\n");
|
|
|
|
break;
|
1996-01-29 06:20:12 +00:00
|
|
|
case pathNotFound:
|
|
|
|
case volNotFound:
|
1997-09-21 22:27:40 +00:00
|
|
|
if (debug) printf("device not renamed: %s\n",strerror(_mapErr(i)));
|
|
|
|
break;
|
1996-01-29 06:20:12 +00:00
|
|
|
default:
|
1997-09-21 22:27:40 +00:00
|
|
|
fprintf(stderr,"couldn't rename %s to %s: %s\n",file1, file2,
|
1996-01-29 06:20:12 +00:00
|
|
|
strerror(_mapErr(i)));
|
1997-09-21 22:27:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1996-01-29 06:20:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|