-
Notifications
You must be signed in to change notification settings - Fork 65
/
FileAttributesPluginSimulator.class.st
829 lines (650 loc) · 23.9 KB
/
FileAttributesPluginSimulator.class.st
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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
"
FileAttributesPluginSimulator provides support functions to allow the FilePluginsAttribute to run in the VM simulator.
faPath is opaque to the VM, but normally stores:
1. The file path being interagated in the format provided by the image (precomposed UTF8).
2. The file path in platform specific format, e.g. wide strings for Windows, decomposed UTF8 for Mac.
3. Platform specific directory iteration information when required, e.g. primOpendir.
The simulator stores an Array with:
1. The session ID
2. The input path in precomposed UTF8.
3. The file name when iterating over directories.
4. The input path with platform specific encoding
5. The file name when iterating over directories with platform specific encoding
6. The pointer to the real faPath used by the plugin.
The third and fourth entries (platform specific encoding) are only valid in specific cases, e.g. primitivePlatToStPath and primitiveStToPlatPath.
Instance Variables
"
Class {
#name : #FileAttributesPluginSimulator,
#superclass : #FileAttributesPlugin,
#instVars : [
'maxPathLen'
],
#classVars : [
'FA_PATH_MAX',
'HAVE_CHMOD',
'HAVE_CHOWN',
'HAVE_LSTAT',
'PATH_MAX',
'S_IFBLK',
'S_IFCHR',
'S_IFDIR',
'S_IFIFO',
'S_IFLNK',
'S_IFMT',
'S_IFREG',
'S_IFSOCK'
],
#category : #FileAttributesPlugin
}
{ #category : #translation }
FileAttributesPluginSimulator class >> shouldBeTranslated [
"This class should not be translated"
^false
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> addressObjectFor: aByteArray [
"The simulation passes around ByteArrays in place of malloc'd memory.
Copy the supplied ByteArray to the simulations memory and answer the address."
^self toOop: aByteArray
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> arrayFromOop: anOop [
"Answer a copy of the supplied array Oop"
| sz array |
sz := interpreterProxy stSizeOf: anOop.
array := Array new: sz.
1 to: sz do: [ :i |
array at: i put: (self fromOop: (interpreterProxy fetchPointer: i-1 ofObject: anOop))].
^array
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> byteArrayFromOop: anOop [
"Answer a copy of the supplied byte array Oop"
| sz array ptr |
sz := interpreterProxy stSizeOf: anOop.
ptr := interpreterProxy arrayValueOf: anOop.
array := ByteArray new: sz.
1 to: sz do: [ :i |
array at: i put: (interpreterProxy byteAt: ptr+i-1)].
^array
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> byteStringFromOop: anOop [
"Answer a copy of the supplied ByteString Oop"
| sz array ptr |
sz := interpreterProxy stSizeOf: anOop.
ptr := interpreterProxy arrayValueOf: anOop.
array := ByteString new: sz.
self strncpy: array _: ptr _: sz.
^array
]
{ #category : #simulation }
FileAttributesPluginSimulator >> chmod: pathByteArray _: newMode [
"Set the mode of pathByateArray to anInteger (as defined by chmod())"
| status |
status := self primFile: pathByteArray posixPermissions: newMode.
"The real primitive answers nil on success, convert to C integer status"
^status ifNil: [0]
]
{ #category : #simulation }
FileAttributesPluginSimulator >> chown: pathByteArray _: uidInteger _: gidInteger [
"Set the owner and group of path by numeric id."
| status |
status := self primFile: pathByteArray uid: uidInteger gid: gidInteger.
"The real primitive answers nil on success, convert to C integer status"
^status ifNil: [0]
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> classOf: anOop [
| clsOop |
anOop = interpreterProxy nilObject ifTrue: [^UndefinedObject].
clsOop := interpreterProxy fetchClassOf: anOop.
clsOop = interpreterProxy classArray ifTrue: [^Array].
clsOop = interpreterProxy classByteArray ifTrue: [^ByteArray].
clsOop = interpreterProxy classString ifTrue: [^ByteString].
clsOop = interpreterProxy classLargePositiveInteger ifTrue: [^LargePositiveInteger].
clsOop = interpreterProxy classSmallInteger ifTrue: [^SmallInteger].
self error: 'unknown class'
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faAccessAttributes: faPath _: accessArray _: offset [
"Set the access attributes in the supplied array (size 3) at the supplied offset.
Simulated by calling primFileAttributes:mask:."
| access |
access := self primFileAttributes: (self faGetStPath: faPath) mask: 2r10.
interpreterProxy
storePointer: offset+0
ofObject: accessArray
withValue: (self toOop: (access at: 1));
storePointer: offset+1
ofObject: accessArray
withValue: (self toOop: (access at: 2));
storePointer: offset+2
ofObject: accessArray
withValue: (self toOop: (access at: 3)).
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faCharToByteArray: filePtr _: byteArrayPtr [
"Copy the supplied file name to the simulation and set the pointer"
byteArrayPtr at: 0 put: (self toOop: filePtr).
^0
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faCloseDirectory: faPath [
"Simulate the the call by actually calling the primitive and discarding the stat information (which will be retrieved again later in the simulation)."
| result status |
result := self primClosedir: (self faPathPtr: faPath).
result isNumber ifFalse:
[faPath at: 6 put: nil.
status := 0 ]
ifTrue:
[status := result < 0
ifTrue: [result]
ifFalse: [self unableToCloseDir]].
^status
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faConvertUnixToLongSqueakTime: anInteger [
"In the simulation the primitive returns the value already converted, so this is a no-op"
^anInteger
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faExists: faPath [
"Simulate the the call by actually calling the primitive."
^self primExists: (self faGetStPath: faPath)
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faFileAttribute: faPath _: attributeNumber [
"Simulate the the call by actually calling the primitive."
| result |
result := self primFileAttribute: (self faGetStPath: faPath) number: attributeNumber.
^self toOop: result
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faFileStatAttributes: faPath _: getLinkStats _: attributeArray [
"Simulate the call to faFileStatAttributes().
The simulator uses a dictionary with keys named after the stat structure members."
| path primArray mask |
path := self faGetStPath: faPath.
mask := getLinkStats
ifTrue: [5] "lstat()"
ifFalse: [1]. "stat()"
primArray := self primFileAttributes: path mask: 1.
primArray isNumber ifTrue: [^primArray].
primArray doWithIndex: [ :entry :index |
interpreterProxy
storePointer: index - 1
ofObject: attributeArray
withValue: (self toOop: entry)].
^0
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faGetPlatPath: faPath [
"Answer the Plat format of the path.
In the simulation, actually answer the St format, this is required as the real primitive will eventually be called, which requires the St format."
^self faGetStPath: faPath
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faGetPlatPathByteCount: faPath [
"Answer the number of bytes in the platform specific encoding"
^(self faGetPlatPath: faPath) size
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faGetPlatformPath: faPath [
"Answer the Platform format of the path.
This isn't normally used within the simulation as the simulation ultimately calls the actual primitive, which requires the St format of the path."
| path |
path := (faPath at: 4) ifNil:
[faPath
at: 5 put: nil;
at: 4 put: (self primToPlatformPath: (self faGetStPath: faPath))].
(faPath at: 5) ifNotNil: [
path := path, (faPath at: 5)].
^path
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faGetStFile: faPath [
"Answer the basename of the path.
The simulated faPath contains the basename as the third entry in the Array."
^faPath at: 3
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faGetStPath: faPath [
"Answer the St format of the path."
| path |
path := faPath second.
faPath third ifNotNil: [
path := path, faPath third].
^path
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faGetStPathLen: faPath [
"Answer the length of the path."
^(self faGetStPath: faPath) size
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faInitSessionId: faPathPtr [
"Set the session id in the supplied pointer"
faPathPtr sessionId: interpreterProxy getThisSessionID.
^self faSuccess
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faInvalidateSessionId: faPathPtr [
"Clear the session ID in the faPathPtr, marking it invalid"
faPathPtr sessionId: nil.
^self faSuccess
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faOpenDirectory: faPath [
"Simulate the the call by actually calling the primitive and discarding the stat information (which will be retrieved again later in the simulation)."
| result status |
result := self primOpendir: (self faGetStPath: faPath).
result ifNotNil: [
faPath
at: 3 put: (result at: 1);
at: 6 put: (result at: 3).
status := 0 ]
ifNil: [status := self noMoreData].
^status
]
{ #category : #primitives }
FileAttributesPluginSimulator >> faPathMax [
"Answer the VMs FA_PATH_MAX value"
<primitive: 'primitivePathMax' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primPathMax'
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faPathPtr: faPath [
"Given the simulation faPath, answer the ByteArray pointing to the actual faPath"
^faPath at: 6
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faReadDirectory: faPath [
"Simulate the the call by actually calling the primitive and discarding the stat information (which will be retrieved again later in the simulation)."
| result status |
result := self primReaddir: (self faPathPtr: faPath).
result ifNotNil: [
faPath at: 3 put: (result at: 1).
status := 0 ]
ifNil: [status := self noMoreData].
^status
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faSessionId: faPath [
"Answer the session id of the current path"
^faPath first
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faSetPlatPathOop: faPath _: fileNameOop [
"Simulate setting the platform encoded file name in the supplied faPath."
| fileNameBytes len path stPath |
fileNameBytes := interpreterProxy arrayValueOf: fileNameOop.
len := interpreterProxy stSizeOf: fileNameOop.
path := ByteArray new: len.
self strncpy: path _: fileNameBytes _: len.
faPath
at: 4 put: path;
at: 5 put: nil.
stPath := self primFromPlatformPath: path.
faPath
at: 2 put: stPath;
at: 3 put: nil.
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faSetStDirOop: faPath _: dirOop [
"Simulate setting the dir name in the supplied faPath."
self faSetStPathOop: faPath _: dirOop.
faPath second last = FileSystem disk delimiter asciiValue ifFalse:
[faPath at: 2 put: (faPath second copyWith: FileSystem disk delimiter asciiValue)].
faPath at: 3 put: nil.
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faSetStPathOop: faPath _: fileNameOop [
"Set the St encoded path."
| fileNameBytes len path |
fileNameBytes := interpreterProxy arrayValueOf: fileNameOop.
self assert: faPath class == Array.
len := interpreterProxy stSizeOf: fileNameOop.
path := ByteArray new: len.
self strncpy: path _: fileNameBytes _: len.
faPath
at: 2 put: path;
at: 3 put: nil.
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faStat: faPath _: statBuf _: fileNameOop [
"Simulate the call to faStat().
The simulator uses a dictionary with keys named after the stat structure members."
| path primArray |
path := self faGetStPath: faPath.
primArray := self primFileAttributes: path mask: 1.
primArray isNumber ifTrue: [^primArray].
"First entry is fileName: **TODO**"
statBuf contents: primArray.
^0
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faValidatePath: faPath [
"The simulation currently doesn't keep track of the sessionId."
^(self faSessionId: faPath) = interpreterProxy getThisSessionID
]
{ #category : #simulation }
FileAttributesPluginSimulator >> faValidateSessionId: anInteger [
"Answer a boolean indicating whether the supplied session id matches the current one."
^anInteger = interpreterProxy getThisSessionID
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> fromOop: anOop [
| cls |
cls := self classOf: anOop.
cls = UndefinedObject ifTrue: [^nil].
cls = Array ifTrue: [^self arrayFromOop: anOop].
cls = ByteArray ifTrue: [^self byteArrayFromOop: anOop].
cls = ByteString ifTrue: [^self byteStringFromOop: anOop].
cls = LargePositiveInteger ifTrue: [^self largePositiveIntegerFromOop: anOop].
cls = SmallInteger ifTrue: [^self smallIntegerFromOop: anOop].
self error: 'Unknown class'.
]
{ #category : #'initialize-release' }
FileAttributesPluginSimulator >> initialize [
"Initialise the receiver for the current platform"
| masks |
masks := self primFileMasks.
S_IFMT := masks at: 1.
S_IFSOCK := masks at: 2.
S_IFLNK := masks at: 3.
S_IFREG := masks at: 4.
S_IFBLK := masks at: 5.
S_IFDIR := masks at: 6.
S_IFCHR := masks at: 7.
S_IFIFO := masks at: 8.
"Simulation has only been tested on Unix"
HAVE_LSTAT := true.
HAVE_CHMOD := true.
HAVE_CHOWN := true.
PATH_MAX := FA_PATH_MAX := self primPathMax.
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> largePositiveIntegerFromOop: anOop [
"Answer a copy of the supplied large positive integer Oop"
| sz array ptr |
sz := interpreterProxy stSizeOf: anOop.
ptr := interpreterProxy arrayValueOf: anOop.
array := ByteArray new: 8.
1 to: sz do: [ :i |
array at: i put: (interpreterProxy byteAt: ptr+i-1)].
^Integer
byte1: (array at: 1)
byte2: (array at: 2)
byte3: (array at: 3)
byte4: (array at: 4)
byte5: (array at: 5)
byte6: (array at: 6)
byte7: (array at: 7)
byte8: (array at: 8)
]
{ #category : #simulation }
FileAttributesPluginSimulator >> lchown: pathByteArray _: uidInteger _: gidInteger [
"Set the symlink owner and group of path by numeric id."
| status |
status := self primFile: pathByteArray symlinkUid: uidInteger gid: gidInteger.
"The real primitive answers nil on success, convert to C integer status"
^status ifNil: [0]
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> maxPathLen [
"Answer the maximum supported path length for the current platform"
^maxPathLen ifNil: [maxPathLen := self primPathMax]
]
{ #category : #private }
FileAttributesPluginSimulator >> objectFromStruct: anObject size: structSize [
"Copy the simulation path in to the simulated image"
^self toOop: anObject
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> pointerFrom: arrayOop [
"For the simulation, convert the supplied address to a ByteArray"
^self fromOop: arrayOop
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primClosedir: directoryPointerBytes [
"Close the directory stream associated with directoryPointerBytes.
Caution: do not call this twice on the same externalAddress."
"self primClosedir: (self primOpendir: '/etc')"
"self primClosedir: (self primOpendir: '/no/such/directory')"
<primitive: 'primitiveClosedir' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primClosedir'
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primExists: aByteArray [
"Answer a boolean indicating whether the supplied file exists."
<primitive: 'primitiveFileExists' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: aByteArray.
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primFile: pathByteArray posixPermissions: anInteger [
"Set the mode of pathByateArray to anInteger (as defined by chmod())"
<primitive: 'primitiveChangeMode' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: pathByteArray
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primFile: pathByteArray symlinkUid: uidInteger gid: gidInteger [
"Set the owner and group of path by numeric id."
<primitive: 'primitiveSymlinkChangeOwner' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: pathByteArray
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primFile: pathByteArray uid: uidInteger gid: gidInteger [
"Set the owner and group of path by numeric id."
<primitive: 'primitiveChangeOwner' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: pathByteArray
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primFileAttribute: aByteArray number: attributeNumber [
"Answer a single attribute for the supplied file.
For backward compatibility (on Unix) with FileReference if the file doesn't exist, and the specified path is a (broken) symbolic link, answer the requested attribute for the symbolic link.
stat() information:
1: name
2: mode
3: ino
4: dev
5: nlink
6: uid
7: gid
8: size
9: accessDate
10: modifiedDate
11: changeDate
12: creationDate
access() information
13: is readable
14: is writeable
15: is executable
symbolic link information
16: is symbolic link
"
<primitive: 'primitiveFileAttribute' module: 'FileAttributesPlugin' error: error>
"FilePlugin>>primitiveDirectoryEntry would return the symbolic link attributes if the symbolic link was broken. This was due to the incorrect implementation of attempting to retrieve symbolic link information.
If the old behaviour is required, the logic is:
(error isPrimitiveError and: [attributeNumber ~= 16 and: [error errorCode = self cantStatPath and: [
self platformSupportsSymbolicLinksEgUnix]]]) ifTrue:
[DiskSymlinkDirectoryEntry fileSystem: DiskStore currentFileSystem path: aString asPath]"
error isPrimitiveError ifTrue: [
(attributeNumber = 16 and: [ error errorCode = self unsupportedOperation ]) ifTrue:
"If symlinks aren't supported, answer false"
[ ^false ]].
^self signalError: error for: aByteArray
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primFileAttributes: aByteArray mask: attributeMask [
"Answer an array of attributes for the supplied file. The size and contents of the array are determined by the attributeMask:
Bit 0: stat() information
Bit 1: access() information
Bit 2: use lstat() (instead of stat())
On error, answer an error code (Integer).
stat() information:
1: name
2: mode
3: ino
4: dev
5: nlink
6: uid
7: gid
8: size
9: accessDate
10: modifiedDate
11: creationDate
access() information
1: is readable
2: is writeable
3: is executable
"
<primitive: 'primitiveFileAttributes' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: aByteArray
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primFileMasks [
"Answer an array of well known masks:
1: S_IFMT
2: S_IFSOCK
3: S_IFLNK
4: S_IFREG
5: S_IFBLK
6: S_IFDIR
7: S_IFCHR
8: S_IFIFO
For more information, see: http://man7.org/linux/man-pages/man2/stat.2.html
"
<primitive: 'primitiveFileMasks' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primFileMasks'
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primFromPlatformPath: aByteArray [
"Convert the supplied platform encoded string to the native (UTF8) equivalent"
<primitive: 'primitivePlatToStPath' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primToPlatformPath:'
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primOpendir: pathString [
"Answer an ExternalAddress for a directory stream on pathString, or nil if
the directory cannot be opened"
"self primOpendir: '/etc'"
"self primOpendir: '.'"
"self primOpendir: '/no/such/directory'"
<primitive: 'primitiveOpendir' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: pathString
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primPathMax [
"Answer the maximum path length for this platform"
<primitive: 'primitivePathMax' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primPathMax'
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primReaddir: directoryPointerBytes [
"Read the next directory entry from the directory stream associated with
directoryPointerBytes. Answer the name of the entry, ornil for end of directory stream."
"self primReaddir: (self primOpendir: '/etc')"
"self primReaddir: (self primOpendir: '/no/such/directory')"
<primitive: 'primitiveReaddir' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primReaddir:'
]
{ #category : #primitives }
FileAttributesPluginSimulator >> primToPlatformPath: aByteArray [
"Convert the supplied UTF8 encoded string to the platform encoded equivalent"
<primitive: 'primitiveStToPlatPath' module: 'FileAttributesPlugin' error: error>
^self signalError: error for: 'primToPlatformPath:'
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> s_IFDIR [
^S_IFDIR
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> s_IFMT [
^S_IFMT
]
{ #category : #primitives }
FileAttributesPluginSimulator >> signalError: error for: aByteArray [
"In the simulation, flag the interpreter as failing and return the error code"
error ifNil: [ ^interpreterProxy primitiveFail ].
error isSymbol ifTrue: [ ^interpreterProxy primitiveFailFor:
((SmalltalkImage current specialObjectsArray at: 52) indexOf: error) ].
error isPrimitiveError ifFalse: [
"We shouldn't ever get here"
^self primitiveFailed. ].
interpreterProxy primitiveFailForOSError: error errorCode.
^error errorCode.
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> simulatedFaPath [
"Answer the simulated faPath.
See class comments for details."
^Array new: self sizeOfFaPath.
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> smallIntegerFromOop: anOop [
"Answer a copy of the supplied large positive integer Oop"
^interpreterProxy integerValueOf: anOop
]
{ #category : #private }
FileAttributesPluginSimulator >> structFromObject: anOop size: structSize [
"Copy the object from the simulated image to the simulator.
At the moment, all objects are passed in Arrays with structSize elements."
| array |
array := self fromOop: anOop.
array isArray ifFalse: [^0].
array size = structSize ifFalse: [^0].
^array
]
{ #category : #'simulation support' }
FileAttributesPluginSimulator >> toOop: anObject [
"Convert the supplied simulation object to an object in the simulated image (oop).
Use a horrible series of class comparisons to keep it all local for now"
| resultOop resultBytes |
anObject class == Array ifTrue: [
resultOop := interpreterProxy
instantiateClass: interpreterProxy classArray
indexableSize: anObject size.
1 to: anObject size do: [ :i |
interpreterProxy
storePointer: i-1
ofObject: resultOop
withValue: (self toOop: (anObject at: i))].
^resultOop].
anObject class == ByteArray ifTrue: [
resultOop := interpreterProxy
instantiateClass: interpreterProxy classByteArray
indexableSize: anObject size.
resultBytes := interpreterProxy arrayValueOf: resultOop.
1 to: anObject size do: [ :i |
interpreterProxy byteAt: resultBytes+i-1 put: (anObject at: i)].
^resultOop].
(anObject isKindOf: Boolean) ifTrue: [
^anObject
ifTrue: [interpreterProxy trueObject]
ifFalse: [interpreterProxy falseObject].
].
anObject isInteger ifTrue: [
(anObject between: -2147483648 and: 2147483648) ifTrue:
[^interpreterProxy signed32BitIntegerFor: anObject].
^anObject > 0
ifTrue: [interpreterProxy positive64BitIntegerFor: anObject]
ifFalse: [interpreterProxy signed64BitIntegerFor: anObject]].
anObject == nil ifTrue:
[^interpreterProxy nilObject].
anObject class == FAPathPtr ifTrue: [
resultOop := interpreterProxy
instantiateClass: interpreterProxy classArray
indexableSize: 2.
interpreterProxy
storePointer: 0
ofObject: resultOop
withValue: (self toOop: anObject sessionId).
interpreterProxy
storePointer: 1
ofObject: resultOop
withValue: (self toOop: anObject faPath).
^resultOop].
self error: 'unknown object type'.
]