diff options
Diffstat (limited to 'shared/fs')
27 files changed, 11 insertions, 144 deletions
diff --git a/shared/fs/afs/afs.zig b/shared/fs/afs/afs.zig index 42990ee..9c494af 100644 --- a/shared/fs/afs/afs.zig +++ b/shared/fs/afs/afs.zig @@ -7,7 +7,6 @@ pub const btree = @import("btree/btree.zig"); pub const read = @import("read/read.zig"); pub const write = @import("write/write.zig"); -// Re-export commonly used types pub const VolumeHeader = types.VolumeHeader; pub const SpanDescriptor = types.SpanDescriptor; pub const ChannelInfo = types.ChannelInfo; @@ -19,13 +18,11 @@ pub const BTreeHeaderRecord = types.BTreeHeaderRecord; pub const IndexKey = types.IndexKey; pub const Permissions = types.Permissions; -// Re-export I/O interfaces pub const BlockReader = io.BlockReader; pub const BlockWriter = io.BlockWriter; pub const BlockDevice = io.BlockDevice; pub const BlockError = io.BlockError; -// Re-export errors pub const BTreeError = btree.BTreeError; pub const ReadError = read.ReadError; pub const WriteError = write.WriteError; diff --git a/shared/fs/afs/btree/btree.zig b/shared/fs/afs/btree/btree.zig index ba72f99..cac9e36 100644 --- a/shared/fs/afs/btree/btree.zig +++ b/shared/fs/afs/btree/btree.zig @@ -3,7 +3,6 @@ pub const node = @import("node.zig"); pub const search = @import("search.zig"); -// Node operations pub const get_node_cell = node.get_node_cell; pub const get_node_offset_in_cell = node.get_node_offset_in_cell; pub const get_record_offset = node.get_record_offset; @@ -11,7 +10,6 @@ pub const get_record_ptr = node.get_record_ptr; pub const get_record_ptr_const = node.get_record_ptr_const; pub const NodeError = node.NodeError; -// Search operations pub const compare_keys = search.compare_keys; pub const search_index_node = search.search_index_node; pub const search_leaf_for_unit = search.search_leaf_for_unit; diff --git a/shared/fs/afs/btree/node.zig b/shared/fs/afs/btree/node.zig index d2ccc73..5fe161f 100644 --- a/shared/fs/afs/btree/node.zig +++ b/shared/fs/afs/btree/node.zig @@ -13,32 +13,27 @@ pub const NodeError = error{ OutOfBounds, }; -/// Calculate the cell containing a node pub fn get_node_cell(node_number: u32, cell_size: u32, node_size: u32) u64 { const nodes_per_cell = cell_size / node_size; return node_number / nodes_per_cell; } -/// Calculate offset of a node within a cell pub fn get_node_offset_in_cell(node_number: u32, cell_size: u32, node_size: u32) u32 { const nodes_per_cell = cell_size / node_size; return (node_number % nodes_per_cell) * node_size; } -/// Get record offset from the offset table at the end of the node pub fn get_record_offset(node_buffer: [*]const u8, node_size: u32, record_index: u16) u16 { const offset_table_start = node_size - (@as(u32, record_index) + 1) * 2; const offset_ptr: *align(1) const u16 = @ptrCast(node_buffer + offset_table_start); return offset_ptr.*; } -/// Get pointer to a record in the node buffer pub fn get_record_ptr(node_buffer: [*]u8, node_size: u32, record_index: u16) [*]u8 { const offset = get_record_offset(node_buffer, node_size, record_index); return node_buffer + offset; } -/// Get const pointer to a record in the node buffer pub fn get_record_ptr_const(node_buffer: [*]const u8, node_size: u32, record_index: u16) [*]const u8 { const offset = get_record_offset(node_buffer, node_size, record_index); return node_buffer + offset; diff --git a/shared/fs/afs/btree/search.zig b/shared/fs/afs/btree/search.zig index 85f7c4b..93614d1 100644 --- a/shared/fs/afs/btree/search.zig +++ b/shared/fs/afs/btree/search.zig @@ -10,8 +10,6 @@ const StackRecord = types.StackRecord; const UnitRecord = types.UnitRecord; const ThreadRecord = types.ThreadRecord; -/// Compare search key against a B-tree key -/// Returns: -1 if search < key, 0 if equal, 1 if search > key pub fn compare_keys(parent_node_id: u32, identity: []const u16, key: *align(1) const IndexKey) i32 { if (parent_node_id < key.parent_node_id) { return -1; @@ -45,7 +43,6 @@ pub fn compare_keys(parent_node_id: u32, identity: []const u16, key: *align(1) c return 0; } -/// Search an index node for the child pointer to follow pub fn search_index_node( node_buffer: [*]const u8, node_size: u32, @@ -65,7 +62,6 @@ pub fn search_index_node( } } - // Return last child pointer if search key is greater than all keys if (record_count > 0) { const last_record = node_ops.get_record_ptr_const(node_buffer, node_size, record_count - 1); const last_key: *align(1) const IndexKey = @ptrCast(last_record); @@ -76,7 +72,6 @@ pub fn search_index_node( return null; } -/// Search a leaf node for a unit record pub fn search_leaf_for_unit( node_buffer: [*]const u8, node_size: u32, @@ -104,7 +99,6 @@ pub fn search_leaf_for_unit( return null; } -/// Search a leaf node for a stack record pub fn search_leaf_for_stack( node_buffer: [*]const u8, node_size: u32, @@ -132,7 +126,6 @@ pub fn search_leaf_for_stack( return null; } -/// Search a leaf node for a thread record pub fn search_leaf_for_thread( node_buffer: [*]const u8, node_size: u32, diff --git a/shared/fs/afs/constants/constants.zig b/shared/fs/afs/constants/constants.zig index 2478a86..6be89a4 100644 --- a/shared/fs/afs/constants/constants.zig +++ b/shared/fs/afs/constants/constants.zig @@ -7,7 +7,6 @@ pub const records = @import("records.zig"); pub const btree = @import("btree.zig"); pub const flags = @import("flags.zig"); -// Re-export commonly used constants pub const signature = magic.signature; pub const version = magic.version; pub const journal_signature = magic.journal_signature; diff --git a/shared/fs/afs/constants/flags.zig b/shared/fs/afs/constants/flags.zig index 3ac1143..32daaa9 100644 --- a/shared/fs/afs/constants/flags.zig +++ b/shared/fs/afs/constants/flags.zig @@ -1,6 +1,5 @@ //! AFS Flags -// Unit flags pub const unit_locked: u16 = 0x0001; pub const unit_has_thread: u16 = 0x0002; pub const unit_has_alias: u16 = 0x0004; @@ -8,21 +7,17 @@ pub const unit_has_security: u16 = 0x0008; pub const unit_has_twins: u16 = 0x0010; pub const unit_has_resource_channel: u16 = 0x0020; -// Channel types pub const channel_data: u8 = 0x00; pub const channel_resource: u8 = 0xFF; -// Compression types pub const compression_none: u32 = 0; pub const compression_zlib: u32 = 1; pub const compression_lz4: u32 = 2; pub const compression_zstd: u32 = 3; -// Encryption types pub const encryption_none: u32 = 0; pub const encryption_aes_128_xts: u32 = 1; pub const encryption_aes_256_xts: u32 = 2; -// Journal flags pub const journal_on_other_device: u32 = 0x00000001; pub const journal_needs_init: u32 = 0x00000002; diff --git a/shared/fs/afs/constants/magic.zig b/shared/fs/afs/constants/magic.zig index 84f46db..f268615 100644 --- a/shared/fs/afs/constants/magic.zig +++ b/shared/fs/afs/constants/magic.zig @@ -1,15 +1,11 @@ //! AFS Magic Numbers and Signatures -/// "AKIBAFS!" signature pub const signature: u64 = 0x2153464142494B41; -/// AFS version pub const version: u16 = 0x0001; -/// "JNRL" journal signature pub const journal_signature: u32 = 0x4A4E524C; -/// AFS partition type GUID: 414B4942-4146-5300-0000-000000000001 pub const partition_type_guid = [16]u8{ 0x42, 0x49, 0x4B, 0x41, 0x46, 0x41, 0x00, 0x53, diff --git a/shared/fs/afs/io/block.zig b/shared/fs/afs/io/block.zig index 8abd71c..8475562 100644 --- a/shared/fs/afs/io/block.zig +++ b/shared/fs/afs/io/block.zig @@ -9,7 +9,6 @@ pub const BlockError = error{ NotSupported, }; -/// Block reader interface - implemented by each consumer pub const BlockReader = struct { context: *anyopaque, read_fn: *const fn (context: *anyopaque, cell: u64, buffer: []u8) BlockError!void, @@ -40,7 +39,6 @@ pub const BlockReader = struct { } }; -/// Block writer interface - implemented by each consumer pub const BlockWriter = struct { context: *anyopaque, write_fn: *const fn (context: *anyopaque, cell: u64, data: []const u8) BlockError!void, @@ -71,7 +69,6 @@ pub const BlockWriter = struct { } }; -/// Combined reader/writer for read-write operations pub const BlockDevice = struct { reader: BlockReader, writer: BlockWriter, diff --git a/shared/fs/afs/read/location.zig b/shared/fs/afs/read/location.zig index ef145fc..f76b9d4 100644 --- a/shared/fs/afs/read/location.zig +++ b/shared/fs/afs/read/location.zig @@ -13,14 +13,12 @@ pub const LocationError = error{ BTreeError, }; -/// Result of looking up a location pub const LookupResult = union(enum) { unit: UnitRecord, stack: StackRecord, not_found: void, }; -/// Convert ASCII location component to UTF-16 identity pub fn component_to_identity(component: []const u8, identity_buffer: []u16) usize { var len: usize = 0; for (component) |byte| { @@ -31,14 +29,12 @@ pub fn component_to_identity(component: []const u8, identity_buffer: []u16) usiz return len; } -/// Iterator for location components pub const LocationIterator = struct { location: []const u8, position: usize, pub fn init(location: []const u8) LocationIterator { var start: usize = 0; - // Skip leading separator if (location.len > 0 and (location[0] == '/' or location[0] == '\\')) { start = 1; } @@ -49,7 +45,6 @@ pub const LocationIterator = struct { } pub fn next(self: *LocationIterator) ?[]const u8 { - // Skip empty components while (self.position < self.location.len and (self.location[self.position] == '/' or self.location[self.position] == '\\')) { diff --git a/shared/fs/afs/read/read.zig b/shared/fs/afs/read/read.zig index 7b232db..6adb4be 100644 --- a/shared/fs/afs/read/read.zig +++ b/shared/fs/afs/read/read.zig @@ -3,13 +3,11 @@ pub const unit = @import("unit.zig"); pub const location = @import("location.zig"); -// Unit operations pub const read_span = unit.read_span; pub const read_unit_inline_spans = unit.read_unit_inline_spans; pub const read_unit = unit.read_unit; pub const ReadError = unit.ReadError; -// Location operations pub const component_to_identity = location.component_to_identity; pub const LocationIterator = location.LocationIterator; pub const LocationError = location.LocationError; diff --git a/shared/fs/afs/read/unit.zig b/shared/fs/afs/read/unit.zig index cecd5f7..46a7b82 100644 --- a/shared/fs/afs/read/unit.zig +++ b/shared/fs/afs/read/unit.zig @@ -17,7 +17,6 @@ pub const ReadError = error{ BufferTooSmall, }; -/// Read data from a span into a buffer pub fn read_span( reader: *const BlockReader, span: *const SpanDescriptor, @@ -50,7 +49,6 @@ pub fn read_span( return bytes_read; } -/// Read unit data using inline spans pub fn read_unit_inline_spans( reader: *const BlockReader, channel: *const ChannelInfo, @@ -86,7 +84,6 @@ pub fn read_unit_inline_spans( return bytes_read; } -/// Read entire unit data (inline spans only, no overflow support yet) pub fn read_unit( reader: *const BlockReader, unit: *const UnitRecord, diff --git a/shared/fs/afs/types/types.zig b/shared/fs/afs/types/types.zig index 151435e..21d5ad6 100644 --- a/shared/fs/afs/types/types.zig +++ b/shared/fs/afs/types/types.zig @@ -8,17 +8,14 @@ pub const attributes = @import("attributes.zig"); pub const journal = @import("journal.zig"); pub const timestamp = @import("timestamp.zig"); -// Volume types pub const VolumeHeader = volume.VolumeHeader; pub const SpanDescriptor = volume.SpanDescriptor; pub const ChannelInfo = volume.ChannelInfo; -// B-tree types pub const BTreeNodeDescriptor = btree.NodeDescriptor; pub const BTreeHeaderRecord = btree.HeaderRecord; pub const IndexKey = btree.IndexKey; -// Catalog types pub const StackRecord = catalog.StackRecord; pub const UnitRecord = catalog.UnitRecord; pub const ThreadRecord = catalog.ThreadRecord; @@ -28,20 +25,16 @@ pub const SpecialInfo = catalog.SpecialInfo; pub const AliasInfo = catalog.AliasInfo; pub const TwinInfo = catalog.TwinInfo; -// Extent types pub const SpanKey = extents.SpanKey; pub const SpanRecord = extents.SpanRecord; -// Attribute types pub const AttributeKey = attributes.AttributeKey; pub const AttributeInlineRecord = attributes.AttributeInlineRecord; pub const AttributeChannelRecord = attributes.AttributeChannelRecord; -// Journal types pub const JournalInfoCell = journal.JournalInfoCell; pub const JournalHeader = journal.JournalHeader; pub const JournalCellList = journal.JournalCellList; pub const JournalCellInfo = journal.JournalCellInfo; -// Timestamp pub const Timestamp = timestamp.Timestamp; diff --git a/shared/fs/afs/write/allocate.zig b/shared/fs/afs/write/allocate.zig index 2377f4f..9573a88 100644 --- a/shared/fs/afs/write/allocate.zig +++ b/shared/fs/afs/write/allocate.zig @@ -5,7 +5,6 @@ pub const AllocationError = error{ InvalidCell, }; -/// Allocation bitmap operations pub const AllocationMap = struct { bitmap: []u8, total_cells: u32, @@ -19,7 +18,6 @@ pub const AllocationMap = struct { }; } - /// Mark a cell as allocated pub fn mark_allocated(self: *AllocationMap, cell: u32) void { if (cell >= self.total_cells) return; const byte_index = cell / 8; @@ -27,7 +25,6 @@ pub const AllocationMap = struct { self.bitmap[byte_index] |= @as(u8, 1) << bit_index; } - /// Mark a cell as free pub fn mark_free(self: *AllocationMap, cell: u32) void { if (cell >= self.total_cells) return; const byte_index = cell / 8; @@ -35,7 +32,6 @@ pub const AllocationMap = struct { self.bitmap[byte_index] &= ~(@as(u8, 1) << bit_index); } - /// Check if a cell is allocated pub fn is_allocated(self: *const AllocationMap, cell: u32) bool { if (cell >= self.total_cells) return true; const byte_index = cell / 8; @@ -43,7 +39,6 @@ pub const AllocationMap = struct { return (self.bitmap[byte_index] & (@as(u8, 1) << bit_index)) != 0; } - /// Allocate a contiguous range of cells pub fn allocate_cells(self: *AllocationMap, count: u32) AllocationError!u32 { if (count == 0) return self.next_free; @@ -61,7 +56,6 @@ pub const AllocationMap = struct { return start; } - /// Mark a range of cells as allocated (for reserved areas) pub fn reserve_range(self: *AllocationMap, start: u32, count: u32) void { var i: u32 = 0; while (i < count) : (i += 1) { @@ -69,7 +63,6 @@ pub const AllocationMap = struct { } } - /// Get count of free cells pub fn free_count(self: *const AllocationMap) u32 { var count: u32 = 0; var i: u32 = 0; @@ -82,7 +75,6 @@ pub const AllocationMap = struct { } }; -/// Calculate bitmap size needed for a given number of cells pub fn bitmap_size(total_cells: u32) u32 { return (total_cells + 7) / 8; } diff --git a/shared/fs/afs/write/stack.zig b/shared/fs/afs/write/stack.zig index 69afd53..0507bae 100644 --- a/shared/fs/afs/write/stack.zig +++ b/shared/fs/afs/write/stack.zig @@ -10,7 +10,6 @@ const IndexKey = types.IndexKey; const Permissions = types.Permissions; const ChannelInfo = types.ChannelInfo; -/// Create a stack record pub fn create_stack_record( node_id: u32, timestamp: u64, @@ -40,7 +39,6 @@ pub fn create_stack_record( }; } -/// Create a unit record pub fn create_unit_record( node_id: u32, timestamp: u64, @@ -73,7 +71,6 @@ pub fn create_unit_record( }; } -/// Create an index key for a catalog entry pub fn create_index_key( parent_node_id: u32, identity: []const u8, @@ -91,7 +88,6 @@ pub fn create_index_key( return key; } -/// Get the size of an index key in bytes pub fn index_key_size(identity_len: usize) usize { return 8 + identity_len * 2; } diff --git a/shared/fs/afs/write/unit.zig b/shared/fs/afs/write/unit.zig index a20da4e..0162219 100644 --- a/shared/fs/afs/write/unit.zig +++ b/shared/fs/afs/write/unit.zig @@ -15,7 +15,6 @@ pub const WriteError = error{ InvalidCell, }; -/// Write data to a span pub fn write_span( writer: *const BlockWriter, span: *const SpanDescriptor, @@ -29,7 +28,6 @@ pub fn write_span( var current_cell = span.start_cell; while (bytes_written < bytes_to_write) { - // Clear cell buffer for (cell_buffer) |*b| { b.* = 0; } @@ -37,7 +35,6 @@ pub fn write_span( const bytes_remaining = bytes_to_write - bytes_written; const bytes_to_copy = if (bytes_remaining < writer.cell_size) bytes_remaining else writer.cell_size; - // Copy data to cell buffer var i: u64 = 0; while (i < bytes_to_copy) : (i += 1) { cell_buffer[@intCast(i)] = data[@intCast(bytes_written + i)]; @@ -54,13 +51,11 @@ pub fn write_span( return bytes_written; } -/// Calculate number of cells needed for a given size pub fn cells_needed(size: u64, cell_size: u32) u32 { if (size == 0) return 0; return @intCast((size + cell_size - 1) / cell_size); } -/// Create a channel info for inline data pub fn create_channel_info( logical_size: u64, start_cell: u64, diff --git a/shared/fs/afs/write/write.zig b/shared/fs/afs/write/write.zig index b33ed3b..c4c1727 100644 --- a/shared/fs/afs/write/write.zig +++ b/shared/fs/afs/write/write.zig @@ -4,18 +4,15 @@ pub const unit = @import("unit.zig"); pub const allocate = @import("allocate.zig"); pub const stack = @import("stack.zig"); -// Unit operations pub const write_span = unit.write_span; pub const cells_needed = unit.cells_needed; pub const create_channel_info = unit.create_channel_info; pub const WriteError = unit.WriteError; -// Allocation operations pub const AllocationMap = allocate.AllocationMap; pub const AllocationError = allocate.AllocationError; pub const bitmap_size = allocate.bitmap_size; -// Stack operations pub const create_stack_record = stack.create_stack_record; pub const create_unit_record = stack.create_unit_record; pub const create_index_key = stack.create_index_key; diff --git a/shared/fs/fat32/constants/constants.zig b/shared/fs/fat32/constants/constants.zig index 2034699..80b8d08 100644 --- a/shared/fs/fat32/constants/constants.zig +++ b/shared/fs/fat32/constants/constants.zig @@ -1,63 +1,52 @@ //! FAT32 Constants -/// Boot sector signature pub const boot_signature: u16 = 0xAA55; -/// FAT32 filesystem type string pub const fs_type_fat32: [8]u8 = .{ 'F', 'A', 'T', '3', '2', ' ', ' ', ' ' }; -// Entry attributes pub const attr_read_only: u8 = 0x01; pub const attr_hidden: u8 = 0x02; pub const attr_system: u8 = 0x04; pub const attr_volume_id: u8 = 0x08; -pub const attr_stack: u8 = 0x10; // FAT32 calls this "directory" +pub const attr_stack: u8 = 0x10; pub const attr_archive: u8 = 0x20; pub const attr_long_identity: u8 = attr_read_only | attr_hidden | attr_system | attr_volume_id; pub const attr_long_identity_mask: u8 = attr_read_only | attr_hidden | attr_system | attr_volume_id | attr_stack | attr_archive; -// FAT32 spec aliases pub const attr_directory = attr_stack; pub const attr_long_name = attr_long_identity; pub const attr_long_name_mask = attr_long_identity_mask; -// Entry markers pub const entry_free: u8 = 0xE5; pub const entry_end: u8 = 0x00; pub const entry_kanji_lead: u8 = 0x05; -// Cluster values pub const cluster_free: u32 = 0x00000000; pub const cluster_reserved_start: u32 = 0x00000001; pub const cluster_reserved_end: u32 = 0x00000001; pub const cluster_data_start: u32 = 0x00000002; pub const cluster_bad: u32 = 0x0FFFFFF7; -pub const cluster_eoc_start: u32 = 0x0FFFFFF8; // End of chain start -pub const cluster_eoc: u32 = 0x0FFFFFFF; // End of chain marker +pub const cluster_eoc_start: u32 = 0x0FFFFFF8; +pub const cluster_eoc: u32 = 0x0FFFFFFF; pub const cluster_mask: u32 = 0x0FFFFFFF; -// Long identity constants pub const lfn_sequence_mask: u8 = 0x1F; pub const lfn_last_entry: u8 = 0x40; pub const lfn_chars_per_entry: usize = 13; -// Short identity lengths pub const short_identity_length: usize = 8; pub const short_ext_length: usize = 3; pub const short_total_length: usize = short_identity_length + short_ext_length; -// Sector sizes pub const sector_size_min: u16 = 512; pub const sector_size_max: u16 = 4096; -// FSInfo signatures pub const fsinfo_sig1: u32 = 0x41615252; pub const fsinfo_sig2: u32 = 0x61417272; pub const fsinfo_sig3: u32 = 0xAA550000; pub const fsinfo_unknown: u32 = 0xFFFFFFFF; -// Default values for creation pub const default_oem_name: [8]u8 = .{ 'M', 'S', 'W', 'I', 'N', '4', '.', '1' }; -pub const default_media_type: u8 = 0xF8; // Fixed disk +pub const default_media_type: u8 = 0xF8; pub const default_drive_number: u8 = 0x80; pub const default_boot_sig: u8 = 0x29; diff --git a/shared/fs/fat32/fat32.zig b/shared/fs/fat32/fat32.zig index 3e3cfdc..48454d4 100644 --- a/shared/fs/fat32/fat32.zig +++ b/shared/fs/fat32/fat32.zig @@ -5,7 +5,6 @@ pub const types = @import("types/types.zig"); pub const read = @import("read/read.zig"); pub const write = @import("write/write.zig"); -// Re-export commonly used types (Akiba terminology) pub const BootSector = types.BootSector; pub const FsInfo = types.FsInfo; pub const StackEntry = types.StackEntry; @@ -13,10 +12,8 @@ pub const LongIdentityEntry = types.LongIdentityEntry; pub const TimeFormat = types.TimeFormat; pub const DateFormat = types.DateFormat; -// FAT32 spec aliases (for compatibility) pub const DirEntry = types.DirEntry; pub const LongNameEntry = types.LongNameEntry; -// Re-export errors pub const ClusterError = read.ClusterError; pub const LocationError = read.LocationError; diff --git a/shared/fs/fat32/read/cluster.zig b/shared/fs/fat32/read/cluster.zig index 7b4161d..3ad196a 100644 --- a/shared/fs/fat32/read/cluster.zig +++ b/shared/fs/fat32/read/cluster.zig @@ -11,19 +11,16 @@ pub const ClusterError = error{ ReadFailed, }; -/// Check if cluster number is valid data cluster pub fn is_valid_cluster(cluster: u32) bool { return cluster >= constants.cluster_data_start and cluster < constants.cluster_eoc_start and cluster != constants.cluster_bad; } -/// Check if cluster marks end of chain pub fn is_end_of_chain(cluster: u32) bool { return (cluster & constants.cluster_mask) >= constants.cluster_eoc_start; } -/// Calculate FAT sector and offset for a cluster pub fn get_fat_position(cluster: u32, bytes_per_sector: u32) struct { sector: u32, offset: u32 } { const fat_offset = cluster * 4; return .{ @@ -32,7 +29,6 @@ pub fn get_fat_position(cluster: u32, bytes_per_sector: u32) struct { sector: u3 }; } -/// Calculate LBA for a cluster's data pub fn cluster_to_lba( cluster: u32, data_start_lba: u64, @@ -41,7 +37,6 @@ pub fn cluster_to_lba( return data_start_lba + (@as(u64, cluster - 2) * sectors_per_cluster); } -/// Read next cluster from FAT entry pub fn parse_fat_entry(entry: u32) ClusterError!?u32 { const next = entry & constants.cluster_mask; diff --git a/shared/fs/fat32/read/read.zig b/shared/fs/fat32/read/read.zig index 7fca337..2bd7411 100644 --- a/shared/fs/fat32/read/read.zig +++ b/shared/fs/fat32/read/read.zig @@ -3,7 +3,6 @@ pub const cluster = @import("cluster.zig"); pub const stack = @import("stack.zig"); -// Cluster operations pub const ClusterError = cluster.ClusterError; pub const is_valid_cluster = cluster.is_valid_cluster; pub const is_end_of_chain = cluster.is_end_of_chain; @@ -11,7 +10,6 @@ pub const get_fat_position = cluster.get_fat_position; pub const cluster_to_lba = cluster.cluster_to_lba; pub const parse_fat_entry = cluster.parse_fat_entry; -// Stack operations pub const LocationError = stack.LocationError; pub const identities_equal = stack.identities_equal; pub const LocationIterator = stack.LocationIterator; diff --git a/shared/fs/fat32/read/stack.zig b/shared/fs/fat32/read/stack.zig index ded95eb..8df3ba4 100644 --- a/shared/fs/fat32/read/stack.zig +++ b/shared/fs/fat32/read/stack.zig @@ -10,7 +10,6 @@ pub const LocationError = error{ InvalidLocation, }; -/// Case-insensitive comparison for identities pub fn identities_equal(a: []const u8, b: []const u8) bool { if (a.len != b.len) { return false; @@ -25,14 +24,12 @@ pub fn identities_equal(a: []const u8, b: []const u8) bool { return true; } -/// Location component iterator pub const LocationIterator = struct { location: []const u8, position: usize, pub fn init(location: []const u8) LocationIterator { var start: usize = 0; - // Skip leading separator if (location.len > 0 and (location[0] == '/' or location[0] == '\\')) { start = 1; } @@ -43,7 +40,6 @@ pub const LocationIterator = struct { } pub fn next(self: *LocationIterator) ?[]const u8 { - // Skip empty components while (self.position < self.location.len and (self.location[self.position] == '/' or self.location[self.position] == '\\')) { @@ -70,7 +66,6 @@ pub const LocationIterator = struct { } }; -/// Check if entry matches an identity (case-insensitive) pub fn entry_matches_identity(entry: *const StackEntry, identity: []const u8) bool { var short_identity_buf: [12]u8 = undefined; const short_identity_len = entry.get_short_identity(&short_identity_buf); diff --git a/shared/fs/fat32/types/boot.zig b/shared/fs/fat32/types/boot.zig index 2735404..68fc786 100644 --- a/shared/fs/fat32/types/boot.zig +++ b/shared/fs/fat32/types/boot.zig @@ -9,15 +9,14 @@ pub const BootSector = extern struct { sectors_per_cluster: u8, reserved_sectors: u16 align(1), fat_count: u8, - root_entry_count: u16 align(1), // Must be 0 for FAT32 - total_sectors_16: u16 align(1), // Must be 0 for FAT32 + root_entry_count: u16 align(1), + total_sectors_16: u16 align(1), media_type: u8, - fat_size_16: u16 align(1), // Must be 0 for FAT32 + fat_size_16: u16 align(1), sectors_per_track: u16 align(1), head_count: u16 align(1), hidden_sectors: u32 align(1), total_sectors_32: u32 align(1), - // FAT32 extended BPB fat_size_32: u32 align(1), ext_flags: u16 align(1), fs_version: u16 align(1), diff --git a/shared/fs/fat32/types/entry.zig b/shared/fs/fat32/types/entry.zig index a2668ff..daa949a 100644 --- a/shared/fs/fat32/types/entry.zig +++ b/shared/fs/fat32/types/entry.zig @@ -2,7 +2,6 @@ const constants = @import("../constants/constants.zig"); -/// Standard 32-byte entry - Stack or Unit pub const StackEntry = extern struct { identity: [8]u8, extension: [3]u8, @@ -47,7 +46,6 @@ pub const StackEntry = extern struct { self.first_cluster_low = @intCast(cluster & 0xFFFF); } - /// Extract short identity (8.3 format) into buffer, returns length pub fn get_short_identity(self: *const StackEntry, buffer: *[12]u8) usize { var length: usize = 0; @@ -56,7 +54,6 @@ pub const StackEntry = extern struct { first_byte = constants.entry_free; } - // Copy identity part (up to 8 chars, stop at space) var i: usize = 0; while (i < 8 and self.identity[i] != ' ') : (i += 1) { if (i == 0) { @@ -67,7 +64,6 @@ pub const StackEntry = extern struct { length += 1; } - // Add extension if present if (self.extension[0] != ' ') { buffer[length] = '.'; length += 1; @@ -83,16 +79,15 @@ pub const StackEntry = extern struct { } }; -/// Long identity entry (LFN) pub const LongIdentityEntry = extern struct { sequence: u8, - identity_1: [10]u8, // 5 UTF-16 characters + identity_1: [10]u8, attributes: u8, entry_type: u8, checksum: u8, - identity_2: [12]u8, // 6 UTF-16 characters - first_cluster: u16 align(1), // Always 0 - identity_3: [4]u8, // 2 UTF-16 characters + identity_2: [12]u8, + first_cluster: u16 align(1), + identity_3: [4]u8, pub fn is_last(self: *const LongIdentityEntry) bool { return (self.sequence & constants.lfn_last_entry) != 0; @@ -102,25 +97,21 @@ pub const LongIdentityEntry = extern struct { return self.sequence & constants.lfn_sequence_mask; } - /// Extract 13 UTF-16 characters from this entry pub fn extract_chars(self: *const LongIdentityEntry, buffer: *[13]u16) void { var index: usize = 0; - // Extract from identity_1 (5 chars) var i: usize = 0; while (i < 10) : (i += 2) { buffer[index] = @as(u16, self.identity_1[i]) | (@as(u16, self.identity_1[i + 1]) << 8); index += 1; } - // Extract from identity_2 (6 chars) i = 0; while (i < 12) : (i += 2) { buffer[index] = @as(u16, self.identity_2[i]) | (@as(u16, self.identity_2[i + 1]) << 8); index += 1; } - // Extract from identity_3 (2 chars) i = 0; while (i < 4) : (i += 2) { buffer[index] = @as(u16, self.identity_3[i]) | (@as(u16, self.identity_3[i + 1]) << 8); @@ -129,20 +120,17 @@ pub const LongIdentityEntry = extern struct { } }; -/// Time format (packed into 16 bits) pub const TimeFormat = packed struct(u16) { second_div_2: u5, minute: u6, hour: u5, }; -/// Date format (packed into 16 bits) pub const DateFormat = packed struct(u16) { day: u5, month: u4, year_from_1980: u7, }; -// FAT32 spec aliases (for external compatibility) pub const DirEntry = StackEntry; pub const LongNameEntry = LongIdentityEntry; diff --git a/shared/fs/fat32/types/types.zig b/shared/fs/fat32/types/types.zig index 7be282e..5799b3c 100644 --- a/shared/fs/fat32/types/types.zig +++ b/shared/fs/fat32/types/types.zig @@ -3,16 +3,13 @@ pub const boot = @import("boot.zig"); pub const entry = @import("entry.zig"); -// Boot sector types pub const BootSector = boot.BootSector; pub const FsInfo = boot.FsInfo; -// Entry types (Akiba terminology) pub const StackEntry = entry.StackEntry; pub const LongIdentityEntry = entry.LongIdentityEntry; pub const TimeFormat = entry.TimeFormat; pub const DateFormat = entry.DateFormat; -// FAT32 spec aliases pub const DirEntry = entry.DirEntry; pub const LongNameEntry = entry.LongNameEntry; diff --git a/shared/fs/fat32/write/boot.zig b/shared/fs/fat32/write/boot.zig index b7bc459..3f64c2e 100644 --- a/shared/fs/fat32/write/boot.zig +++ b/shared/fs/fat32/write/boot.zig @@ -7,7 +7,6 @@ const types = @import("../types/types.zig"); const BootSector = types.BootSector; const FsInfo = types.FsInfo; -/// Parameters for creating a FAT32 filesystem pub const CreateParams = struct { total_sectors: u32, hidden_sectors: u32 = 0, @@ -19,16 +18,13 @@ pub const CreateParams = struct { volume_label: [11]u8 = .{ 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ' }, }; -/// Calculate FAT size in sectors pub fn calculate_fat_size(params: CreateParams) u32 { const data_sectors = params.total_sectors - params.reserved_sectors; const cluster_count = data_sectors / params.sectors_per_cluster; - // Each FAT entry is 4 bytes const fat_bytes = (cluster_count + 2) * 4; return (fat_bytes + params.bytes_per_sector - 1) / params.bytes_per_sector; } -/// Create a boot sector structure pub fn create_boot_sector(params: CreateParams) BootSector { const fat_size = calculate_fat_size(params); @@ -67,7 +63,6 @@ pub fn create_boot_sector(params: CreateParams) BootSector { return boot; } -/// Create FSInfo structure pub fn create_fsinfo(free_clusters: u32, next_free: u32) FsInfo { return FsInfo{ .signature_1 = constants.fsinfo_sig1, @@ -80,20 +75,14 @@ pub fn create_fsinfo(free_clusters: u32, next_free: u32) FsInfo { }; } -/// Initialize FAT table with required entries pub fn init_fat_table(fat: []u8) void { - // Clear @memset(fat, 0); - // Entry 0: Media type std.mem.writeInt(u32, fat[0..4], 0x0FFFFFF8, .little); - // Entry 1: End of chain marker std.mem.writeInt(u32, fat[4..8], 0x0FFFFFFF, .little); - // Entry 2: Origin stack EOC std.mem.writeInt(u32, fat[8..12], 0x0FFFFFFF, .little); } -/// Allocate a cluster in the FAT pub fn allocate_cluster(fat: []u8, cluster: u32) void { const offset = cluster * 4; if (offset + 4 <= fat.len) { @@ -101,7 +90,6 @@ pub fn allocate_cluster(fat: []u8, cluster: u32) void { } } -/// Link two clusters in the FAT pub fn link_clusters(fat: []u8, from: u32, to: u32) void { const offset = from * 4; if (offset + 4 <= fat.len) { diff --git a/shared/fs/fat32/write/entry.zig b/shared/fs/fat32/write/entry.zig index 31f672e..3a26823 100644 --- a/shared/fs/fat32/write/entry.zig +++ b/shared/fs/fat32/write/entry.zig @@ -6,7 +6,6 @@ const types = @import("../types/types.zig"); const StackEntry = types.StackEntry; -/// Create a short (8.3) entry pub fn create_entry( identity: []const u8, extension: []const u8, @@ -30,13 +29,11 @@ pub fn create_entry( .unit_size = unit_size, }; - // Copy identity (uppercase) for (identity, 0..) |c, i| { if (i >= 8) break; entry.identity[i] = to_upper(c); } - // Copy extension (uppercase) for (extension, 0..) |c, i| { if (i >= 3) break; entry.extension[i] = to_upper(c); @@ -45,7 +42,6 @@ pub fn create_entry( return entry; } -/// Create a stack entry pub fn create_stack_entry( identity: []const u8, first_cluster: u32, @@ -53,17 +49,14 @@ pub fn create_stack_entry( return create_entry(identity, "", constants.attr_stack, first_cluster, 0); } -/// Create a "." entry for current stack pub fn create_dot_entry(cluster: u32) StackEntry { return create_entry(".", "", constants.attr_stack, cluster, 0); } -/// Create a ".." entry for parent stack pub fn create_dotdot_entry(parent_cluster: u32) StackEntry { return create_entry("..", "", constants.attr_stack, parent_cluster, 0); } -/// Create a unit entry pub fn create_unit_entry( identity: []const u8, extension: []const u8, @@ -73,7 +66,6 @@ pub fn create_unit_entry( return create_entry(identity, extension, constants.attr_archive, first_cluster, unit_size); } -/// Convert character to uppercase fn to_upper(c: u8) u8 { if (c >= 'a' and c <= 'z') { return c - 32; @@ -81,9 +73,7 @@ fn to_upper(c: u8) u8 { return c; } -/// Parse identity into name and extension parts pub fn parse_identity(identity: []const u8) struct { name: []const u8, ext: []const u8 } { - // Find last dot var dot_pos: ?usize = null; var i: usize = identity.len; while (i > 0) { diff --git a/shared/fs/fat32/write/write.zig b/shared/fs/fat32/write/write.zig index 711293e..b6a596e 100644 --- a/shared/fs/fat32/write/write.zig +++ b/shared/fs/fat32/write/write.zig @@ -3,7 +3,6 @@ pub const boot = @import("boot.zig"); pub const entry = @import("entry.zig"); -// Boot sector creation pub const CreateParams = boot.CreateParams; pub const calculate_fat_size = boot.calculate_fat_size; pub const create_boot_sector = boot.create_boot_sector; @@ -12,7 +11,6 @@ pub const init_fat_table = boot.init_fat_table; pub const allocate_cluster = boot.allocate_cluster; pub const link_clusters = boot.link_clusters; -// Entry creation pub const create_entry = entry.create_entry; pub const create_stack_entry = entry.create_stack_entry; pub const create_dot_entry = entry.create_dot_entry; |
