Skip to content

Commit

Permalink
Add mkdir implementation for UEFI.
Browse files Browse the repository at this point in the history
  • Loading branch information
stikonas committed Nov 26, 2022
1 parent 453ba69 commit 25fe274
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
26 changes: 12 additions & 14 deletions amd64/uefi/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,35 @@
#define S_IRUSR 00400
#define S_IRWXU 00700

void free(void* l);

int __open(struct efi_file_protocol* _rootdir, char* name, long mode, long attributes)
{
struct efi_file_protocol* new_handle;
unsigned rval = __uefi_5(_rootdir, &new_handle, name, mode, attributes, _rootdir->open);
if(rval != NULL)
char* wide_name = _posix_path_to_uefi(name);
unsigned rval = __uefi_5(_rootdir, &new_handle, wide_name, mode, attributes, _rootdir->open);
free(wide_name);
if(rval != EFI_SUCCESS)
{
return -1;
return -1;
}
return new_handle;
}

void free(void* l);

int _open(char* name, int flag, int mode)
{
int fd;

char* wide_filename = _posix_path_to_uefi(name);
long mode = 0;
long attributes = 0;
if(flag == O_WRONLY|O_CREAT|O_TRUNC)
{
long mode = 1 << 63; /* EFI_FILE_MODE_CREATE = 0x8000000000000000 */
mode = mode | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ;
fd = __open(_rootdir, wide_filename, mode, 0);
mode = EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ;
}
else
{ /* Everything else is a read */
fd = __open(_rootdir, wide_filename, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);
mode = EFI_FILE_MODE_READ;
attributes = EFI_FILE_READ_ONLY;
}
free(wide_filename);
return fd;
return __open(_rootdir, name, mode, attributes);
}

#define STDIN_FILENO 0
Expand Down
19 changes: 11 additions & 8 deletions amd64/uefi/sys/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef _SYS_STAT_C
#define _SYS_STAT_C

#include <amd64/uefi/uefi.c>
#include <sys/types.h>

#define S_IRWXU 00700
Expand Down Expand Up @@ -48,15 +49,17 @@ int fchmod(int a, mode_t b)
return 0;
}


int mkdir(char const* a, mode_t b)
int mkdir(char const* name, mode_t _mode)
{
asm("lea_rdi,[rsp+DWORD] %16"
"mov_rdi,[rdi]"
"lea_rsi,[rsp+DWORD] %8"
"mov_rsi,[rsi]"
"mov_rax, %83"
"syscall");
struct efi_file_protocol* new_directory;
long mode = EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ;
long attributes = EFI_FILE_DIRECTORY;
long new_directory = __open(_rootdir, name, mode, attributes);
if(new_directory != -1)
{
_close(new_directory);
}
return new_directory;
}


Expand Down
4 changes: 3 additions & 1 deletion amd64/uefi/uefi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 1
#define EFI_FILE_MODE_READ 1
#define EFI_FILE_MODE_WRITE 2
#define EFI_FILE_MODE_CREATE (1 << 63)
#define EFI_FILE_READ_ONLY 1
#define EFI_FILE_DIRECTORY 0x10
#define EFI_ALLOCATE_ANY_PAGES 0
#define EFI_LOADER_DATA 2

Expand Down Expand Up @@ -406,7 +408,7 @@ void* calloc(int count, int size);
void _posix_path_to_uefi(char *narrow_string)
{
unsigned length = strlen(narrow_string) + 1;
char *wide_string = calloc(length, 2);
char *wide_string = calloc(length, 4);
unsigned i;
for(i = 0; i < length; i += 1)
{
Expand Down

0 comments on commit 25fe274

Please sign in to comment.