Hello,

On Mon, 15 Jun 2020, Dale wrote:
[..]
>While I'm at it, when running dd, I have zero and random in /dev.  Where
>does a person obtain a one?  In other words, I can write all zeros, I
>can write all random but I can't write all ones since it isn't in /dev. 
>Does that even exist?  Can I create it myself somehow?  Can I download
>it or install it somehow?  I been curious about that for a good long
>while now.  I just never remember to ask. 

I've wondered that too. So I just hacked one up just now.

==== ones.c ====
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
static unsigned int buf[BUFSIZ];
int main(void) {
    unsigned int i;
    for(i = 0; i < BUFSIZ; i++) { buf[i] = (unsigned int)-1; }
    while( write(STDOUT_FILENO, buf, sizeof(buf)) );
    exit(0);
}
====

Compile with:
    gcc $CFLAGS -o ones ones.c
or
    gcc $(portageq envvar CFLAGS) -o ones ones.c

and use/test e.g. like

    ./ones | dd of=/dev/null bs=8M count=1000 iflag=fullblock

Here, it's about as fast as

    cat /dev/zero | dd of=/dev/null bs=8M count=1000 iflag=fullblock

(but only about ~25% as fast as 
    dd if=/dev/zero of=/dev/null bs=8M count=1000 iflag=fullblock
for whatever reason ever, but the implementation of /dev/zero is
non-trivial ...)

HTH,
-dnh

-- 
Computers make very fast, very accurate mistakes.

Reply via email to