Skip to content

Support BSDs by special-casing Linux and Android specifically - #158

Closed
ryanavella wants to merge 1 commit into
thecoshman:masterfrom
ryanavella:master
Closed

ryanavella wants to merge 1 commit into
thecoshman:masterfrom
ryanavella:master

Conversation

@ryanavella

Copy link
Copy Markdown

This is kind of gross, but at least gets the crate compiling on the BSDs that don't have an ioctl for querying block size. Solves #157.

To be honest I don't understand this code-base enough to know the "proper" fix. I'd like to understand why the ioctl is needed in the first place, instead of relying exclusively on std::fs::MetaData::len when that is present. This understand could help me to craft the "proper" patch for FreeBSD support.

… This ensures the crate can compile on FreeBSD, OpenBSD, NetBSD, and DragonflyBSD.
@nabijaczleweli

nabijaczleweli commented Dec 27, 2023 •

Copy link
Copy Markdown
Collaborator

Why: struct stat::st_size is 0 for devices, natch
How: this should probably use the same methodology as I do in voreutils (https://git.sr.ht/~nabijaczleweli/voreutils/tree/02bcd701febb555147b67e0fa7fdc1504fe3cca2/item/cmd/wc.cpp#L155-177), which includes Linux, {Free,Net}BSD, OpenBSD, and the illumos gate. maybe drop the illumos gate. I'll probably do this in a bit but this is incredibly annoying to do in Rust

@ryanavella

Copy link
Copy Markdown
Author

Interesting, I didn't realize std::fs::Metadata was just a wrapper around struct stat on linux/bsd. I'll close this in favor of a less gross, more correct fix.

@nabijaczleweli

Copy link
Copy Markdown
Collaborator

unsurprisingly, that works:

root@freebsd:/mnt/http # curl localhost:8000 | grep '<abbr title="[1-9]'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0[2023-12-28 16:03:38] 127.0.0.1:47876 was served directory listing for /dev
len 8 vecnum: 129 sizeof (zfs_cmd_t) 4528
100 51684  100 51684    0     0   137k  <tr><td><a href="/bpf0" id="bpf0" class="file_icon"></a></td> <td><a href="/bpf0">bpf0</a></td> <td><a href="/bpf0" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/bpf0"><abbr title="3 B">3 B</abbr></a></td> </tr>
100 51684  100 51684    0   <tr><td><a href="/kbd0" id="kbd0" class="file_icon"></a></td> <td><a href="/kbd0">kbd0</a></td> <td><a href="/kbd0" class="datetime">2023-12-28
15:51:54</a></td> <td><a href="/kbd0"><abbr title="6 B">6 B</abbr></a></td> </tr>
  0<tr><td><a href="/kbd1" id="kbd1" class="file_icon"></a></td> <td><a href="/kbd1">kbd1</a></td> <td><a href="/kbd1" class="datetime">2023-12-28 15:51:54</a></td> <td><a
href="/kbd1"><abbr title="7 B">7 B</abbr></a></td> </tr>
   137k      0 --:--:--<tr><td><a href="/log" id="log" class="file_icon"></a></td> <td><a href="/log">log</a></td> <td><a href="/log" class="datetime">2023-12-28 15:52:08</a></td> <td><a href="/log"><abbr title="12 B">12 B</abbr></a></td> </tr>
 --:--:-- --:--:--  137k
<tr><td><a href="/md0" id="md0" class="file_icon"></a></td> <td><a href="/md0">md0</a></td> <td><a href="/md0" class="datetime">2023-12-28 15:52:08</a></td> <td><a href="/md0"><abbr title="6442450944 B">6 GiB</abbr></a></td> </tr>
<tr><td><a href="/stderr" id="stderr" class="file_icon"></a></td> <td><a href="/stderr">stderr</a></td> <td><a href="/stderr" class="datetime">2023-12-28 15:51:54</a></td>
<td><a href="/stderr"><abbr title="4 B">4 B</abbr></a></td> </tr>
<tr><td><a href="/stdin" id="stdin" class="file_icon"></a></td> <td><a href="/stdin">stdin</a></td> <td><a href="/stdin" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/stdin"><abbr title="4 B">4 B</abbr></a></td> </tr>
<tr><td><a href="/stdout" id="stdout" class="file_icon"></a></td> <td><a href="/stdout">stdout</a></td> <td><a href="/stdout" class="datetime">2023-12-28 15:51:54</a></td>
<td><a href="/stdout"><abbr title="4 B">4 B</abbr></a></td> </tr>
<tr><td><a href="/urandom" id="urandom" class="file_icon"></a></td> <td><a href="/urandom">urandom</a></td> <td><a href="/urandom" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/urandom"><abbr title="6 B">6 B</abbr></a></td> </tr>
<tr><td><a href="/vtbd0" id="vtbd0" class="file_icon"></a></td> <td><a href="/vtbd0">vtbd0</a></td> <td><a href="/vtbd0" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/vtbd0"><abbr title="107374182400 B">100 GiB</abbr></a></td> </tr>
<tr><td><a href="/vtbd0p1" id="vtbd0p1" class="file_icon"></a></td> <td><a href="/vtbd0p1">vtbd0p1</a></td> <td><a href="/vtbd0p1" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/vtbd0p1"><abbr title="65024 B">63.5 KiB</abbr></a></td> </tr>
<tr><td><a href="/vtbd0p2" id="vtbd0p2" class="file_icon"></a></td> <td><a href="/vtbd0p2">vtbd0p2</a></td> <td><a href="/vtbd0p2" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/vtbd0p2"><abbr title="34091008 B">32.5 MiB</abbr></a></td> </tr>
<tr><td><a href="/vtbd0p3" id="vtbd0p3" class="file_icon"></a></td> <td><a href="/vtbd0p3">vtbd0p3</a></td> <td><a href="/vtbd0p3" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/vtbd0p3"><abbr title="5368709120 B">5 GiB</abbr></a></td> </tr>
<tr><td><a href="/vtbd0p4" id="vtbd0p4" class="file_icon"></a></td> <td><a href="/vtbd0p4">vtbd0p4</a></td> <td><a href="/vtbd0p4" class="datetime">2023-12-28 15:51:54</a></td> <td><a href="/vtbd0p4"><abbr title="101970869248 B">95 GiB</abbr></a></td> </tr>

nabijaczleweli added a commit that referenced this pull request Dec 28, 2023
…nBSD/the illumos gate)

Tested on Linux, FreeBSD, and OpenBSD
(NetBSD rustc too old, bzip2-sys too old to understand tribblix correctly)

Closes: #157
Closes: #158
@nabijaczleweli nabijaczleweli mentioned this pull request Jun 2, 2024
@nabijaczleweli

Copy link
Copy Markdown
Collaborator

Released in v2.0.0.

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.

2 participants