Apple2: implement stat(2) and statvfs(3)
This commit is contained in:
committed by
Oliver Schmidt
parent
4343eebe67
commit
75461e1319
@@ -41,6 +41,7 @@
|
||||
# error This module may only be used when compiling for the Apple ][!
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <apple2_filetype.h>
|
||||
|
||||
|
||||
@@ -142,6 +143,27 @@ extern unsigned char _dos_type;
|
||||
** ProDOS 8 2.4.x - 0x24
|
||||
*/
|
||||
|
||||
/* struct stat.st_mode values */
|
||||
#define S_IFDIR 0x01
|
||||
#define S_IFREG 0x02
|
||||
#define S_IFBLK 0xFF
|
||||
#define S_IFCHR 0xFF
|
||||
#define S_IFIFO 0xFF
|
||||
#define S_IFLNK 0xFF
|
||||
#define S_IFSOCK 0xFF
|
||||
|
||||
struct datetime {
|
||||
struct {
|
||||
unsigned day :5;
|
||||
unsigned mon :4;
|
||||
unsigned year :7;
|
||||
} date;
|
||||
struct {
|
||||
unsigned char min;
|
||||
unsigned char hour;
|
||||
} time;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -151,20 +173,10 @@ extern unsigned char _dos_type;
|
||||
|
||||
|
||||
/* The file stream implementation and the POSIX I/O functions will use the
|
||||
** following struct to set the date and time stamp on files. This specificially
|
||||
** following struct to set the date and time stamp on files. This specifically
|
||||
** applies to the open and fopen functions.
|
||||
*/
|
||||
extern struct {
|
||||
struct {
|
||||
unsigned day :5;
|
||||
unsigned mon :4;
|
||||
unsigned year :7;
|
||||
} createdate; /* Current date: 0 */
|
||||
struct {
|
||||
unsigned char min;
|
||||
unsigned char hour;
|
||||
} createtime; /* Current time: 0 */
|
||||
} _datetime;
|
||||
extern struct datetime _datetime;
|
||||
|
||||
/* The addresses of the static drivers */
|
||||
#if !defined(__APPLE2ENH__)
|
||||
@@ -211,6 +223,12 @@ void rebootafterexit (void);
|
||||
#define _cpeekcolor() COLOR_WHITE
|
||||
#define _cpeekrevers() 0
|
||||
|
||||
struct tm* __fastcall__ gmtime_dt (const struct datetime* dt);
|
||||
/* Converts a ProDOS date/time structure to a struct tm */
|
||||
|
||||
time_t __fastcall__ mktime_dt (const struct datetime* dt);
|
||||
/* Converts a ProDOS date/time structure to a time_t UNIX timestamp */
|
||||
|
||||
|
||||
|
||||
/* End of apple2.h */
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#ifndef _DIRENT_H
|
||||
#define _DIRENT_H
|
||||
|
||||
#include <target.h>
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -46,31 +48,15 @@ typedef struct DIR DIR;
|
||||
#if defined(__APPLE2__)
|
||||
|
||||
struct dirent {
|
||||
char d_name[16];
|
||||
unsigned d_ino;
|
||||
unsigned d_blocks;
|
||||
unsigned long d_size;
|
||||
unsigned char d_type;
|
||||
struct {
|
||||
unsigned day :5;
|
||||
unsigned mon :4;
|
||||
unsigned year :7;
|
||||
} d_cdate;
|
||||
struct {
|
||||
unsigned char min;
|
||||
unsigned char hour;
|
||||
} d_ctime;
|
||||
unsigned char d_access;
|
||||
unsigned d_auxtype;
|
||||
struct {
|
||||
unsigned day :5;
|
||||
unsigned mon :4;
|
||||
unsigned year :7;
|
||||
} d_mdate;
|
||||
struct {
|
||||
unsigned char min;
|
||||
unsigned char hour;
|
||||
} d_mtime;
|
||||
char d_name[16];
|
||||
unsigned d_ino;
|
||||
unsigned d_blocks;
|
||||
unsigned long d_size;
|
||||
unsigned char d_type;
|
||||
struct datetime d_ctime;
|
||||
unsigned char d_access;
|
||||
unsigned d_auxtype;
|
||||
struct datetime d_mtime;
|
||||
};
|
||||
|
||||
#define _DE_ISREG(t) ((t) != 0x0F)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* */
|
||||
/* stat.h */
|
||||
/* */
|
||||
/* Constants for the mode argument of open and creat */
|
||||
/* stat(2) definition */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
@@ -11,6 +11,9 @@
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* (C) 2023 Colin Leroy-Mira */
|
||||
/* EMail: 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 */
|
||||
@@ -36,6 +39,10 @@
|
||||
#ifndef _STAT_H
|
||||
#define _STAT_H
|
||||
|
||||
#include <time.h>
|
||||
#include <target.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -47,6 +54,30 @@
|
||||
#define S_IREAD 0x01
|
||||
#define S_IWRITE 0x02
|
||||
|
||||
#define S_IFMT 0x03
|
||||
|
||||
struct stat {
|
||||
dev_t st_dev;
|
||||
ino_t st_ino;
|
||||
mode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
off_t st_size;
|
||||
struct timespec st_atim;
|
||||
struct timespec st_ctim;
|
||||
struct timespec st_mtim;
|
||||
#ifdef __APPLE2__
|
||||
unsigned char st_access;
|
||||
unsigned char st_type;
|
||||
unsigned int st_auxtype;
|
||||
unsigned char st_storagetype;
|
||||
unsigned int st_blocks;
|
||||
struct datetime st_mtime;
|
||||
struct datetime st_ctime;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -55,5 +86,9 @@
|
||||
|
||||
|
||||
|
||||
int __fastcall__ stat (const char* pathname, struct stat* statbuf);
|
||||
|
||||
|
||||
|
||||
/* End of stat.h */
|
||||
#endif
|
||||
|
||||
74
include/sys/statvfs.h
Normal file
74
include/sys/statvfs.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* statvfs.h */
|
||||
/* */
|
||||
/* statvfs(3) definition */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2023 Colin Leroy-Mira */
|
||||
/* EMail: 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. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef _STATVFS_H
|
||||
#define _STATVFS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
struct statvfs {
|
||||
unsigned long f_bsize;
|
||||
unsigned long f_frsize;
|
||||
fsblkcnt_t f_blocks;
|
||||
fsblkcnt_t f_bfree;
|
||||
fsblkcnt_t f_bavail;
|
||||
fsfilcnt_t f_files;
|
||||
fsfilcnt_t f_ffree;
|
||||
fsfilcnt_t f_favail;
|
||||
unsigned long f_fsid;
|
||||
unsigned long f_flag;
|
||||
unsigned long f_namemax;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
int __fastcall__ statvfs (const char* pathname, struct statvfs* buf);
|
||||
|
||||
|
||||
|
||||
/* End of statvfs.h */
|
||||
#endif
|
||||
@@ -50,6 +50,46 @@
|
||||
typedef long int off_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_dev_t
|
||||
#define _HAVE_dev_t
|
||||
typedef unsigned long int dev_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_ino_t
|
||||
#define _HAVE_ino_t
|
||||
typedef unsigned long int ino_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_nlink_t
|
||||
#define _HAVE_nlink_t
|
||||
typedef unsigned long int nlink_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_uid_t
|
||||
#define _HAVE_uid_t
|
||||
typedef unsigned char uid_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_gid_t
|
||||
#define _HAVE_gid_t
|
||||
typedef unsigned char gid_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_mode_t
|
||||
#define _HAVE_mode_t
|
||||
typedef unsigned char mode_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_fsblkcnt_t
|
||||
#define _HAVE_fsblkcnt_t
|
||||
typedef unsigned long int fsblkcnt_t;
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_fsfilcnt_t
|
||||
#define _HAVE_fsfilcnt_t
|
||||
typedef unsigned long int fsfilcnt_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -60,6 +100,3 @@ typedef long int off_t;
|
||||
|
||||
/* End of types.h */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,15 @@
|
||||
#define _TIME_H
|
||||
|
||||
|
||||
/* Forward declaration for target.h */
|
||||
typedef unsigned long time_t;
|
||||
typedef unsigned long clock_t;
|
||||
|
||||
|
||||
|
||||
#include <target.h>
|
||||
|
||||
|
||||
|
||||
/* NULL pointer */
|
||||
#ifndef NULL
|
||||
@@ -49,9 +58,6 @@
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
|
||||
typedef unsigned long time_t;
|
||||
typedef unsigned long clock_t;
|
||||
|
||||
/* Structure for broken down time */
|
||||
struct tm {
|
||||
int tm_sec;
|
||||
|
||||
Reference in New Issue
Block a user