Merge pull request #148 from philbudne/mkfs

two mkfs7 changes (.. and link to inum -1), make hard link for list program
This commit is contained in:
Phil Budne
2019-10-24 19:47:29 -04:00
committed by GitHub
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -61,11 +61,11 @@ dd drwr- -1 4
nsh frwr- -1 bin/nsh nsh frwr- -1 bin/nsh
nls frwr- -1 bin/nls nls frwr- -1 bin/nls
list l---- -1
# nbc frwr- -1 bin/nbc # nbc frwr- -1 bin/nbc
nstat frwr- -1 bin/nstat nstat frwr- -1 bin/nstat
$ $
ken drwr- 10 ken drwr- 10
system l---- 3 system l---- 3
+8 -1
View File
@@ -62,6 +62,7 @@ my $nextinum = 1; # i-num 0 is never used
my @Dirstack; # Stack of directories. Each value is a ref my @Dirstack; # Stack of directories. Each value is a ref
# to a [ blocknum, offset, inum ] array which # to a [ blocknum, offset, inum ] array which
# is the next free position in the directory # is the next free position in the directory
my $lastinum = -1; # last inum assigned, for link to i-num -1
# Debug printing # Debug printing
sub dprint { sub dprint {
@@ -277,6 +278,8 @@ sub add_block_to_inode {
sub add_direntry { sub add_direntry {
my ( $name, $inum ) = @_; my ( $name, $inum ) = @_;
$inum = $lastinum if ($inum == -1);
# Get the block and offset to the next empty slot in the directory # Get the block and offset to the next empty slot in the directory
my $dirref = $Dirstack[-1]; my $dirref = $Dirstack[-1];
@@ -320,6 +323,7 @@ sub add_direntry {
# Finally, increment the link count # Finally, increment the link count
increment_link_count($inum); increment_link_count($inum);
$lastinum = $inum;
} }
# Given a name, perms, a user-id and an optional i-node number, make a # Given a name, perms, a user-id and an optional i-node number, make a
@@ -360,8 +364,11 @@ sub make_dir {
if (!$no_dd) { if (!$no_dd) {
add_direntry( "dd", $Dirstack[0]->[2] ); add_direntry( "dd", $Dirstack[0]->[2] );
dprintf("Added a dd entry to i-num %d\n", $Dirstack[0]->[2] ); dprintf("Added a dd entry to i-num %d\n", $Dirstack[0]->[2] );
if (!$wantdotdot && !$wantdot) { # PLB 2019
add_direntry( "..", $inum );
dprint("Added a .. entry to ourselves\n");
}
} }
dprintf( "Made directory %s perms %06o uid %d in inum %d\n\n", dprintf( "Made directory %s perms %06o uid %d in inum %d\n\n",
$dirname, $perms, $uid, $inum ); $dirname, $perms, $uid, $inum );
} }