I converted some of the ls code into routines. No change in functionality.
I updated a7out with better sys status handling.
This commit is contained in:
+56
-46
@@ -1,4 +1,4 @@
|
|||||||
" Warren's version of ls. ls [-l] [dirname]
|
" Warren's historic version of ls. ls [-l] [dirname]
|
||||||
"
|
"
|
||||||
" When -l is used, you see
|
" When -l is used, you see
|
||||||
"
|
"
|
||||||
@@ -39,9 +39,15 @@ setlong:
|
|||||||
dac 017777 i " Decrement the arg count and loop back
|
dac 017777 i " Decrement the arg count and loop back
|
||||||
jmp argloop
|
jmp argloop
|
||||||
|
|
||||||
|
" In the historic version of Unix-7, there was
|
||||||
|
" no way to open the current directory unless
|
||||||
|
" it had a name. One way around this is to create
|
||||||
|
" a named link. If you are in the ken directory,
|
||||||
|
" you can do: ln dd ken .
|
||||||
|
" to make a link called .
|
||||||
|
|
||||||
1:
|
1:
|
||||||
sys open; 9:curdir; 0 " Open up the directory, curdir if no arguments
|
sys open; 8:curdir; 0 " Open up the directory, curdir if no arguments
|
||||||
spa
|
spa
|
||||||
jmp error
|
jmp error
|
||||||
dac fd " Save the fd
|
dac fd " Save the fd
|
||||||
@@ -55,35 +61,52 @@ fileloop:
|
|||||||
jmp fileend " Result was zero, so nothing left to read
|
jmp fileend " Result was zero, so nothing left to read
|
||||||
|
|
||||||
dac count " Save the count of words read in
|
dac count " Save the count of words read in
|
||||||
lac ibufptr " Point bufptr at the base of the buffer
|
lac inameptr " Point nameptr at the base of the buffer
|
||||||
dac bufptr
|
dac nameptr
|
||||||
|
|
||||||
" Each directory entry is eight words. We need to print out
|
" Each dir entry is 8 words. We need to print out the
|
||||||
" the filename which is in words 2 to 5. Word 1 is the inum.
|
" filename which is in words 2 to 5. Word 1 is the inum.
|
||||||
entryloop:
|
entryloop:
|
||||||
lac bufptr i " Is the inode number zero?
|
lac nameptr i " Is the inode number zero?
|
||||||
sna
|
sna
|
||||||
jmp skipentry " Yes, skip this entry
|
jmp nextentry " Yes, move to the next directory entry
|
||||||
lac longopt " Are we printing out in long format?
|
|
||||||
sna
|
|
||||||
jmp 1f " No, don't print out the inode number
|
|
||||||
|
|
||||||
lac bufptr i " Print out the inode number as 5 digits
|
lac nameptr " Move up to the filename
|
||||||
jms octal; -5
|
tad d1
|
||||||
|
|
||||||
1: isz bufptr " Move up to the filename
|
|
||||||
lac longopt " Are we printing out in long format?
|
|
||||||
sna
|
|
||||||
jmp printname " No, jump to printname
|
|
||||||
|
|
||||||
lac bufptr
|
|
||||||
dac statfile " Copy the pointer to the status call
|
dac statfile " Copy the pointer to the status call
|
||||||
lac statbufptr " Get the file's details into the statbuf
|
lac statbufptr " Get the file's details into the statbuf
|
||||||
sys status; 8:curdir; statfile:0
|
sys status; 9:curdir; statfile:0
|
||||||
spa
|
spa
|
||||||
jms fileend
|
jms fileend " exit if the status call fails
|
||||||
|
|
||||||
|
lac longopt " Are we printing out in long format?
|
||||||
|
sza
|
||||||
|
jms printlong " Yes, print out the i-node details
|
||||||
|
lac statfile " Now print out the file's name
|
||||||
|
jms printname
|
||||||
|
|
||||||
|
nextentry:
|
||||||
|
lac nameptr " Add 8 to the nameptr to move up to the next one
|
||||||
|
tad d8
|
||||||
|
dac nameptr
|
||||||
|
-8
|
||||||
|
tad count " Decrement the count of words in the buffer by 8
|
||||||
|
dac count
|
||||||
|
sza " Anything left in the buffer to print?
|
||||||
|
jmp entryloop " Yes, stuff left to print
|
||||||
|
jmp fileloop " Nothing in the buffer, try reading some more
|
||||||
|
|
||||||
|
fileend:
|
||||||
|
lac fd " Close the open file descriptor and exit
|
||||||
|
sys close
|
||||||
|
sys exit
|
||||||
|
|
||||||
|
|
||||||
|
" Print out the i-node in long format
|
||||||
|
printlong: 0
|
||||||
" Ugly code. Improvements welcome!
|
" Ugly code. Improvements welcome!
|
||||||
|
lac s.inum " Print out the i-node number
|
||||||
|
jms octal; -5
|
||||||
lac s.perm " See if this is a directory
|
lac s.perm " See if this is a directory
|
||||||
and isdirmask
|
and isdirmask
|
||||||
sna
|
sna
|
||||||
@@ -153,33 +176,19 @@ entryloop:
|
|||||||
jms octal; -3
|
jms octal; -3
|
||||||
lac s.size " Print the size out
|
lac s.size " Print the size out
|
||||||
jms octal; -5
|
jms octal; -5
|
||||||
|
jmp printlong i
|
||||||
|
|
||||||
printname:
|
|
||||||
|
" Given a filename pointer in AC,
|
||||||
|
" print it out with a newline
|
||||||
|
printname: 0
|
||||||
|
dac 1f
|
||||||
lac fd1
|
lac fd1
|
||||||
sys write; bufptr:0; 4 " Write the filename out to stdout
|
sys write; 1:0; 4 " Write the filename out to stdout
|
||||||
lac fd1
|
lac fd1
|
||||||
sys write; newline; 1 " followed by a newline
|
sys write; newline; 1 " followed by a newline
|
||||||
|
jmp printname i
|
||||||
|
|
||||||
lac bufptr " Add 7 to the bufptr
|
|
||||||
tad d7
|
|
||||||
jmp nextentry
|
|
||||||
|
|
||||||
skipentry:
|
|
||||||
lac bufptr " Add 8 to the bufptr if we skipped this entry entirely
|
|
||||||
tad d8 " Or add 8 if we skipped this entry entirely
|
|
||||||
nextentry:
|
|
||||||
dac bufptr
|
|
||||||
-8
|
|
||||||
tad count " Decrement the count of words by 8
|
|
||||||
dac count
|
|
||||||
sza " Anything left in the buffer to print?
|
|
||||||
jmp entryloop " Yes, stuff left to print
|
|
||||||
jmp fileloop " Nothing in the buffer, try reading some more
|
|
||||||
|
|
||||||
fileend:
|
|
||||||
lac fd " Close the open file descriptor and exit
|
|
||||||
sys close
|
|
||||||
sys exit
|
|
||||||
|
|
||||||
" Octal print code: This code borrowed from ds.s
|
" Octal print code: This code borrowed from ds.s
|
||||||
octal: 0
|
octal: 0
|
||||||
@@ -212,7 +221,7 @@ octal: 0
|
|||||||
jmp octal i " and return from subroutine
|
jmp octal i " and return from subroutine
|
||||||
|
|
||||||
error:
|
error:
|
||||||
lac 9b
|
lac 8b
|
||||||
dac 1f
|
dac 1f
|
||||||
lac d1
|
lac d1
|
||||||
sys write; 1:0; 4 " Write out the bad dirname
|
sys write; 1:0; 4 " Write out the bad dirname
|
||||||
@@ -225,6 +234,7 @@ mes:
|
|||||||
|
|
||||||
longopt: 0 " User set the -l option when this is 1
|
longopt: 0 " User set the -l option when this is 1
|
||||||
argptr: 0 " Pointer to the next argument
|
argptr: 0 " Pointer to the next argument
|
||||||
|
nameptr: 0 " Pointer to files name
|
||||||
fd: 0 " File descriptor for the directory
|
fd: 0 " File descriptor for the directory
|
||||||
d1: fd1: 1 " File descriptor 1
|
d1: fd1: 1 " File descriptor 1
|
||||||
d4: 4
|
d4: 4
|
||||||
@@ -238,7 +248,7 @@ cbuf: 0 " Used to print out in the octal routing
|
|||||||
c: .=.+1 " Loop counter for printing octal digits
|
c: .=.+1 " Loop counter for printing octal digits
|
||||||
|
|
||||||
" Input buffer for read
|
" Input buffer for read
|
||||||
ibufptr: buf " Constant pointer to the buffer
|
inameptr: buf " Constant pointer to the buffer
|
||||||
buf: .=.+64 " Directory buffer
|
buf: .=.+64 " Directory buffer
|
||||||
statbufptr: statbuf " Pointer to the statbuf
|
statbufptr: statbuf " Pointer to the statbuf
|
||||||
statbuf: " Status buffer fields below
|
statbuf: " Status buffer fields below
|
||||||
|
|||||||
+13
-14
@@ -1176,18 +1176,17 @@ sub sys_time {
|
|||||||
# Status system call
|
# Status system call
|
||||||
sub sys_status {
|
sub sys_status {
|
||||||
|
|
||||||
# This seems to called as follows:
|
# AC holds the pointer to the stat buffer
|
||||||
# law statbuf
|
# PC+1 is the directory holding the entry
|
||||||
# sys status; scrname; dd
|
# PC+2 is the directory entry we want to stat.
|
||||||
# but I can't tell if PC+1 or PC+2 holds the filename pointer.
|
# The statbuf is:
|
||||||
# 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
|
# word 0: permission bits
|
||||||
# words 1-7: disk block pointers
|
# words 1-7: disk block pointers
|
||||||
# word 8: user-id
|
# word 8: user-id
|
||||||
# word 9: number of links
|
# word 9: number of links
|
||||||
# word 10: size in words
|
# word 10: size in words
|
||||||
# word 11: uniq, I have no idea what this is.
|
# word 11: uniq, I have no idea what this is.
|
||||||
|
# word 12: i-number.
|
||||||
# The permission bits are:
|
# The permission bits are:
|
||||||
# 200000 large file, bigger than 4096 words
|
# 200000 large file, bigger than 4096 words
|
||||||
# 000020 directory
|
# 000020 directory
|
||||||
@@ -1195,23 +1194,23 @@ sub sys_status {
|
|||||||
# 000004 owner write
|
# 000004 owner write
|
||||||
# 000002 user write
|
# 000002 user write
|
||||||
# 000001 user write
|
# 000001 user write
|
||||||
# XXX: We don't seem to have the i-node number in this structure?!
|
|
||||||
|
|
||||||
# Get the start address of the string
|
# Get the directory and file names
|
||||||
# Convert this to a sensible ASCII filename
|
# Convert this to a sensible ASCII filename
|
||||||
my $start = $Mem[ $PC + 1 ];
|
my $dirname = mem2arg($Mem[ $PC + 1 ]);
|
||||||
my $filename = mem2arg($start);
|
my $filename = mem2arg($Mem[ $PC + 2 ]);
|
||||||
dprintf( "status file %s statbuf %06o\n", $filename, $AC );
|
dprintf( "status file %s/%s statbuf %06o\n", $dirname, $filename, $AC );
|
||||||
|
|
||||||
# Get the file's details
|
# Get the file's details
|
||||||
my ( undef, undef, $mode, $nlink, $uid, undef, undef, $size ) =
|
my ( undef, $ino, $mode, $nlink, $uid, undef, undef, $size ) =
|
||||||
stat($filename);
|
stat("$dirname/$filename");
|
||||||
|
|
||||||
# Set up the statbuf if we got a result
|
# Set up the statbuf if we got a result
|
||||||
if ($nlink) {
|
if ($nlink) {
|
||||||
$Mem[ $AC + 8 ] = $uid & MAXINT;
|
$Mem[ $AC + 8 ] = $uid & MAXINT;
|
||||||
$Mem[ $AC + 9 ] = $nlink & MAXINT;
|
$Mem[ $AC + 9 ] = (-$nlink) & MAXINT;
|
||||||
$Mem[ $AC + 10 ] = $size & MAXINT; # Yes, I know, not words
|
$Mem[ $AC + 10 ] = $size & MAXINT; # Yes, I know, not words
|
||||||
|
$Mem[ $AC + 12 ] = $ino & MAXINT;
|
||||||
|
|
||||||
my $perms = 0;
|
my $perms = 0;
|
||||||
$perms = 01 if ( $mode & 02 ); # World writable
|
$perms = 01 if ( $mode & 02 ); # World writable
|
||||||
|
|||||||
Reference in New Issue
Block a user