本文整理汇总了C++中FileSystem::create方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSystem::create方法的具体用法?C++ FileSystem::create怎么用?C++ FileSystem::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: archivefs_create
int archivefs_create(const char *path, mode_t mode, struct fuse_file_info *info) {
char fpath[PATH_MAX];
fullpath(fpath, path);
FileSystem* fs;
int ret;
if (!getFile(fpath, &fs, NULL)) {
ret = creat(fpath, mode);
if (ret == -1) {
ret = errno;
print_err("CREATE", path, ret);
return -ret;
}
info->fh = intptr_t(ret);
return 0;
}
FileNode* node;
char* file;
parsePathName(fpath, &file);
struct fuse_context* context = fuse_get_context();
if (fs->parentAccess(file, W_OK|X_OK, context->uid, context->gid))
return -EACCES;
ret = fs->create(file, mode, &node);
if (ret)
print_err("CREATE", path, ret);
info->fh = intptr_t(new FileHandle(fs, node));
return -ret;
}
示例2: 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;
}
示例3: main
int main()
{
FileSystem sys;
sys.create("partition.sys");
Directory* root = sys.getRoot();
Directory* home = new Directory("home");
Directory* poney = new Directory("poney");
File* bashrc = new File(".bashrc");
bashrc->append("[ -f .bash_aliases ] && . .bash_aliases");
root->addNode(home);
home->addNode(poney);
poney->addNode(bashrc);
sys.flush();
}
示例4: main
int main(void) {
//_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
FileSystem fs;
string userCommand, commandArr[MAXCOMMANDS];
string user = "[email protected]"; // Change this if you want another user to be displayed
string currentDir = "/"; // current directory, used for output
bool bRun = true;
fs.format();
//HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
do {
currentDir = fs.GetCWD();
string data = "";
//SetConsoleTextAttribute(hConsole, 10);
cout << user << " ";
//SetConsoleTextAttribute(hConsole, 14);
cout << currentDir << endl;
//SetConsoleTextAttribute(hConsole, 15);
cout << "$ ";
getline(cin, userCommand);
for (unsigned i = 0; i < MAXCOMMANDS; ++i)
commandArr[i] = "";
int nrOfCommands = parseCommandString(userCommand, commandArr);
if (nrOfCommands > 0) {
int cIndex = findCommand(commandArr[0]);
switch(cIndex) {
case 0: // quit
bRun = false;
cout << "Exiting\n";
break;
case 1: // format
fs.format();
break;
case 2: // ls
if (commandArr[1] == "")
fs.ls();
else
fs.ls(commandArr[1]);
break;
case 3: // create
printf("Please Insert Data:\n");
getline( cin, data );
fs.create(commandArr[1],data);
break;
case 4: // cat
fs.cat(commandArr[1]);
break;
case 5: // createImage
fs.createImage( commandArr[1] );
break;
case 6: // restoreImage
fs.restoreImage( commandArr[1] );
break;
case 7: // rm
fs.rm(commandArr[1]);
break;
case 8: // copy
fs.copy( commandArr[1], commandArr[2] );
break;
case 9: // append
fs.append( commandArr[1], commandArr[2] );
break;
case 10: // rename
fs.rename( commandArr[1], commandArr[2] );
break;
case 11: // mkdir
fs.mkdir(commandArr[1]);
break;
case 12: // cd
fs.cd(commandArr[1]);
break;
case 13: // pwd
cout << fs.GetCWD() << endl;
break;
case 14: // help
cout << help() << endl;
break;
case 15: // rmdir
fs.rmdir(commandArr[1]);
break;
case 16: // chmod
fs.chmod( atoi( commandArr[1].c_str() ), commandArr[2] );
break;
//.........这里部分代码省略.........