📄 wrudf.c
字号:
rootDir->name = ""; readDirectory( NULL, &fsd->rootDirectoryICB, ""); if( medium == CDR ) return; if( lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN ) { GETLINE("** Volume was not closed; do you wish to proceed (y/N) : "); if( (line[0] | 0x20) != 'y' ) exit(0); } /* If prevailing LVID is in one before last block of extent * then next LVID will be in last and must contain continuation extent */ if( integrityDescBlocknumber + 2 == extentLogVolIntegrityDesc.extLocation + (extentLogVolIntegrityDesc.extLength >> 11) ) { getUnallocSpaceExtent( 32 * 2048, extentLogVolIntegrityDesc.extLocation, &lvid->nextIntegrityExt); if( lvid->nextIntegrityExt.extLength == 0 ) { printf("No more unallocated space for Integrity Sequence\n"); } } else { lvid->nextIntegrityExt.extLength = 0; lvid->nextIntegrityExt.extLocation = 0; } integrityDescBlocknumber++; updateTimestamp(0,0); memcpy(lvid->impUse + 2 * sizeof(uint32_t) * lvid->numOfPartitions, &entityWRUDF, sizeof(regid)); lvid->recordingDateAndTime = timeStamp; lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN; lvid->descTag.tagLocation = integrityDescBlocknumber; size = sizeof(struct logicalVolIntegrityDesc) + sizeof(struct logicalVolIntegrityDescImpUse) + 2 * sizeof(uint32_t) * lvid->numOfPartitions; lvid->descTag.descCRCLength = size - sizeof(tag); setChecksum(lvid); p = readTaggedBlock(integrityDescBlocknumber, ABSOLUTE); memcpy( p, lvid, size); dirtyBlock(integrityDescBlocknumber, ABSOLUTE); /* not written because of buffering : Force unit access? */}int finalise(void) { int i, lbn, len, size, blkno ; struct generic_desc *p; short_ad *adSpaceMap; updateDirectory(rootDir); /* and any dirty children */ if( medium == CDR ) { writeVATtable(); } else { /* rewrite Space Bitmap */ if( spaceMapDirty) { adSpaceMap = (short_ad*) &((struct partitionHeaderDesc*)pd->partitionContentsUse)->unallocSpaceBitmap; lbn = adSpaceMap->extPosition; len = adSpaceMap->extLength; for( i = 0; i < len; i += 2048 ) { p = readBlock(lbn, 0); memcpy( p, (uint8_t*)spaceMap + i, 2048); dirtyBlock(lbn, 0); freeBlock(lbn++, 0); } } if( sparingTableDirty ) updateSparingTable(); /* write closed Logical Volume Integrity Descriptor */ lvid->integrityType = LVID_INTEGRITY_TYPE_CLOSE; updateTimestamp(0,0); lvid->recordingDateAndTime = timeStamp; lvid->descTag.tagLocation = integrityDescBlocknumber; size = sizeof(struct logicalVolIntegrityDesc) + sizeof(struct logicalVolIntegrityDescImpUse) + 2 * sizeof(uint32_t) * lvid->numOfPartitions; lvid->descTag.descCRCLength = size - sizeof(tag); setChecksum(lvid); p = readBlock(integrityDescBlocknumber, ABSOLUTE); memcpy(p, lvid, size); dirtyBlock(integrityDescBlocknumber, ABSOLUTE); freeBlock(integrityDescBlocknumber, ABSOLUTE); /* terminating descriptor */ blkno = lvid->nextIntegrityExt.extLocation; if( !blkno ) blkno = integrityDescBlocknumber + 1; p = readBlock(blkno, ABSOLUTE); memset(p, 0, 2048); p->descTag.tagLocation = blkno; p->descTag.tagSerialNum = lvid->descTag.tagSerialNum; p->descTag.tagIdent = TAG_IDENT_TD; p->descTag.descCRCLength = 512 - sizeof(tag); setChecksum(p); dirtyBlock(blkno, ABSOLUTE); freeBlock(blkno, ABSOLUTE); if( usdDirty ) { size = sizeof(struct unallocSpaceDesc) + usd->numAllocDescs * sizeof(extent_ad); usd->descTag.descCRCLength = size - sizeof(tag); setChecksum(usd); p = readBlock(usd->descTag.tagLocation, ABSOLUTE); memcpy(p, usd, size); dirtyBlock(usd->descTag.tagLocation, ABSOLUTE); freeBlock(usd->descTag.tagLocation, ABSOLUTE); /* now rewrite in Reserve Sequence which must be exact copy of Main Sequence */ usd->descTag.tagLocation += extentRsrvVolDescSeq.extLocation - extentMainVolDescSeq.extLocation; setChecksum(usd); p = readBlock(usd->descTag.tagLocation, ABSOLUTE); memcpy(p, usd, size); dirtyBlock(usd->descTag.tagLocation, ABSOLUTE); freeBlock(usd->descTag.tagLocation, ABSOLUTE); } } // end not CDR closeIO(); /* clears packet buffers; closes device */ /* free allocated space */ if(pd) free(pd); if(lvd) free(lvd); if(fsd) free(fsd); if(usd) free (usd); if(spaceMap) free(spaceMap); if(lvid) free(lvid); if(st) free(st); if(vat) free(vat); return 0;}intparseCmnd(char* line) { char *p, *q, next, term; int i, j; int cmnd; if( !cmndvSize ) { cmndvSize = 64; cmndv = malloc(cmndvSize * sizeof(char*)); } if( line[0] == 0 ) return CMND_FAILED; cmndc = 0; for( p = line; *p == ' '; p++ ) ; for( q = p; *q && (*q != ' '); q++ ) ; next = *q; *q = 0; if( !strcmp(p, "cd") || !strcmp(p, "ls") ) { printf("Specify cdh/lsh or cdc/lsc for Harddisk or CompactDisc\n"); return CMND_FAILED; } if( !strcmp(p, "cp") ) cmnd = CMND_CP; else if( !strcmp(p, "rm") ) cmnd = CMND_RM; else if( !strcmp(p, "mkdir") ) cmnd = CMND_MKDIR; else if( !strcmp(p, "rmdir") ) cmnd = CMND_RMDIR; else if( !strcmp(p, "lsc") ) cmnd = CMND_LSC; else if( !strcmp(p, "lsh") ) cmnd = CMND_LSH; else if( !strcmp(p, "cdc") ) cmnd = CMND_CDC; else if( !strcmp(p, "cdh") ) cmnd = CMND_CDH; else if( !strcmp(p, "quit") ) cmnd = CMND_QUIT; else if( !strcmp(p, "exit") ) cmnd = CMND_QUIT; else { printf("Invalid command\n"); return CMND_FAILED; } while( next != 0 ) { if( cmndc == cmndvSize ) { cmndvSize += 32; cmndv = realloc(cmndv, cmndvSize); if( !cmndv ) fail("cmndv reallocation failed\n"); } p = q + 1; while( *p == ' ') p++; if( *p == 0 ) break; if( *p == '"' ) { term = '"'; q = p+1; } else { term = ' '; q = p; } while( *q && *q != term ) q++; next = *q; if( *p == '"' ) { if( *q == 0 ) return CMND_ARG_INVALID; cmndv[cmndc++] = p+1; *(q-1) = 0; } else { cmndv[cmndc++] = p; *q = 0; } } options = 0; for( i = 0; i < cmndc; i ++ ) { if( cmndv[i][0] == '-' ) { for( j = 1; cmndv[i][j]; j++ ) { switch( cmndv[i][j] ) { case 'f': options |= OPT_FORCE; break; case 'r': options |= OPT_RECURSIVE; break; default: return CMND_ARG_INVALID; } } cmndv[i] = NULL; } } for( i = j = 0; i < cmndc; i++ ) { if( i != j ) cmndv[j] = cmndv[i]; if( cmndv[j] != NULL ) j++; } cmndc = j; /* could check whether options valid for command */ return cmnd;}intmain(int argc, char** argv) { int rv; int cmnd; char prompt[256]; Directory *d; printf("wrudf " WRUDF_VERSION "\n"); devicename= "/dev/cdrom"; if(argc > 1 ) devicename = argv[1]; /* can specify disk image filename */ if( setpriority(PRIO_PROCESS, 0, -10) ) { printf("setpriority(): %m\n"); exit(1); } hdWorkingDir = getcwd(NULL, 0); initialise(devicename); for(;;) { d = rootDir; prompt[0] = 0; while( curDir != d ) { strcat(prompt, d->name); strcat(prompt, "/"); d = d->child; } if( d->name[0] == 0 ) strcat(prompt, "/"); else strcat(prompt, d->name); strcat(prompt, " > "); GETLINE(prompt); cmnd = parseCmnd(line); if( cmnd == CMND_FAILED ) continue; if( cmnd == CMND_QUIT ) break; switch( cmnd ) { case CMND_CP: rv = cpCommand(); break; case CMND_RM: rv = rmCommand(); break; case CMND_MKDIR: rv = mkdirCommand(); break; case CMND_RMDIR: rv = rmdirCommand(); break; case CMND_LSC: rv = lscCommand(); break; case CMND_LSH: rv = lshCommand(); break; case CMND_CDC: rv = cdcCommand(); break; case CMND_CDH: rv = cdhCommand(); break; } switch( rv ) { case CMND_OK: break; case CMND_FAILED: printf("Failed\n"); break; case WRONG_NO_ARGS: printf("Incorrect number of arguments\n"); break; case CMND_ARG_INVALID: printf("Invalid argument\n"); break; case NOT_IN_RW_PARTITION: printf("Not in RW partition\n"); break; case DIR_INVALID: printf("Invalid directory\n"); break; case DIR_NOT_EMPTY: printf("Directory not empty\n"); break; case EXISTING_DIR: printf("Dir already exists\n"); break; case DOES_NOT_EXIST: printf("File/directory does not exist\n"); break; case PERMISSION_DENIED: printf("Permission denied\n"); break; case IS_DIRECTORY: printf("Is a directory\n"); break; default: printf("Unknown return value %d\n", rv); } } free(hdWorkingDir); return finalise();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -