-
Notifications
You must be signed in to change notification settings - Fork 4
Example codes
kms1212 edited this page Mar 26, 2022
·
6 revisions
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <openfsl/openfsl.h>
#include <openfsl/fat32/fs_fat32.h>
int main(int argc, char** argv) {
openfsl::FileBlockDevice fbd;
openFSL::BlockDevice::DiskParameter parameter;
parameter.bytesPerSector = 512; // Default BPS value = 512
parameter.sectorPerTrack = 63; // Default SPT value = 63
parameter.headPerCylinder = 16; // Default HPC value = 16
fbd.setDiskParameter(parameter);
// Open FAT32 image file with Read/Write mode and initialize fbd class____
fbd.initialize("fat32.img", openfsl::FileBlockDevice::OpenMode::RW);
/* ^ ^
Image file name File mode */
// Initialize FAT32 file system___________________________________________
openFSL::FAT32 fat32(&fbd, "\\/", "::");
/* ^ ^ ^
| | Root directory name (in this example, "::/subdir" represents
| | subdirectory "subdir" in the root directory.)
| Path separator.
| Can contain multiple characters,
| the first one is the main separator and the others are alternatives.
Disk device class pointer to use in fat32 */
// FAT32 enable cache_____________________________________________________
fat32.enableCache(128); // Maximum cache entry size. Memory usage is variable.
// FAT32 change directory_________________________________________________
fat32.changeDirectory("::/foo/bar/baz/..");
/* ^
Path to navigate */
// FAT32 list directory___________________________________________________
std::vector<openFSL::FS_FAT32::FileInfo> buf; // buffer to store list
fat32.listDirectory(&buf, // File list buffer, will be cleared when method called.
"..", // Path to list
openFSL::FS_FAT32::FileAttribute::Directory | openFSL::FS_FAT32::FileAttribute::Archive // Filter
);
return 0;
}