* [9fans] union directories exploration
@ 2012-09-19 6:31 Bakul Shah
2012-09-19 6:47 ` cinap_lenrek
0 siblings, 1 reply; 3+ messages in thread
From: Bakul Shah @ 2012-09-19 6:31 UTC (permalink / raw)
To: 9fans
I think I understand plan9 union directories but find them
limiting for some uses. Consider
term% mkdir -p a1/b/c a1/b/d a2/b/c a2/b/e
term% touch a1/b1 a2/b2 a1/b/c1 a2/b/c2
term% du -a a1
0 a1/b1
0 a1/b/c
0 a1/b/d
0 a1/b/c1
0 a1/b
0 a1
term% du -a a2
0 a2/b/e
0 a2/b/c2
0 a2/b/c
0 a2/b
0 a2/b2
0 a2
term% bind -a a1 a2
term% du -a a2
0 a2/b/e
0 a2/b/c2
0 a2/b/c
0 a2/b2
0 a2/b1
0 a2/b
0 a2
[Note: redundant entries are deleted]
Notice that after the binding, b/d and b/c1 don't show up in
a2. This happens because b exists in both directories and
once a2/b is traversed, further search is limited to the
original a2/ tree. Even if you ls a2/b/c1, it will fail.
The behavior I want (making all the file in a1 and a2 visible
after binding, with preference to the "before" directory) can
be achieved by binding *every* in a1 directories that has a
correponding dir in a2, starting with the leaf directories and
moving up.
term% unmount a2
term% bind -a a1/b/c a2/b/c
term% bind -a a1/b a2/b
term% bind -a a1 a2
term% du -a a2
0 a2/b/e
0 a2/b/c
0 a2/b/d
0 a2/b2
0 a2/b1
0 a2/b/c2
0 a2/b/c1
0 a2/b
0 a2
[Note: redundant entries are deleted]
What I want to do idea is to overlay one tree on another.
This idea can be used to overlay a r/w tree on a readonly
source tree and do a build. Or even do a concurrent build for
different architectures. But there are hundreds of
directories in /sys so this can get quite unwieldy and a
walk(9) can become more of a shuffle or search. May be this
should be called a "labor" union!
Has anyone tried this and has a script for this? Is there a
better way to handle this (overlay one partial tree on another
to provie a different 'view')? Then there are issues with what
happens when directories are added or deleted. One almost
wants a `Watch' command that watches such changes and does the
right thing.
Since binds are only allowed on directories, deleting a file
foo in the "before" directory can make any file foo in the
"after" directory. I guess this is why *BSD unionfs has a
`whiteout' file type [this is analogous to a `blackhole' route
in a network forwarding table or a `blacklisted' email address
in a spam filter. How funny]
[Thinking about this makes me appreciate the complexity of
*BSD unionfs and why it has never been fully shaken out. May
be worth prototyping on plan9]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] union directories exploration
2012-09-19 6:31 [9fans] union directories exploration Bakul Shah
@ 2012-09-19 6:47 ` cinap_lenrek
2012-09-19 7:42 ` Bakul Shah
0 siblings, 1 reply; 3+ messages in thread
From: cinap_lenrek @ 2012-09-19 6:47 UTC (permalink / raw)
To: 9fans
this has been done before. i can't remember who wrote it
and i couldnt find it in the contrib index.
#!/bin/rc
fn get_dirs {
tmp = /tmp/$pid ^_dirs
echo -n > $tmp
for (f in `{du -nf $root_in | awk '{print $2}' })
ls -l $f | grep '^d' | awk '{print $10}' >> $tmp
dirs = `{sort $tmp}
rm $tmp
}
root_in=$1
root_out=$2
if(~ $3 '')
get_dirs;
if not
dirs = `{cat $3};
for(i in $dirs){
o=`{echo $i | awk '{gsub(ENVIRON["root_in"], ENVIRON["root_out"], $0); print}'}
echo bind -bc $i $o
}
theres also divergefs.
--
cinap
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] union directories exploration
2012-09-19 6:47 ` cinap_lenrek
@ 2012-09-19 7:42 ` Bakul Shah
0 siblings, 0 replies; 3+ messages in thread
From: Bakul Shah @ 2012-09-19 7:42 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
Thanks!
On Wed, 19 Sep 2012 08:47:33 +0200 cinap_lenrek@gmx.de wrote:
> this has been done before. i can't remember who wrote it
> and i couldnt find it in the contrib index.
>
> #!/bin/rc
>
> fn get_dirs {
> tmp = /tmp/$pid ^_dirs
> echo -n > $tmp
>
> for (f in `{du -nf $root_in | awk '{print $2}' })
> ls -l $f | grep '^d' | awk '{print $10}' >> $tmp
> dirs = `{sort $tmp}
> rm $tmp
> }
>
> root_in=$1
> root_out=$2
>
> if(~ $3 '')
> get_dirs;
> if not
> dirs = `{cat $3};
>
> for(i in $dirs){
> o=`{echo $i | awk '{gsub(ENVIRON["root_in"], ENVIRON["root_out"], $0);
> print}'}
> echo bind -bc $i $o
> }
>
>
> theres also divergefs.
>
> --
> cinap
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-19 7:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-19 6:31 [9fans] union directories exploration Bakul Shah
2012-09-19 6:47 ` cinap_lenrek
2012-09-19 7:42 ` Bakul Shah
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).