bool CNFS2Prog::WriteFileAttributes(char *path) { struct stat data; unsigned long nValue; if (stat(path, &data) != 0) return false; switch (data.st_mode & S_IFMT) { case S_IFREG: nValue = NFREG; break; case S_IFDIR: nValue = NFDIR; break; case S_IFCHR: nValue = NFCHR; break; default: nValue = NFNON; break; } m_pOutStream->Write(nValue); //type if (nValue == NFREG) nValue = 0x8000; else if (nValue == NFDIR) nValue = 0x4000; else nValue = 0; if ((data.st_mode & S_IREAD) != 0) nValue |= 0x124; if ((data.st_mode & S_IWRITE) != 0) nValue |= 0x92; //if ((data.st_mode & S_IEXEC) != 0) nValue |= 0x49; m_pOutStream->Write(nValue); //mode m_pOutStream->Write(data.st_nlink); //nlink m_pOutStream->Write(m_nUID); //uid m_pOutStream->Write(m_nGID); //gid m_pOutStream->Write(data.st_size); //size m_pOutStream->Write(8192); //blocksize m_pOutStream->Write(0); //rdev m_pOutStream->Write((data.st_size + 8191) / 8192); //blocks m_pOutStream->Write(4); //fsid m_pOutStream->Write(GetFileID(path)); //fileid m_pOutStream->Write(data.st_atime); //atime m_pOutStream->Write(0); //atime m_pOutStream->Write(data.st_mtime); //mtime m_pOutStream->Write(0); //mtime m_pOutStream->Write(data.st_ctime); //ctime m_pOutStream->Write(0); //ctime return true; }
void DelFile(uint8 Name[11]) { DIR FileDir; uint16 ClusID,Index; Index = GetFileID(Name,&FileDir); //搜索得到文件所在根目录项位置 FileDir.FileName.NAME[0] = 0xE5; //删除根目录下文件 ClusID = FileDir.FilePosit.Start; //文件所在的簇号 WriteFAT(ClusID,0x0000); //清空对应的FAT表FAT1 WriteFAT2(ClusID,0x0000); //使FAT2和FAT1保持一致 WriteDIR(Index,&FileDir); //写指定根目录项 }
void CNFS2Prog::ProcedureREADDIR(void) { unsigned char opaque[3] = {0, 0, 0}; char *path, filePath[MAXPATHLEN + 1]; int handle; struct _finddata_t fileinfo; unsigned long count; unsigned int nLen; PrintLog("READDIR"); path = GetPath(); if (!CheckFile(path)) return; m_pOutStream->Write(NFS_OK); sprintf(filePath, "%s\\*", path); count = 0; handle = _findfirst(filePath, &fileinfo); if (handle) { do { m_pOutStream->Write(1); //value follows sprintf(filePath, "%s\\%s", path, fileinfo.name); m_pOutStream->Write(GetFileID(filePath)); //file id m_pOutStream->Write(nLen = strlen(fileinfo.name)); m_pOutStream->Write(fileinfo.name, nLen); nLen &= 3; if (nLen != 0) m_pOutStream->Write(opaque, 4 - nLen); //opaque bytes m_pOutStream->Write(++count); //cookie } while (_findnext(handle, &fileinfo) == 0); _findclose(handle); } m_pOutStream->Write(0); //no value follows m_pOutStream->Write(1); //EOF }
/*********************************************************************** 函数功能:创建一个子空文件 操作内容:1、文件名必须是数字或者大写字母,小于8位则用空格,扩展名为空格 2、文件大小事先不用设置,均为0; 3、创建子文件的过程实际就是写子目录和FAT表,这里不写文件里的数据 4、这里文件名为短名,8个字节,也就是8个字符 5、子文件的目录写在其父目录的起始簇的空白目录项 ***********************************************************************/ void CreateDirectoryFile(uint8 DirectoryName[11], uint8 FileName[11]) //父文件夹名和新建文件名,短文件名 { uint16 ClusID,ClusIDFile,Index; DIR FileDir; uint16 FileCrtDateTmp,FileCrtTimeTmp; //双字节数据 uint8 FileCrtDate[2],FileCrtTime[2]; //单字节时间日期数据 FileDir.FilePosit.Start = GetNextFAT(); //得到一个空的FAT项,下面用来写对应文件的FAT表 ClusID = FileDir.FilePosit.Start; //文件簇开始簇号,这是子文件的起始簇地址 ClusIDFile = FileDir.FilePosit.Start; //暂存下来,以备后面写入 WriteFAT(ClusID, 0xffff); //写对应文件的FAT表1,即FAT1,0xffff表示文件结束 WriteFAT2(ClusID, 0xffff); //写对应文件的FAT表2,即FAT2,0xffff表示文件结束 Index = GetFileID(DirectoryName,&FileDir); //搜索得到文件夹的属性,主要是获得起始簇位置,方便写文件的目录项 ReadDIR(Index, &FileDir); //读取父文件夹的目录项,只需要其起始簇 FileCrtDateTmp=GetFileCrtDate(2010,7,2); //文件修改日期2010年7月2日 FileCrtDate[0]=(uint8)FileCrtDateTmp&0x00ff; //低字节提取 FileCrtDate[1]=(uint8)(FileCrtDateTmp>>8); //高字节提取 FileCrtTimeTmp=GetFileCrtTime(21,20,10); //文件修改时间21点20分10秒 FileCrtTime[0]=(uint8)FileCrtTimeTmp&0x00ff; //低字节提取 FileCrtTime[1]=(uint8)(FileCrtTimeTmp>>8); //高字节提取 CopyBytes(FileName, &FileDir.FileName, 11); //写入文件名 CopyBytes(FileCrtDate, &FileDir.FileCrtDate, 2); //写入文件创建日期 CopyBytes(FileCrtTime, &FileDir.FileCrtTime, 2); //写入文件创建时间 FileDir.FileAttrib = 0x20; //文件属性填充,0x10为子目录属性,即文件夹 ClusID = FileDir.FilePosit.Start; //父文件夹的开始簇号,子文件目录项写入这个簇中 FileDir.FilePosit.Start=ClusIDFile; //新建文件的起始簇 WriteDirectoryDIR(ClusID,GetDirectoryEmptyDIR(ClusID),&FileDir);//需要扫描父目录的起始簇中空白可以写入子目录的项 }
int Copy(int mode,char *filenameSourc,char *fileextSourc, char* filenameDest,char *fileextDest) { if (mode==1) //内往内 { int p=GetFileID(filenameSourc,fileextSourc); if (p==-1) { printf("复制文件不存在!\n"); return -1; } else if (fileIndex[p].node->filesize>FreeFDBNum*4093) { printf("目标文件大小超出剩余存储空间,操作已取消\n"); return -1; } else { int q=GetFileID(filenameDest,fileextDest); if (q!=-1) { printf("文件已存在,是否替换?\n",filenameDest,fileextDest); printf("yes(y),no(n): "); char input; input=getchar(); while(input=='\n') input=getchar(); if (input=='n') { printf("File existe.Can not copy.\n"); return -1; } else { Delete(1,filenameDest,fileextDest); } } // New(1,filenameDest,fileextDest); q=GetFileID(filenameDest,fileextDest); FileNode *fnq=fileIndex[q].node;//目的地 FileNode *fnp=fileIndex[p].node;//源文件 fnq->filesize=fnp->filesize; //FileNode fn=NowDirDirTree[p]; int nowFDB=fnp->FDBBlock;//源 int size=fnp->filesize;//源文件大小 int BlockNum=(size+4092)/4093;//源文件数据块数 char data[4096]; char desnextadd[3]; int add=0; int firstFDB=-1; for (int i=0;i<BlockNum-1;i++) { add=AddressOfBlock(nowFDB); fseek(fpDisk,add,0); fread(data,1,4096,fpDisk); char three[3]; three[0]=data[4093]; three[1]=data[4094]; three[2]=data[4095]; int nextBlock=ThreeToInt(three); nowFDB=nextBlock; // if (i==0) firstFDB=FirstBlankFDB; add=AddressOfBlock(FirstBlankFDB+FCBRemainNum+3); fseek(fpDisk,add,0); FDBBitmap[FirstBlankFDB]=b_Full; FreeFDBNum--; FirstBlankFDB=GetNextBlankFDB(); IntToThree(FirstBlankFDB+FCBRemainNum+3,desnextadd); data[4093]=desnextadd[0]; data[4094]=desnextadd[1]; data[4095]=desnextadd[2]; fwrite(data,1,4096,fpDisk); } //不足一块的内容 int remainSize=size; if (remainSize%4093==0&&remainSize>0) remainSize=4093; else remainSize%=4093; //memset(data,0,sizeof(data)); if (remainSize>0) { add=AddressOfBlock(nowFDB); //fseek(fpDisk,add,0); ReadBlock(nowFDB,data,remainSize); WriteToBlock(FirstBlankFDB+FCBRemainNum+3,data,remainSize); FDBBitmap[FirstBlankFDB]=b_Full; if(firstFDB==-1) firstFDB=FirstBlankFDB; FirstBlankFDB=GetNextBlankFDB(); FreeFDBNum--; } fnq->FDBBlock=firstFDB+FCBRemainNum+3; ChangeAttribute(1,q); return fnq->filesize; } } else if (mode==2)//内往外 { int size; int fid=GetFileID(filenameSourc,fileextSourc); if (fid==-1) { printf("目录下找不到该文件。\n",filenameSourc,fileextSourc); return -1; } else { FileNode *fn=fileIndex[fid].node; int nowFDB=fn->FDBBlock;//源文件 size=fn->filesize; int BlockNum=(size+4092)/4093; char data[4096]; FILE* fp; fp=fopen(filenameDest,"wb"); for (int i=0;i<BlockNum-1;i++) { int add=AddressOfBlock(nowFDB); fseek(fpDisk,add,0); fread(data,1,4096,fpDisk); char three[3]; three[0]=data[4093]; three[1]=data[4094]; three[2]=data[4095]; int nextBlock=ThreeToInt(three); nowFDB=nextBlock; //fseek(fpDisk,add,0); fwrite(data,1,4093,fp); } int remainSize=size; if (remainSize%4093==0&&remainSize>0) remainSize=4093; else remainSize%=4093; ReadBlock(nowFDB,data,remainSize); for (int j=0;j<remainSize;j++) { fputc(data[j],fp); } int flen=ftell(fp); fclose(fp); } return size; } else//外往内 { FILE* fp; fp=fopen(filenameSourc,"rb"); // if (fp==NULL) { printf("未找到目标文件,操作已终止\n"); return -1; } fseek(fp,0L,SEEK_END); /* 定位到文件末尾 */ int flen=ftell(fp); /* 得到文件大小 */ if (flen>FreeFDBNum*4093) { printf("目标文件大小超出剩余存储空间,操作已取消\n"); return -1; } fseek(fp,0L,SEEK_SET); // int q=GetFileID(filenameDest,fileextDest); if (q!=-1) { printf("文件已存在,是否替换?\n",filenameDest,fileextDest); printf("yes(y),no(n): "); char input; input=getchar(); while(input=='\n') input=getchar(); if (input=='n') { printf("File existe.Can not copy.\n"); return -1; } else { Delete(1,filenameDest,fileextDest); ChangeNowDir(NowDirRoute); } } // New(1,filenameDest,fileextDest); int fid=GetFileID(filenameDest,fileextDest); FileNode *fn=fileIndex[fid].node; int filesize=flen; //文件大小 int firstFDB=-1; char desnextadd[3]; char data[4096]; for (int i=0;i<(flen/4093);i++) { fread(data,1,4093,fp); int add=AddressOfBlock(FirstBlankFDB+FCBRemainNum+3); fseek(fpDisk,add,0); if (i==0) firstFDB=FirstBlankFDB; FDBBitmap[FirstBlankFDB]=b_Full; FreeFDBNum--; FirstBlankFDB=GetNextBlankFDB(); IntToThree(FirstBlankFDB+FCBRemainNum+3,desnextadd); data[4093]=desnextadd[0]; data[4094]=desnextadd[1]; data[4095]=desnextadd[2]; fwrite(data,1,4096,fpDisk); } if (flen%4093!=0&&flen>0) { int remainSize=flen; if (remainSize%4093==0&&remainSize>0) remainSize=4093; else remainSize%=4093; int add=AddressOfBlock(FirstBlankFDB+FCBRemainNum+3); fseek(fpDisk,add,0); fread(data,1,remainSize,fp); WriteToBlock(FirstBlankFDB+FCBRemainNum+3,data,remainSize); FDBBitmap[FirstBlankFDB]=b_Full; FreeFDBNum--; if(firstFDB==-1) firstFDB=FirstBlankFDB; FirstBlankFDB=GetNextBlankFDB(); fn->FDBBlock=firstFDB+FCBRemainNum+3; } fn->filesize=filesize; ChangeAttribute(1,fid); fclose(fp); return flen; } }
//**************************8 // 3整组测量。 //功能: 实现某组电池的整组测量。 //************************* void TotalGrpMeasure(void ) { unchar i; unchar s[12]; unint fint; float fres; float f,arf[3]; switch(MenuStatus) { case 2: if(CURPATH.CurrentDirStarClusID !=0) { CURPATH.CurrentDirStarClusID = 0; } if((ReadFile("CONFIG TXT", (unchar*)pCfgHead, 0,sizeof (CFG_HEAD))!=0xff))//取出系统头 { Index = 1; // t=*(unint*)Temp;再次出现字节对齐的问题,开始调试的时候是没问题的现在又出了。。。 s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = '\0'; Str_8x16(0,0,"组:"); Str_8x16(0,3,s); DispFanBai(0,3,4); MenuStatus =1000; } else { Str_8x16(1,0 ,"系统文件不存在"); Delay_ms(2000); MenuStatus = 3; return; } break; case 1000: switch(GetKey1()) { case ENTER_KEY: DispFanBai(0,3,4);//组位置取消反白 //先从config文件读出该组电池对应的组属性域; if( ReadFile("CONFIG TXT",(unchar*)pGrpHead,Index*64,sizeof (GRP_HEAD))==0xff) { Str_8x16(2,0,"系统配置文件错误"); Delay_ms(2000); MenuStatus =3; return; } //进入该组所在的目录如果没有该组就建立该组的目录。并在该目录下根据时间建立该组的测量文件 if(CURPATH.CurrentDirStarClusID !=0) { CURPATH.CurrentDirStarClusID = 0; } s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = '\0'; if(ChgDir(s)==0xff)//没有该目录建立该目录并进入 { CreateDir(s); } ChgDir(s); DIR *ID=(DIR*)&Temp[12]; s[0] = year/1000+0x30; s[1] = (year%1000)/100+0x30; s[2] = ((year%1000)%100)/10+0x30; s[3] = ((year%1000)%100)%10+0x30; s[4]=month/10+0x30; s[5]= month%10+0x30; s[6]= day/10+0x30; s[7]=day%10+0x30; s[8]='D'; s[9]='A'; s[10]='T'; s[11]=0; if(GetFileID(s, ID)==0xffff)//文件不存在建立之并根据config.txt建立该文件的默认头部 { CreateFile(s); pMeasureHead=(MEASURE_HEAD*)Temp; pMeasureHead->DeviceID=pCfgHead->DeviceID; pMeasureHead->BatGrpID=pGrpHead->BatGrpID; pMeasureHead->BatNumbers=pGrpHead->BatNumbers; AppendData(s,(unchar*)pMeasureHead,sizeof (MEASURE_HEAD)); } //判定该组电池今天已经测量了多少块以便进行下面的测量。 Index =(ID->FilePosit.Size-16)/8+1;//已经存在的电池测量数据组 if(Index>=pGrpHead->BatNumbers) { Str_8x16(1,0,"该组已经测量完毕"); Delay_ms(2000); MenuStatus =3; return; } s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = 0; Str_8x16(0,12,s); //给cy单片机上电打开串口并进行串口初始化; pRecv0Str=&Temp[20];//设置接收缓冲区的地址。 POWRON_CY; Init_Uart0; Uart0RxTimeOut = 0; //等待cy单片机的响应包; while(1) { if(GetKey2( pAck,Temp,10)!=NULL) { //判定得到的数据是否合法 if((Temp[4]==0x04)&&(Temp[5]==0x03)&&(Temp[6]==0x02)&&(Temp[7]==0x01)) { unchar data[4]; data[0] =10;//设定地址为10 data[1] = 0; data[2] = 0; data[3] = 0; SendCmd(SET_ADRESS,0,data); Uart0RxTimeOut =0; } break; } if(Uart0RxTimeOut>=250) { //cy单片机没有响应退出; Str_8x16(1,0,"测量模块没有响应"); Delay_ms(2000); POWROFF_CY; MenuStatus =3; return; } } while(1) { if(GetKey2( pAck,Temp,10)!=NULL)//得到cy的设定地址回应 { if(Temp[2]==10) { break; } break; } if(Uart0RxTimeOut>=250) { //cy单片机没有响应退出; Str_8x16(1,0,"测量模块没有响应"); Delay_ms(2000); POWROFF_CY; MenuStatus =3; return; } } DispFanBai(0,12,4);//电池编号位置加反白; //Index = 1; MenuStatus =2000; break; case UP_KEY: if(Index ==pCfgHead->NumberBatGrps) { Index=1; } else { Index++; } s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = '\0'; Str_8x16(0,3,s); DispFanBai(0,3,4); break; case DOWN_KEY: if(Index==1) { Index = pCfgHead->NumberBatGrps; } else { Index--; } s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = '\0'; Str_8x16(0,3,s); DispFanBai(0,3,4); break; case ESC_KEY: break; default: break; } break; case 2000: //开始测量不响应任何按键 //发送测量命令给cy i = 0; while(1) { Uart0RxTimeOut=0; SendCmd(MEASURE_VOLT,10,s); while(1) { if(GetKey2( pAck,Temp,10)!=NULL) { memcpy((unchar*)&fint,&Temp[4],2); f=(float)fint/1000;//注意字节对齐问题; if((f>=pGrpHead->BatVoltMin)&&(f<=pGrpHead->BatVoltMax)) { arf[i]=f; i++; break; } } else if(Uart0RxTimeOut>=250)//超时退出; { //cy单片机没有响应退出; Str_8x16(1,0,"测量模块没有响应"); Delay_ms(2000); POWROFF_CY; MenuStatus =3; return; } } if(i==3) { //已经测量了3次 i =0; float f1 = fabsf(arf[0]-arf[1]); float f2 = fabsf(arf[0]-arf[2]); float f3 = fabsf(arf[2]-arf[1]); if((f1<=0.01)&&(f2<=0.01)&&(f3<=0.01))//比较有效性 { //夹子夹好了并连续得到三次合格的电压值; //退出电压测量进行电阻测量。 //*******************8 //发测量阻值的命令; Uart0RxTimeOut = 0; SendCmd(MEASURE_RES,10,s); DispFanBai(0,12,4);//取消反白。 f=(arf[0]+arf[1]+arf[2])/3; while(1) { if(GetKey2( pAck,Temp,10)!=NULL) { memcpy(Temp,&f,4); memcpy(&fint,&Temp[4],2); fres =(float)fint/1000; memcpy(Temp,&fres,4); // 显示出电压和内阻值; sprintf((char*)s,"%5.3f",f); Str_8x16(1,5,s); Str_8x16(1,5,s); Str_8x16(1,0,"电压:"); Str_8x16(1,10,"V"); sprintf((char*)s,"%5.3f",fres); Str_8x16(2,5,s); Str_8x16(2,0,"内阻:"); Str_8x16(2,10,"mΩ"); //测量结果存储到文件里 s[0] = year/1000+0x30; s[1] = (year%1000)/100+0x30; s[2] = ((year%1000)%100)/10+0x30; s[3] = ((year%1000)%100)%10+0x30; s[4]=month/10+0x30; s[5]= month%10+0x30; s[6]= day/10+0x30; s[7]=day%10+0x30; s[8]='D'; s[9]='A'; s[10]='T'; s[11]=0; AppendData(s,Temp,8); //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //开始下一个电池的测量 // Str_8x16(2,0, "ENT:下一个 ESC:退出"); ClrKeyBuf(); unchar key; s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = 0; Str_8x16(0,12,s); DispFanBai(0,12,4); //测完了当前电池再次反白此电池表明测量完 while(1)//等待用户操作; { KeyScan(); key=GetKey1(); if(key==ENTER_KEY) { if(Index==pGrpHead->BatNumbers) { //测到了最后一块电池退出系统。 Str_8x16(1,0,"整组测量完毕"); Delay_ms(2000); POWROFF_CY; MenuStatus =3; return; } else { Index++; } s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = 0; Str_8x16(0,12,s); Str_8x16(0,12,s); DispFanBai(0,12,4); Str_8x16(1,0," "); Str_8x16(2,0," "); Uart0RxTimeOut=0; break; } else if(key==ESC_KEY) { Delay_ms(2000); POWROFF_CY; MenuStatus =3; return; } //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } break;//退出测量阻值的应答循环。 } else if(Uart0RxTimeOut>=250)//超时退出; { //cy单片机没有响应退出; Str_8x16(1,0,"测量模块没有响应"); Delay_ms(2000); POWROFF_CY; MenuStatus =3; return; } } //*************************************** //break; } else { //判定为夹子没有夹好 Str_8x16(3,0,"没夹好请重新测量"); unchar key; while(1) { KeyScan(); key=GetKey1(); if(key==ENTER_KEY) { i=0; Str_8x16(3,0," "); break;//继续重试当前电池的测量 } else if(key==ESC_KEY) //放弃对当前电池测量因为这个电池可能已经坏了接着测下面的电池。 { i =0; //先占据文件相应的位置等将来进行单独测量。 s[0] = year/1000+0x30; s[1] = (year%1000)/100+0x30; s[2] = ((year%1000)%100)/10+0x30; s[3] = ((year%1000)%100)%10+0x30; s[4]=month/10+0x30; s[5]= month%10+0x30; s[6]= day/10+0x30; s[7]=day%10+0x30; s[8]='D'; s[9]='A'; s[10]='T'; for (unchar j=0;j<8;j++) Temp[j]=0; AppendData(s,Temp,8); if(Index < pGrpHead->BatNumbers) { Index++; Str_8x16(3,0,"跳过测量下一只 "); } else { //测量完毕; Str_8x16(1,0,"整组测量完毕"); Delay_ms(2000); POWROFF_CY; MenuStatus =3; return; } s[0] = Index/1000+0x30; s[1] = (Index%1000)/100+0x30; s[2] = ((Index%1000)%100)/10+0x30; s[3] = ((Index%1000)%100)%10+0x30; s[4] = 0; Str_8x16(0,12,s); DispFanBai(0,12,4); } } // break; } // break; } } default: break; } }
bool ReflectionParser::ProcessFile(std::string const & fileName, bool InProcessModule) { if (!InProcessModule && !m_sourceCache->RequestGenerate(fileName)) return true; Clear(); m_currentFile = fileName; m_index = clang_createIndex(true, false); std::vector<const char *> arguments; for (auto &argument : m_options.arguments) { // unescape flags boost::algorithm::replace_all(argument, "\\-", "-"); arguments.emplace_back(argument.c_str()); } m_translationUnit = clang_createTranslationUnitFromSourceFile( m_index, fileName.c_str(), static_cast<int>(arguments.size()), arguments.data(), 0, nullptr ); auto cursor = clang_getTranslationUnitCursor(m_translationUnit); try { Namespace tempNamespace; buildClasses(cursor, tempNamespace); tempNamespace.clear(); if (ContainsModule() && !InProcessModule) { if (m_classes.size() > 1) { EMIT_ERROR("You can't implement any other classes in one file with module class"); } return false; } if (RequestGenerate()) { std::string fileId = GetFileID(fileName); std::stringstream outCode; // includes outCode << "#include <memory>\n\n"; outCode << "#include \"sc-memory/cpp/sc_memory.hpp\"\n\n\n"; outCode << "#include \"sc-memory/cpp/sc_event.hpp\"\n\n\n"; for (auto it = m_classes.begin(); it != m_classes.end(); ++it) { Class const * klass = *it; if (klass->ShouldGenerate()) { klass->GenerateCode(fileId, outCode, this); } } /// write ScFileID definition outCode << "\n\n#undef ScFileID\n"; outCode << "#define ScFileID " << fileId; // generate output file boost::filesystem::path outputPath(m_options.outputPath); outputPath /= boost::filesystem::path(GetOutputFileName(fileName)); std::ofstream outputFile(outputPath.string()); outputFile << outCode.str(); outputFile << std::endl << std::endl; outputFile.close(); } clang_disposeIndex(m_index); clang_disposeTranslationUnit(m_translationUnit); } catch (Exception e) { clang_disposeIndex(m_index); clang_disposeTranslationUnit(m_translationUnit); EMIT_ERROR(e.GetDescription()); } return true; }
// Note: logfile is not passed as a reference because we need a local // copy to modify anyhow. bool ReadMultipleUserLogs::monitorLogFile( MyString logfile, bool truncateIfFirst, CondorError &errstack ) { dprintf( D_LOG_FILES, "ReadMultipleUserLogs::monitorLogFile(%s, %d)\n", logfile.Value(), truncateIfFirst ); MyString fileID; if ( !GetFileID( logfile, fileID, errstack ) ) { errstack.push( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error getting file ID in monitorLogFile()" ); return false; } LogFileMonitor *monitor; if ( allLogFiles.lookup( fileID, monitor ) == 0 ) { dprintf( D_LOG_FILES, "ReadMultipleUserLogs: found " "LogFileMonitor object for %s (%s)\n", logfile.Value(), fileID.Value() ); } else { dprintf( D_LOG_FILES, "ReadMultipleUserLogs: didn't " "find LogFileMonitor object for %s (%s)\n", logfile.Value(), fileID.Value() ); // Make sure the log file is in the correct state -- it must // exist, and be truncated if necessary. if ( !MultiLogFiles::InitializeFile( logfile.Value(), truncateIfFirst, errstack ) ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error initializing log file %s", logfile.Value() ); return false; } monitor = new LogFileMonitor( logfile ); ASSERT( monitor ); dprintf( D_LOG_FILES, "ReadMultipleUserLogs: created LogFileMonitor " "object for log file %s\n", logfile.Value() ); // Note: we're only putting a pointer to the LogFileMonitor // object into the hash table; the actual LogFileMonitor should // only be deleted in this object's destructor. if ( allLogFiles.insert( fileID, monitor ) != 0 ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error inserting %s into allLogFiles", logfile.Value() ); delete monitor; return false; } } if ( monitor->refCount < 1 ) { // Open the log file (return to previous location if it was // opened before). if ( monitor->state ) { // If we get here, we've monitored this log file before, // so restore the previous state. if ( monitor->stateError ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Monitoring log file %s fails because of " "previous error saving file state", logfile.Value() ); return false; } monitor->readUserLog = new ReadUserLog( *(monitor->state) ); } else { // Monitoring this log file for the first time, so create // the log reader from scratch. monitor->readUserLog = new ReadUserLog( monitor->logFile.Value() ); } if ( activeLogFiles.insert( fileID, monitor ) != 0 ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error inserting %s (%s) into activeLogFiles", logfile.Value(), fileID.Value() ); return false; } else { dprintf( D_LOG_FILES, "ReadMultipleUserLogs: added log " "file %s (%s) to active list\n", logfile.Value(), fileID.Value() ); } } monitor->refCount++; return true; }
// Note: logfile is not passed as a reference because we need a local // copy to modify anyhow. bool ReadMultipleUserLogs::unmonitorLogFile( MyString logfile, CondorError &errstack ) { dprintf( D_LOG_FILES, "ReadMultipleUserLogs::unmonitorLogFile(%s)\n", logfile.Value() ); MyString fileID; if ( !GetFileID( logfile, fileID, errstack ) ) { errstack.push( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error getting file ID in unmonitorLogFile()" ); return false; } LogFileMonitor *monitor; if ( activeLogFiles.lookup( fileID, monitor ) != 0 ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Didn't find LogFileMonitor object for log " "file %s (%s)!", logfile.Value(), fileID.Value() ); dprintf( D_ALWAYS, "ReadMultipleUserLogs error: %s\n", errstack.message() ); printAllLogMonitors( NULL ); return false; } dprintf( D_LOG_FILES, "ReadMultipleUserLogs: found " "LogFileMonitor object for %s (%s)\n", logfile.Value(), fileID.Value() ); monitor->refCount--; if ( monitor->refCount < 1 ) { // Okay, if we are no longer monitoring this file at all, // we need to close it. We do that by saving its state // into a ReadUserLog::FileState object (so we can go back // to the right place if we later monitor it again) and // then deleting the ReadUserLog object. dprintf( D_LOG_FILES, "Closing file <%s>\n", logfile.Value() ); if ( !monitor->state ) { monitor->state = new ReadUserLog::FileState(); if ( !ReadUserLog::InitFileState( *(monitor->state) ) ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Unable to initialize ReadUserLog::FileState " "object for log file %s", logfile.Value() ); monitor->stateError = true; delete monitor->state; monitor->state = NULL; return false; } } if ( !monitor->readUserLog->GetFileState( *(monitor->state) ) ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error getting state for log file %s", logfile.Value() ); monitor->stateError = true; delete monitor->state; monitor->state = NULL; return false; } delete monitor->readUserLog; monitor->readUserLog = NULL; // Now we remove this file from the "active" list, so // we don't check it the next time we get an event. if ( activeLogFiles.remove( fileID ) != 0 ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error removing %s (%s) from activeLogFiles", logfile.Value(), fileID.Value() ); dprintf( D_ALWAYS, "ReadMultipleUserLogs error: %s\n", errstack.message() ); printAllLogMonitors( NULL ); return false; } dprintf( D_LOG_FILES, "ReadMultipleUserLogs: removed " "log file %s (%s) from active list\n", logfile.Value(), fileID.Value() ); } return true; }
void OperateFile(uint8 Write ,uint8 Name[11], uint32 Start, uint32 Length, void* Data) { uint8 *data = Data; uint16 BytePerClus, SecPerClus, ClusNum, ClusNext,ClusID,ClusIDValue ,m,Index; uint32 LBA, i,length; DIR FileDir; SecPerClus = BPB_SecPerClus; BytePerClus = BPB_SecPerClus * BPB_BytesPerSec; //每簇的字节数 Index = GetFileID(Name, &FileDir); //文件根目录位置0~511 length = Length; //计算开始位置所在簇的簇号 ClusNum = Start / BytePerClus; ClusID = FileDir.FilePosit.Start; for(i = 0; i < ClusNum; i++) { ClusIDValue = ReadFAT(ClusID); //读取对应文件的FAT表,0xFFFF表示文件结束 WriteFAT(ClusID, 0xffff); WriteFAT2(ClusID, 0xffff); if(ClusIDValue==0xffff) //如过ClusIDValue值不为0xFFFF,其他的表示下一个簇地址 ClusNext = GetNextFAT(); else ClusNext = ClusIDValue; WriteFAT(ClusID, ClusNext); WriteFAT2(ClusID, ClusNext); ClusID = ClusNext; } WriteFAT(ClusID, 0xffff); WriteFAT2(ClusID, 0xffff); //计算开始位置所在扇区簇内偏移 i = (Start % BytePerClus) / 512; //计算开始位置扇区内偏移 m = (Start % BytePerClus) % 512; LBA = ClusConvLBA(ClusID) + i; for(i = 0; i < SecPerClus; i++) { if(Write) ReadBlock(LBA); else ReadBlock(LBA++); for(m = 0; m < 512; m++) { if(Write) BUFFER[m] = *data++; else *data++ = BUFFER[m]; //如果读取完成就退出 if(--Length == 0) { if(Write) { //回写扇区 WriteBlock(LBA); //回写目录 FileDir.FilePosit.Size = Start+length; WriteDIR(Index,&FileDir); } return; } } if(Write) WriteBlock(LBA++); //回写扇区,指针下移 } }
bool CNFS3Prog::GetFileAttributesForNFS(char *path, fattr3 *pAttr) { DWORD fileAttr; BY_HANDLE_FILE_INFORMATION lpFileInformation; HANDLE hFile; DWORD dwFlagsAndAttributes; fileAttr = GetFileAttributes(path); if (path == NULL || fileAttr == INVALID_FILE_ATTRIBUTES) { return false; } dwFlagsAndAttributes = 0; if (fileAttr & FILE_ATTRIBUTE_DIRECTORY) { pAttr->type = NF3DIR; dwFlagsAndAttributes = FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS; } else if (fileAttr & FILE_ATTRIBUTE_ARCHIVE) { pAttr->type = NF3REG; dwFlagsAndAttributes = FILE_ATTRIBUTE_ARCHIVE | FILE_FLAG_OVERLAPPED; } else if (fileAttr & FILE_ATTRIBUTE_NORMAL) { pAttr->type = NF3REG; dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED; } else { pAttr->type = 0; } if (fileAttr & FILE_ATTRIBUTE_REPARSE_POINT) { pAttr->type = NF3LNK; dwFlagsAndAttributes = FILE_ATTRIBUTE_REPARSE_POINT | FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS; } hFile = CreateFile(path, FILE_READ_EA, FILE_SHARE_READ, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL); if (hFile == INVALID_HANDLE_VALUE) { return false; } GetFileInformationByHandle(hFile, &lpFileInformation); CloseHandle(hFile); pAttr->mode = 0; // Set execution right for all pAttr->mode |= 0x49; // Set read right for all pAttr->mode |= 0x124; //if ((lpFileInformation.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) { pAttr->mode |= 0x92; //} ULONGLONG fileSize = lpFileInformation.nFileSizeHigh; fileSize <<= sizeof(lpFileInformation.nFileSizeHigh) * 8; fileSize |= lpFileInformation.nFileSizeLow; pAttr->nlink = lpFileInformation.nNumberOfLinks; pAttr->uid = m_nUID; pAttr->gid = m_nGID; pAttr->size = fileSize; pAttr->used = pAttr->size; pAttr->rdev.specdata1 = 0; pAttr->rdev.specdata2 = 0; pAttr->fsid = 7; //NTFS //4; pAttr->fileid = GetFileID(path); pAttr->atime.seconds = FileTimeToPOSIX(lpFileInformation.ftLastAccessTime); pAttr->atime.nseconds = 0; pAttr->mtime.seconds = FileTimeToPOSIX(lpFileInformation.ftLastWriteTime); pAttr->mtime.nseconds = 0; // This seems to be the changed time, not creation time pAttr->ctime.seconds = FileTimeToPOSIX(lpFileInformation.ftLastWriteTime); pAttr->ctime.nseconds = 0; return true; }
nfsstat3 CNFS3Prog::ProcedureREADDIRPLUS(void) { char *path; cookie3 cookie; cookieverf3 cookieverf; count3 dircount, maxcount; post_op_attr dir_attributes; fileid3 fileid; filename3 name; post_op_attr name_attributes; post_op_fh3 name_handle; bool eof; nfsstat3 stat; char filePath[MAXPATHLEN]; int handle, nFound; struct _finddata_t fileinfo; unsigned int i, j; bool bFollows; PrintLog("READDIRPLUS"); path = GetPath(); Read(&cookie); Read(&cookieverf); Read(&dircount); Read(&maxcount); stat = CheckFile(path); if (stat == NFS3_OK) { dir_attributes.attributes_follow = GetFileAttributesForNFS(path, &dir_attributes.attributes); if (!dir_attributes.attributes_follow) { stat = NFS3ERR_IO; } } Write(&stat); Write(&dir_attributes); if (stat == NFS3_OK) { Write(&cookieverf); sprintf_s(filePath, "%s\\*", path); handle = _findfirst(filePath, &fileinfo); eof = true; if (handle) { nFound = 0; for (i = (unsigned int)cookie; i > 0; i--) { nFound = _findnext(handle, &fileinfo); } if (nFound == 0) { bFollows = true; j = 10; do { Write(&bFollows); //value follows sprintf_s(filePath, "%s\\%s", path, fileinfo.name); fileid = GetFileID(filePath); Write(&fileid); //file id name.Set(fileinfo.name); Write(&name); //name ++cookie; Write(&cookie); //cookie name_attributes.attributes_follow = GetFileAttributesForNFS(filePath, &name_attributes.attributes); Write(&name_attributes); name_handle.handle_follows = GetFileHandle(filePath, &name_handle.handle); Write(&name_handle); if (--j == 0) { eof = false; break; } } while (_findnext(handle, &fileinfo) == 0); } _findclose(handle); } bFollows = false; Write(&bFollows); //value follows Write(&eof); //eof } return stat; }
nfsstat3 CNFS3Prog::ProcedureREADDIR(void) { char *path; cookie3 cookie; cookieverf3 cookieverf; count3 count; post_op_attr dir_attributes; fileid3 fileid; filename3 name; bool eof; bool bFollows; nfsstat3 stat; char filePath[MAXPATHLEN]; int handle; struct _finddata_t fileinfo; PrintLog("READDIR"); path = GetPath(); Read(&cookie); Read(&cookieverf); Read(&count); stat = CheckFile(path); if (stat == NFS3_OK) { dir_attributes.attributes_follow = GetFileAttributesForNFS(path, &dir_attributes.attributes); if (!dir_attributes.attributes_follow) { stat = NFS3ERR_IO; } } Write(&stat); Write(&dir_attributes); if (stat == NFS3_OK) { Write(&cookieverf); sprintf_s(filePath, "%s\\*", path); cookie = 0; eof = false; handle = _findfirst(filePath, &fileinfo); bFollows = true; if (handle) { do { Write(&bFollows); //value follows sprintf_s(filePath, "%s\\%s", path, fileinfo.name); fileid = GetFileID(filePath); Write(&fileid); //file id name.Set(fileinfo.name); Write(&name); //name ++cookie; Write(&cookie); //cookie } while (_findnext(handle, &fileinfo) == 0); _findclose(handle); } bFollows = false; Write(&bFollows); eof = true; Write(&eof); //eof } return stat; }
bool ParseCmd(char *cmd) { char operate[100]; sscanf(cmd,"%s",operate); if (!strcmp(operate,"fmt")) { printf("Disk Formating. Please Wait.\n"); Format(); printf("Disk Format Compleated.\n"); } else if (!strcmp(operate,"dr")) { printf("%s\\ 的目录 \n\n",NowDirRoute); Dir(); } else if (!strcmp(operate,"cp")) { isEditing=true; printf("复制中,请稍候.\n"); char file1[1000],file2[1000]; sscanf(cmd,"%*s %s %s",file1,file2); //char dir[1000]; //char filename[10],extention[4]; //sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char filename[10],extention[4]; char filename2[10],extention2[4]; if (strchr(file1,':')) { char *p=strlen(file2)+file2; while(p!=file2) { if (*p=='\\') { break; } p--; } if (p!=file2) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(file2); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } //sscanf(file2,"%[^.]%*c%s",filename,extention); Copy(3,file1,0,filename,extention); } else if (strchr(file2,':')) { char *p=strlen(file1)+file1; while(p!=file1) { if (*p=='\\') { break; } p--; } if (p!=file1) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(file1); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } //sscanf(file2,"%[^.]%*c%s",filename,extention); Copy(2,filename,extention,file2,0); } else { if (!strchr(file1,'\\')&&!strchr(file2,'\\')) { sscanf(file1,"%[^.]%*c%s",filename,extention); sscanf(file2,"%[^.]%*c%s",filename2,extention2); Copy(1,filename,extention,filename2,extention2); } else { char *p=strlen(file1)+file1; while(p!=file1) { if (*p=='\\') { break; } p--; } if (p!=file1) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(file1); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } char ctmp[100]="c:\\"; strcat(ctmp,filename); strcat(ctmp,"_blegtmp."); strcat(ctmp,extention); Copy(2,filename,extention,ctmp,0); ChangeNowDir(OriDir); char *q=strlen(file2)+file2; while(q!=file2) { if (*q=='\\') { break; } q--; } if (q!=file2) { q++; sscanf(q,"%[^.]%*c%s",filename,extention); q--; *q=0; ChangeNowDir(file2); } else { sscanf(q,"%[^.]%*c%s",filename,extention); } Copy(3,ctmp,0,filename,extention); //ChangeNowDir(OriDir); } } ChangeNowDir(OriDir); printf("文件复制完成。\n"); isEditing=false; } else if (!strcmp(operate,"user")) { printf("请输入新用户名:"); while(1) { char tmp[100]; scanf("%s",tmp); if (strlen(tmp)<10) { strcpy(Username,tmp); break; } printf("用户名不能超过 10 个字符,请重新输入新用户名:"); } bool correct=false; int len=0; char tmp[20]; char tmp2[20]; memset(tmp2,0,20); memset(tmp,0,20); while(!correct) { printf("请输入新密码:"); while(1) { char ch=getch(); if (!isdigit(ch)&&!isalpha(ch)&&ch!=13) { continue; } if (ch==13) { if (len>=10) { printf("\n密码必须小于 10 个字符,请重新输入新密码:"); len=0; memset(tmp,0,20); continue; } else { printf("\n请再次输入新密码:"); len=0; break; } } else { tmp[len++]=ch; printf("*"); } } while(1) { char ch=getch(); if (!isdigit(ch)&&!isalpha(ch)&&ch!=13) { continue; } if (ch==13) { if (!strcmp(tmp,tmp2)) { printf("\n新密码已确认。\n"); getchar(); correct=true; break; } else { break; } } tmp2[len++]=ch; printf("*"); } } } else if(!strcmp(operate,"rm")) { char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } bool succ=Delete(1,filename,extention); if(succ) printf("一个文件已被删除.\n"); ChangeNowDir(OriDir); } else if (!strcmp(operate,"block")) { printf("文件所使用的数据块有:\n"); char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } BlockOfFile(filename,extention); ChangeNowDir(OriDir); } else if (!strcmp(operate,"rmdir")) { char dir[1000]; sscanf(cmd,"%*s %s",dir); bool succ=Delete(2,dir,0); if (succ) { printf("一个文件夹已被删除.\n"); } } else if (!strcmp(operate,"deleted")) { printf("回收站:\n"); Delete(3,0,0); } else if (!strcmp(operate,"type")) { char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } int fid=GetFileID(filename,extention); Display(1,fid); ChangeNowDir(OriDir); } else if (!strcmp(operate,"more")) { /* char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } int fid=GetFileID(filename,extention); Display(2,fid); ChangeNowDir(OriDir); */ //system("dir"); char filename[10],extention[4]; sscanf(cmd,"%*s %[^.]%*c%s",filename,extention); char tmp[100]; memset(tmp,0,100); strcat(tmp,"c:\\"); strcat(tmp,filename); strcat(tmp,"."); strcat(tmp,extention); Copy(2,filename,extention,tmp,0); char ccmd[100]="more "; strcat(ccmd,tmp); system(ccmd); } else if(!strcmp(operate,"att")) { char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } DisplayAttribute(filename,extention); ChangeNowDir(OriDir); } else if (!strcmp(operate,"help")) { } else if (!strcmp(operate,"cd")) { char Dir[1000]; sscanf(cmd,"%*s %s",Dir); ChangeNowDir(Dir); } else if (!strcmp(operate,"close")) { Close(); } else if (!strcmp(operate,"new")) { char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } bool succ=New(1,filename,extention); if (succ) { printf("文件创建成功。\n"); } ChangeNowDir(OriDir); } else if (!strcmp(operate,"aaa")) { printf("%d\n",TotalFileNum); printf("%s\n",NowDirRoute); } else if (!strcmp(operate,"newdir")) { char filename[10]; sscanf(cmd,"%*s %s",filename); bool succ=New(2,filename,0); if (succ) { printf("目录创建成功。\n"); } } else if (!strcmp(operate,"editw")) { isEditing=true; char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } Edit(1,filename,extention); printf("1 Files Saved.\n"); ChangeNowDir(OriDir); isEditing=false; } else if (!strcmp(operate,"edita")) { isEditing=true; char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } Edit(2,filename,extention); printf("1 Files Saved.\n"); ChangeNowDir(OriDir); isEditing=false; } else if (!strcmp(operate,"rc")) { char dir[1000]; char filename[10],extention[4]; sscanf(cmd,"%*s %s",dir); char OriDir[1000]; strcpy(OriDir,NowDirRoute); char *p=strlen(dir)+dir; while(p!=dir) { if (*p=='\\') { break; } p--; } if (p!=dir) { p++; sscanf(p,"%[^.]%*c%s",filename,extention); p--; *p=0; ChangeNowDir(dir); } else { sscanf(p,"%[^.]%*c%s",filename,extention); } recovery(filename,extention); printf("文件已恢复。\n"); ChangeNowDir(OriDir); } else if (!strcmp(operate,"space")) { // #ifdef _1M_ // printf("总空间: 1048576 Bytes.可用空间: %d Bytes.剩余空间: %d Bytes.\n",FDBNum*4096,FreeFDBNum*4096); // #endif #ifdef _1G_ printf("总空间: 1073741824 Bytes.可用空间: %d Bytes.剩余空间: %d Bytes.\n",FDBNum*4096,FreeFDBNum*4096); #endif } else if (!strcmp(operate,"tree")) { printf("%s 的文件结构树:\n",NowDirRoute); printf(".\n"); Tree(1,NowDirFid); } else { printf("illegal instruction\n"); } return true; }