Subversion Repositories Spectranet

[/] [trunk/] [rom/] [tnfs_directory.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        "spectranet.inc"
23
.include        "sysvars.inc"
24
.include        "tnfs_defs.inc"
25
.include        "tnfs_sysvars.inc"
26
.include        "stat.inc"
27
.include        "fcntl.inc"
28 442 winston
.include        "errno.inc"
29 399 winston
.text
30 215 winston
 
31
; TNFS directory functions - opendir, readdir. closedir
32
 
33
;=========================================================================
34
; F_tnfs_opendir
35
; Opens a directory.
36
; Arguments:    HL = pointer to null-terminated string containing the path
37
; On success, returns the directory handle in A.
38
; On error, sets the carry flag and sets A to the error number.
39 399 winston
.globl F_tnfs_opendir
40
F_tnfs_opendir:
41 216 winston
        call F_fetchpage                ; get our sysvars at 0x1000
42
        ret c
43
 
44 234 winston
        ld (v_curmountpt), a            ; save the mount point in use
45
 
46 215 winston
        ld a, TNFS_OP_OPENDIR
47
        call F_tnfs_pathcmd             ; send command, get reply
48 216 winston
        jp c, F_leave                   ; return on network error
49 215 winston
        ld a, (tnfs_recv_buffer+tnfs_err_offset)
50
        and a                           ; return code is zero?
51 399 winston
        jr z, .gethandle1
52 215 winston
        scf                             ; return with tnfs error
53 216 winston
        jp F_leave
54 399 winston
.gethandle1:
55 216 winston
        ld a, (v_pgb)                   ; allocate a
56 285 winston
        ld c, ALLOCDIRHND
57
        call RESALLOC                   ; directory handle.
58 399 winston
        jr c, .cleanupandexit1
59 216 winston
        ld h, HANDLESPACE / 256         ; create our private sysvar addr
60 215 winston
        ld a, (tnfs_recv_buffer+tnfs_msg_offset)
61 216 winston
        ld (hl), a                      ; save TNFS handle
62 234 winston
        inc h                           ; point at metadata storage
63
        ld a, (v_curmountpt)            ; and save the mount point
64
        ld (hl), a
65 216 winston
        ld a, l                         ; move dirhandle into A
66
        jp F_leave                      ; return the directory handle
67 399 winston
.cleanupandexit1:
68 216 winston
        push af
69
        ld a, (tnfs_recv_buffer+tnfs_msg_offset)
70
        ld b, a
71
        ld a, TNFS_OP_CLOSEDIR          ; close the TNFS handle
72
        call F_tnfs_header_w
73
        ld (hl), b                      ; message is just the dirhandle
74
        inc hl
75
        call F_tnfs_message_w_hl
76
        pop af
77
        jp F_leave
78
 
79 215 winston
;=========================================================================
80
; F_tnfs_readdir
81
; Reads the next directory entry.
82
; Arguments:    A = directory handle
83
;               DE = pointer to a buffer for the result
84
; On success, returns with carry cleared, and the buffer at DE filled
85
; with the result. On error, sets the carry flag and A to the error number
86 399 winston
.globl F_tnfs_readdir
87
F_tnfs_readdir:
88 216 winston
        call F_fetchpage
89 215 winston
        ret c
90 216 winston
 
91
        ld l, a                         ; get the TNFS handle address
92
        ld h, HANDLESPACE / 256
93
        ld b, (hl)                      ; get the TNFS handle
94 234 winston
        inc h                           ; point at handle metadata
95
        ld a, (hl)                      ; get the mountpoint
96
        ld (v_curmountpt), a
97 215 winston
        push de
98
        ld a, TNFS_OP_READDIR
99
        call F_tnfs_header_w            ; create the header
100
        ld (hl), b                      ; set the dirhandle
101
        inc hl
102
        call F_tnfs_message_w_hl        ; send the message
103
        pop de                          ; get buffer pointer back
104 216 winston
        jp c, F_leave                   ; but return on network error
105 215 winston
        ld a, (tnfs_recv_buffer+tnfs_err_offset)
106
        and a                           ; if rc is zero then copy the
107 399 winston
        jr z, .copybuf2                 ; buffer to DE
108 215 winston
        scf
109 216 winston
        jp F_leave
110 399 winston
.copybuf2:
111 215 winston
        ld hl, tnfs_recv_buffer+tnfs_msg_offset
112
        ld b, 255                       ; max filename length
113 311 winston
        call F_restorepage              ; ... in case it's 0x1000-0x1FFF
114
        jp F_tnfs_strcpy                ; copy then exit (page already restored)
115 215 winston
 
116
;===========================================================================
117
; F_tnfs_closedir
118
; Closes the directory handle.
119
; Arguments:    A = directory handle
120
; On success, returns with carry cleared. On error, returns with carry
121
; set and A as the error.
122 399 winston
.globl F_tnfs_closedir
123
F_tnfs_closedir:
124 216 winston
        call F_fetchpage
125 215 winston
        ret c
126 216 winston
 
127 285 winston
        ld c, FREEDIRHND                ; The dirhandle should always be
128
        call RESALLOC                   ; cleared, even if there's an error.
129
 
130 216 winston
        ld l, a                         ; get the handle address
131
        ld h, HANDLESPACE / 256
132
        ld b, (hl)                      ; and fetch the TNFS handle
133 234 winston
        inc h
134
        ld a, (hl)                      ; get the mount point
135
        ld (v_curmountpt), a
136 215 winston
        ld a, TNFS_OP_CLOSEDIR
137
        call F_tnfs_header_w
138
        ld (hl), b                      ; message is just the dirhandle
139
        inc hl
140
        call F_tnfs_message_w_hl
141 216 winston
        jp c, F_leave                   ; return now on network error
142 215 winston
        ld a, (tnfs_recv_buffer+tnfs_err_offset)
143
        and a
144 216 winston
        jp z, F_leave                   ; no error
145 215 winston
        scf
146 216 winston
        jp F_leave                      ; return error number
147 215 winston
 
148
;===========================================================================
149
; F_tnfs_chdir
150
; Chdir is not part of the protocol, but it's part of the client. It works
151
; by statting the path supplied, and if it's a directory, storing this
152
; path (which gets prepended to subsequent file operations).
153
; Parameters    HL = path to chdir to
154
; Returns with carry set on error and A=error code
155 399 winston
.globl F_tnfs_chdir
156
F_tnfs_chdir:
157 216 winston
        call F_fetchpage
158
        ret c
159
 
160 215 winston
        push hl
161 234 winston
        ld (v_curmountpt), a    ; set the mount point being worked upon
162 217 winston
        ld a, TNFS_OP_STAT
163
        call F_tnfs_pathcmd     ; stat the path
164 399 winston
        jr c, .error4           ; stat returned an error
165 289 winston
        ld a, (tnfs_recv_buffer+tnfs_err_offset)
166
        and a
167 399 winston
        jr nz, .scferror4
168 217 winston
        ld hl, tnfs_recv_buffer+tnfs_msg_offset+1 ; MSB of stat filemode bitfield
169 215 winston
        ld a, S_IFDIR / 256     ; MSB of S_IFDIR bitfield
170
        and (hl)                ; AND it all together...
171 399 winston
        jr z, .notadir4         ; ...if4 zero, it wasn't a directory.
172 215 winston
        pop hl
173 234 winston
 
174
        ld a, (v_curmountpt)
175 399 winston
        add a, v_cwd0 / 256     ; add the MSB of the CWD storage
176 234 winston
        ld d, a                 ; DE = pointer to this mount point's CWD
177
        ld e, 0                 ; copy the directory we just got
178 215 winston
        call F_tnfs_abspath     ; as an absolute path.
179 216 winston
        jp F_leave
180 399 winston
.notadir4:
181 215 winston
        ld a, ENOTDIR
182 399 winston
.scferror4:
183 215 winston
        scf
184 399 winston
.error4:
185 215 winston
        pop hl
186 216 winston
        jp F_leave
187 215 winston
 
188
;-------------------------------------------------------------------------
189
; F_tnfs_mkdir
190
; Create a directory on the server.
191
; Parameters            HL = pointer to directory name
192
; Returns with carry set on error and A=error code.
193 399 winston
.globl F_tnfs_mkdir
194
F_tnfs_mkdir:
195 234 winston
        ld b, TNFS_OP_MKDIR
196 215 winston
        jp F_tnfs_simplepathcmd
197
 
198
;------------------------------------------------------------------------
199
; F_tnfs_rmdir
200
; Removes a directory on the server.
201
; Parameters            HL = pointer to the directory
202
; Returns with carry set on error and A=error code.
203 399 winston
.globl F_tnfs_rmdir
204
F_tnfs_rmdir:
205 234 winston
        ld b, TNFS_OP_RMDIR
206 215 winston
        jp F_tnfs_simplepathcmd
207 279 winston
 
208
;------------------------------------------------------------------------
209
; F_tnfs_getcwd
210
; Gets the current working directory
211
; Parameters            DE = pointer to memory to copy result
212 399 winston
.globl F_tnfs_getcwd
213
F_tnfs_getcwd:
214 279 winston
        call F_fetchpage
215
        ret c
216
 
217 399 winston
        add a, v_cwd0 / 256     ; add the MSB of the CWD storage
218 279 winston
        ld h, a                 ;
219
        ld l, 0                 ; HL = pointer to CWD
220 399 winston
.cploop7:
221 279 winston
        ld a, (hl)
222
        ld (de), a
223
        and a                   ; null terminator?
224
        jp z, F_leave
225
        inc hl
226
        inc de
227 399 winston
        jr .cploop7
228 279 winston