diff --git a/kernel/kernel/FS/FAT/FileSystem.cpp b/kernel/kernel/FS/FAT/FileSystem.cpp index 145290c4..d7c01b9f 100644 --- a/kernel/kernel/FS/FAT/FileSystem.cpp +++ b/kernel/kernel/FS/FAT/FileSystem.cpp @@ -124,18 +124,6 @@ namespace Kernel { LockGuard _(m_mutex); - uint32_t block_count = 0; - { - uint32_t cluster = entry.first_cluster_lo; - if (m_type == Type::FAT32) - cluster |= static_cast(entry.first_cluster_hi) << 16; - while (cluster >= 2 && cluster < cluster_count()) - { - block_count++; - cluster = TRY(get_next_cluster(cluster)); - } - } - uint32_t entry_cluster; switch (m_type) { @@ -144,25 +132,34 @@ namespace Kernel if (parent == m_root_inode) entry_cluster = 1; else - { entry_cluster = parent->entry().first_cluster_lo; - for (uint32_t i = 0; i < cluster_index; i++) - entry_cluster = TRY(get_next_cluster(entry_cluster)); - } break; case Type::FAT32: if (parent == m_root_inode) entry_cluster = m_bpb.ext_32.root_cluster; else entry_cluster = (static_cast(parent->entry().first_cluster_hi) << 16) | parent->entry().first_cluster_lo; - for (uint32_t i = 0; i < cluster_index; i++) - entry_cluster = TRY(get_next_cluster(entry_cluster)); break; default: ASSERT_NOT_REACHED(); } - const ino_t ino = (static_cast(entry_cluster) << 32) | entry_index; + uint32_t block_count = 0; + for (uint32_t i = 0; i < cluster_index; i++) + { + block_count++; + entry_cluster = TRY(get_next_cluster(entry_cluster)); + } + + const uint32_t dirent_per_cluster = m_bpb.bytes_per_sector * m_bpb.sectors_per_cluster / sizeof(FAT::DirectoryEntry); + ASSERT(BAN::Math::is_power_of_two(dirent_per_cluster)); + ASSERT(entry_index < dirent_per_cluster); + + const uint32_t ino_cluster_shift = BAN::Math::ctz(dirent_per_cluster); + const ino_t ino = (static_cast(entry_cluster) << ino_cluster_shift) | entry_index; + if (ino >> ino_cluster_shift != entry_cluster) + dwarnln("FAT ino mapping not unique"); + auto it = m_inode_cache.find(ino); if (it != m_inode_cache.end()) { diff --git a/userspace/libraries/LibC/include/sys/types.h b/userspace/libraries/LibC/include/sys/types.h index afa0d6be..a05c331f 100644 --- a/userspace/libraries/LibC/include/sys/types.h +++ b/userspace/libraries/LibC/include/sys/types.h @@ -98,7 +98,7 @@ __BEGIN_DECLS #if !defined(__ino_t_defined) && (defined(__need_all_types) || defined(__need_ino_t)) #define __ino_t_defined 1 - typedef unsigned long long ino_t; + typedef unsigned int ino_t; #endif #undef __need_ino_t diff --git a/userspace/programs/stat/main.cpp b/userspace/programs/stat/main.cpp index b3ecdf2c..d44c0a1a 100644 --- a/userspace/programs/stat/main.cpp +++ b/userspace/programs/stat/main.cpp @@ -79,7 +79,7 @@ int main(int argc, char** argv) printf("\n"); printf(" Size: %-15ld Blocks: %-10ld IO Block: %-6ld %s\n", st.st_size, st.st_blocks, st.st_blksize, type); - printf("Device: %u,%-5u Inode: %-11llu Links: %-5lu Device type: %u,%u\n", major(st.st_dev), minor(st.st_dev), st.st_ino, st.st_nlink, major(st.st_rdev), minor(st.st_rdev)); + printf("Device: %u,%-5u Inode: %-11u Links: %-5lu Device type: %u,%u\n", major(st.st_dev), minor(st.st_dev), st.st_ino, st.st_nlink, major(st.st_rdev), minor(st.st_rdev)); printf("Access: (%04o/%s) Uid: %5d Gid: %5d\n", st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX), access, st.st_uid, st.st_gid); printf("Access: "); print_timestamp(st.st_atim); printf("\n"); printf("Modify: "); print_timestamp(st.st_mtim); printf("\n");