mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:27:46 +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
7 changed files with 57 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue