Subversion Repositories Spectranet

[/] [trunk/] [rom/] [tnfs_mount.asm] - Blame information for rev 442

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 215 winston
;The MIT License
2
;
3
;Copyright (c) 2009 Dylan Smith
4
;
5
;Permission is hereby granted, free of charge, to any person obtaining a copy
6
;of this software and associated documentation files (the "Software"), to deal
7
;in the Software without restriction, including without limitation the rights
8
;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
;copies of the Software, and to permit persons to whom the Software is
10
;furnished to do so, subject to the following conditions:
11
;
12
;The above copyright notice and this permission notice shall be included in
13
;all copies or substantial portions of the Software.
14
;
15
;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
;THE SOFTWARE.
22 399 winston
.include        "tnfs_defs.inc"
23
.include        "tnfs_sysvars.inc"
24
.include        "spectranet.inc"
25
.include        "sysvars.inc"
26 400 winston
.include        "fcntl.inc"
27 442 winston
.include        "errno.inc"
28 215 winston
 
29
; The TNFS mount and umount functions.
30
;-----------------------------------------------------------------------
31
; F_tnfs_mount: Mount a remote filesystem.
32 216 winston
; Parameters: IX - pointer to 10 byte VFS mount structure:
33
;               byte 0,1 - Pointer to null terminated protocol
34
;               byte 2,3 - pointer to null terminated hostname
35
;               byte 4,5 - pointer to null terminated mount source
36
;               byte 6,7 - pointer to null terminated user id
37
;               byte 8,9 - pointer to null terminated passwd
38
;               A - Mount point - 0 to 3
39
;
40 215 winston
; On success, returns the session number in HL. On error, returns the
41
; error number in HL and sets the carry flag.
42 399 winston
.globl F_tnfs_mount
43
F_tnfs_mount:
44 216 winston
        call F_fetchpage        ; get our private RAM page
45
        ret c                   ; which was allocated on startup.
46
        ld (v_curmountpt), a    ; save the mount point for later
47
 
48
        ; first check the requested protocol
49
        ld e, (ix+0)
50
        ld d, (ix+1)
51
        ld hl, STR_tnfstype
52
        ld bc, 5
53 399 winston
.cploop1:
54 216 winston
        ld a, (de)              ; Effectively this is a "strncmp" to check
55 234 winston
        cpi                     ; that the passed protocol is "tnfs" plus
56 399 winston
        jp nz, .notourfs1        ; a null.
57 216 winston
        inc de
58 399 winston
        jp pe, .cploop1
59 216 winston
 
60
        ; It is now certain that the requested FS is TNFS.
61 400 winston
        ; Check that we have an IP address set
62
        ld a, (v_ethflags)
63
        and 1                   ; if bit 0 is not 1 then we don't have
64
        jr nz, .lookup          ; a valid IP
65
 
66
        ld a, EIO               ; set the error number
67
        scf
68
        jp F_leave
69
.lookup:
70 216 winston
        ld de, buf_tnfs_wkspc   ; Look up the host
71
        ld l, (ix+2)
72
        ld h, (ix+3)
73 350 winston
        push ix
74 215 winston
        call GETHOSTBYNAME
75 350 winston
        pop ix
76 216 winston
        jp c, F_leave           ; exit if host not found
77 215 winston
 
78
        ; create the socket that will be used for tnfs communications
79 216 winston
        ld hl, buf_tnfs_wkspc   ; IP address is here
80 236 winston
        call F_tnfs_prepsock    ; Open the socket if necessary
81 216 winston
        jp c, F_leave           ; unable to open socket
82 215 winston
 
83
        ; We've successfully looked up a host so create the datagram
84
        ; that will be sent.
85 216 winston
        ld hl, buf_tnfs_wkspc+4
86 215 winston
        ld de, 0                ; no session id yet
87
        xor a                   ; cmd is 0x00
88
        call F_tnfs_header      ; create the header, HL now at the next byte
89 399 winston
        ld (hl), 0              ; version 1.01, little endian
90 215 winston
        inc hl
91
        ld (hl), 1              ; msb of protocol version
92
        inc hl
93
        ex de, hl               ; make destination = DE
94 216 winston
        ld l, (ix+4)            ; remote mount point
95
        ld h, (ix+5)
96 215 winston
        ld b, 255               ; maximum size of mount point
97
        call F_tnfs_strcpy
98 216 winston
        ld l, (ix+6)            ; user id
99
        ld h, (ix+7)
100 215 winston
        ld b, 64
101
        call F_tnfs_strcpy
102 216 winston
        ld l, (ix+8)            ; passwd
103
        ld h, (ix+9)
104 215 winston
        ld b, 64
105
        call F_tnfs_strcpy
106
 
107
        ; the packet is assembled - send it.
108
        ex de, hl               ; get current dest pointer into hl
109 216 winston
        ld de, buf_tnfs_wkspc+4 ; calculate the size
110 215 winston
        sbc hl, de              ; hl now contains the size
111
        ld b, h                 ; move into bc
112
        ld c, l
113
        call F_tnfs_message     ; send msg/get response
114 399 winston
        jr c, .mounterr1                ; clean up on error
115 215 winston
 
116
        ; decode the result - first, check for error conditions
117
        ld a, (tnfs_recv_buffer + tnfs_err_offset)
118
        and a                   ; zero = no error
119 399 winston
        jr nz, .mounterr1       ; clean up on error
120 234 winston
 
121 215 winston
        ld hl, (tnfs_recv_buffer + tnfs_sid_offset)
122 234 winston
        ld d, v_tnfs_sid0 / 256 ; start with the lowest SID storage offset
123
        ld a, (v_curmountpt)    ; get the intended mount point number
124
        rlca                    ; multiply by two
125 399 winston
        add a, v_tnfs_sid0 % 256        ; calculate the offset
126 234 winston
        ld e, a                 ; DE = storage for the session id
127
        ex de, hl
128
        ld (hl), e              ; save the session identifier
129
        inc l
130
        ld (hl), d
131 215 winston
 
132 234 winston
        ld a, (v_curmountpt)    ; now calculate the address of the CWD
133 399 winston
        add a, v_cwd0 / 256     ; storage area (A=MSB)
134 234 winston
        ld h, a                 ; and point HL there
135
        ld l, 0
136
        ld (hl), '/'
137
        inc l
138
        ld (hl), 0
139
 
140 216 winston
        ; set up mount point in VFS mount table
141
        ld a, (v_curmountpt)    ; get the mount point
142 399 winston
        add a, VFSVECBASE % 256 ; find it in the sysvars
143 216 winston
        ld l, a
144
        ld h, 0x3F              ; point HL at the address in sysvars
145
        ld a, (v_pgb)           ; Fetch our ROM number
146
        ld (hl), a              ; and store it in the mount point table
147 401 winston
 
148
        ; set initial poll time
149 216 winston
        or 1                    ; reset Z and C flags - mounted OK.
150
        jp F_leave
151
 
152 399 winston
.mounterr1:
153 236 winston
        call F_tnfs_checkclose  ; close the socket if necessary
154 215 winston
        scf                     ; set the carry flag
155 216 winston
        jp F_leave
156 399 winston
.notourfs1:
157 216 winston
        xor a                   ; signal 'not our filesystem' by setting
158
        jp F_leave              ; the zero flag.
159 399 winston
STR_tnfstype: defb "tnfs",0
160 215 winston
 
161
;-------------------------------------------------------------------------
162
; F_tnfs_umount
163
; Unmounts the TNFS filesystem and closes the socket.
164 399 winston
.globl F_tnfs_umount
165
F_tnfs_umount:
166 234 winston
        call F_fetchpage
167 236 winston
        ret c
168
        ld (v_curmountpt), a
169
 
170 215 winston
        ld a, TNFS_OP_UMOUNT
171
        call F_tnfs_header_w            ; create the header
172 236 winston
        inc hl                          ; advance past end
173 215 winston
        call F_tnfs_message_w_hl        ; not much to do here at all
174
        ret c                           ; communications error
175
        ld a, (tnfs_recv_buffer+tnfs_err_offset)
176
        and a                           ; no error?
177 399 winston
        jr nz, .error2
178 236 winston
 
179
        ld a, (v_curmountpt)
180
        rlca                            ; calculate the SID address
181 399 winston
        add a, v_tnfs_sid0 % 256
182 236 winston
        ld h, v_tnfs_sid0 / 256         ; hl points at the sid
183
        ld l, a
184
        ld (hl), 0                      ; clear down the sid
185
        inc l
186
        ld (hl), 0
187
 
188
        ld a, (v_curmountpt)
189
        call FREEMOUNTPOINT             ; clear down the mount point
190
 
191
        call F_tnfs_checkclose          ; close the socket if necessary
192 234 winston
        jp F_leave
193 399 winston
.error2:
194 215 winston
        scf                             ; flag the error condition
195 234 winston
        jp F_leave