coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dd: what is iflag=directory for?


From: Pádraig Brady
Subject: Re: dd: what is iflag=directory for?
Date: Sat, 23 Aug 2014 02:00:54 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 08/23/2014 01:19 AM, Bernhard Voelker wrote:
> With iflag=directory ...
> 
>     `directory'
>           Fail unless the file is a directory.  Most operating systems
>           do not allow I/O to a directory, so this flag has limited
>           utility.
> 
> ... dd(1) would fail if the input file is _not_ a directory:
> 
>   $ src/dd iflag=directory if=src/dd
>   src/dd: failed to open ‘src/dd’: Not a directory
> 
> And on Linux, read(2)ing from a directory fails:
> 
>   src/dd iflag=directory if=. status=none
>   src/dd: error reading ‘.’: Is a directory

On Linux you can open(O_DIRECTORY):

  $ dd iflag=directory if=. count=0 status=none

> So my questions (forwarded from a downstream ML):
> 
> a) on which systems is read(2)ing from a directory supported?
> IIRC HP-UX?

On FreeBSD at least you can also _read_...

  $ mkdir test
  $ cd test
  $ touch a b

  $ dd if=. status=none | od -Ax -tx1z
  000000 0c dd 31 00 0c 00 04 01 2e 00 00 00 12 d9 17 00  >..1.............<
  000010 0c 00 04 02 2e 2e 00 00 0d dd 31 00 0c 00 08 01  >..........1.....<
  000020 61 00 14 c1 0e dd 31 00 dc 01 08 01 62 00 14 c1  >a.....1.....b...<
  000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
  *
  000200

Honestly I don't see the usefulness of a low level read() like this,
and I suppose it's file system dependent too, not working on NFS for example.
FreeBSD has higher level syscalls to read the fd just like Linux.

> b) when 'dd if=DIR' is successful, what would be the output?
> Is it useful to write it e.g. to 'of=DIR2'?

...but not write

  $ cd ..
  $ mkdir test2
  $ dd if=test of=test2
  dd: failed to open 'test2': Is a directory

Pádraig.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]