Re: [LIP] doubt regarding /dev/zero

Sandip Bhattacharya <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Organization Puroga Technologies Pvt. LTd.
Message-ID <[email protected]>
On Sunday 04 July 2004 4:48 pm, Vardhman Jain wrote:
> Hi,
> 	I came accross following code for allocation swap memory.
> I am really confused about the /dev/zero /dev/null files now. I previously
> assumed that they are some kind of sink files but this example changes my
> thought can some one tell me about these files /dev/zero etc.

/dev/null is a bit-sink. You can write anything to it, and it will happily eat 
it up. If you read from it, you will immediately get EOF.

$ wc -c /dev/null
0 /dev/null

/dev/zero is supposed to be used for reading only. You can read endlessly from 
it and will never get an EOF. Every octet that it returns is the '\0' byte. 

$ dd if=/dev/zero of=dump bs=1 count=1
1+0 records in
1+0 records out
$ od -a dump
0000000 nul
0000001


>
> # dd if=/dev/zero of=/swap bs=1024 count=65535
> # mkswap /swap
> # swapon /swap
>

This is ok, it just returns enough null bytes to rewrite every octet of 
the /swap partition with '\0'. Using /dev/null would have been a mistake 
here, because dd wouldnt have been able to read anything from it. It would 
have immediately got an eof.

$ dd if=/dev/null of=dump bs=1 count=1
0+0 records in
0+0 records out




- Sandip

-- 
Sandip Bhattacharya
sandip (at) puroga.com
Puroga Technologies Pvt. Ltd.
Work: http://www.puroga.com        Home: http://www.sandipb.net

GPG: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.