Revision 24:11685cf6d7a1, 0.8 kB
(checked in by Anant Narayanan <anant@kix.in>, 1 month ago)
|
Implement getMode and getTime for IxpStat?, small example.
|
|
Line | |
---|
1 |
<?php |
---|
2 |
|
---|
3 |
function usage() |
---|
4 |
{ |
---|
5 |
echo "usage: php ixpc.php <address> {read | ls} <file>\n"; |
---|
6 |
exit; |
---|
7 |
} |
---|
8 |
|
---|
9 |
function ls($client, $addr, $file) |
---|
10 |
{ |
---|
11 |
$stats = $client->statDir($file); |
---|
12 |
$names = array(); |
---|
13 |
|
---|
14 |
foreach ($stats as $stat) { |
---|
15 |
$mode = $stat->getMode(); |
---|
16 |
$time = $stat->getTime(); |
---|
17 |
$names[$stat->name] = $mode."\t".$stat->uid."\t".$stat->gid."\t".$time; |
---|
18 |
} |
---|
19 |
ksort($names); |
---|
20 |
foreach ($names as $name=>$det) |
---|
21 |
echo $det."\t".$name."\n"; |
---|
22 |
} |
---|
23 |
|
---|
24 |
function read($client, $addr, $file) |
---|
25 |
{ |
---|
26 |
$fid = $client->open($file); |
---|
27 |
while ($buf = $fid->read($fid->iounit)) |
---|
28 |
echo $buf; |
---|
29 |
} |
---|
30 |
|
---|
31 |
if (($argc != 4)) { |
---|
32 |
usage(); |
---|
33 |
} |
---|
34 |
|
---|
35 |
$client = new IxpClient($argv[1]); |
---|
36 |
|
---|
37 |
switch($argv[2]) { |
---|
38 |
case "read" : read($client, $argv[1], $argv[3]); break; |
---|
39 |
case "ls" : ls($client, $argv[1], $argv[3]); break; |
---|
40 |
default : usage(); |
---|
41 |
} |
---|
42 |
|
---|
43 |
$client->unmount(); |
---|
44 |
|
---|