1
0
mirror of https://github.com/DoctorWkt/unix-jun72.git synced 2026-02-12 19:17:50 +00:00
Files
DoctorWkt.unix-jun72/pages/e05-02
2008-05-02 17:50:21 +00:00

57 lines
1.8 KiB
Plaintext

mov r1,i.dskp(r2) / put block number of new block in i-node
jsr r0,setimod / set i-node modified byte
jsr r0,clear / clear new block
2:
jsr r0,dskrd / read in indirect block
mov (sp)+,r2 / get offset
mov r1,-(sp) / save block number of indirect block on stack
add r5,r2 / r5 points to first word in indirect block, r2
/ points to location of inter
mov (r2),r1 / put physical block no of block in file
/ sought in r1
bne 2f / if no block exists
jsr r0,alloc / allocate a new block
mov r1,(r2) / put new block number into proper location in
/ indirect block
mov (sp)+,r1 / get block number of indirect block
mov (r2),-(sp) / save block number of new block
jsr r0,wslot
jsr r0,dskwr / write newly modified indirect block back out
/ on disk
mov (sp),r1 / restore block number of new block
jsr r0,clear / clear new block
2:
tst (sp)+ / bump stack pointer
rts r0
alloc:
mov r2,-(sp) / save r2, r3 on stack
mov r3,-(sp)
mov $systm,r2 / start of inode and free storage map for drum
tst cdev
beq 1f / drum is device
mov $mount,r2 / disk or tape is device, start of inode and free
/ storage map
1:
mov (r2)+,r1 / first word contains number of bytes in free
/ storage map
asl r1 / multiply r1 by eight gives, number of blocks in device
asl r1
asl r1
mov r1,-(sp) / save # of blocks in device on stack
clr r1 / r1 contains bit count of free storage map
1:
mov (r2)+,r3 / word of free storage map in r3
bne 1f / branch if any free blocks in this word
add $16.,r1
cmp r1 ,(sp) / have we examined all free storage bytes
blo 1b
jmp panic / found no free storage
1:
asr r3 / find a free block
bcs 1f / branch when free block found; bit for block k is in
/ byte k/8 / in bit k (mod 8)
inc r1 / increment bit count in bit k (mod8)
br 1b
1: