mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:37:36 +00:00
Finally hook up the mkdir code to a syscall.
Added a /bin/mkdir that makes directories. How very neat :^) There are various limitations because of missing functionality.
This commit is contained in:
parent
303577df16
commit
de4604ac95
26 changed files with 238 additions and 132 deletions
|
@ -18,6 +18,7 @@
|
|||
enum IDECommand : byte {
|
||||
IDENTIFY_DRIVE = 0xEC,
|
||||
READ_SECTORS = 0x21,
|
||||
WRITE_SECTORS = 0x30,
|
||||
};
|
||||
|
||||
enum IDEStatus : byte {
|
||||
|
@ -64,11 +65,8 @@ bool IDEDiskDevice::readBlock(unsigned index, byte* out) const
|
|||
|
||||
bool IDEDiskDevice::writeBlock(unsigned index, const byte* data)
|
||||
{
|
||||
(void) index;
|
||||
(void) data;
|
||||
kprintf("IDEDiskDevice: writeBlock not implemented()\n");
|
||||
notImplemented();
|
||||
return false;
|
||||
write_sectors(index, 1, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef DISK_DEBUG
|
||||
|
@ -221,3 +219,48 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* data)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
dbgprintf("%s(%u): IDEDiskDevice::write_sectors request (%u sector(s) @ %u)\n",
|
||||
current->name().characters(),
|
||||
current->pid(),
|
||||
count,
|
||||
start_sector);
|
||||
disableIRQ();
|
||||
|
||||
auto chs = lba_to_chs(start_sector);
|
||||
|
||||
while (IO::in8(IDE0_STATUS) & BUSY);
|
||||
|
||||
//dbgprintf("IDEDiskDevice: Writing %u sector(s) @ LBA %u (%u/%u/%u)\n", count, start_sector, chs.cylinder, chs.head, chs.sector);
|
||||
|
||||
IO::out8(0x1F2, count == 256 ? 0 : LSB(count));
|
||||
IO::out8(0x1F3, chs.sector);
|
||||
IO::out8(0x1F4, LSB(chs.cylinder));
|
||||
IO::out8(0x1F5, MSB(chs.cylinder));
|
||||
|
||||
IO::out8(0x1F6, 0xA0 | chs.head); /* 0xB0 for 2nd device */
|
||||
|
||||
IO::out8(0x3F6, 0x08);
|
||||
|
||||
IO::out8(IDE0_COMMAND, WRITE_SECTORS);
|
||||
|
||||
while (!(IO::in8(IDE0_STATUS) & DRQ));
|
||||
|
||||
byte status = IO::in8(0x1f7);
|
||||
if (status & DRQ) {
|
||||
//dbgprintf("Sending %u bytes (status=%b), data=%p...\n", count * 512, status, data);
|
||||
auto* data_as_words = (const word*)data;
|
||||
for (dword i = 0; i < (count * 512) / 2; ++i) {
|
||||
IO::out16(IDE0_DATA, data_as_words[i]);
|
||||
}
|
||||
}
|
||||
|
||||
m_interrupted = false;
|
||||
enableIRQ();
|
||||
wait_for_irq();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ private:
|
|||
|
||||
void initialize();
|
||||
bool wait_for_irq();
|
||||
bool read_sectors(dword start_sector, word count, byte* outbuf);
|
||||
bool read_sectors(dword start_sector, word count, byte* buffer);
|
||||
bool write_sectors(dword start_sector, word count, const byte* data);
|
||||
|
||||
SpinLock m_lock;
|
||||
word m_cylinders { 0 };
|
||||
|
|
|
@ -44,7 +44,8 @@ ELFLOADER_OBJS = \
|
|||
AK_OBJS = \
|
||||
../AK/String.o \
|
||||
../AK/StringImpl.o \
|
||||
../AK/StringBuilder.o
|
||||
../AK/StringBuilder.o \
|
||||
../AK/FileSystemPath.o
|
||||
|
||||
OBJS = $(KERNEL_OBJS) $(VFS_OBJS) $(AK_OBJS) $(ELFLOADER_OBJS)
|
||||
|
||||
|
|
|
@ -1751,3 +1751,15 @@ int Process::sys$setgroups(size_t count, const gid_t* gids)
|
|||
m_gids.set(gids[i]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Process::sys$mkdir(const char* pathname, mode_t mode)
|
||||
{
|
||||
if (!validate_read_str(pathname))
|
||||
return -EFAULT;
|
||||
if (strlen(pathname) >= 255)
|
||||
return -ENAMETOOLONG;
|
||||
int error;
|
||||
if (!VFS::the().mkdir(pathname, mode, cwd_inode()->identifier(), error))
|
||||
return error;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -172,6 +172,7 @@ public:
|
|||
int sys$access(const char* pathname, int mode);
|
||||
int sys$fcntl(int fd, int cmd, dword extra_arg);
|
||||
int sys$ioctl(int fd, unsigned request, unsigned arg);
|
||||
int sys$mkdir(const char* pathname, mode_t mode);
|
||||
|
||||
static void initialize();
|
||||
|
||||
|
|
|
@ -175,6 +175,8 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
|
|||
return current->sys$ioctl((int)arg1, (unsigned)arg2, (unsigned)arg3);
|
||||
case Syscall::SC_fstat:
|
||||
return current->sys$fstat((int)arg1, (Unix::stat*)arg2);
|
||||
case Syscall::SC_mkdir:
|
||||
return current->sys$mkdir((const char*)arg1, (mode_t)arg2);
|
||||
default:
|
||||
kprintf("<%u> int0x80: Unknown function %u requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
|
||||
break;
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
__ENUMERATE_SYSCALL(access) \
|
||||
__ENUMERATE_SYSCALL(fcntl) \
|
||||
__ENUMERATE_SYSCALL(ioctl) \
|
||||
__ENUMERATE_SYSCALL(mkdir) \
|
||||
|
||||
|
||||
#define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function))
|
||||
|
|
|
@ -29,6 +29,7 @@ cp -v ../Userland/mm mnt/bin/mm
|
|||
cp -v ../Userland/kill mnt/bin/kill
|
||||
cp -v ../Userland/tty mnt/bin/tty
|
||||
cp -v ../Userland/strsignal mnt/bin/strsignal
|
||||
cp -v ../Userland/mkdir mnt/bin/mkdir
|
||||
sh sync-local.sh
|
||||
cp -v kernel.map mnt/
|
||||
umount mnt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue