本文整理汇总了C++中FileSystem::formatDisk方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSystem::formatDisk方法的具体用法?C++ FileSystem::formatDisk怎么用?C++ FileSystem::formatDisk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem::formatDisk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
FileSystem fileSystem;
int errCode;
//Format filesystem
errCode = fileSystem.formatDisk();
if(errCode == 1)
cout<<"Filesystem formatting failed"<<endl;
//Create a file and open it
int file1 = fileSystem.create();
int fileid1 = fileSystem.open(file1);
//This is the data we'll write
byte buffer[] = "Implementing File Systems, a test program";
//Seek to a large distance so that we actually cause an indirection. As usual, we skip the first 10 blocks, and then write
//Note that 256 is the block size. So, we seek to skip the first 10 direct blocks and then 10 bytes
fileSystem.seek(fileid1, 10*256 + 10, SEEK_CUR);
//Write 20 bytes at that position
//If you could not write 20 bytes, that is definitely an error
if(fileSystem.write(fileid1, buffer, 20) != 20)
cerr<<"Error!"<<endl;
//Close the file
fileSystem.close(fileid1);
//Reopen
fileid1 = fileSystem.open(file1);
/* Read from file currently does not work. So, commenting out */
/*
byte readbuf[16] = "\0";
fileSystem.read(fileid1, readbuf, 6);
cout<<"Read"<<readbuf<<"done" <<endl;
*/
//Owing to the non-functionality of read(), del() cannot be tested
//fileSystem.del(fileid1);
//By our write, we can calculate that the data block is 22
//free() would free that block and add it to the free list
//free() is a private function, however to show that it works, all you have to do is modify the FileSystem.h file and uncomment the following statement
//fileSystem.free(22);
//Also note that inumber() works. It is trivial to verify this
//Only read() and del() do not work.
return 0;
}
示例2: run
void run() {
//we prefer to have pointers so we create these:
FileSystem* fileSystem = &fs_;
File* file = &f_;
Directory* d = &d_;
xprintf("\n////////////////////////////\n"
"main > TESTING INIT AND MOUNT\n"
"//////////////////////\n");
fileSystem->enableDebugOutput(true);
//disk must be mounted before anything else can be done
fileSystem->mountDisk(0);
xprintf("main > mount done\n");
//format will create a new fat file system
//this can be omitted if there already is a fs on the disk
fileSystem->formatDisk(0);
xprintf("main > format done\n");
//setting time changes RODOS system time
fileSystem->setTime(2012, 03, 03, 07, 31, 12);
xprintf("\n////////////////////////////\n"
"main > TESTING DIRECTORY FUNTIONS\n"
"///////////////////////////\n");
file->enableDebugOutput(true);
file->open("/test.txt", file->O_WRITE);
file->putString("This is my first file!\n");
file->close();
xprintf("main > created '/test.txt'\n");
//this will not work because it does not create intermediate directories
xprintf("main > create dir '/FirstDir/ScndDir'\n");
fileSystem->createDirectory("/FirstDir/ScndDir");
bool isDir;
bool exists = fileSystem->fileExists("/FirstDir/ScndDir", &isDir);
if (!exists) {
xprintf("main > directory '/FirstDir/ScndDir' does not exist -> correct\n");
} else {
xprintf("main > directory '/FirstDir/ScndDir' exists -> NOT CORRECT\n");
}
//if we create directories one after the other everything will work fine
xprintf("main > create dir '/FirstDir'\n");
fileSystem->createDirectory("/FirstDir");
xprintf("main > create dir '/FirstDir/ScndDir'\n");
fileSystem->createDirectory("/FirstDir/ScndDir");
exists = fileSystem->fileExists("/FirstDir/ScndDir", &isDir);
if (!exists) {
xprintf("main > directory '/FirstDir/ScndDir' does not exist -> NOT CORRECT\n");
} else {
xprintf("main > directory '/FirstDir/ScndDir' exists -> correct\n");
}
//fill directory with files
fileSystem->move("/test.txt", "/FirstDir/test.txt");
file->open("FirstDir/file2.txt", file->O_WRITE);
file->putString("This is file2, dude.");
file->close();
file->open("FirstDir/file3.txt", file->O_WRITE);
file->putString("This is file3, bro.");
file->close();
//rename entire directory
fileSystem->move("FirstDir", "MyDir");
//open and interate through directory
d->open("/MyDir");
d->resetEntryEnumeration();
xprintf("main > reset entry numeration on '/MyDir/'\n");
char nextFileName[100];
long size;
d->readNextEntry(nextFileName, 100, &size);
while (nextFileName[0] != '\0') {
xprintf("main > next entry in '/MyDir/' is %s\nsize: %ld\n", nextFileName, size);
char path[200];
path[0] = 0;
xsprintf(path, "/MyDir/%s", nextFileName);
exists = fileSystem->fileExists(path, &isDir);
//.........这里部分代码省略.........