Gentoo Archives: gentoo-user

From: David Haller <gentoo@×××××××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Testing a used hard drive to make SURE it is good.
Date: Tue, 16 Jun 2020 01:02:21
Message-Id: 20200615231836.xje3kkkihsxrvhaz@grusum.endjinn.de
In Reply to: [gentoo-user] Testing a used hard drive to make SURE it is good. by Dale
1 Hello,
2
3 On Mon, 15 Jun 2020, Dale wrote:
4 [..]
5 >While I'm at it, when running dd, I have zero and random in /dev.  Where
6 >does a person obtain a one?  In other words, I can write all zeros, I
7 >can write all random but I can't write all ones since it isn't in /dev. 
8 >Does that even exist?  Can I create it myself somehow?  Can I download
9 >it or install it somehow?  I been curious about that for a good long
10 >while now.  I just never remember to ask. 
11
12 I've wondered that too. So I just hacked one up just now.
13
14 ==== ones.c ====
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include <stdio.h>
18 static unsigned int buf[BUFSIZ];
19 int main(void) {
20 unsigned int i;
21 for(i = 0; i < BUFSIZ; i++) { buf[i] = (unsigned int)-1; }
22 while( write(STDOUT_FILENO, buf, sizeof(buf)) );
23 exit(0);
24 }
25 ====
26
27 Compile with:
28 gcc $CFLAGS -o ones ones.c
29 or
30 gcc $(portageq envvar CFLAGS) -o ones ones.c
31
32 and use/test e.g. like
33
34 ./ones | dd of=/dev/null bs=8M count=1000 iflag=fullblock
35
36 Here, it's about as fast as
37
38 cat /dev/zero | dd of=/dev/null bs=8M count=1000 iflag=fullblock
39
40 (but only about ~25% as fast as
41 dd if=/dev/zero of=/dev/null bs=8M count=1000 iflag=fullblock
42 for whatever reason ever, but the implementation of /dev/zero is
43 non-trivial ...)
44
45 HTH,
46 -dnh
47
48 --
49 Computers make very fast, very accurate mistakes.

Replies