summaryrefslogtreecommitdiff
path: root/shell/bin/stat.php
diff options
context:
space:
mode:
Diffstat (limited to 'shell/bin/stat.php')
-rw-r--r--shell/bin/stat.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/shell/bin/stat.php b/shell/bin/stat.php
new file mode 100644
index 0000000..2a13743
--- /dev/null
+++ b/shell/bin/stat.php
@@ -0,0 +1,67 @@
+ <?php
+ function perms($perms) {
+ if (($perms & 0xC000) == 0xC000) {
+ $info = 's'; // Socket
+ } elseif (($perms & 0xA000) == 0xA000) {
+ $info = 'l'; // Symbolic Link
+ } elseif (($perms & 0x8000) == 0x8000) {
+ $info = '-'; // Regular
+ } elseif (($perms & 0x6000) == 0x6000) {
+ $info = 'b'; // Block special
+ } elseif (($perms & 0x4000) == 0x4000) {
+ $info = 'd'; // Directory
+ } elseif (($perms & 0x2000) == 0x2000) {
+ $info = 'c'; // Character special
+ } elseif (($perms & 0x1000) == 0x1000) {
+ $info = 'p'; // FIFO pipe
+ } else {
+ $info = 'u'; // Unknown
+ }
+
+ // Owner
+ $info .= (($perms & 0x0100) ? 'r' : '-');
+ $info .= (($perms & 0x0080) ? 'w' : '-');
+ $info .= (($perms & 0x0040) ?
+ (($perms & 0x0800) ? 's' : 'x' ) :
+ (($perms & 0x0800) ? 'S' : '-'));
+
+ // Group
+ $info .= (($perms & 0x0020) ? 'r' : '-');
+ $info .= (($perms & 0x0010) ? 'w' : '-');
+ $info .= (($perms & 0x0008) ?
+ (($perms & 0x0400) ? 's' : 'x' ) :
+ (($perms & 0x0400) ? 'S' : '-'));
+
+ // World
+ $info .= (($perms & 0x0004) ? 'r' : '-');
+ $info .= (($perms & 0x0002) ? 'w' : '-');
+ $info .= (($perms & 0x0001) ?
+ (($perms & 0x0200) ? 't' : 'x' ) :
+ (($perms & 0x0200) ? 'T' : '-'));
+
+ return '('.substr(sprintf('%o',$perms),-4).'/'.$info.')';
+}
+
+function main($args) {
+ $me = array_shift($args);
+ $ret = 0;
+ foreach ($args as $file) {
+ $data = stat($file);
+ if ($data === false) {
+ echo $me.': cannot stat file: `'.$file."'\n";
+ $ret++;
+ } else {
+ echo ' File: `'.$file."'\n";
+ echo ' Size: '.$data['size']."\t";
+ echo 'Blocks: '.$data['blocks']."\t";
+ //echo 'IO Block: ';
+ echo $data['rdev']."\n";
+ echo 'Device: '.$data['dev']."\t";
+ echo 'Inode: '.$data['ino']."\t";
+ echo 'Links: '.$data['nlink']."\n";
+ echo 'Access: '.perms($data['mode'])."\t";
+ echo "\n";
+ }
+ }
+ return $ret;
+} \ No newline at end of file