mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
VirtualFileSystem class builds inside Kernel.
This commit is contained in:
parent
9171521752
commit
d2425495ca
Notes:
sideshowbarker
2024-07-19 18:47:12 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d2425495ca7
8 changed files with 147 additions and 97 deletions
|
@ -1,12 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef SERENITY_KERNEL
|
||||
inline time_t time(time_t* tloc)
|
||||
{
|
||||
if (tloc)
|
||||
*tloc = 123;
|
||||
return 123;
|
||||
}
|
||||
#include <Kernel/ktime.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#define ktime time
|
||||
|
|
|
@ -28,7 +28,8 @@ VFS_OBJS = \
|
|||
../VirtualFileSystem/RandomDevice.o \
|
||||
../VirtualFileSystem/FileSystem.o \
|
||||
../VirtualFileSystem/DiskBackedFileSystem.o \
|
||||
../VirtualFileSystem/Ext2FileSystem.o
|
||||
../VirtualFileSystem/Ext2FileSystem.o \
|
||||
../VirtualFileSystem/VirtualFileSystem.o
|
||||
|
||||
AK_OBJS = \
|
||||
../AK/String.o \
|
||||
|
|
172
Kernel/VGA.cpp
172
Kernel/VGA.cpp
|
@ -11,55 +11,50 @@ PRIVATE BYTE current_attr = 0x07;
|
|||
|
||||
PRIVATE volatile WORD soft_cursor;
|
||||
|
||||
PRIVATE void print_num( DWORD );
|
||||
PRIVATE void print_hex( DWORD, BYTE fields );
|
||||
static void printSignedNumber(int);
|
||||
template<typename PutChFunc> static int printNumber(PutChFunc, char*&, DWORD);
|
||||
template<typename PutChFunc> static int printHex(PutChFunc, char*&, DWORD, BYTE fields);
|
||||
template<typename PutChFunc> static int printSignedNumber(PutChFunc, char*&, int);
|
||||
|
||||
PRIVATE void
|
||||
putch( char ch )
|
||||
static void vga_putch(char*, char ch)
|
||||
{
|
||||
WORD row;
|
||||
|
||||
switch( ch )
|
||||
{
|
||||
case '\n':
|
||||
row = soft_cursor / 80;
|
||||
if( row == 23 )
|
||||
{
|
||||
memcpy( vga_mem, vga_mem + 160, 160 * 23 );
|
||||
memset( vga_mem + (160 * 23), 0, 160 );
|
||||
soft_cursor = row * 80;
|
||||
}
|
||||
else
|
||||
soft_cursor = (row + 1) * 80;
|
||||
return;
|
||||
default:
|
||||
vga_mem[soft_cursor * 2] = ch;
|
||||
vga_mem[soft_cursor * 2 + 1] = current_attr;
|
||||
soft_cursor++;
|
||||
switch (ch) {
|
||||
case '\n':
|
||||
row = soft_cursor / 80;
|
||||
if (row == 23) {
|
||||
memcpy( vga_mem, vga_mem + 160, 160 * 23 );
|
||||
memset( vga_mem + (160 * 23), 0, 160 );
|
||||
soft_cursor = row * 80;
|
||||
} else {
|
||||
soft_cursor = (row + 1) * 80;
|
||||
}
|
||||
return;
|
||||
default:
|
||||
vga_mem[soft_cursor * 2] = ch;
|
||||
vga_mem[soft_cursor * 2 + 1] = current_attr;
|
||||
++soft_cursor;
|
||||
}
|
||||
row = soft_cursor / 80;
|
||||
if ((row >= 24 && current->handle() != IPC::Handle::PanelTask)) {
|
||||
memcpy( vga_mem, vga_mem + 160, 160 * 23 );
|
||||
memset( vga_mem + (160 * 23), 0, 160 );
|
||||
memcpy(vga_mem, vga_mem + 160, 160 * 23);
|
||||
memset(vga_mem + (160 * 23), 0, 160);
|
||||
soft_cursor = 23 * 80;
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
kprintf( const char *fmt, ... )
|
||||
template<typename PutChFunc>
|
||||
int kprintfInternal(PutChFunc putch, char* buffer, const char*& fmt, char*& ap)
|
||||
{
|
||||
const char *p;
|
||||
va_list ap;
|
||||
|
||||
soft_cursor = vga_get_cursor();
|
||||
|
||||
va_start( ap, fmt );
|
||||
int ret = 0;
|
||||
char* bufptr = buffer;
|
||||
|
||||
for( p = fmt; *p; ++p )
|
||||
{
|
||||
if( *p == '%' && *(p + 1) )
|
||||
{
|
||||
for (p = fmt; *p; ++p) {
|
||||
if (*p == '%' && *(p + 1)) {
|
||||
++p;
|
||||
switch( *p )
|
||||
{
|
||||
|
@ -68,105 +63,136 @@ kprintf( const char *fmt, ... )
|
|||
const char* sp = va_arg(ap, const char*);
|
||||
//ASSERT(sp != nullptr);
|
||||
if (!sp) {
|
||||
putch('<');
|
||||
putch('N');
|
||||
putch('u');
|
||||
putch('L');
|
||||
putch('>');
|
||||
putch(bufptr, '<');
|
||||
putch(bufptr, 'N');
|
||||
putch(bufptr, 'u');
|
||||
putch(bufptr, 'L');
|
||||
putch(bufptr, '>');
|
||||
ret += 5;
|
||||
} else {
|
||||
for (; *sp; ++sp)
|
||||
putch(*sp);
|
||||
for (; *sp; ++sp) {
|
||||
putch(bufptr, *sp);
|
||||
++ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
printSignedNumber(va_arg(ap, int));
|
||||
ret += printSignedNumber(putch, bufptr, va_arg(ap, int));
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
print_num( va_arg( ap, DWORD ));
|
||||
ret += printNumber(putch, bufptr, va_arg(ap, DWORD));
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
print_hex( va_arg( ap, DWORD ), 8 );
|
||||
ret += printHex(putch, bufptr, va_arg(ap, DWORD), 8);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
print_hex( va_arg( ap, int ), 2 );
|
||||
ret += printHex(putch, bufptr, va_arg(ap, int), 2);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
putch( (char)va_arg( ap, int ));
|
||||
putch(bufptr, (char)va_arg(ap, int));
|
||||
++ret;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
putch( '0' );
|
||||
putch( 'x' );
|
||||
print_hex( va_arg( ap, DWORD ), 8 );
|
||||
putch(bufptr, '0');
|
||||
putch(bufptr, 'x');
|
||||
ret += 2;
|
||||
ret += printHex(putch, bufptr, va_arg(ap, DWORD), 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
putch( *p );
|
||||
else {
|
||||
putch(bufptr, *p);
|
||||
++ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* va_arg( ap, type ); */
|
||||
va_end( ap );
|
||||
|
||||
vga_set_cursor( soft_cursor );
|
||||
return ret;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
print_hex( DWORD number, BYTE fields )
|
||||
int kprintf(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
soft_cursor = vga_get_cursor();
|
||||
int ret = kprintfInternal(vga_putch, nullptr, fmt, ap);
|
||||
vga_set_cursor(soft_cursor);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void buffer_putch(char* bufptr, char ch)
|
||||
{
|
||||
*bufptr++ = ch;
|
||||
}
|
||||
|
||||
int ksprintf(char* buffer, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = kprintfInternal(buffer_putch, buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename PutChFunc>
|
||||
int printHex(PutChFunc putch, char*& bufptr, DWORD number, BYTE fields)
|
||||
{
|
||||
static const char h[] = {
|
||||
'0','1','2','3','4','5','6','7',
|
||||
'8','9','a','b','c','d','e','f'
|
||||
};
|
||||
|
||||
int ret = 0;
|
||||
BYTE shr_count = fields * 4;
|
||||
while( shr_count )
|
||||
{
|
||||
while (shr_count) {
|
||||
shr_count -= 4;
|
||||
putch( h[(number >> shr_count) & 0x0F] );
|
||||
putch(bufptr, h[(number >> shr_count) & 0x0F]);
|
||||
++ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
print_num( DWORD number )
|
||||
template<typename PutChFunc>
|
||||
int printNumber(PutChFunc putch, char*& bufptr, DWORD number)
|
||||
{
|
||||
DWORD divisor = 1000000000;
|
||||
char ch;
|
||||
char padding = 1;
|
||||
int ret = 0;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
for (;;) {
|
||||
ch = '0' + (number / divisor);
|
||||
number %= divisor;
|
||||
|
||||
if( ch != '0' )
|
||||
if (ch != '0')
|
||||
padding = 0;
|
||||
|
||||
if( !padding || divisor == 1 )
|
||||
putch( ch );
|
||||
if (!padding || divisor == 1) {
|
||||
putch(bufptr, ch);
|
||||
++ret;
|
||||
}
|
||||
|
||||
if( divisor == 1 )
|
||||
if (divisor == 1)
|
||||
break;
|
||||
divisor /= 10;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void printSignedNumber(int number)
|
||||
template<typename PutChFunc>
|
||||
static int printSignedNumber(PutChFunc putch, char*& bufptr, int number)
|
||||
{
|
||||
if (number < 0) {
|
||||
putch('-');
|
||||
print_num(0 - number);
|
||||
} else {
|
||||
print_num(number);
|
||||
putch(bufptr, '-');
|
||||
return printNumber(putch, bufptr, 0 - number) + 1;
|
||||
}
|
||||
return printNumber(putch, bufptr, number);
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
|
|
|
@ -8,4 +8,6 @@ void vga_set_attr(BYTE);
|
|||
void vga_set_cursor(WORD);
|
||||
void vga_set_cursor(BYTE row, BYTE column);
|
||||
WORD vga_get_cursor();
|
||||
void kprintf(const char *fmt, ...);
|
||||
|
||||
int kprintf(const char *fmt, ...);
|
||||
int ksprintf(char* buf, const char *fmt, ...);
|
||||
|
|
26
Kernel/ktime.h
Normal file
26
Kernel/ktime.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
struct tm {
|
||||
int tm_sec; /* Seconds (0-60) */
|
||||
int tm_min; /* Minutes (0-59) */
|
||||
int tm_hour; /* Hours (0-23) */
|
||||
int tm_mday; /* Day of the month (1-31) */
|
||||
int tm_mon; /* Month (0-11) */
|
||||
int tm_year; /* Year - 1900 */
|
||||
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
|
||||
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
|
||||
int tm_isdst; /* Daylight saving time */
|
||||
};
|
||||
|
||||
inline time_t ktime(time_t* tloc)
|
||||
{
|
||||
if (tloc)
|
||||
*tloc = 123;
|
||||
return 123;
|
||||
}
|
||||
|
||||
inline tm* klocaltime(time_t* t)
|
||||
{
|
||||
static tm timmy;
|
||||
return &timmy;
|
||||
}
|
|
@ -948,7 +948,7 @@ InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const S
|
|||
else
|
||||
initialLinksCount = 1;
|
||||
|
||||
auto timestamp = time(nullptr);
|
||||
auto timestamp = ktime(nullptr);
|
||||
auto e2inode = make<ext2_inode>();
|
||||
memset(e2inode.ptr(), 0, sizeof(ext2_inode));
|
||||
e2inode->i_mode = mode;
|
||||
|
|
|
@ -24,7 +24,7 @@ typedef signed_qword off_t;
|
|||
|
||||
typedef dword blksize_t;
|
||||
typedef dword blkcnt_t;
|
||||
typedef long int time_t;
|
||||
typedef unsigned int time_t;
|
||||
typedef dword size_t;
|
||||
typedef signed_dword ssize_t;
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ bool VirtualFileSystem::mount(RetainPtr<FileSystem>&& fileSystem, const String&
|
|||
|
||||
kprintf("mounting %s{%p} at %s (inode: %u)\n", fileSystem->className(), fileSystem.ptr(), path.characters(), inode.index());
|
||||
// FIXME: check that this is not already a mount point
|
||||
auto mount = make<Mount>(inode, std::move(fileSystem));
|
||||
m_mounts.append(std::move(mount));
|
||||
auto mount = make<Mount>(inode, move(fileSystem));
|
||||
m_mounts.append(move(mount));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto mount = make<Mount>(InodeIdentifier(), std::move(fileSystem));
|
||||
auto mount = make<Mount>(InodeIdentifier(), move(fileSystem));
|
||||
|
||||
auto node = makeNode(mount->guest());
|
||||
if (!node->inUse()) {
|
||||
|
@ -105,13 +105,13 @@ bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
|||
return false;
|
||||
}
|
||||
|
||||
m_rootNode = std::move(node);
|
||||
m_rootNode = move(node);
|
||||
|
||||
kprintf("[VFS] mountRoot mounted %s{%p}\n",
|
||||
m_rootNode->fileSystem()->className(),
|
||||
m_rootNode->fileSystem());
|
||||
|
||||
m_mounts.append(std::move(mount));
|
||||
m_mounts.append(move(mount));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ void VirtualFileSystem::freeNode(Node* node)
|
|||
node->inode.fileSystem()->release();
|
||||
node->inode = InodeIdentifier();
|
||||
node->m_characterDevice = nullptr;
|
||||
m_nodeFreeList.append(std::move(node));
|
||||
m_nodeFreeList.append(move(node));
|
||||
}
|
||||
|
||||
bool VirtualFileSystem::isDirectory(const String& path)
|
||||
|
@ -260,14 +260,14 @@ void VirtualFileSystem::listDirectory(const String& path)
|
|||
|
||||
if (metadata.isCharacterDevice() || metadata.isBlockDevice()) {
|
||||
char buf[16];
|
||||
sprintf(buf, "%u, %u", metadata.majorDevice, metadata.minorDevice);
|
||||
ksprintf(buf, "%u, %u", metadata.majorDevice, metadata.minorDevice);
|
||||
kprintf("%12s ", buf);
|
||||
} else {
|
||||
kprintf("%12lld ", metadata.size);
|
||||
}
|
||||
|
||||
kprintf("\033[30;1m");
|
||||
auto tm = *localtime(&metadata.mtime);
|
||||
auto tm = *klocaltime(&metadata.mtime);
|
||||
kprintf("%04u-%02u-%02u %02u:%02u:%02u ",
|
||||
tm.tm_year + 1900,
|
||||
tm.tm_mon + 1,
|
||||
|
@ -306,7 +306,7 @@ void VirtualFileSystem::listDirectoryRecursively(const String& path)
|
|||
if (metadata.isDirectory()) {
|
||||
if (entry.name != "." && entry.name != "..") {
|
||||
char buf[4096];
|
||||
sprintf(buf, "%s/%s", path.characters(), entry.name.characters());
|
||||
ksprintf(buf, "%s/%s", path.characters(), entry.name.characters());
|
||||
listDirectoryRecursively(buf);
|
||||
}
|
||||
} else {
|
||||
|
@ -320,7 +320,7 @@ bool VirtualFileSystem::touch(const String& path)
|
|||
auto inode = resolvePath(path);
|
||||
if (!inode.isValid())
|
||||
return false;
|
||||
return inode.fileSystem()->setModificationTime(inode, time(nullptr));
|
||||
return inode.fileSystem()->setModificationTime(inode, ktime(nullptr));
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> VirtualFileSystem::open(const String& path)
|
||||
|
@ -331,7 +331,7 @@ OwnPtr<FileHandle> VirtualFileSystem::open(const String& path)
|
|||
auto vnode = getOrCreateNode(inode);
|
||||
if (!vnode)
|
||||
return nullptr;
|
||||
return make<FileHandle>(std::move(vnode));
|
||||
return make<FileHandle>(move(vnode));
|
||||
}
|
||||
|
||||
OwnPtr<FileHandle> VirtualFileSystem::create(const String& path)
|
||||
|
@ -354,7 +354,7 @@ InodeIdentifier VirtualFileSystem::resolveSymbolicLink(const String& basePath, I
|
|||
if (!symlinkContents)
|
||||
return { };
|
||||
char buf[4096];
|
||||
sprintf(buf, "/%s/%s", basePath.characters(), String((const char*)symlinkContents.pointer(), symlinkContents.size()).characters());
|
||||
ksprintf(buf, "/%s/%s", basePath.characters(), String((const char*)symlinkContents.pointer(), symlinkContents.size()).characters());
|
||||
return resolvePath(buf);
|
||||
}
|
||||
|
||||
|
@ -407,7 +407,7 @@ InodeIdentifier VirtualFileSystem::resolvePath(const String& path)
|
|||
char buf[4096] = "";
|
||||
char* p = buf;
|
||||
for (unsigned j = 0; j < i; ++j) {
|
||||
p += sprintf(p, "/%s", parts[j].characters());
|
||||
p += ksprintf(p, "/%s", parts[j].characters());
|
||||
}
|
||||
inode = resolveSymbolicLink(buf, inode);
|
||||
if (!inode.isValid()) {
|
||||
|
@ -436,7 +436,7 @@ void VirtualFileSystem::Node::release()
|
|||
VirtualFileSystem::Mount::Mount(InodeIdentifier host, RetainPtr<FileSystem>&& guestFileSystem)
|
||||
: m_host(host)
|
||||
, m_guest(guestFileSystem->rootInode())
|
||||
, m_fileSystem(std::move(guestFileSystem))
|
||||
, m_fileSystem(move(guestFileSystem))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue