9P-CMDBUF(3)
πΈ NAME πΈ
Cmdbuf, parsecmd, respondcmderror, lookupcmd β control message parsing, bestie. This is the 9P-CMDBUF(3) page from the Library Functions Manual, and it's literally all about parsing textual control messages. Iconic behavior.
β¨ SYNOPSIS β¨
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
typedef struct Cmdbuf
{
char *buf;
char **f;
int nf;
} Cmdbuf;
typedef struct Cmdtab
{
int index;
char *cmd;
int narg;
};
Cmdbuf *parsecmd(char *p, int n)
Cmdtab *lookupcmd(Cmdbuf *cb, Cmdtab *tab, int ntab)
void respondcmderror(Req *r, Cmdbuf *cb, char *fmt, ...)
π DESCRIPTION π
These data structures and functions provide parsing of textual control messages. Periodt.
parsecmd treats the n bytes at p (which need not be NUL-terminated) as a UTF string and splits it using tokenize (see getfields(3)). It returns a Cmdbuf structure holding pointers to each field in the message. Slay.
lookupcmd walks through the array ctab, which has ntab entries, looking for the first Cmdtab that matches the parsed command. Tiny thing: the synopsis parameter is named tab, while the description says ctab β we contain multitudes. If the parsed command is empty, lookupcmd returns nil immediately.
β οΈ Okay so the original matching sentence is lowkey corrupted. It literally says: βACmdtabmatches the command ifcmdis equal tocb->f[0]or ifcmdis Once a matchingCmdtabhas been found, ifnargis not zero, then the parsed command must have exactlynargfields (including the command string itself).β I am not gonna invent the missing words, bestie. Here are the facts that are actually clear:
- A
Cmdtabmatches the command ifcmdis equal tocb->f[0]β that part is clear. - Once a matching
Cmdtabhas been found, ifnargis not zero, then the parsed command must have exactlynargfields (including the command string itself). - If the command has the wrong number of arguments,
lookupcmdreturnsnil. - Otherwise, it returns a pointer to the
Cmdtabentry. - If
lookupcmddoes not find a matching command at all, it returnsnil. - Whenever
lookupcmdreturnsnil, it sets the system error string.
respondcmderror responds β the page literally says resoponds, typo and all, we love that β to request r with an error of the form fmt: cmd, where fmt is the formatted string and cmd is a reconstruction of the parsed command. fmt is often simply %r.
π EXAMPLES π
This interface is not used in any distributed 9P servers. Not one. It was lifted from the Plan 9 kernel. Almost any Plan 9 kernel driver (/sys/src/9/*/dev*.c on Plan 9) is a good example. Go look, bestie.
π SOURCE π
/src/lib9p/parse.c β that's the source, no cap.
π SEE ALSO π
9p(3) β go read that next, bestie π«Ά
And the footer? Just 9P-CMDBUF(3) again, no date, no version, no extra crumbs. That's the whole page, bestie β go parse some control messages πβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms