This commit is contained in:
Kelvin Sherlock 2015-08-13 14:05:19 -04:00
parent 1eaaf3c931
commit 1ec4fec015
9 changed files with 609 additions and 105 deletions

15
fst.equ
View File

@ -10,7 +10,6 @@ my_fcr ds.l 1
call_class ds.w 1
device ds.w 1 ; device for id_disk.
tool_error ds.w 1
@ -19,12 +18,12 @@ inode ds.w 1
parent_inode ds.w 1
disk_inode ds v1_inode
;super ds v1_super
IF *>=$d4 THEN
AERROR 'dp -- too large.'
ENDIF
endr
endr
fcr record 0
@ -40,15 +39,19 @@ access ds.w 1
; fst-specific items
ino ds.w 1
inode ds.w 1
disk_inode ds v1_inode
dirty ds.w 1
mark ds.l 1 ; current position
; dirent stuff.
dirent ds.w 1 ; current directory entry.
dirent_zone ds.w 1 ; current directory zone [0-6]
dirent_offset ds.w 1 ; current directory offset
sizeof equ *
__sizeof equ *
endr
vcr record 0
@ -70,7 +73,7 @@ first_inode_block ds.w 1
first_imap_block ds.w 1
first_zmap_block ds.w 1
sizeof equ *
__sizeof equ *
endr

308
get_dir_entry.aii Normal file
View File

@ -0,0 +1,308 @@
include 'gsos.equ'
include 'minix.equ'
include 'fst.equ'
include 'fst.macros'
include 'M16.Debug'
include 'records.equ'
gde_dp record dp
displacement ds.w 1
count ds.w 1
dirent_size ds.w 1
IF *>=$d4 THEN
AERROR 'dp -- too large.'
ENDIF
endr
endr
get_dir_entry procname export
with fst_parms
with dp
with gde_dp
ldx <fcr_ptr
ldy <fcr_ptr+2
jsl deref
stx <my_fcr
sty <my_fcr+2
; check for read-access
ldy #fcr.access
lda [<my_fcr],y
and #read_access
bne access_ok
lda #invalid_access
sec
rtl
access_ok
; is it a dir?
ldy #fcr.disk_inode.mode
lda [my_fcr],y
and #S_IFMT
cmp #S_IFDIR
beq dir
lda #bad_store_type
sec
rtl
dir
jsr init
jst get_base_displace
bcc @ok
rtl
@ok
; hooray! it's a directory.
; boo! we have to do all this work!
; now need to handle the base/displacement
; base 0 - use displacement
; base 1 - use current position + displacement
; base 2 - use current position - displacement
; 0/0 resets the current displacement to 0 and
; returns the total number of entries in the entryNum
endp
init proc
with fst_parms,dp,gde_dp
lda device
sta dev_parms.dev_num
lda #1024
sta dev_parms.dev_blk_size
sta dev_parms.req_cnt
lda #v1_dirent.sizeof
sta dirent_size
; / 2
lsr disk_inode.size+2
ror disk_inode.size
; / 4
lsr disk_inode.size+2
ror disk_inode.size
; / 8
lsr disk_inode.size+2
ror disk_inode.size
; / 16
lsr disk_inode.size+2
ror disk_inode.size
lda super.magic
cmp #v1L.MAGIC
bne minix
; this is
linux
; linux dirents are twice as big.
asl dirent_size
; / 32
lsr disk_inode.size+2
ror disk_inode.size
minix
rts
endp
get_base_displace proc
; offset is $04 for class 0, $06 for class 1
with fst_parms, dp
with gde_dp
lda #$04
clc
adc <call_class
tay
lda [param_blk_ptr],y ; base
cmp #3
bcs perr
asl a
tax
iny
iny
lda [param_blk_ptr],y ; displacement
sta displacement
jmp (base_table,x)
perr
lda #parm_range_err
sec
rts
base_table
dc.w absolute, forward, backward
absolute
; absolute with a displacement of 0 -> return total count.
;
cmp #0
beq @count
jmp get_indexed_entry
@count
jmp count_entries
forward
jmp get_next_entry
;
backward
; backward 0 ? == forward 0
cmp #0
beq forward
eor #$ffff
sec ; inc / clc
ldy #fcr.dirent
adc [my_fcr],y
sta displacement
jmp get_indexed_entry
endp
get_indexed_entry proc
; get the displacement entry.
lda displacement
beq eod
bmi eod
bra ok
eod
lda #end_of_dir
sec
rts
ok
; if displacement is >= current dirent, use next dirent code.
ldy #fcr.dirent
cmp [my_fcr],y
bcc hard
sec
sbc [my_fcr],y
sta displacement
jmp get_next_entry
hard
; go through all directory entries until we find the one we want.
ldx #0 ; zone.
clc
rts
endp
count_entries proc
; count the number of entries.
with fst_parms
with dp, gde_dp
; read each block and count the entries.
; only handles direct blocks. so there.
; disk inode has been copied to the dp.
ldx #0
zone_loop
lda disk_inode,x
beq done ; directory should not be sparse!
phx ; save
jsr read_data_block
plx ; and restore
bcs exit
jsr count_dirent_block
lda dirent_count
beq done
inx
cpx #v1.NR_DZONES
bcs done
bra zone_loop
;
; minix has 16-byte dirents.
; linux has 32-byte dirents.
done
; also reset the displacement to 0.
lda #0
ldy #fcr.dirent
sta [my_fcr],y
ldy #fcr.dirent_zone
sta [my_fcr],y
ldy #fcr.dirent_offset
sta [my_fcr],y
clc
exit
rts
endp
count_dirent_block proc
; 16-byte dirent entries -- 64 per block.
with dp
ldy #0
loop
lda [io_buffer],y
beq next
inc count
next
; not 32-bit safe.
dec disk_inode.size
beq done
tya
clc
adc dirent_size
tay
cmp #1024
bcc loop
done
rts
endp
end

View File

@ -13,6 +13,8 @@
entry path_to_inode
entry load_inode
import id_disk
import device_read
@ -25,80 +27,16 @@ get_file_info procname export
jsr path_to_inode
bcc @inode
rtl
@inode
; we have an inode. and my_vcr is valid.
; we need to actually _load_ the inode.
bcs exit
jsr load_inode
bcs exit
; todo -- check if inode # is valid?
; todo -- check if bit set in imap?
;~DebugSetTrace #1
;pla ; prev value
ldy #vcr.first_inode_block
lda [my_vcr],y
asl a ; x 2
sta dev_blk_num
; 32 inodes per block.
; however, I'd rather read half-block chunks, with means
; 16 inodes per half-block.
lda inode
dec a ; inode 1 is offset 0.
lsr a ; / 2
lsr a ; / 4
lsr a ; / 8
lsr a ; / 16
;lsr a ; / 32
clc
adc dev_blk_num
sta dev_blk_num
lda #512
sta dev_req_cnt
lda device
sta dev_num
jsr device_read
bcc ok
rtl
ok
; find the inode...
lda inode
dec a ; inode 1 is offset 0.
and #$0f
; multiply by 32
asl a ; x 2
asl a ; x 4
asl a ; x 8
asl a ; x 16
asl a ; x 32
clc
adc io_buffer
sta ptr
lda #0
adc io_buffer+2
sta ptr+2
; copy to dp
ldy #v1_inode.sizeof-2
ldx #v1_inode.sizeof-2
@loop
lda [ptr],y
sta disk_inode,x
dey
dey
dex
dex
bpl @loop
;pha ; space
;~DebugSetTrace #0
@ -126,6 +64,8 @@ class0
cmp #0
rtl
exit
rtl
import do_ignore
import do_access
@ -173,8 +113,97 @@ do_access proc
load_inode proc export
;
; loads inode into disk_inode.
;
; inputs :
; my_vcr
; inode
; device
;
; outputs :
; disk_inode
; error in a/c
path_to_inode proc
; todo -- check if inode # is valid?
; todo -- check if bit set in imap?
with fst_parms
with dev_parms
with dp
ldy #vcr.first_inode_block
lda [my_vcr],y
asl a ; x 2
sta dev_blk_num
; 32 inodes per block.
; however, I'd rather read half-block chunks, with means
; 16 inodes per half-block.
lda inode
dec a ; inode 1 is offset 0.
lsr a ; / 2
lsr a ; / 4
lsr a ; / 8
lsr a ; / 16
;lsr a ; / 32
clc
adc dev_blk_num
sta dev_blk_num
lda #512
sta dev_req_cnt
lda device
sta dev_num
jsr device_read
bcc ok
rtl
ok
; find the inode...
lda inode
dec a ; inode 1 is offset 0.
and #$0f
; multiply by 32
asl a ; x 2
asl a ; x 4
asl a ; x 8
asl a ; x 16
asl a ; x 32
clc
adc #v1_inode.__sizeof-2
tay
;adc io_buffer
;sta ptr
;lda #0
;adc io_buffer+2
;sta ptr+2
; copy to dp
ldx #v1_inode.__sizeof-2
@loop
lda [io_buffer],y
sta disk_inode,x
dey
dey
dex
dex
bpl @loop
lda #0
clc
rts
endp
path_to_inode proc export
with dp,fst_parms

View File

@ -201,6 +201,7 @@ write_enabled equ $0002 ;1=Write Enabled
backup_enabled equ $0020 ;1=Needs to be backed up
rename_enabled equ $0040 ;1=Rename allowed
destroy_enabled equ $0080 ;1=Destroy is enabled
read_access equ $01
write_access equ $02
invis_bit equ $04

View File

@ -165,7 +165,7 @@ dump_vcr
; drop through.
create_vcr
lda #vcr.sizeof
lda #vcr.__sizeof
ldx #default_name
ldy #^default_name
jsl alloc_vcr
@ -199,7 +199,7 @@ create_vcr
adc my_vcr+2
sta ptr+2
ldy #v1_super.sizeof-2
ldy #v1_super.__sizeof-2
@loop
lda [dev_parms.dev_buff],y
sta [ptr],y
@ -235,7 +235,7 @@ create_vcr
sta [my_vcr],y
~DebugHexDump <my_vcr,#vcr.sizeof
~DebugHexDump <my_vcr,#vcr.__sizeof
lda #0
clc

View File

@ -198,6 +198,14 @@ app_entry procname
sta io_buffer+2
sta dev_parms.dev_buff+2
stz dev_parms.dev_num
stz dev_parms.dev_callnum
stz dev_parms.dev_req_cnt
stz dev_parms.dev_req_cnt+2
stz dev_parms.dev_blk_num
stz dev_parms.dev_blk_num+2
stz dev_parms.dev_blk_size
stz dev_parms.dev_blk_size+2
stz <tool_error
stz <device
@ -283,6 +291,55 @@ max_app_call equ *-@app_table-2
endp
init_fcr proc export
; deref the fcr and copy over inode, disk_inode
with fst_parms, dp
ldx fcr_ptr
ldy fcr_ptr+2
jsl deref
stx my_fcr
sty my_fcr+2
ldy #fcr.inode
lda [my_fcr],y
sta inode
;ldy #fcr.disk_inode + v1_inode.sizeof - 2
ldy #fcr.disk_inode.__end-2
ldx #v1_inode.__sizeof-2
@loop
lda [my_fcr],y
sta disk_inode,x
dey
dey
dex
dex
bpl @loop
clc
rts
endp
init_vcr proc export
; deref the vcr
with fst_parms, dp
ldx vcr_ptr
ldy vcr_ptr+2
jsl deref
stx my_vcr
sty my_vcr+2
ldy #vcr.device
lda [my_vcr]
sta device ; should probably just store in the dev_num.
sta dev_parms.dev_num
clc
rts
endp
end

View File

@ -24,6 +24,7 @@ NR_TZONES equ 9 ; 9 total zones
v1_super record 0
__begin equ *
ninodes ds.w 1
nzones ds.w 1
@ -33,11 +34,15 @@ firstdatazone ds.w 1
log_zone_size ds.w 1
max_size ds.l 1
magic ds.w 1
sizeof equ *
__end equ *
__sizeof equ __end - __begin
endr
v1_inode record 0
__begin equ *
mode ds.w 1
uid ds.w 1
@ -46,14 +51,19 @@ mtime ds.l 1
gid ds.b 1
nlinks ds.b 1
zone ds.w v1.NR_TZONES
sizeof equ *
__end equ *
__sizeof equ __end - __begin
endr
v1_dirent record 0
__begin equ *
inode ds.w 1
name ds.b v1.DIRSIZE
sizeof equ *
__end equ *
__sizeof equ __end - __begin
endr
@ -65,7 +75,16 @@ DIRSIZE equ 30
endr
v1L_dirent record 0
__begin equ *
inode ds.w 1
name ds.b v1L.DIRSIZE
__end equ *
__sizeof equ __end - __begin
endr
; version 2
v2 record 0
@ -79,6 +98,7 @@ DIRSIZE equ 14
endr
v2_super record 0
__begin equ *
inodes ds.w 1
nzones ds.w 1
@ -91,11 +111,16 @@ magic ds.w 1
ds.w 1 ; padding
zones ds.l 1
sizeof equ *
__end equ *
__sizeof equ __end - __begin
endr
v2_inode record 0
__begin equ *
mode ds.w 1
nlinks ds.w 1
uid ds.w 1
@ -105,14 +130,22 @@ atime ds.l 1
mtime ds.l 1
ctime ds.l 1
zone ds.l v2.NR_TZONES
sizeof equ *
__end equ *
__sizeof equ __end - __begin
endr
v2_dirent record 0
__begin equ *
inode ds.w 1
name ds.b v2.DIRSIZE
sizeof equ *
__end equ *
__sizeof equ __end - __begin
endr

View File

@ -29,6 +29,9 @@
entry check_access
entry build_fcr
import path_to_inode
import load_inode
open procname export
with fst_parms
@ -37,6 +40,13 @@ open procname export
; find the inode...
jsr path_to_inode
bcs exit
jsr load_inode
bcs exit
; sanity check the parameters.
jsr check_resource
bcs exit
@ -106,9 +116,9 @@ build_fcr proc
with dp
; build filename string...
lda #fcr.sizeof
ldx #0
ldy #0
lda #fcr.__sizeof
ldx #minix_str
ldy #^minix_str
jsl alloc_fcr
bcc @ok
lda #out_of_mem
@ -139,7 +149,7 @@ build_fcr proc
sta [my_fcr],y
lda inode
ldy #fcr.ino
ldy #fcr.inode
sta [my_fcr],y
lda #0
@ -152,10 +162,12 @@ build_fcr proc
iny
sta [my_fcr],y
; memory is 0-filled.
; copy the disk inode
ldx #disk_inode.sizeof-2
ldy #fcr.disk_inode + fcr.disk_inode.sizeof - 2 ; is sizeof updated?
ldx #v1_inode.__sizeof - 2
ldy #fcr.disk_inode.__end - 2
@loop
lda disk_inode,x
@ -168,6 +180,9 @@ build_fcr proc
clc
rts
minix_str str.w ':minix'
endp

View File

@ -1,8 +1,26 @@
;
; n.b. -- __sizeof only works for the record. It does not
; work when actually instantiated. MPW sucks for some reason.
; perhaps it blindly adds the current * to all relative equates....
;
macro
&n begin_struct
&n record 0
__begin equ *
mend
macro
&n end_struct
&n
__end equ *
__sizeof equ __end - __begin
endr
mend
TimeRec RECORD 0
TimeRec begin_struct
second DS.B 1
minute DS.B 1
hour DS.B 1
@ -11,9 +29,49 @@ day DS.B 1
month DS.B 1
extra DS.B 1
weekDay DS.B 1
ENDR
end_struct
FileInfoRecGS RECORD 0
DirEntryRecGS begin_struct
pCount DS.W 1
refNum DS.W 1
flags DS.W 1
base DS.W 1
displacement DS.W 1
name DS.L 1
entryNum DS.W 1
fileType DS.W 1
eof DS.L 1
blockCount DS.L 1
createDateTime DS TimeRec
modDateTime DS TimeRec
access DS.W 1
auxType DS.L 1
fileSysID DS.W 1
optionList DS.L 1
resourceEOF DS.L 1
resourceBlocks DS.L 1
end_struct
DirEntryRec begin_struct
refNum DS.B 2
flags DS.B 2
base DS.B 2
displacement DS.B 2
nameBuffer DS.B 4
entryNum DS.B 2
fileType DS.B 2
endOfFile DS.B 4
blockCount DS.B 4
createTime DS TimeRec
modTime DS TimeRec
access DS.B 2
auxType DS.B 4
fileSysID DS.B 2
end_struct
FileInfoRecGS begin_struct
pCount DS.W 1
pathname DS.L 1
access DS.W 1
@ -27,10 +85,10 @@ eof DS.L 1
blocksUsed DS.L 1
resourceEOF DS.L 1
resourceBlocks DS.L 1
ENDR
end_struct
FileRec RECORD 0
FileRec begin_struct
pathname DS.B 4
fAccess DS.B 2
fileType DS.B 2
@ -41,9 +99,9 @@ createTime DS.B 2
modDate DS.B 2
modTime DS.B 2
blocksUsed DS.B 4
ENDR
end_struct
OpenRecGS RECORD 0
OpenRecGS begin_struct
pCount DS.W 1
refNum DS.W 1
pathname DS.L 1
@ -60,16 +118,16 @@ eof DS.L 1
blocksUsed DS.L 1
resourceEOF DS.L 1
resourceBlocks DS.L 1
ENDR
end_struct
OpenRec RECORD 0
OpenRec begin_struct
openRefNum DS.B 2
openPathname DS.B 4
ioBuffer DS.B 4
ENDR
end_struct
VolumeRecGS RECORD 0
VolumeRecGS begin_struct
pCount DS.W 1
devName DS.L 1
volName DS.L 1
@ -80,14 +138,14 @@ blockSize DS.W 1
characteristics ds.w 1
deviceID ds.w 1
sizeof equ *
ENDR
end_struct
VolumeRec RECORD 0
VolumeRec begin_struct
deviceName DS.B 4
volName DS.B 4
totalBlocks DS.B 4
freeBlocks DS.B 4
fileSysID DS.B 2
sizeof equ *
ENDR
end_struct