Skip to content

Commit b56774a

Browse files
feat(applets): add umount
1 parent 0bc85fe commit b56774a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

applets.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ pub const chroot = @import("applets/chroot.zig");
55
pub const @"false" = @import("applets/false.zig");
66
pub const pwd = @import("applets/pwd.zig");
77
pub const @"true" = @import("applets/true.zig");
8+
pub const umount = @import("applets/umount.zig");
89
pub const uptime = @import("applets/uptime.zig");
910
pub const yes = @import("applets/yes.zig");

applets/umount.zig

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const builtin = @import("builtin");
2+
const clap = @import("clap");
3+
const std = @import("std");
4+
const ziggybox = @import("ziggybox");
5+
6+
fn umount(path: [*:0]const u8) !void {
7+
const r = std.os.linux.umount(path);
8+
return switch (std.os.errno(r)) {
9+
.SUCCESS => {},
10+
.PERM => error.AccessDenied,
11+
else => |err| return std.os.unexpectedErrno(err),
12+
};
13+
}
14+
15+
pub fn run(args: *std.process.ArgIterator) !void {
16+
const stderr = ziggybox.io.getStdErr();
17+
18+
const params = comptime clap.parseParamsComptime(
19+
\\-h, --help Display this help and exit.
20+
\\<path> The directory to unmount
21+
\\
22+
);
23+
24+
var diag = clap.Diagnostic{};
25+
var res = ziggybox.clap.parseEx(clap.Help, &params, comptime .{
26+
.path = clap.parsers.string,
27+
}, args, .{
28+
.allocator = ziggybox.common.allocator,
29+
.diagnostic = &diag,
30+
}) catch |err| {
31+
diag.report(stderr, err) catch {};
32+
return err;
33+
};
34+
defer res.deinit();
35+
36+
if (res.args.help != 0 or res.positionals.len < 1)
37+
return clap.help(stderr, clap.Help, &params, .{});
38+
39+
const path = try ziggybox.common.allocator.dupeZ(u8, res.positionals[0]);
40+
defer ziggybox.common.allocator.free(path);
41+
try umount(path);
42+
}

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn build(b: *std.Build) !void {
2222
"false",
2323
"pwd",
2424
"true",
25+
"umount",
2526
"uptime",
2627
"yes",
2728
};

0 commit comments

Comments
 (0)