A2osX/LIB/LIBCIFS.S.IO.txt

1195 lines
17 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
*--------------------------------------
CIFS.ChTyp
CIFS2.ChTyp
*--------------------------------------
CIFS.ChMod
CIFS2.ChMod
*--------------------------------------
CIFS.FStat
*--------------------------------------
CIFS2.FStat >DEBUG
lda #MLI.E.BADCALL
sec
rts
*--------------------------------------
CIFS.Stat >STYA pPath resolved path
jsr ClearSocket
jsr GetCTX
jsr RequestT2SetupX
ldx #0
.1 lda SMB.QueryPathInfo,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.QueryPathInfo.Len
bne .1
jsr ReqT2SetupPtr2
jsr AppendPathPtr2
jsr SetT2ReqLen
jsr WriteSocket
bcs .9
jmp Sleep
.9 >RET 4
*--------------------------------------
CIFS2.Stat jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
lda #MLI.E.INVPATH Return this for stat() match ProDOS Behavior
bcs .90
jsr GetRespDataPtr1
jsr FileInfo2StatBuf
>PULLW ZPPtr2 Stat Buffer
inc pStack Skip Filename
inc pStack
jsr StatBuf2Ptr2
jmp Exit.OK
.9 jsr Exit.NODATA
beq .99
.90 >POP 4
.99 rts
*--------------------------------------
CIFS.MKDir >STYA pPath resolved path
jsr ClearSocket
jsr GetCtx
jsr RequestT2SetupX
ldx #0
.1 lda SMB.CreateDirectory,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.CreateDirectory.Len
bne .1
jsr AppendPath
lda #0
sta (ZPReqPtr),y
iny
jsr SetT2ReqLenYA
jsr WriteSocket
bcs .9
jmp Sleep
.9 >RET 4
*--------------------------------------
CIFS2.MKDir jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .90
jmp Exit.OK
.9 jsr Exit.NODATA
beq .99
.90 >POP 4
.99 rts
*--------------------------------------
CIFS.OpenDir >STYA pPath resolved path
>LDYAI S.FD.DIR
>SYSCALL2 GetMem
bcs .9
>STYA ZPPtr2
lda #S.FD.T.DIR
sta (ZPPtr2)
lda hHandler
ldy #S.FD.PFT
sta (ZPPtr2),y
lda #0
ldy #S.FD.DIR.EPB
sta (ZPPtr2),y EOF Flag
iny
sta (ZPPtr2),y
iny
sta (ZPPtr2),y
>PUSHW pPath
>PUSHWI 0
txa
>PUSHA
>SYSCALL2 mknod
.9 rts
*--------------------------------------
CIFS2.OpenDir lda #MLI.E.BADCALL
sec
rts
*--------------------------------------
CIFS.ReadDir jsr GetPFD
jsr ClearSocket
jsr GetCtx
ldy #S.FD.DIR.EPB
lda (pFD),y
beq .1
lda #MLI.E.EOF
sec
rts
.1 iny
lda (pFD),y
iny
ora (pFD),y
bne CIFS.ReadDir.Next
jsr RequestT2SetupX
ldx #0
.2 lda SMB.FindFirst2,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.FindFirst2.Len
bne .2
bra CIFS.ReadDir.Send
CIFS.ReadDir.Next
jsr RequestT2SetupX
ldx #0
.2 lda SMB.FindNext2,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.FindNext2.Len
bne .2
phy
ldy #S.FD.DIR.FC+1
lda (pFD),y
tax
dey
lda (pFD),y
ldy #S.NETBIOS+S.SMB.H+SMB.Trans2.H.Len+7 Search ID
sta (ZPReqPtr),y
txa
iny
sta (ZPReqPtr),y
ply
CIFS.ReadDir.Send
lda (pPath)
beq .1
jsr AppendPath
lda #'\'
sta (ZPReqPtr),y
iny
.1 lda #'*'
sta (ZPReqPtr),y
iny
lda #0
sta (ZPReqPtr),y
iny
jsr SetT2ReqLenYA
jsr WriteSocket
bcs .9
jmp Sleep
.9 rts
*--------------------------------------
CIFS2.ReadDir jsr GetPFD
jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .90
ldy #S.FD.DIR.FC
lda (pFD),y
iny
ora (pFD),y
sta bFlag
bne .2
ldy #S.NETBIOS+S.SMB.H+S.TRANS2.H+1 Search ID
lda (ZPRespPtr),y
tax
dey
ora (ZPRespPtr),y
beq .90
lda (ZPRespPtr),y
ldy #S.FD.DIR.FC
sta (pFD),y
iny
txa
sta (pFD),y
.2 jsr GetRespDataPtr1
jsr CIFS2.ReadDir.GetBuf
bcs .99
jsr GetRespDataPtr1
jsr CIFS2.ReadDir.FillBuf
jsr Exit.OK
>LDYA BufPtr
ldx hBuf
clc
.90 rts
.9 jmp Exit.NODATA
.99 jmp Exit.KO
*--------------------------------------
CIFS2.ReadDir.GetBuf
ldy #S.NETBIOS+S.SMB.H+S.TRANS2.H Search Count
lda bFlag
bne .10
iny
iny
.10 iny
iny
lda (ZPRespPtr),y End Of Search
phy
ldy #S.FD.DIR.EPB
sta (pFD),y
ply
dey
dey
lda (ZPRespPtr),y Search Count
beq .99
tax
lda #1 +Ending 0
sta ZPPtr2
stz ZPPtr2+1
.1 lda ZPPtr2
clc
adc #S.STAT
sta ZPPtr2
bcc .2
inc ZPPtr2+1
.2 lda ZPPtr1
clc
adc #22
sta ZPPtr1
bcc .3
inc ZPPtr1+1
.3 lda (ZPPtr1) Filename Len
pha
sec
adc ZPPtr2
sta ZPPtr2
bcc .4
inc ZPPtr2+1
.4 pla
inc
sec
adc ZPPtr1
sta ZPPtr1
bcc .5
inc ZPPtr1+1
.5 dex
bne .1
>LDYA ZPPtr2
>SYSCALL2 GetMem
bcs .9
>STYA BufPtr
>STYA ZPPtr2
stx hBuf
.9 rts
.99 lda #MLI.E.EOF
sec
rts
*--------------------------------------
CIFS2.ReadDir.FillBuf
ldy #S.NETBIOS+S.SMB.H+S.TRANS2.H Search Count
lda bFlag
bne .10
iny
iny
.10 lda (ZPRespPtr),y
tax
.1 jsr FileInfo2StatBuf
lda ZPPtr1
sec skip Filename Len
adc #22
sta ZPPtr1
bcc .2
inc ZPPtr1+1
.2 ldy #$ff
.3 iny
lda (ZPPtr1),y
sta (ZPPtr2),y
bne .3
tya
sec
adc ZPPtr1
sta ZPPtr1
bcc .4
inc ZPPtr1+1
.4 tya
sec
adc ZPPtr2
sta ZPPtr2
bcc .5
inc ZPPtr2+1
.5 jsr StatBuf2Ptr2
lda #S.STAT
clc
adc ZPPtr2
sta ZPPtr2
bcc .7
inc ZPPtr2+1
.7 dex
bne .1
lda #0
sta (ZPPtr2)
rts
*--------------------------------------
CIFS.CloseDir tax
lda Nod.Table.hName-2,x
beq .1
phx
stz Nod.Table.hName-2,x
>SYSCALL2 FreeMem
plx
.1 lda Nod.Table.hFD-2,x
stz Nod.Table.hFD-2,x
>SYSCALL2 FreeMem
stz CIFS.Status
clc
rts
*--------------------------------------
CIFS2.CloseDir lda #MLI.E.INVPATH
sec
rts
*--------------------------------------
CIFS.ChOwn
CIFS2.ChOwn
lda #MLI.E.BADCALL
sec
rts
*--------------------------------------
CIFS.FOpen >STYA pPath resolved path
jsr GetCtx
ldx #S.SMB.H.CMD.NT.CREATE.ANDX
jsr RequestSetupX
ldx #0
.1 lda SMB.ComCreate.H,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.ComCreate.H.Len
bne .1
jsr ReqSetupPtr2
jsr AppendPathPtr2
tya
ldy #S.NETBIOS+S.SMB.H+6 NameLength
sta (ZPReqPtr),y
inc +1 for \0
ldy ByteCountOfs
sta (ZPReqPtr),y
lda #0
ror
iny ByteCountOfs+1
sta (ZPReqPtr),y
jsr SetReqLen
ldx #1 FILE_OPEN
ldy #3 fopen flags
lda (pStack),y
bit #O.WRONLY
beq .8
bit #O.CREATE
bne .3
ldx #3 FILE_OPEN_IF
.3 bit #O.APPEND
bne .8
ldx #5 FILE_OVERWRITE_IF
.8 txa
ldy #S.NETBIOS+S.SMB.H+SMB.Trans2.H.Len+7 CreateDisposition
sta (ZPReqPtr),y
jsr WriteSocket
bcs .9
jmp Sleep
.9 >RET 6
*--------------------------------------
CIFS2.FOpen jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .90
jsr CIFS.NewFD
bcs .91
ldy #S.NETBIOS+S.SMB.H+6 FileID
lda (ZPRespPtr),y
pha
iny
lda (ZPRespPtr),y
ldy #S.FD.REG.REF+1
sta (pFD),y
dey
pla
sta (pFD),y
ldy #3 fopen flags
lda (pStack),y
bit #O.APPEND
beq .3
ldy #S.NETBIOS+S.SMB.H+56+3 EOF
ldx #4
.1 lda (ZPRespPtr),y
pha
dey
dex
bne .1
ldx #4
ldy #S.FD.REG.REF+2
.2 pla
sta (pFD),y
iny
dex
bne .2
bra .8
.3 jsr CIFS.Seek0
.8 ldy #4 path
lda (pStack),y
>PUSHA
lda (pStack),y
>PUSHA
>PUSHWZ mod
>PUSHB hFD
>SYSCALL2 mknod
.91 jsr Exit.KO
bra .90
.9 jsr Exit.NODATA
beq .99
.90 >POP 6
.99 rts
*--------------------------------------
CIFS.FClose jsr GetPFD
jsr GetCtx
ldx #S.SMB.H.CMD.CLOSE
jsr RequestSetupX
ldx #0
.1 lda SMB.ComClose.H,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.ComClose.H.Len
bne .1
sty ZPReqLen
stz ZPReqLen+1
ldy #S.FD.REG.REF
lda (pFD),y
pha
iny
lda (pFD),y
ldy #S.NETBIOS+S.SMB.H+2 FileID
sta (ZPReqPtr),y
pla
dey
sta (ZPReqPtr),y
jsr SetReqLen
jsr WriteSocket
bcs .9
jmp Sleep
.9 rts
*--------------------------------------
CIFS2.FClose sta hFILE
jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .99
lda hFILE
jsr CIFS.CloseDir
jmp Exit.OK
.9 jmp Exit.NODATA
.99 rts
*--------------------------------------
CIFS.FRead ldy #4 hNod
lda (pStack),y
jsr GetPFD
jsr GetCtx
ldx #S.SMB.H.CMD.READ.ANDX
jsr RequestSetupX
ldx #0
.1 lda SMB.ComRead.H,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.ComRead.H.Len
bne .1
jsr ReqSetupPtr2
jsr CIFS.RWGetFidOfs
ldy #1 DataLen HI
lda (pStack),y
bne .2
lda #0
ldx #1 256 bytes to read
bra .3
.2 lda (pStack) DataLen LO
ldx #0
.3 ldy #S.NETBIOS+S.SMB.H+11 MaxCountOfBytesToReturn
sta (ZPReqPtr),y
iny
txa
sta (ZPReqPtr),y
jsr SetReqLen
jsr WriteSocket
bcs .9
jmp Sleep
.9 >RET 5
*--------------------------------------
CIFS2.FRead jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .90
ldy #S.NETBIOS+S.SMB.H+10
lda (ZPRespPtr),y
iny
ora (ZPRespPtr),y
bne .10
jsr Exit.OK
lda #MLI.E.EOF
sec
bra .90
.10 ldy #S.NETBIOS+S.SMB.H+13 DataOffset LO
lda (ZPRespPtr),y
inc
inc
* clc
adc ZPRespPtr
sta ZPPtr1
lda #0
adc ZPRespPtr+1
sta ZPPtr1+1
ldy #3 DataPtr HI
lda (pStack),y
sta ZPPtr2+1
dey DataPtr LO
lda (pStack),y
sta ZPPtr2
ldy #S.NETBIOS+S.SMB.H+11 DataLength LO
lda (ZPRespPtr),y
tax
jsr CIFS.CopyX
ldy #S.NETBIOS+S.SMB.H+11
jsr CIFS2.RWSetOfsY
ldy #S.NETBIOS+S.SMB.H+11 DataLength HI
lda (ZPRespPtr),y
beq .2 less than 256
inc CIFS.Cnt+1
ldy #1 DataLen HI
lda (pStack),y
dec
sta (pStack),y
ldy #3 DataPtr HI
lda (pStack),y
inc
sta (pStack),y
bra .7
.2 dey DataLength LO
lda (ZPRespPtr),y
sta CIFS.Cnt
lda #0
sta (pStack) DataLen LO
.7 jsr Exit.OK
ldy #1 DataLen HI
lda (pStack),y
ora (pStack) DataLen LO
bne .8
>LDYA CIFS.Cnt
bra .90
.8 jmp Sleep2 Back to CIFS.FRead for next chunk
.9 jsr Exit.NODATA
beq .99
.90 >POP 5
.99 rts
*--------------------------------------
CIFS.FWrite ldy #4 hNod
lda (pStack),y
jsr GetPFD
jsr GetCtx
ldx #S.SMB.H.CMD.WRITE.ANDX
jsr RequestSetupX
ldx #0
.1 lda SMB.ComWrite.H,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.ComWrite.H.Len
bne .1
jsr ReqSetupPtr2
jsr CIFS.RWGetFidOfs
ldy #3 DataPtr HI
lda (pStack),y
sta ZPPtr1+1
dey DataPtr LO
lda (pStack),y
sta ZPPtr1
dey DataLen HI
lda (pStack),y
beq .5
lda #0
ldx #1 write $100
bra .6
.5 dey DataLen LO
lda (pStack),y
ldx #0 write $0xx
.6 pha
ldy #S.NETBIOS+S.SMB.H+21 DataLength
sta (ZPReqPtr),y
iny
txa
sta (ZPReqPtr),y
pla
pha
clc
adc ZPReqLen
sta ZPReqLen
txa
adc ZPReqLen+1
sta ZPReqLen+1
pla
pha
ldy ByteCountOfs
sta (ZPReqPtr),y
txa
iny
sta (ZPReqPtr),y
plx
jsr CIFS.CopyX
jsr SetReqLen
jsr WriteSocket
bcs .9
ldy #1 DataLen HI
lda (pStack),y
beq .7
dec DataLen - $100
sta (pStack),y
ldy #3 DataPtr HI
lda (pStack),y
inc DataPtr + $100
sta (pStack),y
jmp Sleep
.7 lda #0
sta (pStack) DataLen = 0
jmp Sleep
.9 >RET 5
*--------------------------------------
CIFS2.FWrite jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .90
ldy #S.NETBIOS+S.SMB.H+5 Count LO
jsr CIFS2.RWSetOfsY
ldy #S.NETBIOS+S.SMB.H+5 Count LO
lda (ZPRespPtr),y
bne .1
inc CIFS.Cnt+1
bra .7
.1 sta CIFS.Cnt
.7 jsr Exit.OK
ldy #1 DataLen HI
lda (pStack),y
ora (pStack) DataLen LO
bne .8
>LDYA CIFS.Cnt
clc
bra .90
.8 jmp Sleep2
.9 jsr Exit.NODATA
beq .99
.90 >POP 5
.99 rts
*--------------------------------------
CIFS.FFlush
CIFS2.FFlush
CIFS.FSeek
CIFS2.FSeek
CIFS.FTell
CIFS2.FTell
CIFS.FEOF
CIFS2.FEOF >DEBUG
lda #MLI.E.BADCALL
sec
rts
*--------------------------------------
CIFS.Remove >STYA pPath resolved path
jsr ClearSocket
jsr GetCTX
ldx #S.SMB.H.CMD.DELETE
jsr RequestSetupX
ldx #0
.1 lda SMB.ComDelete.H,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.ComDelete.H.Len
bne .1
jsr ReqSetupPtr2
lda #$04 BufferFormat
jsr PutBytePtr2
jsr AppendPathPtr2
tya
inc +1 for BufferFormat
inc +1 for \0
jsr Add2ByteCount
jsr SetReqLen
jsr WriteSocket
bcs .9
jmp Sleep
.9 rts
*--------------------------------------
CIFS2.Remove jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .99
jmp Exit.OK
.9 jmp Exit.NODATA
.99 rts
*--------------------------------------
CIFS.Rename >STYA pPath resolved src path
jsr ClearSocket
jsr GetCTX
ldx #S.SMB.H.CMD.RENAME
jsr RequestSetupX
ldx #0
.1 lda SMB.ComRename.H,x
sta (ZPReqPtr),y
iny
inx
cpx #SMB.ComRename.H.Len
bne .1
jsr ReqSetupPtr2
lda #$04 BufferFormat
jsr PutBytePtr2
jsr AppendPathPtr2
tya
inc +1 for BufferFormat
inc +1 for \0
jsr Add2ByteCount
lda (pStack)
sta pPath
ldy #1
lda (pStack),y
sta pPath+1
.2 inc pPath skip /mount
bne .3
inc pPath+1
.3 lda (pPath)
cmp #'/'
bne .2
lda #$04 BufferFormat
jsr PutBytePtr2
jsr AppendPathPtr2
tya
inc +1 for BufferFormat
inc +1 for \0
jsr Add2ByteCount
jsr SetReqLen
jsr WriteSocket
bcs .9
jmp Sleep
.9 >RET 4
*--------------------------------------
CIFS2.Rename jsr ReadSocket
bcs .9
jsr GetRespData
jsr CheckSMBStatus
bcs .99
jsr Exit.OK
bra .99
.9 jmp Exit.NODATA
.99 >RET 4
*--------------------------------------
CIFS.NewFD >LDYAI S.FD.REG
>SYSCALL2 GetMem
bcs .9
>STYA pFD
stx hFD
lda #S.FD.T.REG
sta (pFD)
lda hHandler
ldy #S.FD.PFT
sta (pFD),y
* clc
.9 rts
*--------------------------------------
CIFS.RWGetFidOfs
ldx #6
ldy #S.FD.REG.REF
.1 lda (pFD),y
pha
iny
dex
bne .1
ldx #6
ldy #S.NETBIOS+S.SMB.H+5+5
.2 pla
sta (ZPReqPtr),y
dey
dex
bne .2
rts
*--------------------------------------
CIFS2.RWSetOfsY phy
ldy #4 hNod
lda (pStack),y
jsr GetPFD
ply Count LO
phy
lda (ZPRespPtr),y
ldy #S.FD.REG.REF+2
clc
adc (pFD),y
sta (pFD),y
ply
iny Count HI
lda (ZPRespPtr),y
ldy #S.FD.REG.REF+3
adc (pFD),y
sta (pFD),y
bcc .8
iny
lda (pFD),y
inc
sta (pFD),y
bne .8
iny
lda (pFD),y
inc
sta (pFD),y
.8 rts
*--------------------------------------
CIFS.CopyX ldy #0
.1 lda (ZPPtr1),y
sta (ZPPtr2),y
iny
dex
bne .1
rts
*--------------------------------------
CIFS.Seek0 ldx #4
ldy #S.FD.REG.REF+2
lda #0
.1 sta (pFD),y
iny
dex
bne .1
rts
*--------------------------------------
MAN
SAVE usr/src/lib/libcifs.io.s
LOAD usr/src/lib/libcifs.s
ASM