Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
9d/platform_amiga.c at master · bitplane/9d · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
bitplane
9d
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
9d
/
platform_amiga.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
324 lines (282 loc) · 8.13 KB
master
Breadcrumbs
9d
/
platform_amiga.c
Copy path
Top
File metadata and controls
Code
Blame
324 lines (282 loc) · 8.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include
"namespace.h"
#include
"platform.h"
#include
<dos/dosextens.h>
#include
<dos/dos.h>
#include
<exec/types.h>
#include
<proto/dos.h>
#include
<errno.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<sys/stat.h>
#include
<fcntl.h>
#include
<unistd.h>
#include
<utime.h>
int
platform_joinpath
(
char
*
dst
,
size_t
size
,
const
char
*
dir
,
const
char
*
name
) {
size_t
length
;
if
(!
dst
||
!
dir
||
!
name
||
!
size
)
return
-1
;
length
=
strlen
(
dir
);
if
(
length
&&
dir
[
length
-
1
]
==
':'
) {
while
(
*
name
==
'/'
)
name
++
;
return
snprintf
(
dst
,
size
,
"%s%s"
,
dir
,
name
) >= (
int
)
size
?
-1
:
0
;
}
return
joinpath
(
dst
,
size
,
dir
,
name
);
}
typedef
struct
VolumeName
{
struct
VolumeName
*
next
;
char
name
[
256
];
}
VolumeName
;
static
BPTR
native_root
;
void
platform_namespace_cleanup
(
Namespace
*
ns
) {
(
void
)
ns
;
if
(
native_root
) {
UnLock
(
native_root
);
native_root
=
BNULL
;
}
}
int
platform_namespace_ready
(
Namespace
*
ns
) {
platform_namespace_cleanup
(
ns
);
if
(!
ns
->
synthetic
) {
native_root
=
Lock
((
STRPTR
)
ns
->
native_root
,
ACCESS_READ
);
if
(!
native_root
) {
errno
=
EACCES
;
return
-1
;
}
return
0
;
}
return
0
;
}
static
void
free_names
(
VolumeName
*
names
) {
while
(
names
) {
VolumeName
*
next
=
names
->
next
;
free
(
names
);
names
=
next
;
}
}
static
VolumeName
*
snapshot_names
(
int
*
success
) {
struct
DosList
*
list
;
struct
DosList
*
entry
;
VolumeName
*
head
=
NULL
;
VolumeName
*
*
tail
=
&
head
;
*
success
=
0
;
list
=
LockDosList
(
LDF_VOLUMES
|
LDF_READ
);
if
(!
list
)
return
NULL
;
entry
=
list
;
while
((
entry
=
NextDosEntry
(
entry
,
LDF_VOLUMES
))
!=
NULL
) {
const
char
*
name
=
AROS_BSTR_ADDR
(
entry
->
dol_Name
);
size_t
length
=
AROS_BSTR_strlen
(
entry
->
dol_Name
);
VolumeName
*
volume
;
if
(
length
>=
sizeof
(
volume
->
name
))
continue
;
volume
=
malloc
(
sizeof
(
*
volume
));
if
(!
volume
) {
UnLockDosList
(
LDF_VOLUMES
|
LDF_READ
);
free_names
(
head
);
return
NULL
;
}
memcpy
(
volume
->
name
,
name
,
length
);
volume
->
name
[
length
]
=
'\0'
;
volume
->
next
=
NULL
;
*
tail
=
volume
;
tail
=
&
volume
->
next
;
}
UnLockDosList
(
LDF_VOLUMES
|
LDF_READ
);
*
success
=
1
;
return
head
;
}
int
platform_namespace_init
(
Namespace
*
ns
) {
return
namespace_use_synthetic
(
ns
);
}
int
platform_namespace_discover
(
Namespace
*
ns
) {
VolumeName
*
names
;
VolumeName
*
volume
;
int
success
;
names
=
snapshot_names
(
&
success
);
if
(!
success
)
return
-1
;
for
(
volume
=
names
;
volume
;
volume
=
volume
->
next
) {
char
path
[
258
];
struct
stat
st
;
if
(
snprintf
(
path
,
sizeof
(
path
),
"%s:"
,
volume
->
name
) >= (
int
)
sizeof
(
path
))
continue
;
if
(
stat
(
path
,
&
st
)
<
0
||
!
S_ISDIR
(
st
.
st_mode
))
continue
;
if
(
namespace_add_root
(
ns
,
volume
->
name
,
path
)
<
0
) {
fprintf
(
stderr
,
"Cannot export Amiga volume %s: %s\n"
,
volume
->
name
,
strerror
(
errno
));
free_names
(
names
);
return
-1
;
}
}
free_names
(
names
);
return
0
;
}
static
int
parent_is_exported
(
const
ResolvedPath
*
path
) {
const
char
*
root_name
=
namespace
.
synthetic
?
path
->
root_path
:
namespace
.
native_root
;
char
parent
[
S9_PATH_MAX
];
char
*
slash
;
BPTR
root
;
BPTR
current
;
int
allowed
=
0
;
if
(!
path
->
relative_path
[
0
])
return
1
;
if
(
strlen
(
path
->
native_path
) >=
sizeof
(
parent
)) {
errno
=
ENAMETOOLONG
;
return
0
;
}
strcpy
(
parent
,
path
->
native_path
);
slash
=
strrchr
(
parent
,
'/'
);
if
(
slash
)
*
slash
=
'\0'
;
else
strcpy
(
parent
,
root_name
);
root
=
namespace
.
synthetic
?
Lock
((
STRPTR
)
root_name
,
ACCESS_READ
)
:
DupLock
(
native_root
);
current
=
Lock
((
STRPTR
)
parent
,
ACCESS_READ
);
if
(!
root
||
!
current
)
goto
done
;
for
(;;) {
BPTR
next
;
if
(
SameLock
(
root
,
current
)
==
LOCK_SAME
) {
allowed
=
1
;
break
;
}
next
=
ParentDir
(
current
);
UnLock
(
current
);
current
=
next
;
if
(!
current
)
break
;
}
done
:
if
(
current
)
UnLock
(
current
);
if
(
root
)
UnLock
(
root
);
if
(!
allowed
)
errno
=
EPERM
;
return
allowed
;
}
int
platform_lstat
(
const
ResolvedPath
*
path
,
struct
stat
*
st
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
lstat
(
path
->
native_path
,
st
);
}
int
platform_fstat
(
int
fd
,
const
ResolvedPath
*
path
,
const
struct
stat
*
opened
,
struct
stat
*
st
) {
(
void
)
path
;
(
void
)
opened
;
return
fstat
(
fd
,
st
);
}
int
platform_lstat_child
(
PlatformDir
*
directory
,
const
ResolvedPath
*
path
,
const
char
*
name
,
struct
stat
*
st
) {
(
void
)
directory
;
(
void
)
name
;
return
platform_lstat
(
path
,
st
);
}
int
platform_open
(
const
ResolvedPath
*
path
,
int
flags
,
mode_t
mode
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
open
(
path
->
native_path
,
flags
,
mode
);
}
PlatformDir
*
platform_opendir
(
const
ResolvedPath
*
path
) {
if
(!
parent_is_exported
(
path
))
return
NULL
;
return
opendir
(
path
->
native_path
);
}
int
platform_fstatdir
(
PlatformDir
*
directory
,
struct
stat
*
st
) {
(
void
)
directory
;
(
void
)
st
;
errno
=
ENOTSUP
;
return
-1
;
}
struct
dirent
*
platform_readdir
(
PlatformDir
*
directory
) {
return
readdir
(
directory
);
}
long
platform_telldir
(
PlatformDir
*
directory
) {
return
telldir
(
directory
);
}
void
platform_seekdir
(
PlatformDir
*
directory
,
long
position
) {
seekdir
(
directory
,
position
);
}
void
platform_rewinddir
(
PlatformDir
*
directory
) {
rewinddir
(
directory
);
}
int
platform_closedir
(
PlatformDir
*
directory
) {
return
closedir
(
directory
);
}
ssize_t
platform_readlink
(
const
ResolvedPath
*
path
,
char
*
buffer
,
size_t
size
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
readlink
(
path
->
native_path
,
buffer
,
size
);
}
int
platform_access_execute
(
const
ResolvedPath
*
path
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
access
(
path
->
native_path
,
X_OK
);
}
int
platform_mkdir
(
const
ResolvedPath
*
path
,
mode_t
mode
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
mkdir
(
path
->
native_path
,
mode
);
}
int
platform_symlink
(
const
char
*
target
,
const
ResolvedPath
*
path
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
symlink
(
target
,
path
->
native_path
);
}
int
platform_mknod
(
const
ResolvedPath
*
path
,
mode_t
mode
,
unsigned
major
,
unsigned
minor
) {
(
void
)
mode
;
(
void
)
major
;
(
void
)
minor
;
if
(!
parent_is_exported
(
path
))
return
-1
;
errno
=
EOPNOTSUPP
;
return
-1
;
}
int
platform_remove
(
const
ResolvedPath
*
path
,
int
directory
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
directory
?
rmdir
(
path
->
native_path
) :
unlink
(
path
->
native_path
);
}
int
platform_rename
(
const
ResolvedPath
*
old_path
,
const
ResolvedPath
*
new_path
) {
if
(!
parent_is_exported
(
old_path
)
||
!
parent_is_exported
(
new_path
))
return
-1
;
return
rename
(
old_path
->
native_path
,
new_path
->
native_path
);
}
int
platform_chmod
(
const
ResolvedPath
*
path
,
mode_t
mode
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
chmod
(
path
->
native_path
,
mode
);
}
int
platform_chown
(
const
ResolvedPath
*
path
,
uid_t
uid
,
gid_t
gid
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
chown
(
path
->
native_path
,
uid
,
gid
);
}
int
platform_device_spec
(
const
struct
stat
*
st
,
char
*
buffer
,
size_t
size
) {
(
void
)
st
;
(
void
)
buffer
;
(
void
)
size
;
errno
=
EINVAL
;
return
-1
;
}
int
platform_set_times
(
const
ResolvedPath
*
path
,
time_t
atime
,
time_t
mtime
) {
struct
utimbuf
times
;
if
(!
parent_is_exported
(
path
))
return
-1
;
times
.
actime
=
atime
;
times
.
modtime
=
mtime
;
return
utime
(
path
->
native_path
,
&
times
);
}
int
platform_truncate
(
const
ResolvedPath
*
path
,
off_t
length
) {
if
(!
parent_is_exported
(
path
))
return
-1
;
return
truncate
(
path
->
native_path
,
length
);
}
You can’t perform that action at this time.