#ifndef _S256_DISK_ #define _S256_DISK_ #define TRUE 1 #define FALSE 0 typedef unsigned char byte; typedef unsigned short word; typedef unsigned long dword; typedef int BOOLEAN; #define KS_FAR far /* Derived types. These are derived from the values above and should not be changed */ typedef byte KS_FAR * PFBYTE; typedef int KS_FAR * PFINT; typedef word KS_FAR * PFWORD; typedef long KS_FAR * PFLONG; typedef dword KS_FAR * PFDWORD; typedef char KS_FAR * PFCHAR; typedef void KS_FAR * PFVOID; #define KS_CONSTANT const typedef KS_CONSTANT char KS_FAR * PFCCHAR; typedef KS_CONSTANT byte KS_FAR * PFCBYTE; typedef int PCFD; /* file desc */ #if (VFAT) #define EMAXPATH 260 /* Maximum path length. Change if you like */ #else #define EMAXPATH 148 /* Maximum path length. Change if you like */ #endif #if (FAT32) typedef unsigned long CLUSTERTYPE; #else typedef unsigned short CLUSTERTYPE; #endif #if (USE_MEM_MAPPED_IO) typedef volatile unsigned char * IOADDRESS; /* Memory mapped IO */ #else typedef unsigned short IOADDRESS; /* IO mapped IO */ #endif /* Parameter block for formatting: Used by format.c */ typedef struct fmtparms { char oemname[9]; /* Only first 8 bytes are used */ byte secpalloc; /* Sectors per cluster */ word secreserved; /* Reserved sectors before the FAT */ byte numfats; /* Number of FATS on the disk */ #if (FAT32) dword secpfat; /* Sectors per fat */ byte fmttype; /* As defined below */ #define FMT_FAT32 0x01 #define FMT_DOS 0x00 #else word secpfat; /* Sectors per fat */ #endif dword numhide; /* Hidden sectors */ word numroot; /* Maximum # of root dir entries */ byte mediadesc; /* Media descriptor byte */ word secptrk; /* sectors per track */ word numhead; /* number of heads */ word numcyl; /* number of cylinders */ byte physical_drive_no; dword binary_volume_label; char text_volume_label[12]; } FMTPARMS; typedef struct dev_geometry { int dev_geometry_heads; //- Must be < 256 dword dev_geometry_cylinders; //- Must be < 1024 int dev_geometry_secptrack; //- Must be < 64 dword dev_geometry_lbas; //- For oversize media BOOLEAN fmt_parms_valid; //If the device io control call sets this //TRUE then it it telling the applications //layer that these format parameters should //be used. This is a way to format floppy //disks exactly as they are fromatted by dos. FMTPARMS fmt; } DEV_GEOMETRY; #define ARDONLY 0x1 /* MS-DOS File attributes */ #define AHIDDEN 0x2 #define ASYSTEM 0x4 #define AVOLUME 0x8 #define ADIRENT 0x10 #define ARCHIVE 0x20 #define ANORMAL 0x00 #define CHICAGO_EXT 0x0f /* Chicago extended filename attribute */ /* Date stamping buffer */ typedef struct datestr { word date; word time; } DATESTR; /* Structure for use by pc_gfirst, pc_gnext */ typedef struct dstat { char fname[9]; /* Null terminated file and extension */ char fext[4]; #if (VFAT) byte lfname[FILENAMESIZE]; /* Long file name fro vfat. */ #endif char filename[15]; /* Null terminated file.ext */ byte fattribute; /* File attributes */ word ftime; /* time & date lastmodified. See date */ word fdate; /* and time handlers for getting info */ dword fsize; /* File size */ /* INTERNAL */ int driveno; byte pname[9]; /* Pattern. */ byte pext[4]; char path[EMAXPATH]; void *pobj; /* Info for getting at the inode */ void *pmom; /* Info for getting at parent inode */ } DSTAT; /* Structure for use by pc_stat and pc_fstat */ /* Portions of this structure and the macros were lifted from BSD sources. See the RTFS ANSI library for BSD terms & conditions */ typedef struct stat { int st_dev; /* (drive number, rtfs) */ int st_ino; /* inode number (0) */ dword st_mode; /* (see S_xxxx below) */ int st_nlink; /* (always 1) */ int st_rdev; /* (drive number, rtfs) */ dword st_size; /* file size, in bytes */ DATESTR st_atime; /* last access (all times are the same) */ DATESTR st_mtime; /* last modification */ DATESTR st_ctime; /* last file status change */ long st_blksize; /* optimal blocksize for I/O (cluster size) */ long st_blocks; /* blocks allocated for file */ byte fattribute; /* File attributes - DOS attributes (non standard but useful) */ } STAT; typedef unsigned long int BLOCKT; /* 32 BIT unsigned */ /* Structure used to track cached fat blocks */ typedef struct fatswap { word n_to_swap; /* Next to swap. For implementing round robin */ /* These two counters track cache usage as we fill it. Eventually the FAT fills and we go into swapping mode at steady state */ word n_blocks_used; /* How many blocks in the cache have we used */ word n_blocks_total; /* How many blocks are available in the cache */ BOOLEAN block_0_is_valid; /* If TRUE then data_map[0] contains the offset of the first block of the FAT */ #if (FAT_BUFFER_SIZE > 63) /* This should work on systems with 32 bit integers and segments but we'll leave it as an option for now */ byte pdirty[FAT_BUFFER_SIZE/8]; byte data_map[FAT_BUFFER_SIZE*4]; #else byte pdirty[32]; /* BIT-map of blocks needing flushing */ byte data_map[256]; /* Table that maps block numbers in the fat to block offsets in our data array. zero means the block is not mapped. Except.. data_map[0] contains block zero of the FAT which is at location 0 in the data array */ #endif PFBYTE data_array; /* Block buffer area */ } FATSWAP; /* Structure to contain block 0 image from the disk */ typedef struct ddrive { BOOLEAN mount_valid; /* True if valid volume and BLOCK 0, fat buffer, block pool etc are valid */ dword volume_serialno; /* Volume serial number block 0 */ byte volume_label[14]; /* Volume entry from block 0 */ word bytespcluster; /* */ dword byte_into_cl_mask; /* And this with file pointer to get the byte offset into the cluster */ word fasize; /* Nibbles per fat entry. (2 or 4) */ BLOCKT rootblock; /* First block of root dir */ BLOCKT firstclblock; /* First block of cluster area */ word driveno; /* Driveno. Set when open succeeds */ CLUSTERTYPE maxfindex; /* Last element in the fat - FAT32*/ BLOCKT fatblock; /* First block in fat */ word secproot; /* blocks in root dir */ BOOLEAN fat_is_dirty; FATSWAP fat_swap_structure; /* Fat swap structure if swapping */ dword bootaddr; char oemname[9]; word bytspsector; /* Must be 512 for this implementation */ byte secpalloc; /* Sectors per cluster */ word log2_secpalloc; /* Log of sectors per cluster */ word secreserved; /* Reserved sectors before the FAT */ byte numfats; /* Number of FATS on the disk */ word numroot; /* Maximum # of root dir entries */ BLOCKT numsecs; /* Total # sectors on the disk */ byte mediadesc; /* Media descriptor byte */ CLUSTERTYPE secpfat; /* Size of each fat */ word secptrk; /* sectors per track */ word numhead; /* number of heads */ BLOCKT numhide; /* # hidden sectors */ CLUSTERTYPE free_contig_base; /* Guess of where file data would most */ CLUSTERTYPE free_contig_pointer;/* Efficiently stored */ #if (FAT32) long known_free_clusters;/* If non-zero pc_free may use this value - FAT32 */ word infosec; #else word known_free_clusters;/* If non-zero pc_free may use this value */ #endif // NEWNEW // These arent new but they are moved to this section because they play a larger // role. These values are loaded by the routine pc_read_partition_table(). And // used by formatting and read/write routines. BLOCKT partition_base; /* Start of the partition */ dword partition_size; /* Size of the partition */ int partition_type; /* Partition type */ int begin_user_area; /* Beyond this is initialized at run time and must not be written by ertfs */ /* user init is required for the following elements required */ IOADDRESS register_file_address; int interrupt_number; // note -1 is polled for IDE /* Flags - These must be set by the pc_ertfs_init */ #define DRIVE_FLAGS_PARTITIONED 0x0002 /* Partitioned device */ #define DRIVE_FLAGS_PCMCIA 0x0004 /* Pcmcia device */ #define DRIVE_FLAGS_PCMCIA_ATA 0x0008 /* Flags - These must be set by the warmstrt IOCTL call to the driver */ #define DRIVE_FLAGS_VALID 0x0001 /* Flags have been set */ #define DRIVE_FLAGS_REMOVABLE 0x0040 /* Device is removable */ #define DRIVE_FLAGS_INSERTED 0x0080 /* Device drivers use to remember states */ #define DRIVE_FLAGS_CDFS 0x0100 /* VALID is set by the device driver as a result of a successful call to the device ioctl call DEVCTL_WARMSTART. If the driver does not set this flag then it i assumed that the driver probe or init sequence failed */ word drive_flags; int partition_number; int lock_unit; int pcmcia_slot_number; int pcmcia_controller_number; byte pcmcia_cfg_opt_value; int controller_number; int logical_unit_number; /* These two routines are attached to device driver specific routines */ BOOLEAN (*dev_table_drive_io)(int driveno, dword sector, void KS_FAR *buffer, word count, BOOLEAN readin); int (*dev_table_perform_device_ioctl)(int driveno, int opcode, PFVOID arg); /* end user init required */ } DDRIVE; /* File seg info structure. An array of these structures is passed to pc_get_file_extents(). The extents of the file are returned in this array */ typedef struct fileseginfo { long block; /* Block number of the current extent */ long nblocks; /* Number of blocks in the extent */ } FILESEGINFO; /* Free list info structure. An array of these structures is passed to pc_get_free_list(). The list of free clusters is returned in this array */ typedef struct freelistinfo { dword cluster; /* Cluster where the free region starts */ long nclusters; /* Number of free clusters the free segment */ } FREELISTINFO; /* Values for the st_mode field */ #define S_IFMT 0170000 /* type of file mask */ #define S_IFCHR 0020000 /* character special (unused) */ #define S_IFDIR 0040000 /* directory */ #define S_IFBLK 0060000 /* block special (unused) */ #define S_IFREG 0100000 /* regular */ #define S_IWRITE 0000400 /* Write permitted */ #define S_IREAD 0000200 /* Read permitted. (Always true anyway)*/ #define DEFFILEMODE (S_IREAD|S_IWRITE) #define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */ #define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */ #define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */ #define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */ #define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */ /* Error codes */ #define PCERR_FAT_FLUSH 0 /*Cant flush FAT */ #define PCERR_INITMEDI 1 /*Not a DOS disk:pc_dskinit */ #define PCERR_INITDRNO 2 /*Invalid driveno to pc_dskinit */ #define PCERR_INITCORE 3 /*Out of core:pc_dskinit */ #define PCERR_INITDEV 4 /*Can't initialize device:pc_dskinit */ #define PCERR_INITREAD 5 /*Can't read block 0:pc_dskinit */ #define PCERR_BLOCKCLAIM 6 /*PANIC: Buffer Claim */ #define PCERR_BLOCKLOCK 7 /*Warning: freeing a locked buffer */ #define PCERR_REMINODE 8 /*Trying to remove inode with open > 1 */ #define PCERR_FATREAD 9 /* "IO Error While Failed Reading FAT" */ #define PCERR_DROBJALLOC 10 /* "Memory Failure: Out of DROBJ Structures" */ #define PCERR_FINODEALLOC 11 /* "Memory Failure: Out of FINODE Structures" */ /* File creation permissions for open */ /* Note: OCTAL */ #define PS_IWRITE 0000400 /* Write permitted */ #define PS_IREAD 0000200 /* Read permitted. (Always true anyway)*/ /* File access flags */ #define PO_RDONLY 0x0000 /* Open for read only*/ #define PO_WRONLY 0x0001 /* Open for write only*/ #define PO_RDWR 0x0002 /* Read/write access allowed.*/ #define PO_APPEND 0x0008 /* Seek to eof on each write*/ #define PO_CREAT 0x0100 /* Create the file if it does not exist.*/ #define PO_TRUNC 0x0200 /* Truncate the file if it already exists*/ #define PO_EXCL 0x0400 /* Fail if creating and already exists*/ #define PO_TEXT 0x4000 /* Ignored*/ #define PO_BINARY 0x8000 /* Ignored. All file access is binary*/ #define PO_NOSHAREANY 0x0004 /* Wants this open to fail if already open. Other opens will fail while this open is active */ #define PO_NOSHAREWRITE 0x0800 /* Wants this opens to fail if already open for write. Other open for write calls will fail while this open is active. */ /* Errno values */ #define PEBADF 9 /* Invalid file descriptor*/ #define PENOENT 2 /* File not found or path to file not found*/ #define PEMFILE 24 /* No file descriptors available (too many files open)*/ #define PEEXIST 17 /* Exclusive access requested but file already exists.*/ #define PEACCES 13 /* Attempt to open a read only file or a special (directory)*/ #define PEINVAL 22 /* Seek to negative file pointer attempted.*/ #define PENOSPC 28 /* Write failed. Presumably because of no space*/ #define PESHARE 30 /* Open failed do to sharing */ #define PEDEVICE 31 /* No Valid Disk Present */ #define PEBADDIR 32 /* DELTREE -- Directory structure corrupt */ #if (INCLUDE_UDMA) #define PEALIGN 34 /* Dest buffer not aligned as required (i.e. word boundary, etc). */ #define PEDMADSC 35 /* Not enough Ultra DMA descriptors */ # endif //#if (INCLUDE_UDMA) /* Arguments to SEEK */ #define PSEEK_SET 0 /* offset from begining of file*/ #define PSEEK_CUR 1 /* offset from current file pointer*/ #define PSEEK_END 2 /* offset from end of file*/ /* Arguments to po_extend_file */ #define PC_FIRST_FIT 1 #define PC_BEST_FIT 2 #define PC_WORST_FIT 3 #define PC_FIXED_FIT 4 /* Arguments to critical_error_handler() */ #define CRERR_BAD_FORMAT 1 #define CRERR_NO_CARD 2 #define CRERR_BAD_CARD 3 #define CRERR_CHANGED_CARD 4 #define CRERR_CARD_FAILURE 5 /* Return code from critical_error_handler() */ #define CRITICAL_ERROR_ABORT 1 #define CRITICAL_ERROR_RETRY 2 #define CRITICAL_ERROR_FORMAT 3 #define CRITICAL_ERROR_CLEARECC 4 // File API.C: BOOLEAN pc_diskflush(char *path); BOOLEAN pc_mkdir(char *name); PCFD pc_open(char *name, word flag, word mode);// int pc_read(PCFD fd, byte *buf, word count);// int pc_write(PCFD fd, byte *buf, word count); // long pc_lseek(PCFD fd, long offset, int origin);// BOOLEAN pc_truncate(PCFD fd, long offset);// BOOLEAN pc_flush(PCFD fd);// int pc_close(PCFD fd); // BOOLEAN pc_mv(char *name, char *newname); BOOLEAN pc_unlink(char *name); BOOLEAN pc_rmdir(char *name); BOOLEAN pc_deltree(char *name); long pc_free(char *path, dword *blocks_total, dword *blocks_free); BOOLEAN pc_gfirst(DSTAT *statobj, char *name); BOOLEAN pc_gnext(DSTAT *statobj); void pc_gdone(DSTAT *statobj); BOOLEAN pc_set_default_drive(char *drive); BOOLEAN pc_setdfltdrvno(int driveno); int pc_getdfltdrvno(void); BOOLEAN pc_set_cwd(char *name); BOOLEAN pc_isdir(char *path); BOOLEAN pc_isvol(char *path); BOOLEAN pc_pwd(char *drive, char *path); int pc_fstat(PCFD fd, STAT *pstat); int pc_stat(char *name, STAT *pstat); BOOLEAN pc_get_attributes(char *path, byte *p_return); BOOLEAN pc_set_attributes(char *path, byte attributes); int pc_cluster_size(char *drive); long pc_extend_file(PCFD fd, long n_bytes, long start_cluster, int method);// int pc_get_file_extents(PCFD fd, int infolistsize, FILESEGINFO *plist, BOOLEAN raw); int pc_raw_read(int driveno, byte *buf, long blockno, int nblocks, BOOLEAN raw_io); int pc_raw_write(int driveno, byte *buf, long blockno, int nblocks, BOOLEAN raw_io); int pc_get_free_list(int driveno, int listsize, FREELISTINFO *plist, long threshhold); int po_chsize(PCFD fd, long offset); byte *pc_mfile(byte *to, byte *filename, byte *ext); byte *pc_mpath(byte *to, byte *path, byte *filename); char *pc_parsedrive(int *driveno, char *path); int pc_parse_raw_drive(char *path); DDRIVE *pc_drno_to_drive_struct(int driveno); BOOLEAN check_media(int driveno, BOOLEAN ok_to_automount, BOOLEAN raw_access_requested, BOOLEAN call_crit_err); typedef struct dev_geometry KS_FAR *PDEV_GEOMETRY; BOOLEAN pc_get_media_parms(char *path, PDEV_GEOMETRY pgeometry); BOOLEAN pc_format_media(char *path, PDEV_GEOMETRY pgeometry); BOOLEAN pc_partition_media(char *path, PDEV_GEOMETRY pgeometry, PFDWORD partition_list); BOOLEAN pc_format_volume(char *path, PDEV_GEOMETRY pgeometry); int get_errno(void); BOOLEAN pc_set_ftime(char *path, DATESTR date); /* UTIL.C */ /* Ansi replacements for functions in util. Take these out if you don't have ansi */ #include #include void copybuff(void *vto, void *vfrom, int size); void pc_memfill(void *vto, int size, byte c); //#define tc_strcpy strcpy //#define tc_strcmp strcmp //#define tc_strlen strlen //#define tc_strcat strcat //#define tc_atoi atoi //#define tc_atol atol //#if (defined(ERTFS_SA)) //int tc_strcpy(PFCHAR targ, PFCCHAR src); //int tc_strcmp(PFCCHAR s1, PFCCHAR s2); //int tc_strlen(PFCCHAR string); //PFCHAR tc_strcat(PFCHAR targ, PFCCHAR src); //int tc_isdigit(char ch); //int tc_atoi(PFCHAR s); //long tc_atol(PFCHAR s); //void tc_memset(PFBYTE p, byte b, int n); //#endif /* -------------------------------------- */ BOOLEAN pc_ertfs_init(void); int RAM_Init(void); #endif