Skip to content

mknod: implement it - #255

Open
metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:mknod-implementation
Open

metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:mknod-implementation

Conversation

@metif12

@metif12 metif12 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

mknod creates special files, with -m and -Z.

Types are FIFO (p), block (b) and character (c) devices. u is rejected because Linux does not implement the POSIX "unspecified" type — measured against GNU rather than assumed.

Block and character devices need a major and minor number, packed the way makedev does. The file type is folded into the mode passed to mknod(2) alongside the permission bits, which is the detail that distinguishes a FIFO from a plain file.

The default mode is 0666 masked by the umask, as GNU applies.

How this was verified

V cannot link a Linux binary from Windows, only emit C. So I cross-compiled with -os linux, rewrote V's absolute Windows #include paths to their /mnt equivalents, and built with WSL's gcc. FIFOs turn out to be creatable unprivileged, which made real verification possible rather than only error-path checking:

  • a FIFO is created with the same type and mode as GNU's (fifo 644)
  • every diagnostic matches byte-for-byte, including the curly quotes GNU puts around operands (‘ff’) and the bare mknod: ex: File exists form with no cannot create and no quotes

One correction worth recording: GNU's diagnostics use U+2018/U+2019 curly quotes, not ASCII apostrophes. My first version emitted the ASCII form and looked right in the terminal, which is exactly the kind of difference that only byte-level comparison catches.

Same caveat as the other nix-only tools: the _nix_test.v suite covers only parsing and the mode arithmetic. It compiles for Linux, but I could not execute it, since V will not generate C for a test target. It will run on the ubuntu-* CI jobs.

Creates special files, with -m and -Z. Types are FIFO (p), block (b) and character (c) devices; u is rejected because Linux does not implement the POSIX unspecified type. Block and character devices need a major and minor number, packed the way makedev does, and the file type is folded into the mode passed to mknod(2) alongside the permission bits, which is the detail that distinguishes a FIFO from a plain file. The default mode is 0666 masked by the umask, as GNU applies. Nix-only: mknod(2) does not exist on Windows and the file types have no Windows equivalent, so mknod stays in the build.vsh ignore list and the suite is named _nix_test.v. Verified by cross-compiling to Linux and running under WSL: a FIFO is created with the same type and mode as GNU's, and every diagnostic matches byte for byte, including the curly quotes GNU puts around operands and the bare 'name: File exists' form.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant