4 ms·
I don't read it that way. He calls out that 'weird' command specifically. But indeed he doesn't specify. I wonder what cat does in terms of buffers, I kinda do
by GekkePrutser 4y ago
I don't read it that way. He calls out that 'weird' command specifically. But indeed he doesn't specify.
I wonder what cat does in terms of buffers, I kinda doubt it has any special optimisations though I would guess the shell redirect might have. As that's really the thing doing the work there, not cat. Edit: Nope, I'm wrong there!!
Also that command does more than just specify the memory buffer like he says. That's my point, it's useful for tuning which can be super helpful with huge images.
It can also lead to some dangerous gotchas as well when working with files. But with full disk images these don't apply generally.
- LukeShu 4y ago> though I would guess the shell redirect might have. As that's really the thing doing the work there, not cat. No? The shell redirection is just int tmp_fd = open("/dev/sdb", O_WRONLY|O_TRUNC, 0666); dup2(tmp_fd, STDOUT_FILENO); close(tmp_fd); (plus error handling and whatnot) `cat` ends up with a file descriptor directly to the block device, same as `dd` does; the only difference is whether the `open()` call comes before or after the `execve()` call.
- GekkePrutser 4y agoAh ok good point! I stand corrected. I really doubt cat is smart enough to figure out a suitable block size though. At least with dd you can specify one.
- bhaney 4y ago> I really doubt cat is smart enough to figure out a suitable block size though It seems to try, at least https://github.com/coreutils/coreutils/blob/master/src/cat.c#L648-L649 https://github.com/coreutils/coreutils/blob/master/src/cat.c...
- LukeShu 4y agoGoing through the historical versions (copying from my other comment): - >=9.1 (2022-04-15) : Use the `copy_file_range()` syscall and let the kernel figure it out - >=8.23 (2014-07-18) : max(128KiB, st_blksize(infile), st_blksize(outfile)) - >=8.17 (2012-05-10) : max(64KiB, st_blksize(infile), st_blksize(outfile)) - >=7.2 (2009-03-31) : max(32KiB, st_blksize(infile), st_blksize(outfile)) - at least as far back as 1996 : max(st_blksize(infile), st_blksize(outfile)) (In my psuedo-code, `st_blksize(fd)` is the `ST_BLKSIZE(buf)` of the result of `fstat(fd, buf)`.)