M module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp => module-vfs/drivers/src/purefs/fs/filesystem_littlefs.cpp +11 -3
@@ 120,10 120,11 @@ namespace
LOG_ERROR("Block size doesn't match partition size");
return -ERANGE;
}
- cfg->block_count = total_siz / cfg->block_size;
+ cfg->block_count = total_siz / cfg->block_size - 1;
cfg->read_size = cfg->block_size;
cfg->prog_size = cfg->block_size;
cfg->cache_size = cfg->block_size;
+ LOG_INFO("LFS: block_count %u sector_size %u", unsigned(cfg->block_count), unsigned(cfg->block_size));
return 0;
}
@@ 220,13 221,20 @@ namespace purefs::fs::drivers
}
{
auto diskmm = disk_mngr();
- auto ssize = diskmm->get_info(disk, blkdev::info_type::sector_size);
+ const auto ssize = diskmm->get_info(disk, blkdev::info_type::sector_size);
if (ssize < 0) {
LOG_ERROR("Unable to read sector size %i", int(ssize));
err = ssize;
}
else {
- err = setup_lfs_config(vmnt->lfs_config(), ssize, disk->sectors());
+ auto sect_count = diskmm->get_info(disk, blkdev::info_type::sector_count);
+ if (sect_count > 0) {
+ err = setup_lfs_config(vmnt->lfs_config(), ssize, sect_count);
+ }
+ else {
+ LOG_ERROR("Unable to read sector count %i", int(sect_count));
+ err = sect_count;
+ }
}
}
if (!err) {
M module-vfs/include/user/purefs/blkdev/defs.hpp => module-vfs/include/user/purefs/blkdev/defs.hpp +1 -1
@@ 26,7 26,7 @@ namespace purefs::blkdev
// Information parameter
enum class info_type
{
- sector_count, //! Number of sectors on disk
+ sector_count, //! Number of sectors on disk or part
sector_size, //! Single sector size
erase_block //! Number of sectors in erase block
};
M module-vfs/src/purefs/blkdev/disk_manager.cpp => module-vfs/src/purefs/blkdev/disk_manager.cpp +12 -1
@@ 272,7 272,18 @@ namespace purefs::blkdev
LOG_ERROR("Disk doesn't exists");
return {};
}
- return disk->get_info(what);
+ //! When it is partition as for partition sectors count
+ if (what == info_type::sector_count && dfd->has_partition()) {
+ if (unsigned(dfd->partition()) >= disk->partitions().size()) {
+ LOG_ERROR("Partition number out of range");
+ return -ERANGE;
+ }
+ const auto part = disk->partitions()[dfd->partition()];
+ return part.num_sectors;
+ }
+ else {
+ return disk->get_info(what);
+ }
}
auto disk_manager::reread_partitions(disk_fd dfd) -> int
{