Skip to content

Commit

Permalink
Apple2: implement stat(2) and statvfs(3)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinleroy authored and oliverschmidt committed Jan 1, 2024
1 parent 4343eeb commit 75461e1
Show file tree
Hide file tree
Showing 23 changed files with 999 additions and 124 deletions.
64 changes: 64 additions & 0 deletions asminc/stat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
;****************************************************************************
;* *
;* stat.inc *
;* *
;* Stat struct *
;* *
;* *
;* *
;*(C) 2023 Colin Leroy-Mira <colin@colino.net> *
;* *
;* *
;*This software is provided 'as-is', without any expressed or implied *
;*warranty. In no event will the authors be held liable for any damages *
;*arising from the use of this software. *
;* *
;*Permission is granted to anyone to use this software for any purpose, *
;*including commercial applications, and to alter it and redistribute it *
;*freely, subject to the following restrictions: *
;* *
;*1. The origin of this software must not be misrepresented; you must not *
;* claim that you wrote the original software. If you use this software *
;* in a product, an acknowledgment in the product documentation would be *
;* appreciated but is not required. *
;*2. Altered source versions must be plainly marked as such, and must not *
;* be misrepresented as being the original software. *
;*3. This notice may not be removed or altered from any source *
;* distribution. *
;* *
;****************************************************************************

.include "time.inc"

;------------------------------------------------------------------------------
; st_mode values

S_IFDIR = $01
S_IFREG = $02

;------------------------------------------------------------------------------
; struct stat

.struct stat
st_dev .dword
st_ino .dword
st_mode .byte
st_nlink .dword
st_uid .byte
st_gid .byte
st_size .dword
st_atim .tag timespec
st_ctim .tag timespec
st_mtim .tag timespec
.ifdef __APPLE2__
st_access .byte
st_type .byte
st_auxtype .word
st_storagetype .byte
st_blocks .word
st_mod_date .word
st_mod_time .word
st_create_date .word
st_create_time .word
.endif
.endstruct
46 changes: 46 additions & 0 deletions asminc/statvfs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
;****************************************************************************
;* *
;* statvfs.inc *
;* *
;* Statvfs struct *
;* *
;* *
;* *
;*(C) 2023 Colin Leroy-Mira <colin@colino.net> *
;* *
;* *
;*This software is provided 'as-is', without any expressed or implied *
;*warranty. In no event will the authors be held liable for any damages *
;*arising from the use of this software. *
;* *
;*Permission is granted to anyone to use this software for any purpose, *
;*including commercial applications, and to alter it and redistribute it *
;*freely, subject to the following restrictions: *
;* *
;*1. The origin of this software must not be misrepresented; you must not *
;* claim that you wrote the original software. If you use this software *
;* in a product, an acknowledgment in the product documentation would be *
;* appreciated but is not required. *
;*2. Altered source versions must be plainly marked as such, and must not *
;* be misrepresented as being the original software. *
;*3. This notice may not be removed or altered from any source *
;* distribution. *
;* *
;****************************************************************************

;------------------------------------------------------------------------------
; struct statvfs

.struct statvfs
f_bsize .dword
f_frsize .dword
f_blocks .dword
f_bfree .dword
f_bavail .dword
f_files .dword
f_ffree .dword
f_favail .dword
f_fsid .dword
f_flag .dword
f_namemax .dword
.endstruct
37 changes: 35 additions & 2 deletions doc/apple2.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,15 @@ Programs containing Apple&nbsp;&rsqb;&lsqb; specific code may use the

<sect1>Apple&nbsp;&rsqb;&lsqb; specific functions<p>

The functions listed below are special for the Apple&nbsp;&rsqb;&lsqb;. See
the <url url="funcref.html" name="function reference"> for declaration and
The functions and variables listed below are special for the Apple&nbsp;&rsqb;&lsqb;.
See the <url url="funcref.html" name="function reference"> for declaration and
usage.

<itemize>
<item>_auxtype
<item>_dos_type
<item>_filetype
<item>_datetime
<item>get_ostype
<item>rebootafterexit
<item>ser_apple2_slot
Expand Down Expand Up @@ -569,6 +570,28 @@ program. See the discussion of the <tt/.CONDES/ feature in the <url
url="ca65.html" name="assembler manual">.


<sect1>ProDOS date/time manipulation<p>

<descrip>
The readdir and stat function return ProDOS timestamps in their file
creation/modification time attributes. You can convert them to more portable
time representations using either:

<tag/struct tm/
<tt/struct tm* __fastcall__ gmtime_dt (const struct datetime* dt);/

Converts a <tt/struct datetime/ into a <tt/struct tm/. Returns NULL in case
of error and sets errno.

<tag/time_t/
<tt/time_t __fastcall__ mktime_dt (const struct datetime* dt);/

Parses a <tt/struct datetime/ and returns a UNIX timestamp. Returns 0 on error and
sets errno.

</descrip>


<sect1>DIO<p>

<descrip>
Expand Down Expand Up @@ -630,6 +653,16 @@ url="ca65.html" name="assembler manual">.
that can be used to set these variables. It is included in
<tt/apple2.h/.

The global variable <tt/_datetime/ allows the file creation date/time
to be set before a call to <tt/fopen()/
or <tt/open()/ that creates the file. It is defined in <tt/apple2.h/:

<tscreen>
<verb>
extern struct datetime _datetime;
</verb>
</tscreen>

<tag>Example</tag>

A text file cannot be created with just the
Expand Down
39 changes: 36 additions & 3 deletions doc/apple2enh.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ Programs containing enhanced&nbsp;Apple&nbsp;//e specific code may use the

<sect1>Enhanced&nbsp;Apple&nbsp;//e specific functions<p>

The functions listed below are special for the enhanced&nbsp;Apple&nbsp;//e. See
the <url url="funcref.html" name="function reference"> for declaration and
The functions and variables listed below are special for the Apple&nbsp;&rsqb;&lsqb;.
See the <url url="funcref.html" name="function reference"> for declaration and
usage.

<itemize>
<item>_auxtype
<item>_dos_type
<item>_filetype
<item>_datetime
<item>get_ostype
<item>rebootafterexit
<item>ser_apple2_slot
Expand Down Expand Up @@ -575,6 +576,28 @@ program. See the discussion of the <tt/.CONDES/ feature in the <url
url="ca65.html" name="assembler manual">.


<sect1>ProDOS date/time manipulation<p>

<descrip>
The readdir and stat function return ProDOS timestamps in their file
creation/modification time attributes. You can convert them to more portable
time representations using either:

<tag/struct tm/
<tt/struct tm* __fastcall__ gmtime_dt (const struct datetime* dt);/

Converts a <tt/struct datetime/ into a <tt/struct tm/. Returns -1 in case
of error and sets errno, 0 on success.

<tag/time_t/
<tt/time_t __fastcall__ mktime_dt (const struct datetime* dt);/

Parses a <tt/struct datetime/ and returns a UNIX timestamp. Returns 0 on error and
sets errno.

</descrip>


<sect1>DIO<p>

<descrip>
Expand Down Expand Up @@ -619,7 +642,7 @@ url="ca65.html" name="assembler manual">.
auxiliary type. Therefore, some additional mechanism for specifying
the file types is needed.

<tag>Specifying the File Type and Auxiliary Type</tag>
<tag>Specifying the File Type, Auxiliary Type and creation date</tag>

There are two global variables provided that allow the file type
and auxiliary type to be specified before a call to <tt/fopen()/
Expand All @@ -636,6 +659,16 @@ url="ca65.html" name="assembler manual">.
that can be used to set these variables. It is included in
<tt/apple2.h/, which is in turn included in <tt/apple2enh.h/.

The global variable <tt/_datetime/ allows the file creation date/time
to be set before a call to <tt/fopen()/
or <tt/open()/ that creates the file. It is defined in <tt/apple2.h/:

<tscreen>
<verb>
extern struct datetime _datetime;
</verb>
</tscreen>

<tag>Example</tag>

A text file cannot be created with just the
Expand Down
Loading

0 comments on commit 75461e1

Please sign in to comment.