From d150c551439c657bb1ac0523811a2a294295ba99 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 11 Jan 2023 18:42:50 +0100 Subject: [PATCH] TarStream: Support mode --- kernel/src/main.cpp | 4 ++-- libc/include/bits/fixed-size-types.h | 23 +++++++++++++++++++++++ libc/include/sys/types.h | 6 ++++-- luna/include/luna/CString.h | 1 + luna/include/luna/TarStream.h | 2 ++ luna/src/TarStream.cpp | 2 ++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 libc/include/bits/fixed-size-types.h diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 273963ff..9f5e7d3f 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -59,8 +59,8 @@ Result init() { if (entry.type == TarStream::EntryType::RegularFile) { - kinfoln("Found file %s in initial ramdisk, of size %s", entry.name, - to_dynamic_unit(entry.size).release_value().chars()); + kinfoln("Found file %s in initial ramdisk, of size %s and mode %#ho", entry.name, + to_dynamic_unit(entry.size).release_value().chars(), entry.mode); if (!strcmp(entry.name, "bin/app")) { TRY(Scheduler::new_userspace_thread(entry, g_initrd)); } } diff --git a/libc/include/bits/fixed-size-types.h b/libc/include/bits/fixed-size-types.h new file mode 100644 index 00000000..2003b0e9 --- /dev/null +++ b/libc/include/bits/fixed-size-types.h @@ -0,0 +1,23 @@ +/* bits/fixed-size-types.h: Fixed size types for internal use. Do not use in applications, include . */ + +#ifndef _BITS_FIXED_SIZE_TYPES_H +#define _BITS_FIXED_SIZE_TYPES_H + +#ifndef _SYS_TYPES_H +#error "Never include bits/fixed-size-types.h, use the standard header instead." +#endif + +#if defined(__GNUC__) +typedef __INT8_TYPE__ __i8_t; +typedef __UINT8_TYPE__ __u8_t; +typedef __INT16_TYPE__ __i16_t; +typedef __UINT16_TYPE__ __u16_t; +typedef __INT32_TYPE__ __i32_t; +typedef __UINT32_TYPE__ __u32_t; +typedef __INT64_TYPE__ __i64_t; +typedef __UINT64_TYPE__ __u64_t; +#else +#error "Unsupported compiler" +#endif + +#endif diff --git a/libc/include/sys/types.h b/libc/include/sys/types.h index 0f224f41..cf368ed9 100644 --- a/libc/include/sys/types.h +++ b/libc/include/sys/types.h @@ -6,8 +6,10 @@ #define __need_size_t #include -typedef int pid_t; +#include -typedef long time_t; +typedef int pid_t; +typedef __i64_t time_t; +typedef __u16_t mode_t; #endif diff --git a/luna/include/luna/CString.h b/luna/include/luna/CString.h index b4ac3029..68bc930f 100644 --- a/luna/include/luna/CString.h +++ b/luna/include/luna/CString.h @@ -15,6 +15,7 @@ extern "C" char* strdup(const char* str); // Copies len bytes from src into dest and adds a null terminator. + // FIXME: Replace this invented function with strlcpy(). void nullcpy(char* dest, const char* src, usize len); [[deprecated]] char* strcpy(char* dst, const char* src); diff --git a/luna/include/luna/TarStream.h b/luna/include/luna/TarStream.h index bbed03ab..7ee5a909 100644 --- a/luna/include/luna/TarStream.h +++ b/luna/include/luna/TarStream.h @@ -2,6 +2,7 @@ #include #include #include +#include class TarStream { @@ -16,6 +17,7 @@ class TarStream { char name[257]; usize size; + mode_t mode; EntryType type; private: diff --git a/luna/src/TarStream.cpp b/luna/src/TarStream.cpp index 1bb0a2e2..f4fcae66 100644 --- a/luna/src/TarStream.cpp +++ b/luna/src/TarStream.cpp @@ -43,6 +43,8 @@ Result TarStream::parse_header(const TarStream::TarHeader* hdr nullcpy(size, hdr->size, 12); entry.size = parse_unsigned_integer(size, nullptr, 8); + entry.mode = (mode_t)parse_unsigned_integer(hdr->mode, nullptr, 8); + entry.pos = m_offset; switch (hdr->typeflag)