mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Add SpinLock to IDE disk access.
This forces serialization of accesses. This driver needs to be redesigned.
This commit is contained in:
parent
dec5683e9c
commit
8f6998c902
Notes:
sideshowbarker
2024-07-19 18:35:39 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8f6998c902c
7 changed files with 57 additions and 13 deletions
|
@ -73,8 +73,11 @@ void interrupt()
|
|||
interrupted = true;
|
||||
}
|
||||
|
||||
static SpinLock* s_diskLock;
|
||||
|
||||
void initialize()
|
||||
{
|
||||
s_diskLock = new SpinLock;
|
||||
disableIRQ();
|
||||
interrupted = false;
|
||||
registerInterruptHandler(IRQ_VECTOR_BASE + IRQ_FIXED_DISK, ide_ISR);
|
||||
|
@ -135,6 +138,7 @@ static CHS lba2chs(BYTE drive_index, DWORD lba)
|
|||
|
||||
bool readSectors(DWORD startSector, WORD count, BYTE* outbuf)
|
||||
{
|
||||
LOCKER(*s_diskLock);
|
||||
#ifdef DISK_DEBUG
|
||||
kprintf("%s: Disk::readSectors request (%u sector(s) @ %u)\n",
|
||||
current->name().characters(),
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "assert.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func)
|
||||
{
|
||||
printf("ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func);
|
||||
fprintf(stderr, "ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
|
10
LibC/pwd.cpp
10
LibC/pwd.cpp
|
@ -5,6 +5,8 @@
|
|||
#include <sys/mman.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
struct passwd_with_strings : public passwd {
|
||||
char name_buffer[256];
|
||||
char passwd_buffer[256];
|
||||
|
@ -24,6 +26,10 @@ void setpwent()
|
|||
rewind(__pwdb_stream);
|
||||
} else {
|
||||
__pwdb_stream = fopen("/etc/passwd", "r");
|
||||
if (!__pwdb_stream) {
|
||||
perror("open /etc/passwd");
|
||||
}
|
||||
assert(__pwdb_stream);
|
||||
__pwdb_entry = (struct passwd_with_strings*)mmap(nullptr, getpagesize());
|
||||
set_mmap_name(__pwdb_entry, getpagesize(), "setpwent");
|
||||
}
|
||||
|
@ -67,6 +73,7 @@ struct passwd* getpwent()
|
|||
if (!__pwdb_stream)
|
||||
setpwent();
|
||||
|
||||
assert(__pwdb_stream);
|
||||
if (feof(__pwdb_stream))
|
||||
return nullptr;
|
||||
|
||||
|
@ -76,6 +83,7 @@ next_entry:
|
|||
char* s = fgets(buffer, sizeof(buffer), __pwdb_stream);
|
||||
if (!s)
|
||||
return nullptr;
|
||||
assert(__pwdb_stream);
|
||||
if (feof(__pwdb_stream))
|
||||
return nullptr;
|
||||
String line(s);
|
||||
|
@ -116,3 +124,5 @@ next_entry:
|
|||
strncpy(__pwdb_entry->shell_buffer, e_shell.characters(), e_shell.length());
|
||||
return __pwdb_entry;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,16 +13,19 @@ extern "C" {
|
|||
|
||||
int fileno(FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
return stream->fd;
|
||||
}
|
||||
|
||||
int feof(FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
return stream->eof;
|
||||
}
|
||||
|
||||
char* fgets(char* buffer, int size, FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
ssize_t nread = 0;
|
||||
for (;;) {
|
||||
if (nread >= size)
|
||||
|
@ -41,6 +44,7 @@ char* fgets(char* buffer, int size, FILE* stream)
|
|||
|
||||
int fgetc(FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
char ch;
|
||||
fread(&ch, sizeof(char), 1, stream);
|
||||
return ch;
|
||||
|
@ -58,6 +62,7 @@ int getchar()
|
|||
|
||||
int fputc(int ch, FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
write(stream->fd, &ch, 1);
|
||||
return (byte)ch;
|
||||
}
|
||||
|
@ -74,11 +79,13 @@ int putchar(int ch)
|
|||
|
||||
void clearerr(FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
stream->eof = false;
|
||||
}
|
||||
|
||||
size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
ssize_t nread = read(stream->fd, ptr, nmemb * size);
|
||||
if (nread < 0)
|
||||
return 0;
|
||||
|
@ -89,6 +96,7 @@ size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream)
|
|||
|
||||
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
ssize_t nwritten = write(stream->fd, ptr, nmemb * size);
|
||||
if (nwritten < 0)
|
||||
return 0;
|
||||
|
@ -97,6 +105,7 @@ size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream)
|
|||
|
||||
int fseek(FILE* stream, long offset, int whence)
|
||||
{
|
||||
assert(stream);
|
||||
off_t off = lseek(stream->fd, offset, whence);
|
||||
if (off < 0)
|
||||
return off;
|
||||
|
@ -105,6 +114,7 @@ int fseek(FILE* stream, long offset, int whence)
|
|||
|
||||
long ftell(FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
return lseek(stream->fd, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
#include <LibC/string.h>
|
||||
#include <LibC/stdlib.h>
|
||||
#include <LibC/utsname.h>
|
||||
#include <LibC/pwd.h>
|
||||
#include <AK/FileSystemPath.h>
|
||||
|
||||
struct GlobalState {
|
||||
String cwd;
|
||||
String username;
|
||||
char ttyname[32];
|
||||
char hostname[32];
|
||||
};
|
||||
|
@ -19,7 +21,7 @@ static void prompt()
|
|||
if (getuid() == 0)
|
||||
printf("# ");
|
||||
else
|
||||
printf("\033[31;1m%s\033[0m:\033[37;1m%s\033[0m:\033[32;1m%s\033[0m$> ", g->ttyname, g->hostname, g->cwd.characters());
|
||||
printf("\033[31;1m%s\033[0m@\033[37;1m%s\033[0m:\033[32;1m%s\033[0m$> ", g->username.characters(), g->hostname, g->cwd.characters());
|
||||
}
|
||||
|
||||
static int sh_pwd(int, const char**)
|
||||
|
@ -170,6 +172,12 @@ int main(int, char**)
|
|||
rc = ttyname_r(0, g->ttyname, sizeof(g->ttyname));
|
||||
if (rc < 0)
|
||||
perror("ttyname_r");
|
||||
{
|
||||
auto* pw = getpwuid(getuid());
|
||||
if (pw)
|
||||
g->username = pw->pw_name;
|
||||
endpwent();
|
||||
}
|
||||
|
||||
greeting();
|
||||
|
||||
|
|
|
@ -129,6 +129,9 @@ bool Ext2FileSystem::initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
// Preheat the BGD cache.
|
||||
blockGroupDescriptor(0);
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
for (unsigned i = 1; i <= m_blockGroupCount; ++i) {
|
||||
auto& group = blockGroupDescriptor(i);
|
||||
|
|
|
@ -59,6 +59,8 @@ auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node>
|
|||
if (!metadata.isValid())
|
||||
return nullptr;
|
||||
|
||||
InterruptDisabler disabler;
|
||||
|
||||
CharacterDevice* characterDevice = nullptr;
|
||||
if (metadata.isCharacterDevice()) {
|
||||
auto it = m_characterDevices.find(encodedDevice(metadata.majorDevice, metadata.minorDevice));
|
||||
|
@ -91,6 +93,7 @@ auto VirtualFileSystem::makeNode(InodeIdentifier inode) -> RetainPtr<Node>
|
|||
|
||||
auto VirtualFileSystem::makeNode(CharacterDevice& device) -> RetainPtr<Node>
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto vnode = allocateNode();
|
||||
ASSERT(vnode);
|
||||
|
||||
|
@ -106,17 +109,23 @@ auto VirtualFileSystem::makeNode(CharacterDevice& device) -> RetainPtr<Node>
|
|||
|
||||
auto VirtualFileSystem::getOrCreateNode(InodeIdentifier inode) -> RetainPtr<Node>
|
||||
{
|
||||
auto it = m_inode2vnode.find(inode);
|
||||
if (it != m_inode2vnode.end())
|
||||
return (*it).value;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto it = m_inode2vnode.find(inode);
|
||||
if (it != m_inode2vnode.end())
|
||||
return (*it).value;
|
||||
}
|
||||
return makeNode(inode);
|
||||
}
|
||||
|
||||
auto VirtualFileSystem::getOrCreateNode(CharacterDevice& device) -> RetainPtr<Node>
|
||||
{
|
||||
auto it = m_device2vnode.find(encodedDevice(device.major(), device.minor()));
|
||||
if (it != m_device2vnode.end())
|
||||
return (*it).value;
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto it = m_device2vnode.find(encodedDevice(device.major(), device.minor()));
|
||||
if (it != m_device2vnode.end())
|
||||
return (*it).value;
|
||||
}
|
||||
return makeNode(device);
|
||||
}
|
||||
|
||||
|
@ -152,7 +161,7 @@ bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
|||
return false;
|
||||
}
|
||||
if (!node->inode.metadata().isDirectory()) {
|
||||
kprintf("VFS: root inode for / is not in use :(\n");
|
||||
kprintf("VFS: root inode for / is not a directory :(\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -168,7 +177,6 @@ bool VirtualFileSystem::mountRoot(RetainPtr<FileSystem>&& fileSystem)
|
|||
|
||||
auto VirtualFileSystem::allocateNode() -> RetainPtr<Node>
|
||||
{
|
||||
|
||||
if (m_nodeFreeList.isEmpty()) {
|
||||
kprintf("VFS: allocateNode has no nodes left\n");
|
||||
return nullptr;
|
||||
|
@ -182,6 +190,7 @@ auto VirtualFileSystem::allocateNode() -> RetainPtr<Node>
|
|||
|
||||
void VirtualFileSystem::freeNode(Node* node)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ASSERT(node);
|
||||
ASSERT(node->inUse());
|
||||
if (node->inode.isValid()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue