Skip to content

Commit

Permalink
Add resource.zig and improve lib/ubik.zig
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratakor committed Oct 29, 2023
1 parent 70154a3 commit 88ef8e1
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 36 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ Make sure to have `zig master`, `xorriso` and `qemu-system-x86` then run
% git clone https://github.com/ratakor/ubik --recursive
% zig build run -Doptimize=ReleaseFast
```

# File structure
This shouldn't be in readme.

1. imports
2. type definitions
3. constants
4. variables
5. init function
6. pub functions
7. other functions
6 changes: 3 additions & 3 deletions kernel/arch/x86_64/x86_64.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = @import("std").debug.assert;

pub const Rflags = packed struct {
pub const RFlags = packed struct {
CF: u1 = 0,
reserved: u1 = 1,
PF: u1 = 0,
Expand All @@ -25,8 +25,8 @@ pub const Rflags = packed struct {
reserved4: u42 = 0,

comptime {
assert(@sizeOf(Rflags) == @sizeOf(u64));
assert(@bitSizeOf(Rflags) == @bitSizeOf(u64));
assert(@sizeOf(RFlags) == @sizeOf(u64));
assert(@bitSizeOf(RFlags) == @bitSizeOf(u64));
}
};

Expand Down
1 change: 0 additions & 1 deletion kernel/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ const source_files = [_][]const u8{
"serial.zig",
"smp.zig",
"SpinLock.zig",
"STANDARD.F16",
"time.zig",
"TTY.zig",
"vfs.zig",
Expand Down
6 changes: 3 additions & 3 deletions kernel/event.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub const Listener = struct {
};

pub const Event = struct {
lock: SpinLock,
pending: usize,
listeners_i: usize,
lock: SpinLock = .{},
pending: usize = 0,
listeners_i: usize = 0,
listeners: [max_listeners]Listener,
};

Expand Down
16 changes: 8 additions & 8 deletions kernel/fs/tmpfs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ const File = struct {
return buf.len;
}

fn stat(vnode: *vfs.VNode, buf: *vfs.Stat) vfs.StatError!void {
fn stat(vnode: *vfs.VNode, buf: *std.os.Stat) vfs.StatError!void {
const self = @fieldParentPtr(File, "vnode", vnode);

buf.* = std.mem.zeroes(vfs.Stat);
buf.* = std.mem.zeroes(std.os.Stat);
buf.ino = vnode.inode;
buf.mode = 0o777 | std.os.linux.S.IFREG; // TODO
buf.mode = 0o777 | std.os.S.IFREG; // TODO
buf.size = @intCast(self.data.items.len);
buf.blksize = page_size;
buf.blocks = @intCast(std.mem.alignForward(usize, self.data.items.len, page_size) / page_size);
Expand Down Expand Up @@ -82,12 +82,12 @@ const Dir = struct {
fn read(vnode: *vfs.VNode, buf: []u8, offset: *usize) vfs.ReadDirError!usize {
const self = @fieldParentPtr(Dir, "vnode", vnode);

var dir_ent: *vfs.DirectoryEntry = @ptrCast(@alignCast(buf.ptr));
var dir_ent: *std.os.system.DirectoryEntry = @ptrCast(@alignCast(buf.ptr));
var buf_offset: usize = 0;

while (offset.* < self.children.items.len) : (offset.* += 1) {
const child = self.children.items[offset.*];
const real_size = child.name.len + 1 - (1024 - @sizeOf(vfs.DirectoryEntry));
const real_size = child.name.len + 1 - (1024 - @sizeOf(std.os.system.DirectoryEntry));

if (buf_offset + real_size > buf.len) break;

Expand All @@ -114,10 +114,10 @@ const Dir = struct {
try self.children.append(root.allocator, new_child);
}

fn stat(vnode: *vfs.VNode, buf: *vfs.Stat) vfs.StatError!void {
buf.* = std.mem.zeroes(vfs.Stat);
fn stat(vnode: *vfs.VNode, buf: *std.os.Stat) vfs.StatError!void {
buf.* = std.mem.zeroes(std.os.Stat);
buf.ino = vnode.inode;
buf.mode = 0o777 | std.os.linux.S.IFDIR; // TODO
buf.mode = 0o777 | std.os.S.IFDIR; // TODO
}
};

Expand Down
Loading

0 comments on commit 88ef8e1

Please sign in to comment.