Skip to content

Commit d5c9055

Browse files
authored
Merge pull request #823 from alfred-bratterud/dev
PIT fix, cached fs from gunzo, clang++ from spjoe
2 parents 4b04d67 + 361fbc0 commit d5c9055

10 files changed

Lines changed: 89 additions & 34 deletions

File tree

api/fs/fat.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <functional>
2525
#include <cstdint>
2626
#include <memory>
27+
#include <map>
2728

2829
namespace fs
2930
{
@@ -32,24 +33,26 @@ namespace fs
3233
struct FAT : public FileSystem
3334
{
3435
/// ----------------------------------------------------- ///
35-
virtual void mount(uint64_t lba, uint64_t size, on_mount_func on_mount) override;
36+
void mount(uint64_t lba, uint64_t size, on_mount_func on_mount) override;
3637

3738
// path is a path in the mounted filesystem
38-
virtual void ls (const std::string& path, on_ls_func) override;
39-
virtual void ls (const Dirent& entry, on_ls_func) override;
40-
virtual List ls(const std::string& path) override;
41-
virtual List ls(const Dirent&) override;
39+
void ls (const std::string& path, on_ls_func) override;
40+
void ls (const Dirent& entry, on_ls_func) override;
41+
List ls(const std::string& path) override;
42+
List ls(const Dirent&) override;
4243

4344
/** Read @n bytes from file pointed by @entry starting at position @pos */
44-
virtual void read(const Dirent&, uint64_t pos, uint64_t n, on_read_func) override;
45-
virtual Buffer read(const Dirent&, uint64_t pos, uint64_t n) override;
45+
void read(const Dirent&, uint64_t pos, uint64_t n, on_read_func) override;
46+
Buffer read(const Dirent&, uint64_t pos, uint64_t n) override;
4647

4748
// return information about a filesystem entity
48-
virtual void stat(const std::string&, on_stat_func) override;
49-
virtual Dirent stat(const std::string& ent) override;
49+
void stat(const std::string&, on_stat_func) override;
50+
Dirent stat(const std::string& ent) override;
51+
// async cached stat
52+
void cstat(const std::string&, on_stat_func) override;
5053

5154
// returns the name of the filesystem
52-
virtual std::string name() const override
55+
std::string name() const override
5356
{
5457
switch (this->fat_type)
5558
{
@@ -91,7 +94,7 @@ namespace fs
9194
uint8_t attrib;
9295
uint8_t pad1[8];
9396
uint16_t cluster_hi;
94-
uint8_t pad2[4];
97+
uint32_t modified;
9598
uint16_t cluster_lo;
9699
uint32_t filesize;
97100

@@ -210,6 +213,9 @@ namespace fs
210213
uint32_t root_cluster; // index of root cluster
211214
uint32_t data_index; // index of first data sector (relative to partition)
212215
uint32_t data_sectors; // number of data sectors
216+
217+
// simplistic cache for stat results
218+
std::map<std::string, FileSystem::Dirent> stat_cache;
213219
};
214220

215221
} // fs

api/fs/filesystem.hpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ namespace fs {
6262
struct Dirent {
6363
/** Default constructor */
6464
explicit Dirent(const Enttype t = INVALID_ENTITY, const std::string& n = "",
65-
const uint64_t blk = 0U, const uint64_t pr = 0U,
66-
const uint64_t sz = 0U, const uint32_t attr = 0U) :
67-
ftype {t},
68-
fname {n},
69-
block {blk},
70-
parent {pr},
71-
size_ {sz},
72-
attrib {attr},
73-
timestamp {0}
65+
const uint64_t blk = 0, const uint64_t pr = 0,
66+
const uint64_t sz = 0, const uint32_t attr = 0,
67+
const uint32_t modt = 0)
68+
: ftype {t},
69+
fname {n},
70+
block {blk},
71+
parent {pr},
72+
size_ {sz},
73+
attrib {attr},
74+
modif {modt}
7475
{}
7576

7677
Enttype type() const noexcept
@@ -108,6 +109,25 @@ namespace fs {
108109
} //< switch (type)
109110
}
110111

112+
// good luck
113+
uint64_t modified() const
114+
{
115+
/*
116+
uint32_t oldshit = modif;
117+
uint32_t day = (oldshit & 0x1f);
118+
uint32_t month = (oldshit >> 5) & 0x0f;
119+
uint32_t year = (oldshit >> 9) & 0x7f;
120+
oldshit >>= 16;
121+
uint32_t secs = (oldshit & 0x1f) * 2;
122+
uint32_t mins = (oldshit >> 5) & 0x3f;
123+
uint32_t hrs = (oldshit >> 11) & 0x1f;
124+
// invalid timestamp?
125+
if (hrs > 23 or mins > 59 or secs > 59)
126+
return 0;
127+
*/
128+
return modif;
129+
}
130+
111131
uint64_t size() const noexcept {
112132
return size_;
113133
}
@@ -118,7 +138,7 @@ namespace fs {
118138
uint64_t parent; //< Parent's block#
119139
uint64_t size_;
120140
uint32_t attrib;
121-
int64_t timestamp;
141+
uint32_t modif;
122142
}; //< struct Dirent
123143

124144
struct List {
@@ -168,6 +188,9 @@ namespace fs {
168188
virtual void stat(const std::string& ent, on_stat_func) = 0;
169189
virtual Dirent stat(const std::string& ent) = 0;
170190

191+
/** Cached async stat */
192+
virtual void cstat(const std::string&, on_stat_func) = 0;
193+
171194
/** Returns the name of this filesystem */
172195
virtual std::string name() const = 0;
173196

api/kernel/os.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
#ifndef KERNEL_OS_HPP
1919
#define KERNEL_OS_HPP
2020

21-
#ifndef OS_VERSION
22-
#define OS_VERSION "v?.?.?"
23-
#endif
24-
2521
#include <string>
2622
#include <sstream>
2723
#include <common>
@@ -45,7 +41,7 @@ class OS {
4541

4642
/* Get the version of the os */
4743
static std::string version()
48-
{ return std::string(OS_VERSION); }
44+
{ return version_field; }
4945

5046
/** Clock cycles since boot. */
5147
static uint64_t cycles_since_boot() {
@@ -168,7 +164,7 @@ class OS {
168164
static hw::Serial& com1;
169165

170166
static RTC::timestamp_t booted_at_;
171-
167+
static std::string version_field;
172168

173169
struct Custom_init_struct {
174170
Custom_init_struct(Custom_init f, const char* n)

src/fs/fat.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ namespace fs
239239
D->dir_cluster(root_cluster),
240240
sector, // parent block
241241
D->size(),
242-
D->attrib);
242+
D->attrib,
243+
D->modified);
243244
}
244245
}
245246
else {
@@ -255,7 +256,8 @@ namespace fs
255256
D->dir_cluster(root_cluster),
256257
sector, // parent block
257258
D->size(),
258-
D->attrib);
259+
D->attrib,
260+
D->modified);
259261
}
260262
} // entry is long name
261263

src/fs/fat_async.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ namespace fs
198198

199199
void FAT::stat(const std::string& strpath, on_stat_func func)
200200
{
201+
// manual lookup
201202
auto path = std::make_shared<Path> (strpath);
202203
if (unlikely(path->empty())) {
203204
// root doesn't have any stat anyways
@@ -223,7 +224,7 @@ namespace fs
223224
// find the matching filename in directory
224225
for (auto& e : *dirents) {
225226
if (unlikely(e.name() == filename)) {
226-
// read this file
227+
// return this dir entry
227228
func(no_error, e);
228229
return;
229230
}
@@ -233,4 +234,21 @@ namespace fs
233234
func({ error_t::E_NOENT, filename }, Dirent(INVALID_ENTITY, filename));
234235
});
235236
}
237+
238+
void FAT::cstat(const std::string& strpath, on_stat_func func)
239+
{
240+
// cache lookup
241+
auto it = stat_cache.find(strpath);
242+
if (it != stat_cache.end()) {
243+
debug("used cached stat for %s\n", strpath.c_str());
244+
func(no_error, it->second);
245+
return;
246+
}
247+
248+
stat(strpath,
249+
[this, strpath, func] (error_t error, const FileSystem::Dirent& ent) {
250+
stat_cache[strpath] = ent;
251+
func(error, ent);
252+
});
253+
}
236254
}

src/hw/pit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ namespace hw {
6161

6262
void PIT::disable_regular_interrupts()
6363
{
64-
oneshot(1);
65-
IRQ_manager::get().disable_irq(0);
64+
if (current_mode_ != ONE_SHOT)
65+
oneshot(1);
6666
}
6767

6868
PIT::PIT() {}

src/kernel/os.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ const uintptr_t OS::elf_binary_size_ {(uintptr_t)&_ELF_END_ - (uintptr_t)&_ELF_S
5454

5555
std::vector<OS::Custom_init_struct> OS::custom_init_;
5656

57+
#ifndef OS_VERSION
58+
#define OS_VERSION "v?.?.?"
59+
#endif
60+
std::string OS::version_field = OS_VERSION;
61+
5762
// Set default rsprint_handler
5863
OS::rsprint_func OS::rsprint_handler_ = &OS::default_rsprint;
5964
hw::Serial& OS::com1 = hw::Serial::port<1>();

src/seed/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ INC_NEWLIB=$(INSTALL)/newlib/include
4040
INC_LIBCXX=$(INSTALL)/libcxx/include
4141

4242
CC = $(shell command -v clang-3.8 || command -v clang-3.6) -target i686-elf
43-
CPP = $(shell command -v clang++-3.8 || command -v clang++-3.6) -target i686-elf
43+
CPP = $(shell command -v clang++-3.8 || command -v clang++-3.6 || command -v clang++) -target i686-elf
4444
ifndef LD_INC
4545
LD_INC = ld
4646
endif

src/seed/Makelib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ INC_NEWLIB=$(INSTALL)/newlib/include
2222
INC_LIBCXX=$(INSTALL)/libcxx/include
2323

2424
CC = $(shell command -v clang-3.8 || command -v clang-3.6) -target i686-elf
25-
CPP = $(shell command -v clang++-3.8 || command -v clang++-3.6) -target i686-elf
25+
CPP = $(shell command -v clang++-3.8 || command -v clang++-3.6 || command -v clang++) -target i686-elf
2626

2727
ifndef AR_INC
2828
AR_INC = ar

test/stress/service.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ uint64_t TCP_BYTES_SENT = 0;
7171

7272
void Service::start(const std::string&)
7373
{
74+
75+
// Timer spam
76+
for (int i = 0; i < 1000; i++)
77+
Timers::oneshot(std::chrono::microseconds(i + 200), [](auto){});
78+
7479
static auto& inet = net::Inet4::stack<0>();
7580

7681
// Static IP configuration, until we (possibly) get DHCP

0 commit comments

Comments
 (0)