void FileSystem::createFile(arguments str, outputStream out) { checkArgumentsCount(str, 2); std::ofstream::pos_type size = std::stoll(str.at(1)); // 1234asd321 -> 1234, its ok? if(_fsFile->create(str.at(0), size)) { out << "File created"; } else { out << "file not created"; } out << "\n"; }
void FileSystem::filestat(arguments arg, outputStream out) { checkArgumentsCount(arg, 1); uint64_t descriptorId = std::stoll(arg.at(0)); FSDescriptor descriptor; try { descriptor = _descriptors.getDescriptor(descriptorId); } catch(const std::invalid_argument &) { out << "Bad descriptor\n"; return; } if(descriptor.type == DescriptorVariant::None) { out << "Descriptor does not exist\n"; return; } using std::to_string; out << "File statistic: \n\tid: " << descriptorId; if(descriptor.type == DescriptorVariant::File) { out << descriptor.fileSize; } out << "\n\tType: " << to_string(descriptor.type) << "\n\tReferences: " << descriptor.referencesCount << "\n\tHas extended blocks: " << (descriptor.nextDataSegment == Constants::HEADER_ADDRESS() ? "false" : "true") << "\n"; }
void FileSystem::create(arguments arg) { checkArgumentsCount(arg, 1); FSDescriptor fileDescriptor; fileDescriptor.initFile(); allocAndAppendDescriptorToCurrentFolder(fileDescriptor, arg.at(0)); }
void FileSystem::cd(arguments arg) { checkArgumentsCount(arg, 1); _currentFolder = getLastPathElementHandle(arg.at(0)) .descriptorHandle(); // auto v = p.getParsedPath(); }
void FileSystem::mkdir(arguments arg) { checkArgumentsCount(arg, 1); FSDescriptor fileDescriptor; fileDescriptor.initDirectory(currentDirectory()); string name = arg.at(0); allocAndAppendDescriptorToCurrentFolder(fileDescriptor, name); }
void FileSystem::mount(arguments str) { checkArgumentsCount(str, 1); _fsFile->open(str.at(0)); if(_fsFile->isFormatedFS()) { fileFormatChanged(); } else { } }
void FileSystem::rmdir(arguments arg, outputStream out) { checkArgumentsCount(arg, 1); string name = arg.at(0); if(removeDescriptorFromDirectory(currentDirectory(), DescriptorVariant::Directory, name)) { out << "Directory deleted\n"; } else { out << "Directory not found\n"; } }
void FileSystem::unlink(arguments arg, outputStream out) { checkArgumentsCount(arg, 1); string name = arg.at(0); descriptorIndex_tp dir = currentDirectory(); if(removeDescriptorFromDirectory(dir, DescriptorVariant::File | DescriptorVariant::SymLink, name)) { out << "Descriptor deleted\n"; } else { out << "Descriptor not found\n"; } }
void FileSystem::close(arguments arg) { checkArgumentsCount(arg, 1); uint64_t openedDescriptor = std::stoull(arg.at(1)); auto findResult = _opennedFiles.find(openedDescriptor); if(findResult == _opennedFiles.end()) { throw file_system_exception("Descriptor currently not open."); } else { _opennedFiles.erase(findResult); } }
void FileSystem::link(arguments arg) { checkArgumentsCount(arg, 2); string srcName = arg.at(0); string destName = arg.at(1); descriptorIndex_tp destDir = currentDirectory(); descriptorIndex_tp srcDir = currentDirectory(); auto it = getDirectoryDescriptorIterator(srcDir); while(it.hasNext()) { ++it; if(it->name(header().filenameLength) == srcName) { addDescriptorToDirectory(destDir, it->descriptor, destName); } } }