Skip to content

Commit d38468e

Browse files
committed
Compiles on december zig master, untested
1 parent f29ac60 commit d38468e

10 files changed

Lines changed: 65 additions & 63 deletions

File tree

build.zig.zon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
.fingerprint = 0x9947018c924eecb2,
55
.dependencies = .{
66
.zfat = .{
7-
.url = "git+https://github.com/ZigEmbeddedGroup/zfat.git#0571b0d8c8cc4fcb037a1d5e7ea5666cb2f83ddf",
8-
.hash = "zfat-0.15.0-SNNK9RRqcgCLQ5mjXghbB6mokzcHORsGnY7GtbfOt2k3",
7+
// .url = "git+https://github.com/CascadeOS/zfat#2806bfd983dd810c9c74b0ea6a63f783208518b5",
8+
// .hash = "zfat-0.16.0-SNNK9fKtTgASssfmCblZwRMLU4pndVtwxTNhYCegBOyA",
9+
.path = "../zfat"
910
},
1011
.args = .{
1112
.url = "git+https://github.com/ikskuh/zig-args.git#8ae26b44a884ff20dca98ee84c098e8f8e94902f",

src/Parser.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ pub const Error = Tokenizer.Error || error{
1818
UnknownDirective,
1919
OutOfMemory,
2020
InvalidEscapeSequence,
21+
Canceled,
2122
};
2223

2324
pub const IO = struct {
24-
fetch_file_fn: *const fn (io: *const IO, std.mem.Allocator, path: []const u8) error{ FileNotFound, IoError, OutOfMemory, InvalidPath }![]const u8,
25+
fetch_file_fn: *const fn (io: *const IO, std.mem.Allocator, path: []const u8) error{ FileNotFound, IoError, OutOfMemory, InvalidPath, Canceled }![]const u8,
2526
resolve_variable_fn: *const fn (io: *const IO, name: []const u8) error{UnknownVariable}![]const u8,
2627

27-
pub fn fetch_file(io: *const IO, allocator: std.mem.Allocator, path: []const u8) error{ FileNotFound, IoError, OutOfMemory, InvalidPath }![]const u8 {
28+
pub fn fetch_file(io: *const IO, allocator: std.mem.Allocator, path: []const u8) error{ FileNotFound, IoError, OutOfMemory, InvalidPath, Canceled }![]const u8 {
2829
return io.fetch_file_fn(io, allocator, path);
2930
}
3031

src/components/EmptyData.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pub fn parse(ctx: dim.Context) !dim.Content {
1515
}));
1616
}
1717

18-
fn render(self: *EmptyData, stream: *dim.BinaryStream) dim.Content.RenderError!void {
18+
fn render(self: *EmptyData, io: std.Io, stream: *dim.BinaryStream) dim.Content.RenderError!void {
1919
_ = self;
2020
_ = stream;
21+
_ = io;
2122
}

src/components/FillData.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub fn parse(ctx: dim.Context) !dim.Content {
1919
}));
2020
}
2121

22-
fn render(self: *FillData, stream: *dim.BinaryStream) dim.Content.RenderError!void {
22+
fn render(self: *FillData, io: std.Io, stream: *dim.BinaryStream) dim.Content.RenderError!void {
23+
_ = io;
2324
var writer = stream.writer();
2425
writer.interface.splatByteAll(
2526
self.fill_value,

src/components/PasteFile.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ pub fn parse(ctx: dim.Context) !dim.Content {
1515
}));
1616
}
1717

18-
fn render(self: *PasteFile, stream: *dim.BinaryStream) dim.Content.RenderError!void {
19-
try self.file_handle.copy_to(stream);
18+
fn render(self: *PasteFile, io: std.Io, stream: *dim.BinaryStream) dim.Content.RenderError!void {
19+
try self.file_handle.copy_to(io, stream);
2020
}

src/components/fs/FatFileSystem.zig

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ const Appender = struct {
8181
}
8282
};
8383

84-
fn render(self: *FAT, stream: *dim.BinaryStream) dim.Content.RenderError!void {
84+
fn render(self: *FAT, io: std.Io, stream: *dim.BinaryStream) dim.Content.RenderError!void {
85+
fatfs.io = io;
8586
var bsd: BinaryStreamDisk = .{ .stream = stream };
8687

8788
const min_size, const max_size = self.format_as.get_size_limits();
@@ -154,7 +155,7 @@ fn render(self: *FAT, stream: *dim.BinaryStream) dim.Content.RenderError!void {
154155

155156
const wrapper = AtomicOps{};
156157
for (self.ops.items) |op| {
157-
try op.execute(wrapper);
158+
try op.execute(io, wrapper);
158159
}
159160
}
160161

@@ -241,7 +242,7 @@ const AtomicOps = struct {
241242
defer fs_file.close();
242243

243244
var fs_file_buffer: [1024]u8 = undefined;
244-
var adapter = fs_file.writer(&fs_file_buffer);
245+
var adapter = fs_file.writer(io, &fs_file_buffer);
245246

246247
_ = try reader.streamRemaining(&adapter.writer);
247248

@@ -273,16 +274,17 @@ const BinaryStreamDisk = struct {
273274
return disk_getStatus(intf);
274275
}
275276

276-
fn disk_read(intf: *fatfs.Disk, buff: [*]u8, sector: fatfs.LBA, count: c_uint) fatfs.Disk.Error!void {
277+
fn disk_read(intf: *fatfs.Disk, io: std.Io, buff: [*]u8, sector: fatfs.LBA, count: c_uint) fatfs.Disk.Error!void {
277278
const bsd: *BinaryStreamDisk = @fieldParentPtr("disk", intf);
278279

279-
bsd.stream.read(block_size * sector, buff[0 .. count * block_size]) catch |err| {
280+
bsd.stream.read(io, block_size * sector, buff[0 .. count * block_size]) catch |err| {
280281
bsd.disk_error = err;
281282
return error.IoError;
282283
};
283284
}
284285

285-
fn disk_write(intf: *fatfs.Disk, buff: [*]const u8, sector: fatfs.LBA, count: c_uint) fatfs.Disk.Error!void {
286+
fn disk_write(intf: *fatfs.Disk, io: std.Io, buff: [*]const u8, sector: fatfs.LBA, count: c_uint) fatfs.Disk.Error!void {
287+
_ = io;
286288
const bsd: *BinaryStreamDisk = @fieldParentPtr("disk", intf);
287289

288290
bsd.stream.write(block_size * sector, buff[0 .. count * block_size]) catch |err| {
@@ -291,7 +293,8 @@ const BinaryStreamDisk = struct {
291293
};
292294
}
293295

294-
fn disk_ioctl(intf: *fatfs.Disk, cmd: fatfs.IoCtl, buff: [*]u8) fatfs.Disk.Error!void {
296+
fn disk_ioctl(intf: *fatfs.Disk, io: std.Io, cmd: fatfs.IoCtl, buff: [*]u8) fatfs.Disk.Error!void {
297+
_ = io;
295298
const bsd: *BinaryStreamDisk = @fieldParentPtr("disk", intf);
296299

297300
switch (cmd) {

src/components/fs/common.zig

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub const FsOperation = union(enum) {
2626
contents: dim.Content,
2727
},
2828

29-
pub fn execute(op: FsOperation, executor: anytype) !void {
29+
pub fn execute(op: FsOperation, io: std.Io, executor: anytype) !void {
3030
const exec: Executor(@TypeOf(executor)) = .init(executor);
31-
try exec.execute(op);
31+
try exec.execute(io, op);
3232
}
3333
};
3434

@@ -42,7 +42,7 @@ fn Executor(comptime T: type) type {
4242
return .{ .inner = wrapped };
4343
}
4444

45-
fn execute(exec: Exec, op: FsOperation) dim.Content.RenderError!void {
45+
fn execute(exec: Exec, io: std.Io, op: FsOperation) dim.Content.RenderError!void {
4646
switch (op) {
4747
.make_dir => |data| {
4848
try exec.recursive_mkdir(data.path);
@@ -53,10 +53,10 @@ fn Executor(comptime T: type) type {
5353
error.FileNotFound => return, // open() already reported the error
5454
else => |e| return e,
5555
};
56-
defer handle.close();
56+
defer handle.close(io);
5757

5858
var buffer: [1024]u8 = undefined;
59-
var adapter = handle.reader(&buffer);
59+
var adapter = handle.reader(io, &buffer);
6060

6161
try exec.add_file(data.path, &adapter.interface);
6262
},
@@ -92,10 +92,10 @@ fn Executor(comptime T: type) type {
9292
};
9393

9494
var file = try fname.open();
95-
defer file.close();
95+
defer file.close(io);
9696

9797
var buffer: [1024]u8 = undefined;
98-
var adapter = file.reader(&buffer);
98+
var adapter = file.reader(io, &buffer);
9999

100100
try exec.add_file(path, &adapter.interface);
101101
},
@@ -121,7 +121,7 @@ fn Executor(comptime T: type) type {
121121

122122
var bs: dim.BinaryStream = .init_buffer(buffer);
123123

124-
try data.contents.render(&bs);
124+
try data.contents.render(io, &bs);
125125

126126
var reader: std.Io.Reader = .fixed(buffer);
127127

@@ -159,14 +159,14 @@ fn Executor(comptime T: type) type {
159159

160160
fn walk_err(err: (std.fs.Dir.OpenError || std.mem.Allocator.Error)) dim.Content.RenderError {
161161
return switch (err) {
162-
error.InvalidUtf8,
163-
error.InvalidWtf8,
164162
error.BadPathName,
165163
error.NameTooLong => error.InvalidPath,
166164

167165
error.OutOfMemory => error.OutOfMemory,
168166
error.FileNotFound => error.FileNotFound,
169167

168+
error.Canceled => error.Canceled,
169+
170170
error.DeviceBusy,
171171
error.AccessDenied,
172172
error.SystemResources,
@@ -177,11 +177,7 @@ fn Executor(comptime T: type) type {
177177
error.ProcessFdQuotaExceeded,
178178
error.SystemFdQuotaExceeded,
179179
error.NotDir,
180-
error.ProcessNotFound,
181180
error.PermissionDenied, => error.IoError,
182-
error.ProcessNotFound,
183-
error.PermissionDenied,
184-
=> error.IoError,
185181
};
186182
}
187183
};

src/components/part/GptPartitionTable.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn parsePartition(ctx: dim.Context) !Partition {
148148
return part;
149149
}
150150

151-
pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderError!void {
151+
pub fn render(table: *PartTable, io: std.Io, stream: *dim.BinaryStream) dim.Content.RenderError!void {
152152
const random = std.crypto.random;
153153

154154
const lba_len = stream.length / block_size;
@@ -211,7 +211,7 @@ pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderEr
211211
try stream.write(block_size * secondary_pe_array_lba + pe_ofs, &pe_block);
212212

213213
var sub_view = try stream.slice(offset, size);
214-
try partition.contains.render(&sub_view);
214+
try partition.contains.render(io, &sub_view);
215215

216216
pe_ofs += 0x80;
217217
}
@@ -273,7 +273,7 @@ pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderEr
273273
std.mem.writeInt(u32, backup_gpt_header[0x10..0x14], backup_gpt_header_crc32, .little); // CRC32 of backup header
274274

275275
// write everything we generated to disk
276-
try mbr.render(stream);
276+
try mbr.render(io, stream);
277277
try stream.write(block_size, &gpt_header_block);
278278
try stream.write(block_size * secondary_pth_lba, &backup_gpt_header_block);
279279
}

src/components/part/MbrPartitionTable.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn parse_partition(ctx: dim.Context) !Partition {
137137
return part;
138138
}
139139

140-
pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderError!void {
140+
pub fn render(table: *PartTable, io: std.Io, stream: *dim.BinaryStream) dim.Content.RenderError!void {
141141
const last_part_id = blk: {
142142
var last: usize = 0;
143143
for (table.partitions, 0..) |p, i| {
@@ -161,7 +161,7 @@ pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderEr
161161
if (table.bootloader) |bootloader| {
162162
var sector: dim.BinaryStream = .init_buffer(&boot_sector);
163163

164-
try bootloader.render(&sector);
164+
try bootloader.render(io, &sector);
165165

166166
const upper_limit: u64 = if (table.disk_id != null)
167167
0x01B8
@@ -247,7 +247,7 @@ pub fn render(table: *PartTable, stream: *dim.BinaryStream) dim.Content.RenderEr
247247

248248
var sub_view = try stream.slice(info.offset, info.size);
249249

250-
try part.contains.render(&sub_view);
250+
try part.contains.render(io, &sub_view);
251251
}
252252
}
253253

0 commit comments

Comments
 (0)