From 72473c411b0091ef0c435d411c4d41c9f52c5609 Mon Sep 17 00:00:00 2001 From: Warren Toomey Date: Thu, 3 Mar 2016 14:15:35 +1000 Subject: [PATCH] I've written some code for the sys status syscall in a7out but I've not tested it yet. --- tools/a7out | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/tools/a7out b/tools/a7out index 9c769e5..9412614 100755 --- a/tools/a7out +++ b/tools/a7out @@ -551,7 +551,7 @@ sub cal { # 22 badcal # 23 capt # 24 rele - # 25 status + 25 => \&sys_status, # 26 badcal 27 => \&sys_smes, 28 => \&sys_rmes, @@ -946,6 +946,61 @@ sub sys_time { return; } +# Status system call +sub sys_status { + # This seems to called as follows: + # law statbuf + # sys status; scrname; dd + # but I can't tell if PC+1 or PC+2 holds the filename pointer. + # For now, I'll use PC+1. $AC seems to hold the pointer to the statbuf + # which, as far as we can tell is: + # word 0: permission bits + # words 1-7: disk block pointers + # word 8: user-id + # word 9: number of links + # word 10: size in words + # word 11: uniq, I have no idea what this is. + # The permission bits are: + # 200000 large file, bigger than 4096 words + # 000020 directory + # 000010 owner read + # 000004 owner write + # 000002 user write + # 000001 user write + + # Get the start address of the string + # Convert this to a sensible ASCII filename + my $start = $Mem[ $PC + 1 ]; + my $filename = mem2arg($start); + dprintf( "status file %s statbuf %06o\n", $filename, $AC ); + + # Get the file's details + my (undef,undef,$mode,$nlink,$uid,undef,undef,$size)= stat($filename); + + # Set up the statbuf if we got a result + if ($nlink) { + $Mem[ $AC+8 ]= $uid & MAXINT; + $Mem[ $AC+9 ]= $nlink & MAXINT; + $Mem[ $AC+10 ]= $size & MAXINT; # Yes, I know, not words + + my $perms=0; + $perms= 01 if ($mode & 02); # World writable + $perms|= 02 if ($mode & 04); # World readable + $perms|= 04 if ($mode & 0200); # Owner writable + $perms|= 010 if ($mode & 0400); # Owner readable + $perms|= 020 if ( -d $filename); # Directory + $perms|= 0200000 if ($size > 4096); # Large file + $Mem[ $AC ] = $perms; + # Set AC to zero as we got something, else return -1 + $AC= 0; + } else { + $AC= MAXINT; + } + + $PC += 3; + return; +} + # Convert an 18-bit word into two ASCII characters and return them. # Don't return NUL characters sub word2ascii {