lkml.org 
[lkml]   [1998]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: /dev/one - why not /dev/repeat?
On Tue, Dec 22, 1998 at 09:58:53PM +0000, thunder7@xs4all.nl wrote:

> Are there advantages in having something like /dev/repeat?
>
> echo -n "echo this" > /dev/repeat
>
> cat /dev/repeat
> echo thisecho thisecho thisecho this
>
> echo "echo this now" > /dev/repeat
> cat /dev/repeat
> echo this now
> echo this now
> echo this now
> echo this now
>
> etc.
>
> Then everyone that needed some repeating pattern could just get that pattern.
> Would this be workable, or are there problems in multi-user setups?

There are problems in multi-process setups. Say I have one process
which wants to have /dev/repeat return 01010101. I have another
process which wants 00000000, and another which wants 11111111. The
first process writes 01010101 to /dev/repeat. The second writes
00000000. Then the first finally gets around to reading
/dev/repeat. Then the third process writes 11111111, and the second
process reads. Oops. :)

I could be wrong, but it seems that one of the primary uses of
/dev/zero are to mmap it and get copy-on-write pages. Adding different
device objects for different bit patterns doesn't seem too useful to
me.

If you want a particular repeated pattern, use a function like
memfill() from Lars Wirzenius's 'publib' library. If you don't want to
use publib, such a function is easy to write, provided you know the
length of your pattern.

In fact, here's his code:

/*
* memfill.c -- fill memory area with pattern
*
* Part of publib. See man page for more information
* "@(#)publib-strutil:$Id: memfill.c,v 1.2 1994/02/05 17:08:42 liw
Exp $"
*/

#include <assert.h>
#include <string.h>
#include "publib/strutil.h"


void *memfill(void *buf, size_t bufsize, const void *pat, size_t patsize) {
char *p;

assert(buf != NULL);
assert(bufsize > 0);
assert(pat != NULL);
assert(patsize > 0);
assert(!memoverlap(buf, bufsize, pat, patsize));

for (p = buf; bufsize > patsize; p += patsize, bufsize -= patsize)
memcpy(p, pat, patsize);
memcpy(p, pat, bufsize);
return buf;
}

That code snippet depends on memoverlap(), which is also defined in
that library.

This library is available at
ftp://ftp.cdrom.com/pub/linux/debian/dists/unstable/main/source/libs/publib_0.28.tar.gz.
(The version number is subject to change.)


--
-----BEGIN GEEK CODE BLOCK-----
GMD/CS/S d-(++) s: a? C++++ UL++++ P+>+++ L+++(++++) E- W-- N+ o>++ K w---
!O M-- V-- PS+(+++) PE+(+++) Y++ PGP+++ t+ 5++ X+@ R+++ tv++ b+ DI D--- G++
e++>+++++ h* r y?
-----END GEEK CODE BLOCK-----
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 13:46    [W:0.203 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site