diff options
| author | Bobby <[email protected]> | 2026-07-28 06:35:39 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-07-28 06:35:39 +0530 |
| commit | 6003b9a719d36804f93c47e29db1cd3a15601ed6 (patch) | |
| tree | d64fa2fa1df804961a65cadc6c12a837f921d22d /shared | |
| parent | b6bf52bef0ccef82113c1641be7e5b18297b5f4b (diff) | |
| download | akiba-main.tar.xz akiba-main.zip | |
Extract utils module (bits/math/text/crc/format/address/path) and fix kernel entry stack misalignmentHEADmain
Diffstat (limited to 'shared')
| -rw-r--r-- | shared/afs/read/location.zig | 64 | ||||
| -rw-r--r-- | shared/afs/read/read.zig | 1 | ||||
| -rw-r--r-- | shared/afs/write/allocate.zig | 21 | ||||
| -rw-r--r-- | shared/afs/write/unit.zig | 4 | ||||
| -rw-r--r-- | shared/fat32/read/stack.zig | 60 | ||||
| -rw-r--r-- | shared/fat32/write/boot.zig | 4 | ||||
| -rw-r--r-- | shared/fat32/write/entry.zig | 6 |
7 files changed, 20 insertions, 140 deletions
diff --git a/shared/afs/read/location.zig b/shared/afs/read/location.zig deleted file mode 100644 index 3553f1f..0000000 --- a/shared/afs/read/location.zig +++ /dev/null @@ -1,64 +0,0 @@ -//! AFS Location Operations - -const types = @import("shared").afs.types; - -const StackRecord = types.catalog.StackRecord; -const UnitRecord = types.catalog.UnitRecord; - -pub const LookupResult = union(enum) { - Unit: UnitRecord, - Stack: StackRecord, - NotFound: void, -}; - -pub fn componentToIdentity(component: []const u8, identity_buffer: []u16) usize { - var length: usize = 0; - for (component) |byte| { - if (length >= identity_buffer.len) break; - identity_buffer[length] = byte; - length += 1; - } - return length; -} - -pub const LocationIterator = struct { - Location: []const u8, - Position: usize, - - pub fn init(location: []const u8) LocationIterator { - var start: usize = 0; - if (location.len > 0 and (location[0] == '/' or location[0] == '\\')) { - start = 1; - } - return LocationIterator{ - .Location = location, - .Position = start, - }; - } - - pub fn next(self: *LocationIterator) ?[]const u8 { - while (self.Position < self.Location.len and - (self.Location[self.Position] == '/' or self.Location[self.Position] == '\\')) - { - self.Position += 1; - } - - if (self.Position >= self.Location.len) { - return null; - } - - const start = self.Position; - while (self.Position < self.Location.len and - self.Location[self.Position] != '/' and - self.Location[self.Position] != '\\') - { - self.Position += 1; - } - - if (self.Position == start) { - return null; - } - - return self.Location[start..self.Position]; - } -}; diff --git a/shared/afs/read/read.zig b/shared/afs/read/read.zig index fc119ec..1410ea0 100644 --- a/shared/afs/read/read.zig +++ b/shared/afs/read/read.zig @@ -1,4 +1,3 @@ //! AFS Read Operations -pub const location = @import("location.zig"); pub const unit = @import("unit.zig"); diff --git a/shared/afs/write/allocate.zig b/shared/afs/write/allocate.zig index e521d2a..5bfc316 100644 --- a/shared/afs/write/allocate.zig +++ b/shared/afs/write/allocate.zig @@ -2,6 +2,8 @@ const errors = @import("shared").afs.errors; +const bits = @import("utils").bits; + const AllocationError = errors.allocate.AllocationError; pub const AllocationMap = struct { @@ -19,23 +21,17 @@ pub const AllocationMap = struct { pub fn markAllocated(self: *AllocationMap, cell: u32) void { if (cell >= self.TotalCells) return; - const byte_index = cell / @bitSizeOf(u8); - const bit_index: u3 = @intCast(cell % @bitSizeOf(u8)); - self.Bitmap[byte_index] |= @as(u8, 1) << bit_index; + bits.operations.setBit(self.Bitmap, cell); } pub fn markFree(self: *AllocationMap, cell: u32) void { if (cell >= self.TotalCells) return; - const byte_index = cell / @bitSizeOf(u8); - const bit_index: u3 = @intCast(cell % @bitSizeOf(u8)); - self.Bitmap[byte_index] &= ~(@as(u8, 1) << bit_index); + bits.operations.clearBit(self.Bitmap, cell); } pub fn isAllocated(self: *const AllocationMap, cell: u32) bool { if (cell >= self.TotalCells) return true; - const byte_index = cell / @bitSizeOf(u8); - const bit_index: u3 = @intCast(cell % @bitSizeOf(u8)); - return (self.Bitmap[byte_index] & (@as(u8, 1) << bit_index)) != 0; + return bits.operations.testBit(self.Bitmap, cell); } pub fn allocateCells(self: *AllocationMap, count: u32) AllocationError!u32 { @@ -46,10 +42,7 @@ pub const AllocationMap = struct { return AllocationError.OutOfSpace; } - var index: u32 = 0; - while (index < count) : (index += 1) { - self.markAllocated(start + index); - } + self.reserveRange(start, count); self.NextFree = start + count; return start; @@ -75,5 +68,5 @@ pub const AllocationMap = struct { }; pub fn bitmapSize(total_cells: u32) u32 { - return (total_cells + @bitSizeOf(u8) - 1) / @bitSizeOf(u8); + return @intCast(bits.operations.bitmapBytes(total_cells)); } diff --git a/shared/afs/write/unit.zig b/shared/afs/write/unit.zig index b476c9f..c912306 100644 --- a/shared/afs/write/unit.zig +++ b/shared/afs/write/unit.zig @@ -5,6 +5,8 @@ const errors = @import("shared").afs.errors; const io = @import("shared").afs.io; const types = @import("shared").afs.types; +const math = @import("utils").math; + const BlockWriter = io.block.BlockWriter; const ChannelInfo = types.volume.ChannelInfo; const SpanDescriptor = types.volume.SpanDescriptor; @@ -48,7 +50,7 @@ pub fn writeSpan( pub fn cellsNeeded(size: u64, cell_size: u32) u32 { if (size == 0) return 0; - return @intCast((size + cell_size - 1) / cell_size); + return @intCast(math.integer.divideCeil(size, cell_size)); } pub fn createChannelInfo( diff --git a/shared/fat32/read/stack.zig b/shared/fat32/read/stack.zig index 93993ab..19c224b 100644 --- a/shared/fat32/read/stack.zig +++ b/shared/fat32/read/stack.zig @@ -3,66 +3,12 @@ const constants = @import("shared").fat32.constants; const types = @import("shared").fat32.types; -const StackEntry = types.entry.StackEntry; - -pub fn identitiesEqual(left: []const u8, right: []const u8) bool { - if (left.len != right.len) { - return false; - } - for (left, right) |left_char, right_char| { - const upper_left = if (left_char >= 'a' and left_char <= 'z') left_char - ('a' - 'A') else left_char; - const upper_right = if (right_char >= 'a' and right_char <= 'z') right_char - ('a' - 'A') else right_char; - if (upper_left != upper_right) { - return false; - } - } - return true; -} - -pub const LocationIterator = struct { - Location: []const u8, - Position: usize, - - pub fn init(location: []const u8) LocationIterator { - var start: usize = 0; - if (location.len > 0 and (location[0] == '/' or location[0] == '\\')) { - start = 1; - } - return LocationIterator{ - .Location = location, - .Position = start, - }; - } +const text = @import("utils").text; - pub fn next(self: *LocationIterator) ?[]const u8 { - while (self.Position < self.Location.len and - (self.Location[self.Position] == '/' or self.Location[self.Position] == '\\')) - { - self.Position += 1; - } - - if (self.Position >= self.Location.len) { - return null; - } - - const start = self.Position; - while (self.Position < self.Location.len and - self.Location[self.Position] != '/' and - self.Location[self.Position] != '\\') - { - self.Position += 1; - } - - if (self.Position == start) { - return null; - } - - return self.Location[start..self.Position]; - } -}; +const StackEntry = types.entry.StackEntry; pub fn entryMatchesIdentity(entry: *const StackEntry, identity: []const u8) bool { var short_identity_buffer: [constants.sizes.SHORT_DISPLAY_LENGTH]u8 = undefined; const short_identity_length = entry.getShortIdentity(&short_identity_buffer); - return identitiesEqual(short_identity_buffer[0..short_identity_length], identity); + return text.ascii.equalsIgnoreCase(short_identity_buffer[0..short_identity_length], identity); } diff --git a/shared/fat32/write/boot.zig b/shared/fat32/write/boot.zig index 56b229b..6ef7050 100644 --- a/shared/fat32/write/boot.zig +++ b/shared/fat32/write/boot.zig @@ -5,6 +5,8 @@ const std = @import("std"); const constants = @import("shared").fat32.constants; const types = @import("shared").fat32.types; +const math = @import("utils").math; + const BootSector = types.boot.BootSector; const FsInfo = types.boot.FsInfo; @@ -23,7 +25,7 @@ pub fn calculateFatSize(params: CreateParams) u32 { const data_sectors = params.TotalSectors - params.ReservedSectors; const cluster_count = data_sectors / params.SectorsPerCluster; const fat_bytes = (cluster_count + constants.clusters.CLUSTER_DATA_START) * @sizeOf(u32); - return (fat_bytes + params.BytesPerSector - 1) / params.BytesPerSector; + return math.integer.divideCeil(fat_bytes, params.BytesPerSector); } pub fn createBootSector(params: CreateParams) BootSector { diff --git a/shared/fat32/write/entry.zig b/shared/fat32/write/entry.zig index 1535ddd..c64ce80 100644 --- a/shared/fat32/write/entry.zig +++ b/shared/fat32/write/entry.zig @@ -3,6 +3,8 @@ const constants = @import("shared").fat32.constants; const types = @import("shared").fat32.types; +const text = @import("utils").text; + const StackEntry = types.entry.StackEntry; pub fn createEntry( @@ -30,12 +32,12 @@ pub fn createEntry( for (identity, 0..) |char, index| { if (index >= constants.sizes.SHORT_IDENTITY_LENGTH) break; - entry.Identity[index] = toUpper(char); + entry.Identity[index] = text.ascii.toUpper(char); } for (extension, 0..) |char, index| { if (index >= constants.sizes.SHORT_EXT_LENGTH) break; - entry.Extension[index] = toUpper(char); + entry.Extension[index] = text.ascii.toUpper(char); } return entry; |
