package main;
use strict;
use Plan9;
use Socket;
use IO::Handle; # for autoflush
use Data::Dumper;
my ($fs, $f, $f1, $s, $n, $d, @d);
#$ENV{NAMESPACE} = "/tmp/ns.$ENV{USER}.$ENV{DISPLAY}"
# unless defined $ENV{NAMESPACE};
#my $conn = "$ENV{NAMESPACE}/factotum";
#socket(S9, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
#connect(S9, sockaddr_un($conn)) or die "connect: $!";
#
# rm -f /srv/rrr && ramfs -DsS rrr
#
open(S9, "</srv/rrr") or die "open /srv/rrr: $!";
STDOUT->autoflush(1);
STDERR->autoflush(1);
# $::chatty9pclient = 1;
$fs = Plan9::fsmount(S9);
if(!defined $fs){
print STDERR "fsmount: $@\n";
exit 1;
}
$f = Plan9::fsopen($fs, ".", 0);
if(!defined $f){
print STDERR "open: $@\n";
}else{
@d = Plan9::fsdirreadall($f);
for(@d){
print "\t", $_->{name}, "\n";
}
Plan9::fsclose($f);
}
$f1 = Plan9::fscreate($fs, "x", 0, Plan9::DMDIR | 0775);
if(!defined $f1){
print STDERR "create: $@\n";
}
$f = Plan9::fscreate($fs, "x/yy", 2, 0664);
if(!defined $f){
print STDERR "create: $@\n";
}
Plan9::fswrite($f, "hello");
Plan9::fsprintf($f, ", %s!", 'world');
Plan9::fsclose($f);
Plan9::fsclose($f1);
%{$d} = %Plan9::syncdir;
$d->{name} = "y";
if(Plan9::fsdirwstat($fs, "x/yy", %$d) < 0){
print STDERR "wstat: $@\n";
}
$d = Plan9::fsdirstat($fs, "x/y");
if(!defined $d){
print STDERR "stat: $@\n";
}else{
print "stat ok: ", Plan9::dirstr(%$d), "\n";
}
$f = Plan9::fsopen($fs, "x/y", 0);
if(!defined $f){
print STDERR "open: $@\n";
}
print "read ok: ", Plan9::fsread($f, Plan9::fsiounit($f)), "\n";
Plan9::fsclose($f);
if(Plan9::fsremove($fs, "x/y") < 0){
print STDERR "remove: $@\n";
}
$f = Plan9::fscreate($fs, "x/z", 2, 0664);
if(!defined $f){
print STDERR "create: $@\n";
}
if(Plan9::fsfremove($f) < 0){
print STDERR "remove: $@\n";
}
if(Plan9::fsremove($fs, "x") < 0){
print STDERR "remove: $@\n";
}
$f = Plan9::fswalk($fs->{root});
if(!defined($f)){
print STDERR "walk: $@\n";
}
$d = Plan9::fsdirfstat($f);
if(!defined $d){
print STDERR "stat: $@\n";
}else{
print "stat ok: ", Plan9::dirstr(%$d), "\n";
}
Plan9::fsunmount($fs);
Plan9::fsclose($f);
|