xaizek / tos (License: GPLv3 only) (since 2018-12-07)
This is an alternative version of sources presented as part of Write Your Own OS video tutorial by Viktor Engelmann.
Commit 888a93b2b76bf5d903eb777bd6e9d6b3a8634251

Fix bugs in reading files
Author: xaizek
Author date (UTC): 2018-04-12 09:00
Committer name: xaizek
Committer date (UTC): 2018-04-12 13:51
Parent(s): 94ae3c0eeefc0a1baa186b8a74509e024ae3bb8f
Signing key: 99DC5E4DB05F6BE2
Tree: c8cea34ec55197142f64de9b472b91c76819b673
File Lines added Lines deleted
src/fs/fat.cpp 10 4
File src/fs/fat.cpp changed (mode: 100644) (index 9b2ff57..73d5fce)
... ... FAT::printFileContents(const DirectoryEntryFat32 &ent) const
61 61 + bpb.sectorsPerCluster*(currentCluster - 2); + bpb.sectorsPerCluster*(currentCluster - 2);
62 62 int sectorOffset = 0; int sectorOffset = 0;
63 63
64 for (; size > 0; size -= 512) {
64 while (size > 0) {
65 65 hd.read28(sector + sectorOffset, buffer, 512); hd.read28(sector + sectorOffset, buffer, 512);
66 66
67 67 buffer[size > 512 ? 512 : size] = '\0'; buffer[size > 512 ? 512 : size] = '\0';
68 68 kprint(reinterpret_cast<const char *>(buffer)); kprint(reinterpret_cast<const char *>(buffer));
69 69
70 if (++sectorOffset > bpb.sectorsPerCluster) {
70 size -= 512;
71
72 if (++sectorOffset == bpb.sectorsPerCluster) {
71 73 break; break;
72 74 } }
73 75 } }
74 76
75 std::uint8_t fat[513];
77 if (size <= 0) {
78 break;
79 }
80
81 std::uint8_t fat[512];
76 82 std::uint32_t fatSector = currentCluster/(512/sizeof(std::uint32_t)); std::uint32_t fatSector = currentCluster/(512/sizeof(std::uint32_t));
77 83 hd.read28(fatStart + fatSector, fat, 512); hd.read28(fatStart + fatSector, fat, 512);
78 std::uint32_t fatOffset = currentCluster%(512/sizeof(std::uint32_t));
84 std::uint32_t fatOffset = currentCluster%(512/sizeof(std::uint32_t))*4;
79 85
80 86 currentCluster = fat[fatOffset + 3] & 0x0f; currentCluster = fat[fatOffset + 3] & 0x0f;
81 87 currentCluster = (currentCluster << 8) | fat[fatOffset + 2]; currentCluster = (currentCluster << 8) | fat[fatOffset + 2];
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/tos

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/tos

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master