summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fs.zig20
-rw-r--r--src/ninep/ctl.zig30
-rw-r--r--src/ninep/events.zig42
-rw-r--r--src/ninep/pane.zig20
4 files changed, 51 insertions, 61 deletions
diff --git a/src/fs.zig b/src/fs.zig
index 4b7bba31..d8633593 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -18,8 +18,8 @@ const Req = tree.Req;
const Reply = tree.Reply;
const E = tree.E;
-/// The served README; tree.zig answers it.
-/// The tree's README; a build that embeds no sources lists no src/.
+/// The tree's README, which tree.zig answers; a build that embeds no
+/// sources lists no src/.
pub const help = help: {
const raw = @embedFile("fs-help.txt");
if (limits.embedded_sources) break :help raw;
@@ -1353,11 +1353,8 @@ pub const Namespace = struct {
refused: bool = false,
failure: [256]u8 = undefined,
failure_len: u16 = 0,
- /// What went wrong performing a write's effects after it was answered
- /// by the core (a save the host could not do): the 9P write, which
- /// waits for them, fails with it (src/9p_io.zig).
/// A header tag truncated by an open not yet released (ninep/cols.zig):
- /// 0 the workspace's, a column's its index + 1; and whether the newline
+ /// 0 the workspace's, a column's its serial; and whether the newline
/// that ended its last write is held back.
header_rewrite: ?u32 = null,
/// A column's or the workspace's tag truncated, not yet done (as a
@@ -1374,6 +1371,9 @@ pub const Namespace = struct {
said: [256]u8 = undefined,
said_len: u16 = 0,
said_at: u32 = 0,
+ /// What went wrong performing a write's effects after it was answered
+ /// by the core (a save the host could not do): the 9P write, which
+ /// waits for them, fails with it (src/9p_io.zig).
late_failure: [256]u8 = undefined,
late_failure_len: u16 = 0,
/// A 9P write asked a language server something: the answer count it
@@ -1402,10 +1402,6 @@ pub const Namespace = struct {
/// The whole text of the newest counted log record, hashed: its record
/// may be cut, and a repeat is only the same whole text again.
log_full_hash: u64 = 0,
- /// Writes one open made in a row into one place of a pane's body (an
- /// append to `body`, an insert at `data`'s address), held and put in
- /// as one edit when anything else comes (ninep/pane.zig flushBatch): a
- /// 10 MB write in 8 KB pieces is one copy and one undo step, not 1280.
/// The text of /pager opens closed before a read put it in, each with
/// its +Pager's serial, for the editor's step to put in (ctl.fillPager):
/// a close through a mount may not wait for the editor to be quiet,
@@ -1416,6 +1412,10 @@ pub const Namespace = struct {
/// (tree.runClosedLines): a close is answered at once, for the same
/// reason as `pages`.
closed_lines: std.ArrayList(struct { node: u64, bytes: std.ArrayList(u8) }) = .empty,
+ /// Writes one open made in a row into one place of a pane's body (an
+ /// append to `body`, an insert at `data`'s address), held and put in
+ /// as one edit when anything else comes (ninep/pane.zig flushBatch): a
+ /// 10 MB write in 8 KB pieces is one copy and one undo step, not 1280.
batch: struct {
serial: u32 = 0,
node: u64 = 0,
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 53753b42..de4166cd 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -122,10 +122,6 @@ const Messages = struct {
/// a diff's context line ` ` alone): only its `\r` goes.
keep_blanks: bool = false,
- fn init(p: *Pardes, data: []const u8) Messages {
- return .{ .p = p, .data = data };
- }
-
fn next(m: *Messages) ?[]const u8 {
if (m.at >= m.data.len) return null;
const start = m.at;
@@ -198,7 +194,7 @@ pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Rep
if (editNotAlone(p, req.data)) return tree.failText(req.tag, E.INVAL, e_after_edit);
for ([2]bool{ false, true }) |apply| {
if (apply) p.fs.results_len = 0;
- var it = Messages.init(p, req.data);
+ var it: Messages = .{ .p = p, .data = req.data };
it.keep_blanks = !exec;
while (it.next()) |text| {
if (text.len == 0) continue;
@@ -273,7 +269,7 @@ fn editNotAlone(p: *Pardes, data: []const u8) bool {
const sam = @import("../sam_edit.zig");
var lines: usize = 0;
var runs = false;
- var it = Messages.init(p, data);
+ var it: Messages = .{ .p = p, .data = data };
while (it.next()) |line| {
if (line.len == 0 or exec_line.isComment(line)) continue;
lines += 1;
@@ -651,7 +647,7 @@ pub fn settingsText(p: *Pardes) ![]const u8 {
pub fn writePager(p: *Pardes, req: Req) Reply {
// A refused write leaves its open no answer, not the last one's.
p.fs.results_len = 0;
- var it = Messages.init(p, req.data);
+ var it: Messages = .{ .p = p, .data = req.data };
const line = it.next() orelse "";
// Words 9ns maps back to EINVAL (`invalid`), as every refusal here. One
// directory an open, as pty/run takes one line: through a mount
@@ -669,15 +665,17 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
var shown: [256]u8 = undefined;
return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch "pager: invalid directory: must be absolute");
}
- if (comptime pardes.hosted) if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| if (exec_line.kindOf(local) != .directory) {
+ if (comptime pardes.hosted) if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| {
// A file there is no directory, ENOTDIR; nothing there, ENOENT.
- if (exec_line.kindOf(local) != null)
- return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: not a directory");
- return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: no such directory");
+ if (exec_line.kindOf(local) != .directory) {
+ if (exec_line.kindOf(local) != null)
+ return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: not a directory");
+ return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: no such directory");
+ }
+ // Nor one that may not be written, as a file's name there is refused.
+ if (pardes.filesystem.deniedAbove(local))
+ return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch "pager: permission denied");
};
- // Nor one that may not be written, as a file's name there is refused.
- if (comptime pardes.hosted) if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| if (pardes.filesystem.deniedAbove(local))
- return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch "pager: permission denied");
const id = pardes.panes.Output.openPager(p, p.active, dir) catch |err|
return tree.failText(req.tag, if (err == error.NoPaneRoom or err == error.NoPaneSlots) E.NOSPC else E.IO, switch (err) {
error.NoPaneRoom, error.NoPaneSlots => "pager: no space for a +Pager pane",
@@ -732,7 +730,7 @@ pub fn fillClosedPagers(p: *Pardes) void {
pub fn writeRoot(p: *Pardes, req: Req) Reply {
for ([2]bool{ false, true }) |apply| {
if (apply) p.fs.results_len = 0;
- var it = Messages.init(p, req.data);
+ var it: Messages = .{ .p = p, .data = req.data };
while (it.next()) |line| {
if (line.len == 0 or exec_line.isComment(line)) continue;
if (std.mem.startsWith(u8, line, "size ") or std.mem.eql(u8, line, "size")) {
@@ -1061,7 +1059,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
for ([2]bool{ false, true }) |apply| {
if (apply) p.fs.results_len = 0;
var held = !other and pane.fs.lock != null;
- var it = Messages.init(p, req.data);
+ var it: Messages = .{ .p = p, .data = req.data };
while (it.next()) |line_in| {
if (line_in.len == 0 or exec_line.isComment(line_in)) continue;
// A line before this one may have closed the pane (`Del`).
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index bc43dbfd..e67deb1d 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -195,13 +195,6 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void {
std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept, cut })) catch return, said);
}
-/// Records `err <serial|-> <file>: <why>` for a write that was refused or
-/// failed: through a mount a shell sees only the errno the
-/// kernel mapped the reply to (`Invalid argument`), and here is the reason.
-/// The log is the one place for it, as acme's `errors` file takes text and
-/// answers nothing: a per-pane readable error file would be a second.
-/// `dump <path>` when a Dump is written, `restore <path>` first in a
-/// Restore's replacement.
/// `notePath` for an `err` record: the same one again straight after is
/// counted, `(x2)`, as every err is.
pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
@@ -210,12 +203,19 @@ pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text}) catch return, text);
}
+/// Records `<what> <path>`: `dump <path>` when a Dump is written,
+/// `restore <path>` first in a Restore's replacement.
pub fn notePath(p: *Pardes, what: []const u8, path: []const u8) void {
bootFirst(p);
var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined;
pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path }) catch return);
}
+/// Records `err <serial|-> <file>: <why>` for a write that was refused or
+/// failed: through a mount a shell sees only the errno the kernel mapped
+/// the reply to (`Invalid argument`), and here is the reason. The log is
+/// the one place for it, as acme's `errors` file takes text and answers
+/// nothing: a per-pane readable error file would be a second.
pub fn noteError(p: *Pardes, req: Req, reply: Reply) void {
const why = if (reply.ename.len > 0) reply.ename else cloud9.fs.errString(reply.errno);
var name: [32]u8 = undefined;
@@ -354,9 +354,8 @@ pub fn shown(text: []const u8, out: []u8) []u8 {
fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 {
var w: usize = 0;
var i: usize = 0;
- const body = text;
- while (i < body.len and w + 4 <= out.len) {
- const c = body[i];
+ while (i < text.len and w + 4 <= out.len) {
+ const c = text[i];
// A name's own backslash is `\\`, so `\n` and `\xNN` read back as
// the escapes they are, never as a name that held them.
if (c == '\\' and escape_newline) {
@@ -385,16 +384,16 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 {
continue;
}
const n = std.unicode.utf8ByteSequenceLength(c) catch 0;
- if (n == 0 or i + n > body.len or !std.unicode.utf8ValidateSlice(body[i .. i + n])) {
+ if (n == 0 or i + n > text.len or !std.unicode.utf8ValidateSlice(text[i .. i + n])) {
_ = std.fmt.bufPrint(out[w..], "\\x{x:0>2}", .{c}) catch break;
w += 4;
i += 1;
continue;
}
- if (n == 2 and c == 0xC2 and body[i + 1] <= 0x9F) {
+ if (n == 2 and c == 0xC2 and text[i + 1] <= 0x9F) {
if (escape_newline) {
if (w + 8 > out.len) break;
- _ = std.fmt.bufPrint(out[w..], "\\xc2\\x{x:0>2}", .{body[i + 1]}) catch break;
+ _ = std.fmt.bufPrint(out[w..], "\\xc2\\x{x:0>2}", .{text[i + 1]}) catch break;
w += 8;
i += 2;
continue;
@@ -405,7 +404,7 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 {
continue;
}
if (w + n > out.len) break;
- @memcpy(out[w..][0..n], body[i..][0..n]);
+ @memcpy(out[w..][0..n], text[i..][0..n]);
w += n;
i += n;
}
@@ -555,7 +554,6 @@ pub const Action = enum(u8) {
};
pub const flag_builtin: u32 = 1;
-pub const flag_expansion: u32 = 2;
pub const flag_filename: u32 = 4;
pub const flag_chorded: u32 = 8;
@@ -722,14 +720,11 @@ fn scanNumber(data: []const u8, i: *usize, overflow: *bool) ?u32 {
return @intCast(n);
}
-/// Writing a Look or Exec record back performs the action it names.
-/// The word a click at `at` expands to: the file name or word run under it
-/// on its line (look.expandedWord), else nothing.
-/// An empty range written back: what a click at `at` takes, as the mouse's
-/// does (exec.operandAt). In a diff pane's body that is look.diffClick's
-/// answer, the line's address or its code's words.
-/// `for_look`: only a look in a body takes a diff line's address
-/// (exec.operandAt); an exec takes the word there, as anywhere.
+/// What a click at `at` takes, as the mouse's does (exec.operandAt),
+/// for an empty range written back: the file name or word under it on its
+/// line (look.expandedWord), else nothing; in a diff pane's body, for a
+/// look alone (`for_look`, exec.operandAt), look.diffClick's answer, the
+/// line's address or its code's words.
pub fn expandAt(p: *Pardes, pane: *Pane, whole: []const u8, at: usize, in_body: bool, for_look: bool) []const u8 {
const start = if (std.mem.lastIndexOfScalar(u8, whole[0..at], '\n')) |nl| nl + 1 else 0;
const end = std.mem.indexOfScalarPos(u8, whole, at, '\n') orelse whole.len;
@@ -750,6 +745,7 @@ pub fn expandAt(p: *Pardes, pane: *Pane, whole: []const u8, at: usize, in_body:
return whole[start + word_from + b.lo .. start + word_from + b.hi];
}
+/// Writing a Look or Exec record back performs the action it names.
pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply {
const pane0 = p.panes[id] orelse return Reply.fail(asked.tag, E.NOENT);
// Its last record needs no newline, as every other line file's last
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 48095c46..90934791 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -854,20 +854,14 @@ fn writeFlag(p: *Pardes, req: Req, pane: *Pane, file: PaneFile) Reply {
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
-/// Writing `name` renames the buffer: a relative name resolves against the
-/// pane's directory, as the tag's name field does.
-/// acme's refusal of a name with a blank or a control character in it
-/// (editors/acme/xfid.c:650-652). A blank inside a name is taken here, as
-/// pardes names files with spaces; one at either end is refused, not
-/// quietly cut off, so the name a script wrote is the name it gets.
+/// acme's words for a name it refuses (editors/acme/xfid.c:650-652), the
+/// reason after them.
pub const e_name_char = "bad character in file name";
-/// Why `name` is not one file name, with the reason, or null: a newline, a
-/// control byte, DEL or a C1 control (U+0080-U+009F), a blank at either
-/// end, or bytes that are not UTF-8.
-/// What no file name can hold, said: a newline (a name is one line) and
-/// a NUL. Any other byte a file system takes is taken, controls and bytes
-/// not UTF-8 included, so a name read from `name` writes back as it was.
+/// What no file name can hold, said: a newline (a name is one line), a
+/// NUL, a component over 255 bytes. Any other byte a file system takes is
+/// taken, blanks, controls and bytes not UTF-8 included, so a name read
+/// from `name` writes back as it was.
fn nameFault(name: []const u8) ?[]const u8 {
if (std.mem.indexOfScalar(u8, name, '\n') != null) return e_name_char ++ ": a newline (a name is one line)";
if (std.mem.indexOfScalar(u8, name, 0) != null) return e_name_char ++ ": a NUL";
@@ -895,6 +889,8 @@ pub fn heldNameFault(p: *Pardes, serial: u32, held: []const u8) ?[]const u8 {
return null;
}
+/// Writing `name` renames the buffer: a relative name resolves against the
+/// pane's directory, as the tag's name field does.
fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
// One name: its newline ends it, as `echo` writes it, and it is one.
const name = if (std.mem.endsWith(u8, req.data, "\n")) req.data[0 .. req.data.len - 1] else req.data;