mirror of
https://github.com/open-simh/simtools.git
synced 2026-01-23 19:07:19 +00:00
Reorganize commands into separate modules - ods2.c was way too big. This reduces it from around 3000 LOC to less than 1K LOC. Reorder I/O so PHYVIRT mediates all physical access. Fix memory leaks of device structures. Reorganize Files-11 vs. internal structures. Allow more granular control of DEBUG from the makefile. Show VOLUME handles free space and tries to match geometry from SCB to known disk types. Fix many compilation warnings. Add code to allow dumping disk data for debug. Automatically generate descrip.mms from dependencies. Correctly handle directory default version limit; previously confused with file version limit. Teach help to sort tables for presentation; manually keeping them sorted is problematic, and code maintenance prefers functional groupings. Add the ability to initialize a Files-11 volume. (Not quite complete.) Add dependency generation to makefiles. Excludes system headers so makedepends isn't required to build. Simplify makefiles to use more recipes. Teach makefiles to list all sources and headers so it's easier to keep git and MSVC up-to-date. Add support for accessing images of disks with interleave/skew/offsets (e.g. RX02). Add VHD support, including ability to create a snapshot with mount/write. Teach RMS to handle NOSPAN variable length records correctly. Fix RMS GET handling of variable length records with VFC that span block boundaries. Fix delete file (a day-one incomplete). Still some cases to validate. Purge cache of modified blocks at rundown and at the end of each command. Do not allow deletion of reserved files. Move revision history to version.h Correct various permissions in git.
162 lines
6.4 KiB
C
162 lines
6.4 KiB
C
/* This is part of ODS2 written by Paul Nankervis,
|
|
* email address: Paulnank@au1.ibm.com
|
|
|
|
* ODS2 is distributed freely for all members of the
|
|
* VMS community to use. However all derived works
|
|
* must maintain comments in their source to acknowledge
|
|
* the contibution of the original author.
|
|
*/
|
|
|
|
#if !defined( DEBUG ) && defined( DEBUG_INITIALCMD )
|
|
#define DEBUG DEBUG_INITIALCMD
|
|
#else
|
|
#ifndef DEBUG
|
|
#define DEBUG 0
|
|
#endif
|
|
#endif
|
|
|
|
#include "cmddef.h"
|
|
|
|
#include "access.h"
|
|
#include "device.h"
|
|
#include "initvol.h"
|
|
#include "phyvirt.h"
|
|
|
|
/******************************************************************* doinitial() */
|
|
|
|
static struct NEWVOL initpars;
|
|
|
|
#define init_beg OPT_GENERIC_1
|
|
#define init_mid OPT_GENERIC_2
|
|
#define init_blk OPT_GENERIC_3
|
|
#define init_mount OPT_GENERIC_4
|
|
|
|
qual_t idxkwds[] = { {"beginning", init_beg, init_mid|init_blk, NV,
|
|
"Place index file in lowest available LBNs"},
|
|
{"block", init_blk, init_beg|init_mid, DV(&initpars.indexlbn),
|
|
"Place index file near specific LBN"},
|
|
{"middle", init_mid, init_beg|init_blk, NV,
|
|
"Place index file near middle of volume (default)"},
|
|
{NULL, 0, 0, NV, NULL}
|
|
};
|
|
|
|
qual_t iniquals[] = { {DT_NAME, 0, MOU_DEVTYPE, CV(NULL), "Drive type (DEC model name) "},
|
|
{"cluster_size", 0, 0, DV(&initpars.clustersize),
|
|
"Cluster size (blocks)" },
|
|
{"create", PHY_CREATE|MOU_VIRTUAL, 0, NV, "Create a new image file" },
|
|
{"directories", 0, 0, DV(&initpars.directories),
|
|
"Directory entries to pre-allocate" },
|
|
{"headers", 0, 0, DV(&initpars.headers),
|
|
"File headers to pre-allocate" },
|
|
{"index", 0, init_beg|init_mid|init_blk, KV(idxkwds),
|
|
"Index file placement hint"},
|
|
{"image", PHY_CREATE|MOU_VIRTUAL, 0, NV,
|
|
"Initialize a disk image file", },
|
|
{"log", MOU_LOG, 0, NV, "-Show progress"},
|
|
{"nolog", 0, MOU_LOG, NV, NULL},
|
|
{"replace", MOU_VIRTUAL, PHY_CREATE, NV,
|
|
"Replace filesystem in existing image file" },
|
|
{"mount", init_mount, 0, NV, "-Mount volume after initializing it"},
|
|
{"nomount", 0, init_mount, NV, NULL },
|
|
{"virtual", PHY_CREATE|MOU_VIRTUAL, 0, NV, NULL, },
|
|
{"maximum_files", 0, 0, DV(&initpars.maxfiles),
|
|
"Maximum number of files volume can (ever) contain" },
|
|
{"owner_uic", 0, 0, SV(&initpars.useruic),
|
|
"Volume owner's UIC, default [1,1]"},
|
|
{"user_name", 0, 0, SV(&initpars.username),
|
|
"Volume owner's username, default yours"},
|
|
{NULL, 0, 0, NV, NULL } };
|
|
|
|
param_t inipars[] = { {"device", REQ, LCLFS, NOPA,
|
|
"for device or disk image to be initialized.\n "
|
|
"ALL EXISTING DATA WILL BE LOST."
|
|
},
|
|
{"labels", REQ, LCLFS, NOPA, "volume label for new volume" },
|
|
{ NULL, 0, 0, NOPA, NULL }
|
|
};
|
|
|
|
DECL_CMD(initial) {
|
|
int sts = SS$_NORMAL;
|
|
char *devname = NULL;
|
|
size_t len;
|
|
struct DEV *dev;
|
|
int options;
|
|
|
|
UNUSED(argc);
|
|
|
|
devname = argv[1];
|
|
|
|
options = checkquals( PHY_CREATE | init_mid | init_mount, iniquals, qualc, qualv );
|
|
do {
|
|
|
|
if( options == -1 ) {
|
|
sts = SS$_BADPARAM;
|
|
break;
|
|
}
|
|
options |= MOU_WRITE;
|
|
if( !(options & MOU_VIRTUAL) )
|
|
options &= ~PHY_CREATE;
|
|
|
|
if( options & init_mid )
|
|
initpars.indexlbn = INIT_INDEX_MIDDLE;
|
|
if( options & init_beg )
|
|
initpars.indexlbn = 0;
|
|
if( (options & init_blk) && initpars.indexlbn == INIT_INDEX_MIDDLE )
|
|
initpars.indexlbn--;
|
|
|
|
initpars.options = 0;
|
|
if( options & MOU_LOG )
|
|
initpars.options |= INIT_LOG;
|
|
if( options & MOU_VIRTUAL )
|
|
initpars.options |= INIT_VIRTUAL;
|
|
|
|
initpars.devtype = disktype[(options & MOU_DEVTYPE) >> MOU_V_DEVTYPE].name;
|
|
|
|
len = strlen( argv[2] );
|
|
if( len > 12 || !*argv[2] ||
|
|
strspn( argv[2], VOL_ALPHABET ) != len ) {
|
|
printf( "Volume label must be between 1 and 12 alphanumeric characters long\n" );
|
|
sts = SS$_BADPARAM;
|
|
break;
|
|
}
|
|
initpars.label = argv[2];
|
|
|
|
if( !((sts = virt_open( &devname, options, &dev )) & STS$M_SUCCESS) )
|
|
break;
|
|
|
|
if( !(dev->access & MOU_WRITE) ) {
|
|
sts = SS$_WRITLCK;
|
|
virt_close( dev );
|
|
break;
|
|
}
|
|
initpars.devnam = devname;
|
|
if( !((sts = initvol( dev, &initpars )) & STS$M_SUCCESS) ) {
|
|
virt_close( dev );
|
|
break;
|
|
}
|
|
if( !((sts = virt_close( dev )) & STS$M_SUCCESS) )
|
|
break;
|
|
|
|
if( options & init_mount ) {
|
|
sts = mount( (options & (MOU_VIRTUAL|MOU_DEVTYPE|MOU_WRITE)) | MOU_LOG,
|
|
1, argv+1, argv+2 );
|
|
}
|
|
} while( 0 );
|
|
|
|
initpars.username =
|
|
initpars.useruic = NULL;
|
|
|
|
if( sts & STS$M_SUCCESS )
|
|
return sts;
|
|
|
|
printf( "%%ODS2-E-FAILED, Initialize failed: %s\n", getmsg( sts, MSG_TEXT ) );
|
|
|
|
if( (options & (MOU_VIRTUAL|PHY_CREATE)) == (MOU_VIRTUAL|PHY_CREATE) &&
|
|
!( (sts & STS$M_COND_ID) == (SS$_DUPFILENAME & STS$M_COND_ID) ||
|
|
(sts & STS$M_COND_ID) == (SS$_IVDEVNAM & STS$M_COND_ID) ) ) {
|
|
(void) unlink( argv[1] );
|
|
}
|
|
|
|
return sts;
|
|
}
|