Posts

Plan 9 Plumber

Image
Plumb Zip file   View files inside a zip compressed file via Plumber without extraction. Zip file contents are accessible at /n/tapefs. (Note: sam displays the UTF Byte-Order-Mark (BOM) as is - the garbage in the beginning of the first line). #zip file content in a new window type    is    text data    matches    '([a-zA-Z¡-ï¿¿0-9_\-.,/]+)\.zip' arg    isfile    $0 plumb    start    window fs/zipfs $file; cd /n/tapefs; ls; rc   Plumber process, usually running in the parent process, does not have visibility into the folders mounted by the child process because of namespace isolation. Hence, you need the following changes: zipfs (or 32vfs, cpiofs, tapfs, tarfs, tpfs, v6fs, v10fs etc.) must expose a service in the /srv directory. ( fs.c ) plumber must mount the zipfs for paths starting with /n/tapefs before checking for file existence. ( match.c )   

Plan 9: Tiled Map

Image
  Use plot(1) to display tiled maps. The zoom factor decides the grid dimension. osm.js: Download tile images using hget. Cache the images. Convert the PNG image into Plan 9 format using png. Display the images using plot. Plot script   ra 0 0 200 200 m 0 100 im /file :Note - must end the script with a newline     Plot tries to center the drawing. Hence the origin is at the bottom with a slight offset from the left. However, image uses origin at the top left.     Interactive Plotting and Maps Use plot command in server mode (-s option). plot -s a.plt  mount /srv/plot /mnt/plot echo li 0 0 100 100 > /mnt/plot/ctl echo erase > /mnt/plot/ctl Usage as an interactive map.    Text Formatting   Demo of some advanced features. - Set pen color - Align text around a point - Set pen thickness - Set start and end of the line. Available ends are square, disc and arrow. - Use vec for polyline (a set of points connected with line...

Browser in Javascript

Image
  A Proof-of-Concept Browser written in Javascript for minimal Web 2.0 browsing experience. This DOES NOT depend on any browser engine like Blink, Gecko or Webkit. Use an existing HTML rendering engine like netsurf or roll-out your own . This uses QuickJS-ng for JS runtime, Linkedom for DOM API and curl for network downloads. Font decoration uses Terminal ANSI escape codes . Since linkedom is an npm module, it needs to be converted to ES6 module for use with quickjs.  npm install linkedom npx esbuild node_modules/linkedom/esm/index.js \     --bundle \     --format=esm \     --outfile= linkedom.bundle.js \     --platform=neutral         Code https://gitlab.com/atamariya/quickjs/-/blob/dev/ldom.js https://gitlab.com/atamariya/quickjs/-/blob/dev/net.js https://gitlab.com/atamariya/quickjs/-/blob/dev/render.js   Lessons Learnt std.urlGet() only supports stateless downloads. For form posts, header manipulati...

Plan 9: Network Printer (HP Deskjet Ink Advantage 3545)

Image
Internet Printing Protocol Printing with  Internet Printing Protocol (IPP)  involves sending a Unirast   Format (URF) image with appropriate protocol headers to port 631. It is the basis for standards like  Windows Mopria Alliance , Apple   AirPrint , and IPP Everywhere .  It is also called  Driverless Printing   since this doesn't involve installing any printer specific driver. On Plan 9, printing involves three steps: Convert the document to PDF using lp Convert the PDF to URF using  gs  (use urfgray, urfrgb or urfcmyk device) Send the request to the printer using hget IPP header ( req.bin in the below script) contains page output options like paper size, margins etc. This is generated   using ippenc.c .        #!/bin/rc HOST=$1 FILE=$2 TFILE=/tmp/a.pdf URL=( http://$HOST:631/ipp/print/ ) if (! ~ $#* 2)    echo 'Usage: $0 <printer-ip> <file>'     lp -d stdout $FILE > $TFILE...

Plan 9: Audio-Video Pipeline

Image
Video pipeline in action Two important points about videos: A video is a series of images. RGB format is used for display. YUV format is used for storage and transmission.  Recording   ──────────────────────────────────────────────────────── [Video Source] → [Frame Processing] → [Video Encode] ┐                                                                                                      ├→ [Mux] → [Container Stream] [Audio Source] → [Audio Processing] → [Audio Encode] ┘ Playback   ──────────────────────────────────────────────────────── [Container Stream] → [Demux] → [Video Decode] → [Video Sink]                                   ...

Plan 9: Real Time Streaming

Image
Stream a single window or the whole screen via Real Time Streaming Protocol (RTSP). This uses MJPEG stream over TCP-interleave . Plan 9 /dev/screen and /dev/window produces RGBA byte stream with Plan 9 headers. This is converted to JPEG using tojpg and streamed using RTSP. In the video, host port 12554 port is being forwarded to 554 in the Plan 9 VM.  ffplay -rtsp_transport tcp rtsp://localhost:12554/ stream1       Code https://gitlab.com/atamariya/plan9front/-/blob/dev/sys/src/cmd/rtsp/server.c https://gitlab.com/atamariya/plan9front/-/blob/dev/sys/src/cmd/jpg/tojpg.c https://gitlab.com/atamariya/plan9front/-/blob/dev/sys/src/cmd/jpg/writejpg.c ( Update 16/03/2026 : server.c is moved to /sys/src/cmd/stream/rtsp/)   Youtube Live Use Real-Time Messaging Protocol ( RTMP ) to feed into Youtube / Twitch Live. video/hj264 -f 25 /dev/screen | video/rtmp -a /dev/audio rtmp://.... rtmp://...         Note:   The encoder and the publisher pr...

Plan 9: WiFi Protected Setup

Image
  Demo of Wifi router connection using WiFi Protected Setup (WPS). WiFi Protected Setup (WPS) allows you to connect to an Access Point (router) via Push Button Control (PBC) or a temporary PIN.   Authentication Flow   Direction Message / Contents Phase / Purpose Supplicant → AP Authentication Request 802.11 Authentication Supplicant ← AP Authentication Response Supplicant → AP Association Request 802.11 Association Supplicant ← AP Association Response Supplicant → AP EAPOL-Start EAP Initiation Supplicant ← AP EAP-Request Identity Supplicant → AP EAP-Response Identity (Identity: “WFA-SimpleConfig-Registrar-1-0”) Supplicant ← AP WSC Start Enrollee → Registrar (M1) N1 || Descripti...