-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_file_info.aii
631 lines (486 loc) · 8.25 KB
/
get_file_info.aii
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
string asis
include 'gsos.equ'
include 'minix.equ'
include 'records.equ'
include 'fst.equ'
include 'fst.macros'
include 'M16.Debug'
entry path_to_inode
entry load_inode
entry find_file
entry volume_by_name
entry vstrcmp
import id_disk
import device_read
import disk_inode:v1_inode
import disk_super:v1_super
data record
path_offset ds.w 1
more ds.w 1
endr
get_file_info procname export
with fst_parms
with dev_parms
with dp
;~DebugSetTrace #1
;brk $ea
jsr path_to_inode
bcs exit
jsr load_inode
bcs exit
;pha ; space
;~DebugSetTrace #0
;pla ; prev value
lda <call_class
beq class0
class1
lda [param_blk_ptr] ; pcount
dec a
asl a ; x 2
asl a ; x 4
tax
dispatch file_info_dcb_1
lda tool_error
cmp #1
rtl
class0
ldx #file_info_dcb_0_size-4
dispatch file_info_dcb_0
lda tool_error
cmp #1
rtl
exit
rtl
import do_ignore
import do_access
import do_create_date_time, do_mod_date_time
import do_create_date_time_0, do_mod_date_time_0
import do_option_list
import do_file_type, do_aux_type, do_storage_type
import do_eof, do_blocks, do_r_eof, do_r_blocks
file_info_dcb_0
with FileRec
dc.w pathname, do_ignore ; pathname
dc.w fAccess, do_access
dc.w fileType, do_file_type
dc.w auxType, do_aux_type
dc.w storageType, do_storage_type
dc.w createDate, do_create_date_time_0
dc.w modDate, do_mod_date_time_0
dc.w blocksUsed, do_blocks
endwith
file_info_dcb_0_size equ *-file_info_dcb_0
file_info_dcb_1
with FileInfoRecGS
;dc.w $00, do_ignore ; pCount
dc.w pathname, do_ignore ; pathname
dc.w access, do_access
dc.w fileType, do_file_type
dc.w auxType, do_aux_type
dc.w storageType, do_storage_type
dc.w createDateTime, do_create_date_time
dc.w modDateTime, do_mod_date_time
dc.w optionList, do_option_list
dc.w eof, do_eof
dc.w blocksUsed, do_blocks
dc.w resourceEOF, do_r_eof
dc.w resourceBlocks, do_r_blocks
endwith
endp
load_inode procname export
;
; loads inode into disk_inode.
;
; inputs :
; my_vcr
; inode
; device
;
; outputs :
; disk_inode
; error in a/c
; 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
;lda #0
;rol a
;sta dev_blk_num+2
stz dev_blk_num+2 ; should be less than 0xffff inode blocks!
; 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_blk_size
sta dev_req_cnt
; dev_num must already be set up.
;lda device ;;;;
;sta dev_num
jsr device_read
bcc ok
rts
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
;
; sets inode, parent_inode, disk_inode,
; if file not present but path is otherwise, ok (eg, create),
; parent inode and disk_inode will be valid for the parent directory.
;
; uses path1, dev1, span1.
;
;
; After GS/OS expands prefixes, there are two path types
; 1. device root (.dev:path)
; 2. path root (:volume:path)
;
; in the case of 1, verify the device is a minix volume, create
; the vcr (if necessary) and proceed from there.
;
; in the case of 2, gs/os will check for a vcr with the volume
; name and, if found, give the FST a first shot at handling it.
; if the FST doesn't claim it, or no vcr is found, all FSTs will
; be called until it's claimed.
;
; fst_parms.vcr will not be populated even if GS/OS previously found
; it.
;
path_to_inode procname export
with dp,fst_parms
path equ path1_ptr
dev_num equ dev1_num
span equ span1
stz inode
lda #1
sta parent_inode
lda path_flag
and #$4000
bne check_path
no_path
; device only (eg, .dev1 )
;
lda #1
sta inode
lda dev_num
beq bps
;sta device
jmp id_disk
; returns
bps
lda #bad_path_syntax
sec
exit
rts
check_path
; linux allows a 30-char name. minix is 14 char
; will check for minix later.
lda span
cmp #v1L.DIRSIZE+1
bcs bps
; but is it relative?
ldy #2
lda [path],y
and #$00ff
cmp #':'
beq absolute
lda #1
sta inode
lda dev_num
beq bps
;sta device
jsr id_disk
bcs exit
lda #2
sta data.path_offset ; skip past gs-os length word
brl find_file ; will rts.
;
absolute
;
; worst case ...
; 1. extract the volume name.
; 2. call find_vcr to find it by name
; 3. if that fails, scan all devices.
jsr volume_by_name
_rts.cs
brl find_file
endp
entry skip_colon
skip_colon proc
;returns carry set if end of path.
with dp, data
path equ fst_parms.path1_ptr
ldy path_offset
short m
@loop
lda [path],y
beq zero
cmp #':'
bne done
iny
bra @loop
done
lda #':'
sta more
sty path_offset
long m
clc
rts
zero
long m
stz more
sty data.path_offset
sec
rts
endp
find_file procname
with dp
with data
import find_entry_by_name
path equ fst_parms.path1_ptr
dev_num equ fst_parms.dev1_num
span equ fst_parms.span1
import target:GSString32
stz more
; we always need to load inode 1
lda #1
sta inode
jsr load_inode
_rts.cs
dir_loop
; get a path component.
; 1. check for a null path.
jsr skip_colon
bcs done
lda inode
sta parent_inode
ldx #0
ldy path_offset
short m
path_loop
lda [path],y
beq eop
cmp #':'
beq eop
sta target.text,x
inx
iny
bra path_loop
eop
sta more
long m
stx target.length
sty path_offset
; a = ':' or 0 ... worry about which later!
; target is valid, inode is valid, is target in inode?
;~DebugHexDump #target, #34
jsr find_entry_by_name
bcc @ok
; may be file_not_found, may be path_not_found.
ldx more
beq @exit
lda #path_not_found
@exit
sec
rts
@ok
; inode, has been updated.
jsr load_inode
_rts.cs
lda more
beq done
; more to go...
; this is a directory, right?
lda disk_inode.mode
and #S_IFMT
cmp #S_IFDIR
beq dir_loop
lda #path_not_found
sec
rts
done
clc
rts
endp
volume_by_name procname export
;
; extract the volume name from path1_ptr and find (or create) a vcr.
;
;
with dp
with data
path equ fst_parms.path1_ptr
import target:GSString32
; copy volume name to target.
; leading : is NOT included.
ldx #0
ldy #3
short m
@loop
lda [path],y
beq done
cmp #':'
bne @next
iny
bra done
@next
sta target.text,x
inx
iny
bra @loop
done
long m
sty path_offset
stx target.length
ldx #target
ldy #^target
lda #0
jsl find_vcr
bcs no_vcr
; store it for later...
;stx ptr
; sty ptr+2
jsl deref
stx my_vcr
sty my_vcr+2
ldy #vcr.fst_id
lda [my_vcr],y
cmp #fst_id
bne no_vcr
; there is a vcr and it's a minix vcr.
; 1. should do a case-sensitive name check.
; 2. if the volume is marked as swapped, we need to
; re-scan devices.
; 3. if the volume is not swapped, we need to verify
; the disk didn't switch on us.
ldy #vcr.status
lda [my_vcr],y
and #vcr_swapped
bne no_vcr
ldy #vcr.device
lda [my_vcr],y
jsr id_disk
bcs no_vcr
;
; I suppose reading a block could alloc memory and invalidate the vcr...
;
;ldx ptr
;ldy ptr+2
;jsl deref
;stx my_vcr
;sty my_vcr+2
; check the volume name here...
jsr vstrcmp
bcs no_vcr
rts
no_vcr
; no vcr on file... scan all devices to find the volume.
stz my_vcr
stz my_vcr+2
stz device
@loop
lda device
inc a
sta device
jsr id_disk
bcs @error_check
; check if the volume name matches...
jsr vstrcmp
bcs @loop
; match! hooray!
clc
rts
@error_check
cmp #dup_volume
beq @error
cmp #invalid_dev_num
bne @loop
lda #vol_not_found
@error
sec
rts
device
ds.w 1
endp
vstrcmp procname
import target:GSString32
; case-sensitive strcmp for volume name
;
; target does not have a leading :
; vcr.vname has a leading :
;
with dp
lda target.length
inc a ; + 1 for :
ldy #vcr.vname.length
cmp [my_vcr],y
bne fail
lda #vcr.vname.text
clc
adc target.length
tay
ldx target.length
dex
short m
@loop
lda target.text,x
cmp [my_vcr],y
bne fail8
dey
dex
bpl @loop
;success
long m
clc
rts
fail8
long m
fail
sec
rts
endp
end