From b6d423a1b3ab80703f2ae03e30fe039c59477e9a Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Sun, 18 Nov 2001 14:01:12 +0000 Subject: [PATCH] Ran all .c and .h files through "indent" git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@329 6ac86273-5f31-0410-b378-82cca8765d1b --- hdr/algnbyte.h | 22 +- hdr/buffer.h | 19 +- hdr/cds.h | 27 +- hdr/clock.h | 7 +- hdr/date.h | 3 +- hdr/dcb.h | 44 +- hdr/device.h | 266 ++++---- hdr/dirmatch.h | 22 +- hdr/dosnames.h | 9 +- hdr/error.h | 6 +- hdr/exe.h | 10 +- hdr/fat.h | 23 +- hdr/fcb.h | 22 +- hdr/file.h | 4 +- hdr/fnode.h | 24 +- hdr/kbd.h | 10 +- hdr/kconfig.h | 22 +- hdr/mcb.h | 9 +- hdr/network.h | 20 +- hdr/nls.h | 236 ++++--- hdr/pcb.h | 49 +- hdr/portab.h | 91 ++- hdr/process.h | 80 +-- hdr/sft.h | 47 +- hdr/tail.h | 10 +- hdr/time.h | 4 +- hdr/version.h | 7 +- hdr/xstructs.h | 80 ++- kernel/blockio.c | 297 ++++----- kernel/break.c | 6 +- kernel/chario.c | 85 +-- kernel/config.c | 1177 ++++++++++++++++----------------- kernel/config.h | 7 +- kernel/dosfns.c | 1333 +++++++++++++++++++------------------ kernel/dosnames.c | 120 ++-- kernel/dsk.c | 1170 +++++++++++++++++---------------- kernel/dyndata.c | 4 +- kernel/dyndata.h | 6 +- kernel/dyninit.c | 69 +- kernel/error.c | 32 +- kernel/fatdir.c | 229 +++---- kernel/fatfs.c | 818 ++++++++++++----------- kernel/fattab.c | 188 +++--- kernel/fcbfns.c | 148 +++-- kernel/globals.h | 196 ++---- kernel/init-dat.h | 32 +- kernel/init-mod.h | 112 ++-- kernel/initdisk.c | 1608 ++++++++++++++++++++++----------------------- kernel/inithma.c | 678 ++++++++++--------- kernel/initoem.c | 6 +- kernel/inthndlr.c | 1304 ++++++++++++++++++------------------ kernel/intr.h | 4 +- kernel/ioctl.c | 165 +++-- kernel/lfnapi.c | 227 ++++--- kernel/main.c | 331 +++++----- kernel/memmgr.c | 248 ++++--- kernel/misc.c | 4 +- kernel/network.c | 4 +- kernel/newstuff.c | 473 +++++++------ kernel/nls.c | 616 ++++++++--------- kernel/nls_load.c | 449 +++++++------ kernel/prf.c | 454 ++++++------- kernel/proto.h | 152 +++-- kernel/strings.c | 4 +- kernel/sysclk.c | 106 ++- kernel/syspack.c | 6 +- kernel/systime.c | 78 +-- kernel/task.c | 721 ++++++++++---------- sys/bin2c.c | 3 +- sys/fdkrncfg.c | 379 ++++++----- sys/sys.c | 493 +++++++------- utils/patchobj.c | 294 ++++----- utils/relocinf.c | 205 +++--- 73 files changed, 8037 insertions(+), 8177 deletions(-) diff --git a/hdr/algnbyte.h b/hdr/algnbyte.h index 55d1c3d..4040b41 100644 --- a/hdr/algnbyte.h +++ b/hdr/algnbyte.h @@ -1,14 +1,14 @@ #if defined(_MSC_VER) - #define asm __asm - #if _MSC_VER >= 700 - #pragma warning(disable:4103) - #endif - #pragma pack(1) -#elif defined(_QC) || defined(__WATCOM__) - #pragma pack(1) -#elif defined(__ZTC__) - #pragma ZTC align 1 -#elif defined(__TURBOC__) && (__TURBOC__ > 0x202) - #pragma option -a- +#define asm __asm +#if _MSC_VER >= 700 +#pragma warning(disable:4103) +#endif +#pragma pack(1) +#elif defined(_QC) || defined(__WATCOM__) +#pragma pack(1) +#elif defined(__ZTC__) +#pragma ZTC align 1 +#elif defined(__TURBOC__) && (__TURBOC__ > 0x202) +#pragma option -a- #endif diff --git a/hdr/buffer.h b/hdr/buffer.h index 20cc7d2..36c1ebe 100644 --- a/hdr/buffer.h +++ b/hdr/buffer.h @@ -32,14 +32,14 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *buffer_hRcsId = "$Id$"; +static BYTE *buffer_hRcsId = + "$Id$"; #endif #endif #define BUFFERSIZE 512 -struct buffer -{ - WORD b_dummy; /* dummy self pointing word to keep MFT from crashing */ +struct buffer { + WORD b_dummy; /* dummy self pointing word to keep MFT from crashing */ struct buffer FAR *b_next; /* form linked list for LRU */ BYTE b_unit; /* disk for this buffer */ @@ -52,14 +52,12 @@ struct buffer #else UWORD b_offset; /* span between copies */ #endif -#if 0 /*TE*/ - union - { +#if 0 /*TE*/ + union { struct dpb FAR *_b_dpbp; /* pointer to DPB */ LONG _b_huge_blkno; /* DOS-C: actual block number if >= 0xffff */ - } - _b; -#endif + } _b; +#endif BYTE b_buffer[BUFFERSIZE]; /* 512 byte sectors for now */ }; @@ -79,4 +77,3 @@ struct buffer * Rev 1.0 20 Apr 2001 17:30:00 Bart Oldeman * Initial revision. */ - diff --git a/hdr/cds.h b/hdr/cds.h index 0af5269..c7b6522 100644 --- a/hdr/cds.h +++ b/hdr/cds.h @@ -28,30 +28,25 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *Cds_hRcsId = "$Id$"; +static BYTE *Cds_hRcsId = + "$Id$"; #endif #endif #define MAX_CDSPATH 67 -struct cds -{ +struct cds { BYTE cdsCurrentPath[MAX_CDSPATH]; UWORD cdsFlags; struct dpb FAR *cdsDpb; - union - { - BYTE FAR * - _cdsRedirRec; - struct - { + union { + BYTE FAR *_cdsRedirRec; + struct { UWORD _cdsStrtClst; UWORD _cdsParam; - } - _cdsRedir; - } - _cdsUnion; + } _cdsRedir; + } _cdsUnion; UWORD cdsStoreUData; @@ -67,11 +62,9 @@ struct cds #define cdsRedirRec _cdsUnion._cdsRedirRec #define cdsParam _cdsUnion._cdsRedir._cdsParam -typedef struct _cdstbl -{ +typedef struct _cdstbl { struct cds cds_table[26]; -} -cdstbl; +} cdstbl; /* Bits for cdsFlags */ #define CDSNETWDRV 0x8000 diff --git a/hdr/clock.h b/hdr/clock.h index aeaea89..45cd996 100644 --- a/hdr/clock.h +++ b/hdr/clock.h @@ -32,13 +32,12 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *clock_hRcsId = "$Id$"; +static BYTE *clock_hRcsId = + "$Id$"; #endif #endif - -struct ClockRecord -{ +struct ClockRecord { UWORD clkDays; /* days since Jan 1, 1980. */ UBYTE clkMinutes; /* residual minutes. */ UBYTE clkHours; /* residual hours. */ diff --git a/hdr/date.h b/hdr/date.h index f7368bf..03a7d93 100644 --- a/hdr/date.h +++ b/hdr/date.h @@ -32,7 +32,8 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *date_hRcsId = "$Id$"; +static BYTE *date_hRcsId = + "$Id$"; #endif #endif diff --git a/hdr/dcb.h b/hdr/dcb.h index 4be6a51..23ccfbb 100644 --- a/hdr/dcb.h +++ b/hdr/dcb.h @@ -30,13 +30,13 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *clock_hRcsId = "$Id$"; +static BYTE *clock_hRcsId = + "$Id$"; #endif #endif /* Internal drive parameter block */ -struct dpb -{ +struct dpb { BYTE dpb_unit; /* unit for error reporting */ BYTE dpb_subunit; /* the sub-unit for driver */ UWORD dpb_secsize; /* sector size */ @@ -56,41 +56,39 @@ struct dpb struct dpb FAR * /* next dpb in chain */ dpb_next; /* -1 = end */ UWORD dpb_cluster; /* cluster # of first free */ - /* -1 if not known */ + /* -1 if not known */ #ifndef WITHFAT32 - UWORD dpb_nfreeclst; /* number of free clusters */ - /* -1 if not known */ -#else - union - { - struct - { + UWORD dpb_nfreeclst; /* number of free clusters */ + /* -1 if not known */ +#else + union { + struct { UWORD dpb_nfreeclst_lo; UWORD dpb_nfreeclst_hi; } dpb_nfreeclst_st; - ULONG _dpb_xnfreeclst; /* number of free clusters */ - /* -1 if not known */ + ULONG _dpb_xnfreeclst; /* number of free clusters */ + /* -1 if not known */ } dpb_nfreeclst_un; - #define dpb_nfreeclst dpb_nfreeclst_un.dpb_nfreeclst_st.dpb_nfreeclst_lo - #define dpb_xnfreeclst dpb_nfreeclst_un._dpb_xnfreeclst - +#define dpb_nfreeclst dpb_nfreeclst_un.dpb_nfreeclst_st.dpb_nfreeclst_lo +#define dpb_xnfreeclst dpb_nfreeclst_un._dpb_xnfreeclst + UWORD dpb_xflags; /* extended flags, see bpb */ UWORD dpb_xfsinfosec; /* FS info sector number, */ - /* 0xFFFF if unknown */ + /* 0xFFFF if unknown */ UWORD dpb_xbackupsec; /* backup boot sector number */ - /* 0xFFFF if unknown */ + /* 0xFFFF if unknown */ ULONG dpb_xdata; ULONG dpb_xsize; /* # of clusters+1 on media */ ULONG dpb_xfatsize; /* # of sectors / FAT */ ULONG dpb_xrootclst; /* starting cluster of root dir */ ULONG dpb_xcluster; /* cluster # of first free */ - /* -1 if not known */ -#endif + /* -1 if not known */ +#endif }; -#define UNKNCLUSTER 0x0000 /* see RBIL INT 21/AH=52 entry */ -#define XUNKNCLSTFREE 0xffffffffl /* unknown for DOS */ -#define UNKNCLSTFREE 0xffff /* unknown for DOS */ +#define UNKNCLUSTER 0x0000 /* see RBIL INT 21/AH=52 entry */ +#define XUNKNCLSTFREE 0xffffffffl /* unknown for DOS */ +#define UNKNCLSTFREE 0xffff /* unknown for DOS */ /* * Log: dcb.h,v diff --git a/hdr/device.h b/hdr/device.h index f2a8bf7..1de1e92 100644 --- a/hdr/device.h +++ b/hdr/device.h @@ -29,11 +29,11 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *device_hRcsId = "$Id$"; +static BYTE *device_hRcsId = + "$Id$"; #endif #endif - /* * Status Word Bits */ @@ -122,8 +122,7 @@ static BYTE *device_hRcsId = "$Id$"; /* Device header */ -struct dhdr -{ +struct dhdr { struct dhdr FAR *dh_next; UWORD dh_attr; @@ -153,10 +152,9 @@ struct dhdr #define FAT_NO_MIRRORING 0x80 -#define BPB_SIZEOF 31 /* size of the standard BPB */ +#define BPB_SIZEOF 31 /* size of the standard BPB */ -typedef struct -{ +typedef struct { UWORD bpb_nbyte; /* Bytes per Sector */ UBYTE bpb_nsector; /* Sectors per Allocation Unit */ UWORD bpb_nreserved; /* # Reserved Sectors */ @@ -169,23 +167,22 @@ typedef struct UWORD bpb_nheads; /* Number of heads */ ULONG bpb_hidden; /* Hidden sectors */ ULONG bpb_huge; /* Size in sectors if */ - /* bpb_nsize == 0 */ + /* bpb_nsize == 0 */ #ifdef WITHFAT32 ULONG bpb_xnfsect; /* FAT size in sectors if */ - /* bpb_nfsect == 0 */ + /* bpb_nfsect == 0 */ UWORD bpb_xflags; /* extended flags */ - /* bit 7: disable mirroring */ - /* bits 6-4: reserved (0) */ - /* bits 3-0: active FAT number */ + /* bit 7: disable mirroring */ + /* bits 6-4: reserved (0) */ + /* bits 3-0: active FAT number */ UWORD bpb_xfsversion; /* filesystem version */ ULONG bpb_xrootclst; /* starting cluster of root dir */ UWORD bpb_xfsinfosec; /* FS info sector number, */ - /* 0xFFFF if unknown */ + /* 0xFFFF if unknown */ UWORD bpb_xbackupsec; /* backup boot sector number */ - /* 0xFFFF if unknown */ + /* 0xFFFF if unknown */ #endif -} -bpb; +} bpb; #define N_RETRY 5 /* number of retries permitted */ #define SEC_SIZE 512 /* size of sector in bytes */ @@ -193,64 +190,61 @@ bpb; #define LBA_READ 0x4200 #define LBA_WRITE 0x4300 - -struct _bios_LBA_address_packet /* Used to access a hard disk via LBA */ - /* Added by Brian E. Reifsnyder */ +struct _bios_LBA_address_packet + /* Used to access a hard disk via LBA */ + /* Added by Brian E. Reifsnyder */ { - unsigned char packet_size; /* size of this packet...set to 16 */ - unsigned char reserved_1; /* set to 0...unused */ - unsigned char number_of_blocks; /* 0 < number_of_blocks < 128 */ - unsigned char reserved_2; /* set to 0...unused */ - UBYTE far * buffer_address; /* addr of transfer buffer */ - unsigned long block_address; /* LBA address */ - unsigned long block_address_high; /* high bytes of LBA addr...unused */ + unsigned char packet_size; /* size of this packet...set to 16 */ + unsigned char reserved_1; /* set to 0...unused */ + unsigned char number_of_blocks; /* 0 < number_of_blocks < 128 */ + unsigned char reserved_2; /* set to 0...unused */ + UBYTE far *buffer_address; /* addr of transfer buffer */ + unsigned long block_address; /* LBA address */ + unsigned long block_address_high; /* high bytes of LBA addr...unused */ }; struct CHS { - ULONG Cylinder; - UWORD Head; - UWORD Sector; + ULONG Cylinder; + UWORD Head; + UWORD Sector; }; /* DOS 4.0-7.0 drive data table (see RBIL at INT2F,AX=0803) */ -typedef struct ddtstruct -{ +typedef struct ddtstruct { struct ddtstruct FAR *ddt_next; - /* pointer to next table (offset FFFFh if last table) */ - UBYTE ddt_driveno; /* physical unit number (for INT 13) */ - UBYTE ddt_logdriveno; /* logical drive number (0=A:) */ - bpb ddt_bpb; /* BIOS Parameter Block */ + /* pointer to next table (offset FFFFh if last table) */ + UBYTE ddt_driveno; /* physical unit number (for INT 13) */ + UBYTE ddt_logdriveno; /* logical drive number (0=A:) */ + bpb ddt_bpb; /* BIOS Parameter Block */ UBYTE ddt_flags; - /* bit 6: 16-bit FAT instead of 12-bit - bit 7: unsupportable disk (all accesses will return Not Ready) */ - UWORD ddt_FileOC; /* Count of Open files on Drv */ - UBYTE ddt_type; /* device type */ - UWORD ddt_descflags;/* bit flags describing drive */ - UWORD ddt_ncyl; /* number of cylinders - (for partition only, if hard disk) */ - bpb ddt_defbpb; /* BPB for default (highest) capacity supported */ - UBYTE ddt_reserved[6]; /* (part of BPB above) */ - UBYTE ddt_ltrack; /* last track accessed */ - union - { - ULONG ddt_lasttime; /* removable media: time of last access - in clock ticks (FFFFFFFFh if never) */ - struct - { - UWORD ddt_part; /* partition (FFFFh = primary, 0001h = extended) - always 0001h for DOS 5+ */ - UWORD ddt_abscyl; /* absolute cylinder number of partition's - start on physical drive - (FFFFh if primary partition in DOS 4.x)*/ + /* bit 6: 16-bit FAT instead of 12-bit + bit 7: unsupportable disk (all accesses will return Not Ready) */ + UWORD ddt_FileOC; /* Count of Open files on Drv */ + UBYTE ddt_type; /* device type */ + UWORD ddt_descflags; /* bit flags describing drive */ + UWORD ddt_ncyl; /* number of cylinders + (for partition only, if hard disk) */ + bpb ddt_defbpb; /* BPB for default (highest) capacity supported */ + UBYTE ddt_reserved[6]; /* (part of BPB above) */ + UBYTE ddt_ltrack; /* last track accessed */ + union { + ULONG ddt_lasttime; /* removable media: time of last access + in clock ticks (FFFFFFFFh if never) */ + struct { + UWORD ddt_part; /* partition (FFFFh = primary, 0001h = extended) + always 0001h for DOS 5+ */ + UWORD ddt_abscyl; /* absolute cylinder number of partition's + start on physical drive + (FFFFh if primary partition in DOS 4.x) */ } ddt_hd; } ddt_fh; - UBYTE ddt_volume[12]; /* ASCIIZ volume label or "NO NAME " if none - (apparently taken from extended boot record - rather than root directory) */ - ULONG ddt_serialno; /* serial number */ - UBYTE ddt_fstype[9]; /* ASCIIZ filesystem type ("FAT12 " or "FAT16 ")*/ - ULONG ddt_offset; /* relative partition offset */ - BITS ddt_LBASupported:1; /* set, if INT13 extensions enabled */ + UBYTE ddt_volume[12]; /* ASCIIZ volume label or "NO NAME " if none + (apparently taken from extended boot record + rather than root directory) */ + ULONG ddt_serialno; /* serial number */ + UBYTE ddt_fstype[9]; /* ASCIIZ filesystem type ("FAT12 " or "FAT16 ") */ + ULONG ddt_offset; /* relative partition offset */ + BITS ddt_LBASupported:1; /* set, if INT13 extensions enabled */ BITS ddt_WriteVerifySupported:1; } ddt; @@ -268,41 +262,39 @@ typedef struct ddtstruct /* typedef struct ddtstruct ddt;*/ -struct gblkio -{ - UBYTE gbio_spcfunbit; - UBYTE gbio_devtype; - UWORD gbio_devattrib; - UWORD gbio_ncyl; - UBYTE gbio_media; - bpb gbio_bpb; - UWORD gbio_nsecs; +struct gblkio { + UBYTE gbio_spcfunbit; + UBYTE gbio_devtype; + UWORD gbio_devattrib; + UWORD gbio_ncyl; + UBYTE gbio_media; + bpb gbio_bpb; + UWORD gbio_nsecs; }; -struct gblkfv /* for format / verify track */ +struct gblkfv /* for format / verify track */ { - UBYTE gbfv_spcfunbit; - UWORD gbfv_head; - UWORD gbfv_cyl; - UWORD gbfv_ntracks; + UBYTE gbfv_spcfunbit; + UWORD gbfv_head; + UWORD gbfv_cyl; + UWORD gbfv_ntracks; }; -struct gblkrw /* for read / write track */ +struct gblkrw /* for read / write track */ { - UBYTE gbrw_spcfunbit; - UWORD gbrw_head; - UWORD gbrw_cyl; - UWORD gbrw_sector; - UWORD gbrw_nsecs; - UBYTE FAR * gbrw_buffer; + UBYTE gbrw_spcfunbit; + UWORD gbrw_head; + UWORD gbrw_cyl; + UWORD gbrw_sector; + UWORD gbrw_nsecs; + UBYTE FAR *gbrw_buffer; }; -struct Gioc_media -{ - WORD ioc_level; +struct Gioc_media { + WORD ioc_level; ULONG ioc_serialno; - BYTE ioc_volume[11]; - BYTE ioc_fstype[8]; + BYTE ioc_volume[11]; + BYTE ioc_fstype[8]; }; /* */ @@ -315,90 +307,68 @@ struct Gioc_media #define BT_BPB 11 #define BT_SIZEOF 36 -typedef struct -{ - BYTE bt_jump[3]; /* Boot Jump opcodes */ - BYTE bt_oem[8]; /* OEM Name */ - bpb bt_bpb; /* BPB for this media/device */ - WORD bt_nsecs; /* # Sectors per Track */ - WORD bt_nheads; /* # Heads */ - WORD bt_hidden; /* # Hidden sectors */ - LONG bt_huge; /* use if nsecs == 0 */ - BYTE bt_drvno; - BYTE bt_reserv; - BYTE bt_btid; +typedef struct { + BYTE bt_jump[3]; /* Boot Jump opcodes */ + BYTE bt_oem[8]; /* OEM Name */ + bpb bt_bpb; /* BPB for this media/device */ + WORD bt_nsecs; /* # Sectors per Track */ + WORD bt_nheads; /* # Heads */ + WORD bt_hidden; /* # Hidden sectors */ + LONG bt_huge; /* use if nsecs == 0 */ + BYTE bt_drvno; + BYTE bt_reserv; + BYTE bt_btid; ULONG bt_serialno; - BYTE bt_volume[11]; - BYTE bt_fstype[8]; -} -boot; + BYTE bt_volume[11]; + BYTE bt_fstype[8]; +} boot; /* File system information structure */ -struct fsinfo -{ - UDWORD fi_signature; /* must be 0x61417272 */ - DWORD fi_nfreeclst; /* number of free clusters, -1 if unknown */ - DWORD fi_cluster; /* most recently allocated cluster, -1 if unknown */ +struct fsinfo { + UDWORD fi_signature; /* must be 0x61417272 */ + DWORD fi_nfreeclst; /* number of free clusters, -1 if unknown */ + DWORD fi_cluster; /* most recently allocated cluster, -1 if unknown */ UBYTE fi_reserved[12]; }; typedef boot super; /* Alias for boot structure */ -typedef struct -{ +typedef struct { UBYTE r_length; /* Request Header length */ UBYTE r_unit; /* Unit Code */ UBYTE r_command; /* Command Code */ WORD r_status; /* Status */ BYTE r_reserved[8]; /* DOS Reserved Area */ - union - { - struct - { + union { + struct { UBYTE _r_nunits; /* number of units */ BYTE FAR *_r_endaddr; /* Ending Address */ bpb *FAR * _r_bpbptr; /* ptr to BPB array */ UBYTE _r_firstunit; - } - _r_init; - struct - { + } _r_init; + struct { BYTE _r_meddesc; /* MEDIA Descriptor */ BYTE _r_retcode; /* Return Code */ - BYTE FAR - * _r_vid; /* volume id */ - } - _r_media; - struct - { + BYTE FAR * _r_vid; /* volume id */ + } _r_media; + struct { BYTE _r_meddesc; /* MEDIA Descriptor */ - boot FAR - * _r_fat; /* boot sector pointer */ - bpb FAR - * _r_bpbpt; /* ptr to BPB table */ - } - _r_bpb; - struct - { + boot FAR * _r_fat; /* boot sector pointer */ + bpb FAR * _r_bpbpt; /* ptr to BPB table */ + } _r_bpb; + struct { BYTE _r_meddesc; /* MEDIA Descriptor */ - BYTE FAR - * _r_trans; /* Transfer Address */ + BYTE FAR * _r_trans; /* Transfer Address */ UWORD _r_count; /* Byte/Sector Count */ UWORD _r_start; /* Starting Sector No. */ - BYTE FAR - * _r_vid; /* Pointer to volume id */ + BYTE FAR * _r_vid; /* Pointer to volume id */ LONG _r_huge; /* for > 32Mb drives */ - } - _r_rw; - struct - { + } _r_rw; + struct { BYTE _r_ndbyte; /* Byte Read From Device */ - } - _r_nd; - } - _r_x; -} -request; + } _r_nd; + } _r_x; +} request; #define HUGECOUNT 0xffff #define MAXSHORT 0xffffl diff --git a/hdr/dirmatch.h b/hdr/dirmatch.h index 112b82f..b8e55d1 100644 --- a/hdr/dirmatch.h +++ b/hdr/dirmatch.h @@ -30,26 +30,24 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *dirmatch_hRcsId = "$Id$"; +static BYTE *dirmatch_hRcsId = + "$Id$"; #endif #endif - -typedef struct -{ +typedef struct { BYTE dm_drive; BYTE dm_name_pat[FNAME_SIZE + FEXT_SIZE]; BYTE dm_attr_srch; UWORD dm_entry; -#ifdef WITHFAT32 +#ifdef WITHFAT32 ULONG dm_dircluster; -#else +#else UWORD dm_dircluster; UWORD reserved; #endif - struct - { + struct { BITS /* directory has been modified */ f_dmod:1; BITS /* directory is the root */ @@ -60,16 +58,14 @@ typedef struct f_ddir:1; BITS /* filler to avoid a bad bug (feature?) in */ f_filler:12; /* TC 2.01 */ - } - dm_flags; /* file flags */ + } dm_flags; /* file flags */ BYTE dm_attr_fnd; /* found file attribute */ time dm_time; /* file time */ date dm_date; /* file date */ LONG dm_size; /* file size */ - BYTE dm_name[FNAME_SIZE + FEXT_SIZE + 2]; /* file name */ -} -dmatch; + BYTE dm_name[FNAME_SIZE + FEXT_SIZE + 2]; /* file name */ +} dmatch; /* * Log: dirmatch.h,v diff --git a/hdr/dosnames.h b/hdr/dosnames.h index 73e6ce0..e06cc62 100644 --- a/hdr/dosnames.h +++ b/hdr/dosnames.h @@ -30,19 +30,18 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *dosnames_hRcsId = "$Id$"; +static BYTE *dosnames_hRcsId = + "$Id$"; #endif #endif - #define PARSE_MAX 64 -struct dosnames -{ +struct dosnames { UBYTE dn_drive; /* the drive that was parsed */ UBYTE dn_network[PARSE_MAX]; /* specified network */ UBYTE dn_path[PARSE_MAX]; /* the path */ - UBYTE dn_name[FNAME_SIZE + FEXT_SIZE + 1]; /* the file name */ + UBYTE dn_name[FNAME_SIZE + FEXT_SIZE + 1]; /* the file name */ }; /* diff --git a/hdr/error.h b/hdr/error.h index 98b180d..984df3f 100644 --- a/hdr/error.h +++ b/hdr/error.h @@ -30,11 +30,11 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *error_hRcsId = "$Id$"; +static BYTE *error_hRcsId = + "$Id$"; #endif #endif - /* Internal system error returns */ #define SUCCESS 0 /* Function was successful */ #define DE_INVLDFUNC -1 /* Invalid function number */ @@ -60,7 +60,7 @@ static BYTE *error_hRcsId = "$Id$"; #define DE_SEEK -25 /* error on file seek */ #define DE_HNDLDSKFULL -28 /* handle disk full (?) */ -#define DE_INVLDPARM -0x57 /* invalid parameter */ +#define DE_INVLDPARM -0x57 /* invalid parameter */ #define DE_DEADLOCK -36 #define DE_LOCK -39 diff --git a/hdr/exe.h b/hdr/exe.h index d8058c2..c895db0 100644 --- a/hdr/exe.h +++ b/hdr/exe.h @@ -30,13 +30,12 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *exe_hRcsId = "$Id$"; +static BYTE *exe_hRcsId = + "$Id$"; #endif #endif - -typedef struct -{ +typedef struct { UWORD exSignature; UWORD exExtraBytes; UWORD exPages; @@ -51,8 +50,7 @@ typedef struct UWORD exInitCS; UWORD exRelocTable; UWORD exOverlay; -} -exe_header; +} exe_header; #define MAGIC 0x5a4d diff --git a/hdr/fat.h b/hdr/fat.h index 0c7ad4b..164079d 100644 --- a/hdr/fat.h +++ b/hdr/fat.h @@ -30,11 +30,11 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *fat_hRcsId = "$Id$"; +static BYTE *fat_hRcsId = + "$Id$"; #endif #endif - /* FAT file system attribute bits */ #define D_NORMAL 0 /* normal */ #define D_RDONLY 0x01 /* read-only file */ @@ -79,8 +79,7 @@ static BYTE *fat_hRcsId = "$Id$"; /* dpb_size == 0 for FAT32, hence doing -1 here */ /* FAT file system directory entry */ -struct dirent -{ +struct dirent { UBYTE dir_name[FNAME_SIZE]; /* Filename */ UBYTE dir_ext[FEXT_SIZE]; /* Filename extension */ UBYTE dir_attrib; /* File Attribute */ @@ -93,12 +92,11 @@ struct dirent time dir_time; /* Time file created/updated */ date dir_date; /* Date file created/updated */ UWORD dir_start; /* Starting cluster */ - /* 1st available = 2 */ + /* 1st available = 2 */ ULONG dir_size; /* File size in bytes */ }; -struct lfn_entry -{ +struct lfn_entry { UBYTE lfn_id; UNICODE lfn_name0_4[5]; UBYTE lfn_attrib; @@ -142,16 +140,15 @@ struct lfn_entry #define DIRENT_SIZE 32 -struct lfn_inode -{ +struct lfn_inode { UNICODE name[256]; - + struct dirent l_dir; - + ULONG l_diroff; /* offset of the dir entry */ }; - -typedef struct lfn_inode FAR * lfn_inode_ptr; + +typedef struct lfn_inode FAR *lfn_inode_ptr; /* * Log: fat.h,v diff --git a/hdr/fcb.h b/hdr/fcb.h index 61f467a..1253b72 100644 --- a/hdr/fcb.h +++ b/hdr/fcb.h @@ -30,11 +30,11 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *fcb_hRcsId = "$Id$"; +static BYTE *fcb_hRcsId = + "$Id$"; #endif #endif - /* fcb convience defines */ /* block device info */ #define FID_CHARDEV 0x80 /* 1 defines character device */ @@ -77,8 +77,7 @@ static BYTE *fcb_hRcsId = "$Id$"; #define FCB_WRITE 1 /* File Control Block (FCB) */ -typedef struct -{ +typedef struct { BYTE fcb_drive; /* Drive number 0=default, 1=A, etc */ BYTE fcb_fname[FNAME_SIZE]; /* File name */ BYTE fcb_fext[FEXT_SIZE]; /* File name Extension */ @@ -99,21 +98,17 @@ typedef struct /* end reserved */ UBYTE fcb_curec; /* Current block number of */ ULONG fcb_rndm; /* Current relative record number */ -} -fcb; +} fcb; /* FAT extended fcb */ -typedef struct -{ +typedef struct { UBYTE xfcb_flag; /* 0xff indicates Extended FCB */ BYTE xfcb_resvrd[5]; /* Reserved */ UBYTE xfcb_attrib; /* Attribute */ fcb xfcb_fcb; -} -xfcb; +} xfcb; -typedef struct -{ +typedef struct { UBYTE renDriveID; /* drive no. */ BYTE renOldName[8]; /* Old Filename */ BYTE renOldExtent[3]; /* Old File Extension */ @@ -121,8 +116,7 @@ typedef struct BYTE renNewName[8]; /* New Filename */ BYTE renNewExtent[3]; /* New FileExtension */ BYTE renReserved2[9]; -} -rfcb; +} rfcb; /* * Log: fcb.h,v diff --git a/hdr/file.h b/hdr/file.h index 7fe79ff..e143e43 100644 --- a/hdr/file.h +++ b/hdr/file.h @@ -30,11 +30,11 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *file_hRcsId = "$Id$"; +static BYTE *file_hRcsId = + "$Id$"; #endif #endif - /* 0 = CON, standard input, can be redirected */ /* 1 = CON, standard output, can be redirected */ /* 2 = CON, standard error */ diff --git a/hdr/fnode.h b/hdr/fnode.h index d7502c2..21bac17 100644 --- a/hdr/fnode.h +++ b/hdr/fnode.h @@ -30,25 +30,22 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *fnode_hRcsId = "$Id$"; +static BYTE *fnode_hRcsId = + "$Id$"; #endif #endif - -struct f_node -{ +struct f_node { UWORD f_count; /* number of uses of this file */ COUNT f_mode; /* read, write, read-write, etc */ - struct - { + struct { BITS f_dmod:1; /* directory has been modified */ BITS f_droot:1; /* directory is the root */ BITS f_dnew:1; /* fnode is new and needs fill */ BITS f_ddir:1; /* fnode is assigned to dir */ BITS f_ddate:1; /* date set using setdate */ - } - f_flags; /* file flags */ + } f_flags; /* file flags */ struct dirent f_dir; /* this file's dir entry image */ @@ -67,21 +64,20 @@ struct f_node }; #if 0 -struct lfn_inode - { +struct lfn_inode { UNICODE name[255]; struct dirent l_dir; /* this file's dir entry image */ ULONG l_diroff; /* offset of the dir entry */ CLUSTER l_dirstart; /* the starting cluster of dir */ - /* when dir is not root */ - }; + /* when dir is not root */ +}; -typedef struct lfn_inode FAR * lfn_inode_ptr; +typedef struct lfn_inode FAR *lfn_inode_ptr; #endif -typedef struct f_node * f_node_ptr; +typedef struct f_node *f_node_ptr; /* * Log: fnode.h,v diff --git a/hdr/kbd.h b/hdr/kbd.h index 7493639..4894665 100644 --- a/hdr/kbd.h +++ b/hdr/kbd.h @@ -30,21 +30,19 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *kbd_hRcsId = "$Id$"; +static BYTE *kbd_hRcsId = + "$Id$"; #endif #endif - #define KBD_MAXLENGTH 256 /* Keyboard buffer */ -typedef struct -{ +typedef struct { UBYTE kb_size; /* size of buffer in bytes */ UBYTE kb_count; /* number of bytes returned */ BYTE kb_buf[KBD_MAXLENGTH]; /* the buffer itself */ -} -keyboard; +} keyboard; /* * Log: kbd.h,v diff --git a/hdr/kconfig.h b/hdr/kconfig.h index cddbfcb..f08506e 100644 --- a/hdr/kconfig.h +++ b/hdr/kconfig.h @@ -13,15 +13,15 @@ < 0 : not possible to skip config.sys = 0 : only possible if already pressed before, no message > 0 : wait so long for F5/F8 -*/ +*/ typedef struct _KernelConfig { - char CONFIG[6]; /* "CONFIG" */ - unsigned short ConfigSize; - - unsigned char DLASortByDriveNo; - unsigned char InitDiskShowDriveAssignment; - signed char SkipConfigSeconds; - unsigned char ForceLBA; - unsigned char GlobalEnableLBAsupport; /* = 0 --> disable LBA support */ - } KernelConfig; -extern struct _KernelConfig FAR LowKernelConfig; + char CONFIG[6]; /* "CONFIG" */ + unsigned short ConfigSize; + + unsigned char DLASortByDriveNo; + unsigned char InitDiskShowDriveAssignment; + signed char SkipConfigSeconds; + unsigned char ForceLBA; + unsigned char GlobalEnableLBAsupport; /* = 0 --> disable LBA support */ +} KernelConfig; +extern struct _KernelConfig FAR LowKernelConfig; diff --git a/hdr/mcb.h b/hdr/mcb.h index 6637e03..71d87bc 100644 --- a/hdr/mcb.h +++ b/hdr/mcb.h @@ -30,7 +30,8 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *mcb_hRcsId = "$Id$"; +static BYTE *mcb_hRcsId = + "$Id$"; #endif #endif @@ -56,15 +57,13 @@ static BYTE *mcb_hRcsId = "$Id$"; typedef UWORD seg; typedef UWORD offset; -typedef struct -{ +typedef struct { BYTE m_type; /* mcb type - chain or end */ UWORD m_psp; /* owner id via psp segment */ UWORD m_size; /* size of segment in paragraphs */ BYTE m_fill[3]; BYTE m_name[8]; /* owner name limited to 8 bytes */ -} -mcb; +} mcb; /* * Log: mcb.h,v diff --git a/hdr/network.h b/hdr/network.h index a9fddd8..dcb66f0 100644 --- a/hdr/network.h +++ b/hdr/network.h @@ -59,30 +59,22 @@ #define REM_PRINTREDIR 0x1125 #define REM_EXTOC 0x112e -struct rgds -{ +struct rgds { UWORD r_spc; UWORD r_navc; UWORD r_bps; UWORD r_nc; }; -struct remote_fileattrib -{ +struct remote_fileattrib { UWORD rfa_file; /* File Attributes */ - union - { + union { ULONG rfa_filesize; /* file size */ - struct - { + struct { UWORD rfa_filesize_lo; /* DI Low */ UWORD rfa_filesize_hi; /* BX High */ - } - _split_rfa_fz; - } - rfa_fz_union; + } _split_rfa_fz; + } rfa_fz_union; UWORD rfa_time; UWORD rfa_date; }; - - diff --git a/hdr/nls.h b/hdr/nls.h index 072d817..a8d1b37 100644 --- a/hdr/nls.h +++ b/hdr/nls.h @@ -281,20 +281,19 @@ access to often used and mandatoryly present tables. */ #define NLS_REORDER_POINTERS - /* * How the kernel and NLSFUNC communicate with each other */ - /* Must be returned by NLSFUNC upon MUX-14-00 */ + /* Must be returned by NLSFUNC upon MUX-14-00 */ #define NLS_FREEDOS_NLSFUNC_ID 0x534b - /* Represents a call to DOS-38 within DOS-65 handlers. - Current implementation relys on 0x101! */ + /* Represents a call to DOS-38 within DOS-65 handlers. + Current implementation relys on 0x101! */ #define NLS_DOS_38 0x101 - /* NLSFUNC may return NLS_REDO to instruct the kernel to - try to perform the same action another time. This is most - useful if the kernel only loads the NLS pkg into memory so - the kernel will find it and will process the request internally - now. */ + /* NLSFUNC may return NLS_REDO to instruct the kernel to + try to perform the same action another time. This is most + useful if the kernel only loads the NLS pkg into memory so + the kernel will find it and will process the request internally + now. */ #define NLS_REDO 353 /* Codes of the subfunctions of external NLSFUNC */ @@ -320,42 +319,41 @@ a "1" in the bitfield means that the feature is active/enabled. All currently non-defined bits are to be zero to allow future useage. */ -#define NLS_FLAG_DIRECT_UPCASE 0x0001 /* DOS-65-2[012], */ -#define NLS_FLAG_DIRECT_FUPCASE 0x0002 /* DOS-65-A[012], internal */ -#define NLS_FLAG_DIRECT_YESNO 0x0004 /* DOS-65-23 */ -#define NLS_FLAG_DIRECT_GETDATA 0x0008 /* DOS-65-XX, DOS-38 */ +#define NLS_FLAG_DIRECT_UPCASE 0x0001 /* DOS-65-2[012], */ +#define NLS_FLAG_DIRECT_FUPCASE 0x0002 /* DOS-65-A[012], internal */ +#define NLS_FLAG_DIRECT_YESNO 0x0004 /* DOS-65-23 */ +#define NLS_FLAG_DIRECT_GETDATA 0x0008 /* DOS-65-XX, DOS-38 */ #define NLS_FLAG_HARDCODED NLS_FLAG_DIRECT_UPCASE \ | NLS_FLAG_DIRECT_FUPCASE \ | NLS_FLAG_DIRECT_YESNO \ | NLS_FLAG_DIRECT_GETDATA - /* No codepage / country code given */ + /* No codepage / country code given */ #define NLS_DEFAULT ((UWORD)-1) /* * This is the data in the exact order returned by DOS-65-01 */ -struct nlsExtCntryInfo -{ - UBYTE subfct; /* always 1 */ - WORD size; /* size of this structure - without this WORD itself */ - WORD countryCode; /* current country code */ - WORD codePage; /* current code page (CP) */ +struct nlsExtCntryInfo { + UBYTE subfct; /* always 1 */ + WORD size; /* size of this structure + without this WORD itself */ + WORD countryCode; /* current country code */ + WORD codePage; /* current code page (CP) */ - /* - * This is the data in the exact order as to return on - * DOS-38; it is also the most (important) part of DOS-65-01 - */ - /* Note: The ASCIZ strings might become - a totally different understanding with - DBCS (Double Byte Character Support) */ + /* + * This is the data in the exact order as to return on + * DOS-38; it is also the most (important) part of DOS-65-01 + */ + /* Note: The ASCIZ strings might become + a totally different understanding with + DBCS (Double Byte Character Support) */ WORD dateFmt; /* order of portions of date - 0: mm/dd/yyyy (USA) - 1: dd/mm/yyyy (Europe) - 2: yyyy/mm/dd (Japan) - */ + 0: mm/dd/yyyy (USA) + 1: dd/mm/yyyy (Europe) + 2: yyyy/mm/dd (Japan) + */ char curr[5]; /* ASCIZ of currency string */ char thSep[2]; /* ASCIZ of thousand's separator */ char point[2]; /* ASCIZ of decimal point */ @@ -363,64 +361,63 @@ struct nlsExtCntryInfo char timeSep[2]; /* ASCIZ of time separator */ BYTE currFmt; /* format of currency: bit 0: currency string is placed - 0: before number - 1: behind number + 0: before number + 1: behind number bit 1: currency string and number are - separated by a space - 0: No - 1: Yes + separated by a space + 0: No + 1: Yes bit 2: currency string replaces decimal - sign - 0: No - 1: Yes + sign + 0: No + 1: Yes */ BYTE prescision; /* of monetary numbers */ BYTE timeFmt; /* time format: - 0: 12 hours (append AM/PM) - 1: 24 houres - */ - VOID(FAR * upCaseFct) (VOID); /* far call to a function upcasing the - character in register AL */ + 0: 12 hours (append AM/PM) + 1: 24 houres + */ + VOID(FAR * upCaseFct) (VOID); /* far call to a function upcasing the + character in register AL */ char dataSep[2]; /* ASCIZ of separator in data records */ }; -struct nlsPointer { /* Information of DOS-65-0X is addressed - by a pointer */ - UBYTE subfct; /* number of the subfunction */ - VOID FAR *pointer; /* the pointer to be returned when the subfunction - of DOS-65 is called (Note: won't work for - subfunctions 0, 1, 0x20, 0x21, 0x22, 0x23, - 0xA0, 0xA1,& 0xA2 */ +struct nlsPointer { /* Information of DOS-65-0X is addressed + by a pointer */ + UBYTE subfct; /* number of the subfunction */ + VOID FAR *pointer; /* the pointer to be returned when the subfunction + of DOS-65 is called (Note: won't work for + subfunctions 0, 1, 0x20, 0x21, 0x22, 0x23, + 0xA0, 0xA1,& 0xA2 */ }; - -struct nlsPackage { /* the contents of one chain item of the - list of NLS packages */ - struct nlsPackage FAR *nxt; /* next item in chain */ - UWORD cntry, cp; /* country ID / codepage of this NLS pkg */ - int flags; /* direct access and other flags */ - /* Note: Depending on the flags above all remaining - portions may be omitted, if the external NLSFUNC-like - MUX-14 processor does not require them and performs - all actions itself, so that the kernel never tries to - fetch this information itself. */ - UBYTE yeschar; /* yes / no character DOS-65-23 */ - UBYTE nochar; - unsigned numSubfct; /* number of supported sub-functions */ - struct nlsPointer nlsPointers[1]; /* grows dynamically */ +struct nlsPackage { /* the contents of one chain item of the + list of NLS packages */ + struct nlsPackage FAR *nxt; /* next item in chain */ + UWORD cntry, cp; /* country ID / codepage of this NLS pkg */ + int flags; /* direct access and other flags */ + /* Note: Depending on the flags above all remaining + portions may be omitted, if the external NLSFUNC-like + MUX-14 processor does not require them and performs + all actions itself, so that the kernel never tries to + fetch this information itself. */ + UBYTE yeschar; /* yes / no character DOS-65-23 */ + UBYTE nochar; + unsigned numSubfct; /* number of supported sub-functions */ + struct nlsPointer nlsPointers[1]; /* grows dynamically */ }; -struct nlsDBCS { /* The internal structure is unknown to me */ - UWORD numEntries; - UWORD dbcsTbl[1]; +struct nlsDBCS { /* The internal structure is unknown to me */ + UWORD numEntries; + UWORD dbcsTbl[1]; }; struct nlsCharTbl { - /* table containing a list of characters */ - UWORD numEntries; /* number of entries of this table. - If <= 0x80, the first element of - the table corresponse to character 0x80 */ - unsigned char tbl[1]; /* grows dynamically */ + /* table containing a list of characters */ + UWORD numEntries; /* number of entries of this table. + If <= 0x80, the first element of + the table corresponse to character 0x80 */ + unsigned char tbl[1]; /* grows dynamically */ }; #define nlsChBuf(len) struct nlsCharTbl##len { \ UWORD numEntries; \ @@ -431,37 +428,35 @@ nlsChBuf(256); /* in file names permittable characters for DOS-65-05 */ struct nlsFnamTerm { - WORD size; /* size of this structure */ - BYTE dummy1; - char firstCh, - lastCh; /* first, last permittable character */ - BYTE dummy2; - char firstExcl, - lastExcl; /* first, last excluded character */ - BYTE dummy3; - BYTE numSep; /* number of file name separators */ - char separators[1]; /* grows dynamically */ + WORD size; /* size of this structure */ + BYTE dummy1; + char firstCh, lastCh; /* first, last permittable character */ + BYTE dummy2; + char firstExcl, lastExcl; /* first, last excluded character */ + BYTE dummy3; + BYTE numSep; /* number of file name separators */ + char separators[1]; /* grows dynamically */ }; -struct nlsInfoBlock { /* This block contains all information - shared by the kernel and the external NLSFUNC program */ - char FAR *fname; /* filename from COUNTRY=; - maybe tweaked by NLSFUNC */ - UWORD sysCodePage; /* system code page */ - unsigned flags; /* implementation flags */ - struct nlsPackage FAR *actPkg; /* current NLS package */ - struct nlsPackage FAR *chain; /* first item of info chain -- - hardcoded U.S.A./CP437 */ +struct nlsInfoBlock { /* This block contains all information + shared by the kernel and the external NLSFUNC program */ + char FAR *fname; /* filename from COUNTRY=; + maybe tweaked by NLSFUNC */ + UWORD sysCodePage; /* system code page */ + unsigned flags; /* implementation flags */ + struct nlsPackage FAR *actPkg; /* current NLS package */ + struct nlsPackage FAR *chain; /* first item of info chain -- + hardcoded U.S.A./CP437 */ }; -extern struct nlsInfoBlock nlsInfo; -extern struct nlsPackage nlsPackageHardcoded; - /* These are the "must have" tables within the hard coded NLS pkg */ -extern struct nlsFnamTerm nlsFnameTermHardcoded; -extern struct nlsDBCS nlsDBCSHardcoded; -extern struct nlsCharTbl nlsUpcaseHardcoded; -extern struct nlsCharTbl nlsFUpcaseHardcoded; -extern struct nlsCharTbl nlsCollHardcoded; +extern struct nlsInfoBlock nlsInfo; +extern struct nlsPackage nlsPackageHardcoded; + /* These are the "must have" tables within the hard coded NLS pkg */ +extern struct nlsFnamTerm nlsFnameTermHardcoded; +extern struct nlsDBCS nlsDBCSHardcoded; +extern struct nlsCharTbl nlsUpcaseHardcoded; +extern struct nlsCharTbl nlsFUpcaseHardcoded; +extern struct nlsCharTbl nlsCollHardcoded; extern struct nlsExtCntryInfo nlsCntryInfoHardcoded; extern BYTE FAR hcTablesStart[], hcTablesEnd[]; @@ -522,35 +517,34 @@ extern BYTE FAR hcTablesStart[], hcTablesEnd[]; #define CSYS_FD_IDSTRING "FreeDOS COUNTRY.SYS v1.0\r\n" -struct nlsCSys_function { /* S3: function definition */ - UDWORD csys_rpos; /* relative position to actual data */ - UWORD csys_length; - UBYTE csys_fctID; /* As passed to DOS-65-XX */ - UBYTE csys_reserved1; /* always 0, reserved for future use */ +struct nlsCSys_function { /* S3: function definition */ + UDWORD csys_rpos; /* relative position to actual data */ + UWORD csys_length; + UBYTE csys_fctID; /* As passed to DOS-65-XX */ + UBYTE csys_reserved1; /* always 0, reserved for future use */ }; -struct nlsCSys_ccDefinition { /* S1: country/codepage reference */ - UDWORD csys_rpos; /* moving the 4byte value to the front - can increase performance */ - UWORD csys_cp; - UWORD csys_cntry; +struct nlsCSys_ccDefinition { /* S1: country/codepage reference */ + UDWORD csys_rpos; /* moving the 4byte value to the front + can increase performance */ + UWORD csys_cp; + UWORD csys_cntry; }; -struct nlsCSys_numEntries { /* helper structure for "number of entries" */ - UWORD csys_numEntries; +struct nlsCSys_numEntries { /* helper structure for "number of entries" */ + UWORD csys_numEntries; }; /* Actually, this structure is never really used */ -struct nlsCSys_fileHeader { /* S0: primary structure */ - unsigned char csys_idstring[sizeof(CSYS_FD_IDSTRING) - 1]; - /* decrement by 1 to cut off \0 from IDString -- ska*/ +struct nlsCSys_fileHeader { /* S0: primary structure */ + unsigned char csys_idstring[sizeof(CSYS_FD_IDSTRING) - 1]; + /* decrement by 1 to cut off \0 from IDString -- ska */ }; -struct nlsCSys_completeFileHeader { /* as S0, but full 128 bytes */ - unsigned char csys_idstring[sizeof(CSYS_FD_IDSTRING) - 1]; - unsigned char csys_padbytes[128 - (sizeof(CSYS_FD_IDSTRING) - 1)]; +struct nlsCSys_completeFileHeader { /* as S0, but full 128 bytes */ + unsigned char csys_idstring[sizeof(CSYS_FD_IDSTRING) - 1]; + unsigned char csys_padbytes[128 - (sizeof(CSYS_FD_IDSTRING) - 1)]; }; - /* standard alignment */ #include diff --git a/hdr/pcb.h b/hdr/pcb.h index 4a6520e..87a3785 100644 --- a/hdr/pcb.h +++ b/hdr/pcb.h @@ -51,27 +51,23 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *pcb_hRcsId = "$Id$"; +static BYTE *pcb_hRcsId = + "$Id$"; #endif #endif - /* Force one-byte alignment for all the internal structures, see above */ #include /* */ /* interrupt handler structure definition */ /* */ -typedef union -{ +typedef union { UWORD x; /* access mode for ax, bx, etc. */ - struct - { + struct { UBYTE l; /* access mode for al, bl, etc. */ UBYTE h; /* access mode for ah, bh, etc. */ - } - b; -} -xreg; + } b; +} xreg; /* The structure assumes that: 1) An interrupt was invoked, & @@ -79,41 +75,26 @@ xreg; Furthermore, the PUSH$ALL macro must push ES first and AX last. -- 2000/03/22 ska*/ /* maps MS-DOS unique stacking order */ -typedef struct _iregss -{ - xreg a, - b, - c, - d; - UWORD si, - di, - bp, - ds, - es; - UWORD ip, - cs, - flags; -} -iregs; +typedef struct _iregss { + xreg a, b, c, d; + UWORD si, di, bp, ds, es; + UWORD ip, cs, flags; +} iregs; /* Registers directly passed to syscall; - must be the same order as iregs! - Is used to define parameters. */ + must be the same order as iregs! + Is used to define parameters. */ #define DIRECT_IREGS \ xreg a, xreg b, xreg c, xreg d, \ UWORD si, UWORD di, UWORD bp, UWORD ds, UWORD es, \ UWORD ip, UWORD cs, UWORD flags - - /* Process control block for task switching */ -typedef struct -{ +typedef struct { UWORD pc_ss; UWORD pc_sp; iregs pc_regs; -} -pcb; +} pcb; /* Note: The following figure is not made by myself and I assume that the order of "ES" through "AX" are misinterpreted?! -- 2000/03/22 ska*/ diff --git a/hdr/portab.h b/hdr/portab.h index 4269ff2..5a20298 100644 --- a/hdr/portab.h +++ b/hdr/portab.h @@ -30,7 +30,8 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static char *portab_hRcsId = "$Id$"; +static char *portab_hRcsId = + "$Id$"; #endif #endif @@ -57,84 +58,71 @@ static char *portab_hRcsId = "$Id$"; /* */ /****************************************************************/ - - /* commandline overflow - removing -DI86 TE*/ + /* commandline overflow - removing -DI86 TE */ #if defined(__TURBOC__) - #define I86 - #define CDECL cdecl - void __int__(int); - -#elif defined (_MSC_VER) +#define I86 +#define CDECL cdecl +void __int__(int); - #define I86 - #define CDECL _cdecl - #define __int__(intno) asm int intno; +#elif defined (_MSC_VER) - #if defined(M_I286) /* /G3 doesn't set M_I386, but sets M_I286 TE*/ - #define I386 - #endif +#define I86 +#define CDECL _cdecl +#define __int__(intno) asm int intno; -#elif defined(__WATCOMC__) /* don't know a better way */ +#if defined(M_I286) /* /G3 doesn't set M_I386, but sets M_I286 TE */ +#define I386 +#endif - #define I86 - #define __int__(intno) asm int intno; - #define asm __asm - #define far __far - #define CDECL __cdecl - - #if _M_IX86 >= 300 - #define I386 - #endif +#elif defined(__WATCOMC__) /* don't know a better way */ + +#define I86 +#define __int__(intno) asm int intno; +#define asm __asm +#define far __far +#define CDECL __cdecl + +#if _M_IX86 >= 300 +#define I386 +#endif #elif defined (_MYMC68K_COMILER_) - #define MC68K +#define MC68K -#else - anyone knows a _portable_ way to create nice errors?? - at least this causes the compiler not to compile :-) +#else +anyone knows a _portable_ way to create nice errors ? ? + at least this causes the compiler not to compile : -) #endif /* functions, that are shared between C and ASM _must_ - have a certain calling standard. These are declared - as 'ASMCFUNC', and is (and will be ?-) cdecl */ + have a certain calling standard. These are declared + as 'ASMCFUNC', and is (and will be ?-) cdecl */ #define ASMCFUNC cdecl - #ifdef MC68K - #define far /* No far type */ #define interrupt /* No interrupt type */ - #define VOID void #define FAR /* linear architecture */ #define NEAR /* " " */ #define INRPT interrupt - #define CONST #define REG register - #define API int /* linear architecture */ #define NONNATIVE - #define PARASIZE 4096 /* "paragraph" size */ #endif - #ifdef I86 - #define VOID void #define FAR far /* segment architecture */ #define NEAR near /* " " */ #define INRPT interrupt - #define CONST const #define REG register - -#define API int far pascal /* segment architecture */ +#define API int far pascal /* segment architecture */ #define NATIVE - #define PARASIZE 16 /* "paragraph" size */ #endif - /* */ /* Boolean type & definitions of TRUE and FALSE boolean values */ /* */ @@ -186,8 +174,7 @@ typedef unsigned short CLUSTER; #endif typedef unsigned short UNICODE; -#define STATIC /* local calls inside module */ - +#define STATIC /* local calls inside module */ #ifdef UNIX typedef char FAR *ADDRESS; @@ -220,16 +207,16 @@ typedef signed long LONG; this suppresses the warning unreferenced parameter 'x' and (hopefully) generates no code -*/ +*/ #if defined(__TURBOC__) - #define UNREFERENCED_PARAMETER(x) if (x); -#else - #define UNREFERENCED_PARAMETER(x) x; -#endif +#define UNREFERENCED_PARAMETER(x) if (x); +#else +#define UNREFERENCED_PARAMETER(x) x; +#endif -#ifdef I86 /* commandline overflow - removing /DPROTO TE*/ - #define PROTO +#ifdef I86 /* commandline overflow - removing /DPROTO TE */ +#define PROTO #endif /* diff --git a/hdr/process.h b/hdr/process.h index 6c8da92..5cd99cf 100644 --- a/hdr/process.h +++ b/hdr/process.h @@ -30,7 +30,8 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *process_hRcsId = "$Id$"; +static BYTE *process_hRcsId = + "$Id$"; #endif #endif @@ -40,36 +41,27 @@ static BYTE *process_hRcsId = "$Id$"; #define P_NOWAIT 1 /* both concurrent -- not implemented */ #define P_OVERLAY 2 /* child replaces parent, parent no longer exists */ -typedef struct -{ - union - { - struct - { +typedef struct { + union { + struct { UWORD load_seg; UWORD reloc; - } - _load; - struct - { + } _load; + struct { UWORD env_seg; CommandTail FAR *cmd_line; fcb FAR *fcb_1; fcb FAR *fcb_2; BYTE FAR *stack; BYTE FAR *start_addr; - } - _exec; - } - ldata; -} -exec_blk; + } _exec; + } ldata; +} exec_blk; #define exec ldata._exec #define load ldata._load -typedef struct -{ +typedef struct { UWORD ps_exit; /* 00 CP/M-like exit poimt */ UWORD ps_size; /* 02 memory size in paragraphs */ BYTE ps_fill1; /* 04 single char fill */ @@ -77,9 +69,9 @@ typedef struct /* CP/M-like entry point */ UBYTE ps_farcall; /* 05 far call opcode */ VOID(FAR * ps_reentry) (); /* 06 re-entry point */ - VOID(interrupt FAR * ps_isv22) (),/* 0a terminate address */ - (interrupt FAR * ps_isv23) (), /* 0e break address */ - (interrupt FAR * ps_isv24) (); /* 12 critical error address */ + VOID(interrupt FAR * ps_isv22) (), /* 0a terminate address */ + (interrupt FAR * ps_isv23) (), /* 0e break address */ + (interrupt FAR * ps_isv24) (); /* 12 critical error address */ UWORD ps_parent; /* 16 parent psp segment */ UBYTE ps_files[20]; /* 18 file table - 0xff is unused */ UWORD ps_environ; /* 2c environment paragraph */ @@ -89,39 +81,25 @@ typedef struct VOID FAR *ps_prevpsp; /* 38 previous psp pointer */ BYTE FAR *ps_dta; /* 3c process dta address */ BYTE ps_fill2[16]; - UBYTE ps_unix[3]; /* unix style call - 0xcd 0x21 0xcb */ + UBYTE ps_unix[3]; /* unix style call - 0xcd 0x21 0xcb */ BYTE ps_fill3[9]; - union - { - struct - { - fcb - _ps_fcb1; /* first command line argument */ - } - _u1; - struct - { - BYTE - fill4[16]; - fcb - _ps_fcb2; /* second command line argument */ - } - _u2; - struct - { + union { + struct { + fcb _ps_fcb1; /* first command line argument */ + } _u1; + struct { + BYTE fill4[16]; + fcb _ps_fcb2; /* second command line argument */ + } _u2; + struct { BYTE fill5[36]; - struct - { + struct { BYTE _ps_cmd_count; BYTE _ps_cmd[127]; /* command tail */ - } - _u4; - } - _u3; - } - _u; -} -psp; + } _u4; + } _u3; + } _u; +} psp; #define ps_fcb1 _u._u1._ps_fcb1 #define ps_fcb2 _u._u2._ps_fcb2 diff --git a/hdr/sft.h b/hdr/sft.h index c91a53d..98c5dcc 100644 --- a/hdr/sft.h +++ b/hdr/sft.h @@ -29,16 +29,15 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *sft_hRcsId = "$Id$"; +static BYTE *sft_hRcsId = + "$Id$"; #endif #endif - #define SFTMAX 128 /* Handle Definition entry */ -typedef struct -{ +typedef struct { WORD sft_count; /* 00 - reference count */ WORD sft_mode; /* 02 - open mode - see below */ BYTE sft_attrib; /* 04 - file attribute - dir style */ @@ -46,24 +45,17 @@ typedef struct union /* 05 */ { WORD _sft_flags; - struct - { + struct { BYTE _sft_flags_lo; BYTE _sft_flags_hi; - } - _split_sft_flags; - } - sft_flags_union; + } _split_sft_flags; + } sft_flags_union; union /* 07 */ { - struct dpb FAR * - _sft_dcb; /* The device control block */ - struct dhdr FAR * - _sft_dev; /* device driver for char dev */ - } - - sft_dcb_or_dev; + struct dpb FAR *_sft_dcb; /* The device control block */ + struct dhdr FAR *_sft_dev; /* device driver for char dev */ + } sft_dcb_or_dev; WORD sft_stclust; /* 0b - Starting cluster */ time sft_time; /* 0d - File time */ date sft_date; /* 0f - File date */ @@ -74,36 +66,30 @@ typedef struct WORD sft_dirdlust; /* 1d - Sector containing cluster */ BYTE sft_diridx; /* 1f - directory index */ BYTE sft_name[11]; /* 20 - dir style file name */ - BYTE FAR * - sft_bshare; /* 2b - backward link of file sharing sft */ + BYTE FAR *sft_bshare; /* 2b - backward link of file sharing sft */ WORD sft_mach; /* 2f - machine number - network apps */ WORD sft_psp; /* 31 - owner psp */ WORD sft_shroff; /* 33 - Sharing offset */ WORD sft_status; /* 35 - this sft status */ - BYTE FAR * sft_ifsptr; /* 37 - pointer to IFS driver for file, 0000000h if native DOS */ -} -sft; + BYTE FAR *sft_ifsptr; /* 37 - pointer to IFS driver for file, 0000000h if native DOS */ +} sft; /* SFT Table header definition */ -typedef struct _sftheader -{ +typedef struct _sftheader { struct _sfttbl FAR * /* link to next table in list */ sftt_next; WORD sftt_count; /* # of handle definition */ /* entries, this table */ -} -sftheader; +} sftheader; /* System File Definition List */ -typedef struct _sfttbl -{ +typedef struct _sfttbl { struct _sfttbl FAR * /* link to next table in list */ sftt_next; WORD sftt_count; /* # of handle definition */ /* entries, this table */ sft sftt_table[SFTMAX]; /* The array of sft for block */ -} -sfttbl; +} sfttbl; /* defines for sft use */ #define SFT_MASK 0x0060 /* splits device data */ @@ -153,7 +139,6 @@ sfttbl; #define sft_flags_hi sft_flags_union._split_sft_flags._sft_flags_hi #define sft_flags_lo sft_flags_union._split_sft_flags._sft_flags_lo - /* * Log: sft.h,v * diff --git a/hdr/tail.h b/hdr/tail.h index 3577f44..2b36d28 100644 --- a/hdr/tail.h +++ b/hdr/tail.h @@ -30,21 +30,19 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *tail_hRcsId = "$Id$"; +static BYTE *tail_hRcsId = + "$Id$"; #endif #endif - #ifndef LINESIZE #define LINESIZE 127 #endif -typedef struct -{ +typedef struct { UBYTE ctCount; /* number of bytes returned */ BYTE ctBuffer[LINESIZE]; /* the buffer itself */ -} -CommandTail; +} CommandTail; /* * Log: tail.h,v diff --git a/hdr/time.h b/hdr/time.h index 8ee7f45..951450a 100644 --- a/hdr/time.h +++ b/hdr/time.h @@ -34,7 +34,8 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *time_hRcsId = "$Id$"; +static BYTE *time_hRcsId = + "$Id$"; #endif #endif @@ -87,4 +88,3 @@ typedef UWORD time; * Rev 1.0 02 Jul 1995 10:39:56 patv * Initial revision. */ - diff --git a/hdr/version.h b/hdr/version.h index e953a81..f98d542 100644 --- a/hdr/version.h +++ b/hdr/version.h @@ -28,7 +28,8 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *date_hRcsId = "$Id$"; +static BYTE *date_hRcsId = + "$Id$"; #endif #endif @@ -45,5 +46,5 @@ static BYTE *date_hRcsId = "$Id$"; #define REVISION_SEQ 25 #define BUILD "2025" #define SUB_BUILD "b" -#define KERNEL_VERSION_STRING "1.1.25b" /*#REVISION_MAJOR "." #REVISION_MINOR "." #REVISION_SEQ*/ -#define KERNEL_BUILD_STRING "2025b" /*#BUILD SUB_BUILD*/ +#define KERNEL_VERSION_STRING "1.1.25b" /*#REVISION_MAJOR "." #REVISION_MINOR "." #REVISION_SEQ */ +#define KERNEL_BUILD_STRING "2025b" /*#BUILD SUB_BUILD */ diff --git a/hdr/xstructs.h b/hdr/xstructs.h index 4b0d631..90310a5 100644 --- a/hdr/xstructs.h +++ b/hdr/xstructs.h @@ -8,54 +8,52 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *XStructs_hRcsId = "$Id$"; +static BYTE *XStructs_hRcsId = + "$Id$"; #endif #endif -struct xdpbdata -{ - UWORD xdd_dpbsize; +struct xdpbdata { + UWORD xdd_dpbsize; struct dpb xdd_dpb; }; -struct xfreespace -{ - UWORD xfs_datasize; /* size of this structure */ +struct xfreespace { + UWORD xfs_datasize; /* size of this structure */ union { - UWORD requested; /* requested structure version */ - UWORD actual; /* actual structure version */ + UWORD requested; /* requested structure version */ + UWORD actual; /* actual structure version */ } xfs_version; - ULONG xfs_clussize; /* number of sectors per cluster */ - ULONG xfs_secsize; /* number of bytes per sector */ - ULONG xfs_freeclusters; /* number of available clusters */ - ULONG xfs_totalclusters; /* total number of clusters on the drive */ - ULONG xfs_freesectors; /* number of physical sectors available */ - ULONG xfs_totalsectors; /* total number of physical sectors */ - ULONG xfs_freeunits; /* number of available allocation units */ - ULONG xfs_totalunits; /* total allocation units */ + ULONG xfs_clussize; /* number of sectors per cluster */ + ULONG xfs_secsize; /* number of bytes per sector */ + ULONG xfs_freeclusters; /* number of available clusters */ + ULONG xfs_totalclusters; /* total number of clusters on the drive */ + ULONG xfs_freesectors; /* number of physical sectors available */ + ULONG xfs_totalsectors; /* total number of physical sectors */ + ULONG xfs_freeunits; /* number of available allocation units */ + ULONG xfs_totalunits; /* total allocation units */ UBYTE xfs_reserved[8]; }; -struct xdpbforformat -{ - UWORD xdff_datasize; /* size of this structure */ +struct xdpbforformat { + UWORD xdff_datasize; /* size of this structure */ union { - UWORD requested; /* requested structure version */ - UWORD actual; /* actual structure version */ + UWORD requested; /* requested structure version */ + UWORD actual; /* actual structure version */ } xdff_version; - UDWORD xdff_function; /* function number: - 00h invalidate DPB counts - 01h rebuild DPB from BPB - 02h force media change - 03h get/set active FAT number and mirroring - 04h get/set root directory cluster number - */ + UDWORD xdff_function; /* function number: + 00h invalidate DPB counts + 01h rebuild DPB from BPB + 02h force media change + 03h get/set active FAT number and mirroring + 04h get/set root directory cluster number + */ union { struct { - DWORD nfreeclst; /* # free clusters - (-1 - unknown, 0 - don't change) */ - DWORD cluster; /* cluster # of first free - (-1 - unknown, 0 - don't change) */ + DWORD nfreeclst; /* # free clusters + (-1 - unknown, 0 - don't change) */ + DWORD cluster; /* cluster # of first free + (-1 - unknown, 0 - don't change) */ UDWORD reserved[2]; } setdpbcounts; @@ -66,18 +64,18 @@ struct xdpbforformat } rebuilddpb; struct { - DWORD newmirroring; /* new active FAT/mirroring state, or -1 to get - bits 3-0: the 0-based FAT number of the active FAT - bits 6-4: reserved (0) - bit 7: do not mirror active FAT to inactive FATs - */ - DWORD oldmirroring; /* previous active FAT/mirroring state (as above) */ + DWORD newmirroring; /* new active FAT/mirroring state, or -1 to get + bits 3-0: the 0-based FAT number of the active FAT + bits 6-4: reserved (0) + bit 7: do not mirror active FAT to inactive FATs + */ + DWORD oldmirroring; /* previous active FAT/mirroring state (as above) */ UDWORD reserved[2]; } setmirroring; struct { - DWORD newrootclst; /* set new root directory cluster, -1 - get current */ - DWORD oldrootclst; /* get previous root directory cluster */ + DWORD newrootclst; /* set new root directory cluster, -1 - get current */ + DWORD oldrootclst; /* get previous root directory cluster */ UDWORD reserved[2]; } setroot; } xdff_f; diff --git a/kernel/blockio.c b/kernel/blockio.c index 1f4d540..7a78e7b 100644 --- a/kernel/blockio.c +++ b/kernel/blockio.c @@ -32,9 +32,10 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *blockioRcsId = "$Id$"; +static BYTE *blockioRcsId = + "$Id$"; #endif - + /************************************************************************/ /* */ /* block cache routines */ @@ -42,7 +43,6 @@ static BYTE *blockioRcsId = "$Id$"; /************************************************************************/ /* #define DISPLAY_GETBLOCK */ - /* */ /* Initialize the buffer structure */ /* */ @@ -75,7 +75,7 @@ VOID FAR reloc_call_init_buffers(void) */ /* Extract the block number from a buffer structure. */ #if 0 /*TE*/ -ULONG getblkno(struct buffer FAR * bp) + ULONG getblkno(struct buffer FAR * bp) { if (bp->b_blkno == 0xffffu) return bp->b_huge_blkno; @@ -89,7 +89,7 @@ ULONG getblkno(struct buffer FAR * bp) /* Set the block number of a buffer structure. (The caller should */ /* set the unit number before calling this function.) */ #if 0 /*TE*/ -VOID setblkno(struct buffer FAR * bp, ULONG blkno) + VOID setblkno(struct buffer FAR * bp, ULONG blkno) { if (blkno >= 0xffffu) { @@ -101,7 +101,7 @@ VOID setblkno(struct buffer FAR * bp, ULONG blkno) bp->b_blkno = blkno; /* bp->b_dpbp = &blk_devices[bp->b_unit]; */ - bp->b_dpbp = CDSp->cds_table[bp->b_unit].cdsDpb; + bp->b_dpbp = CDSp->cds_table[bp->b_unit].cdsDpb; } } @@ -124,38 +124,34 @@ VOID setblkno(struct buffer FAR * bp, ULONG blkno) UNCACHE buffers are recycled first. intended to be used for full sector reads into application buffer -*/ +*/ -BOOL searchblock(ULONG blkno, COUNT dsk, - struct buffer FAR ** pBuffp) +BOOL searchblock(ULONG blkno, COUNT dsk, struct buffer FAR ** pBuffp) { - int fat_count = 0; - struct buffer FAR *bp; - struct buffer FAR *lbp = NULL; - struct buffer FAR *lastNonFat = NULL; - struct buffer FAR *uncacheBuf = NULL; + int fat_count = 0; + struct buffer FAR *bp; + struct buffer FAR *lbp = NULL; + struct buffer FAR *lastNonFat = NULL; + struct buffer FAR *uncacheBuf = NULL; - #ifdef DISPLAY_GETBLOCK - printf("[searchblock %d, blk %ld, buf ", dsk, blkno); + printf("[searchblock %d, blk %ld, buf ", dsk, blkno); #endif - - /* Search through buffers to see if the required block */ /* is already in a buffer */ - for (bp = firstbuf; bp != NULL;lbp = bp, bp = bp->b_next) + for (bp = firstbuf; bp != NULL; lbp = bp, bp = bp->b_next) { - if ((getblkno(bp) == blkno) && + if ((getblkno(bp) == blkno) && (bp->b_flag & BFR_VALID) && (bp->b_unit == dsk)) { /* found it -- rearrange LRU links */ if (lbp != NULL) { - lbp->b_next = bp->b_next; - bp->b_next = firstbuf; - firstbuf = bp; + lbp->b_next = bp->b_next; + bp->b_next = firstbuf; + firstbuf = bp; } #ifdef DISPLAY_GETBLOCK printf("HIT %04x:%04x]\n", FP_SEG(bp), FP_OFF(bp)); @@ -165,92 +161,87 @@ BOOL searchblock(ULONG blkno, COUNT dsk, } if (bp->b_flag & BFR_UNCACHE) - uncacheBuf = bp; - + uncacheBuf = bp; if (bp->b_flag & BFR_FAT) - fat_count++; + fat_count++; else - lastNonFat = bp; + lastNonFat = bp; } - - /* - now take either the last buffer in chain (not used recently) - or, if we are low on FAT buffers, the last non FAT buffer - */ - if (uncacheBuf) + /* + now take either the last buffer in chain (not used recently) + or, if we are low on FAT buffers, the last non FAT buffer + */ + + if (uncacheBuf) { - lbp = uncacheBuf; - } - else + lbp = uncacheBuf; + } + else { - if (lbp ->b_flag & BFR_FAT && fat_count < 3 && lastNonFat) + if (lbp->b_flag & BFR_FAT && fat_count < 3 && lastNonFat) { - lbp = lastNonFat; + lbp = lastNonFat; } - } - - lbp->b_flag &= ~BFR_UNCACHE; /* reset uncache attribute */ - + } + + lbp->b_flag &= ~BFR_UNCACHE; /* reset uncache attribute */ + *pBuffp = lbp; - + #ifdef DISPLAY_GETBLOCK printf("MISS, replace %04x:%04x]\n", FP_SEG(lbp), FP_OFF(lbp)); #endif - - - if (lbp != firstbuf) /* move to front */ - { + if (lbp != firstbuf) /* move to front */ + { for (bp = firstbuf; bp->b_next != lbp; bp = bp->b_next) - ; + ; bp->b_next = bp->b_next->b_next; lbp->b_next = firstbuf; firstbuf = lbp; - } - + } + return FALSE; -} +} BOOL DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk) { - struct buffer FAR *bp; + struct buffer FAR *bp; /* Search through buffers to see if the required block */ /* is already in a buffer */ for (bp = firstbuf; bp != NULL; bp = bp->b_next) { - if (blknolow <= getblkno(bp) && + if (blknolow <= getblkno(bp) && getblkno(bp) <= blknohigh && - (bp->b_flag & BFR_VALID) && (bp->b_unit == dsk)) + (bp->b_flag & BFR_VALID) && (bp->b_unit == dsk)) { - flush1(bp); + flush1(bp); } } - return FALSE; -} - + return FALSE; +} void dumpBufferCache(void) { - struct buffer FAR *bp; - int printed = 0; + struct buffer FAR *bp; + int printed = 0; /* Search through buffers to see if the required block */ /* is already in a buffer */ - for (bp = firstbuf; bp != NULL;bp = bp->b_next) + for (bp = firstbuf; bp != NULL; bp = bp->b_next) { - printf("%8lx %02x ",getblkno(bp),bp->b_flag); + printf("%8lx %02x ", getblkno(bp), bp->b_flag); if (++printed % 6 == 0) - printf("\n"); - } + printf("\n"); + } printf("\n"); -} - +} /* */ /* Return the address of a buffer structure containing the */ @@ -263,37 +254,34 @@ void dumpBufferCache(void) /* */ struct buffer FAR *getblock(ULONG blkno, COUNT dsk) { - struct buffer FAR *bp; - - + struct buffer FAR *bp; /* Search through buffers to see if the required block */ /* is already in a buffer */ - if (searchblock(blkno, dsk, &bp)) - { - return (bp); - } + if (searchblock(blkno, dsk, &bp)) + { + return (bp); + } /* The block we need is not in a buffer, we must make a buffer */ /* available, and fill it with the desired block */ - /* take the buffer that lbp points to and flush it, then read new block. */ if (!flush1(bp)) - return NULL; - - /* Fill the indicated disk buffer with the current track and sector */ + return NULL; + + /* Fill the indicated disk buffer with the current track and sector */ if (dskxfer(dsk, blkno, (VOID FAR *) bp->b_buffer, 1, DSKREAD)) - { - return NULL; - } + { + return NULL; + } bp->b_flag = BFR_VALID | BFR_DATA; bp->b_unit = dsk; setblkno(bp, blkno); - + return bp; } @@ -302,23 +290,23 @@ struct buffer FAR *getblock(ULONG blkno, COUNT dsk) exactly the same as getblock(), but the data will be completely overwritten. so there is no need to read from disk first */ -struct buffer FAR * getblockOver(ULONG blkno, COUNT dsk) +struct buffer FAR *getblockOver(ULONG blkno, COUNT dsk) { - struct buffer FAR *bp; + struct buffer FAR *bp; /* Search through buffers to see if the required block */ /* is already in a buffer */ - if (searchblock(blkno, dsk, &bp)) - { - return bp; - } + if (searchblock(blkno, dsk, &bp)) + { + return bp; + } /* The block we need is not in a buffer, we must make a buffer */ /* available. */ /* take the buffer than lbp points to and flush it, then make it available. */ - if (flush1(bp)) /* success */ + if (flush1(bp)) /* success */ { bp->b_flag = 0; bp->b_unit = dsk; @@ -331,6 +319,7 @@ struct buffer FAR * getblockOver(ULONG blkno, COUNT dsk) return NULL; } } + /* */ /* Mark all buffers for a disk as not valid */ /* */ @@ -374,14 +363,13 @@ BOOL flush_buffers(REG COUNT dsk) /* */ BOOL flush1(struct buffer FAR * bp) { -/* All lines with changes on 9/4/00 by BER marked below */ - - UWORD result; /* BER 9/4/00 */ +/* All lines with changes on 9/4/00 by BER marked below */ + + UWORD result; /* BER 9/4/00 */ if ((bp->b_flag & BFR_VALID) && (bp->b_flag & BFR_DIRTY)) { - result = dskxfer(bp->b_unit, getblkno(bp), - (VOID FAR *) bp->b_buffer, 1, DSKWRITE); /* BER 9/4/00 */ + result = dskxfer(bp->b_unit, getblkno(bp), (VOID FAR *) bp->b_buffer, 1, DSKWRITE); /* BER 9/4/00 */ if (bp->b_flag & BFR_FAT) { int i = bp->b_copies; @@ -390,19 +378,18 @@ BOOL flush1(struct buffer FAR * bp) while (--i > 0) { blkno += bp->b_offset; - result = dskxfer(bp->b_unit, blkno, - (VOID FAR *) bp->b_buffer, 1, DSKWRITE); /* BER 9/4/00 */ + result = dskxfer(bp->b_unit, blkno, (VOID FAR *) bp->b_buffer, 1, DSKWRITE); /* BER 9/4/00 */ } } } else - result = 0; /* This negates any error code returned in result...BER */ - /* and 0 returned, if no errors occurred - tom */ + result = 0; /* This negates any error code returned in result...BER */ + /* and 0 returned, if no errors occurred - tom */ bp->b_flag &= ~BFR_DIRTY; /* even if error, mark not dirty */ if (result != 0) /* otherwise system has trouble */ bp->b_flag &= ~BFR_VALID; /* continuing. */ - return (TRUE); /* Forced to TRUE...was like this before dskxfer() */ - /* returned error codes...BER */ + return (TRUE); /* Forced to TRUE...was like this before dskxfer() */ + /* returned error codes...BER */ } /* */ @@ -428,7 +415,6 @@ BOOL flush(void) return (ok); } - /************************************************************************/ /* */ /* Device Driver Interface Functions */ @@ -439,32 +425,33 @@ BOOL flush(void) /* */ /* Changed to UWORD 9/4/00 BER */ -UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, COUNT mode) +UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, + COUNT mode) /* End of change */ { /* REG struct dpb *dpbp = &blk_devices[dsk]; */ REG struct dpb FAR *dpbp = CDSp->cds_table[dsk].cdsDpb; - - if ((UCOUNT)dsk >= lastdrive ) - { - return 0x0201; /* illegal command */ - } + if ((UCOUNT) dsk >= lastdrive) + { + return 0x0201; /* illegal command */ + } if (!(CDSp->cds_table[dsk].cdsFlags & CDSPHYSDRV)) - { - return 0x0201; /* illegal command */ - } - + { + return 0x0201; /* illegal command */ + } + #if TOM #define KeyboardShiftState() (*(BYTE FAR *)(MK_FP(0x40,0x17))) if (KeyboardShiftState() & 0x01) - { - printf("dskxfer:%s %x - %lx %u\n", mode == DSKWRITE ? "write" : "read", dsk, blkno, numblocks); + { + printf("dskxfer:%s %x - %lx %u\n", mode == DSKWRITE ? "write" : "read", + dsk, blkno, numblocks); if ((KeyboardShiftState() & 0x03) == 3) - dumpBufferCache(); - } + dumpBufferCache(); + } #endif for (;;) @@ -472,18 +459,27 @@ UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, COUNT mod IoReqHdr.r_length = sizeof(request); IoReqHdr.r_unit = dpbp->dpb_subunit; - switch(mode) + switch (mode) + { + case DSKWRITE: + if (verify_ena) { - case DSKWRITE : if (verify_ena) { IoReqHdr.r_command = C_OUTVFY; break; } - /* else fall through */ - case DSKWRITEINT26: IoReqHdr.r_command = C_OUTPUT; break; - - case DSKREADINT25: - case DSKREAD : IoReqHdr.r_command = C_INPUT; break; - default: - return 0x0100; /* illegal command */ - } - + IoReqHdr.r_command = C_OUTVFY; + break; + } + /* else fall through */ + case DSKWRITEINT26: + IoReqHdr.r_command = C_OUTPUT; + break; + + case DSKREADINT25: + case DSKREAD: + IoReqHdr.r_command = C_INPUT; + break; + default: + return 0x0100; /* illegal command */ + } + IoReqHdr.r_status = 0; IoReqHdr.r_meddesc = dpbp->dpb_mdb; IoReqHdr.r_trans = (BYTE FAR *) buf; @@ -499,46 +495,43 @@ UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, COUNT mod if (!(IoReqHdr.r_status & S_ERROR) && (IoReqHdr.r_status & S_DONE)) break; - /* INT25/26 (_SEEMS_ TO) return immediately with 0x8002, - if drive is not online,... - - normal operations (DIR) wait for ABORT/RETRY - - other condition codes not tested - */ + /* INT25/26 (_SEEMS_ TO) return immediately with 0x8002, + if drive is not online,... + + normal operations (DIR) wait for ABORT/RETRY + + other condition codes not tested + */ if (mode >= DSKWRITEINT26) - return (IoReqHdr.r_status); + return (IoReqHdr.r_status); /* Changed 9/4/00 BER return (IoReqHdr.r_status); */ - - - /* Skip the abort, retry, fail code...it needs fixed...BER */ /* End of change */ - loop: - switch (block_error(&IoReqHdr, dpbp->dpb_unit, dpbp->dpb_device)) - { - case ABORT: - case FAIL: - return (IoReqHdr.r_status); + loop: + switch (block_error(&IoReqHdr, dpbp->dpb_unit, dpbp->dpb_device)) + { + case ABORT: + case FAIL: + return (IoReqHdr.r_status); - case RETRY: - continue; + case RETRY: + continue; - case CONTINUE: - break; + case CONTINUE: + break; - default: - goto loop; - } + default: + goto loop; + } - } /* retry loop */ + } /* retry loop */ /* *** Changed 9/4/00 BER */ - return 0; /* Success! Return 0 for a successful operation. */ + return 0; /* Success! Return 0 for a successful operation. */ /* End of change */ } @@ -547,7 +540,7 @@ UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, COUNT mod * 2000/9/04 Brian Reifsnyder * Modified dskxfer() such that error codes are now returned. * Functions that rely on dskxfer() have also been modified accordingly. - */ + */ /* * Log: blockio.c,v - for newer entries do "cvs log blockio.c" diff --git a/kernel/break.c b/kernel/break.c index 48612e5..c9e1c55 100644 --- a/kernel/break.c +++ b/kernel/break.c @@ -33,7 +33,8 @@ extern void ASMCFUNC spawn_int23(void); #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif #define CB_FLG *(UBYTE FAR*)MK_FP(0x40, 0x71) @@ -67,7 +68,7 @@ void handle_break(void) if (!ErrorMode) /* within int21_handler, InDOS is not incremented */ if (InDOS) --InDOS; /* fail-safe */ - + spawn_int23(); /* invoke user INT-23 and never come back */ } @@ -81,4 +82,3 @@ void handle_break(void) * Steffen contributed. * */ - diff --git a/kernel/chario.c b/kernel/chario.c index baf0d2e..d8b45b6 100644 --- a/kernel/chario.c +++ b/kernel/chario.c @@ -31,7 +31,8 @@ #include "portab.h" #ifdef VERSION_STRINGS -static BYTE *charioRcsId = "$Id$"; +static BYTE *charioRcsId = + "$Id$"; #endif #include "globals.h" @@ -67,26 +68,28 @@ struct dhdr FAR *finddev(UWORD attr_mask) VOID _cso(COUNT c) { - if (syscon->dh_attr & ATTR_FASTCON) { - #if defined(__TURBOC__) - _AL = c; - __int__(0x29); - #else - asm { - mov al, byte ptr c; - int 0x29; - } - #endif - return; - } - CharReqHdr.r_length = sizeof(request); - CharReqHdr.r_command = C_OUTPUT; - CharReqHdr.r_count = 1; - CharReqHdr.r_trans = (BYTE FAR *) (&c); - CharReqHdr.r_status = 0; - execrh((request FAR *) & CharReqHdr, syscon); - if (CharReqHdr.r_status & S_ERROR) - char_error(&CharReqHdr, syscon); + if (syscon->dh_attr & ATTR_FASTCON) + { +#if defined(__TURBOC__) + _AL = c; + __int__(0x29); +#else + asm + { + mov al, byte ptr c; + int 0x29; + } +#endif + return; + } + CharReqHdr.r_length = sizeof(request); + CharReqHdr.r_command = C_OUTPUT; + CharReqHdr.r_count = 1; + CharReqHdr.r_trans = (BYTE FAR *) (&c); + CharReqHdr.r_status = 0; + execrh((request FAR *) & CharReqHdr, syscon); + if (CharReqHdr.r_status & S_ERROR) + char_error(&CharReqHdr, syscon); } VOID cso(COUNT c) @@ -95,7 +98,7 @@ VOID cso(COUNT c) con_hold(); if (PrinterEcho) - DosWrite(STDPRN, 1, (BYTE FAR *) & c, (COUNT FAR *) &UnusedRetVal); + DosWrite(STDPRN, 1, (BYTE FAR *) & c, (COUNT FAR *) & UnusedRetVal); switch (c) { @@ -106,20 +109,24 @@ VOID cso(COUNT c) case BELL: break; case BS: - if (scr_pos > 0) scr_pos--; + if (scr_pos > 0) + scr_pos--; break; case HT: - do _cso(' '); while ((++scr_pos) & 7); + do + _cso(' '); + while ((++scr_pos) & 7); break; default: scr_pos++; } - if (c != HT) _cso(c); + if (c != HT) + _cso(c); } VOID sto(COUNT c) { - DosWrite(STDOUT, 1, (BYTE FAR *) & c, (COUNT FAR *) &UnusedRetVal); + DosWrite(STDOUT, 1, (BYTE FAR *) & c, (COUNT FAR *) & UnusedRetVal); } VOID mod_cso(REG UCOUNT c) @@ -169,11 +176,11 @@ COUNT ndread(void) COUNT con_read(void) { BYTE c; - + CharReqHdr.r_length = sizeof(request); CharReqHdr.r_command = C_INPUT; CharReqHdr.r_count = 1; - CharReqHdr.r_trans = (BYTE FAR *)&c; + CharReqHdr.r_trans = (BYTE FAR *) & c; CharReqHdr.r_status = 0; execrh((request FAR *) & CharReqHdr, syscon); if (CharReqHdr.r_status & S_ERROR) @@ -186,7 +193,7 @@ COUNT con_read(void) VOID con_hold(void) { UBYTE c = ndread(); - if(c == CTL_S) + if (c == CTL_S) { con_read(); Do_DosIdle_loop(); @@ -210,8 +217,9 @@ UCOUNT _sti(BOOL check_break) Do_DosIdle_loop(); if (check_break) con_hold(); - while (GenericRead(STDIN, 1, (BYTE FAR *) & c, (COUNT FAR *) & UnusedRetVal, TRUE) - != 1) ; + while (GenericRead + (STDIN, 1, (BYTE FAR *) & c, (COUNT FAR *) & UnusedRetVal, + TRUE) != 1) ; return c; } @@ -285,11 +293,9 @@ static VOID kbfill(keyboard FAR * kp, UCOUNT c, BOOL ctlf, UWORD * vp) /* return number of characters before EOF if there is one, else just the total */ UCOUNT sti_0a(keyboard FAR * kp) { - REG UWORD c, - cu_pos = scr_pos; - UWORD - virt_pos = scr_pos; - UWORD init_count = 0; /* kp->kb_count; */ + REG UWORD c, cu_pos = scr_pos; + UWORD virt_pos = scr_pos; + UWORD init_count = 0; /* kp->kb_count; */ BOOL eof = FALSE; #ifndef NOSPCL static BYTE local_buffer[LINESIZE]; @@ -327,7 +333,7 @@ UCOUNT sti_0a(keyboard FAR * kp) break; } - case F1: + case F1: case RIGHT: c = local_buffer[kp->kb_count]; if (c) @@ -377,7 +383,7 @@ UCOUNT sti_0a(keyboard FAR * kp) return eof; else return kp->kb_count--; - + case LF: break; @@ -406,7 +412,7 @@ UCOUNT sti(keyboard * kp) UCOUNT ReadCount = sti_0a(kp); kp->kb_count++; - if (ReadCount >= kp->kb_count && kp->kb_count < kp->kb_size) + if (ReadCount >= kp->kb_count && kp->kb_count < kp->kb_size) { kp->kb_buf[kp->kb_count++] = LF; cso(LF); @@ -483,4 +489,3 @@ UCOUNT sti(keyboard * kp) * Initial revision. * */ - diff --git a/kernel/config.c b/kernel/config.c index b15b2e3..3c9daf8 100644 --- a/kernel/config.c +++ b/kernel/config.c @@ -33,14 +33,15 @@ #include "dyndata.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif #ifdef DEBUG - #define DebugPrintf(x) printf x -#else - #define DebugPrintf(x) -#endif +#define DebugPrintf(x) printf x +#else +#define DebugPrintf(x) +#endif #ifdef KDB #include @@ -56,86 +57,77 @@ static BYTE *RcsId = "$Id$"; -- Bart */ -extern f_node_ptr DOSFAR f_nodes; /* pointer to the array */ -extern UWORD DOSFAR f_nodes_cnt, /* number of allocated f_nodes */ - DOSFAR first_mcb; /* Start of user memory */ +extern f_node_ptr DOSFAR f_nodes; /* pointer to the array */ +extern UWORD DOSFAR f_nodes_cnt, /* number of allocated f_nodes */ + DOSFAR first_mcb; /* Start of user memory */ extern UBYTE DOSFAR lastdrive, DOSFAR nblkdev, DOSFAR mem_access_mode, - DOSFAR uppermem_link; -extern struct dhdr - DOSTEXTFAR blk_dev, /* Block device (Disk) driver */ - DOSFAR nul_dev; -extern struct buffer FAR * DOSFAR firstbuf; /* head of buffers linked list */ + DOSFAR uppermem_link; +extern struct dhdr +DOSTEXTFAR blk_dev, /* Block device (Disk) driver */ + DOSFAR nul_dev; +extern struct buffer FAR *DOSFAR firstbuf; /* head of buffers linked list */ -extern struct dpb FAR * DOSFAR DPBp; +extern struct dpb FAR *DOSFAR DPBp; /* First drive Parameter Block */ -extern cdstbl FAR * DOSFAR CDSp; +extern cdstbl FAR *DOSFAR CDSp; /* Current Directory Structure */ -extern sfttbl FAR * DOSFAR sfthead; +extern sfttbl FAR *DOSFAR sfthead; /* System File Table head */ -extern sfttbl FAR * DOSFAR FCBp; +extern sfttbl FAR *DOSFAR FCBp; -extern BYTE DOSFAR VgaSet, - DOSFAR _HMATextAvailable, /* first byte of available CODE area */ - FAR _HMATextStart[], /* first byte of HMAable CODE area */ - FAR _HMATextEnd[], - DOSFAR break_ena, /* break enabled flag */ - DOSFAR os_major, /* major version number */ - DOSFAR os_minor, /* minor version number */ - DOSFAR switchar, - DOSFAR _InitTextStart, /* first available byte of ram */ - DOSFAR ReturnAnyDosVersionExpected; +extern BYTE DOSFAR VgaSet, DOSFAR _HMATextAvailable, /* first byte of available CODE area */ + FAR _HMATextStart[], /* first byte of HMAable CODE area */ + FAR _HMATextEnd[], DOSFAR break_ena, /* break enabled flag */ + DOSFAR os_major, /* major version number */ + DOSFAR os_minor, /* minor version number */ + DOSFAR switchar, DOSFAR _InitTextStart, /* first available byte of ram */ + DOSFAR ReturnAnyDosVersionExpected; -extern UWORD DOSFAR ram_top, /* How much ram in Kbytes */ +extern UWORD DOSFAR ram_top, /* How much ram in Kbytes */ + DOSFAR UMB_top, - DOSFAR umb_start, - DOSFAR uppermem_root, - DOSFAR LoL_nbuffers; + DOSFAR umb_start, DOSFAR uppermem_root, DOSFAR LoL_nbuffers; -struct config Config - = - { - NUMBUFF, - NFILES, - NFCBS, - 0, - "command.com", - " /P /E:256\r\n", - NLAST, - NSTACKS, - 128 - /* COUNTRY= is initialized within DoConfig() */ - ,0 /* country ID */ - ,0 /* codepage */ - ,"" /* filename */ - ,0 /* amount required memory */ - ,0 /* pointer to loaded data */ - ,0 /* strategy for command.com is low by default */ - } -; - /* MSC places uninitialized data into COMDEF records, - that end up in DATA segment. this can't be tolerated - in INIT code. - please make sure, that ALL data in INIT is initialized !! - */ +struct config Config = { + NUMBUFF, + NFILES, + NFCBS, + 0, + "command.com", + " /P /E:256\r\n", + NLAST, + NSTACKS, + 128 + /* COUNTRY= is initialized within DoConfig() */ + , 0 /* country ID */ + , 0 /* codepage */ + , "" /* filename */ + , 0 /* amount required memory */ + , 0 /* pointer to loaded data */ + , 0 /* strategy for command.com is low by default */ +}; + /* MSC places uninitialized data into COMDEF records, + that end up in DATA segment. this can't be tolerated + in INIT code. + please make sure, that ALL data in INIT is initialized !! + */ BYTE FAR *lpBase = 0; BYTE FAR *upBase = 0; -BYTE FAR *lpTop = 0; +BYTE FAR *lpTop = 0; BYTE FAR *lpOldTop = 0; STATIC COUNT nCfgLine = 0; STATIC COUNT nPass = 0; - COUNT UmbState = 0; -STATIC BYTE szLine[256] = {0}; -STATIC BYTE szBuf[256] = {0}; +COUNT UmbState = 0; +STATIC BYTE szLine[256] = { 0 }; +STATIC BYTE szBuf[256] = { 0 }; -BYTE singleStep = FALSE; /* F8 processing */ -BYTE SkipAllConfig = FALSE; /* F5 processing */ -BYTE askThisSingleCommand = FALSE; /* ?device= device?= */ +BYTE singleStep = FALSE; /* F8 processing */ +BYTE SkipAllConfig = FALSE; /* F5 processing */ +BYTE askThisSingleCommand = FALSE; /* ?device= device?= */ - - -INIT VOID zumcb_init(UCOUNT seg, UWORD size); -INIT VOID mumcb_init(UCOUNT seg, UWORD size); +INIT VOID zumcb_init(UCOUNT seg, UWORD size); +INIT VOID mumcb_init(UCOUNT seg, UWORD size); INIT VOID Config_Buffers(BYTE * pLine); INIT VOID sysScreenMode(BYTE * pLine); @@ -162,10 +154,10 @@ INIT struct dhdr FAR *linkdev(struct dhdr FAR * dhp); INIT UWORD initdev(struct dhdr FAR * dhp, BYTE FAR * cmdTail); INIT int SkipLine(char *pLine); INIT char *stristr(char *s1, char *s2); -INIT COUNT strcasecmp(REG BYTE *d, REG BYTE *s); +INIT COUNT strcasecmp(REG BYTE * d, REG BYTE * s); extern void HMAconfig(int finalize); -VOID config_init_buffers(COUNT anzBuffers); /* from BLOCKIO.C */ +VOID config_init_buffers(COUNT anzBuffers); /* from BLOCKIO.C */ INIT STATIC VOID FAR *AlignParagraph(VOID FAR * lpPtr); #ifndef I86 @@ -176,15 +168,13 @@ INIT STATIC VOID FAR *AlignParagraph(VOID FAR * lpPtr); INIT struct table *LookUp(struct table *p, BYTE * token); -struct table -{ +struct table { BYTE *entry; BYTE pass; VOID(*func) (BYTE * pLine); }; -STATIC struct table commands[] = -{ +STATIC struct table commands[] = { {"BREAK", 1, CfgBreak}, {"BUFFERS", 1, Config_Buffers}, {"COMMAND", 1, InitPgm}, @@ -196,7 +186,7 @@ STATIC struct table commands[] = {"FILES", 1, Files}, {"LASTDRIVE", 1, CfgLastdrive}, {"NUMLOCK", 1, Numlock}, - /* rem is never executed by locking out pass */ + /* rem is never executed by locking out pass */ {"REM", 0, CfgFailure}, {";", 0, CfgFailure}, {"SHELL", 1, InitPgm}, @@ -205,8 +195,8 @@ STATIC struct table commands[] = {"SWITCHAR", 1, CfgSwitchar}, {"SCREEN", 1, sysScreenMode}, /* JPP */ {"VERSION", 1, sysVersion}, /* JPP */ - {"ANYDOS", 1, SetAnyDos}, /* JPP */ - /* default action */ + {"ANYDOS", 1, SetAnyDos}, /* JPP */ + /* default action */ {"", -1, CfgFailure} }; @@ -218,23 +208,24 @@ INIT BYTE FAR *KernelAllocDma(WORD); BYTE *pLineStart = 0; BYTE HMAState = 0; -#define HMA_NONE 0 /* do nothing */ -#define HMA_REQ 1 /* DOS = HIGH detected */ -#define HMA_DONE 2 /* Moved kernel to HMA */ -#define HMA_LOW 3 /* Definitely LOW */ +#define HMA_NONE 0 /* do nothing */ +#define HMA_REQ 1 /* DOS = HIGH detected */ +#define HMA_DONE 2 /* Moved kernel to HMA */ +#define HMA_LOW 3 /* Definitely LOW */ -void FAR * ConfigAlloc(COUNT bytes) +void FAR *ConfigAlloc(COUNT bytes) { - VOID FAR *p; + VOID FAR *p; - p = HMAalloc(bytes); - - if (p == NULL) p = KernelAlloc(bytes); + p = HMAalloc(bytes); - /* printf("ConfigAlloc %d at %p\n", bytes, p);*/ - - return p; -} + if (p == NULL) + p = KernelAlloc(bytes); + + /* printf("ConfigAlloc %d at %p\n", bytes, p); */ + + return p; +} /* Do first time initialization. Store last so that we can reset it */ /* later. */ @@ -243,15 +234,15 @@ INIT void PreConfig(void) /* Set pass number */ nPass = 0; VgaSet = 0; - UmbState = 0; - + UmbState = 0; + /* Initialize the base memory pointers */ - + #ifdef DEBUG - { - extern BYTE FAR internal_data[]; - printf("SDA located at 0x%p\n", internal_data); - } + { + extern BYTE FAR internal_data[]; + printf("SDA located at 0x%p\n", internal_data); + } #endif /* Begin by initializing our system buffers */ /* the dms_scratch buffer is statically allocated @@ -259,8 +250,6 @@ INIT void PreConfig(void) /* dma_scratch = (BYTE FAR *) KernelAllocDma(BUFFERSIZE); */ /* DebugPrintf(("Preliminary DMA scratchpad allocated at 0x%p\n",dma_scratch));*/ - - /* buffers = (struct buffer FAR *) KernelAlloc(Config.cfgBuffers * sizeof(struct buffer)); */ #ifdef DEBUG @@ -272,43 +261,41 @@ INIT void PreConfig(void) KernelAlloc(Config.cfgFiles * sizeof(struct f_node));*/ f_nodes = (f_node_ptr) - DynAlloc("f_nodes", Config.cfgFiles , sizeof(struct f_node)); + DynAlloc("f_nodes", Config.cfgFiles, sizeof(struct f_node)); f_nodes_cnt = Config.cfgFiles; /* sfthead = (sfttbl FAR *)&basesft; */ /* FCBp = (sfttbl FAR *)&FcbSft; */ /* FCBp = (sfttbl FAR *) - KernelAlloc(sizeof(sftheader) - + Config.cfgFiles * sizeof(sft));*/ + KernelAlloc(sizeof(sftheader) + + Config.cfgFiles * sizeof(sft)); */ - lpBase = AlignParagraph((BYTE FAR *)DynLast()+0x0f); + lpBase = AlignParagraph((BYTE FAR *) DynLast() + 0x0f); - config_init_buffers( Config.cfgBuffers); + config_init_buffers(Config.cfgBuffers); sfthead->sftt_next = (sfttbl FAR *) - KernelAlloc(sizeof(sftheader) - + (Config.cfgFiles-5) * sizeof(sft)); + KernelAlloc(sizeof(sftheader) + (Config.cfgFiles - 5) * sizeof(sft)); sfthead->sftt_next->sftt_next = (sfttbl FAR *) - 1; - sfthead->sftt_next->sftt_count = Config.cfgFiles-5; + sfthead->sftt_next->sftt_count = Config.cfgFiles - 5; - CDSp = (cdstbl FAR *) - KernelAlloc(0x58 * lastdrive); + CDSp = (cdstbl FAR *) KernelAlloc(0x58 * lastdrive); DPBp = (struct dpb FAR *) - KernelAlloc(blk_dev.dh_name[0]*sizeof(struct dpb)); + KernelAlloc(blk_dev.dh_name[0] * sizeof(struct dpb)); #ifdef DEBUG - printf("Preliminary:\n f_node 0x%x",f_nodes); + printf("Preliminary:\n f_node 0x%x", f_nodes); /* printf(" FCB table 0x%p\n",FCBp);*/ - printf(" sft table 0x%p\n",sfthead->sftt_next); - printf(" CDS table 0x%p\n",CDSp); - printf(" DPB table 0x%p\n",DPBp); + printf(" sft table 0x%p\n", sfthead->sftt_next); + printf(" CDS table 0x%p\n", CDSp); + printf(" DPB table 0x%p\n", DPBp); #endif /* Done. Now initialize the MCB structure */ /* This next line is 8086 and 80x86 real mode specific */ #ifdef DEBUG - printf("Preliminary allocation completed: top at 0x%p\n",lpBase); + printf("Preliminary allocation completed: top at 0x%p\n", lpBase); #endif #ifdef KDB @@ -319,7 +306,7 @@ INIT void PreConfig(void) #endif /* We expect ram_top as Kbytes, so convert to paragraphs */ - mcb_init(first_mcb, ram_top*64 - first_mcb - 1); + mcb_init(first_mcb, ram_top * 64 - first_mcb - 1); nPass = 1; } @@ -329,36 +316,33 @@ INIT void PostConfig(void) { /* close all (device) files */ - /* Set pass number */ nPass = 2; /* compute lastdrive ... */ lastdrive = Config.cfgLastdrive; - if (lastdrive < nblkdev ) - lastdrive = nblkdev ; + if (lastdrive < nblkdev) + lastdrive = nblkdev; - /* initialize NEAR allocated things */ + /* initialize NEAR allocated things */ /* Initialize the file table */ DynFree(f_nodes); f_nodes = (f_node_ptr) - DynAlloc("f_nodes", Config.cfgFiles , sizeof(struct f_node)); - - f_nodes_cnt = Config.cfgFiles; /* and the number of allocated files */ + DynAlloc("f_nodes", Config.cfgFiles, sizeof(struct f_node)); + f_nodes_cnt = Config.cfgFiles; /* and the number of allocated files */ /* Initialize the base memory pointers from last time. */ /* - if the kernel could be moved to HMA, everything behind the dynamic - near data is free. - otherwise, the kernel is moved down - behind the dynamic allocated data, - and allocation starts after the kernel. - */ + if the kernel could be moved to HMA, everything behind the dynamic + near data is free. + otherwise, the kernel is moved down - behind the dynamic allocated data, + and allocation starts after the kernel. + */ - lpBase = AlignParagraph((BYTE FAR *)DynLast()+0x0f); - - DebugPrintf(("starting FAR allocations at %p\n",lpBase)); - + lpBase = AlignParagraph((BYTE FAR *) DynLast() + 0x0f); + + DebugPrintf(("starting FAR allocations at %p\n", lpBase)); /* Begin by initializing our system buffers */ /* dma_scratch = (BYTE FAR *) KernelAllocDma(BUFFERSIZE); */ @@ -366,143 +350,142 @@ INIT void PostConfig(void) /* printf("DMA scratchpad allocated at 0x%p\n", dma_scratch); */ #endif - config_init_buffers(Config.cfgBuffers); /* sfthead = (sfttbl FAR *)&basesft; */ /* FCBp = (sfttbl FAR *)&FcbSft; */ /* FCBp = (sfttbl FAR *) - KernelAlloc(sizeof(sftheader) - + Config.cfgFiles * sizeof(sft));*/ + KernelAlloc(sizeof(sftheader) + + Config.cfgFiles * sizeof(sft)); */ sfthead->sftt_next = (sfttbl FAR *) - KernelAlloc(sizeof(sftheader) - + (Config.cfgFiles-5) * sizeof(sft)); + KernelAlloc(sizeof(sftheader) + (Config.cfgFiles - 5) * sizeof(sft)); sfthead->sftt_next->sftt_next = (sfttbl FAR *) - 1; - sfthead->sftt_next->sftt_count = Config.cfgFiles-5; + sfthead->sftt_next->sftt_count = Config.cfgFiles - 5; - CDSp = (cdstbl FAR *) - KernelAlloc(0x58 * lastdrive); + CDSp = (cdstbl FAR *) KernelAlloc(0x58 * lastdrive); DPBp = (struct dpb FAR *) - KernelAlloc(blk_dev.dh_name[0]*sizeof(struct dpb)); - + KernelAlloc(blk_dev.dh_name[0] * sizeof(struct dpb)); #ifdef DEBUG - printf("Final: \n f_node 0x%x\n",f_nodes); + printf("Final: \n f_node 0x%x\n", f_nodes); /* printf(" FCB table 0x%p\n",FCBp);*/ - printf(" sft table 0x%p\n",sfthead->sftt_next); - printf(" CDS table 0x%p\n",CDSp); - printf(" DPB table 0x%p\n",DPBp); -#endif + printf(" sft table 0x%p\n", sfthead->sftt_next); + printf(" CDS table 0x%p\n", CDSp); + printf(" DPB table 0x%p\n", DPBp); +#endif if (Config.cfgStacks) { - VOID FAR *stackBase = KernelAlloc(Config.cfgStacks * Config.cfgStackSize); + VOID FAR *stackBase = + KernelAlloc(Config.cfgStacks * Config.cfgStackSize); init_stacks(stackBase, Config.cfgStacks, Config.cfgStackSize); - DebugPrintf(("Stacks allocated at %p\n",stackBase)); + DebugPrintf(("Stacks allocated at %p\n", stackBase)); } - DebugPrintf(("Allocation completed: top at 0x%p\n",lpBase)); + DebugPrintf(("Allocation completed: top at 0x%p\n", lpBase)); } /* This code must be executed after device drivers has been loaded */ INIT VOID configDone(VOID) { - if ( HMAState != HMA_DONE ) - { - lpBase = AlignParagraph(lpBase); - - DebugPrintf(("HMA not available, moving text to %x\n",FP_SEG(lpBase))); - MoveKernel(FP_SEG(lpBase)); - - lpBase = AlignParagraph((BYTE FAR *)lpBase + HMAFree + 0x0f); - - DebugPrintf(("kernel is low, start alloc at %p",lpBase)); + if (HMAState != HMA_DONE) + { + lpBase = AlignParagraph(lpBase); - /* final buffer processing, now upwards */ - HMAState = HMA_LOW; - config_init_buffers( Config.cfgBuffers); - } + DebugPrintf(("HMA not available, moving text to %x\n", + FP_SEG(lpBase))); + MoveKernel(FP_SEG(lpBase)); - if (lastdrive < nblkdev) { + lpBase = AlignParagraph((BYTE FAR *) lpBase + HMAFree + 0x0f); - DebugPrintf(("lastdrive %c too small upping it to: %c\n", lastdrive + 'A', nblkdev + 'A' -1)); + DebugPrintf(("kernel is low, start alloc at %p", lpBase)); + + /* final buffer processing, now upwards */ + HMAState = HMA_LOW; + config_init_buffers(Config.cfgBuffers); + } + + if (lastdrive < nblkdev) + { + + DebugPrintf(("lastdrive %c too small upping it to: %c\n", + lastdrive + 'A', nblkdev + 'A' - 1)); lastdrive = nblkdev; - CDSp = (cdstbl FAR *) - KernelAlloc(0x58 * lastdrive); + CDSp = (cdstbl FAR *) KernelAlloc(0x58 * lastdrive); } first_mcb = FP_SEG(lpBase) + ((FP_OFF(lpBase) + 0x0f) >> 4); /* We expect ram_top as Kbytes, so convert to paragraphs */ - mcb_init(first_mcb, ram_top*64 - first_mcb - 1); + mcb_init(first_mcb, ram_top * 64 - first_mcb - 1); - if(UmbState == 1) - { + if (UmbState == 1) + { - mumcb_init(ram_top*64 - 1, umb_start - 64*ram_top); + mumcb_init(ram_top * 64 - 1, umb_start - 64 * ram_top); /* Check if any devices were loaded in umb */ - if(umb_start != FP_SEG(upBase) ){ + if (umb_start != FP_SEG(upBase)) + { /* make last block normal with SC for the devices */ - - UCOUNT umr_new = FP_SEG(upBase) + ((FP_OFF(upBase) + 0x0f) >> 4); - - mumcb_init(uppermem_root, umr_new - uppermem_root - 1); - uppermem_root = umr_new; - zumcb_init(uppermem_root, (umb_start + UMB_top ) - uppermem_root - 1); - upBase += 16; - } + UCOUNT umr_new = FP_SEG(upBase) + ((FP_OFF(upBase) + 0x0f) >> 4); - { - /* are there any more UMB's ?? - this happens, if memory mapped devces are in between - like UMB memory c800..c8ff, d8ff..efff with device at d000..d7ff - */ + mumcb_init(uppermem_root, umr_new - uppermem_root - 1); - /* TE - this code - a) isn't the best I ever wrote :-( - b) works for 2 memory areas (no while(), use of UMB_top,...) - and the first discovered is the larger one. - no idea what happens, if the larger one is higher in memory. - might work, though - */ - - UCOUNT umb_seg, umb_size, umbz_root; - - umbz_root = uppermem_root; - - if(UMB_get_largest(&umb_seg, &umb_size)){ - - mcb_init(umbz_root, (umb_start + UMB_top ) - uppermem_root - 1); - - /* change UMB 'Z' to 'M' */ - ((mcb FAR *)MK_FP(umbz_root,0))->m_type = 'M'; - - /* move to end */ - umbz_root += ((mcb FAR *)MK_FP(umbz_root,0))->m_size + 1; - - /* create link mcb */ - mumcb_init(umbz_root, umb_seg - umbz_root - 1); - - - /* should the UMB driver return - adjacent memory in several pieces */ - if (umb_seg - umbz_root - 1 == 0) - ((mcb FAR *)MK_FP(umbz_root,0))->m_psp = FREE_PSP; - - /* create new 'Z' mcb */ - zumcb_init(umb_seg, umb_size - 1); - } - } + uppermem_root = umr_new; + zumcb_init(uppermem_root, (umb_start + UMB_top) - uppermem_root - 1); + upBase += 16; } - DebugPrintf(("UMB Allocation completed: top at 0x%p\n",upBase)); + { + /* are there any more UMB's ?? + this happens, if memory mapped devces are in between + like UMB memory c800..c8ff, d8ff..efff with device at d000..d7ff + */ + + /* TE - this code + a) isn't the best I ever wrote :-( + b) works for 2 memory areas (no while(), use of UMB_top,...) + and the first discovered is the larger one. + no idea what happens, if the larger one is higher in memory. + might work, though + */ + + UCOUNT umb_seg, umb_size, umbz_root; + + umbz_root = uppermem_root; + + if (UMB_get_largest(&umb_seg, &umb_size)) + { + + mcb_init(umbz_root, (umb_start + UMB_top) - uppermem_root - 1); + + /* change UMB 'Z' to 'M' */ + ((mcb FAR *) MK_FP(umbz_root, 0))->m_type = 'M'; + + /* move to end */ + umbz_root += ((mcb FAR *) MK_FP(umbz_root, 0))->m_size + 1; + + /* create link mcb */ + mumcb_init(umbz_root, umb_seg - umbz_root - 1); + + /* should the UMB driver return + adjacent memory in several pieces */ + if (umb_seg - umbz_root - 1 == 0) + ((mcb FAR *) MK_FP(umbz_root, 0))->m_psp = FREE_PSP; + + /* create new 'Z' mcb */ + zumcb_init(umb_seg, umb_size - 1); + } + } + } + + DebugPrintf(("UMB Allocation completed: top at 0x%p\n", upBase)); /* The standard handles should be reopened here, because we may have loaded new console or printer drivers in CONFIG.SYS */ - } INIT VOID DoConfig(VOID) @@ -515,9 +498,9 @@ INIT VOID DoConfig(VOID) /* exit since we don't force the user to have one. */ if ((nFileDesc = open("fdconfig.sys", 0)) >= 0) { - DebugPrintf(("Reading FDCONFIG.SYS...\n")); + DebugPrintf(("Reading FDCONFIG.SYS...\n")); } - else + else { DebugPrintf(("FDCONFIG.SYS not found\n")); if ((nFileDesc = open("config.sys", 0)) < 0) @@ -527,7 +510,6 @@ INIT VOID DoConfig(VOID) } DebugPrintf(("Reading CONFIG.SYS...\n")); } - /* Have one -- initialize. */ nCfgLine = 0; @@ -538,91 +520,89 @@ INIT VOID DoConfig(VOID) /* do the table lookup and execute the handler for that */ /* function. */ - for (;!bEof;nCfgLine++) + for (; !bEof; nCfgLine++) { struct table *pEntry; pLineStart = szLine; - - /* read in a single line, \n or ^Z terminated */ - + + /* read in a single line, \n or ^Z terminated */ + for (pLine = szLine;;) - { - if (read(nFileDesc, pLine, 1) <= 0) - { - bEof = TRUE; - break; - } - - /* immediately convert to upper case */ - *pLine = toupper(*pLine); - - if (pLine >= szLine + sizeof(szLine)-3) - { - CfgFailure(pLine); - printf("error - line overflow line %d \n",nCfgLine); - break; - } - - if (*pLine == '\n' || - *pLine == EOF ) /* end of line */ - break; - - if (*pLine == '\r') /* ignore */ - ; - else - pLine++; - } - - *pLine = 0; - pLine = szLine; - - - /* Skip leading white space and get verb. */ - pLine = scan(pLine, szBuf); - - /* If the line was blank, skip it. Otherwise, look up */ - /* the verb and execute the appropriate function. */ - if (*szBuf == '\0') - continue; - - pEntry = LookUp(commands, szBuf); - - if (pEntry->pass >= 0 && pEntry->pass != nPass) - continue; - - if ( SkipLine(pLineStart)) /* F5/F8 processing */ - continue; - - pLine = skipwh(pLine); - - if ('=' != *pLine) - CfgFailure(pLine); - else /* YES. DO IT */ - (*(pEntry->func)) (skipwh(pLine+1)); - - - - /* might have been the UMB driver */ - if(UmbState == 2){ - - UCOUNT umb_seg, umb_size; - - if(UMB_get_largest(&umb_seg, &umb_size)){ - UmbState = 1; - upBase = MK_FP(umb_seg , 0); - UMB_top = umb_size; - umb_start = umb_seg; - -/* reset root */ - uppermem_root = umb_seg; -/* setup the real mcb for the devicehigh block */ - zumcb_init(umb_seg, UMB_top - 1); - upBase += 16; - } - } - + { + if (read(nFileDesc, pLine, 1) <= 0) + { + bEof = TRUE; + break; } + + /* immediately convert to upper case */ + *pLine = toupper(*pLine); + + if (pLine >= szLine + sizeof(szLine) - 3) + { + CfgFailure(pLine); + printf("error - line overflow line %d \n", nCfgLine); + break; + } + + if (*pLine == '\n' || *pLine == EOF) /* end of line */ + break; + + if (*pLine == '\r') /* ignore */ + ; + else + pLine++; + } + + *pLine = 0; + pLine = szLine; + + /* Skip leading white space and get verb. */ + pLine = scan(pLine, szBuf); + + /* If the line was blank, skip it. Otherwise, look up */ + /* the verb and execute the appropriate function. */ + if (*szBuf == '\0') + continue; + + pEntry = LookUp(commands, szBuf); + + if (pEntry->pass >= 0 && pEntry->pass != nPass) + continue; + + if (SkipLine(pLineStart)) /* F5/F8 processing */ + continue; + + pLine = skipwh(pLine); + + if ('=' != *pLine) + CfgFailure(pLine); + else /* YES. DO IT */ + (*(pEntry->func)) (skipwh(pLine + 1)); + + /* might have been the UMB driver */ + if (UmbState == 2) + { + + UCOUNT umb_seg, umb_size; + + if (UMB_get_largest(&umb_seg, &umb_size)) + { + UmbState = 1; + upBase = MK_FP(umb_seg, 0); + UMB_top = umb_size; + umb_start = umb_seg; + +/* reset root */ + uppermem_root = umb_seg; +/* setup the real mcb for the devicehigh block */ + zumcb_init(umb_seg, UMB_top - 1); + upBase += 16; + } + } + + } close(nFileDesc); } @@ -654,114 +634,113 @@ INIT struct table *LookUp(struct table *p, BYTE * token) ULONG GetBiosTime(VOID) { - return *(ULONG FAR *)(MK_FP(0x40,0x6c)); -} + return *(ULONG FAR *) (MK_FP(0x40, 0x6c)); +} + UWORD GetBiosKey(int timeout) { - iregs r; - - ULONG startTime = GetBiosTime(); + iregs r; - for (;;) + ULONG startTime = GetBiosTime(); + + for (;;) + { + r.a.x = 0x0100; /* are there keys available ? */ + init_call_intr(0x16, &r); + + if ((r.flags & 0x40) == 0) /* yes - fetch and return */ { - r.a.x = 0x0100; /* are there keys available ? */ - init_call_intr(0x16,&r); + r.a.x = 0x0000; + init_call_intr(0x16, &r); - if ((r.flags & 0x40) == 0) /* yes - fetch and return */ - { - r.a.x = 0x0000; - init_call_intr(0x16,&r); - - return r.a.x; - } + return r.a.x; + } if (timeout < 0) - continue; - - if (GetBiosTime() - startTime >= timeout*18) - break; - } - return 0xffff; -} + continue; + + if (GetBiosTime() - startTime >= timeout * 18) + break; + } + return 0xffff; +} INIT BOOL SkipLine(char *pLine) { short key; - + static char initialized = FALSE; - + if (!initialized) { - - initialized = TRUE; - - if (InitKernelConfig.SkipConfigSeconds < 0) - return FALSE; - - if (InitKernelConfig.SkipConfigSeconds > 0) - printf("Press F8 to trace or F5 to skip CONFIG.SYS/AUTOEXEC.BAT"); - - key = GetBiosKey(InitKernelConfig.SkipConfigSeconds); /* wait 2 seconds */ - - if (key == 0x3f00) /* F5 */ - { - SkipAllConfig = TRUE; - } - if (key == 0x4200) /* F8 */ - { - singleStep = TRUE; - } - - printf("\r%79s\r",""); /* clear line */ - - if (SkipAllConfig) - printf("Skipping CONFIG.SYS/AUTOEXEC.BAT\n"); + + initialized = TRUE; + + if (InitKernelConfig.SkipConfigSeconds < 0) + return FALSE; + + if (InitKernelConfig.SkipConfigSeconds > 0) + printf("Press F8 to trace or F5 to skip CONFIG.SYS/AUTOEXEC.BAT"); + + key = GetBiosKey(InitKernelConfig.SkipConfigSeconds); /* wait 2 seconds */ + + if (key == 0x3f00) /* F5 */ + { + SkipAllConfig = TRUE; + } + if (key == 0x4200) /* F8 */ + { + singleStep = TRUE; + } + + printf("\r%79s\r", ""); /* clear line */ + + if (SkipAllConfig) + printf("Skipping CONFIG.SYS/AUTOEXEC.BAT\n"); } - - - if (SkipAllConfig) + if (SkipAllConfig) return TRUE; if (!askThisSingleCommand && !singleStep) return FALSE; - + printf("%s[Y,N]?", pLine); - + for (;;) { key = GetBiosKey(-1); - - switch(toupper(key & 0x00ff)) - { - case 'N': - case 'n': - printf("N\n"); - return TRUE; - case 0x1b: /* don't know where documented - ESCAPE answers all following questions - with YES - */ - singleStep = FALSE; /* and fall through */ - - case '\r': - case '\n': - case 'Y': - case 'y': - printf("Y\n"); - return FALSE; - - } - - if (key == 0x3f00) /* YES, you may hit F5 here, too */ + switch (toupper(key & 0x00ff)) { - printf("N\n"); - SkipAllConfig = TRUE; - return TRUE; + case 'N': + case 'n': + printf("N\n"); + return TRUE; + + case 0x1b: /* don't know where documented + ESCAPE answers all following questions + with YES + */ + singleStep = FALSE; /* and fall through */ + + case '\r': + case '\n': + case 'Y': + case 'y': + printf("Y\n"); + return FALSE; + } - } - + + if (key == 0x3f00) /* YES, you may hit F5 here, too */ + { + printf("N\n"); + SkipAllConfig = TRUE; + return TRUE; + } + } + } INIT BYTE *GetNumArg(BYTE * pLine, COUNT * pnArg) @@ -794,7 +773,8 @@ INIT void Config_Buffers(BYTE * pLine) return; /* Got the value, assign either default or new value */ - Config.cfgBuffers = (nBuffers < 0 ? nBuffers : max(Config.cfgBuffers, nBuffers)); + Config.cfgBuffers = + (nBuffers < 0 ? nBuffers : max(Config.cfgBuffers, nBuffers)); } INIT STATIC VOID sysScreenMode(BYTE * pLine) @@ -813,24 +793,24 @@ INIT STATIC VOID sysScreenMode(BYTE * pLine) 0x12 (18) 43/50 lines 0x14 (20) 25 lines */ -#if defined(__TURBOC__) +#if defined(__TURBOC__) _AX = (0x11 << 8) + nMode; _BL = 0; __int__(0x10); #else - asm { - mov al, byte ptr nMode; - mov ah, 0x11; - mov bl, 0; - int 0x10; - } + asm + { + mov al, byte ptr nMode; + mov ah, 0x11; + mov bl, 0; + int 0x10; + } #endif } INIT STATIC VOID sysVersion(BYTE * pLine) { - COUNT major, - minor; + COUNT major, minor; char *p; p = pLine; @@ -880,7 +860,7 @@ INIT STATIC VOID CfgLastdrive(BYTE * pLine) return; } drv -= 'A'; - drv++; /* Make real number*/ + drv++; /* Make real number */ Config.cfgLastdrive = max(Config.cfgLastdrive, drv); } @@ -888,43 +868,51 @@ INIT STATIC VOID CfgLastdrive(BYTE * pLine) UmbState of confidence, 1 is sure, 2 maybe, 4 unknown and 0 no way. */ - INIT STATIC VOID Dosmem(BYTE * pLine) { - BYTE *pTmp; - BYTE UMBwanted = FALSE; + BYTE *pTmp; + BYTE UMBwanted = FALSE; /* extern BYTE FAR INITDataSegmentClaimed; */ - pLine = GetStringArg(pLine, szBuf); + pLine = GetStringArg(pLine, szBuf); - for (pTmp = szBuf; *pTmp != '\0'; pTmp++) - *pTmp = toupper(*pTmp); + for (pTmp = szBuf; *pTmp != '\0'; pTmp++) + *pTmp = toupper(*pTmp); - printf("DOS called with %s\n", szBuf); + printf("DOS called with %s\n", szBuf); - for (pTmp = szBuf ; ; ) + for (pTmp = szBuf;;) + { + if (fmemcmp(pTmp, "UMB", 3) == 0) { - if (fmemcmp(pTmp, "UMB" ,3) == 0) { UMBwanted = TRUE; pTmp += 3; } - if (fmemcmp(pTmp, "HIGH",4) == 0) { HMAState = HMA_REQ; pTmp += 4; } + UMBwanted = TRUE; + pTmp += 3; + } + if (fmemcmp(pTmp, "HIGH", 4) == 0) + { + HMAState = HMA_REQ; + pTmp += 4; + } /* if (fmemcmp(pTmp, "CLAIMINIT",9) == 0) { INITDataSegmentClaimed = 0; pTmp += 9; }*/ - pTmp = skipwh(pTmp); + pTmp = skipwh(pTmp); - if (*pTmp != ',') - break; - pTmp++; - } - - - if(UmbState == 0){ - uppermem_link = 0; - uppermem_root = 0; - UmbState = UMBwanted ? 2 : 0; - } - /* Check if HMA is available straight away */ - if (HMAState == HMA_REQ && MoveKernelToHMA()){ - HMAState = HMA_DONE; - } + if (*pTmp != ',') + break; + pTmp++; + } + + if (UmbState == 0) + { + uppermem_link = 0; + uppermem_root = 0; + UmbState = UMBwanted ? 2 : 0; + } + /* Check if HMA is available straight away */ + if (HMAState == HMA_REQ && MoveKernelToHMA()) + { + HMAState = HMA_DONE; + } } INIT STATIC VOID CfgSwitchar(BYTE * pLine) @@ -968,13 +956,13 @@ INIT STATIC VOID Fcbs(BYTE * pLine) INIT BOOL LoadCountryInfo(char *filename, UWORD ctryCode, UWORD codePage) { /* printf("cntry: %u, CP%u, file=\"%s\"\n", ctryCode, codePage, filename); */ - printf("Sorry, the COUNTRY= statement has been temporarily disabled\n"); - - UNREFERENCED_PARAMETER(codePage); - UNREFERENCED_PARAMETER(ctryCode); - UNREFERENCED_PARAMETER(filename); - - return FALSE; + printf("Sorry, the COUNTRY= statement has been temporarily disabled\n"); + + UNREFERENCED_PARAMETER(codePage); + UNREFERENCED_PARAMETER(ctryCode); + UNREFERENCED_PARAMETER(filename); + + return FALSE; } INIT STATIC VOID Country(BYTE * pLine) @@ -1046,7 +1034,6 @@ INIT STATIC VOID InitPgmHigh(BYTE * pLine) Config.cfgP_0_startmode = 0x80; } - INIT STATIC VOID InitPgm(BYTE * pLine) { /* Get the string argument that represents the new init pgm */ @@ -1072,9 +1059,9 @@ INIT STATIC VOID CfgBreak(BYTE * pLine) INIT STATIC VOID Numlock(BYTE * pLine) { extern VOID ASMCFUNC keycheck(); - + /* Format: NUMLOCK = (ON | OFF) */ - BYTE FAR *keyflags = (BYTE FAR *)MK_FP(0x40,0x17); + BYTE FAR *keyflags = (BYTE FAR *) MK_FP(0x40, 0x17); GetStringArg(pLine, szBuf); @@ -1085,24 +1072,24 @@ INIT STATIC VOID Numlock(BYTE * pLine) INIT STATIC VOID DeviceHigh(BYTE * pLine) { - if(UmbState == 1) + if (UmbState == 1) + { + if (LoadDevice(pLine, UMB_top, TRUE) == DE_NOMEM) { - if (LoadDevice(pLine, UMB_top, TRUE) == DE_NOMEM) - { - printf("Not enough free memory in UMB's: loading low\n"); - LoadDevice(pLine, ram_top, FALSE); - } - } - else - { - printf("UMB's unavailable!\n"); - LoadDevice(pLine, ram_top, FALSE); + printf("Not enough free memory in UMB's: loading low\n"); + LoadDevice(pLine, ram_top, FALSE); } + } + else + { + printf("UMB's unavailable!\n"); + LoadDevice(pLine, ram_top, FALSE); + } } INIT void Device(BYTE * pLine) { - LoadDevice(pLine, ram_top, FALSE); + LoadDevice(pLine, ram_top, FALSE); } INIT BOOL LoadDevice(BYTE * pLine, COUNT top, COUNT mode) @@ -1112,7 +1099,7 @@ INIT BOOL LoadDevice(BYTE * pLine, COUNT top, COUNT mode) struct dhdr FAR *next_dhp; BOOL result; - if(mode) + if (mode) dhp = AlignParagraph(upBase); else dhp = AlignParagraph(lpBase); @@ -1125,52 +1112,49 @@ INIT BOOL LoadDevice(BYTE * pLine, COUNT top, COUNT mode) eb.load.reloc = eb.load.load_seg = FP_SEG(dhp); #ifdef DEBUG - printf("Loading device driver %s at segment %04x\n", - szBuf, FP_SEG(dhp)); + printf("Loading device driver %s at segment %04x\n", szBuf, FP_SEG(dhp)); #endif - if ((result = init_DosExec(3, &eb, szBuf)) != SUCCESS) - { + { CfgFailure(pLine); return result; - } - - strcpy(szBuf, pLine); + } - /* TE this fixes the loading of devices drivers with - multiple devices in it. NUMEGA's SoftIce is such a beast - */ - - /* add \r\n to the command line */ - strcat(szBuf, "\r\n"); - - - for (next_dhp=NULL; FP_OFF(next_dhp) != 0xffff && - (result=init_device(dhp, szBuf, mode, top))==SUCCESS - ; dhp = next_dhp) - { - next_dhp = dhp->dh_next; - if (FP_SEG(next_dhp) == 0xffff) - /* Does this ever occur with FP_OFF(next_dhp) != 0xffff ??? */ + strcpy(szBuf, pLine); + + /* TE this fixes the loading of devices drivers with + multiple devices in it. NUMEGA's SoftIce is such a beast + */ + + /* add \r\n to the command line */ + strcat(szBuf, "\r\n"); + + for (next_dhp = NULL; FP_OFF(next_dhp) != 0xffff && + (result = init_device(dhp, szBuf, mode, top)) == SUCCESS; + dhp = next_dhp) + { + next_dhp = dhp->dh_next; + if (FP_SEG(next_dhp) == 0xffff) + /* Does this ever occur with FP_OFF(next_dhp) != 0xffff ??? */ next_dhp = MK_FP(FP_SEG(dhp), FP_OFF(next_dhp)); -#ifdef DEBUG - else if (FP_OFF(next_dhp) != 0xffff) /* end of internal chain */ - printf("multisegmented device driver found, next %p\n",next_dhp); - /* give warning message */ -#endif - /* Link in device driver and save nul_dev pointer to next */ - dhp->dh_next = nul_dev.dh_next; - nul_dev.dh_next = dhp; - } - /* We could just have loaded FDXMS or HIMEM */ - if (HMAState == HMA_REQ && MoveKernelToHMA()) - { - /* final HMA processing: */ - /* final buffer processing, now upwards */ - HMAState = HMA_DONE; - config_init_buffers( Config.cfgBuffers); - } +#ifdef DEBUG + else if (FP_OFF(next_dhp) != 0xffff) /* end of internal chain */ + printf("multisegmented device driver found, next %p\n", next_dhp); + /* give warning message */ +#endif + /* Link in device driver and save nul_dev pointer to next */ + dhp->dh_next = nul_dev.dh_next; + nul_dev.dh_next = dhp; + } + /* We could just have loaded FDXMS or HIMEM */ + if (HMAState == HMA_REQ && MoveKernelToHMA()) + { + /* final HMA processing: */ + /* final buffer processing, now upwards */ + HMAState = HMA_DONE; + config_init_buffers(Config.cfgBuffers); + } return result; } @@ -1204,7 +1188,7 @@ INIT BYTE FAR *KernelAlloc(WORD nBytes) else lpBase += nBytes; - fmemset( lpAllocated, 0, nBytes); + fmemset(lpAllocated, 0, nBytes); return lpAllocated; } @@ -1229,9 +1213,9 @@ INIT void FAR *AlignParagraph(VOID FAR * lpPtr) /* First, convert the segmented pointer to linear address */ uSegVal = FP_SEG(lpPtr); - uSegVal += (FP_OFF(lpPtr)+0xf) >> 4; + uSegVal += (FP_OFF(lpPtr) + 0xf) >> 4; if (FP_OFF(lpPtr) > 0xfff0) - uSegVal += 0x1000; /* handle overflow */ + uSegVal += 0x1000; /* handle overflow */ /* and return an adddress adjusted to the nearest paragraph */ /* boundary. */ @@ -1239,39 +1223,36 @@ INIT void FAR *AlignParagraph(VOID FAR * lpPtr) } #endif -INIT BYTE * - skipwh(BYTE * s) +INIT BYTE *skipwh(BYTE * s) { while (*s && (*s == 0x0d || *s == 0x0a || *s == ' ' || *s == '\t')) ++s; return s; } -INIT BYTE * - scan(BYTE * s, BYTE * d) +INIT BYTE *scan(BYTE * s, BYTE * d) { askThisSingleCommand = FALSE; - + s = skipwh(s); - if (*s == ';') { + if (*s == ';') + { /* semicolon is a synonym for rem */ *d++ = *s++; } - else while (*s && - !(*s == 0x0d - || *s == 0x0a - || *s == ' ' - || *s == '\t' - || *s == '=')) - { - if (*s == '?') - { - askThisSingleCommand = TRUE; - s++; - } - else - *d++ = *s++; - } + else + while (*s && + !(*s == 0x0d + || *s == 0x0a || *s == ' ' || *s == '\t' || *s == '=')) + { + if (*s == '?') + { + askThisSingleCommand = TRUE; + s++; + } + else + *d++ = *s++; + } *d = '\0'; return s; } @@ -1304,7 +1285,7 @@ INIT BYTE *GetNumber(REG BYTE * pszString, REG COUNT * pnNum) pszString++; Sign = TRUE; } - + while (isnum(pszString) || toupper(*pszString) == 'X') { if (toupper(*pszString) == 'X') @@ -1342,20 +1323,19 @@ INIT COUNT toupper(COUNT c) /* The following code is 8086 dependant */ -#if 1 /* ifdef KERNEL */ -INIT VOID - mcb_init(UCOUNT seg, UWORD size) +#if 1 /* ifdef KERNEL */ +INIT VOID mcb_init(UCOUNT seg, UWORD size) { COUNT i; - mcb FAR * mcbp = MK_FP(seg,0); - + mcb FAR *mcbp = MK_FP(seg, 0); + mcbp->m_type = MCB_LAST; mcbp->m_psp = FREE_PSP; /* if(UmbState == 1)*/ - mcbp->m_size = (size - 1); + mcbp->m_size = (size - 1); /* mcbp->m_size = size; */ @@ -1364,12 +1344,11 @@ INIT VOID mem_access_mode = FIRST_FIT; } -INIT VOID - zumcb_init(UCOUNT seg, UWORD size) +INIT VOID zumcb_init(UCOUNT seg, UWORD size) { COUNT i; - mcb FAR * mcbp = MK_FP(seg,0); - + mcb FAR *mcbp = MK_FP(seg, 0); + mcbp->m_type = MCB_LAST; mcbp->m_psp = FREE_PSP; mcbp->m_size = size; @@ -1378,12 +1357,11 @@ INIT VOID } -INIT VOID - mumcb_init(UCOUNT seg, UWORD size) +INIT VOID mumcb_init(UCOUNT seg, UWORD size) { COUNT i; - mcb FAR * mcbp = MK_FP(seg,0); - + mcb FAR *mcbp = MK_FP(seg, 0); + static char name[8] = "SC\0\0\0\0\0\0"; mcbp->m_type = MCB_NORMAL; @@ -1394,8 +1372,7 @@ INIT VOID } #endif -INIT VOID - strcat(REG BYTE * d, REG BYTE * s) +INIT VOID strcat(REG BYTE * d, REG BYTE * s) { while (*d != 0) ++d; @@ -1405,37 +1382,37 @@ INIT VOID /* see if the second string is contained in the first one, ignoring case */ char *stristr(char *s1, char *s2) { - int loop; - - for ( ; *s1 ; s1++) - for ( loop = 0; ; loop++) - { - if (s2[loop] == 0) /* found end of string 2 -> success */ - { - return s1; /* position where s2 was found */ - } - if (toupper(s1[loop]) != toupper(s2[loop]) ) - break; - } - - return NULL; + int loop; + + for (; *s1; s1++) + for (loop = 0;; loop++) + { + if (s2[loop] == 0) /* found end of string 2 -> success */ + { + return s1; /* position where s2 was found */ + } + if (toupper(s1[loop]) != toupper(s2[loop])) + break; + } + + return NULL; } /* compare two ASCII strings ignoring case */ -INIT COUNT strcasecmp(REG BYTE *d, REG BYTE *s) +INIT COUNT strcasecmp(REG BYTE * d, REG BYTE * s) { - while (*s != '\0' && *d != '\0') - { - - if (toupper(*d) == toupper(*s)) - ++s, ++d; - - else - return toupper(*d) - toupper(*s); - - } - - return toupper(*d) - toupper(*s); + while (*s != '\0' && *d != '\0') + { + + if (toupper(*d) == toupper(*s)) + ++s, ++d; + + else + return toupper(*d) - toupper(*s); + + } + + return toupper(*d) - toupper(*s); } /* @@ -1443,7 +1420,6 @@ INIT COUNT strcasecmp(REG BYTE *d, REG BYTE *s) that saves some relocation problems */ - VOID config_init_buffers(COUNT anzBuffers) { REG WORD i; @@ -1457,30 +1433,31 @@ VOID config_init_buffers(COUNT anzBuffers) anzBuffers = -anzBuffers; fillhma = FALSE; } - - anzBuffers = max(anzBuffers,6); + + anzBuffers = max(anzBuffers, 6); if (anzBuffers > 99) - { - printf("BUFFERS=%u not supported, reducing to 99\n",anzBuffers); + { + printf("BUFFERS=%u not supported, reducing to 99\n", anzBuffers); anzBuffers = 99; - } + } LoL_nbuffers = anzBuffers; - + lpTop = lpOldTop; if (HMAState == HMA_NONE || HMAState == HMA_REQ) - lpTop = lpBase = lpTop - anzBuffers * (sizeof (struct buffer) + 0xf); - - firstbuf = ConfigAlloc(sizeof (struct buffer)); - - pbuffer = firstbuf; + lpTop = lpBase = lpTop - anzBuffers * (sizeof(struct buffer) + 0xf); + + firstbuf = ConfigAlloc(sizeof(struct buffer)); + + pbuffer = firstbuf; DebugPrintf(("init_buffers at")); - for (i = 0; ; ++i) + for (i = 0;; ++i) { - if (FP_SEG(pbuffer) == 0xffff) HMAcount++; - + if (FP_SEG(pbuffer) == 0xffff) + HMAcount++; + pbuffer->b_dummy = FP_OFF(pbuffer); pbuffer->b_unit = 0; pbuffer->b_flag = 0; @@ -1489,43 +1466,43 @@ VOID config_init_buffers(COUNT anzBuffers) pbuffer->b_offset = 0; pbuffer->b_next = NULL; - DebugPrintf((" (%d,%p)",i, pbuffer)); - - /* now, we can have quite some buffers in HMA - -- up to 37 for KE38616. - so we fill the HMA with buffers - but not if the BUFFERS count is negative ;-) - */ - + DebugPrintf((" (%d,%p)", i, pbuffer)); + + /* now, we can have quite some buffers in HMA + -- up to 37 for KE38616. + so we fill the HMA with buffers + but not if the BUFFERS count is negative ;-) + */ + if (i < (anzBuffers - 1)) { - pbuffer->b_next = HMAalloc(sizeof (struct buffer)); - - if (pbuffer->b_next == NULL) - { - /* if more buffer requested then fit into HMA, allocate - some from low memory as rewuested - */ - pbuffer->b_next = ConfigAlloc(sizeof (struct buffer)); - } + pbuffer->b_next = HMAalloc(sizeof(struct buffer)); + + if (pbuffer->b_next == NULL) + { + /* if more buffer requested then fit into HMA, allocate + some from low memory as rewuested + */ + pbuffer->b_next = ConfigAlloc(sizeof(struct buffer)); + } } else if (fillhma) - pbuffer->b_next = HMAalloc(sizeof (struct buffer)); - + pbuffer->b_next = HMAalloc(sizeof(struct buffer)); + if (pbuffer->b_next == NULL) - break; - - pbuffer = pbuffer->b_next; + break; + + pbuffer = pbuffer->b_next; } - + DebugPrintf((" done\n")); - + if (HMAcount) - printf("Kernel: allocated %d Diskbuffers = %u Bytes in HMA\n", - HMAcount, HMAcount*sizeof (struct buffer)); - + printf("Kernel: allocated %d Diskbuffers = %u Bytes in HMA\n", + HMAcount, HMAcount * sizeof(struct buffer)); + if (HMAState == HMA_NONE || HMAState == HMA_REQ) - lpBase = tmplpBase; + lpBase = tmplpBase; } /* @@ -1534,13 +1511,12 @@ VOID config_init_buffers(COUNT anzBuffers) ANYDOS will report to MSDOS programs just the version number they expect. be careful with it! -*/ - +*/ INIT VOID SetAnyDos(BYTE * pLine) { - UNREFERENCED_PARAMETER(pLine); - ReturnAnyDosVersionExpected = TRUE; + UNREFERENCED_PARAMETER(pLine); + ReturnAnyDosVersionExpected = TRUE; } /* @@ -1622,4 +1598,3 @@ INIT VOID SetAnyDos(BYTE * pLine) * Rev 1.0 19 Feb 1996 3:22:16 patv * Added NLS, int2f and config.sys processing */ - diff --git a/kernel/config.h b/kernel/config.h index 0a800fa..d06e885 100644 --- a/kernel/config.h +++ b/kernel/config.h @@ -27,12 +27,11 @@ /* Cambridge, MA 02139, USA. */ /****************************************************************/ - #ifdef DEBUG - /* Enable debugging of NLS part */ + /* Enable debugging of NLS part */ - /* Caution: Enabling NLS debugging usually generates - _a_lot_ of noise. */ + /* Caution: Enabling NLS debugging usually generates + _a_lot_ of noise. */ /*& #define NLS_DEBUG */ #endif diff --git a/kernel/dosfns.c b/kernel/dosfns.c index 527001e..ae28684 100644 --- a/kernel/dosfns.c +++ b/kernel/dosfns.c @@ -29,7 +29,8 @@ #include "portab.h" #ifdef VERSION_STRINGS -static BYTE *dosfnsRcsId = "$Id$"; +static BYTE *dosfnsRcsId = + "$Id$"; #endif #include "globals.h" @@ -40,80 +41,73 @@ BOOL cmatch(COUNT, COUNT, COUNT); f_node_ptr xlt_fd(COUNT); - /* /// Added for SHARE. - Ron Cemer */ BYTE share_installed = 0; - /* DOS calls this to see if it's okay to open the file. - Returns a file_table entry number to use (>= 0) if okay - to open. Otherwise returns < 0 and may generate a critical - error. If < 0 is returned, it is the negated error return - code, so DOS simply negates this value and returns it in - AX. */ -static int share_open_check - (char far *filename, /* far pointer to fully qualified filename */ - unsigned short pspseg, /* psp segment address of owner process */ - int openmode, /* 0=read-only, 1=write-only, 2=read-write */ - int sharemode); /* SHARE_COMPAT, etc... */ + /* DOS calls this to see if it's okay to open the file. + Returns a file_table entry number to use (>= 0) if okay + to open. Otherwise returns < 0 and may generate a critical + error. If < 0 is returned, it is the negated error return + code, so DOS simply negates this value and returns it in + AX. */ +static int share_open_check(char far * filename, /* far pointer to fully qualified filename */ + unsigned short pspseg, /* psp segment address of owner process */ + int openmode, /* 0=read-only, 1=write-only, 2=read-write */ + int sharemode); /* SHARE_COMPAT, etc... */ - /* DOS calls this to record the fact that it has successfully - closed a file, or the fact that the open for this file failed. */ -static void share_close_file - (int fileno); /* file_table entry number */ + /* DOS calls this to record the fact that it has successfully + closed a file, or the fact that the open for this file failed. */ +static void share_close_file(int fileno); /* file_table entry number */ - /* DOS calls this to determine whether it can access (read or - write) a specific section of a file. We call it internally - from lock_unlock (only when locking) to see if any portion - of the requested region is already locked. If pspseg is zero, - then it matches any pspseg in the lock table. Otherwise, only - locks which DO NOT belong to pspseg will be considered. - Returns zero if okay to access or lock (no portion of the - region is already locked). Otherwise returns non-zero and - generates a critical error (if allowcriter is non-zero). - If non-zero is returned, it is the negated return value for - the DOS call. */ -static int share_access_check - (unsigned short pspseg,/* psp segment address of owner process */ - int fileno, /* file_table entry number */ - unsigned long ofs, /* offset into file */ - unsigned long len, /* length (in bytes) of region to access */ - int allowcriter); /* allow a critical error to be generated */ + /* DOS calls this to determine whether it can access (read or + write) a specific section of a file. We call it internally + from lock_unlock (only when locking) to see if any portion + of the requested region is already locked. If pspseg is zero, + then it matches any pspseg in the lock table. Otherwise, only + locks which DO NOT belong to pspseg will be considered. + Returns zero if okay to access or lock (no portion of the + region is already locked). Otherwise returns non-zero and + generates a critical error (if allowcriter is non-zero). + If non-zero is returned, it is the negated return value for + the DOS call. */ +static int share_access_check(unsigned short pspseg, /* psp segment address of owner process */ + int fileno, /* file_table entry number */ + unsigned long ofs, /* offset into file */ + unsigned long len, /* length (in bytes) of region to access */ + int allowcriter); /* allow a critical error to be generated */ - /* DOS calls this to lock or unlock a specific section of a file. - Returns zero if successfully locked or unlocked. Otherwise - returns non-zero. - If the return value is non-zero, it is the negated error - return code for the DOS 0x5c call. */ -static int share_lock_unlock - (unsigned short pspseg,/* psp segment address of owner process */ - int fileno, /* file_table entry number */ - unsigned long ofs, /* offset into file */ - unsigned long len, /* length (in bytes) of region to lock or unlock */ - int unlock); /* non-zero to unlock; zero to lock */ + /* DOS calls this to lock or unlock a specific section of a file. + Returns zero if successfully locked or unlocked. Otherwise + returns non-zero. + If the return value is non-zero, it is the negated error + return code for the DOS 0x5c call. */ +static int share_lock_unlock(unsigned short pspseg, /* psp segment address of owner process */ + int fileno, /* file_table entry number */ + unsigned long ofs, /* offset into file */ + unsigned long len, /* length (in bytes) of region to lock or unlock */ + int unlock); /* non-zero to unlock; zero to lock */ /* /// End of additions for SHARE. - Ron Cemer */ - #ifdef WITHFAT32 -struct dpb FAR *GetDriveDPB(UBYTE drive, COUNT *rc) +struct dpb FAR *GetDriveDPB(UBYTE drive, COUNT * rc) { struct dpb FAR *dpb; drive = drive == 0 ? default_drive : drive - 1; - + if (drive >= lastdrive) - { - *rc = DE_INVLDDRV; - return 0; - } + { + *rc = DE_INVLDDRV; + return 0; + } dpb = CDSp->cds_table[drive].cdsDpb; - if (dpb == 0 || - CDSp->cds_table[drive].cdsFlags & CDSNETWDRV) - { - *rc = DE_INVLDDRV; - return 0; - } + if (dpb == 0 || CDSp->cds_table[drive].cdsFlags & CDSNETWDRV) + { + *rc = DE_INVLDDRV; + return 0; + } *rc = SUCCESS; return dpb; @@ -141,16 +135,15 @@ sft FAR *idx_to_sft(COUNT SftIndex) return (sft FAR *) - 1; /* Get the SFT block that contains the SFT */ - for (sp = sfthead; sp != (sfttbl FAR *) - 1; - sp = sp->sftt_next) + for (sp = sfthead; sp != (sfttbl FAR *) - 1; sp = sp->sftt_next) { - if (SftIndex < sp->sftt_count) + if (SftIndex < sp->sftt_count) { lpCurSft = (sft FAR *) & (sp->sftt_table[SftIndex]); - + /* finally, point to the right entry */ return lpCurSft; - } + } else SftIndex -= sp->sftt_count; } @@ -181,8 +174,8 @@ sft FAR *get_sft(UCOUNT hndl) * binary reads, while for 0x40 the type of read (binary/text) depends on what * the SFT says. -- ror4 */ -UCOUNT GenericReadSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err, - BOOL force_binary) +UCOUNT GenericReadSft(sft FAR * s, UCOUNT n, BYTE FAR * bp, + COUNT FAR * err, BOOL force_binary) { UCOUNT ReadCount; @@ -211,7 +204,7 @@ UCOUNT GenericReadSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err, save_dta = dta; lpCurSft = s; - current_filepos = s->sft_posit; /* needed for MSCDEX */ + current_filepos = s->sft_posit; /* needed for MSCDEX */ dta = bp; ReadCount = remote_read(s, n, &rc); dta = save_dta; @@ -274,19 +267,21 @@ UCOUNT GenericReadSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err, COUNT rc; /* /// Added for SHARE - Ron Cemer */ - if (IsShareInstalled()) { - if (s->sft_shroff >= 0) { - int share_result = share_access_check - (cu_psp, - s->sft_shroff, - s->sft_posit, - (unsigned long)n, - 1); - if (share_result != 0) { - *err = share_result; - return 0; - } - } + if (IsShareInstalled()) + { + if (s->sft_shroff >= 0) + { + int share_result = share_access_check(cu_psp, + s->sft_shroff, + s->sft_posit, + (unsigned long)n, + 1); + if (share_result != 0) + { + *err = share_result; + return 0; + } + } } /* /// End of additions for SHARE - Ron Cemer */ @@ -305,7 +300,7 @@ UCOUNT DosRead(COUNT hndl, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) } #endif -UCOUNT DosWriteSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) +UCOUNT DosWriteSft(sft FAR * s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) { UCOUNT WriteCount; @@ -332,7 +327,7 @@ UCOUNT DosWriteSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) save_dta = dta; lpCurSft = s; - current_filepos = s->sft_posit; /* needed for MSCDEX */ + current_filepos = s->sft_posit; /* needed for MSCDEX */ dta = bp; WriteCount = remote_write(s, n, &rc); dta = save_dta; @@ -399,13 +394,14 @@ UCOUNT DosWriteSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) { REG WORD xfer; - for(xfer = 0; xfer < n && *bp != CTL_Z; bp++, xfer++) + for (xfer = 0; xfer < n && *bp != CTL_Z; bp++, xfer++) { if (s->sft_flags & SFT_FCONOUT) - { - cso(*bp); + { + cso(*bp); } - else FOREVER + else + FOREVER { rq.r_length = sizeof(request); rq.r_command = C_OUTPUT; @@ -414,22 +410,22 @@ UCOUNT DosWriteSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) rq.r_status = 0; execrh((request FAR *) & rq, s->sft_dev); if (!(rq.r_status & S_ERROR)) - break; - charloop: - switch(char_error(&rq, s->sft_dev)) - { - case ABORT: - case FAIL: - *err = DE_INVLDACC; - return xfer; - case CONTINUE: - break; - case RETRY: - continue; - default: - goto charloop; - } - break; + break; + charloop: + switch (char_error(&rq, s->sft_dev)) + { + case ABORT: + case FAIL: + *err = DE_INVLDACC; + return xfer; + case CONTINUE: + break; + case RETRY: + continue; + default: + goto charloop; + } + break; } if (control_break()) { @@ -447,27 +443,29 @@ UCOUNT DosWriteSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) COUNT rc; /* /// Added for SHARE - Ron Cemer */ - if (IsShareInstalled()) { - if (s->sft_shroff >= 0) { - int share_result = share_access_check - (cu_psp, - s->sft_shroff, - s->sft_posit, - (unsigned long)n, - 1); - if (share_result != 0) { - *err = share_result; - return 0; - } - } + if (IsShareInstalled()) + { + if (s->sft_shroff >= 0) + { + int share_result = share_access_check(cu_psp, + s->sft_shroff, + s->sft_posit, + (unsigned long)n, + 1); + if (share_result != 0) + { + *err = share_result; + return 0; + } + } } /* /// End of additions for SHARE - Ron Cemer */ WriteCount = writeblock(s->sft_status, bp, n, &rc); s->sft_size = dos_getcufsize(s->sft_status); /* if (rc < SUCCESS) */ - if (rc == DE_ACCESS || /* -5 Access denied */ - rc == DE_INVLDHNDL ) /* -6 Invalid handle */ + if (rc == DE_ACCESS || /* -5 Access denied */ + rc == DE_INVLDHNDL) /* -6 Invalid handle */ { *err = rc; return 0; @@ -482,7 +480,7 @@ UCOUNT DosWriteSft(sft FAR *s, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) return 0; } -COUNT SftSeek(sft FAR *s, LONG new_pos, COUNT mode) +COUNT SftSeek(sft FAR * s, LONG new_pos, COUNT mode) { /* Test for invalid mode */ if (mode < 0 || mode > 2) @@ -493,7 +491,8 @@ COUNT SftSeek(sft FAR *s, LONG new_pos, COUNT mode) if (s->sft_flags & SFT_FSHARED) { /* seek from end of file */ - if (mode == 2) { + if (mode == 2) + { /* * RB list has it as Note: * this function is called by the DOS 3.1+ kernel, but only when seeking @@ -504,60 +503,64 @@ COUNT SftSeek(sft FAR *s, LONG new_pos, COUNT mode) * Lredir via mfs.c from DosEMU works when writing appended files. * Mfs.c looks for these mode bits set, so here is my best guess.;^) */ - if ((s->sft_mode & SFT_MDENYREAD) || (s->sft_mode & SFT_MDENYNONE)) - { - s->sft_posit = remote_lseek(s, new_pos); - return SUCCESS; - } - else - { - s->sft_posit = s->sft_size + new_pos; - return SUCCESS; - } - } - if (mode == 0) { - s->sft_posit = new_pos; + if ((s->sft_mode & SFT_MDENYREAD) || (s->sft_mode & SFT_MDENYNONE)) + { + s->sft_posit = remote_lseek(s, new_pos); return SUCCESS; - } - if (mode == 1) { - s->sft_posit += new_pos; + } + else + { + s->sft_posit = s->sft_size + new_pos; return SUCCESS; + } + } + if (mode == 0) + { + s->sft_posit = new_pos; + return SUCCESS; + } + if (mode == 1) + { + s->sft_posit += new_pos; + return SUCCESS; } return DE_INVLDFUNC; - } + } - /* Do special return for character devices */ - if (s->sft_flags & SFT_FDEVICE) - { - s->sft_posit = 0l; - return SUCCESS; - } + /* Do special return for character devices */ + if (s->sft_flags & SFT_FDEVICE) + { + s->sft_posit = 0l; + return SUCCESS; + } + else + { + LONG result = dos_lseek(s->sft_status, new_pos, mode); + if (result < 0l) + return (int)result; else { - LONG result = dos_lseek(s->sft_status, new_pos, mode); - if (result < 0l) - return (int)result; - else { - s->sft_posit = result; - return SUCCESS; - } + s->sft_posit = result; + return SUCCESS; } + } } COUNT DosSeek(COUNT hndl, LONG new_pos, COUNT mode, ULONG * set_pos) { - sft FAR *s; - COUNT result; + sft FAR *s; + COUNT result; - /* Get the SFT block that contains the SFT */ - if ((s = get_sft(hndl)) == (sft FAR *) - 1) - return DE_INVLDHNDL; + /* Get the SFT block that contains the SFT */ + if ((s = get_sft(hndl)) == (sft FAR *) - 1) + return DE_INVLDHNDL; - result = SftSeek(s, new_pos, mode); - if (result == SUCCESS) { - *set_pos = s->sft_posit; - } - return result; + result = SftSeek(s, new_pos, mode); + if (result == SUCCESS) + { + *set_pos = s->sft_posit; + } + return result; } STATIC COUNT get_free_hndl(void) @@ -573,7 +576,7 @@ STATIC COUNT get_free_hndl(void) return DE_TOOMANY; } -sft FAR *get_free_sft(COUNT *sft_idx) +sft FAR *get_free_sft(COUNT * sft_idx) { COUNT sys_idx = 0; sfttbl FAR *sp; @@ -584,17 +587,17 @@ sft FAR *get_free_sft(COUNT *sft_idx) REG COUNT i = sp->sftt_count; sft FAR *sfti = sp->sftt_table; - for(; --i >= 0 ; sys_idx++, sfti++) + for (; --i >= 0; sys_idx++, sfti++) { if (sfti->sft_count == 0) { - *sft_idx = sys_idx; + *sft_idx = sys_idx; - /* MS NET uses this on open/creat TE*/ - { + /* MS NET uses this on open/creat TE */ + { extern WORD current_sft_idx; current_sft_idx = sys_idx; - } + } return sfti; } @@ -648,12 +651,12 @@ COUNT DosCreatSft(BYTE * fname, COUNT attrib) WORD result; COUNT drive; - /* NEVER EVER allow directories to be created */ + /* NEVER EVER allow directories to be created */ attrib &= 0xff; - if (attrib & ~(D_RDONLY|D_HIDDEN|D_SYSTEM|D_ARCHIVE)) - { - return DE_ACCESS; - } + if (attrib & ~(D_RDONLY | D_HIDDEN | D_SYSTEM | D_ARCHIVE)) + { + return DE_ACCESS; + } /* now get a free system file table entry */ if ((sftp = get_free_sft(&sft_idx)) == (sft FAR *) - 1) @@ -661,47 +664,50 @@ COUNT DosCreatSft(BYTE * fname, COUNT attrib) fmemset(sftp, 0, sizeof(sft)); - sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ + sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ sftp->sft_psp = cu_psp; sftp->sft_mode = SFT_MRDWR; sftp->sft_attrib = attrib; sftp->sft_psp = cu_psp; - /* check for a device */ - dhp = IsDevice(fname); - if ( dhp ) - { - sftp->sft_count += 1; - sftp->sft_flags = - ((dhp->dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF; - fmemcpy(sftp->sft_name, (BYTE FAR *) SecPathName, FNAME_SIZE + FEXT_SIZE); - sftp->sft_dev = dhp; - return sft_idx; - } + /* check for a device */ + dhp = IsDevice(fname); + if (dhp) + { + sftp->sft_count += 1; + sftp->sft_flags = + ((dhp-> + dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF; + fmemcpy(sftp->sft_name, (BYTE FAR *) SecPathName, + FNAME_SIZE + FEXT_SIZE); + sftp->sft_dev = dhp; + return sft_idx; + } - if (current_ldt->cdsFlags & CDSNETWDRV) { - lpCurSft = sftp; - result = remote_creat(sftp, attrib); - if (result == SUCCESS) { - sftp->sft_count += 1; - return sft_idx; - } - return result; + if (current_ldt->cdsFlags & CDSNETWDRV) + { + lpCurSft = sftp; + result = remote_creat(sftp, attrib); + if (result == SUCCESS) + { + sftp->sft_count += 1; + return sft_idx; + } + return result; } - + drive = get_verify_drive(fname); - if (drive < 0) { - return drive; + if (drive < 0) + { + return drive; } - + /* /// Added for SHARE. - Ron Cemer */ - if (IsShareInstalled()) { - if ((sftp->sft_shroff = share_open_check - ((char far *)fname, - cu_psp, - 0x02, /* read-write */ - 0)) < 0) /* compatibility mode */ - return sftp->sft_shroff; + if (IsShareInstalled()) + { + if ((sftp->sft_shroff = share_open_check((char far *)fname, cu_psp, 0x02, /* read-write */ + 0)) < 0) /* compatibility mode */ + return sftp->sft_shroff; } /* /// End of additions for SHARE. - Ron Cemer */ @@ -712,11 +718,14 @@ COUNT DosCreatSft(BYTE * fname, COUNT attrib) sftp->sft_flags = drive; DosGetFile(fname, sftp->sft_name); return sft_idx; - } else { + } + else + { /* /// Added for SHARE *** CURLY BRACES ADDED ALSO!!! ***. - Ron Cemer */ - if (IsShareInstalled()) { - share_close_file(sftp->sft_shroff); - sftp->sft_shroff = -1; + if (IsShareInstalled()) + { + share_close_file(sftp->sft_shroff); + sftp->sft_shroff = -1; } /* /// End of additions for SHARE. - Ron Cemer */ return sftp->sft_status; @@ -727,21 +736,22 @@ COUNT DosCreat(BYTE FAR * fname, COUNT attrib) { psp FAR *p = MK_FP(cu_psp, 0); COUNT sft_idx, hndl, result; - + /* get a free handle */ if ((hndl = get_free_hndl()) < 0) return hndl; result = truename(fname, PriPathName, FALSE); - if (result != SUCCESS) { + if (result != SUCCESS) + { return result; } sft_idx = DosCreatSft(PriPathName, attrib); if (sft_idx < SUCCESS) - return sft_idx; - + return sft_idx; + p->ps_filetab[hndl] = sft_idx; return hndl; } @@ -780,7 +790,8 @@ COUNT DosDup(COUNT Handle) return NewHandle; /* If everything looks ok, bump it up. */ - if ((Sftp->sft_flags & (SFT_FDEVICE | SFT_FSHARED)) || (Sftp->sft_status >= 0)) + if ((Sftp->sft_flags & (SFT_FDEVICE | SFT_FSHARED)) + || (Sftp->sft_status >= 0)) { p->ps_filetab[NewHandle] = p->ps_filetab[Handle]; Sftp->sft_count += 1; @@ -813,7 +824,8 @@ COUNT DosForceDup(COUNT OldHandle, COUNT NewHandle) } /* If everything looks ok, bump it up. */ - if ((Sftp->sft_flags & (SFT_FDEVICE | SFT_FSHARED)) || (Sftp->sft_status >= 0)) + if ((Sftp->sft_flags & (SFT_FDEVICE | SFT_FSHARED)) + || (Sftp->sft_status >= 0)) { p->ps_filetab[NewHandle] = p->ps_filetab[OldHandle]; @@ -851,47 +863,50 @@ COUNT DosOpenSft(BYTE * fname, COUNT mode) /* check for a device */ dhp = IsDevice(fname); - if ( dhp ) + if (dhp) { - sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ - + sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ sftp->sft_count += 1; sftp->sft_flags = - ((dhp->dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF; - fmemcpy(sftp->sft_name, (BYTE FAR *) SecPathName, FNAME_SIZE + FEXT_SIZE); + ((dhp-> + dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF; + fmemcpy(sftp->sft_name, (BYTE FAR *) SecPathName, + FNAME_SIZE + FEXT_SIZE); sftp->sft_dev = dhp; sftp->sft_date = dos_getdate(); sftp->sft_time = dos_gettime(); return sft_idx; } - if (current_ldt->cdsFlags & CDSNETWDRV) { - lpCurSft = sftp; - result = remote_open(sftp, mode); - /* printf("open SFT %d = %p\n",sft_idx,sftp); */ - if (result == SUCCESS) { - sftp->sft_count += 1; - return sft_idx; - } - return result; + if (current_ldt->cdsFlags & CDSNETWDRV) + { + lpCurSft = sftp; + result = remote_open(sftp, mode); + /* printf("open SFT %d = %p\n",sft_idx,sftp); */ + if (result == SUCCESS) + { + sftp->sft_count += 1; + return sft_idx; + } + return result; } drive = get_verify_drive(fname); - if (drive < 0) { - return drive; + if (drive < 0) + { + return drive; } - sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ + sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ /* /// Added for SHARE. - Ron Cemer */ - if (IsShareInstalled()) { + if (IsShareInstalled()) + { if ((sftp->sft_shroff = share_open_check - ((char far *)fname, - (unsigned short)cu_psp, - mode & 0x03, - (mode >> 2) & 0x07)) < 0) - return sftp->sft_shroff; + ((char far *)fname, + (unsigned short)cu_psp, mode & 0x03, (mode >> 2) & 0x07)) < 0) + return sftp->sft_shroff; } /* /// End of additions for SHARE. - Ron Cemer */ @@ -907,24 +922,27 @@ COUNT DosOpenSft(BYTE * fname, COUNT mode) if ((sftp->sft_attrib & (D_DIR | D_VOLID)) || ((sftp->sft_attrib & D_RDONLY) && (mode != O_RDONLY))) { - dos_close(sftp->sft_status); + dos_close(sftp->sft_status); return DE_ACCESS; } sftp->sft_size = dos_getfsize(sftp->sft_status); dos_getftime(sftp->sft_status, - (date FAR *) & sftp->sft_date, - (time FAR *) & sftp->sft_time); + (date FAR *) & sftp->sft_date, + (time FAR *) & sftp->sft_time); sftp->sft_count += 1; sftp->sft_mode = mode; sftp->sft_flags = drive; DosGetFile(fname, sftp->sft_name); return sft_idx; - } else { + } + else + { /* /// Added for SHARE *** CURLY BRACES ADDED ALSO!!! ***. - Ron Cemer */ - if (IsShareInstalled()) { - share_close_file(sftp->sft_shroff); - sftp->sft_shroff = -1; + if (IsShareInstalled()) + { + share_close_file(sftp->sft_shroff); + sftp->sft_shroff = -1; } /* /// End of additions for SHARE. - Ron Cemer */ return sftp->sft_status; @@ -941,15 +959,16 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode) return hndl; result = truename(fname, PriPathName, FALSE); - if (result != SUCCESS) { - return result; + if (result != SUCCESS) + { + return result; } sft_idx = DosOpenSft(PriPathName, mode); if (sft_idx < SUCCESS) - return sft_idx; - + return sft_idx; + p->ps_filetab[hndl] = sft_idx; return hndl; } @@ -957,7 +976,7 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode) COUNT DosCloseSft(WORD sft_idx) { sft FAR *sftp = idx_to_sft(sft_idx); - + if (sftp == (sft FAR *) - 1) return DE_INVLDHNDL; @@ -970,10 +989,10 @@ COUNT DosCloseSft(WORD sft_idx) remote sub sft_count. */ if (sftp->sft_flags & SFT_FSHARED) - { + { /* printf("closing SFT %d = %p\n",sft_idx,sftp); */ return remote_close(sftp); - } + } /* now just drop the count if a device, else */ /* call file system handler */ @@ -984,11 +1003,14 @@ COUNT DosCloseSft(WORD sft_idx) { if (sftp->sft_count > 0) return SUCCESS; - else { + else + { /* /// Added for SHARE *** CURLY BRACES ADDED ALSO!!! ***. - Ron Cemer */ - if (IsShareInstalled()) { - if (sftp->sft_shroff >= 0) share_close_file(sftp->sft_shroff); - sftp->sft_shroff = -1; + if (IsShareInstalled()) + { + if (sftp->sft_shroff >= 0) + share_close_file(sftp->sft_shroff); + sftp->sft_shroff = -1; } /* /// End of additions for SHARE. - Ron Cemer */ return dos_close(sftp->sft_status); @@ -1008,57 +1030,58 @@ COUNT DosClose(COUNT hndl) return ret; } -BOOL DosGetFree(UBYTE drive, UCOUNT FAR * spc, UCOUNT FAR * navc, UCOUNT FAR * bps, UCOUNT FAR * nc) +BOOL DosGetFree(UBYTE drive, UCOUNT FAR * spc, UCOUNT FAR * navc, + UCOUNT FAR * bps, UCOUNT FAR * nc) { - /* *nc==0xffff means: called from FatGetDrvData, fcbfns.c */ + /* *nc==0xffff means: called from FatGetDrvData, fcbfns.c */ struct dpb FAR *dpbp; struct cds FAR *cdsp; - COUNT rg[4]; + COUNT rg[4]; /* next - "log" in the drive */ drive = (drive == 0 ? default_drive : drive - 1); - /* first check for valid drive */ + /* first check for valid drive */ *spc = -1; if (drive >= lastdrive) - return FALSE; - + return FALSE; + cdsp = &CDSp->cds_table[drive]; if (!(cdsp->cdsFlags & CDSVALID)) - return FALSE; - + return FALSE; + if (cdsp->cdsFlags & CDSNETWDRV) { - if (*nc == 0xffff) - { - /* Undoc DOS says, its not supported for - network drives. so it's probably OK */ - /*printf("FatGetDrvData not yet supported over network drives\n");*/ - return FALSE; - } - - remote_getfree(cdsp, rg); - - *spc = (COUNT) rg[0]; - *nc = (COUNT) rg[1]; - *bps = (COUNT) rg[2]; - *navc = (COUNT) rg[3]; - return TRUE; + if (*nc == 0xffff) + { + /* Undoc DOS says, its not supported for + network drives. so it's probably OK */ + /*printf("FatGetDrvData not yet supported over network drives\n"); */ + return FALSE; + } + + remote_getfree(cdsp, rg); + + *spc = (COUNT) rg[0]; + *nc = (COUNT) rg[1]; + *bps = (COUNT) rg[2]; + *navc = (COUNT) rg[3]; + return TRUE; } dpbp = CDSp->cds_table[drive].cdsDpb; if (dpbp == NULL) - return FALSE; + return FALSE; if (*nc == 0xffff) { - flush_buffers(dpbp->dpb_unit); - dpbp->dpb_flags = M_CHANGED; + flush_buffers(dpbp->dpb_unit); + dpbp->dpb_flags = M_CHANGED; } - + if (media_check(dpbp) < 0) - return FALSE; + return FALSE; /* get the data available from dpb */ *spc = dpbp->dpb_clsmask + 1; *bps = dpbp->dpb_secsize; @@ -1071,9 +1094,10 @@ BOOL DosGetFree(UBYTE drive, UCOUNT FAR * spc, UCOUNT FAR * navc, UCOUNT FAR * b ULONG cluster_size, ntotal, nfree; /* we shift ntotal until it is equal to or below 0xfff6 */ - cluster_size = (ULONG)dpbp->dpb_secsize << dpbp->dpb_shftcnt; + cluster_size = (ULONG) dpbp->dpb_secsize << dpbp->dpb_shftcnt; ntotal = dpbp->dpb_xsize - 1; - if (*nc != 0xffff) nfree = dos_free(dpbp); + if (*nc != 0xffff) + nfree = dos_free(dpbp); while (ntotal > FAT_MAGIC16 && cluster_size < 0x8000) { cluster_size <<= 1; @@ -1082,24 +1106,26 @@ BOOL DosGetFree(UBYTE drive, UCOUNT FAR * spc, UCOUNT FAR * navc, UCOUNT FAR * b nfree >>= 1; } /* get the data available from dpb */ - *nc = ntotal > FAT_MAGIC16 ? FAT_MAGIC16 : (UCOUNT)ntotal; + *nc = ntotal > FAT_MAGIC16 ? FAT_MAGIC16 : (UCOUNT) ntotal; /* now tell fs to give us free cluster */ /* count */ - *navc = nfree > FAT_MAGIC16 ? FAT_MAGIC16 : (UCOUNT)nfree; + *navc = nfree > FAT_MAGIC16 ? FAT_MAGIC16 : (UCOUNT) nfree; return TRUE; } #endif /* a passed nc of 0xffff means: skip free; see FatGetDrvData fcbfns.c */ - if (*nc != 0xffff) *navc = (COUNT)dos_free(dpbp); + if (*nc != 0xffff) + *navc = (COUNT) dos_free(dpbp); *nc = dpbp->dpb_size - 1; - if (*spc > 64) { - /* fake for 64k clusters do confuse some DOS programs, but let - others work without overflowing */ + if (*spc > 64) + { + /* fake for 64k clusters do confuse some DOS programs, but let + others work without overflowing */ *spc >>= 1; - *navc = (*navc < FAT_MAGIC16/2) ? (*navc << 1) : FAT_MAGIC16; - *nc = (*nc < FAT_MAGIC16/2) ? (*nc << 1) : FAT_MAGIC16; + *navc = (*navc < FAT_MAGIC16 / 2) ? (*navc << 1) : FAT_MAGIC16; + *nc = (*nc < FAT_MAGIC16 / 2) ? (*nc << 1) : FAT_MAGIC16; } return TRUE; } @@ -1107,48 +1133,52 @@ BOOL DosGetFree(UBYTE drive, UCOUNT FAR * spc, UCOUNT FAR * navc, UCOUNT FAR * b #ifdef WITHFAT32 /* network names like \\SERVER\C aren't supported yet */ #define IS_SLASH(ch) (ch == '\\' || ch == '/') -COUNT DosGetExtFree(BYTE FAR *DriveString, struct xfreespace FAR *xfsp) +COUNT DosGetExtFree(BYTE FAR * DriveString, struct xfreespace FAR * xfsp) { struct dpb FAR *dpbp; struct cds FAR *cdsp; UBYTE drive; - UCOUNT rg[4]; + UCOUNT rg[4]; if (IS_SLASH(DriveString[0]) || !IS_SLASH(DriveString[2]) - || DriveString[1] != ':') - return DE_INVLDDRV; + || DriveString[1] != ':') + return DE_INVLDDRV; drive = DosUpFChar(*DriveString) - 'A'; - if (drive >= lastdrive) return DE_INVLDDRV; + if (drive >= lastdrive) + return DE_INVLDDRV; cdsp = &CDSp->cds_table[drive]; if (!(cdsp->cdsFlags & CDSVALID)) - return DE_INVLDDRV; - + return DE_INVLDDRV; + if (cdsp->cdsFlags & CDSNETWDRV) { - remote_getfree(cdsp, rg); - - xfsp->xfs_clussize = rg[0]; - xfsp->xfs_totalclusters = rg[1]; - xfsp->xfs_secsize = rg[2]; - xfsp->xfs_freeclusters = rg[3]; - } else { - dpbp = CDSp->cds_table[drive].cdsDpb; - if (dpbp == NULL || media_check(dpbp) < 0) - return DE_INVLDDRV; - xfsp->xfs_secsize = dpbp->dpb_secsize; - xfsp->xfs_totalclusters = (ISFAT32(dpbp) ? dpbp->dpb_xsize : dpbp->dpb_size); - xfsp->xfs_freeclusters = dos_free(dpbp); - xfsp->xfs_clussize = dpbp->dpb_clsmask + 1; - } - xfsp->xfs_totalunits = xfsp->xfs_totalclusters; - xfsp->xfs_freeunits = xfsp->xfs_freeclusters; - xfsp->xfs_totalsectors = xfsp->xfs_totalclusters * xfsp->xfs_clussize; - xfsp->xfs_freesectors = xfsp->xfs_freeclusters * xfsp->xfs_clussize; - xfsp->xfs_datasize = sizeof(struct xfreespace); + remote_getfree(cdsp, rg); - fmemset(xfsp->xfs_reserved, 0, 8); + xfsp->xfs_clussize = rg[0]; + xfsp->xfs_totalclusters = rg[1]; + xfsp->xfs_secsize = rg[2]; + xfsp->xfs_freeclusters = rg[3]; + } + else + { + dpbp = CDSp->cds_table[drive].cdsDpb; + if (dpbp == NULL || media_check(dpbp) < 0) + return DE_INVLDDRV; + xfsp->xfs_secsize = dpbp->dpb_secsize; + xfsp->xfs_totalclusters = + (ISFAT32(dpbp) ? dpbp->dpb_xsize : dpbp->dpb_size); + xfsp->xfs_freeclusters = dos_free(dpbp); + xfsp->xfs_clussize = dpbp->dpb_clsmask + 1; + } + xfsp->xfs_totalunits = xfsp->xfs_totalclusters; + xfsp->xfs_freeunits = xfsp->xfs_freeclusters; + xfsp->xfs_totalsectors = xfsp->xfs_totalclusters * xfsp->xfs_clussize; + xfsp->xfs_freesectors = xfsp->xfs_freeclusters * xfsp->xfs_clussize; + xfsp->xfs_datasize = sizeof(struct xfreespace); + + fmemset(xfsp->xfs_reserved, 0, 8); return SUCCESS; } @@ -1157,22 +1187,23 @@ COUNT DosGetExtFree(BYTE FAR *DriveString, struct xfreespace FAR *xfsp) COUNT DosGetCuDir(UBYTE drive, BYTE FAR * s) { BYTE FAR *cp; - + /* next - "log" in the drive */ drive = (drive == 0 ? default_drive : drive - 1); /* first check for valid drive */ - if (drive >= lastdrive || !(CDSp->cds_table[drive].cdsFlags & CDSVALID)) { + if (drive >= lastdrive || !(CDSp->cds_table[drive].cdsFlags & CDSVALID)) + { return DE_INVLDDRV; } - + current_ldt = &CDSp->cds_table[drive]; cp = ¤t_ldt->cdsCurrentPath[current_ldt->cdsJoinOffset]; if (*cp == '\0') - s[0]='\0'; + s[0] = '\0'; else - fstrncpy(s, cp+1, 64); + fstrncpy(s, cp + 1, 64); return SUCCESS; } @@ -1181,43 +1212,43 @@ COUNT DosGetCuDir(UBYTE drive, BYTE FAR * s) COUNT DosChangeDir(BYTE FAR * s) { REG COUNT drive; - COUNT result; - BYTE FAR *p; - - /* don't do wildcard CHDIR --TE*/ - for (p = s; *p; p++) - if (*p == '*' || *p == '?') - return DE_PATHNOTFND; - - + COUNT result; + BYTE FAR *p; - drive = get_verify_drive(s); - if (drive < 0 ) { - return drive; - } + /* don't do wildcard CHDIR --TE */ + for (p = s; *p; p++) + if (*p == '*' || *p == '?') + return DE_PATHNOTFND; - result = truename(s, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } + drive = get_verify_drive(s); + if (drive < 0) + { + return drive; + } + + result = truename(s, PriPathName, FALSE); + if (result != SUCCESS) + { + return result; + } current_ldt = &CDSp->cds_table[drive]; - if (strlen(PriPathName) > sizeof(current_ldt->cdsCurrentPath)-1) + if (strlen(PriPathName) > sizeof(current_ldt->cdsCurrentPath) - 1) return DE_PATHNOTFND; #if defined(CHDIR_DEBUG) - printf("Remote Chdir: n='%Fs' p='%Fs\n",s,PriPathName); + printf("Remote Chdir: n='%Fs' p='%Fs\n", s, PriPathName); #endif /* now get fs to change to new */ - /* directory */ + /* directory */ result = (current_ldt->cdsFlags & CDSNETWDRV) ? remote_chdir() : dos_cd(current_ldt, PriPathName); #if defined(CHDIR_DEBUG) printf("status = %04x, new_path='%Fs'\n", result, cdsd->cdsCurrentPath); #endif if (result != SUCCESS) - return result; + return result; /* Copy the path to the current directory structure. @@ -1225,9 +1256,9 @@ COUNT DosChangeDir(BYTE FAR * s) Some redirectors do not write back to the CDS. SHSUCdX needs this. jt */ - fstrcpy(current_ldt->cdsCurrentPath,PriPathName); + fstrcpy(current_ldt->cdsCurrentPath, PriPathName); if (PriPathName[7] == 0) - current_ldt->cdsCurrentPath[8] = 0; /* Need two Zeros at the end */ + current_ldt->cdsCurrentPath[8] = 0; /* Need two Zeros at the end */ return SUCCESS; } @@ -1237,7 +1268,7 @@ STATIC VOID pop_dmp(dmatch FAR * dmp) dmp->dm_time = SearchDir.dir_time; dmp->dm_date = SearchDir.dir_date; dmp->dm_size = (LONG) SearchDir.dir_size; - ConvertName83ToNameSZ(dmp->dm_name, (BYTE FAR *)SearchDir.dir_name); + ConvertName83ToNameSZ(dmp->dm_name, (BYTE FAR *) SearchDir.dir_name); } COUNT DosFindFirst(UCOUNT attr, BYTE FAR * name) @@ -1246,40 +1277,41 @@ COUNT DosFindFirst(UCOUNT attr, BYTE FAR * name) REG dmatch FAR *dmp = (dmatch FAR *) dta; BYTE FAR *p; - /* /// Added code here to do matching against device names. - DOS findfirst will match exact device names if the - filename portion (excluding the extension) contains - a valid device name. - Credits: some of this code was ripped off from truename() - in newstuff.c. - - Ron Cemer */ + /* /// Added code here to do matching against device names. + DOS findfirst will match exact device names if the + filename portion (excluding the extension) contains + a valid device name. + Credits: some of this code was ripped off from truename() + in newstuff.c. + - Ron Cemer */ fmemset(dta, 0, sizeof(dmatch)); - + /* initially mark the dta as invalid for further findnexts */ - ((dmatch FAR *)dta)->dm_attr_fnd = D_DEVICE; - + ((dmatch FAR *) dta)->dm_attr_fnd = D_DEVICE; + memset(&SearchDir, 0, sizeof(struct dirent)); - + rc = truename(name, PriPathName, FALSE); if (rc != SUCCESS) - return rc; - + return rc; + if (IsDevice(PriPathName)) { COUNT i; - + /* Found a matching device. Hence there cannot be wildcards. */ SearchDir.dir_attrib = D_DEVICE; SearchDir.dir_time = dos_gettime(); SearchDir.dir_date = dos_getdate(); p = get_root(PriPathName); - memset(SearchDir.dir_name, ' ', FNAME_SIZE+FEXT_SIZE); + memset(SearchDir.dir_name, ' ', FNAME_SIZE + FEXT_SIZE); for (i = 0; i < FNAME_SIZE && *p && *p != '.'; i++) - SearchDir.dir_name[i] = *p++; - if (*p == '.') p++; + SearchDir.dir_name[i] = *p++; + if (*p == '.') + p++; for (i = 0; i < FEXT_SIZE && *p && *p != '.'; i++) - SearchDir.dir_ext[i] = *p++; + SearchDir.dir_ext[i] = *p++; pop_dmp(dmp); return SUCCESS; } @@ -1293,17 +1325,18 @@ COUNT DosFindFirst(UCOUNT attr, BYTE FAR * name) fmemcpy(TempBuffer, dta, 21); p = dta; - dta = (BYTE FAR *)TempBuffer; - + dta = (BYTE FAR *) TempBuffer; + rc = current_ldt->cdsFlags & CDSNETWDRV ? - remote_findfirst((VOID FAR *)current_ldt) : - dos_findfirst(attr, PriPathName); + remote_findfirst((VOID FAR *) current_ldt) : + dos_findfirst(attr, PriPathName); dta = p; fmemcpy(dta, TempBuffer, 21); - pop_dmp((dmatch FAR *)dta); - if (rc != SUCCESS) ((dmatch FAR *)dta)->dm_attr_fnd = D_DEVICE; /* mark invalid */ + pop_dmp((dmatch FAR *) dta); + if (rc != SUCCESS) + ((dmatch FAR *) dta)->dm_attr_fnd = D_DEVICE; /* mark invalid */ return rc; } @@ -1313,8 +1346,8 @@ COUNT DosFindNext(void) BYTE FAR *p; /* /// findnext will always fail on a device name. - Ron Cemer */ - if (((dmatch FAR *)dta)->dm_attr_fnd == D_DEVICE) - return DE_NFILES; + if (((dmatch FAR *) dta)->dm_attr_fnd == D_DEVICE) + return DE_NFILES; /* * The new version of SHSUCDX 1.0 looks at the dm_drive byte to @@ -1334,20 +1367,18 @@ COUNT DosFindNext(void) * (12h, DE_NFILES) */ #if 0 - printf("findnext: %d\n", - ((dmatch FAR *)dta)->dm_drive); + printf("findnext: %d\n", ((dmatch FAR *) dta)->dm_drive); #endif fmemcpy(TempBuffer, dta, 21); fmemset(dta, 0, sizeof(dmatch)); p = dta; - dta = (BYTE FAR *)TempBuffer; - rc = (((dmatch *)TempBuffer)->dm_drive & 0x80) ? - remote_findnext((VOID FAR *)current_ldt) : - dos_findnext(); - + dta = (BYTE FAR *) TempBuffer; + rc = (((dmatch *) TempBuffer)->dm_drive & 0x80) ? + remote_findnext((VOID FAR *) current_ldt) : dos_findnext(); + dta = p; fmemcpy(dta, TempBuffer, 21); - pop_dmp((dmatch FAR *)dta); + pop_dmp((dmatch FAR *) dta); return rc; } @@ -1380,7 +1411,7 @@ COUNT DosSetFtimeSft(WORD sft_idx, date dp, time tp) { /* Get the SFT block that contains the SFT */ sft FAR *s = idx_to_sft(sft_idx); - + if (s == (sft FAR *) - 1) return DE_INVLDHNDL; @@ -1405,37 +1436,42 @@ COUNT DosSetFtimeSft(WORD sft_idx, date dp, time tp) COUNT DosGetFattr(BYTE FAR * name) { - COUNT result, drive; + COUNT result, drive; - if (IsDevice(name)) { - return DE_FILENOTFND; - } + if (IsDevice(name)) + { + return DE_FILENOTFND; + } - drive = get_verify_drive(name); - if (drive < 0) { - return drive; - } + drive = get_verify_drive(name); + if (drive < 0) + { + return drive; + } - result = truename(name, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } + result = truename(name, PriPathName, FALSE); + if (result != SUCCESS) + { + return result; + } /* /// Added check for "d:\", which returns 0x10 (subdirectory) under DOS. - Ron Cemer */ - if ( (PriPathName[0] != '\0') - && (PriPathName[1] == ':') - && ( (PriPathName[2] == '/') || (PriPathName[2] == '\\') ) - && (PriPathName[3] == '\0') ) { - return 0x10; - } + if ((PriPathName[0] != '\0') + && (PriPathName[1] == ':') + && ((PriPathName[2] == '/') || (PriPathName[2] == '\\')) + && (PriPathName[3] == '\0')) + { + return 0x10; + } - current_ldt = &CDSp->cds_table[drive]; - if (current_ldt->cdsFlags & CDSNETWDRV) - { - return remote_getfattr(); - } - else { + current_ldt = &CDSp->cds_table[drive]; + if (current_ldt->cdsFlags & CDSNETWDRV) + { + return remote_getfattr(); + } + else + { /* /// Use truename()'s result, which we already have in PriPathName. I copy it to tmp_name because PriPathName is global and seems to get trashed somewhere in transit. @@ -1451,48 +1487,52 @@ COUNT DosGetFattr(BYTE FAR * name) /* no longer true. dos_getfattr() is A) intelligent (uses dos_open) anyway B) there are some problems with MAX_PARSE, i.e. if PATH ~= 64 - and TRUENAME adds a C:, which leeds to trouble. - + and TRUENAME adds a C:, which leeds to trouble. + the problem was discovered, when VC did something like - - fd = DosOpen(filename,...) - jc can't_copy_dialog; - attr = DosGetAttrib(filename); - jc can't_copy_dialog; - and suddenly, the filehandle stays open - shit. - tom - */ - return dos_getfattr(PriPathName); + fd = DosOpen(filename,...) + jc can't_copy_dialog; - } + attr = DosGetAttrib(filename); + jc can't_copy_dialog; + and suddenly, the filehandle stays open + shit. + tom + */ + return dos_getfattr(PriPathName); + + } } COUNT DosSetFattr(BYTE FAR * name, UWORD attrp) { - COUNT result, drive; + COUNT result, drive; - if (IsDevice(name) ) { - return DE_FILENOTFND; - } + if (IsDevice(name)) + { + return DE_FILENOTFND; + } - drive = get_verify_drive(name); - if (drive < 0) { - return drive; - } + drive = get_verify_drive(name); + if (drive < 0) + { + return drive; + } - result = truename(name, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } + result = truename(name, PriPathName, FALSE); + if (result != SUCCESS) + { + return result; + } - current_ldt = &CDSp->cds_table[drive]; - if (current_ldt->cdsFlags & CDSNETWDRV) - { - return remote_setfattr(attrp); - } - else { + current_ldt = &CDSp->cds_table[drive]; + if (current_ldt->cdsFlags & CDSNETWDRV) + { + return remote_setfattr(attrp); + } + else + { /* /// Use truename()'s result, which we already have in PriPathName. I copy it to tmp_name because PriPathName is global and seems to get trashed somewhere in transit. @@ -1503,135 +1543,160 @@ COUNT DosSetFattr(BYTE FAR * name, UWORD attrp) return dos_setfattr(SecPathName, attrp); see DosGetAttr() -*/ - return dos_setfattr(PriPathName, attrp); +*/ + return dos_setfattr(PriPathName, attrp); - } + } } UBYTE DosSelectDrv(UBYTE drv) { current_ldt = &CDSp->cds_table[drv]; - + if ((drv < lastdrive) && (current_ldt->cdsFlags & CDSVALID)) /* && ((cdsp->cdsFlags & CDSNETWDRV) || (cdsp->cdsDpb!=NULL && media_check(cdsp->cdsDpb)==SUCCESS))) -*/ +*/ default_drive = drv; - + return lastdrive; } -COUNT DosDelete(BYTE FAR *path) +COUNT DosDelete(BYTE FAR * path) { - COUNT result, drive; + COUNT result, drive; - if (IsDevice(path)) { - return DE_FILENOTFND; - } + if (IsDevice(path)) + { + return DE_FILENOTFND; + } - drive = get_verify_drive(path); - if (drive < 0) { - return drive; - } - result = truename(path, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } - current_ldt = &CDSp->cds_table[drive]; - if (current_ldt->cdsFlags & CDSNETWDRV) { - return remote_delete(); - } else { - return dos_delete(PriPathName); - } + drive = get_verify_drive(path); + if (drive < 0) + { + return drive; + } + result = truename(path, PriPathName, FALSE); + if (result != SUCCESS) + { + return result; + } + current_ldt = &CDSp->cds_table[drive]; + if (current_ldt->cdsFlags & CDSNETWDRV) + { + return remote_delete(); + } + else + { + return dos_delete(PriPathName); + } } COUNT DosRenameTrue(BYTE * path1, BYTE * path2) { - COUNT drive1, drive2; + COUNT drive1, drive2; - if (IsDevice(path1) || IsDevice(path2)) { - return DE_FILENOTFND; - } + if (IsDevice(path1) || IsDevice(path2)) + { + return DE_FILENOTFND; + } - drive1 = get_verify_drive(path1); - drive2 = get_verify_drive(path2); - if ((drive1 != drive2) || (drive1 < 0)) { - return DE_INVLDDRV; - } - current_ldt = &CDSp->cds_table[drive1]; - if (current_ldt->cdsFlags & CDSNETWDRV) { - return remote_rename(); - } else { - return dos_rename(PriPathName, SecPathName); - } + drive1 = get_verify_drive(path1); + drive2 = get_verify_drive(path2); + if ((drive1 != drive2) || (drive1 < 0)) + { + return DE_INVLDDRV; + } + current_ldt = &CDSp->cds_table[drive1]; + if (current_ldt->cdsFlags & CDSNETWDRV) + { + return remote_rename(); + } + else + { + return dos_rename(PriPathName, SecPathName); + } } COUNT DosRename(BYTE FAR * path1, BYTE FAR * path2) { - COUNT result; + COUNT result; - result = truename(path1, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } + result = truename(path1, PriPathName, FALSE); + if (result != SUCCESS) + { + return result; + } - result = truename(path2, SecPathName, FALSE); - if (result != SUCCESS) { - return result; - } + result = truename(path2, SecPathName, FALSE); + if (result != SUCCESS) + { + return result; + } - return DosRenameTrue(PriPathName, SecPathName); + return DosRenameTrue(PriPathName, SecPathName); } COUNT DosMkdir(BYTE FAR * dir) { - COUNT result, drive; + COUNT result, drive; - if (IsDevice(dir)) { - return DE_PATHNOTFND; - } + if (IsDevice(dir)) + { + return DE_PATHNOTFND; + } - drive = get_verify_drive(dir); - if (drive < 0) { - return drive; - } - result = truename(dir, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } - current_ldt = &CDSp->cds_table[drive]; - if (current_ldt->cdsFlags & CDSNETWDRV) { - return remote_mkdir(); - } else { - return dos_mkdir(PriPathName); - } + drive = get_verify_drive(dir); + if (drive < 0) + { + return drive; + } + result = truename(dir, PriPathName, FALSE); + if (result != SUCCESS) + { + return result; + } + current_ldt = &CDSp->cds_table[drive]; + if (current_ldt->cdsFlags & CDSNETWDRV) + { + return remote_mkdir(); + } + else + { + return dos_mkdir(PriPathName); + } } COUNT DosRmdir(BYTE FAR * dir) { - COUNT result, drive; + COUNT result, drive; - if (IsDevice(dir)) { - return DE_PATHNOTFND; - } + if (IsDevice(dir)) + { + return DE_PATHNOTFND; + } - drive = get_verify_drive(dir); - if (drive < 0) { - return drive; - } - result = truename(dir, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } - current_ldt = &CDSp->cds_table[drive]; - if (CDSp->cds_table[drive].cdsFlags & CDSNETWDRV) { - return remote_rmdir(); - } else { - return dos_rmdir(PriPathName); - } + drive = get_verify_drive(dir); + if (drive < 0) + { + return drive; + } + result = truename(dir, PriPathName, FALSE); + if (result != SUCCESS) + { + return result; + } + current_ldt = &CDSp->cds_table[drive]; + if (CDSp->cds_table[drive].cdsFlags & CDSNETWDRV) + { + return remote_rmdir(); + } + else + { + return dos_rmdir(PriPathName); + } } /* /// Added for SHARE. - Ron Cemer */ @@ -1641,13 +1706,16 @@ COUNT DosLockUnlock(COUNT hndl, LONG pos, LONG len, COUNT unlock) sft FAR *s; /* Invalid function unless SHARE is installed. */ - if (!IsShareInstalled()) return DE_INVLDFUNC; + if (!IsShareInstalled()) + return DE_INVLDFUNC; /* Get the SFT block that contains the SFT */ - if ((s = get_sft(hndl)) == (sft FAR *) -1) return DE_INVLDHNDL; + if ((s = get_sft(hndl)) == (sft FAR *) - 1) + return DE_INVLDHNDL; /* Lock violation if this SFT entry does not support locking. */ - if (s->sft_shroff < 0) return DE_LOCK; + if (s->sft_shroff < 0) + return DE_LOCK; /* Let SHARE do the work. */ return share_lock_unlock(cu_psp, s->sft_shroff, pos, len, unlock); @@ -1659,12 +1727,12 @@ COUNT DosLockUnlock(COUNT hndl, LONG pos, LONG len, COUNT unlock) * This seems to work well. */ -struct dhdr FAR * IsDevice(BYTE FAR * fname) +struct dhdr FAR *IsDevice(BYTE FAR * fname) { struct dhdr FAR *dhp; BYTE FAR *froot; WORD i; - BYTE tmpPathName[FNAME_SIZE+1]; + BYTE tmpPathName[FNAME_SIZE + 1]; /* check for a device */ froot = get_root(fname); @@ -1691,129 +1759,133 @@ struct dhdr FAR * IsDevice(BYTE FAR * fname) { */ - for (dhp = (struct dhdr FAR *)&nul_dev; dhp != (struct dhdr FAR *)-1; dhp = dhp->dh_next) + for (dhp = (struct dhdr FAR *)&nul_dev; dhp != (struct dhdr FAR *)-1; + dhp = dhp->dh_next) + { + + /* BUGFIX: MSCD000<00> should be handled like MSCD000<20> TE */ + + char dev_name_buff[FNAME_SIZE]; + + int namelen = fstrlen(dhp->dh_name); + + memset(dev_name_buff, ' ', FNAME_SIZE); + + fmemcpy(dev_name_buff, dhp->dh_name, min(namelen, FNAME_SIZE)); + + if (fnmatch + ((BYTE FAR *) tmpPathName, (BYTE FAR *) dev_name_buff, FNAME_SIZE, + FALSE)) { - - /* BUGFIX: MSCD000<00> should be handled like MSCD000<20> TE */ - - char dev_name_buff[FNAME_SIZE]; - - int namelen = fstrlen(dhp->dh_name); - - memset(dev_name_buff, ' ', FNAME_SIZE); - - fmemcpy(dev_name_buff,dhp->dh_name, min(namelen,FNAME_SIZE)); - - if (fnmatch((BYTE FAR *) tmpPathName, (BYTE FAR *) dev_name_buff, FNAME_SIZE, FALSE)) - { - memcpy(SecPathName, tmpPathName, i+1); - return dhp; - } + memcpy(SecPathName, tmpPathName, i + 1); + return dhp; } + } return (struct dhdr FAR *)0; } - /* /// Added for SHARE. - Ron Cemer */ -BOOL IsShareInstalled(void) { - if (!share_installed) { - iregs regs; - - regs.a.x = 0x1000; - intr(0x2f, ®s); - share_installed = ((regs.a.x & 0xff) == 0xff); - } - return share_installed; -} - - /* DOS calls this to see if it's okay to open the file. - Returns a file_table entry number to use (>= 0) if okay - to open. Otherwise returns < 0 and may generate a critical - error. If < 0 is returned, it is the negated error return - code, so DOS simply negates this value and returns it in - AX. */ -static int share_open_check - (char far *filename, /* far pointer to fully qualified filename */ - unsigned short pspseg, /* psp segment address of owner process */ - int openmode, /* 0=read-only, 1=write-only, 2=read-write */ - int sharemode) { /* SHARE_COMPAT, etc... */ +BOOL IsShareInstalled(void) +{ + if (!share_installed) + { iregs regs; - regs.a.x = 0x10a0; - regs.ds = FP_SEG(filename); - regs.si = FP_OFF(filename); - regs.b.x = pspseg; - regs.c.x = openmode; - regs.d.x = sharemode; + regs.a.x = 0x1000; intr(0x2f, ®s); - return (int)regs.a.x; + share_installed = ((regs.a.x & 0xff) == 0xff); + } + return share_installed; } - /* DOS calls this to record the fact that it has successfully - closed a file, or the fact that the open for this file failed. */ -static void share_close_file - (int fileno) { /* file_table entry number */ - iregs regs; + /* DOS calls this to see if it's okay to open the file. + Returns a file_table entry number to use (>= 0) if okay + to open. Otherwise returns < 0 and may generate a critical + error. If < 0 is returned, it is the negated error return + code, so DOS simply negates this value and returns it in + AX. */ +static int share_open_check(char far * filename, /* far pointer to fully qualified filename */ + unsigned short pspseg, /* psp segment address of owner process */ + int openmode, /* 0=read-only, 1=write-only, 2=read-write */ + int sharemode) +{ /* SHARE_COMPAT, etc... */ + iregs regs; - regs.a.x = 0x10a1; - regs.b.x = fileno; - intr(0x2f, ®s); + regs.a.x = 0x10a0; + regs.ds = FP_SEG(filename); + regs.si = FP_OFF(filename); + regs.b.x = pspseg; + regs.c.x = openmode; + regs.d.x = sharemode; + intr(0x2f, ®s); + return (int)regs.a.x; } - /* DOS calls this to determine whether it can access (read or - write) a specific section of a file. We call it internally - from lock_unlock (only when locking) to see if any portion - of the requested region is already locked. If pspseg is zero, - then it matches any pspseg in the lock table. Otherwise, only - locks which DO NOT belong to pspseg will be considered. - Returns zero if okay to access or lock (no portion of the - region is already locked). Otherwise returns non-zero and - generates a critical error (if allowcriter is non-zero). - If non-zero is returned, it is the negated return value for - the DOS call. */ -static int share_access_check - (unsigned short pspseg,/* psp segment address of owner process */ - int fileno, /* file_table entry number */ - unsigned long ofs, /* offset into file */ - unsigned long len, /* length (in bytes) of region to access */ - int allowcriter) { /* allow a critical error to be generated */ - iregs regs; + /* DOS calls this to record the fact that it has successfully + closed a file, or the fact that the open for this file failed. */ +static void share_close_file(int fileno) +{ /* file_table entry number */ + iregs regs; - regs.a.x = 0x10a2 | (allowcriter ? 0x01 : 0x00); - regs.b.x = pspseg; - regs.c.x = fileno; - regs.si = (unsigned short)((ofs >> 16) & 0xffffL); - regs.di = (unsigned short)(ofs & 0xffffL); - regs.es = (unsigned short)((len >> 16) & 0xffffL); - regs.d.x = (unsigned short)(len & 0xffffL); - intr(0x2f, ®s); - return (int)regs.a.x; + regs.a.x = 0x10a1; + regs.b.x = fileno; + intr(0x2f, ®s); } - /* DOS calls this to lock or unlock a specific section of a file. - Returns zero if successfully locked or unlocked. Otherwise - returns non-zero. - If the return value is non-zero, it is the negated error - return code for the DOS 0x5c call. */ -static int share_lock_unlock - (unsigned short pspseg,/* psp segment address of owner process */ - int fileno, /* file_table entry number */ - unsigned long ofs, /* offset into file */ - unsigned long len, /* length (in bytes) of region to lock or unlock */ - int unlock) { /* non-zero to unlock; zero to lock */ - iregs regs; + /* DOS calls this to determine whether it can access (read or + write) a specific section of a file. We call it internally + from lock_unlock (only when locking) to see if any portion + of the requested region is already locked. If pspseg is zero, + then it matches any pspseg in the lock table. Otherwise, only + locks which DO NOT belong to pspseg will be considered. + Returns zero if okay to access or lock (no portion of the + region is already locked). Otherwise returns non-zero and + generates a critical error (if allowcriter is non-zero). + If non-zero is returned, it is the negated return value for + the DOS call. */ +static int share_access_check(unsigned short pspseg, /* psp segment address of owner process */ + int fileno, /* file_table entry number */ + unsigned long ofs, /* offset into file */ + unsigned long len, /* length (in bytes) of region to access */ + int allowcriter) +{ /* allow a critical error to be generated */ + iregs regs; - regs.a.x = 0x10a4 | (unlock ? 0x01 : 0x00); - regs.b.x = pspseg; - regs.c.x = fileno; - regs.si = (unsigned short)((ofs >> 16) & 0xffffL); - regs.di = (unsigned short)(ofs & 0xffffL); - regs.es = (unsigned short)((len >> 16) & 0xffffL); - regs.d.x = (unsigned short)(len & 0xffffL); - intr(0x2f, ®s); - return (int)regs.a.x; + regs.a.x = 0x10a2 | (allowcriter ? 0x01 : 0x00); + regs.b.x = pspseg; + regs.c.x = fileno; + regs.si = (unsigned short)((ofs >> 16) & 0xffffL); + regs.di = (unsigned short)(ofs & 0xffffL); + regs.es = (unsigned short)((len >> 16) & 0xffffL); + regs.d.x = (unsigned short)(len & 0xffffL); + intr(0x2f, ®s); + return (int)regs.a.x; +} + + /* DOS calls this to lock or unlock a specific section of a file. + Returns zero if successfully locked or unlocked. Otherwise + returns non-zero. + If the return value is non-zero, it is the negated error + return code for the DOS 0x5c call. */ +static int share_lock_unlock(unsigned short pspseg, /* psp segment address of owner process */ + int fileno, /* file_table entry number */ + unsigned long ofs, /* offset into file */ + unsigned long len, /* length (in bytes) of region to lock or unlock */ + int unlock) +{ /* non-zero to unlock; zero to lock */ + iregs regs; + + regs.a.x = 0x10a4 | (unlock ? 0x01 : 0x00); + regs.b.x = pspseg; + regs.c.x = fileno; + regs.si = (unsigned short)((ofs >> 16) & 0xffffL); + regs.di = (unsigned short)(ofs & 0xffffL); + regs.es = (unsigned short)((len >> 16) & 0xffffL); + regs.d.x = (unsigned short)(len & 0xffffL); + intr(0x2f, ®s); + return (int)regs.a.x; } /* /// End of additions for SHARE. - Ron Cemer */ @@ -1905,4 +1977,3 @@ static int share_lock_unlock * Rev 1.0 02 Jul 1995 8:04:20 patv * Initial revision. */ - diff --git a/kernel/dosnames.c b/kernel/dosnames.c index 3a99cfb..eceff6c 100644 --- a/kernel/dosnames.c +++ b/kernel/dosnames.c @@ -31,7 +31,8 @@ #include "portab.h" #ifdef VERSION_STRINGS -static BYTE *dosnamesRcsId = "$Id$"; +static BYTE *dosnamesRcsId = + "$Id$"; #endif #include "globals.h" @@ -79,16 +80,10 @@ VOID SpacePad(BYTE * szString, COUNT nChars) COUNT ParseDosName(BYTE * lpszFileName, COUNT * pnDrive, BYTE * pszDir, - BYTE * pszFile, - BYTE * pszExt, - BOOL bAllowWildcards) + BYTE * pszFile, BYTE * pszExt, BOOL bAllowWildcards) { - COUNT nDirCnt, - nFileCnt, - nExtCnt; - BYTE *lpszLclDir, - *lpszLclFile, - *lpszLclExt; + COUNT nDirCnt, nFileCnt, nExtCnt; + BYTE *lpszLclDir, *lpszLclFile, *lpszLclExt; /* Initialize the users data fields */ if (pszDir) @@ -118,12 +113,13 @@ COUNT ParseDosName(BYTE * lpszFileName, } nDirCnt = FP_OFF(lpszLclFile) - FP_OFF(lpszLclDir); /* Fix lengths to maximums allowed by MS-DOS. */ - if (nDirCnt > PARSE_MAX-1) - nDirCnt = PARSE_MAX-1; + if (nDirCnt > PARSE_MAX - 1) + nDirCnt = PARSE_MAX - 1; /* Parse out the file name portion. */ lpszFileName = lpszLclFile; - while (bAllowWildcards ? WildChar(*lpszFileName) : NameChar(*lpszFileName)) + while (bAllowWildcards ? WildChar(*lpszFileName) : + NameChar(*lpszFileName)) { ++nFileCnt; ++lpszFileName; @@ -131,26 +127,25 @@ COUNT ParseDosName(BYTE * lpszFileName, if (nFileCnt == 0) /* Lixing Yuan Patch */ - if (bAllowWildcards) /* for find first */ - { - if (*lpszFileName != '\0') - return DE_FILENOTFND; - if (nDirCnt == 1) /* for d:\ */ - return DE_NFILES; - if (pszDir) - { - memcpy(pszDir, lpszLclDir, nDirCnt); - pszDir[nDirCnt] = '\0'; - } - if (pszFile) - memcpy(pszFile, "????????", FNAME_SIZE+1); - if (pszExt) - memcpy(pszExt, "???", FEXT_SIZE+1); - return SUCCESS; - } - else - return DE_FILENOTFND; - + if (bAllowWildcards) /* for find first */ + { + if (*lpszFileName != '\0') + return DE_FILENOTFND; + if (nDirCnt == 1) /* for d:\ */ + return DE_NFILES; + if (pszDir) + { + memcpy(pszDir, lpszLclDir, nDirCnt); + pszDir[nDirCnt] = '\0'; + } + if (pszFile) + memcpy(pszFile, "????????", FNAME_SIZE + 1); + if (pszExt) + memcpy(pszExt, "???", FEXT_SIZE + 1); + return SUCCESS; + } + else + return DE_FILENOTFND; /* Now we have pointers set to the directory portion and the */ /* file portion. Now determine the existance of an extension. */ @@ -160,14 +155,16 @@ COUNT ParseDosName(BYTE * lpszFileName, lpszLclExt = ++lpszFileName; while (*lpszFileName) { - if (bAllowWildcards ? WildChar(*lpszFileName) : NameChar(*lpszFileName)) + if (bAllowWildcards ? WildChar(*lpszFileName) : + NameChar(*lpszFileName)) { ++nExtCnt; ++lpszFileName; } - else{ + else + { return DE_FILENOTFND; - } + } } } else if (*lpszFileName) @@ -199,14 +196,10 @@ COUNT ParseDosName(BYTE * lpszFileName, #if 0 /* not necessary anymore because of truename */ COUNT ParseDosPath(BYTE * lpszFileName, - COUNT * pnDrive, - BYTE * pszDir, - BYTE * pszCurPath) + COUNT * pnDrive, BYTE * pszDir, BYTE * pszCurPath) { - COUNT nDirCnt, - nPathCnt; - BYTE *lpszLclDir, - *pszBase = pszDir; + COUNT nDirCnt, nPathCnt; + BYTE *lpszLclDir, *pszBase = pszDir; /* Initialize the users data fields */ *pszDir = '\0'; @@ -237,10 +230,10 @@ COUNT ParseDosPath(BYTE * lpszFileName, lpszLclDir = lpszFileName; if (!PathSep(*lpszLclDir)) { - fstrncpy(pszDir, pszCurPath, PARSE_MAX - 1); /*TE*/ - nPathCnt = fstrlen(pszCurPath); - if (!PathSep(pszDir[nPathCnt - 1]) && nPathCnt < PARSE_MAX - 1) /*TE*/ - pszDir[nPathCnt++] = '\\'; + fstrncpy(pszDir, pszCurPath, PARSE_MAX - 1); + /*TE*/ nPathCnt = fstrlen(pszCurPath); + if (!PathSep(pszDir[nPathCnt - 1]) && nPathCnt < PARSE_MAX - 1) + /*TE*/ pszDir[nPathCnt++] = '\\'; if (nPathCnt > PARSE_MAX) nPathCnt = PARSE_MAX; pszDir += nPathCnt; @@ -248,16 +241,15 @@ COUNT ParseDosPath(BYTE * lpszFileName, /* Now see how long a directory component we have. */ while (NameChar(*lpszFileName) - || PathSep(*lpszFileName) - || '.' == *lpszFileName) + || PathSep(*lpszFileName) || '.' == *lpszFileName) { ++nDirCnt; ++lpszFileName; } /* Fix lengths to maximums allowed by MS-DOS. */ - if ((nDirCnt + nPathCnt) > PARSE_MAX - 1) /*TE*/ - nDirCnt = PARSE_MAX - 1 - nPathCnt; + if ((nDirCnt + nPathCnt) > PARSE_MAX - 1) + /*TE*/ nDirCnt = PARSE_MAX - 1 - nPathCnt; /* Finally copy whatever the user wants extracted to the user's */ /* buffers. */ @@ -289,11 +281,8 @@ COUNT ParseDosPath(BYTE * lpszFileName, VOID DosTrimPath(BYTE * lpszPathNamep) { - BYTE *lpszLast, - *lpszNext, - *lpszRoot = NULL; - COUNT nChars, - flDotDot; + BYTE *lpszLast, *lpszNext, *lpszRoot = NULL; + COUNT nChars, flDotDot; /* First, convert all '/' to '\'. Look for root as we scan */ if (*lpszPathNamep == '\\') @@ -302,14 +291,13 @@ VOID DosTrimPath(BYTE * lpszPathNamep) { if (*lpszNext == '/') *lpszNext = '\\'; - if (!lpszRoot && - *lpszNext == ':' && *(lpszNext + 1) == '\\') + if (!lpszRoot && *lpszNext == ':' && *(lpszNext + 1) == '\\') lpszRoot = lpszNext + 1; } - /* NAMEMAX + 2, must include C: TE*/ + /* NAMEMAX + 2, must include C: TE */ for (lpszLast = lpszNext = lpszPathNamep, nChars = 0; - *lpszNext != '\0' && nChars < NAMEMAX+2;) + *lpszNext != '\0' && nChars < NAMEMAX + 2;) { /* Initialize flag for loop. */ flDotDot = FALSE; @@ -325,8 +313,7 @@ VOID DosTrimPath(BYTE * lpszPathNamep) /* as appropriate. */ else if (*(lpszNext + 1) == '.') { - if (*(lpszNext + 2) == '.' - && !(*(lpszNext + 3))) + if (*(lpszNext + 2) == '.' && !(*(lpszNext + 3))) { /* At the end, just truncate */ /* and exit. */ @@ -337,8 +324,7 @@ VOID DosTrimPath(BYTE * lpszPathNamep) return; } - if (*(lpszNext + 2) == '.' - && *(lpszNext + 3) == '\\') + if (*(lpszNext + 2) == '.' && *(lpszNext + 3) == '\\') { fstrncpy(lpszLast, lpszNext + 3, NAMEMAX); /* bump back to the last */ @@ -351,8 +337,7 @@ VOID DosTrimPath(BYTE * lpszPathNamep) { --lpszLast; } - while (lpszLast != lpszPathNamep - && *lpszLast != '\\'); + while (lpszLast != lpszPathNamep && *lpszLast != '\\'); flDotDot = TRUE; } /* Note: we skip strange stuff that */ @@ -360,7 +345,7 @@ VOID DosTrimPath(BYTE * lpszPathNamep) else if (*(lpszNext + 2) == '\\') { fstrncpy(lpszNext, lpszNext + 2, NAMEMAX); - flDotDot = TRUE; + flDotDot = TRUE; } /* If we're at the end of a string, */ /* just exit. */ @@ -460,4 +445,3 @@ VOID DosTrimPath(BYTE * lpszPathNamep) * Initial revision. * */ - diff --git a/kernel/dsk.c b/kernel/dsk.c index 075c5ee..be89ccb 100644 --- a/kernel/dsk.c +++ b/kernel/dsk.c @@ -29,22 +29,20 @@ #include "dyndata.h" #ifdef VERSION_STRINGS -static BYTE *dskRcsId = "$Id$"; +static BYTE *dskRcsId = + "$Id$"; #endif -#if defined(DEBUG) - #define DebugPrintf(x) printf x -#else - #define DebugPrintf(x) -#endif +#if defined(DEBUG) +#define DebugPrintf(x) printf x +#else +#define DebugPrintf(x) +#endif /* #define STATIC */ - - - #ifdef PROTO -BOOL ASMCFUNC fl_reset(WORD); +BOOL ASMCFUNC fl_reset(WORD); COUNT ASMCFUNC fl_readdasd(WORD); COUNT ASMCFUNC fl_diskchanged(WORD); COUNT ASMCFUNC fl_rd_status(WORD); @@ -57,11 +55,12 @@ COUNT ASMCFUNC fl_setdisktype(WORD, WORD); COUNT ASMCFUNC fl_setmediatype(WORD, WORD, WORD); VOID ASMCFUNC fl_readkey(VOID); -extern COUNT ASMCFUNC fl_lba_ReadWrite (BYTE drive, WORD mode, - struct _bios_LBA_address_packet FAR *dap_p); +extern COUNT ASMCFUNC fl_lba_ReadWrite(BYTE drive, WORD mode, + struct _bios_LBA_address_packet FAR + * dap_p); -int LBA_Transfer(ddt *pddt ,UWORD mode, VOID FAR *buffer, - ULONG LBA_address,unsigned total, UWORD *transferred); +int LBA_Transfer(ddt * pddt, UWORD mode, VOID FAR * buffer, + ULONG LBA_address, unsigned total, UWORD * transferred); #else BOOL fl_reset(); COUNT fl_readdasd(); @@ -76,86 +75,79 @@ COUNT fl_setmediatype(); COUNT fl_setdisktype(); #endif -#define NENTRY 26 /* total size of dispatch table */ +#define NENTRY 26 /* total size of dispatch table */ extern BYTE FAR nblk_rel; extern int FAR ASMCFUNC Get_nblk_rel(void); - - #define LBA_READ 0x4200 #define LBA_WRITE 0x4300 -UWORD LBA_WRITE_VERIFY = 0x4302; +UWORD LBA_WRITE_VERIFY = 0x4302; #define LBA_VERIFY 0x4400 -#define LBA_FORMAT 0xffff /* fake number for FORMAT track - (only for NON-LBA floppies now!) */ +#define LBA_FORMAT 0xffff /* fake number for FORMAT track + (only for NON-LBA floppies now!) */ /* this buffer must not overlap a 64K boundary due to DMA transfers this is certainly true, if located somewhere at 0xf+1000 and must hold already during BOOT time - */ + */ UBYTE DiskTransferBuffer[1 * SEC_SIZE]; -static struct Access_info -{ - BYTE AI_spec; - BYTE AI_Flag; +static struct Access_info { + BYTE AI_spec; + BYTE AI_Flag; }; -struct FS_info -{ - ULONG serialno; - BYTE volume[11]; - BYTE fstype[8]; +struct FS_info { + ULONG serialno; + BYTE volume[11]; + BYTE fstype[8]; }; extern struct DynS Dyn; /*TE - array access functions */ -ddt *getddt(int dev) { return &(((ddt*)Dyn.Buffer)[dev]);} +ddt *getddt(int dev) +{ + return &(((ddt *) Dyn.Buffer)[dev]); +} #define N_PART 4 /* number of partitions per - table partition */ + table partition */ -COUNT nUnits; /* number of returned units */ +COUNT nUnits; /* number of returned units */ #define PARTOFF 0x1be - #ifdef PROTO WORD - _dsk_init (rqptr rq, ddt *pddt), - mediachk (rqptr rq, ddt *pddt), - bldbpb (rqptr rq, ddt *pddt), - blockio (rqptr rq, ddt *pddt), - IoctlQueblk(rqptr rq, ddt *pddt), - Genblkdev (rqptr rq, ddt *pddt), - Getlogdev (rqptr rq, ddt *pddt), - Setlogdev (rqptr rq, ddt *pddt), - blk_Open (rqptr rq, ddt *pddt), - blk_Close (rqptr rq, ddt *pddt), - blk_Media (rqptr rq, ddt *pddt), - blk_noerr (rqptr rq, ddt *pddt), - blk_nondr (rqptr rq, ddt *pddt), - blk_error (rqptr rq, ddt *pddt); +_dsk_init(rqptr rq, ddt * pddt), +mediachk(rqptr rq, ddt * pddt), +bldbpb(rqptr rq, ddt * pddt), +blockio(rqptr rq, ddt * pddt), +IoctlQueblk(rqptr rq, ddt * pddt), +Genblkdev(rqptr rq, ddt * pddt), +Getlogdev(rqptr rq, ddt * pddt), +Setlogdev(rqptr rq, ddt * pddt), +blk_Open(rqptr rq, ddt * pddt), +blk_Close(rqptr rq, ddt * pddt), +blk_Media(rqptr rq, ddt * pddt), +blk_noerr(rqptr rq, ddt * pddt), +blk_nondr(rqptr rq, ddt * pddt), blk_error(rqptr rq, ddt * pddt); WORD dskerr(COUNT); #else WORD _dsk_init(), - mediachk(), - bldbpb(), - blockio(), - IoctlQueblk(), - Genblkdev(), - Getlogdev(), - Setlogdev(), - blk_Open(), - blk_Close(), - blk_Media(), - blk_noerr(), - blk_nondr(), - blk_error(); +mediachk(), +bldbpb(), +blockio(), +IoctlQueblk(), +Genblkdev(), +Getlogdev(), +Setlogdev(), +blk_Open(), +blk_Close(), blk_Media(), blk_noerr(), blk_nondr(), blk_error(); WORD dskerr(); #endif @@ -164,12 +156,12 @@ WORD dskerr(); /* */ #ifdef PROTO -static WORD(*dispatch[NENTRY]) (rqptr rq, ddt *pddt) = +static WORD(*dispatch[NENTRY]) (rqptr rq, ddt * pddt) = #else static WORD(*dispatch[NENTRY]) () = #endif { - _dsk_init, /* Initialize */ + _dsk_init, /* Initialize */ mediachk, /* Media Check */ bldbpb, /* Build BPB */ blk_error, /* Ioctl In */ @@ -197,20 +189,12 @@ static WORD(*dispatch[NENTRY]) () = IoctlQueblk /* Ioctl Query */ }; - - - - - #define hd(x) ((x) & DF_FIXED) /* ----------------------------------------------------------------------- */ /* F U N C T I O N S --------------------------------------------------- */ /* ----------------------------------------------------------------------- */ - - - COUNT FAR ASMCFUNC blk_driver(rqptr rp) { if (rp->r_unit >= nUnits && rp->r_command != C_INIT) @@ -224,45 +208,45 @@ COUNT FAR ASMCFUNC blk_driver(rqptr rp) } /* disk init is done in diskinit.c, so this should never be called */ -WORD _dsk_init(rqptr rp, ddt *pddt) +WORD _dsk_init(rqptr rp, ddt * pddt) { UNREFERENCED_PARAMETER(rp); UNREFERENCED_PARAMETER(pddt); fatal("No disk init!"); - return S_DONE; /* to keep the compiler happy */ + return S_DONE; /* to keep the compiler happy */ } -STATIC WORD play_dj(ddt*pddt) +STATIC WORD play_dj(ddt * pddt) { /* play the DJ ... */ if ((pddt->ddt_descflags & (DF_MULTLOG | DF_CURLOG)) == DF_MULTLOG) { - int i; - ddt *pddt2 = getddt(0); - for (i = 0; i < nUnits; i++, pddt2++) - { - if (pddt->ddt_driveno == pddt2->ddt_driveno && - (pddt2->ddt_descflags & (DF_MULTLOG | DF_CURLOG)) == - (DF_MULTLOG | DF_CURLOG)) - break; - } - if (i == nUnits) - { - printf("Error in the DJ mechanism!\n"); /* should not happen! */ - return M_CHANGED; - } - printf("Remove diskette in drive %c:\n", 'A'+pddt2->ddt_logdriveno); - printf("Insert diskette in drive %c:\n", 'A'+pddt->ddt_logdriveno); - printf("Press the any key to continue ... \n"); - fl_readkey(); - pddt2->ddt_descflags &= ~DF_CURLOG; - pddt->ddt_descflags |= DF_CURLOG; + int i; + ddt *pddt2 = getddt(0); + for (i = 0; i < nUnits; i++, pddt2++) + { + if (pddt->ddt_driveno == pddt2->ddt_driveno && + (pddt2->ddt_descflags & (DF_MULTLOG | DF_CURLOG)) == + (DF_MULTLOG | DF_CURLOG)) + break; + } + if (i == nUnits) + { + printf("Error in the DJ mechanism!\n"); /* should not happen! */ return M_CHANGED; + } + printf("Remove diskette in drive %c:\n", 'A' + pddt2->ddt_logdriveno); + printf("Insert diskette in drive %c:\n", 'A' + pddt->ddt_logdriveno); + printf("Press the any key to continue ... \n"); + fl_readkey(); + pddt2->ddt_descflags &= ~DF_CURLOG; + pddt->ddt_descflags |= DF_CURLOG; + return M_CHANGED; } return M_NOT_CHANGED; -} +} -STATIC WORD diskchange(ddt *pddt) +STATIC WORD diskchange(ddt * pddt) { COUNT result; @@ -273,7 +257,7 @@ STATIC WORD diskchange(ddt *pddt) if (play_dj(pddt) == M_CHANGED) return M_CHANGED; - if (pddt->ddt_descflags & DF_CHANGELINE) /* if we can detect a change ... */ + if (pddt->ddt_descflags & DF_CHANGELINE) /* if we can detect a change ... */ { if ((result = fl_diskchanged(pddt->ddt_driveno)) == 1) /* check if it has changed... */ @@ -286,7 +270,7 @@ STATIC WORD diskchange(ddt *pddt) return tdelay((LONG) 37) ? M_DONT_KNOW : M_NOT_CHANGED; } -WORD mediachk(rqptr rp, ddt *pddt) +WORD mediachk(rqptr rp, ddt * pddt) { /* check floppy status */ if (pddt->ddt_descflags & DF_REFORMAT) @@ -299,7 +283,7 @@ WORD mediachk(rqptr rp, ddt *pddt) pddt->ddt_descflags &= ~DF_DISKCHANGE; rp->r_mcretcode = M_DONT_KNOW; } - else + else { rp->r_mcretcode = diskchange(pddt); } @@ -309,136 +293,141 @@ WORD mediachk(rqptr rp, ddt *pddt) /* * Read Write Sector Zero or Hard Drive Dos Bpb */ -STATIC WORD RWzero(ddt *pddt, UWORD mode) +STATIC WORD RWzero(ddt * pddt, UWORD mode) { - UWORD done; + UWORD done; return LBA_Transfer(pddt, mode, - (UBYTE FAR *)&DiskTransferBuffer, - pddt->ddt_offset,1,&done); + (UBYTE FAR *) & DiskTransferBuffer, + pddt->ddt_offset, 1, &done); } /* 0 if not set, 1 = a, 2 = b, etc, assume set. page 424 MS Programmer's Ref. */ -static WORD Getlogdev(rqptr rp, ddt *pddt) +static WORD Getlogdev(rqptr rp, ddt * pddt) { - BYTE x = rp->r_unit; - - UNREFERENCED_PARAMETER(pddt); - - x++; - if( x > Get_nblk_rel() ) - return failure(E_UNIT); + BYTE x = rp->r_unit; - rp->r_unit = x; - return S_DONE; + UNREFERENCED_PARAMETER(pddt); + + x++; + if (x > Get_nblk_rel()) + return failure(E_UNIT); + + rp->r_unit = x; + return S_DONE; } -static WORD Setlogdev(rqptr rp, ddt *pddt) +static WORD Setlogdev(rqptr rp, ddt * pddt) { - UNREFERENCED_PARAMETER(rp); - UNREFERENCED_PARAMETER(pddt); + UNREFERENCED_PARAMETER(rp); + UNREFERENCED_PARAMETER(pddt); - return S_DONE; + return S_DONE; } -static WORD blk_Open(rqptr rp, ddt *pddt) -{ - UNREFERENCED_PARAMETER(rp); - - pddt->ddt_FileOC++; - return S_DONE; -} - -static WORD blk_Close(rqptr rp, ddt *pddt) -{ - UNREFERENCED_PARAMETER(rp); - - pddt->ddt_FileOC--; - return S_DONE; -} - -static WORD blk_nondr(rqptr rp, ddt *pddt) -{ - UNREFERENCED_PARAMETER(rp); - UNREFERENCED_PARAMETER(pddt); - - return S_BUSY|S_DONE; -} - -static WORD blk_Media(rqptr rp, ddt *pddt) +static WORD blk_Open(rqptr rp, ddt * pddt) { UNREFERENCED_PARAMETER(rp); - if (hd( pddt->ddt_descflags)) - return S_BUSY|S_DONE; /* Hard Drive */ + pddt->ddt_FileOC++; + return S_DONE; +} + +static WORD blk_Close(rqptr rp, ddt * pddt) +{ + UNREFERENCED_PARAMETER(rp); + + pddt->ddt_FileOC--; + return S_DONE; +} + +static WORD blk_nondr(rqptr rp, ddt * pddt) +{ + UNREFERENCED_PARAMETER(rp); + UNREFERENCED_PARAMETER(pddt); + + return S_BUSY | S_DONE; +} + +static WORD blk_Media(rqptr rp, ddt * pddt) +{ + UNREFERENCED_PARAMETER(rp); + + if (hd(pddt->ddt_descflags)) + return S_BUSY | S_DONE; /* Hard Drive */ else return S_DONE; /* Floppy */ } -static WORD getbpb(ddt *pddt) +static WORD getbpb(ddt * pddt) { ULONG count; bpb *pbpbarray = &pddt->ddt_bpb; - WORD head,/*track,*/sector,ret; + WORD head, /*track, */ sector, ret; - pddt->ddt_descflags |= DF_NOACCESS; /* set drive to not accessible and changed */ + pddt->ddt_descflags |= DF_NOACCESS; /* set drive to not accessible and changed */ if (diskchange(pddt) != M_NOT_CHANGED) - pddt->ddt_descflags |= DF_DISKCHANGE; + pddt->ddt_descflags |= DF_DISKCHANGE; ret = RWzero(pddt, LBA_READ); if (ret != 0) - return (dskerr(ret)); - - getword(&((((BYTE *) & DiskTransferBuffer[BT_BPB]))[0]), &pbpbarray->bpb_nbyte); + return (dskerr(ret)); - if (DiskTransferBuffer[0x1fe]!=0x55 || DiskTransferBuffer[0x1ff]!=0xaa || - pbpbarray->bpb_nbyte != 512) { - /* copy default bpb to be sure that there is no bogus data */ - memcpy(pbpbarray, &pddt->ddt_defbpb, sizeof(bpb)); - return S_DONE; + getword(&((((BYTE *) & DiskTransferBuffer[BT_BPB]))[0]), + &pbpbarray->bpb_nbyte); + + if (DiskTransferBuffer[0x1fe] != 0x55 + || DiskTransferBuffer[0x1ff] != 0xaa || pbpbarray->bpb_nbyte != 512) + { + /* copy default bpb to be sure that there is no bogus data */ + memcpy(pbpbarray, &pddt->ddt_defbpb, sizeof(bpb)); + return S_DONE; } - pddt->ddt_descflags &= ~DF_NOACCESS; /* set drive to accessible */ + pddt->ddt_descflags &= ~DF_NOACCESS; /* set drive to accessible */ -/*TE ~ 200 bytes*/ +/*TE ~ 200 bytes*/ fmemcpy(pbpbarray, &DiskTransferBuffer[BT_BPB], sizeof(bpb)); #ifdef WITHFAT32 - /*??*/ + /*?? */ /* 2b is fat16 volume label. if memcmp, then offset 0x36. - if (fstrncmp((BYTE *) & DiskTransferBuffer[0x36], "FAT16",5) == 0 || - fstrncmp((BYTE *) & DiskTransferBuffer[0x36], "FAT12",5) == 0) { - TE: I'm not sure, what the _real_ decision point is, however MSDN - 'A_BF_BPB_SectorsPerFAT - The number of sectors per FAT. - Note: This member will always be zero in a FAT32 BPB. - Use the values from A_BF_BPB_BigSectorsPerFat... - */ + if (fstrncmp((BYTE *) & DiskTransferBuffer[0x36], "FAT16",5) == 0 || + fstrncmp((BYTE *) & DiskTransferBuffer[0x36], "FAT12",5) == 0) { + TE: I'm not sure, what the _real_ decision point is, however MSDN + 'A_BF_BPB_SectorsPerFAT + The number of sectors per FAT. + Note: This member will always be zero in a FAT32 BPB. + Use the values from A_BF_BPB_BigSectorsPerFat... + */ if (pbpbarray->bpb_nfsect != 0) { /* FAT16/FAT12 boot sector */ - getlong(&((((BYTE *) & DiskTransferBuffer[0x27])[0])), &pddt->ddt_serialno); - memcpy(pddt->ddt_volume,&DiskTransferBuffer[0x2B], 11); - memcpy(pddt->ddt_fstype,&DiskTransferBuffer[0x36], 8); - } else { - /* FAT32 boot sector */ - getlong(&((((BYTE *) & DiskTransferBuffer[0x43])[0])), &pddt->ddt_serialno); - memcpy(pddt->ddt_volume,&DiskTransferBuffer[0x47], 11); - memcpy(pddt->ddt_fstype,&DiskTransferBuffer[0x52], 8); + getlong(&((((BYTE *) & DiskTransferBuffer[0x27])[0])), + &pddt->ddt_serialno); + memcpy(pddt->ddt_volume, &DiskTransferBuffer[0x2B], 11); + memcpy(pddt->ddt_fstype, &DiskTransferBuffer[0x36], 8); + } + else + { + /* FAT32 boot sector */ + getlong(&((((BYTE *) & DiskTransferBuffer[0x43])[0])), + &pddt->ddt_serialno); + memcpy(pddt->ddt_volume, &DiskTransferBuffer[0x47], 11); + memcpy(pddt->ddt_fstype, &DiskTransferBuffer[0x52], 8); pbpbarray->bpb_ndirent = 512; - } + } #else - getlong(&((((BYTE *) & DiskTransferBuffer[0x27])[0])), &pddt->ddt_serialno); - memcpy(pddt->ddt_volume,&DiskTransferBuffer[0x2B], 11); - memcpy(pddt->ddt_fstype,&DiskTransferBuffer[0x36], 8); + getlong(&((((BYTE *) & DiskTransferBuffer[0x27])[0])), + &pddt->ddt_serialno); + memcpy(pddt->ddt_volume, &DiskTransferBuffer[0x2B], 11); + memcpy(pddt->ddt_fstype, &DiskTransferBuffer[0x36], 8); #endif - - #ifdef DSK_DEBUG printf("BPB_NBYTE = %04x\n", pbpbarray->bpb_nbyte); printf("BPB_NSECTOR = %02x\n", pbpbarray->bpb_nsector); @@ -452,8 +441,7 @@ static WORD getbpb(ddt *pddt) count = pbpbarray->bpb_nsize == 0 ? - pbpbarray->bpb_huge : - pbpbarray->bpb_nsize; + pbpbarray->bpb_huge : pbpbarray->bpb_nsize; head = pbpbarray->bpb_nheads; sector = pbpbarray->bpb_nsecs; @@ -463,7 +451,7 @@ static WORD getbpb(ddt *pddt) return failure(E_FAILURE); } pddt->ddt_ncyl = (count + head * sector - 1) / (head * sector); - + tmark(); #ifdef DSK_DEBUG @@ -476,340 +464,357 @@ static WORD getbpb(ddt *pddt) return 0; } - -STATIC WORD bldbpb(rqptr rp, ddt *pddt) +STATIC WORD bldbpb(rqptr rp, ddt * pddt) { WORD result; if ((result = getbpb(pddt)) != 0) - return result; + return result; rp->r_bpptr = &pddt->ddt_bpb; return S_DONE; } - -static WORD IoctlQueblk(rqptr rp, ddt *pddt) +static WORD IoctlQueblk(rqptr rp, ddt * pddt) { - UNREFERENCED_PARAMETER(pddt); + UNREFERENCED_PARAMETER(pddt); - switch(rp->r_count){ + switch (rp->r_count) + { case 0x0846: case 0x0847: case 0x0860: case 0x0866: case 0x0867: - break; + break; default: - return failure(E_CMD); - } + return failure(E_CMD); + } return S_DONE; } -COUNT Genblockio(ddt *pddt, UWORD mode, WORD head, WORD track, WORD sector, - WORD count, VOID FAR *buffer) +COUNT Genblockio(ddt * pddt, UWORD mode, WORD head, WORD track, + WORD sector, WORD count, VOID FAR * buffer) { - UWORD transferred; + UWORD transferred; - /* apparently sector is ZERO, not ONE based !!! */ - return LBA_Transfer(pddt, mode, buffer, - ((ULONG)track * pddt->ddt_bpb.bpb_nheads + head) * - (ULONG)pddt->ddt_bpb.bpb_nsecs + - pddt->ddt_offset + sector, - count, &transferred); + /* apparently sector is ZERO, not ONE based !!! */ + return LBA_Transfer(pddt, mode, buffer, + ((ULONG) track * pddt->ddt_bpb.bpb_nheads + head) * + (ULONG) pddt->ddt_bpb.bpb_nsecs + + pddt->ddt_offset + sector, count, &transferred); } -STATIC WORD Genblkdev(rqptr rp,ddt *pddt) +STATIC WORD Genblkdev(rqptr rp, ddt * pddt) { - int ret; - bpb *pbpb; + int ret; + bpb *pbpb; #ifdef WITHFAT32 - int extended = 0; - - if ((rp->r_count >> 8) == 0x48) extended = 1; - else + int extended = 0; + + if ((rp->r_count >> 8) == 0x48) + extended = 1; + else #endif - if ((rp->r_count >> 8) != 8) - return failure(E_CMD); + if ((rp->r_count >> 8) != 8) + return failure(E_CMD); - switch(rp->r_count & 0xff){ - case 0x40: /* set device parameters */ - { - struct gblkio FAR * gblp = (struct gblkio FAR *) rp->r_trans; + switch (rp->r_count & 0xff) + { + case 0x40: /* set device parameters */ + { + struct gblkio FAR *gblp = (struct gblkio FAR *)rp->r_trans; - pddt->ddt_type = gblp->gbio_devtype; - pddt->ddt_descflags &= ~3; - pddt->ddt_descflags |= (gblp->gbio_devattrib & 3) - | (DF_DPCHANGED | DF_REFORMAT); - pddt->ddt_ncyl = gblp->gbio_ncyl; - /* use default dpb or current bpb? */ - pbpb = (gblp->gbio_spcfunbit & 0x01) == 0 ? &pddt->ddt_defbpb : &pddt->ddt_bpb; + pddt->ddt_type = gblp->gbio_devtype; + pddt->ddt_descflags &= ~3; + pddt->ddt_descflags |= (gblp->gbio_devattrib & 3) + | (DF_DPCHANGED | DF_REFORMAT); + pddt->ddt_ncyl = gblp->gbio_ncyl; + /* use default dpb or current bpb? */ + pbpb = + (gblp->gbio_spcfunbit & 0x01) == + 0 ? &pddt->ddt_defbpb : &pddt->ddt_bpb; #ifdef WITHFAT32 - if (!extended) fmemcpy(pbpb, &gblp->gbio_bpb, BPB_SIZEOF); - else + if (!extended) + fmemcpy(pbpb, &gblp->gbio_bpb, BPB_SIZEOF); + else #endif - fmemcpy(pbpb, &gblp->gbio_bpb, sizeof(gblp->gbio_bpb)); - /*pbpb->bpb_nsector = gblp->gbio_nsecs;*/ - break; - } - case 0x41: /* write track */ - { - struct gblkrw FAR * rw = (struct gblkrw FAR *) rp->r_trans; - ret = Genblockio(pddt, LBA_WRITE, rw->gbrw_head, rw->gbrw_cyl, - rw->gbrw_sector, rw->gbrw_nsecs, rw->gbrw_buffer); - if (ret != 0) - return dskerr(ret); - } - break; - case 0x42: /* format/verify track */ - { - struct gblkfv FAR * fv = (struct gblkfv FAR *) rp->r_trans; - COUNT tracks; - struct thst {UBYTE track, head, sector, type;} *addrfield, afentry; + fmemcpy(pbpb, &gblp->gbio_bpb, sizeof(gblp->gbio_bpb)); + /*pbpb->bpb_nsector = gblp->gbio_nsecs; */ + break; + } + case 0x41: /* write track */ + { + struct gblkrw FAR *rw = (struct gblkrw FAR *)rp->r_trans; + ret = Genblockio(pddt, LBA_WRITE, rw->gbrw_head, rw->gbrw_cyl, + rw->gbrw_sector, rw->gbrw_nsecs, rw->gbrw_buffer); + if (ret != 0) + return dskerr(ret); + } + break; + case 0x42: /* format/verify track */ + { + struct gblkfv FAR *fv = (struct gblkfv FAR *)rp->r_trans; + COUNT tracks; + struct thst { + UBYTE track, head, sector, type; + } *addrfield, afentry; - if (hd(pddt->ddt_descflags)) - { - /* XXX no low-level formatting for hard disks implemented */ - fv->gbfv_spcfunbit = 1; /* "not supported by bios" */ - pddt->ddt_descflags &= ~DF_DPCHANGED; - return S_DONE; - } - if (pddt->ddt_descflags & DF_DPCHANGED) - { - pddt->ddt_descflags &= ~DF_DPCHANGED; - - /* first try newer setmediatype function */ - ret = fl_setmediatype(pddt->ddt_driveno, pddt->ddt_ncyl, - pddt->ddt_bpb.bpb_nsecs); - if (ret == 0xc) + if (hd(pddt->ddt_descflags)) { + /* XXX no low-level formatting for hard disks implemented */ + fv->gbfv_spcfunbit = 1; /* "not supported by bios" */ + pddt->ddt_descflags &= ~DF_DPCHANGED; + return S_DONE; + } + if (pddt->ddt_descflags & DF_DPCHANGED) + { + pddt->ddt_descflags &= ~DF_DPCHANGED; + + /* first try newer setmediatype function */ + ret = fl_setmediatype(pddt->ddt_driveno, pddt->ddt_ncyl, + pddt->ddt_bpb.bpb_nsecs); + if (ret == 0xc) + { /* specified tracks, sectors/track not allowed for drive */ fv->gbfv_spcfunbit = 2; return dskerr(ret); - } - else if (ret == 0x80) { - fv->gbfv_spcfunbit = 3; /* no disk in drive */ + } + else if (ret == 0x80) + { + fv->gbfv_spcfunbit = 3; /* no disk in drive */ return dskerr(ret); - } - else if (ret != 0) - /* otherwise, setdisktype */ - { + } + else if (ret != 0) + /* otherwise, setdisktype */ + { COUNT type = 0; if ((fv->gbfv_spcfunbit & 1) && - (ret = fl_read(pddt->ddt_driveno,0,0,1,1,DiskTransferBuffer)) != 0) + (ret = + fl_read(pddt->ddt_driveno, 0, 0, 1, 1, + DiskTransferBuffer)) != 0) { - fv->gbfv_spcfunbit = 3; /* no disk in drive */ - return dskerr(ret); + fv->gbfv_spcfunbit = 3; /* no disk in drive */ + return dskerr(ret); } if (pddt->ddt_ncyl == 40 && - (pddt->ddt_bpb.bpb_nsecs == 9 || pddt->ddt_bpb.bpb_nsecs == 8)) + (pddt->ddt_bpb.bpb_nsecs == 9 + || pddt->ddt_bpb.bpb_nsecs == 8)) { - if (pddt->ddt_type == 0) - type = 1; /* 320/360K disk in 360K drive */ - else if (pddt->ddt_type == 1) - type = 2; /* 320/360K disk in 1.2M drive */ + if (pddt->ddt_type == 0) + type = 1; /* 320/360K disk in 360K drive */ + else if (pddt->ddt_type == 1) + type = 2; /* 320/360K disk in 1.2M drive */ } else if (pddt->ddt_type == 1 && pddt->ddt_ncyl == 80 && pddt->ddt_bpb.bpb_nsecs == 15) - type = 3; /* 1.2M disk in 1.2M drive */ + type = 3; /* 1.2M disk in 1.2M drive */ else if ((pddt->ddt_type == 2 || pddt->ddt_type == 7) && - pddt->ddt_ncyl == 80 && pddt->ddt_bpb.bpb_nsecs == 15 - ) - type = 4; /* 720kb disk in 1.44M or 720kb drive */ + pddt->ddt_ncyl == 80 && pddt->ddt_bpb.bpb_nsecs == 15) + type = 4; /* 720kb disk in 1.44M or 720kb drive */ if (type == 0) { - /* specified tracks, sectors/track not allowed for drive */ - fv->gbfv_spcfunbit = 2; - return dskerr(0xc); + /* specified tracks, sectors/track not allowed for drive */ + fv->gbfv_spcfunbit = 2; + return dskerr(0xc); } fl_setdisktype(pddt->ddt_driveno, type); + } } - } - if (fv->gbfv_spcfunbit & 1) return S_DONE; + if (fv->gbfv_spcfunbit & 1) + return S_DONE; - afentry.type = 2; /* 512 byte sectors */ - afentry.track = fv->gbfv_cyl; - afentry.head = fv->gbfv_head; + afentry.type = 2; /* 512 byte sectors */ + afentry.track = fv->gbfv_cyl; + afentry.head = fv->gbfv_head; - for (tracks = fv->gbfv_spcfunbit & 2 ? fv->gbfv_ntracks : 1; tracks > 0; - tracks--) - { - addrfield = (struct thst *)DiskTransferBuffer; + for (tracks = fv->gbfv_spcfunbit & 2 ? fv->gbfv_ntracks : 1; + tracks > 0; tracks--) + { + addrfield = (struct thst *)DiskTransferBuffer; - if (afentry.track > pddt->ddt_ncyl) - return failure(E_FAILURE); + if (afentry.track > pddt->ddt_ncyl) + return failure(E_FAILURE); - for (afentry.sector = 1; afentry.sector <= pddt->ddt_bpb.bpb_nsecs; - afentry.sector++) - memcpy(addrfield++, &afentry, sizeof(afentry)); + for (afentry.sector = 1; + afentry.sector <= pddt->ddt_bpb.bpb_nsecs; afentry.sector++) + memcpy(addrfield++, &afentry, sizeof(afentry)); - ret = Genblockio(pddt, LBA_FORMAT, afentry.head, afentry.track, 0, - pddt->ddt_bpb.bpb_nsecs, DiskTransferBuffer); - if (ret != 0) - return dskerr(ret); + ret = + Genblockio(pddt, LBA_FORMAT, afentry.head, afentry.track, 0, + pddt->ddt_bpb.bpb_nsecs, DiskTransferBuffer); + if (ret != 0) + return dskerr(ret); + } + afentry.head++; + if (afentry.head >= pddt->ddt_bpb.bpb_nheads) + { + afentry.head = 0; + afentry.track++; + } } - afentry.head++; - if (afentry.head >= pddt->ddt_bpb.bpb_nheads) + + /* fall through to verify */ + + case 0x62: /* verify track */ { - afentry.head = 0; - afentry.track++; + struct gblkfv FAR *fv = (struct gblkfv FAR *)rp->r_trans; + + ret = Genblockio(pddt, LBA_VERIFY, fv->gbfv_head, fv->gbfv_cyl, 0, + (fv->gbfv_spcfunbit ? + fv->gbfv_ntracks * pddt->ddt_defbpb.bpb_nsecs : + pddt->ddt_defbpb.bpb_nsecs), DiskTransferBuffer); + if (ret != 0) + return dskerr(ret); + fv->gbfv_spcfunbit = 0; /* success */ } - } + break; + case 0x46: /* set volume serial number */ + { + struct Gioc_media FAR *gioc = (struct Gioc_media FAR *)rp->r_trans; + struct FS_info FAR *fs; - /* fall through to verify */ - - case 0x62: /* verify track */ - { - struct gblkfv FAR * fv = (struct gblkfv FAR *) rp->r_trans; - - ret = Genblockio(pddt, LBA_VERIFY, fv->gbfv_head, fv->gbfv_cyl, 0, - (fv->gbfv_spcfunbit ? - fv->gbfv_ntracks * pddt->ddt_defbpb.bpb_nsecs : - pddt->ddt_defbpb.bpb_nsecs), DiskTransferBuffer); - if (ret != 0) - return dskerr(ret); - fv->gbfv_spcfunbit = 0; /* success */ - } - break; - case 0x46: /* set volume serial number */ - { - struct Gioc_media FAR * gioc = (struct Gioc_media FAR *) rp->r_trans; - struct FS_info FAR * fs; - ret = getbpb(pddt); if (ret != 0) - return (ret); + return (ret); - fs = (struct FS_info FAR *) &DiskTransferBuffer + fs = (struct FS_info FAR *)&DiskTransferBuffer [(pddt->ddt_bpb.bpb_nfsect != 0 ? 0x27 : 0x43)]; - fs->serialno = gioc->ioc_serialno; + fs->serialno = gioc->ioc_serialno; pddt->ddt_serialno = fs->serialno; ret = RWzero(pddt, LBA_WRITE); if (ret != 0) - return (dskerr(ret)); - } - break; - case 0x47: /* set access flag */ - { - struct Access_info FAR * ai = (struct Access_info FAR *) rp->r_trans; - pddt->ddt_descflags &= ~DF_NOACCESS; - pddt->ddt_descflags |= (ai->AI_Flag ? 0 : DF_NOACCESS); - } - break; - case 0x60: /* get device parameters */ - { - struct gblkio FAR * gblp = (struct gblkio FAR *) rp->r_trans; + return (dskerr(ret)); + } + break; + case 0x47: /* set access flag */ + { + struct Access_info FAR *ai = (struct Access_info FAR *)rp->r_trans; + pddt->ddt_descflags &= ~DF_NOACCESS; + pddt->ddt_descflags |= (ai->AI_Flag ? 0 : DF_NOACCESS); + } + break; + case 0x60: /* get device parameters */ + { + struct gblkio FAR *gblp = (struct gblkio FAR *)rp->r_trans; - gblp->gbio_devtype = pddt->ddt_type; - gblp->gbio_devattrib = pddt->ddt_descflags & 3; - /* 360 kb disk in 1.2 MB drive */ - gblp->gbio_media = (pddt->ddt_type == 1) && (pddt->ddt_ncyl == 40); - gblp->gbio_ncyl = pddt->ddt_ncyl; - /* use default dpb or current bpb? */ - pbpb = (gblp->gbio_spcfunbit & 0x01) == 0 ? &pddt->ddt_defbpb : &pddt->ddt_bpb; + gblp->gbio_devtype = pddt->ddt_type; + gblp->gbio_devattrib = pddt->ddt_descflags & 3; + /* 360 kb disk in 1.2 MB drive */ + gblp->gbio_media = (pddt->ddt_type == 1) && (pddt->ddt_ncyl == 40); + gblp->gbio_ncyl = pddt->ddt_ncyl; + /* use default dpb or current bpb? */ + pbpb = + (gblp->gbio_spcfunbit & 0x01) == + 0 ? &pddt->ddt_defbpb : &pddt->ddt_bpb; #ifdef WITHFAT32 - if (!extended) fmemcpy(&gblp->gbio_bpb, pbpb, BPB_SIZEOF); - else + if (!extended) + fmemcpy(&gblp->gbio_bpb, pbpb, BPB_SIZEOF); + else #endif - fmemcpy(&gblp->gbio_bpb, pbpb, sizeof(gblp->gbio_bpb)); - /*gblp->gbio_nsecs = pbpb->bpb_nsector;*/ - break; - } - case 0x61: /* read track */ - { - struct gblkrw FAR * rw = (struct gblkrw FAR *) rp->r_trans; - ret = Genblockio(pddt, LBA_READ, rw->gbrw_head, rw->gbrw_cyl, - rw->gbrw_sector, rw->gbrw_nsecs, rw->gbrw_buffer); - if (ret != 0) - return dskerr(ret); - } - break; - case 0x66: /* get volume serial number */ - { - struct Gioc_media FAR * gioc = (struct Gioc_media FAR *) rp->r_trans; + fmemcpy(&gblp->gbio_bpb, pbpb, sizeof(gblp->gbio_bpb)); + /*gblp->gbio_nsecs = pbpb->bpb_nsector; */ + break; + } + case 0x61: /* read track */ + { + struct gblkrw FAR *rw = (struct gblkrw FAR *)rp->r_trans; + ret = Genblockio(pddt, LBA_READ, rw->gbrw_head, rw->gbrw_cyl, + rw->gbrw_sector, rw->gbrw_nsecs, rw->gbrw_buffer); + if (ret != 0) + return dskerr(ret); + } + break; + case 0x66: /* get volume serial number */ + { + struct Gioc_media FAR *gioc = (struct Gioc_media FAR *)rp->r_trans; ret = getbpb(pddt); if (ret != 0) - return (ret); + return (ret); gioc->ioc_serialno = pddt->ddt_serialno; - fmemcpy(gioc->ioc_volume, pddt->ddt_volume,11); - fmemcpy(gioc->ioc_fstype, pddt->ddt_fstype,8); - } - break; - case 0x67: /* get access flag */ - { - struct Access_info FAR * ai = (struct Access_info FAR *) rp->r_trans; - ai->AI_Flag = pddt->ddt_descflags & DF_NOACCESS ? 0 : 1; /* bit 9 */ - } - break; + fmemcpy(gioc->ioc_volume, pddt->ddt_volume, 11); + fmemcpy(gioc->ioc_fstype, pddt->ddt_fstype, 8); + } + break; + case 0x67: /* get access flag */ + { + struct Access_info FAR *ai = (struct Access_info FAR *)rp->r_trans; + ai->AI_Flag = pddt->ddt_descflags & DF_NOACCESS ? 0 : 1; /* bit 9 */ + } + break; default: - return failure(E_CMD); - } + return failure(E_CMD); + } return S_DONE; } -WORD blockio(rqptr rp, ddt *pddt) +WORD blockio(rqptr rp, ddt * pddt) { - ULONG start, size; - WORD ret; - - int action; - bpb *pbpb; + ULONG start, size; + WORD ret; + int action; + bpb *pbpb; - switch (rp->r_command){ - case C_INPUT: action = LBA_READ; break; - case C_OUTPUT:action = LBA_WRITE; break; - case C_OUTVFY:action = LBA_WRITE_VERIFY; break; - default: - return failure(E_FAILURE); - } + switch (rp->r_command) + { + case C_INPUT: + action = LBA_READ; + break; + case C_OUTPUT: + action = LBA_WRITE; + break; + case C_OUTVFY: + action = LBA_WRITE_VERIFY; + break; + default: + return failure(E_FAILURE); + } - if (pddt->ddt_descflags & 0x200) /* drive inaccessible */ - return failure(E_FAILURE); + if (pddt->ddt_descflags & 0x200) /* drive inaccessible */ + return failure(E_FAILURE); - tmark(); - start = (rp->r_start != HUGECOUNT ? rp->r_start : rp->r_huge); - pbpb = hd(pddt->ddt_descflags) ? &pddt->ddt_defbpb : &pddt->ddt_bpb; - size = (pbpb->bpb_nsize ? pbpb->bpb_nsize : pbpb->bpb_huge); - - if (start >= size || - start + rp->r_count > size) - { - return 0x0408; - } - start += pddt->ddt_offset; - - ret = LBA_Transfer(pddt, action, - rp->r_trans, - start, rp->r_count,(UWORD*)&rp->r_count); - - if (ret != 0) - { - return dskerr(ret); - } - return S_DONE; + tmark(); + start = (rp->r_start != HUGECOUNT ? rp->r_start : rp->r_huge); + pbpb = hd(pddt->ddt_descflags) ? &pddt->ddt_defbpb : &pddt->ddt_bpb; + size = (pbpb->bpb_nsize ? pbpb->bpb_nsize : pbpb->bpb_huge); + + if (start >= size || start + rp->r_count > size) + { + return 0x0408; + } + start += pddt->ddt_offset; + + ret = LBA_Transfer(pddt, action, + rp->r_trans, + start, rp->r_count, (UWORD *) & rp->r_count); + + if (ret != 0) + { + return dskerr(ret); + } + return S_DONE; } -STATIC WORD blk_error(rqptr rp, ddt *pddt) +STATIC WORD blk_error(rqptr rp, ddt * pddt) { UNREFERENCED_PARAMETER(pddt); - + rp->r_count = 0; return failure(E_FAILURE); /* general failure */ } - -STATIC WORD blk_noerr(rqptr rp, ddt *pddt) +STATIC WORD blk_noerr(rqptr rp, ddt * pddt) { - UNREFERENCED_PARAMETER(rp); - UNREFERENCED_PARAMETER(pddt); - - return S_DONE; + UNREFERENCED_PARAMETER(rp); + UNREFERENCED_PARAMETER(pddt); + + return S_DONE; } STATIC WORD dskerr(COUNT code) @@ -820,10 +825,10 @@ STATIC WORD dskerr(COUNT code) { case 1: /* invalid command - general failure */ if (code & 0x08) - return S_ERROR | E_NOTRDY; /* failure(E_NOTRDY); at least on yhe INT25 route, - 0x8002 is returned */ + return S_ERROR | E_NOTRDY; /* failure(E_NOTRDY); at least on yhe INT25 route, + 0x8002 is returned */ else - return failure(E_CMD); + return failure(E_CMD); case 2: /* address mark not found - general failure */ return failure(E_FAILURE); @@ -833,62 +838,55 @@ STATIC WORD dskerr(COUNT code) default: if (code & 0x80) /* time-out */ - return failure(E_NOTRDY); + return failure(E_NOTRDY); else if (code & 0x40) /* seek error */ - return failure(E_SEEK); + return failure(E_SEEK); else if (code & 0x10) /* CRC error */ - return failure(E_CRC); + return failure(E_CRC); else if (code & 0x04) - return failure(E_NOTFND); + return failure(E_NOTFND); else - return failure(E_FAILURE); + return failure(E_FAILURE); } } - /* translate LBA sectors into CHS addressing */ -void LBA_to_CHS(struct CHS *chs, ULONG LBA_address, ddt *pddt) +void LBA_to_CHS(struct CHS *chs, ULONG LBA_address, ddt * pddt) { - /* we need the defbpb values since those are taken from the - BIOS, not from some random boot sector, except when - we're dealing with a floppy */ - bpb *pbpb = hd(pddt->ddt_descflags) ? - &pddt->ddt_defbpb : - &pddt->ddt_bpb; - - chs->Sector = LBA_address % pbpb->bpb_nsecs + 1; + /* we need the defbpb values since those are taken from the + BIOS, not from some random boot sector, except when + we're dealing with a floppy */ + bpb *pbpb = hd(pddt->ddt_descflags) ? &pddt->ddt_defbpb : &pddt->ddt_bpb; - LBA_address /= pbpb->bpb_nsecs; + chs->Sector = LBA_address % pbpb->bpb_nsecs + 1; - chs->Head = LBA_address % pbpb->bpb_nheads; - chs->Cylinder = LBA_address / pbpb->bpb_nheads; + LBA_address /= pbpb->bpb_nsecs; + + chs->Head = LBA_address % pbpb->bpb_nheads; + chs->Cylinder = LBA_address / pbpb->bpb_nheads; } - - /* Test for 64K boundary crossing and return count small */ /* enough not to exceed the threshold. */ -STATIC unsigned DMA_max_transfer(void FAR *buffer, unsigned count) +STATIC unsigned DMA_max_transfer(void FAR * buffer, unsigned count) { - UWORD utemp = (((UWORD) FP_SEG(buffer) << 4) + FP_OFF(buffer)); - -#define SEC_SHIFT 9 /* = 0x200 = 512 */ - - utemp >>= SEC_SHIFT; - - if (count > (0xffff >> SEC_SHIFT) - utemp) - { - count = (0xffff >> SEC_SHIFT) - utemp; - } + UWORD utemp = (((UWORD) FP_SEG(buffer) << 4) + FP_OFF(buffer)); - return count; -} +#define SEC_SHIFT 9 /* = 0x200 = 512 */ + utemp >>= SEC_SHIFT; + if (count > (0xffff >> SEC_SHIFT) - utemp) + { + count = (0xffff >> SEC_SHIFT) - utemp; + } + + return count; +} /* int LBA_Transfer( @@ -918,153 +916,157 @@ STATIC unsigned DMA_max_transfer(void FAR *buffer, unsigned count) */ -int LBA_Transfer(ddt *pddt ,UWORD mode, VOID FAR *buffer, - ULONG LBA_address,unsigned totaltodo, UWORD *transferred) +int LBA_Transfer(ddt * pddt, UWORD mode, VOID FAR * buffer, + ULONG LBA_address, unsigned totaltodo, + UWORD * transferred) { - static struct _bios_LBA_address_packet dap = { - 16,0,0,0,0,0,0 - }; - - unsigned count; - unsigned error_code; - struct CHS chs; - void FAR *transfer_address; + static struct _bios_LBA_address_packet dap = { + 16, 0, 0, 0, 0, 0, 0 + }; - int num_retries; + unsigned count; + unsigned error_code; + struct CHS chs; + void FAR *transfer_address; - /* only low-level format floppies for now ! */ - if (mode == LBA_FORMAT && hd(pddt->ddt_descflags)) - return 0; + int num_retries; - /* optionally change from A: to B: or back */ - play_dj(pddt); + /* only low-level format floppies for now ! */ + if (mode == LBA_FORMAT && hd(pddt->ddt_descflags)) + return 0; - *transferred = 0; + /* optionally change from A: to B: or back */ + play_dj(pddt); + + *transferred = 0; /* if (LBA_address+totaltodo > pddt->total_sectors) { printf("LBA-Transfer error : address overflow = %lu > %lu max\n",LBA_address+totaltodo,driveParam->total_sectors); return 1; } -*/ +*/ - for ( ;totaltodo != 0; ) + for (; totaltodo != 0;) + { + count = totaltodo; + + count = min(count, 0x7f); + + /* avoid overflowing 64K DMA boundary */ + count = DMA_max_transfer(buffer, count); + + if (FP_SEG(buffer) >= 0xa000 || count == 0) + { + transfer_address = DiskTransferBuffer; + count = 1; + + if ((mode & 0xff00) == (LBA_WRITE & 0xff00)) + { + fmemcpy(DiskTransferBuffer, buffer, 512); + } + } + else + { + transfer_address = buffer; + } + + for (num_retries = 0; num_retries < N_RETRY; num_retries++) + { + if (pddt->ddt_LBASupported && mode != LBA_FORMAT) + { + dap.number_of_blocks = count; + + dap.buffer_address = transfer_address; + + dap.block_address_high = 0; /* clear high part */ + dap.block_address = LBA_address; /* clear high part */ + + /* Load the registers and call the interrupt. */ + + if (pddt->ddt_WriteVerifySupported || mode != LBA_WRITE_VERIFY) { - count = totaltodo; - - count = min(count, 0x7f); - - /* avoid overflowing 64K DMA boundary */ - count = DMA_max_transfer(buffer,count); - + error_code = fl_lba_ReadWrite(pddt->ddt_driveno, mode, &dap); + } + else + { + /* verify requested, but not supported */ + error_code = + fl_lba_ReadWrite(pddt->ddt_driveno, LBA_WRITE, &dap); - if (FP_SEG(buffer) >= 0xa000 || count == 0) - { - transfer_address = DiskTransferBuffer; - count = 1; - - if ((mode & 0xff00) == (LBA_WRITE & 0xff00)) - { - fmemcpy(DiskTransferBuffer,buffer,512); - } - } - else { - transfer_address = buffer; - } + if (error_code == 0) + { + error_code = + fl_lba_ReadWrite(pddt->ddt_driveno, LBA_VERIFY, &dap); + } + } + } + else + { /* transfer data, using old bios functions */ + LBA_to_CHS(&chs, LBA_address, pddt); + /* avoid overflow at end of track */ - for ( num_retries = 0; num_retries < N_RETRY; num_retries++) - { - if (pddt->ddt_LBASupported && mode != LBA_FORMAT) - { - dap.number_of_blocks = count; - - dap.buffer_address = transfer_address; - - dap.block_address_high = 0; /* clear high part */ - dap.block_address = LBA_address; /* clear high part */ - - - /* Load the registers and call the interrupt. */ - - if (pddt->ddt_WriteVerifySupported || mode != LBA_WRITE_VERIFY) - { - - error_code = fl_lba_ReadWrite(pddt->ddt_driveno,mode, &dap); - } - else { - /* verify requested, but not supported */ - error_code = fl_lba_ReadWrite(pddt->ddt_driveno,LBA_WRITE, &dap); - - if (error_code == 0) - { - error_code = fl_lba_ReadWrite(pddt->ddt_driveno,LBA_VERIFY, &dap); - } - } - } - else - { /* transfer data, using old bios functions */ - - LBA_to_CHS(&chs, LBA_address, pddt); - - /* avoid overflow at end of track */ - - if (chs.Sector + count > pddt->ddt_bpb.bpb_nsecs + 1) - { - count = pddt->ddt_bpb.bpb_nsecs + 1 - chs.Sector; - } - - if (chs.Cylinder > 1023) - { - printf("LBA-Transfer error : cylinder %u > 1023\n", chs.Cylinder); - return 1; - } - - error_code = (mode == LBA_READ ? fl_read : - mode == LBA_VERIFY ? fl_verify : - mode == LBA_FORMAT ? fl_format : fl_write)( - pddt->ddt_driveno, - chs.Head, (UWORD)chs.Cylinder, chs.Sector, - count, transfer_address); - - if (error_code == 0 && - mode == LBA_WRITE_VERIFY) - { - error_code = fl_verify( - pddt->ddt_driveno, - chs.Head, (UWORD)chs.Cylinder, chs.Sector, - count, transfer_address); - } - } - if (error_code == 0) - break; - - fl_reset(pddt->ddt_driveno); - - } /* end of retries */ - - if (error_code) - { - return error_code; - } - - /* copy to user buffer if nesessary */ - if (transfer_address == DiskTransferBuffer && - (mode & 0xff00) == (LBA_READ & 0xff00)) - { - fmemcpy(buffer,DiskTransferBuffer,512); - } - - *transferred += count; - LBA_address += count; - totaltodo -= count; - - buffer = add_far(buffer,count*512); + if (chs.Sector + count > pddt->ddt_bpb.bpb_nsecs + 1) + { + count = pddt->ddt_bpb.bpb_nsecs + 1 - chs.Sector; } - return(error_code); + if (chs.Cylinder > 1023) + { + printf("LBA-Transfer error : cylinder %u > 1023\n", + chs.Cylinder); + return 1; + } + + error_code = (mode == LBA_READ ? fl_read : + mode == LBA_VERIFY ? fl_verify : + mode == + LBA_FORMAT ? fl_format : fl_write) (pddt-> + ddt_driveno, + chs.Head, + (UWORD) chs. + Cylinder, + chs.Sector, + count, + transfer_address); + + if (error_code == 0 && mode == LBA_WRITE_VERIFY) + { + error_code = fl_verify(pddt->ddt_driveno, + chs.Head, (UWORD) chs.Cylinder, + chs.Sector, count, transfer_address); + } + } + if (error_code == 0) + break; + + fl_reset(pddt->ddt_driveno); + + } /* end of retries */ + + if (error_code) + { + return error_code; + } + + /* copy to user buffer if nesessary */ + if (transfer_address == DiskTransferBuffer && + (mode & 0xff00) == (LBA_READ & 0xff00)) + { + fmemcpy(buffer, DiskTransferBuffer, 512); + } + + *transferred += count; + LBA_address += count; + totaltodo -= count; + + buffer = add_far(buffer, count * 512); + } + + return (error_code); } /* diff --git a/kernel/dyndata.c b/kernel/dyndata.c index 6388896..30f46d6 100644 --- a/kernel/dyndata.c +++ b/kernel/dyndata.c @@ -5,9 +5,9 @@ alll data herein goes to special segment DYN_DATA AFTER BSS, but immediately before HMA_TEXT -*/ +*/ #include "portab.h" #include "init-mod.h" #include "dyndata.h" -struct DynS Dyn = {0}; +struct DynS Dyn = { 0 }; diff --git a/kernel/dyndata.h b/kernel/dyndata.h index fa30616..e980a2c 100644 --- a/kernel/dyndata.h +++ b/kernel/dyndata.h @@ -14,6 +14,6 @@ void far *DynLast(void); void DynFree(void *ptr); struct DynS { - unsigned Allocated; - char Buffer[1]; - }; + unsigned Allocated; + char Buffer[1]; +}; diff --git a/kernel/dyninit.c b/kernel/dyninit.c index a6bb222..02355d8 100644 --- a/kernel/dyninit.c +++ b/kernel/dyninit.c @@ -4,7 +4,6 @@ this serves requests from the INIT modules to allocate dynamic data. - kernel layout: 00000H 000FFH 00100H PSP PSP 00100H 004E1H 003E2H _TEXT CODE @@ -28,7 +27,6 @@ additionally: 122E0H 12AA5H 007C6H ID ID 12AA6H 12CBFH 0021AH IB IB - purpose is to move the HMA_TEXT = resident kernel around, so that below it - after BSS, there is data addressable near by the kernel, to hold some arrays @@ -36,62 +34,61 @@ additionally: making f_nodes near saves ~2.150 code in HMA -*/ +*/ #include "portab.h" #include "init-mod.h" -#include "dyndata.h" +#include "dyndata.h" #if defined(DEBUG) - #define DebugPrintf(x) printf x +#define DebugPrintf(x) printf x #else - #define DebugPrintf(x) +#define DebugPrintf(x) #endif - /*extern struct DynS FAR Dyn;*/ #ifndef __TURBOC__ - #include "init-dat.h" - extern struct DynS DOSFAR Dyn; +#include "init-dat.h" +extern struct DynS DOSFAR Dyn; #else - extern struct DynS FAR Dyn; -#endif - - +extern struct DynS FAR Dyn; +#endif void far *DynAlloc(char *what, unsigned num, unsigned size) { - void far *now; - unsigned total = num * size; + void far *now; + unsigned total = num * size; #ifndef DEBUG - UNREFERENCED_PARAMETER(what); + UNREFERENCED_PARAMETER(what); #endif - if ((ULONG)total + Dyn.Allocated > 0xffff) - { - printf("PANIC:Dyn %lu\n", (ULONG)total + Dyn.Allocated); - for (;;); - } - - DebugPrintf(("DYNDATA:allocating %s - %u * %u bytes, total %u, %u..%u\n", - what, num, size, total, Dyn.Allocated,Dyn.Allocated+total)); - - now = (void far *)&Dyn.Buffer[Dyn.Allocated]; - fmemset(now, 0, total); - - Dyn.Allocated += total; - - return now; -} + if ((ULONG) total + Dyn.Allocated > 0xffff) + { + printf("PANIC:Dyn %lu\n", (ULONG) total + Dyn.Allocated); + for (;;) ; + } + + DebugPrintf(("DYNDATA:allocating %s - %u * %u bytes, total %u, %u..%u\n", + what, num, size, total, Dyn.Allocated, + Dyn.Allocated + total)); + + now = (void far *)&Dyn.Buffer[Dyn.Allocated]; + fmemset(now, 0, total); + + Dyn.Allocated += total; + + return now; +} void DynFree(void *ptr) { - Dyn.Allocated = (char *)ptr - (char *)Dyn.Buffer; + Dyn.Allocated = (char *)ptr - (char *)Dyn.Buffer; } void FAR *DynLast() { - DebugPrintf(("dynamic data end at %p\n",(void FAR *)(Dyn.Buffer+Dyn.Allocated))); + DebugPrintf(("dynamic data end at %p\n", + (void FAR *)(Dyn.Buffer + Dyn.Allocated))); - return Dyn.Buffer+Dyn.Allocated; -} + return Dyn.Buffer + Dyn.Allocated; +} diff --git a/kernel/error.c b/kernel/error.c index 8a6df37..52131a6 100644 --- a/kernel/error.c +++ b/kernel/error.c @@ -29,7 +29,8 @@ #include "portab.h" #ifdef VERSION_STRINGS -static BYTE *errorRcsId = "$Id$"; +static BYTE *errorRcsId = + "$Id$"; #endif #include "globals.h" @@ -39,19 +40,11 @@ static BYTE *errorRcsId = "$Id$"; VOID dump(void) { printf("Register Dump [AH = %02x CS:IP = %04x:%04x]\n", - error_regs.AH, - error_regs.CS, - error_regs.IP); + error_regs.AH, error_regs.CS, error_regs.IP); printf("AX:%04x BX:%04x CX:%04x DX:%04x\n", - error_regs.AX, - error_regs.BX, - error_regs.CX, - error_regs.DX); + error_regs.AX, error_regs.BX, error_regs.CX, error_regs.DX); printf("SI:%04x DI:%04x DS:%04x ES:%04x\n", - error_regs.SI, - error_regs.DI, - error_regs.DS, - error_regs.ES); + error_regs.SI, error_regs.DI, error_regs.DS, error_regs.ES); } #endif @@ -82,21 +75,15 @@ VOID fatal(BYTE * err_msg) /* Abort, retry or fail for character devices */ COUNT char_error(request * rq, struct dhdr FAR * lpDevice) { - return CriticalError( - EFLG_CHAR | EFLG_ABORT | EFLG_RETRY | EFLG_IGNORE, - 0, - rq->r_status & S_MASK, - lpDevice); + return CriticalError(EFLG_CHAR | EFLG_ABORT | EFLG_RETRY | EFLG_IGNORE, + 0, rq->r_status & S_MASK, lpDevice); } /* Abort, retry or fail for block devices */ COUNT block_error(request * rq, COUNT nDrive, struct dhdr FAR * lpDevice) { - return CriticalError( - EFLG_ABORT | EFLG_RETRY | EFLG_IGNORE, - nDrive, - rq->r_status & S_MASK, - lpDevice); + return CriticalError(EFLG_ABORT | EFLG_RETRY | EFLG_IGNORE, + nDrive, rq->r_status & S_MASK, lpDevice); } /* @@ -139,4 +126,3 @@ COUNT block_error(request * rq, COUNT nDrive, struct dhdr FAR * lpDevice) * Rev 1.0 02 Jul 1995 8:06:14 patv * Initial revision. */ - diff --git a/kernel/fatdir.c b/kernel/fatdir.c index 5445558..89fbf37 100644 --- a/kernel/fatdir.c +++ b/kernel/fatdir.c @@ -31,7 +31,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *fatdirRcsId = "$Id$"; +static BYTE *fatdirRcsId = + "$Id$"; #endif /* Description. @@ -45,24 +46,25 @@ VOID dir_init_fnode(f_node_ptr fnp, CLUSTER dirstart) fnp->f_flags.f_droot = FALSE; fnp->f_flags.f_ddir = TRUE; fnp->f_flags.f_dnew = TRUE; - fnp->f_diroff = fnp->f_offset = fnp->f_cluster_offset = fnp->f_highwater = 0l; + fnp->f_diroff = fnp->f_offset = fnp->f_cluster_offset = + fnp->f_highwater = 0l; /* root directory */ if (dirstart == 0) - { + { #ifdef WITHFAT32 - if (ISFAT32(fnp->f_dpb)) - { - fnp->f_cluster = fnp->f_dirstart = fnp->f_dpb->dpb_xrootclst; - } - else -#endif - { - fnp->f_dirstart = 0l; - fnp->f_flags.f_droot = TRUE; - } + if (ISFAT32(fnp->f_dpb)) + { + fnp->f_cluster = fnp->f_dirstart = fnp->f_dpb->dpb_xrootclst; } - else /* non-root */ + else +#endif + { + fnp->f_dirstart = 0l; + fnp->f_flags.f_droot = TRUE; + } + } + else /* non-root */ fnp->f_cluster = fnp->f_dirstart = dirstart; } @@ -76,17 +78,18 @@ f_node_ptr dir_open(BYTE * dirname) BYTE *pszPath = dirname + 2; /* Allocate an fnode if possible - error return (0) if not. */ - if ((fnp = get_f_node()) == (f_node_ptr)0) + if ((fnp = get_f_node()) == (f_node_ptr) 0) { - return (f_node_ptr)0; + return (f_node_ptr) 0; } /* Force the fnode into read-write mode */ fnp->f_mode = RDWR; /* determine what drive we are using... */ - if (ParseDosName(dirname, &drive, (BYTE *) 0, (BYTE *) 0, (BYTE *) 0, FALSE) - != SUCCESS) + if (ParseDosName + (dirname, &drive, (BYTE *) 0, (BYTE *) 0, (BYTE *) 0, + FALSE) != SUCCESS) { release_f_node(fnp); return NULL; @@ -104,7 +107,8 @@ f_node_ptr dir_open(BYTE * dirname) { drive = default_drive; } - if (drive >= lastdrive) { + if (drive >= lastdrive) + { release_f_node(fnp); return NULL; } @@ -113,7 +117,7 @@ f_node_ptr dir_open(BYTE * dirname) /* Generate full path name */ /* not necessary anymore, since truename did that already - i = cdsp->cdsJoinOffset; + i = cdsp->cdsJoinOffset; ParseDosPath(dirname, (COUNT *) 0, pszPath, (BYTE FAR *) & cdsp->cdsCurrentPath[i]); */ /* for testing only for now */ @@ -139,7 +143,7 @@ f_node_ptr dir_open(BYTE * dirname) if (media_check(fnp->f_dpb) < 0) { release_f_node(fnp); - return (f_node_ptr)0; + return (f_node_ptr) 0; } /* Walk the directory tree to find the starting cluster */ @@ -161,8 +165,8 @@ f_node_ptr dir_open(BYTE * dirname) /* comparison... */ /* first the file name with trailing spaces... */ - memset(TempBuffer, ' ', FNAME_SIZE+FEXT_SIZE); - + memset(TempBuffer, ' ', FNAME_SIZE + FEXT_SIZE); + for (i = 0; i < FNAME_SIZE; i++) { if (*p != '\0' && *p != '.' && *p != '/' && *p != '\\') @@ -191,9 +195,12 @@ f_node_ptr dir_open(BYTE * dirname) while (dir_read(fnp) == 1) { - if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED) + if (fnp->f_dir.dir_name[0] != '\0' + && fnp->f_dir.dir_name[0] != DELETED) { - if (fcmp(TempBuffer, (BYTE *)fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE)) + if (fcmp + (TempBuffer, (BYTE *) fnp->f_dir.dir_name, + FNAME_SIZE + FEXT_SIZE)) { i = TRUE; break; @@ -205,7 +212,7 @@ f_node_ptr dir_open(BYTE * dirname) { release_f_node(fnp); - return (f_node_ptr)0; + return (f_node_ptr) 0; } else { @@ -250,7 +257,7 @@ COUNT dir_read(REG f_node_ptr fnp) if (fnp->f_flags.f_droot) { - if (new_diroff >= DIRENT_SIZE * (ULONG)fnp->f_dpb->dpb_dirents) + if (new_diroff >= DIRENT_SIZE * (ULONG) fnp->f_dpb->dpb_dirents) return DE_SEEK; bp = getblock((ULONG) (new_diroff / secsize @@ -294,14 +301,15 @@ COUNT dir_read(REG f_node_ptr fnp) bp->b_flag &= ~(BFR_DATA | BFR_FAT); bp->b_flag |= BFR_DIR | BFR_VALID; - getdirent((BYTE FAR *) & bp->b_buffer[((UWORD)new_diroff) % fnp->f_dpb->dpb_secsize], - (struct dirent FAR *)&fnp->f_dir); + getdirent((BYTE FAR *) & bp-> + b_buffer[((UWORD) new_diroff) % fnp->f_dpb->dpb_secsize], + (struct dirent FAR *)&fnp->f_dir); /* Update the fnode's directory info */ fnp->f_flags.f_dmod = FALSE; fnp->f_flags.f_dnew = FALSE; fnp->f_diroff = new_diroff; - + /* and for efficiency, stop when we hit the first */ /* unused entry. */ /* either returns 1 or 0 */ @@ -328,10 +336,9 @@ BOOL dir_write(REG f_node_ptr fnp) /* simple. */ if (fnp->f_flags.f_droot) { - bp = getblock( - (ULONG) ((UWORD)fnp->f_diroff / secsize - + fnp->f_dpb->dpb_dirstrt), - fnp->f_dpb->dpb_unit); + bp = getblock((ULONG) ((UWORD) fnp->f_diroff / secsize + + fnp->f_dpb->dpb_dirstrt), + fnp->f_dpb->dpb_unit); #ifdef DISPLAY_GETBLOCK printf("DIR (dir_write)\n"); #endif @@ -348,7 +355,7 @@ BOOL dir_write(REG f_node_ptr fnp) fnp->f_offset = fnp->f_diroff; fnp->f_back = LONG_LAST_CLUSTER; fnp->f_cluster = fnp->f_dirstart; - fnp->f_cluster_offset = 0l; /*JPP */ + fnp->f_cluster_offset = 0l; /*JPP */ /* Search through the FAT to find the block */ /* that this entry is in. */ @@ -383,11 +390,12 @@ BOOL dir_write(REG f_node_ptr fnp) release_f_node(fnp); return FALSE; } - + if (fnp->f_flags.f_dnew && fnp->f_dir.dir_attrib != D_LFN) - fmemset(&fnp->f_dir.dir_case, 0, 8); + fmemset(&fnp->f_dir.dir_case, 0, 8); putdirent((struct dirent FAR *)&fnp->f_dir, - (VOID FAR *) & bp->b_buffer[(UWORD)fnp->f_diroff % fnp->f_dpb->dpb_secsize]); + (VOID FAR *) & bp->b_buffer[(UWORD) fnp->f_diroff % + fnp->f_dpb->dpb_secsize]); bp->b_flag &= ~(BFR_DATA | BFR_FAT); bp->b_flag |= BFR_DIR | BFR_DIRTY | BFR_VALID; @@ -417,7 +425,7 @@ VOID dir_close(REG f_node_ptr fnp) } #ifndef IPL -COUNT dos_findfirst(UCOUNT attr, BYTE *name) +COUNT dos_findfirst(UCOUNT attr, BYTE * name) { REG f_node_ptr fnp; REG dmatch *dmp = (dmatch *) TempBuffer; @@ -425,8 +433,7 @@ COUNT dos_findfirst(UCOUNT attr, BYTE *name) COUNT nDrive; BYTE *p; - BYTE local_name[FNAME_SIZE + 1], - local_ext[FEXT_SIZE + 1]; + BYTE local_name[FNAME_SIZE + 1], local_ext[FEXT_SIZE + 1]; /* printf("ff %Fs\n", name);*/ @@ -438,7 +445,8 @@ COUNT dos_findfirst(UCOUNT attr, BYTE *name) /* current directory, do a seek and read, then close the fnode. */ /* Parse out the drive, file name and file extension. */ - i = ParseDosName(name, &nDrive, &szDirName[2], local_name, local_ext, TRUE); + i = ParseDosName(name, &nDrive, &szDirName[2], local_name, local_ext, + TRUE); if (i != SUCCESS) return i; /* @@ -453,14 +461,14 @@ COUNT dos_findfirst(UCOUNT attr, BYTE *name) SearchDir.dir_name[i] = *p; for (; i < FNAME_SIZE; ++i) - SearchDir.dir_name[i] = ' '; + SearchDir.dir_name[i] = ' '; /* and the extension (don't forget to add trailing spaces)... */ for (p = local_ext, i = 0; i < FEXT_SIZE && *p; ++p, ++i) SearchDir.dir_ext[i] = *p; for (; i < FEXT_SIZE; ++i) - SearchDir.dir_ext[i] = ' '; + SearchDir.dir_ext[i] = ' '; /* Convert everything to uppercase. */ DosUpFMem(SearchDir.dir_name, FNAME_SIZE + FEXT_SIZE); @@ -471,7 +479,7 @@ COUNT dos_findfirst(UCOUNT attr, BYTE *name) /* name */ szDirName[0] = 'A' + nDrive; szDirName[1] = ':'; - + /* Special handling - the volume id is only in the root */ /* directory and only searched for once. So we need to open */ /* the root and return only the first entry that contains the */ @@ -483,16 +491,16 @@ COUNT dos_findfirst(UCOUNT attr, BYTE *name) } /* Now open this directory so that we can read the */ /* fnode entry and do a match on it. */ - + /* printf("dir_open %s\n", szDirName);*/ if ((fnp = dir_open(szDirName)) == NULL) return DE_PATHNOTFND; /* Now initialize the dirmatch structure. */ - - nDrive=get_verify_drive(name); + + nDrive = get_verify_drive(name); if (nDrive < 0) - return nDrive; + return nDrive; dmp->dm_drive = nDrive; dmp->dm_attr_srch = attr; @@ -507,7 +515,7 @@ COUNT dos_findfirst(UCOUNT attr, BYTE *name) /* Test the attribute and return first found */ if ((fnp->f_dir.dir_attrib & ~(D_RDONLY | D_ARCHIVE)) == D_VOLID) { - dmp->dm_dircluster = fnp->f_dirstart; /* TE */ + dmp->dm_dircluster = fnp->f_dirstart; /* TE */ memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent)); dir_close(fnp); return SUCCESS; @@ -531,6 +539,7 @@ COUNT dos_findfirst(UCOUNT attr, BYTE *name) return dos_findnext(); } } + /* BUGFIX TE 06/28/01 @@ -547,11 +556,11 @@ COUNT dos_findnext(void) BOOL found = FALSE; /* Allocate an fnode if possible - error return (0) if not. */ - if ((fnp = get_f_node()) == (f_node_ptr)0) + if ((fnp = get_f_node()) == (f_node_ptr) 0) { return DE_NFILES; } - + memset(fnp, 0, sizeof(*fnp)); /* Force the fnode into read-write mode */ @@ -571,35 +580,38 @@ COUNT dos_findnext(void) /* Search through the directory to find the entry, but do a */ /* seek first. */ if (dmp->dm_entry > 0) - { - fnp->f_diroff = (ULONG)(dmp->dm_entry - 1) * DIRENT_SIZE; + { + fnp->f_diroff = (ULONG) (dmp->dm_entry - 1) * DIRENT_SIZE; fnp->f_flags.f_dnew = FALSE; - } + } else - { + { fnp->f_diroff = 0; fnp->f_flags.f_dnew = TRUE; - } + } /* Loop through the directory */ while (dir_read(fnp) == 1) { ++dmp->dm_entry; if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED - && (fnp->f_dir.dir_attrib & D_VOLID) != D_VOLID ) + && (fnp->f_dir.dir_attrib & D_VOLID) != D_VOLID) { - if (fcmp_wild((BYTE FAR *)dmp->dm_name_pat, (BYTE FAR *)fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE)) + if (fcmp_wild + ((BYTE FAR *) dmp->dm_name_pat, (BYTE FAR *) fnp->f_dir.dir_name, + FNAME_SIZE + FEXT_SIZE)) { /* - MSD Command.com uses FCB FN 11 & 12 with attrib set to 0x16. - Bits 0x21 seem to get set some where in MSD so Rd and Arc - files are returned. - RdOnly + Archive bits are ignored + MSD Command.com uses FCB FN 11 & 12 with attrib set to 0x16. + Bits 0x21 seem to get set some where in MSD so Rd and Arc + files are returned. + RdOnly + Archive bits are ignored */ - + /* Test the attribute as the final step */ if (!(fnp->f_dir.dir_attrib & D_VOLID) && - ((~dmp->dm_attr_srch & fnp->f_dir.dir_attrib & (D_DIR | D_SYSTEM | D_HIDDEN)) == 0)) + ((~dmp->dm_attr_srch & fnp->f_dir. + dir_attrib & (D_DIR | D_SYSTEM | D_HIDDEN)) == 0)) { found = TRUE; break; @@ -612,10 +624,10 @@ COUNT dos_findnext(void) /* If found, transfer it to the dmatch structure */ if (found) - { + { dmp->dm_dircluster = fnp->f_dirstart; memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent)); - } + } /* return the result */ release_f_node(fnp); @@ -631,61 +643,57 @@ COUNT dos_findnext(void) "test e", " test .y z",... so we have to work from the last blank backward -*/ -void ConvertName83ToNameSZ(BYTE FAR *destSZ, BYTE FAR *srcFCBName) +*/ +void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName) { - int loop; - int noExtension = FALSE; - - if (*srcFCBName == '.') - { - noExtension = TRUE; - } - - + int loop; + int noExtension = FALSE; - fmemcpy(destSZ,srcFCBName,FNAME_SIZE); + if (*srcFCBName == '.') + { + noExtension = TRUE; + } - srcFCBName += FNAME_SIZE; - - for (loop = FNAME_SIZE; --loop >= 0; ) - { - if (destSZ[loop] != ' ') - break; - } - destSZ += loop + 1; - - - - if (!noExtension) /* not for ".", ".." */ + fmemcpy(destSZ, srcFCBName, FNAME_SIZE); + + srcFCBName += FNAME_SIZE; + + for (loop = FNAME_SIZE; --loop >= 0;) + { + if (destSZ[loop] != ' ') + break; + } + destSZ += loop + 1; + + if (!noExtension) /* not for ".", ".." */ + { + + for (loop = FEXT_SIZE; --loop >= 0;) { - - for (loop = FEXT_SIZE; --loop >= 0; ) - { - if (srcFCBName[loop] != ' ') - break; - } - if (loop >= 0) - { - *destSZ++ = '.'; - fmemcpy(destSZ,srcFCBName,loop+1); - destSZ += loop+1; - } + if (srcFCBName[loop] != ' ') + break; } - *destSZ = '\0'; + if (loop >= 0) + { + *destSZ++ = '.'; + fmemcpy(destSZ, srcFCBName, loop + 1); + destSZ += loop + 1; + } + } + *destSZ = '\0'; } /* returns the asciiSZ length of a 8.3 filename -*/ +*/ -int FileName83Length(BYTE *filename83) +int FileName83Length(BYTE * filename83) { - BYTE buff[13]; + BYTE buff[13]; - ConvertName83ToNameSZ(buff, filename83); - - return strlen(buff); + ConvertName83ToNameSZ(buff, filename83); + + return strlen(buff); } /* @@ -777,4 +785,3 @@ int FileName83Length(BYTE *filename83) * Rev 1.0 02 Jul 1995 8:04:34 patv * Initial revision. */ - diff --git a/kernel/fatfs.c b/kernel/fatfs.c index e4068ae..5114fa0 100644 --- a/kernel/fatfs.c +++ b/kernel/fatfs.c @@ -59,18 +59,16 @@ BOOL first_fat(f_node_ptr); COUNT map_cluster(f_node_ptr, COUNT); STATIC VOID shrink_file(f_node_ptr fnp); -ULONG clus2phys(CLUSTER cl_no, struct dpb FAR *dpbp) +ULONG clus2phys(CLUSTER cl_no, struct dpb FAR * dpbp) { - CLUSTER data = + CLUSTER data = #ifdef WITHFAT32 - ISFAT32(dpbp) ? - dpbp->dpb_xdata : + ISFAT32(dpbp) ? dpbp->dpb_xdata : #endif dpbp->dpb_data; - return ((ULONG)(cl_no - 2) << dpbp->dpb_shftcnt) + data; + return ((ULONG) (cl_no - 2) << dpbp->dpb_shftcnt) + data; } - /************************************************************************/ /* */ /* Internal file handlers - open, create, read, write, close, etc. */ @@ -118,9 +116,9 @@ COUNT dos_open(BYTE * path, COUNT flag) fnp->f_flags.f_dnew = FALSE; fnp->f_flags.f_ddir = FALSE; - merge_file_changes(fnp, TRUE); /* /// Added - Ron Cemer */ + merge_file_changes(fnp, TRUE); /* /// Added - Ron Cemer */ - /* /// Moved from above. - Ron Cemer */ + /* /// Moved from above. - Ron Cemer */ fnp->f_cluster = getdstart(fnp->f_dir); fnp->f_cluster_offset = 0l; /*JPP */ @@ -160,7 +158,7 @@ COUNT dos_close(COUNT fd) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) return DE_INVLDHNDL; if (fnp->f_flags.f_dmod) @@ -170,10 +168,10 @@ COUNT dos_close(COUNT fd) { fnp->f_dir.dir_time = dos_gettime(); fnp->f_dir.dir_date = dos_getdate(); - } + } fnp->f_dir.dir_size = fnp->f_highwater; - merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ + merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ } fnp->f_flags.f_ddir = TRUE; @@ -184,8 +182,7 @@ COUNT dos_close(COUNT fd) /* */ /* split a path into it's component directory and file name */ /* */ -f_node_ptr - split_path(BYTE * path, BYTE * fname, BYTE * fext) +f_node_ptr split_path(BYTE * path, BYTE * fname, BYTE * fext) { REG f_node_ptr fnp; COUNT nDrive; @@ -194,7 +191,7 @@ f_node_ptr /* Start off by parsing out the components. */ if (ParseDosName(path, &nDrive, &szDirName[2], fname, fext, FALSE) != SUCCESS) - return (f_node_ptr)0; + return (f_node_ptr) 0; if (nDrive < 0) nDrive = default_drive; @@ -205,8 +202,9 @@ f_node_ptr SpacePad(fname, FNAME_SIZE); SpacePad(fext, FEXT_SIZE); - if (nDrive >= lastdrive) { - return (f_node_ptr)0; + if (nDrive >= lastdrive) + { + return (f_node_ptr) 0; } cdsp = &CDSp->cds_table[nDrive]; @@ -229,10 +227,11 @@ f_node_ptr */ #ifdef DEBUG - if (cdsp->cdsFlags & CDSNETWDRV) { + if (cdsp->cdsFlags & CDSNETWDRV) + { printf("split path called for redirected file: `%s.%s'\n", - fname, fext); - return (f_node_ptr)0; + fname, fext); + return (f_node_ptr) 0; } #endif @@ -242,10 +241,10 @@ f_node_ptr /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit... */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) { dir_close(fnp); - return (f_node_ptr)0; + return (f_node_ptr) 0; } /* Convert the name into an absolute name for comparison... */ @@ -267,8 +266,8 @@ STATIC BOOL find_fname(f_node_ptr fnp, BYTE * fname, BYTE * fext) if (fnp->f_dir.dir_name[0] == DELETED) continue; - if (fcmp(fname, (BYTE *)fnp->f_dir.dir_name, FNAME_SIZE) - && fcmp(fext, (BYTE *)fnp->f_dir.dir_ext, FEXT_SIZE) + if (fcmp(fname, (BYTE *) fnp->f_dir.dir_name, FNAME_SIZE) + && fcmp(fext, (BYTE *) fnp->f_dir.dir_ext, FEXT_SIZE) && ((fnp->f_dir.dir_attrib & D_VOLID) == 0)) { found = TRUE; @@ -292,10 +291,12 @@ COUNT remove_lfn_entries(f_node_ptr fnp) { ULONG original_diroff = fnp->f_diroff; COUNT rc; - - while (TRUE) { - if(fnp->f_diroff == 0) break; - fnp->f_diroff -= 2*DIRENT_SIZE; + + while (TRUE) + { + if (fnp->f_diroff == 0) + break; + fnp->f_diroff -= 2 * DIRENT_SIZE; /* it cannot / should not get below 0 because of '.' and '..' */ if ((rc = dir_read(fnp)) < 0) return rc; @@ -310,6 +311,7 @@ COUNT remove_lfn_entries(f_node_ptr fnp) return rc; return SUCCESS; } + /* /// Added - Ron Cemer */ /* If more than one f_node has a file open, and a write occurs, this function must be called to propagate the @@ -319,65 +321,74 @@ COUNT remove_lfn_entries(f_node_ptr fnp) reasons, since DOS without SHARE does not share changes between two or more open instances of the same file unless these instances were generated by dup() or dup2(). */ -STATIC void merge_file_changes(f_node_ptr fnp, int collect) { - f_node_ptr fnp2; - int i; +STATIC void merge_file_changes(f_node_ptr fnp, int collect) +{ + f_node_ptr fnp2; + int i; - if (!IsShareInstalled()) return; - for (i = 0; i < f_nodes_cnt; i++) { - fnp2 = (f_node_ptr)&f_nodes[i]; - if ( (fnp != (f_node_ptr)0) - && (fnp != fnp2) - && (fnp->f_count > 0) - && (is_same_file(fnp, fnp2)) ) { - if (collect) { - /* We're collecting file changes from any other - f_node which refers to this file. */ - if (fnp2->f_mode != RDONLY) { - fnp2->f_dir.dir_size = fnp2->f_highwater; - copy_file_changes(fnp2, fnp); - break; - } - } else { - /* We just made changes to this file, so we are - distributing these changes to the other f_nodes - which refer to this file. */ - if (fnp->f_mode != RDONLY) - fnp->f_dir.dir_size = fnp->f_highwater; - copy_file_changes(fnp, fnp2); - } + if (!IsShareInstalled()) + return; + for (i = 0; i < f_nodes_cnt; i++) + { + fnp2 = (f_node_ptr) & f_nodes[i]; + if ((fnp != (f_node_ptr) 0) + && (fnp != fnp2) + && (fnp->f_count > 0) && (is_same_file(fnp, fnp2))) + { + if (collect) + { + /* We're collecting file changes from any other + f_node which refers to this file. */ + if (fnp2->f_mode != RDONLY) + { + fnp2->f_dir.dir_size = fnp2->f_highwater; + copy_file_changes(fnp2, fnp); + break; } + } + else + { + /* We just made changes to this file, so we are + distributing these changes to the other f_nodes + which refer to this file. */ + if (fnp->f_mode != RDONLY) + fnp->f_dir.dir_size = fnp->f_highwater; + copy_file_changes(fnp, fnp2); + } } + } } /* /// Added - Ron Cemer */ -STATIC int is_same_file(f_node_ptr fnp1, f_node_ptr fnp2) { - return - (fnp1->f_dpb->dpb_unit == fnp2->f_dpb->dpb_unit) - && (fnp1->f_dpb->dpb_subunit == fnp2->f_dpb->dpb_subunit) - && (fcmp - ((BYTE *)fnp1->f_dir.dir_name, - (BYTE *)fnp2->f_dir.dir_name, FNAME_SIZE)) - && (fcmp - ((BYTE *)fnp1->f_dir.dir_ext, - (BYTE *)fnp2->f_dir.dir_ext, FEXT_SIZE)) - && ((fnp1->f_dir.dir_attrib & D_VOLID) == 0) - && ((fnp2->f_dir.dir_attrib & D_VOLID) == 0) - && (fnp1->f_diroff == fnp2->f_diroff) - && (fnp1->f_dirstart == fnp2->f_dirstart) - && (fnp1->f_dpb == fnp2->f_dpb); +STATIC int is_same_file(f_node_ptr fnp1, f_node_ptr fnp2) +{ + return + (fnp1->f_dpb->dpb_unit == fnp2->f_dpb->dpb_unit) + && (fnp1->f_dpb->dpb_subunit == fnp2->f_dpb->dpb_subunit) + && (fcmp + ((BYTE *) fnp1->f_dir.dir_name, + (BYTE *) fnp2->f_dir.dir_name, FNAME_SIZE)) + && (fcmp + ((BYTE *) fnp1->f_dir.dir_ext, + (BYTE *) fnp2->f_dir.dir_ext, FEXT_SIZE)) + && ((fnp1->f_dir.dir_attrib & D_VOLID) == 0) + && ((fnp2->f_dir.dir_attrib & D_VOLID) == 0) + && (fnp1->f_diroff == fnp2->f_diroff) + && (fnp1->f_dirstart == fnp2->f_dirstart) + && (fnp1->f_dpb == fnp2->f_dpb); } /* /// Added - Ron Cemer */ -STATIC void copy_file_changes(f_node_ptr src, f_node_ptr dst) { - dst->f_highwater = src->f_highwater; - dst->f_dir.dir_start = src->f_dir.dir_start; +STATIC void copy_file_changes(f_node_ptr src, f_node_ptr dst) +{ + dst->f_highwater = src->f_highwater; + dst->f_dir.dir_start = src->f_dir.dir_start; #ifdef WITHFAT32 - dst->f_dir.dir_start_high = src->f_dir.dir_start_high; + dst->f_dir.dir_start_high = src->f_dir.dir_start_high; #endif - dst->f_dir.dir_size = src->f_dir.dir_size; - dst->f_dir.dir_date = src->f_dir.dir_date; - dst->f_dir.dir_time = src->f_dir.dir_time; + dst->f_dir.dir_size = src->f_dir.dir_size; + dst->f_dir.dir_date = src->f_dir.dir_date; + dst->f_dir.dir_time = src->f_dir.dir_time; } COUNT dos_creat(BYTE * path, COUNT attrib) @@ -477,7 +488,7 @@ COUNT dos_creat(BYTE * path, COUNT attrib) fnp->f_flags.f_dnew = FALSE; fnp->f_flags.f_ddir = FALSE; - merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ + merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ return xlt_fnp(fnp); } @@ -485,11 +496,11 @@ COUNT dos_creat(BYTE * path, COUNT attrib) STATIC COUNT delete_dir_entry(f_node_ptr fnp) { COUNT rc; - + /* Ok, so we can delete. Start out by */ /* clobbering all FAT entries for this file */ /* (or, in English, truncate the FAT). */ - if ((rc=remove_lfn_entries(fnp)) < 0) + if ((rc = remove_lfn_entries(fnp)) < 0) return rc; wipe_out(fnp); @@ -568,11 +579,11 @@ COUNT dos_rmdir(BYTE * path) /* check for any other bit set. If it is, give */ /* an access error. */ /* if (fnp->f_dir.dir_attrib & ~D_DIR) */ - + /* directories may have attributes, too. at least my WinNT disk has many 'archive' directories - we still don't allow RDONLY directories to be deleted TE*/ - + we still don't allow RDONLY directories to be deleted TE */ + /* if (fnp->f_dir.dir_attrib & ~(D_DIR |D_HIDDEN|D_ARCHIVE|D_SYSTEM)) { dir_close(fnp); @@ -604,7 +615,8 @@ COUNT dos_rmdir(BYTE * path) { if (fnp1->f_dir.dir_name[0] == '\0') break; - if (fnp1->f_dir.dir_name[0] == DELETED || fnp1->f_dir.dir_attrib == D_LFN) + if (fnp1->f_dir.dir_name[0] == DELETED + || fnp1->f_dir.dir_attrib == D_LFN) continue; else { @@ -693,7 +705,7 @@ COUNT dos_rename(BYTE * path1, BYTE * path2) } } - if ((ret=remove_lfn_entries(fnp1)) < 0) + if ((ret = remove_lfn_entries(fnp1)) < 0) return ret; /* put the fnode's name into the directory. */ @@ -731,10 +743,10 @@ COUNT dos_rename(BYTE * path1, BYTE * path2) /* */ /* wipe out all FAT entries starting from st for create, delete, etc. */ /* */ -STATIC VOID wipe_out_clusters(struct dpb FAR *dpbp, CLUSTER st) +STATIC VOID wipe_out_clusters(struct dpb FAR * dpbp, CLUSTER st) { REG CLUSTER next; - + /* Loop from start until either a FREE entry is */ /* encountered (due to a fractured file system) of the */ /* last cluster is encountered. */ @@ -754,20 +766,20 @@ STATIC VOID wipe_out_clusters(struct dpb FAR *dpbp, CLUSTER st) #ifdef WITHFAT32 if (ISFAT32(dpbp)) { - if ((dpbp->dpb_xcluster == UNKNCLUSTER) - || (dpbp->dpb_xcluster > st)) + if ((dpbp->dpb_xcluster == UNKNCLUSTER) || (dpbp->dpb_xcluster > st)) dpbp->dpb_xcluster = st; - } else + } + else #endif - if ((dpbp->dpb_cluster == UNKNCLUSTER) - || (dpbp->dpb_cluster > st)) + if ((dpbp->dpb_cluster == UNKNCLUSTER) || (dpbp->dpb_cluster > st)) dpbp->dpb_cluster = st; /* and just follow the linked list */ st = next; } #ifdef WITHFAT32 - if (ISFAT32(dpbp)) write_fsinfo(dpbp); + if (ISFAT32(dpbp)) + write_fsinfo(dpbp); #endif } @@ -786,7 +798,7 @@ STATIC VOID wipe_out(f_node_ptr fnp) STATIC BOOL find_free(f_node_ptr fnp) { COUNT rc; - + while ((rc = dir_read(fnp)) == 1) if (fnp->f_dir.dir_name[0] == DELETED) return TRUE; @@ -799,9 +811,7 @@ STATIC BOOL find_free(f_node_ptr fnp) date dos_getdate() { #ifndef NOTIME - BYTE WeekDay, - Month, - MonthDay; + BYTE WeekDay, Month, MonthDay; COUNT Year; date Date; @@ -809,8 +819,7 @@ date dos_getdate() /* on start-up or the CMOS clock */ DosGetDate((BYTE FAR *) & WeekDay, (BYTE FAR *) & Month, - (BYTE FAR *) & MonthDay, - (COUNT FAR *) & Year); + (BYTE FAR *) & MonthDay, (COUNT FAR *) & Year); Date = DT_ENCODE(Month, MonthDay, Year - EPOCH_YEAR); return Date; @@ -827,18 +836,14 @@ date dos_getdate() time dos_gettime() { #ifndef NOTIME - BYTE Hour, - Minute, - Second, - Hundredth; + BYTE Hour, Minute, Second, Hundredth; /* First - get the system time set by either the user */ /* on start-up or the CMOS clock */ DosGetTime((BYTE FAR *) & Hour, (BYTE FAR *) & Minute, - (BYTE FAR *) & Second, - (BYTE FAR *) & Hundredth); - return TM_ENCODE(Hour, Minute, Second/2); + (BYTE FAR *) & Second, (BYTE FAR *) & Hundredth); + return TM_ENCODE(Hour, Minute, Second / 2); #else return 0; #endif @@ -858,7 +863,7 @@ COUNT dos_getftime(COUNT fd, date FAR * dp, time FAR * tp) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) return DE_INVLDHNDL; /* Get the date and time from the fnode and return */ @@ -882,14 +887,14 @@ COUNT dos_setftime(COUNT fd, date dp, time tp) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) return DE_INVLDHNDL; /* Set the date and time from the fnode and return */ fnp->f_dir.dir_date = dp; fnp->f_dir.dir_time = tp; - fnp->f_flags.f_dmod = TRUE; /* mark file as modified */ - fnp->f_flags.f_ddate = TRUE; /* set this date upon closing */ + fnp->f_flags.f_dmod = TRUE; /* mark file as modified */ + fnp->f_flags.f_ddate = TRUE; /* set this date upon closing */ return SUCCESS; } @@ -908,7 +913,7 @@ LONG dos_getcufsize(COUNT fd) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) return -1l; /* Return the file size */ @@ -929,7 +934,7 @@ LONG dos_getfsize(COUNT fd) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) return -1l; /* Return the file size */ @@ -950,14 +955,14 @@ BOOL dos_setfsize(COUNT fd, LONG size) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) return FALSE; /* Change the file size */ fnp->f_dir.dir_size = size; fnp->f_highwater = size; - merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ + merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ return TRUE; } @@ -983,8 +988,9 @@ STATIC CLUSTER find_fat_free(f_node_ptr fnp) { if (dpbp->dpb_xcluster != UNKNCLUSTER) idx = dpbp->dpb_xcluster; - size = dpbp->dpb_xsize; - } else + size = dpbp->dpb_xsize; + } + else #endif if (dpbp->dpb_cluster != UNKNCLUSTER) idx = dpbp->dpb_cluster; @@ -1003,20 +1009,20 @@ STATIC CLUSTER find_fat_free(f_node_ptr fnp) { if (idx > dpbp->dpb_xsize) { - dpbp->dpb_xcluster = UNKNCLUSTER; + dpbp->dpb_xcluster = UNKNCLUSTER; write_fsinfo(dpbp); dir_close(fnp); return LONG_LAST_CLUSTER; } if (dpbp->dpb_xnfreeclst != XUNKNCLSTFREE) - dpbp->dpb_xnfreeclst--; /* TE: moved from link_fat() */ + dpbp->dpb_xnfreeclst--; /* TE: moved from link_fat() */ /* return the free entry */ dpbp->dpb_xcluster = idx; write_fsinfo(dpbp); return idx; } -#endif +#endif if (idx > dpbp->dpb_size) { @@ -1026,7 +1032,7 @@ STATIC CLUSTER find_fat_free(f_node_ptr fnp) } if (dpbp->dpb_nfreeclst != UNKNCLSTFREE) - dpbp->dpb_nfreeclst--; /* TE: moved from link_fat() */ + dpbp->dpb_nfreeclst--; /* TE: moved from link_fat() */ /* return the free entry */ dpbp->dpb_cluster = idx; @@ -1052,16 +1058,16 @@ COUNT dos_mkdir(BYTE * dir) { return DE_PATHNOTFND; } - + /* check that the resulting combined path does not exceed the 64 PARSE_MAX limit. this leeds to problems: A) you can't CD to this directory later B) you can't create files in this subdirectory C) the created dir will not be found later, so you - can create an unlimited amount of same dirs. this space - is lost forever - */ - if (strlen(dir) > PARSE_MAX+2) /* dir is already output of "truename" */ + can create an unlimited amount of same dirs. this space + is lost forever + */ + if (strlen(dir) > PARSE_MAX + 2) /* dir is already output of "truename" */ { dir_close(fnp); return DE_PATHNOTFND; @@ -1075,68 +1081,65 @@ COUNT dos_mkdir(BYTE * dir) return DE_ACCESS; } - /* Reset the directory by a close followed by */ - /* an open */ - fnp->f_flags.f_dmod = FALSE; - parent = fnp->f_dirstart; - dir_close(fnp); - fnp = split_path(dir, szFileName, szFileExt); + /* Reset the directory by a close followed by */ + /* an open */ + fnp->f_flags.f_dmod = FALSE; + parent = fnp->f_dirstart; + dir_close(fnp); + fnp = split_path(dir, szFileName, szFileExt); - /* Get a free f_node pointer so that we can use */ - /* it in building the new file. */ - /* Note that if we're in the root and we don't */ - /* find an empty slot, we need to abort. */ - if (find_free(fnp) == 0) + /* Get a free f_node pointer so that we can use */ + /* it in building the new file. */ + /* Note that if we're in the root and we don't */ + /* find an empty slot, we need to abort. */ + if (find_free(fnp) == 0) + { + if (fnp->f_flags.f_droot) { - if (fnp->f_flags.f_droot) - { - fnp->f_flags.f_dmod = FALSE; - dir_close(fnp); - return DE_TOOMANY; - } + fnp->f_flags.f_dmod = FALSE; + dir_close(fnp); + return DE_TOOMANY; + } /* Otherwise just expand the directory */ - if ((ret = extend_dir(fnp)) != SUCCESS) - return ret; - } + if ((ret = extend_dir(fnp)) != SUCCESS) + return ret; + } - - /* get an empty cluster, so that we make it into a */ - /* directory. */ - /* TE this has to be done (and failed) BEFORE the dir entry */ - /* is changed */ - free_fat = find_fat_free(fnp); - - /* No empty clusters, disk is FULL! Translate into a */ - /* useful error message. */ - if (free_fat == LONG_LAST_CLUSTER) - { - dir_close(fnp); - return DE_HNDLDSKFULL; - } - + /* get an empty cluster, so that we make it into a */ + /* directory. */ + /* TE this has to be done (and failed) BEFORE the dir entry */ + /* is changed */ + free_fat = find_fat_free(fnp); - /* put the fnode's name into the directory. */ - memcpy(fnp->f_dir.dir_name, szFileName, FNAME_SIZE); - memcpy(fnp->f_dir.dir_ext, szFileExt, FEXT_SIZE); + /* No empty clusters, disk is FULL! Translate into a */ + /* useful error message. */ + if (free_fat == LONG_LAST_CLUSTER) + { + dir_close(fnp); + return DE_HNDLDSKFULL; + } - /* Set the fnode to the desired mode */ - fnp->f_mode = WRONLY; - fnp->f_back = LONG_LAST_CLUSTER; + /* put the fnode's name into the directory. */ + memcpy(fnp->f_dir.dir_name, szFileName, FNAME_SIZE); + memcpy(fnp->f_dir.dir_ext, szFileExt, FEXT_SIZE); - fnp->f_dir.dir_size = 0l; - fnp->f_dir.dir_attrib = D_DIR; - fnp->f_dir.dir_time = dos_gettime(); - fnp->f_dir.dir_date = dos_getdate(); + /* Set the fnode to the desired mode */ + fnp->f_mode = WRONLY; + fnp->f_back = LONG_LAST_CLUSTER; - fnp->f_flags.f_dmod = TRUE; - fnp->f_flags.f_dnew = FALSE; - fnp->f_flags.f_ddir = TRUE; + fnp->f_dir.dir_size = 0l; + fnp->f_dir.dir_attrib = D_DIR; + fnp->f_dir.dir_time = dos_gettime(); + fnp->f_dir.dir_date = dos_getdate(); - fnp->f_highwater = 0l; - fnp->f_offset = 0l; + fnp->f_flags.f_dmod = TRUE; + fnp->f_flags.f_dnew = FALSE; + fnp->f_flags.f_ddir = TRUE; + fnp->f_highwater = 0l; + fnp->f_offset = 0l; /* Mark the cluster in the FAT as used */ fnp->f_cluster = free_fat; @@ -1147,8 +1150,7 @@ COUNT dos_mkdir(BYTE * dir) /* Craft the new directory. Note that if we're in a new */ /* directory just under the root, ".." pointer is 0. */ /* as we are overwriting it completely, don't read first */ - bp = getblockOver(clus2phys(free_fat, dpbp), - dpbp->dpb_unit); + bp = getblockOver(clus2phys(free_fat, dpbp), dpbp->dpb_unit); #ifdef DISPLAY_GETBLOCK printf("FAT (dos_mkdir)\n"); #endif @@ -1173,17 +1175,19 @@ COUNT dos_mkdir(BYTE * dir) /* create the ".." entry */ memcpy(DirEntBuffer.dir_name, ".. ", FNAME_SIZE); #ifdef WITHFAT32 - if (ISFAT32(dpbp) && parent == dpbp->dpb_xrootclst) { - parent = 0; + if (ISFAT32(dpbp) && parent == dpbp->dpb_xrootclst) + { + parent = 0; } #endif setdstart(DirEntBuffer, parent); /* and put it out */ - putdirent((struct dirent FAR *)&DirEntBuffer, (BYTE FAR *) & bp->b_buffer[DIRENT_SIZE]); + putdirent((struct dirent FAR *)&DirEntBuffer, + (BYTE FAR *) & bp->b_buffer[DIRENT_SIZE]); /* fill the rest of the block with zeros */ - fmemset( & bp->b_buffer[2 * DIRENT_SIZE],0, BUFFERSIZE - 2 * DIRENT_SIZE); + fmemset(&bp->b_buffer[2 * DIRENT_SIZE], 0, BUFFERSIZE - 2 * DIRENT_SIZE); /* Mark the block to be written out */ bp->b_flag |= BFR_DIRTY | BFR_VALID; @@ -1192,7 +1196,7 @@ COUNT dos_mkdir(BYTE * dir) for (idx = 1; idx <= dpbp->dpb_clsmask; idx++) { - /* as we are overwriting it completely, don't read first */ + /* as we are overwriting it completely, don't read first */ bp = getblockOver(clus2phys(getdstart(fnp->f_dir), dpbp) + idx, dpbp->dpb_unit); #ifdef DISPLAY_GETBLOCK @@ -1205,7 +1209,7 @@ COUNT dos_mkdir(BYTE * dir) } fmemset(bp->b_buffer, 0, BUFFERSIZE); bp->b_flag |= BFR_DIRTY | BFR_VALID; - bp->b_flag |= BFR_UNCACHE; /* need not be cached */ + bp->b_flag |= BFR_UNCACHE; /* need not be cached */ } /* flush the drive buffers so that all info is written */ @@ -1270,15 +1274,16 @@ STATIC COUNT extend_dir(f_node_ptr fnp) #ifdef DISPLAY_GETBLOCK printf("DIR (extend_dir)\n"); #endif - if (bp == NULL) { + if (bp == NULL) + { dir_close(fnp); return DE_BLKINVLD; } fmemset(bp->b_buffer, 0, BUFFERSIZE); bp->b_flag |= BFR_DIRTY | BFR_VALID; - + if (idx != 0) - bp->b_flag |= BFR_UNCACHE; /* needs not be cached */ + bp->b_flag |= BFR_UNCACHE; /* needs not be cached */ } if (!find_free(fnp)) @@ -1351,7 +1356,7 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode) #endif /* The variable clssize will be used later. */ - clssize = (ULONG)fnp->f_dpb->dpb_secsize << fnp->f_dpb->dpb_shftcnt; + clssize = (ULONG) fnp->f_dpb->dpb_secsize << fnp->f_dpb->dpb_shftcnt; /* If someone did a seek, but no writes have occured, we will */ /* need to initialize the fnode. */ @@ -1365,7 +1370,7 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode) } } - if (fnp->f_offset >= fnp->f_cluster_offset) /*JPP */ + if (fnp->f_offset >= fnp->f_cluster_offset) /*JPP */ { /* Set internal index and cluster size. */ idx = fnp->f_offset - fnp->f_cluster_offset; @@ -1400,13 +1405,13 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode) if (!extend(fnp)) { dir_close(fnp); - return DE_HNDLDSKFULL; + return DE_HNDLDSKFULL; } } if (idx < clssize) break; - + fnp->f_back = fnp->f_cluster; /* get next cluster in the chain */ @@ -1414,7 +1419,7 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode) fnp->f_cluster_offset += clssize; idx -= clssize; } - + #ifdef DISPLAY_GETBLOCK printf("done.\n"); #endif @@ -1461,7 +1466,6 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode) the same should be done for writes as well - the time to compile the complete kernel (on some P200) is reduced from 67 to 56 seconds - in an otherwise identical configuration. @@ -1487,7 +1491,6 @@ COUNT map_cluster(REG f_node_ptr fnp, COUNT mode) */ - /* Read block from disk */ UCOUNT readblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) { @@ -1497,7 +1500,7 @@ UCOUNT readblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) UCOUNT ret_cnt = 0; UWORD secsize; UCOUNT to_xfer = count; - ULONG currentblock; + ULONG currentblock; #if defined( DEBUG ) && 0 if (bDumpRdWrParms) @@ -1513,7 +1516,7 @@ UCOUNT readblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) { *err = DE_INVLDHNDL; return 0; @@ -1556,8 +1559,7 @@ UCOUNT readblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) { /* Do an EOF test and return whatever was transferred */ /* but only for regular files. */ - if (!(fnp->f_flags.f_ddir) - && (fnp->f_offset >= fnp->f_highwater)) + if (!(fnp->f_flags.f_ddir) && (fnp->f_offset >= fnp->f_highwater)) { *err = SUCCESS; return ret_cnt; @@ -1596,96 +1598,90 @@ UCOUNT readblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) } /* Compute the block within the cluster and the offset */ - /* within the block. */ + /* within the block. */ fnp->f_sector = (fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask; fnp->f_boff = fnp->f_offset & (secsize - 1); currentblock = clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector; /* see comments above */ - - if (!fnp->f_flags.f_ddir && /* don't experiment with directories yet */ - fnp->f_boff == 0 ) /* complete sectors only */ + + if (!fnp->f_flags.f_ddir && /* don't experiment with directories yet */ + fnp->f_boff == 0) /* complete sectors only */ { - static ULONG startoffset; - UCOUNT sectors_to_read,sectors_wanted; + static ULONG startoffset; + UCOUNT sectors_to_read, sectors_wanted; - - startoffset = fnp->f_offset; - - /* avoid EOF problems */ - sectors_wanted = ((UCOUNT) min(fnp->f_highwater - fnp->f_offset, to_xfer)) / - secsize; + startoffset = fnp->f_offset; - if (sectors_wanted < 2) - goto normal_read; - - sectors_to_read = fnp->f_dpb->dpb_clsmask + 1 - fnp->f_sector; + /* avoid EOF problems */ + sectors_wanted = + ((UCOUNT) min(fnp->f_highwater - fnp->f_offset, to_xfer)) / + secsize; + + if (sectors_wanted < 2) + goto normal_read; + + sectors_to_read = fnp->f_dpb->dpb_clsmask + 1 - fnp->f_sector; + + sectors_to_read = min(sectors_to_read, sectors_wanted); + + fnp->f_offset += sectors_to_read * secsize; + + while (sectors_to_read < sectors_wanted) + { + if (map_cluster(fnp, XFR_READ) != SUCCESS) + break; + + if (clus2phys(fnp->f_cluster, fnp->f_dpb) != + currentblock + sectors_to_read) + break; + + sectors_to_read += fnp->f_dpb->dpb_clsmask + 1; sectors_to_read = min(sectors_to_read, sectors_wanted); - fnp->f_offset += sectors_to_read*secsize; - - while (sectors_to_read < sectors_wanted) - { - if (map_cluster(fnp, XFR_READ) != SUCCESS) - break; - - if (clus2phys(fnp->f_cluster, fnp->f_dpb) != currentblock + sectors_to_read) - break; + fnp->f_offset = startoffset + sectors_to_read * secsize; - sectors_to_read += fnp->f_dpb->dpb_clsmask + 1; - - sectors_to_read = min(sectors_to_read, sectors_wanted); + } - fnp->f_offset = startoffset + sectors_to_read*secsize; + xfr_cnt = sectors_to_read * secsize; - } - - xfr_cnt = sectors_to_read * secsize; + /* avoid caching trouble */ - /* avoid caching trouble */ - - DeleteBlockInBufferCache(currentblock, - currentblock + sectors_to_read - 1, - fnp->f_dpb->dpb_unit); - - if (dskxfer(fnp->f_dpb->dpb_unit, - currentblock, - (VOID FAR *) buffer, sectors_to_read, DSKREAD)) - { - fnp->f_offset = startoffset; - *err = DE_BLKINVLD; - return ret_cnt; - } - + DeleteBlockInBufferCache(currentblock, + currentblock + sectors_to_read - 1, + fnp->f_dpb->dpb_unit); - goto update_pointers; + if (dskxfer(fnp->f_dpb->dpb_unit, + currentblock, + (VOID FAR *) buffer, sectors_to_read, DSKREAD)) + { + fnp->f_offset = startoffset; + *err = DE_BLKINVLD; + return ret_cnt; + } + + goto update_pointers; } - - - - - /* normal read: just the old, buffer = sector based read */ -normal_read: - + /* normal read: just the old, buffer = sector based read */ + normal_read: #ifdef DSK_DEBUG printf("read %d links; dir offset %ld, cluster %lx\n", - fnp->f_count, - fnp->f_diroff, - fnp->f_cluster); + fnp->f_count, fnp->f_diroff, fnp->f_cluster); #endif /* Get the block we need from cache */ - bp = getblock(currentblock /*clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector*/, - fnp->f_dpb->dpb_unit); + bp = getblock(currentblock + /*clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector */ + , fnp->f_dpb->dpb_unit); #ifdef DISPLAY_GETBLOCK printf("DATA (readblock)\n"); #endif - if (bp == NULL) /* (struct buffer *)0 --> DS:0 !! */ + if (bp == NULL) /* (struct buffer *)0 --> DS:0 !! */ { *err = DE_BLKINVLD; return ret_cnt; @@ -1699,25 +1695,24 @@ normal_read: if (fnp->f_flags.f_ddir) xfr_cnt = min(to_xfer, secsize - fnp->f_boff); else - xfr_cnt = (UWORD)min(min(to_xfer, secsize - fnp->f_boff), - fnp->f_highwater - fnp->f_offset); + xfr_cnt = (UWORD) min(min(to_xfer, secsize - fnp->f_boff), + fnp->f_highwater - fnp->f_offset); fmemcpy(buffer, &bp->b_buffer[fnp->f_boff], xfr_cnt); - /* complete buffer read ? - probably not reused later - */ + /* complete buffer read ? + probably not reused later + */ if (xfr_cnt == sizeof(bp->b_buffer) || - fnp->f_offset + xfr_cnt == fnp->f_highwater ) - { - bp->b_flag |= BFR_UNCACHE; - } - + fnp->f_offset + xfr_cnt == fnp->f_highwater) + { + bp->b_flag |= BFR_UNCACHE; + } /* update pointers and counters */ fnp->f_offset += xfr_cnt; -update_pointers: + update_pointers: ret_cnt += xfr_cnt; to_xfer -= xfr_cnt; buffer = add_far((VOID FAR *) buffer, (ULONG) xfr_cnt); @@ -1735,78 +1730,74 @@ update_pointers: /* default */ STATIC COUNT dos_extend(f_node_ptr fnp) { -#ifdef WRITEZEROS +#ifdef WRITEZEROS struct buffer FAR *bp; UCOUNT xfr_cnt = 0; /* The variable secsize will be used later. */ UWORD secsize = fnp->f_dpb->dpb_secsize; ULONG count; -#endif +#endif if (fnp->f_offset <= fnp->f_highwater) return SUCCESS; -#ifdef WRITEZEROS +#ifdef WRITEZEROS count = fnp->f_offset - fnp->f_highwater; fnp->f_offset = fnp->f_highwater; while (count > 0) +#endif { -#endif if (map_cluster(fnp, XFR_WRITE) != SUCCESS) return DE_HNDLDSKFULL; #ifdef WRITEZEROS /* Compute the block within the cluster and the offset */ /* within the block. */ - fnp->f_sector = - (fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask; + fnp->f_sector = (fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask; fnp->f_boff = fnp->f_offset & (secsize - 1); #ifdef DSK_DEBUG printf("write %d links; dir offset %ld, cluster %d\n", - fnp->f_count, - fnp->f_diroff, - fnp->f_cluster); + fnp->f_count, fnp->f_diroff, fnp->f_cluster); #endif - xfr_cnt = count < (ULONG)secsize - fnp->f_boff ? - (UWORD) count : - secsize - fnp->f_boff; + xfr_cnt = count < (ULONG) secsize - fnp->f_boff ? + (UWORD) count : secsize - fnp->f_boff; /* get a buffer to store the block in */ - if ( (fnp->f_boff == 0) && (xfr_cnt == secsize) ) { - bp = getblockOver(clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector, - fnp->f_dpb->dpb_unit); - - } else { - bp = getblock(clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector, - fnp->f_dpb->dpb_unit); + if ((fnp->f_boff == 0) && (xfr_cnt == secsize)) + { + bp = getblockOver(clus2phys(fnp->f_cluster, fnp->f_dpb) + + fnp->f_sector, fnp->f_dpb->dpb_unit); + } - if (bp == NULL) { + else + { + bp = getblock(clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector, + fnp->f_dpb->dpb_unit); + } + if (bp == NULL) + { return DE_BLKINVLD; - } - + } /* set a block to zero */ fmemset((BYTE FAR *) & bp->b_buffer[fnp->f_boff], 0, xfr_cnt); bp->b_flag |= BFR_DIRTY | BFR_VALID; - if (xfr_cnt == sizeof(bp->b_buffer)) /* probably not used later */ - { - bp->b_flag |= BFR_UNCACHE; - } + if (xfr_cnt == sizeof(bp->b_buffer)) /* probably not used later */ + { + bp->b_flag |= BFR_UNCACHE; + } /* update pointers and counters */ count -= xfr_cnt; fnp->f_offset += xfr_cnt; + fnp->f_dir.dir_size = fnp->f_offset; +#endif fnp->f_highwater = fnp->f_offset; - fnp->f_dir.dir_size = fnp->f_highwater; - merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ + merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ } -#else - fnp->f_highwater = fnp->f_offset; - merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ -#endif return SUCCESS; } @@ -1835,7 +1826,7 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) /* If the fd was invalid because it was out of range or the */ /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) { *err = DE_INVLDHNDL; return 0; @@ -1848,14 +1839,14 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) return 0; } - fnp->f_flags.f_dmod = TRUE; /* mark file as modified */ - fnp->f_flags.f_ddate = FALSE; /* set date not valid any more */ + fnp->f_flags.f_dmod = TRUE; /* mark file as modified */ + fnp->f_flags.f_ddate = FALSE; /* set date not valid any more */ - /* extend file from fnp->f_highwater to fnp->f_offset */ + /* extend file from fnp->f_highwater to fnp->f_offset */ *err = dos_extend(fnp); if (*err != SUCCESS) return 0; - + /* Test that we are really about to do a data transfer. If the */ /* count is zero and the mode is XFR_READ, just exit. (Any */ /* read with a count of zero is a nop). */ @@ -1864,13 +1855,13 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) /* file length to the current length (truncates it). */ /* */ /* NOTE: doing this up front saves a lot of headaches later. */ - + if (count == 0) { - /* NOTE: doing this up front made a lot of headaches later :-( TE */ + /* NOTE: doing this up front made a lot of headaches later :-( TE */ /* FAT allocation has to be extended if necessary TE */ /* Now done in dos_extend BO */ - /* remove all the following allocated clusters in shrink_file */ + /* remove all the following allocated clusters in shrink_file */ fnp->f_highwater = fnp->f_offset; shrink_file(fnp); return 0; @@ -1948,15 +1939,12 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) /* Compute the block within the cluster and the offset */ /* within the block. */ - fnp->f_sector = - (fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask; + fnp->f_sector = (fnp->f_offset / secsize) & fnp->f_dpb->dpb_clsmask; fnp->f_boff = fnp->f_offset & (secsize - 1); #ifdef DSK_DEBUG printf("write %d links; dir offset %ld, cluster %d\n", - fnp->f_count, - fnp->f_diroff, - fnp->f_cluster); + fnp->f_count, fnp->f_diroff, fnp->f_cluster); #endif /* /// Moved xfr_cnt calculation from below so we can @@ -1970,29 +1958,32 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) /* get a buffer to store the block in */ /* /// BUG!!! Added conditional to only use getbuf() if we're going - to write the entire block, which is faster because it does - not first read the block from disk. However, if we are - going to only write part of the block, we MUST use the - getblock() call, which first reads the block from disk. - Without this modification, the kernel was writing garbage - to the file when sequential writes were attempted at less - than the block size. This was causing problems with - piping and redirection in FreeCOM, as well as many other - potential problems. - - Ron Cemer */ - if ( (fnp->f_boff == 0) && (xfr_cnt == secsize) ) { - bp = getblockOver(clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector, - fnp->f_dpb->dpb_unit); - - } else { - bp = getblock(clus2phys(fnp->f_cluster, fnp->f_dpb) + fnp->f_sector, - fnp->f_dpb->dpb_unit); + to write the entire block, which is faster because it does + not first read the block from disk. However, if we are + going to only write part of the block, we MUST use the + getblock() call, which first reads the block from disk. + Without this modification, the kernel was writing garbage + to the file when sequential writes were attempted at less + than the block size. This was causing problems with + piping and redirection in FreeCOM, as well as many other + potential problems. + - Ron Cemer */ + if ((fnp->f_boff == 0) && (xfr_cnt == secsize)) + { + bp = getblockOver(clus2phys(fnp->f_cluster, fnp->f_dpb) + + fnp->f_sector, fnp->f_dpb->dpb_unit); + } - if (bp == NULL) { + else + { + bp = getblock(clus2phys(fnp->f_cluster, fnp->f_dpb) + + fnp->f_sector, fnp->f_dpb->dpb_unit); + } + if (bp == NULL) + { *err = DE_BLKINVLD; return ret_cnt; - } - + } /* transfer a block */ /* Transfer size as either a full block size, or the */ @@ -2007,11 +1998,10 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) fmemcpy(&bp->b_buffer[fnp->f_boff], buffer, xfr_cnt); bp->b_flag |= BFR_DIRTY | BFR_VALID; - if (xfr_cnt == sizeof(bp->b_buffer)) /* probably not used later */ - { - bp->b_flag |= BFR_UNCACHE; - } - + if (xfr_cnt == sizeof(bp->b_buffer)) /* probably not used later */ + { + bp->b_flag |= BFR_UNCACHE; + } /* update pointers and counters */ ret_cnt += xfr_cnt; @@ -2023,7 +2013,7 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err) fnp->f_highwater = fnp->f_offset; fnp->f_dir.dir_size = fnp->f_highwater; } - merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ + merge_file_changes(fnp, FALSE); /* /// Added - Ron Cemer */ } *err = SUCCESS; return ret_cnt; @@ -2043,7 +2033,7 @@ LONG dos_lseek(COUNT fd, LONG foffset, COUNT origin) /* requested file was not open, tell the caller and exit */ /* note: an invalid fd is indicated by a 0 return */ - if (fnp == (f_node_ptr)0 || fnp->f_count <= 0) + if (fnp == (f_node_ptr) 0 || fnp->f_count <= 0) return (LONG) DE_INVLDHNDL; /* now do the actual lseek adjustment to the file poitner */ @@ -2069,7 +2059,7 @@ LONG dos_lseek(COUNT fd, LONG foffset, COUNT origin) } /* returns the number of unused clusters */ -CLUSTER dos_free(struct dpb FAR *dpbp) +CLUSTER dos_free(struct dpb FAR * dpbp) { /* There's an unwritten rule here. All fs */ /* cluster start at 2 and run to max_cluster+2 */ @@ -2079,23 +2069,24 @@ CLUSTER dos_free(struct dpb FAR *dpbp) #ifdef WITHFAT32 if (ISFAT32(dpbp)) - { + { if (dpbp->dpb_xnfreeclst != XUNKNCLSTFREE) return dpbp->dpb_xnfreeclst; max_cluster = dpbp->dpb_xsize + 1; - } - else -#endif - if (dpbp->dpb_nfreeclst != UNKNCLSTFREE) - return dpbp->dpb_nfreeclst; - + } + else +#endif + if (dpbp->dpb_nfreeclst != UNKNCLSTFREE) + return dpbp->dpb_nfreeclst; + for (i = 2; i < max_cluster; i++) { if (next_cluster(dpbp, i) == 0) ++cnt; } #ifdef WITHFAT32 - if (ISFAT32(dpbp)) { + if (ISFAT32(dpbp)) + { dpbp->dpb_xnfreeclst = cnt; write_fsinfo(dpbp); return cnt; @@ -2105,19 +2096,17 @@ CLUSTER dos_free(struct dpb FAR *dpbp) return cnt; } - - #ifndef IPL -COUNT dos_cd(struct cds FAR * cdsp, BYTE *PathName) +COUNT dos_cd(struct cds FAR * cdsp, BYTE * PathName) { f_node_ptr fnp; /* first check for valid drive */ if (cdsp->cdsDpb == 0) - return DE_INVLDDRV; + return DE_INVLDDRV; if ((media_check(cdsp->cdsDpb) < 0)) - return DE_INVLDDRV; + return DE_INVLDDRV; /* now test for its existance. If it doesn't, return an error. */ if ((fnp = dir_open(PathName)) == NULL) @@ -2143,7 +2132,7 @@ f_node_ptr get_f_node(void) return &f_nodes[i]; } } - return (f_node_ptr)0; + return (f_node_ptr) 0; } VOID release_f_node(f_node_ptr fnp) @@ -2171,7 +2160,7 @@ COUNT dos_getfattr(BYTE * name) return DE_FILENOTFND; /* note: an invalid fd is indicated by a 0 return */ - if ((fnp = xlt_fd(fd)) == (f_node_ptr)0) + if ((fnp = xlt_fd(fd)) == (f_node_ptr) 0) return DE_TOOMANY; /* If the fd was invalid because it was out of range or the */ @@ -2199,7 +2188,7 @@ COUNT dos_setfattr(BYTE * name, UWORD attrp) return DE_FILENOTFND; /* note: an invalid fd is indicated by a 0 return */ - if ((fnp = xlt_fd(fd)) == (f_node_ptr)0) + if ((fnp = xlt_fd(fd)) == (f_node_ptr) 0) return DE_TOOMANY; /* If the fd was invalid because it was out of range or the */ @@ -2218,10 +2207,10 @@ COUNT dos_setfattr(BYTE * name, UWORD attrp) /* Set the attribute from the fnode and return */ /* clear all attributes but DIR and VOLID */ - fnp->f_dir.dir_attrib &= (D_VOLID | D_DIR); /* JPP */ + fnp->f_dir.dir_attrib &= (D_VOLID | D_DIR); /* JPP */ /* set attributes that user requested */ - fnp->f_dir.dir_attrib |= attrp; /* JPP */ + fnp->f_dir.dir_attrib |= attrp; /* JPP */ fnp->f_flags.f_dmod = TRUE; fnp->f_flags.f_ddate = TRUE; dos_close(fd); @@ -2230,10 +2219,10 @@ COUNT dos_setfattr(BYTE * name, UWORD attrp) #endif #ifdef WITHFAT32 -VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp, BOOL extended) +VOID bpb_to_dpb(bpb FAR * bpbp, REG struct dpb FAR * dpbp, BOOL extended) #else -VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp) -#endif +VOID bpb_to_dpb(bpb FAR * bpbp, REG struct dpb FAR * dpbp) +#endif { ULONG size; REG UWORD shftcnt; @@ -2244,16 +2233,13 @@ VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp) dpbp->dpb_fatstrt = bpbp->bpb_nreserved; dpbp->dpb_fats = bpbp->bpb_nfat; dpbp->dpb_dirents = bpbp->bpb_ndirent; - size = bpbp->bpb_nsize == 0 ? - bpbp->bpb_huge : - (ULONG) bpbp->bpb_nsize; + size = bpbp->bpb_nsize == 0 ? bpbp->bpb_huge : (ULONG) bpbp->bpb_nsize; dpbp->dpb_fatsize = bpbp->bpb_nfsect; dpbp->dpb_dirstrt = dpbp->dpb_fatstrt + dpbp->dpb_fats * dpbp->dpb_fatsize; dpbp->dpb_data = dpbp->dpb_dirstrt - + ((DIRENT_SIZE * (ULONG)dpbp->dpb_dirents - + (dpbp->dpb_secsize - 1)) - / dpbp->dpb_secsize); + + ((DIRENT_SIZE * (ULONG) dpbp->dpb_dirents + + (dpbp->dpb_secsize - 1)) / dpbp->dpb_secsize); /* Michal Meller patch to jimtabor */ dpbp->dpb_size = ((size - dpbp->dpb_data) / ((ULONG) bpbp->bpb_nsector) + 1); @@ -2266,9 +2252,9 @@ VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp) if (extended) { dpbp->dpb_xfatsize = bpbp->bpb_nfsect == 0 ? bpbp->bpb_xnfsect - : bpbp->bpb_nfsect; + : bpbp->bpb_nfsect; dpbp->dpb_xcluster = UNKNCLUSTER; - dpbp->dpb_xnfreeclst = XUNKNCLSTFREE; /* number of free clusters */ + dpbp->dpb_xnfreeclst = XUNKNCLSTFREE; /* number of free clusters */ dpbp->dpb_xflags = 0; dpbp->dpb_xfsinfosec = 0xffff; @@ -2276,8 +2262,8 @@ VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp) dpbp->dpb_xrootclst = 0; dpbp->dpb_xdata = dpbp->dpb_data; dpbp->dpb_xsize = dpbp->dpb_size; - - if (ISFAT32(dpbp)) + + if (ISFAT32(dpbp)) { dpbp->dpb_xflags = bpbp->bpb_xflags; dpbp->dpb_xfsinfosec = bpbp->bpb_xfsinfosec; @@ -2285,13 +2271,14 @@ VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp) dpbp->dpb_dirents = 0; dpbp->dpb_dirstrt = 0xffff; dpbp->dpb_size = 0; - dpbp->dpb_xdata = dpbp->dpb_fatstrt + dpbp->dpb_fats * dpbp->dpb_xfatsize; - dpbp->dpb_xsize = ((size - dpbp->dpb_xdata) - / ((ULONG) bpbp->bpb_nsector) + 1); + dpbp->dpb_xdata = + dpbp->dpb_fatstrt + dpbp->dpb_fats * dpbp->dpb_xfatsize; + dpbp->dpb_xsize = + ((size - dpbp->dpb_xdata) / ((ULONG) bpbp->bpb_nsector) + 1); dpbp->dpb_xrootclst = bpbp->bpb_xrootclst; read_fsinfo(dpbp); - } - } + } + } #endif for (shftcnt = 0; (bpbp->bpb_nsector >> shftcnt) > 1; shftcnt++) @@ -2310,7 +2297,8 @@ COUNT media_check(REG struct dpb FAR * dpbp) MediaReqHdr.r_mcmdesc = dpbp->dpb_mdb; MediaReqHdr.r_status = 0; execrh((request FAR *) & MediaReqHdr, dpbp->dpb_device); - if (!(MediaReqHdr.r_status & S_ERROR) && (MediaReqHdr.r_status & S_DONE)) + if (!(MediaReqHdr.r_status & S_ERROR) + && (MediaReqHdr.r_status & S_DONE)) break; else { @@ -2357,12 +2345,14 @@ COUNT media_check(REG struct dpb FAR * dpbp) MediaReqHdr.r_mcmdesc = dpbp->dpb_mdb; MediaReqHdr.r_status = 0; execrh((request FAR *) & MediaReqHdr, dpbp->dpb_device); - if (!(MediaReqHdr.r_status & S_ERROR) && (MediaReqHdr.r_status & S_DONE)) + if (!(MediaReqHdr.r_status & S_ERROR) + && (MediaReqHdr.r_status & S_DONE)) break; else { loop2: - switch (block_error(&MediaReqHdr, dpbp->dpb_unit, dpbp->dpb_device)) + switch (block_error + (&MediaReqHdr, dpbp->dpb_unit, dpbp->dpb_device)) { case ABORT: case FAIL: @@ -2391,13 +2381,13 @@ COUNT media_check(REG struct dpb FAR * dpbp) /* translate the fd into an f_node pointer */ f_node_ptr xlt_fd(COUNT fd) { - return fd >= f_nodes_cnt ? (f_node_ptr)0 : &f_nodes[fd]; + return fd >= f_nodes_cnt ? (f_node_ptr) 0 : &f_nodes[fd]; } /* translate the f_node pointer into an fd */ COUNT xlt_fnp(f_node_ptr fnp) { - return (COUNT)(fnp - f_nodes); + return (COUNT) (fnp - f_nodes); } #if 0 @@ -2406,12 +2396,11 @@ struct dhdr FAR *select_unit(COUNT drive) /* Just get the header from the dhdr array */ /* return blk_devices[drive].dpb_device; */ - return (struct dhdr FAR *)CDSp->cds_table[drive].cdsDpb; + return (struct dhdr FAR *)CDSp->cds_table[drive].cdsDpb; } #endif - /* TE if the current filesize in FAT is larger then the dir_size it's truncated here. @@ -2430,45 +2419,45 @@ struct dhdr FAR *select_unit(COUNT drive) STATIC VOID shrink_file(f_node_ptr fnp) { - ULONG lastoffset = fnp->f_offset; /* has to be saved */ - CLUSTER next,st; - struct dpb FAR *dpbp = fnp->f_dpb; + ULONG lastoffset = fnp->f_offset; /* has to be saved */ + CLUSTER next, st; + struct dpb FAR *dpbp = fnp->f_dpb; - fnp->f_offset = fnp->f_highwater; /* end of file */ + fnp->f_offset = fnp->f_highwater; /* end of file */ - if (fnp->f_offset) fnp->f_offset--; /* last existing cluster */ - - if (map_cluster(fnp, XFR_READ) != SUCCESS) /* error, don't truncate */ - goto done; - - st = fnp->f_cluster; + if (fnp->f_offset) + fnp->f_offset--; /* last existing cluster */ - next = next_cluster(dpbp, st); + if (map_cluster(fnp, XFR_READ) != SUCCESS) /* error, don't truncate */ + goto done; - if (next == LONG_LAST_CLUSTER) /* last cluster found */ - goto done; + st = fnp->f_cluster; - /* Loop from start until either a FREE entry is */ - /* encountered (due to a damaged file system) or the */ - /* last cluster is encountered. */ - /* zap the FAT pointed to */ + next = next_cluster(dpbp, st); - - if (fnp->f_highwater == 0) - { - setdstart(fnp->f_dir, FREE); - link_fat(dpbp, st, FREE); - } - else - { - link_fat(dpbp, st,LONG_LAST_CLUSTER); - } + if (next == LONG_LAST_CLUSTER) /* last cluster found */ + goto done; + + /* Loop from start until either a FREE entry is */ + /* encountered (due to a damaged file system) or the */ + /* last cluster is encountered. */ + /* zap the FAT pointed to */ + + if (fnp->f_highwater == 0) + { + setdstart(fnp->f_dir, FREE); + link_fat(dpbp, st, FREE); + } + else + { + link_fat(dpbp, st, LONG_LAST_CLUSTER); + } + + wipe_out_clusters(dpbp, next); - wipe_out_clusters(dpbp, next); - done: - fnp->f_offset = lastoffset; /* has to be restored */ - + fnp->f_offset = lastoffset; /* has to be restored */ + } /* @@ -2617,4 +2606,3 @@ done: * Rev 1.0 02 Jul 1995 8:04:46 patv * Initial revision. */ - diff --git a/kernel/fattab.c b/kernel/fattab.c index ce510d4..b6a05c2 100644 --- a/kernel/fattab.c +++ b/kernel/fattab.c @@ -30,7 +30,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif #ifdef PROTO @@ -56,43 +57,43 @@ CLUSTER next_cl32(); /************************************************************************/ #ifndef ISFAT32 -int ISFAT32(struct dpb FAR *dpbp) +int ISFAT32(struct dpb FAR * dpbp) { - return _ISFAT32(dpbp); + return _ISFAT32(dpbp); } #endif - -struct buffer FAR *getFATblock(CLUSTER cluster, struct dpb FAR *dpbp) +struct buffer FAR *getFATblock(CLUSTER cluster, struct dpb FAR * dpbp) { - ULONG sector; + ULONG sector; struct buffer FAR *bp; if (ISFAT12(dpbp)) - { - sector = ((cluster << 1) + cluster) >> 1; - } + { + sector = ((cluster << 1) + cluster) >> 1; + } #ifdef WITHFAT32 else if (ISFAT32(dpbp)) - { - sector = (ULONG)cluster * SIZEOF_CLST32; - } + { + sector = (ULONG) cluster *SIZEOF_CLST32; + } #endif else - { - sector = (ULONG)cluster * SIZEOF_CLST16; - } - sector = sector / dpbp->dpb_secsize + dpbp->dpb_fatstrt; + { + sector = (ULONG) cluster *SIZEOF_CLST16; + } + sector = sector / dpbp->dpb_secsize + dpbp->dpb_fatstrt; #ifdef WITHFAT32 - if (ISFAT32(dpbp) && (dpbp->dpb_xflags & FAT_NO_MIRRORING)) { + if (ISFAT32(dpbp) && (dpbp->dpb_xflags & FAT_NO_MIRRORING)) + { /* we must modify the active fat, it's number is in the 0-3 bits of dpb_xflags */ sector += (dpbp->dpb_xflags & 0xf) * dpbp->dpb_xfatsize; } #endif - + bp = getblock(sector, dpbp->dpb_unit); - + if (bp) { bp->b_flag &= ~(BFR_DATA | BFR_DIR); @@ -108,11 +109,11 @@ struct buffer FAR *getFATblock(CLUSTER cluster, struct dpb FAR *dpbp) } #endif } - return bp; + return bp; } #ifdef WITHFAT32 -void read_fsinfo(struct dpb FAR *dpbp) +void read_fsinfo(struct dpb FAR * dpbp) { struct buffer FAR *bp; struct fsinfo FAR *fip; @@ -121,12 +122,12 @@ void read_fsinfo(struct dpb FAR *dpbp) bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT | BFR_DIRTY); bp->b_flag |= BFR_VALID; - fip = (struct fsinfo FAR *) & bp->b_buffer[0x1e4]; + fip = (struct fsinfo FAR *)&bp->b_buffer[0x1e4]; dpbp->dpb_xnfreeclst = fip->fi_nfreeclst; dpbp->dpb_xcluster = fip->fi_cluster; } -void write_fsinfo(struct dpb FAR *dpbp) +void write_fsinfo(struct dpb FAR * dpbp) { struct buffer FAR *bp; struct fsinfo FAR *fip; @@ -135,7 +136,7 @@ void write_fsinfo(struct dpb FAR *dpbp) bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT); bp->b_flag |= BFR_VALID | BFR_DIRTY; - fip = (struct fsinfo FAR *) & bp->b_buffer[0x1e4]; + fip = (struct fsinfo FAR *)&bp->b_buffer[0x1e4]; fip->fi_nfreeclst = dpbp->dpb_xnfreeclst; fip->fi_cluster = dpbp->dpb_xcluster; } @@ -157,10 +158,11 @@ void write_fsinfo(struct dpb FAR *dpbp) /* 12 bytes are compressed to 9 bytes */ /* */ -UCOUNT link_fat(struct dpb FAR *dpbp, CLUSTER Cluster1, REG CLUSTER Cluster2) +UCOUNT link_fat(struct dpb FAR * dpbp, CLUSTER Cluster1, + REG CLUSTER Cluster2) { UCOUNT res; - + if (ISFAT12(dpbp)) res = link_fat12(dpbp, Cluster1, Cluster2); else if (ISFAT16(dpbp)) @@ -172,7 +174,6 @@ UCOUNT link_fat(struct dpb FAR *dpbp, CLUSTER Cluster1, REG CLUSTER Cluster2) else return DE_BLKINVLD; - /* update the free space count */ if (res == SUCCESS && Cluster2 == FREE) @@ -181,36 +182,38 @@ UCOUNT link_fat(struct dpb FAR *dpbp, CLUSTER Cluster1, REG CLUSTER Cluster2) if (ISFAT32(dpbp) && dpbp->dpb_xnfreeclst != XUNKNCLSTFREE) { /* update the free space count for returned */ - /* cluster */ + /* cluster */ ++dpbp->dpb_xnfreeclst; write_fsinfo(dpbp); - } else + } + else #endif if (dpbp->dpb_nfreeclst != UNKNCLSTFREE) ++dpbp->dpb_nfreeclst; } - /*if (Cluster2 == FREE) - { */ - /* update the free space count for returned */ - /* cluster */ - /* ++dpbp->dpb_nfreeclst; - }*/ + /*if (Cluster2 == FREE) + { */ + /* update the free space count for returned */ + /* cluster */ + /* ++dpbp->dpb_nfreeclst; + } */ - /* update the free space count for removed */ - /* cluster */ - /* BUG: was counted twice for 2nd,.. cluster. moved to find_fat_free() */ - /* BO: don't completely understand this yet - leave here for now as - a comment */ - /* else - { - --dpbp->dpb_nfreeclst; - } */ - return res; + /* update the free space count for removed */ + /* cluster */ + /* BUG: was counted twice for 2nd,.. cluster. moved to find_fat_free() */ + /* BO: don't completely understand this yet - leave here for now as + a comment */ + /* else + { + --dpbp->dpb_nfreeclst; + } */ + return res; } #ifdef WITHFAT32 -UCOUNT link_fat32(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) +UCOUNT link_fat32(struct dpb FAR * dpbp, CLUSTER Cluster1, + CLUSTER Cluster2) { UCOUNT idx; struct buffer FAR *bp; @@ -223,7 +226,7 @@ UCOUNT link_fat32(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) /* form an index so that we can read the block as a */ /* byte array */ - idx = (UWORD)((Cluster1 * SIZEOF_CLST32) % dpbp->dpb_secsize); + idx = (UWORD) ((Cluster1 * SIZEOF_CLST32) % dpbp->dpb_secsize); /* Finally, put the word into the buffer and mark the */ /* buffer as dirty. */ @@ -237,7 +240,8 @@ UCOUNT link_fat32(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) #endif -UCOUNT link_fat16(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) +UCOUNT link_fat16(struct dpb FAR * dpbp, CLUSTER Cluster1, + CLUSTER Cluster2) { UCOUNT idx; struct buffer FAR *bp; @@ -250,7 +254,7 @@ UCOUNT link_fat16(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) /* form an index so that we can read the block as a */ /* byte array */ - idx = (UWORD)(( Cluster1 * SIZEOF_CLST16) % dpbp->dpb_secsize); + idx = (UWORD) ((Cluster1 * SIZEOF_CLST16) % dpbp->dpb_secsize); /* Finally, put the word into the buffer and mark the */ /* buffer as dirty. */ @@ -262,22 +266,21 @@ UCOUNT link_fat16(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) return SUCCESS; } -UCOUNT link_fat12(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) +UCOUNT link_fat12(struct dpb FAR * dpbp, CLUSTER Cluster1, + CLUSTER Cluster2) { - REG UBYTE FAR *fbp0, - FAR * fbp1; + REG UBYTE FAR *fbp0, FAR * fbp1; UCOUNT idx; - struct buffer FAR *bp, - FAR * bp1; + struct buffer FAR *bp, FAR * bp1; /* Get the block that this cluster is in */ - bp = getFATblock(Cluster1 , dpbp); + bp = getFATblock(Cluster1, dpbp); if (bp == NULL) return DE_BLKINVLD; /* form an index so that we can read the block as a */ /* byte array */ - idx = (UCOUNT)(((Cluster1 << 1) + Cluster1) >> 1) % dpbp->dpb_secsize; + idx = (UCOUNT) (((Cluster1 << 1) + Cluster1) >> 1) % dpbp->dpb_secsize; /* Test to see if the cluster straddles the block. If */ /* it does, get the next block and use both to form the */ @@ -285,7 +288,7 @@ UCOUNT link_fat12(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) /* block. */ if (idx >= dpbp->dpb_secsize - 1) { - bp1 = getFATblock(Cluster1 + 1,dpbp); + bp1 = getFATblock(Cluster1 + 1, dpbp); if (bp1 == 0) return DE_BLKINVLD; @@ -315,12 +318,14 @@ UCOUNT link_fat12(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2) /* Given the disk parameters, and a cluster number, this function looks at the FAT, and returns the next cluster in the clain. */ -CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) +CLUSTER next_cluster(struct dpb FAR * dpbp, CLUSTER ClusterNum) { struct buffer FAR *bp; #ifdef DEBUG - if (ClusterNum == LONG_LAST_CLUSTER) printf("fatal error: trying to do next_cluster(dpbp, EOC)!\n"); - if (ClusterNum == 0) printf("fatal error: trying to do next_cluster(dpbp, 0)!\n"); + if (ClusterNum == LONG_LAST_CLUSTER) + printf("fatal error: trying to do next_cluster(dpbp, EOC)!\n"); + if (ClusterNum == 0) + printf("fatal error: trying to do next_cluster(dpbp, 0)!\n"); #endif /* Get the block that this cluster is in */ @@ -332,20 +337,22 @@ CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) if (ISFAT12(dpbp)) { union { - UBYTE bytes[2]; - UCOUNT word; + UBYTE bytes[2]; + UCOUNT word; } clusterbuff; - + UCOUNT idx; /* form an index so that we can read the block as a */ /* byte array */ - idx = (UCOUNT)(((ClusterNum << 1) + ClusterNum) >> 1) % dpbp->dpb_secsize; + idx = + (UCOUNT) (((ClusterNum << 1) + + ClusterNum) >> 1) % dpbp->dpb_secsize; clusterbuff.bytes[0] = bp->b_buffer[idx]; - clusterbuff.bytes[1] = bp->b_buffer[idx+1]; /* next byte, will be overwritten, - if not valid */ + clusterbuff.bytes[1] = bp->b_buffer[idx + 1]; /* next byte, will be overwritten, + if not valid */ /* Test to see if the cluster straddles the block. If it */ /* does, get the next block and use both to form the */ @@ -353,7 +360,7 @@ CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) /* block. */ if (idx >= dpbp->dpb_secsize - 1) { - bp = getFATblock(ClusterNum +1, dpbp); + bp = getFATblock(ClusterNum + 1, dpbp); if (bp == 0) return LONG_BAD; @@ -363,19 +370,20 @@ CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) /* Now to unpack the contents of the FAT entry. Odd and */ /* even bytes are packed differently. */ - -#ifndef I86 /* the latter assumes byte ordering */ + +#ifndef I86 /* the latter assumes byte ordering */ if (ClusterNum & 0x01) - idx = ((clusterbuff.byte[0] & 0xf0) >> 4) | (clusterbuff.byte[1] << 4); + idx = + ((clusterbuff.byte[0] & 0xf0) >> 4) | (clusterbuff.byte[1] << 4); else idx = clusterbuff.byte[0] | ((clusterbuff.byte[0] & 0x0f) << 8); #else - + if (ClusterNum & 0x01) idx = (unsigned short)clusterbuff.word >> 4; else - idx = clusterbuff.word & 0x0fff; -#endif + idx = clusterbuff.word & 0x0fff; +#endif if (idx >= MASK12) return LONG_LAST_CLUSTER; @@ -384,7 +392,7 @@ CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) return idx; } else if (ISFAT16(dpbp)) - { + { UWORD res; #ifndef I86 @@ -395,16 +403,22 @@ CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) idx = (ClusterNum * SIZEOF_CLST16) % dpbp->dpb_secsize; /* Get the cluster number, */ - + fgetword((VOID FAR *) & (bp->b_buffer[idx]), (WORD FAR *) & res); #else /* this saves 2 WORDS of stack :-) */ - - res = *(UWORD FAR *)&(bp->b_buffer[(UCOUNT)((ClusterNum * SIZEOF_CLST16) % dpbp->dpb_secsize)]); -#endif - if (res >= MASK16) return LONG_LAST_CLUSTER; - if (res == BAD16) return LONG_BAD; + + res = + *(UWORD FAR *) & (bp-> + b_buffer[(UCOUNT) + ((ClusterNum * SIZEOF_CLST16) % + dpbp->dpb_secsize)]); +#endif + if (res >= MASK16) + return LONG_LAST_CLUSTER; + if (res == BAD16) + return LONG_BAD; return res; } @@ -413,10 +427,15 @@ CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) { UDWORD res; - res = *(UDWORD FAR *)&(bp->b_buffer[(UCOUNT)((ClusterNum * SIZEOF_CLST32) % dpbp->dpb_secsize)]); - if (res > LONG_BAD) return LONG_LAST_CLUSTER; + res = + *(UDWORD FAR *) & (bp-> + b_buffer[(UCOUNT) + ((ClusterNum * SIZEOF_CLST32) % + dpbp->dpb_secsize)]); + if (res > LONG_BAD) + return LONG_LAST_CLUSTER; - return res; + return res; } #endif return LONG_LAST_CLUSTER; @@ -477,6 +496,3 @@ CLUSTER next_cluster(struct dpb FAR *dpbp, CLUSTER ClusterNum) * Rev 1.0 02 Jul 1995 8:04:56 patv * Initial revision. */ - - - diff --git a/kernel/fcbfns.c b/kernel/fcbfns.c index ff8969d..2988b46 100644 --- a/kernel/fcbfns.c +++ b/kernel/fcbfns.c @@ -30,7 +30,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif #define FCB_SUCCESS 0 @@ -41,7 +42,8 @@ static BYTE *RcsId = "$Id$"; #ifdef PROTO fcb FAR *ExtFcbToFcb(xfcb FAR * lpExtFcb); -fcb FAR *CommonFcbInit(xfcb FAR * lpExtFcb, BYTE * pszBuffer, COUNT * pCurDrive); +fcb FAR *CommonFcbInit(xfcb FAR * lpExtFcb, BYTE * pszBuffer, + COUNT * pCurDrive); void FcbNameInit(fcb FAR * lpFcb, BYTE * pszBuffer, COUNT * pCurDrive); VOID FcbNextRecord(fcb FAR * lpFcb); BOOL FcbCalcRec(xfcb FAR * lpXfcb); @@ -53,9 +55,8 @@ VOID FcbNextRecord(); BOOL FcbCalcRec(); #endif -#define TestCmnSeps(lpFileName) (strchr(":<|>+=,", *lpFileName) != NULL) -#define TestFieldSeps(lpFileName) (*(lpFileName) <= ' ' || strchr("/\"[]<>|.", *lpFileName) != NULL) - +#define TestCmnSeps(lpFileName) (strchr(":<|>+=,", *lpFileName) != NULL) +#define TestFieldSeps(lpFileName) (*(lpFileName) <= ' ' || strchr("/\"[]<>|.", *lpFileName) != NULL) static dmatch Dmatch; @@ -63,12 +64,12 @@ VOID FatGetDrvData(UCOUNT drive, UCOUNT FAR * spc, UCOUNT FAR * bps, UCOUNT FAR * nc, BYTE FAR ** mdp) { UCOUNT navc; - + /* get the data available from dpb */ - *nc = 0xffff; /* pass 0xffff to skip free count */ - if (DosGetFree((UBYTE)drive, spc, &navc, bps, nc)) - /* Point to the media desctriptor for this drive */ - *mdp = (BYTE FAR*)&(CDSp->cds_table[drive].cdsDpb->dpb_mdb); + *nc = 0xffff; /* pass 0xffff to skip free count */ + if (DosGetFree((UBYTE) drive, spc, &navc, bps, nc)) + /* Point to the media desctriptor for this drive */ + *mdp = (BYTE FAR *) & (CDSp->cds_table[drive].cdsDpb->dpb_mdb); } #define PARSE_SEP_STOP 0x01 @@ -84,7 +85,7 @@ VOID FatGetDrvData(UCOUNT drive, UCOUNT FAR * spc, UCOUNT FAR * bps, WORD FcbParseFname(int wTestMode, BYTE FAR ** lpFileName, fcb FAR * lpFcb) { COUNT nIndex; - WORD wRetCodeName,wRetCodeExt; + WORD wRetCodeName, wRetCodeExt; /* pjv -- ExtFcbToFcb? */ /* Start out with some simple stuff first. Check if we are */ @@ -131,24 +132,28 @@ WORD FcbParseFname(int wTestMode, BYTE FAR ** lpFileName, fcb FAR * lpFcb) /* special cases: '.' and '..' */ if (**lpFileName == '.') { - lpFcb->fcb_fname[0]='.'; + lpFcb->fcb_fname[0] = '.'; + ++*lpFileName; + if (**lpFileName == '.') + { + lpFcb->fcb_fname[1] = '.'; ++*lpFileName; - if (**lpFileName == '.') - { - lpFcb->fcb_fname[1]='.'; - ++*lpFileName; - } - return PARSE_RET_NOWILD; + } + return PARSE_RET_NOWILD; } - + /* Now to format the file name into the string */ - *lpFileName = GetNameField(*lpFileName, (BYTE FAR *) lpFcb->fcb_fname, FNAME_SIZE, (BOOL *) & wRetCodeName); + *lpFileName = + GetNameField(*lpFileName, (BYTE FAR *) lpFcb->fcb_fname, FNAME_SIZE, + (BOOL *) & wRetCodeName); /* Do we have an extension? If do, format it else return */ if (**lpFileName == '.') - *lpFileName = GetNameField(++*lpFileName, (BYTE FAR *) lpFcb->fcb_fext, FEXT_SIZE, (BOOL *) & wRetCodeExt); + *lpFileName = + GetNameField(++*lpFileName, (BYTE FAR *) lpFcb->fcb_fext, + FEXT_SIZE, (BOOL *) & wRetCodeExt); - return (wRetCodeName|wRetCodeExt) ? PARSE_RET_WILD : PARSE_RET_NOWILD; + return (wRetCodeName | wRetCodeExt) ? PARSE_RET_WILD : PARSE_RET_NOWILD; } BYTE FAR *ParseSkipWh(BYTE FAR * lpFileName) @@ -158,24 +163,22 @@ BYTE FAR *ParseSkipWh(BYTE FAR * lpFileName) return lpFileName; } -#if 0 /* defined above */ +#if 0 /* defined above */ BOOL TestCmnSeps(BYTE FAR * lpFileName) { - BYTE *pszTest, - *pszCmnSeps = ":<|>+=,"; + BYTE *pszTest, *pszCmnSeps = ":<|>+=,"; for (pszTest = pszCmnSeps; *pszTest != '\0'; ++pszTest) if (*lpFileName == *pszTest) return TRUE; return FALSE; } -#endif +#endif #if 0 BOOL TestFieldSeps(BYTE FAR * lpFileName) { - BYTE *pszTest, - *pszCmnSeps = "/\"[]<>|."; + BYTE *pszTest, *pszCmnSeps = "/\"[]<>|."; /* Another non-portable construct */ if (*lpFileName <= ' ') @@ -188,7 +191,6 @@ BOOL TestFieldSeps(BYTE FAR * lpFileName) } #endif - BYTE FAR *GetNameField(BYTE FAR * lpFileName, BYTE FAR * lpDestField, COUNT nFieldSize, BOOL * pbWildCard) { @@ -196,7 +198,8 @@ BYTE FAR *GetNameField(BYTE FAR * lpFileName, BYTE FAR * lpDestField, BYTE cFill = ' '; *pbWildCard = FALSE; - while (*lpFileName != '\0' && !TestFieldSeps(lpFileName) && nIndex < nFieldSize) + while (*lpFileName != '\0' && !TestFieldSeps(lpFileName) + && nIndex < nFieldSize) { if (*lpFileName == ' ') break; @@ -231,8 +234,8 @@ static VOID FcbNextRecord(fcb FAR * lpFcb) static ULONG FcbRec(VOID) { UWORD tmp = 128; - - return ((ULONG)lpFcb->fcb_cublock * tmp) + lpFcb->fcb_curec; + + return ((ULONG) lpFcb->fcb_cublock * tmp) + lpFcb->fcb_curec; } BOOL FcbRead(xfcb FAR * lpXfcb, COUNT * nErrorCode) @@ -395,7 +398,8 @@ BOOL FcbCalcRec(xfcb FAR * lpXfcb) return TRUE; } -BOOL FcbRandomBlockRead(xfcb FAR * lpXfcb, COUNT nRecords, COUNT * nErrorCode) +BOOL FcbRandomBlockRead(xfcb FAR * lpXfcb, COUNT nRecords, + COUNT * nErrorCode) { FcbCalcRec(lpXfcb); @@ -412,7 +416,8 @@ BOOL FcbRandomBlockRead(xfcb FAR * lpXfcb, COUNT nRecords, COUNT * nErrorCode) return TRUE; } -BOOL FcbRandomBlockWrite(xfcb FAR * lpXfcb, COUNT nRecords, COUNT * nErrorCode) +BOOL FcbRandomBlockWrite(xfcb FAR * lpXfcb, COUNT nRecords, + COUNT * nErrorCode) { FcbCalcRec(lpXfcb); @@ -430,7 +435,7 @@ BOOL FcbRandomBlockWrite(xfcb FAR * lpXfcb, COUNT nRecords, COUNT * nErrorCode) } BOOL FcbRandomIO(xfcb FAR * lpXfcb, COUNT * nErrorCode, - BOOL (*FcbFunc)(xfcb FAR *, COUNT *)) + BOOL(*FcbFunc) (xfcb FAR *, COUNT *)) { UWORD uwCurrentBlock; UBYTE ucCurrentRecord; @@ -443,7 +448,7 @@ BOOL FcbRandomIO(xfcb FAR * lpXfcb, COUNT * nErrorCode, uwCurrentBlock = lpFcb->fcb_cublock; ucCurrentRecord = lpFcb->fcb_curec; - (*FcbFunc)(lpXfcb, nErrorCode); + (*FcbFunc) (lpXfcb, nErrorCode); lpFcb->fcb_cublock = uwCurrentBlock; lpFcb->fcb_curec = ucCurrentRecord; @@ -466,7 +471,7 @@ BOOL FcbCreate(xfcb FAR * lpXfcb) sft_idx = DosCreatSft(PriPathName, 0); if (sft_idx < 0) - return FALSE; + return FALSE; sftp = idx_to_sft(sft_idx); sftp->sft_mode |= SFT_MFCB; @@ -476,7 +481,8 @@ BOOL FcbCreate(xfcb FAR * lpXfcb) lpFcb->fcb_sftno = sft_idx; lpFcb->fcb_curec = 0; lpFcb->fcb_recsiz = (dhp ? 0 : 128); - if (!dhp) lpFcb->fcb_drive = FcbDrive; + if (!dhp) + lpFcb->fcb_drive = FcbDrive; lpFcb->fcb_fsize = 0; lpFcb->fcb_date = dos_getdate(); lpFcb->fcb_time = dos_gettime(); @@ -509,9 +515,9 @@ STATIC fcb FAR *CommonFcbInit(xfcb FAR * lpExtFcb, BYTE * pszBuffer, void FcbNameInit(fcb FAR * lpFcb, BYTE * szBuffer, COUNT * pCurDrive) { - BYTE loc_szBuffer[2+FNAME_SIZE+1+FEXT_SIZE+1]; /* 'A:' + '.' + '\0' */ + BYTE loc_szBuffer[2 + FNAME_SIZE + 1 + FEXT_SIZE + 1]; /* 'A:' + '.' + '\0' */ BYTE *pszBuffer = loc_szBuffer; - + /* Build a traditional DOS file name */ if (lpFcb->fcb_drive != 0) { @@ -540,30 +546,30 @@ BOOL FcbOpen(xfcb FAR * lpXfcb) sft_idx = DosOpenSft(PriPathName, O_RDWR); if (sft_idx < 0) - return FALSE; - + return FALSE; + sftp = idx_to_sft(sft_idx); sftp->sft_mode |= SFT_MFCB; - + /* check for a device */ lpFcb->fcb_curec = 0; lpFcb->fcb_rndm = 0; lpFcb->fcb_sftno = sft_idx; dhp = IsDevice(PriPathName); - if (dhp ) + if (dhp) { - lpFcb->fcb_recsiz = 0; - lpFcb->fcb_fsize = 0; - lpFcb->fcb_date = dos_getdate(); - lpFcb->fcb_time = dos_gettime(); + lpFcb->fcb_recsiz = 0; + lpFcb->fcb_fsize = 0; + lpFcb->fcb_date = dos_getdate(); + lpFcb->fcb_time = dos_gettime(); } else { - lpFcb->fcb_drive = FcbDrive; - lpFcb->fcb_recsiz = 128; - lpFcb->fcb_fsize = sftp->sft_size; - lpFcb->fcb_date = sftp->sft_date; - lpFcb->fcb_time = sftp->sft_time; + lpFcb->fcb_drive = FcbDrive; + lpFcb->fcb_recsiz = 128; + lpFcb->fcb_fsize = sftp->sft_size; + lpFcb->fcb_date = sftp->sft_date; + lpFcb->fcb_time = sftp->sft_time; } return TRUE; } @@ -586,7 +592,9 @@ BOOL FcbDelete(xfcb FAR * lpXfcb) dmatch Dmatch; dta = (BYTE FAR *) & Dmatch; - if (DosFindFirst(D_ALL, SecPathName[1] == ':' ? &SecPathName[2] : SecPathName) != SUCCESS) + if (DosFindFirst + (D_ALL, + SecPathName[1] == ':' ? &SecPathName[2] : SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; @@ -625,7 +633,9 @@ BOOL FcbRename(xfcb FAR * lpXfcb) dmatch Dmatch; dta = (BYTE FAR *) & Dmatch; - if (DosFindFirst(D_ALL, SecPathName[1] == ':' ? &SecPathName[2] : SecPathName) != SUCCESS) + if (DosFindFirst + (D_ALL, + SecPathName[1] == ':' ? &SecPathName[2] : SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; @@ -634,8 +644,7 @@ BOOL FcbRename(xfcb FAR * lpXfcb) do { fcb LocalFcb; - BYTE *pToName, - *pszFrom; + BYTE *pToName, *pszFrom; BYTE FAR *pFromPattern; COUNT nIndex; @@ -718,7 +727,7 @@ BOOL FcbClose(xfcb FAR * lpXfcb) lpFcb = ExtFcbToFcb(lpXfcb); /* An already closed FCB can be closed again without error */ - if (lpFcb->fcb_sftno == (BYTE)0xff) + if (lpFcb->fcb_sftno == (BYTE) 0xff) return TRUE; /* Get the SFT block that contains the SFT */ @@ -730,8 +739,9 @@ BOOL FcbClose(xfcb FAR * lpXfcb) if (!(s->sft_flags & SFT_FSHARED)) dos_setfsize(s->sft_status, lpFcb->fcb_fsize); DosSetFtimeSft(lpFcb->fcb_sftno, lpFcb->fcb_date, lpFcb->fcb_time); - if (DosCloseSft(lpFcb->fcb_sftno) == SUCCESS) { - lpFcb->fcb_sftno = (BYTE)0xff; + if (DosCloseSft(lpFcb->fcb_sftno) == SUCCESS) + { + lpFcb->fcb_sftno = (BYTE) 0xff; return TRUE; } return FALSE; @@ -743,7 +753,7 @@ VOID FcbCloseAll() COUNT idx = 0; sft FAR *sftp; - for (idx = 0; (sftp = idx_to_sft(idx)) != (sft FAR *) -1; idx++) + for (idx = 0; (sftp = idx_to_sft(idx)) != (sft FAR *) - 1; idx++) if ((sftp->sft_mode & SFT_MFCB) && sftp->sft_psp == cu_psp) DosCloseSft(idx); } @@ -764,8 +774,8 @@ BOOL FcbFindFirst(xfcb FAR * lpXfcb) if (lpXfcb->xfcb_flag == 0xff) { wAttr = lpXfcb->xfcb_attrib; - fmemcpy(lpDir, lpXfcb, 7); - lpDir += 7; + fmemcpy(lpDir, lpXfcb, 7); + lpDir += 7; } else wAttr = D_ALL; @@ -776,10 +786,10 @@ BOOL FcbFindFirst(xfcb FAR * lpXfcb) return FALSE; } - *lpDir++ = FcbDrive; + *lpDir++ = FcbDrive; fmemcpy(lpDir, &SearchDir, sizeof(struct dirent)); - lpFcb->fcb_dirclst = (UWORD)Dmatch.dm_dircluster; + lpFcb->fcb_dirclst = (UWORD) Dmatch.dm_dircluster; lpFcb->fcb_strtclst = Dmatch.dm_entry; /* @@ -787,7 +797,7 @@ BOOL FcbFindFirst(xfcb FAR * lpXfcb) The First byte is the current directory count and the second seems to be the attribute byte. */ - lpFcb->fcb_sftno = Dmatch.dm_drive; /* MSD seems to save this @ fcb_date.*/ + lpFcb->fcb_sftno = Dmatch.dm_drive; /* MSD seems to save this @ fcb_date. */ #if 0 lpFcb->fcb_cublock = Dmatch.dm_entry; lpFcb->fcb_cublock *= 0x100; @@ -838,10 +848,10 @@ BOOL FcbFindNext(xfcb FAR * lpXfcb) return FALSE; } - *lpDir++ = FcbDrive; + *lpDir++ = FcbDrive; fmemcpy((struct dirent FAR *)lpDir, &SearchDir, sizeof(struct dirent)); - lpFcb->fcb_dirclst = (UWORD)Dmatch.dm_dircluster; + lpFcb->fcb_dirclst = (UWORD) Dmatch.dm_dircluster; lpFcb->fcb_strtclst = Dmatch.dm_entry; lpFcb->fcb_sftno = Dmatch.dm_drive; @@ -917,5 +927,3 @@ BOOL FcbFindNext(xfcb FAR * lpXfcb) * Rev 1.0 02 Jul 1995 8:06:06 patv * Initial revision. */ - - diff --git a/kernel/globals.h b/kernel/globals.h index 6baac31..2829106 100644 --- a/kernel/globals.h +++ b/kernel/globals.h @@ -29,11 +29,11 @@ #ifdef VERSION_STRINGS #ifdef MAIN -static BYTE *Globals_hRcsId = "$Id$"; +static BYTE *Globals_hRcsId = + "$Id$"; #endif #endif - #include "device.h" #include "mcb.h" #include "pcb.h" @@ -86,7 +86,7 @@ static BYTE *Globals_hRcsId = "$Id$"; /* */ /* Defaults and limits - System wide */ #define PARSE_MAX MAX_CDSPATH /* maximum # of bytes in path */ -#define NAMEMAX PARSE_MAX /* Maximum path for CDS */ +#define NAMEMAX PARSE_MAX /* Maximum path for CDS */ /* internal error from failure or aborted operation */ #define ERROR -1 @@ -127,8 +127,6 @@ static BYTE *Globals_hRcsId = "$Id$"; #define DSKWRITEINT26 3 #define DSKREADINT25 4 - - /* FAT cluster special flags */ #define FREE 0x000 @@ -162,86 +160,79 @@ FAR clk_dev, /* Clock device driver */ FAR prn_dev, /* Generic printer device driver */ FAR aux_dev, /* Generic aux device driver */ FAR blk_dev; /* Block device (Disk) driver */ -extern UWORD - ram_top; /* How much ram in Kbytes */ -extern COUNT * - error_tos, /* error stack */ +extern UWORD ram_top; /* How much ram in Kbytes */ +extern COUNT *error_tos, /* error stack */ disk_api_tos, /* API handler stack - disk fns */ char_api_tos; /* API handler stack - char fns */ -extern BYTE - FAR _InitTextStart; /* first available byte of ram */ -extern BYTE - FAR _HMATextAvailable, /* first byte of available CODE area */ +extern BYTE FAR _InitTextStart; /* first available byte of ram */ +extern BYTE FAR _HMATextAvailable, /* first byte of available CODE area */ FAR _HMATextStart[], /* first byte of HMAable CODE area */ FAR _HMATextEnd[]; /* and the last byte of it */ -extern - BYTE DosLoadedInHMA; /* if InitHMA has moved DOS up */ - +extern +BYTE DosLoadedInHMA; /* if InitHMA has moved DOS up */ + extern struct ClockRecord ClkRecord; /* */ /* Global variables */ /* */ -GLOBAL BYTE - os_major, /* major version number */ +GLOBAL BYTE os_major, /* major version number */ os_minor, /* minor version number */ - rev_number /* minor version number */ #ifdef MAIN -= REV_NUMBER, + = REV_NUMBER, #else , #endif - version_flags /* minor version number */ #ifdef MAIN -= 0; + = 0; #else - ; + ; #endif #ifdef DEBUG GLOBAL WORD bDumpRegs #ifdef MAIN -= FALSE; + = FALSE; #else ; #endif GLOBAL WORD bDumpRdWrParms #ifdef MAIN -= FALSE; + = FALSE; #else ; #endif #endif -#if 0 /* defined in MAIN.C now to save low memory */ +#if 0 /* defined in MAIN.C now to save low memory */ -GLOBAL BYTE copyright[] = +GLOBAL BYTE copyright[] = "(C) Copyright 1995-2001 Pasquale J. Villani and The FreeDOS Project.\n" "All Rights Reserved. This is free software and comes with ABSOLUTELY NO\n" "WARRANTY; you can redistribute it and/or modify it under the terms of the\n" "GNU General Public License as published by the Free Software Foundation;\n" "either version 2, or (at your option) any later version.\n"; - + #endif GLOBAL BYTE os_release[] #ifdef MAIN #if 0 -= "DOS-C version %d.%d Beta %d [FreeDOS Release] (Build %d).\n" + = "DOS-C version %d.%d Beta %d [FreeDOS Release] (Build %d).\n" #endif -= "FreeDOS kernel version " KERNEL_VERSION_STRING \ - " (Build " KERNEL_BUILD_STRING ") [" __DATE__ " " __TIME__ "]\n" + = "FreeDOS kernel version " KERNEL_VERSION_STRING + " (Build " KERNEL_BUILD_STRING ") [" __DATE__ " " __TIME__ "]\n" #if 0 -"For technical information and description of the DOS-C operating system\n\ + "For technical information and description of the DOS-C operating system\n\ consult \"FreeDOS Kernel\" by Pat Villani, published by Miller\n\ Freeman Publishing, Lawrence KS, USA (ISBN 0-87930-436-7).\n\ \n" #endif #endif -; + ; /* Globally referenced variables - WARNING: ORDER IS DEFINED IN */ /* KERNAL.ASM AND MUST NOT BE CHANGED. DO NOT CHANGE ORDER BECAUSE THEY */ @@ -251,109 +242,81 @@ Freeman Publishing, Lawrence KS, USA (ISBN 0-87930-436-7).\n\ extern UWORD NetBios; extern BYTE *net_name; extern BYTE net_set_count; -extern BYTE NetDelay, - NetRetry; +extern BYTE NetDelay, NetRetry; -extern UWORD - first_mcb, /* Start of user memory */ - UMB_top, - umb_start, - uppermem_root; /* Start of umb chain ? */ +extern UWORD first_mcb, /* Start of user memory */ + UMB_top, umb_start, uppermem_root; /* Start of umb chain ? */ extern struct dpb FAR *DPBp; /* First drive Parameter Block */ -extern sfttbl - FAR * sfthead; /* System File Table head */ +extern sfttbl FAR * sfthead; /* System File Table head */ extern struct dhdr FAR *clock, /* CLOCK$ device */ FAR * syscon; /* console device */ -extern WORD - maxbksize; /* Number of Drives in system */ +extern WORD maxbksize; /* Number of Drives in system */ extern struct buffer FAR *firstbuf; /* head of buffers linked list */ -extern cdstbl - FAR * CDSp; /* Current Directory Structure */ +extern cdstbl FAR * CDSp; /* Current Directory Structure */ extern struct cds FAR *current_ldt; extern LONG current_filepos; /* current file position */ -extern sfttbl - FAR * FCBp; /* FCB table pointer */ -extern WORD - nprotfcb; /* number of protected fcbs */ -extern UBYTE - nblkdev, /* number of block devices */ +extern sfttbl FAR * FCBp; /* FCB table pointer */ +extern WORD nprotfcb; /* number of protected fcbs */ +extern UBYTE nblkdev, /* number of block devices */ lastdrive, /* value of last drive */ uppermem_link, /* UMB Link flag */ - PrinterEcho; /* Printer Echo Flag */ + PrinterEcho; /* Printer Echo Flag */ + +extern UWORD LoL_nbuffers; /* Number of buffers */ -extern UWORD - LoL_nbuffers; /* Number of buffers */ - extern struct dhdr nul_dev; -extern UBYTE - mem_access_mode; /* memory allocation scheme */ -extern BYTE - ErrorMode, /* Critical error flag */ +extern UBYTE mem_access_mode; /* memory allocation scheme */ +extern BYTE ErrorMode, /* Critical error flag */ InDOS, /* In DOS critical section */ OpenMode, /* File Open Attributes */ SAttr, /* Attrib Mask for Dir Search */ - dosidle_flag, - Server_Call, - CritErrLocus, - CritErrAction, - CritErrClass, - VgaSet, - njoined; /* number of joined devices */ + dosidle_flag, Server_Call, CritErrLocus, CritErrAction, CritErrClass, VgaSet, njoined; /* number of joined devices */ extern UWORD Int21AX; extern COUNT CritErrCode; -extern BYTE FAR * CritErrDev; +extern BYTE FAR *CritErrDev; extern struct dirent SearchDir; -extern struct -{ +extern struct { COUNT nDrive; BYTE szName[FNAME_SIZE + 1]; BYTE szExt[FEXT_SIZE + 1]; -} -FcbSearchBuffer; +} FcbSearchBuffer; -extern struct /* Path name parsing buffer */ +extern struct /* Path name parsing buffer */ { BYTE _PriPathName[128]; -} -_PriPathBuffer; +} _PriPathBuffer; -extern struct -{ +extern struct { BYTE _fname[FNAME_SIZE]; - BYTE _fext[FEXT_SIZE+1]; /* space for 0 */ -} -szNames; + BYTE _fext[FEXT_SIZE + 1]; /* space for 0 */ +} szNames; #define PriPathName _PriPathBuffer._PriPathName #define szDirName TempCDS.cdsCurrentPath #define szFileName szNames._fname #define szFileExt szNames._fext -extern struct /* Alternate path name parsing buffer */ +extern struct /* Alternate path name parsing buffer */ { BYTE _SecPathName[128]; -} -_SecPathBuffer; +} _SecPathBuffer; #define SecPathName _SecPathBuffer._SecPathName -extern UWORD - wAttr; +extern UWORD wAttr; -extern BYTE - default_drive; /* default drive for dos */ +extern BYTE default_drive; /* default drive for dos */ -extern BYTE - TempBuffer[], /* Temporary general purpose buffer */ +extern BYTE TempBuffer[], /* Temporary general purpose buffer */ FAR internal_data[], /* sda areas */ FAR swap_always[], /* " " */ FAR swap_indos[], /* " " */ @@ -361,57 +324,46 @@ extern BYTE break_flg, /* true if break was detected */ break_ena, /* break enabled flag */ FAR * dta; /* Disk transfer area (kludge) */ -extern seg - cu_psp; /* current psp segment */ -extern iregs - FAR * user_r; /* User registers for int 21h call */ +extern seg cu_psp; /* current psp segment */ +extern iregs FAR * user_r; /* User registers for int 21h call */ extern struct dirent /* Temporary directory entry */ DirEntBuffer; extern request /* I/O Request packets */ - CharReqHdr, - IoReqHdr, - MediaReqHdr; + CharReqHdr, IoReqHdr, MediaReqHdr; -extern fcb - FAR * lpFcb; /* Pointer to users fcb */ +extern fcb FAR * lpFcb; /* Pointer to users fcb */ -extern sft - FAR * lpCurSft; +extern sft FAR * lpCurSft; -extern BYTE - verify_ena, /* verify enabled flag */ +extern BYTE verify_ena, /* verify enabled flag */ switchar, /* switch char */ return_mode, /* Process termination rets */ return_code; /* " " " */ -extern BYTE - BootDrive, /* Drive we came up from */ +extern BYTE BootDrive, /* Drive we came up from */ scr_pos; /* screen position for bs, ht, etc */ /*extern WORD - NumFloppies; !!*/ /* How many floppies we have */ + NumFloppies; !!*//* How many floppies we have */ -extern keyboard - kb_buf; +extern keyboard kb_buf; extern struct cds TempCDS; /* start of uncontrolled variables */ -GLOBAL seg - RootPsp; /* Root process -- do not abort */ +GLOBAL seg RootPsp; /* Root process -- do not abort */ /* don't know what it should do, but its no longer in use TE GLOBAL struct f_node *pDirFileNode; -*/ +*/ #ifdef DEBUG GLOBAL iregs error_regs; /* registers for dump */ -GLOBAL WORD - dump_regs; /* dump registers of bad call */ +GLOBAL WORD dump_regs; /* dump registers of bad call */ #endif @@ -421,7 +373,7 @@ GLOBAL UWORD f_nodes_cnt; /* number of allocated f_nodes */ /*!! GLOBAL iregs FAR * ustackp, /* user stack */ -/*!! FAR * kstackp; */ /* kernel stack */ +/*!! FAR * kstackp; *//* kernel stack */ /* */ /* Function prototypes - automatically generated */ @@ -430,21 +382,18 @@ GLOBAL UWORD f_nodes_cnt; /* number of allocated f_nodes */ /* Process related functions - not under automatic generation. */ /* Typically, these are in ".asm" files. */ -VOID -FAR ASMCFUNC cpm_entry(VOID) +VOID FAR ASMCFUNC cpm_entry(VOID) /*INRPT FAR handle_break(VOID) */ ; -VOID -enable(VOID), -disable(VOID); +VOID enable(VOID), disable(VOID); COUNT -ASMCFUNC CriticalError( - COUNT nFlag, COUNT nDrive, COUNT nError, struct dhdr FAR * lpDevice); + ASMCFUNC CriticalError(COUNT nFlag, COUNT nDrive, COUNT nError, + struct dhdr FAR * lpDevice); #ifdef PROTO VOID FAR ASMCFUNC CharMapSrvc(VOID); VOID FAR ASMCFUNC set_stack(VOID); VOID FAR ASMCFUNC restore_stack(VOID); -WORD ASMCFUNC execrh(request FAR *, struct dhdr FAR *); +WORD ASMCFUNC execrh(request FAR *, struct dhdr FAR *); VOID exit(COUNT); /*VOID INRPT FAR handle_break(VOID); */ VOID ASMCFUNC tmark(VOID); @@ -515,14 +464,13 @@ VOID fputbyte(); /*#define is_leap_year(y) ((y) & 3 ? 0 : (y) % 100 ? 1 : (y) % 400 ? 0 : 1) */ /* ^Break handling */ -void ASMCFUNC spawn_int23(void); /* procsupt.asm */ +void ASMCFUNC spawn_int23(void); /* procsupt.asm */ int control_break(void); /* break.c */ void handle_break(void); /* break.c */ - GLOBAL BYTE ReturnAnyDosVersionExpected; -GLOBAL COUNT UnusedRetVal; /* put unused errors here (to save stack space) */ +GLOBAL COUNT UnusedRetVal; /* put unused errors here (to save stack space) */ /* * Log: globals.h,v diff --git a/kernel/init-dat.h b/kernel/init-dat.h index ea6e79d..e51d1df 100644 --- a/kernel/init-dat.h +++ b/kernel/init-dat.h @@ -1,31 +1,27 @@ /* Included by initialisation functions */ #if _MSC_VER != 0 - extern __segment DosDataSeg;/* serves for all references to the DOS DATA segment - necessary for MSC+our funny linking model - */ +extern __segment DosDataSeg; /* serves for all references to the DOS DATA segment + necessary for MSC+our funny linking model + */ - extern __segment DosTextSeg; +extern __segment DosTextSeg; - #define DOSFAR __based(DosDataSeg) - #define DOSTEXTFAR __based(DosTextSeg) +#define DOSFAR __based(DosDataSeg) +#define DOSTEXTFAR __based(DosTextSeg) #elif defined(__TURBOC__) - #define DOSFAR FAR - #define DOSTEXTFAR FAR +#define DOSFAR FAR +#define DOSTEXTFAR FAR #elif defined(__WATCOMC__) - #define DOSFAR FAR - #define DOSTEXTFAR FAR +#define DOSFAR FAR +#define DOSTEXTFAR FAR #else - #pragma error("unknown compiler - please adjust") - this should simply not compile !! -#endif - - - -extern BYTE DOSFAR version_flags; /* minor version number */ - +#pragma error("unknown compiler - please adjust") +this should simply not compile ! ! +#endif +extern BYTE DOSFAR version_flags; /* minor version number */ diff --git a/kernel/init-mod.h b/kernel/init-mod.h index c1c1e29..de6e7cf 100644 --- a/kernel/init-mod.h +++ b/kernel/init-mod.h @@ -22,8 +22,7 @@ #include "buffer.h" #include "KConfig.h" -extern struct _KernelConfig InitKernelConfig; - +extern struct _KernelConfig InitKernelConfig; /* * The null macro `INIT' can be used to allow the reader to differentiate @@ -58,7 +57,7 @@ COUNT ASMCFUNC strlen(REG BYTE * s); /*inithma.c*/ extern BYTE DosLoadedInHMA; -extern fmemcmp(BYTE far *s1, BYTE FAR *s2, unsigned len); +extern fmemcmp(BYTE far * s1, BYTE FAR * s2, unsigned len); #define setvec(n, isr) (void)(*(VOID (FAR * FAR *)())(MK_FP(0,4 * (n))) = (isr)) @@ -75,46 +74,43 @@ extern fmemcmp(BYTE far *s1, BYTE FAR *s2, unsigned len); #define MAX_HARD_DRIVE 8 #define NDEV 26 /* up to Z: */ - - /* Start of configuration variables */ -struct config -{ - BYTE cfgBuffers; - /* number of buffers in the system */ - UBYTE cfgFiles; - /* number of available files */ - UBYTE cfgFcbs; - /* number of available FCBs */ - UBYTE cfgProtFcbs; - /* number of protected FCBs */ - BYTE cfgInit[NAMEMAX]; - /* init of command.com */ - BYTE cfgInitTail[NAMEMAX]; - /* command.com's tail */ - UBYTE cfgLastdrive; - /* last drive */ - BYTE cfgStacks; - /* number of stacks */ - UWORD cfgStackSize; - /* stacks size for each stack */ - /* COUNTRY= - In Pass #1 these information is collected and in PostConfig() - the NLS package is loaded into memory. - -- 2000/06/11 ska*/ - WORD cfgCSYS_cntry; - /* country ID to be loaded */ - WORD cfgCSYS_cp; - /* requested codepage; NLS_DEFAULT if default */ - BYTE cfgCSYS_fnam[NAMEMAX]; - /* filename of COUNTRY= */ - WORD cfgCSYS_memory; - /* number of bytes required for the NLS pkg; - 0 if none */ - VOID FAR *cfgCSYS_data; - /* where the loaded data is for PostConfig() */ - UBYTE cfgP_0_startmode; - /* load command.com high or not */ +struct config { + BYTE cfgBuffers; + /* number of buffers in the system */ + UBYTE cfgFiles; + /* number of available files */ + UBYTE cfgFcbs; + /* number of available FCBs */ + UBYTE cfgProtFcbs; + /* number of protected FCBs */ + BYTE cfgInit[NAMEMAX]; + /* init of command.com */ + BYTE cfgInitTail[NAMEMAX]; + /* command.com's tail */ + UBYTE cfgLastdrive; + /* last drive */ + BYTE cfgStacks; + /* number of stacks */ + UWORD cfgStackSize; + /* stacks size for each stack */ + /* COUNTRY= + In Pass #1 these information is collected and in PostConfig() + the NLS package is loaded into memory. + -- 2000/06/11 ska */ + WORD cfgCSYS_cntry; + /* country ID to be loaded */ + WORD cfgCSYS_cp; + /* requested codepage; NLS_DEFAULT if default */ + BYTE cfgCSYS_fnam[NAMEMAX]; + /* filename of COUNTRY= */ + WORD cfgCSYS_memory; + /* number of bytes required for the NLS pkg; + 0 if none */ + VOID FAR *cfgCSYS_data; + /* where the loaded data is for PostConfig() */ + UBYTE cfgP_0_startmode; + /* load command.com high or not */ }; extern struct config Config; @@ -134,7 +130,7 @@ INIT VOID mcb_init(UCOUNT seg, UWORD size); INIT VOID strcat(REG BYTE * d, REG BYTE * s); INIT BYTE FAR *KernelAlloc(WORD nBytes); INIT COUNT ASMCFUNC Umb_Test(void); -INIT COUNT ASMCFUNC UMB_get_largest(UCOUNT *seg, UCOUNT *size); +INIT COUNT ASMCFUNC UMB_get_largest(UCOUNT * seg, UCOUNT * size); INIT BYTE *GetStringArg(BYTE * pLine, BYTE * pszString); /* diskinit.c */ @@ -152,27 +148,28 @@ UWORD init_oem(void); /* intr.asm */ -void ASMCFUNC init_call_intr(int nr, iregs *rp); -UCOUNT ASMCFUNC read(int fd, void *buf, UCOUNT count); +void ASMCFUNC init_call_intr(int nr, iregs * rp); +UCOUNT ASMCFUNC read(int fd, void *buf, UCOUNT count); int ASMCFUNC open(const char *pathname, int flags); int ASMCFUNC close(int fd); int ASMCFUNC dup2(int oldfd, int newfd); -int ASMCFUNC allocmem(UWORD size, seg *segp); +int ASMCFUNC allocmem(UWORD size, seg * segp); INIT VOID ASMCFUNC init_PSPInit(seg psp_seg); INIT VOID ASMCFUNC init_PSPSet(seg psp_seg); INIT COUNT ASMCFUNC init_DosExec(COUNT mode, exec_blk * ep, BYTE * lp); INIT VOID ASMCFUNC keycheck(VOID); /* irqstack.asm */ -VOID ASMCFUNC init_stacks(VOID FAR * stack_base, COUNT nStacks, WORD stackSize); +VOID ASMCFUNC init_stacks(VOID FAR * stack_base, COUNT nStacks, + WORD stackSize); /* inthndlr.c */ -VOID far ASMCFUNC int21_entry(iregs UserRegs); -VOID ASMCFUNC int21_service(iregs far * r); +VOID far ASMCFUNC int21_entry(iregs UserRegs); +VOID ASMCFUNC int21_service(iregs far * r); VOID FAR ASMCFUNC int0_handler(void); VOID FAR ASMCFUNC int6_handler(void); VOID FAR ASMCFUNC empty_handler(void); -VOID far ASMCFUNC got_cbreak(void); /* procsupt.asm */ +VOID far ASMCFUNC got_cbreak(void); /* procsupt.asm */ VOID far ASMCFUNC int20_handler(iregs UserRegs); VOID far ASMCFUNC int21_handler(iregs UserRegs); VOID FAR ASMCFUNC int22_handler(void); @@ -187,21 +184,22 @@ VOID FAR ASMCFUNC int2f_handler(void); /* main.c */ INIT VOID ASMCFUNC FreeDOSmain(void); -INIT BOOL init_device(struct dhdr FAR * dhp, BYTE FAR * cmdLine, COUNT mode, COUNT top); +INIT BOOL init_device(struct dhdr FAR * dhp, BYTE FAR * cmdLine, + COUNT mode, COUNT top); INIT VOID init_fatal(BYTE * err_msg); /* prf.c */ -WORD init_printf(CONST BYTE * fmt,...); +WORD init_printf(CONST BYTE * fmt, ...); WORD init_sprintf(BYTE * buff, CONST BYTE * fmt, ...); void MoveKernel(unsigned NewKernelSegment); -extern WORD HMAFree; /* first byte in HMA not yet used */ +extern WORD HMAFree; /* first byte in HMA not yet used */ extern unsigned CurrentKernelSegment; #if defined(WATCOM) && 0 -ULONG FAR ASMCFUNC MULULUS(ULONG mul1, UWORD mul2); /* MULtiply ULong by UShort */ -ULONG FAR ASMCFUNC MULULUL(ULONG mul1, ULONG mul2); /* MULtiply ULong by ULong */ -ULONG FAR ASMCFUNC DIVULUS(ULONG mul1, UWORD mul2); /* DIVide ULong by UShort */ -ULONG FAR ASMCFUNC DIVMODULUS(ULONG mul1, UWORD mul2,UWORD *rem); /* DIVide ULong by UShort */ +ULONG FAR ASMCFUNC MULULUS(ULONG mul1, UWORD mul2); /* MULtiply ULong by UShort */ +ULONG FAR ASMCFUNC MULULUL(ULONG mul1, ULONG mul2); /* MULtiply ULong by ULong */ +ULONG FAR ASMCFUNC DIVULUS(ULONG mul1, UWORD mul2); /* DIVide ULong by UShort */ +ULONG FAR ASMCFUNC DIVMODULUS(ULONG mul1, UWORD mul2, UWORD * rem); /* DIVide ULong by UShort */ #endif diff --git a/kernel/initdisk.c b/kernel/initdisk.c index 358ff26..f2bf01d 100644 --- a/kernel/initdisk.c +++ b/kernel/initdisk.c @@ -29,12 +29,13 @@ #include "init-dat.h" #include "dyndata.h" #ifdef VERSION_STRINGS -static BYTE *dskRcsId = "$Id$"; +static BYTE *dskRcsId = + "$Id$"; #endif /* data shared between DSK.C and INITDISK.C -*/ +*/ extern UBYTE DOSFAR DiskTransferBuffer[1 * SEC_SIZE]; extern COUNT DOSFAR nUnits; @@ -157,22 +158,20 @@ extern UWORD DOSFAR LBA_WRITE_VERIFY; /* #define DEBUG */ -#define _BETA_ /* messages for initial phase only */ - +#define _BETA_ /* messages for initial phase only */ #if defined(DEBUG) - #define DebugPrintf(x) printf x +#define DebugPrintf(x) printf x #else - #define DebugPrintf(x) +#define DebugPrintf(x) #endif #if defined(_BETA_) - #define BetaPrintf(x) printf x +#define BetaPrintf(x) printf x #else - #define BetaPrintf(x) +#define BetaPrintf(x) #endif - #define LBA_to_CHS init_LBA_to_CHS /* @@ -184,25 +183,24 @@ extern UWORD DOSFAR LBA_WRITE_VERIFY; #define SCAN_EXTENDED 0x02 #define SCAN_PRIMARY2 0x03 - #define FAT12 0x01 #define FAT16SMALL 0x04 #define EXTENDED 0x05 #define FAT16LARGE 0x06 -#define FAT32 0x0b /* FAT32 partition that ends before the 8.4 */ +#define FAT32 0x0b /* FAT32 partition that ends before the 8.4 */ /* GB boundary */ -#define FAT32_LBA 0x0c /* FAT32 partition that ends after the 8.4GB */ +#define FAT32_LBA 0x0c /* FAT32 partition that ends after the 8.4GB */ /* boundary. LBA is needed to access this. */ -#define FAT16_LBA 0x0e /* like 0x06, but it is supposed to end past */ +#define FAT16_LBA 0x0e /* like 0x06, but it is supposed to end past */ /* the 8.4GB boundary */ -#define FAT12_LBA 0xff /* fake FAT12 LBA entry for internal use */ -#define EXTENDED_LBA 0x0f /* like 0x05, but it is supposed to end past */ +#define FAT12_LBA 0xff /* fake FAT12 LBA entry for internal use */ +#define EXTENDED_LBA 0x0f /* like 0x05, but it is supposed to end past */ /* Let's play it safe and do not allow partitions with clusters above * * or equal to 0xff0/0xfff0/0xffffff0 to be created * * the problem with fff0-fff6 is that they might be interpreted as BAD * * even though the standard BAD value is ...ff7 */ - + #define FAT12MAX (FAT_MAGIC-7) #define FAT16MAX (FAT_MAGIC16-7) #define FAT32MAX (FAT_MAGIC32-7) @@ -228,48 +226,46 @@ extern UWORD DOSFAR LBA_WRITE_VERIFY; (parttyp) == FAT16_LBA) #endif -#define MSDOS_EXT_SIGN 0x29 /* extended boot sector signature */ +#define MSDOS_EXT_SIGN 0x29 /* extended boot sector signature */ #define MSDOS_FAT12_SIGN "FAT12 " /* FAT12 filesystem signature */ #define MSDOS_FAT16_SIGN "FAT16 " /* FAT16 filesystem signature */ #define MSDOS_FAT32_SIGN "FAT32 " /* FAT32 filesystem signature */ /* local - returned and used for BIOS interface INT 13, AH=48*/ struct _bios_LBA_disk_parameterS { - UWORD size; - UWORD information; - ULONG cylinders; - ULONG heads; - ULONG sectors; + UWORD size; + UWORD information; + ULONG cylinders; + ULONG heads; + ULONG sectors; - ULONG totalSect; - ULONG totalSectHigh; - UWORD BytesPerSector; - - ULONG eddparameters; - } ; + ULONG totalSect; + ULONG totalSectHigh; + UWORD BytesPerSector; + ULONG eddparameters; +}; /* physical characteristics of a drive */ -struct DriveParamS -{ - UBYTE driveno; /* = 0x8x */ - BITS LBA_supported:1; /* set, if INT13 extensions enabled */ - BITS WriteVerifySupported:1; /* */ - ULONG total_sectors; +struct DriveParamS { + UBYTE driveno; /* = 0x8x */ + BITS LBA_supported:1; /* set, if INT13 extensions enabled */ + BITS WriteVerifySupported:1; /* */ + ULONG total_sectors; - struct CHS chs; /* for normal INT 13 */ + struct CHS chs; /* for normal INT 13 */ }; -struct PartTableEntry /* INTERNAL representation of partition table entry */ - { - UBYTE Bootable; - UBYTE FileSystem; - struct CHS Begin; - struct CHS End; - ULONG RelSect; - ULONG NumSect; - }; +struct PartTableEntry /* INTERNAL representation of partition table entry */ +{ + UBYTE Bootable; + UBYTE FileSystem; + struct CHS Begin; + struct CHS End; + ULONG RelSect; + ULONG NumSect; +}; /* internal global data @@ -277,23 +273,23 @@ struct PartTableEntry /* INTERNAL representation of partition table entry */ COUNT init_readdasd(UBYTE drive) { - static iregs regs; - - regs.a.b.h = 0x15; - regs.d.b.l = drive; - init_call_intr(0x13,®s); - if ((regs.flags & 1) == 0) switch (regs.a.b.h) + static iregs regs; + + regs.a.b.h = 0x15; + regs.d.b.l = drive; + init_call_intr(0x13, ®s); + if ((regs.flags & 1) == 0) + switch (regs.a.b.h) { - case 2: - return DF_CHANGELINE; - case 3: - return DF_FIXED; + case 2: + return DF_CHANGELINE; + case 3: + return DF_FIXED; } - return 0; + return 0; } -typedef struct -{ +typedef struct { UWORD bpb_nbyte; /* Bytes per Sector */ UBYTE bpb_nsector; /* Sectors per Allocation Unit */ UWORD bpb_nreserved; /* # Reserved Sectors */ @@ -307,42 +303,42 @@ typedef struct } floppy_bpb; floppy_bpb floppy_bpbs[5] = { -/* copied from Brian Reifsnyder's FORMAT, bpb.h */ - {SEC_SIZE,2,1,2,112, 720,0xfd,2, 9,2}, /* FD360 5.25 DS */ - {SEC_SIZE,1,1,2,224,2400,0xf9,7,15,2}, /* FD1200 5.25 HD */ - {SEC_SIZE,2,1,2,112,1440,0xf9,3, 9,2}, /* FD720 3.5 LD */ - {SEC_SIZE,1,1,2,224,2880,0xf0,9,18,2}, /* FD1440 3.5 HD */ - {SEC_SIZE,2,1,2,240,5760,0xf0,9,36,2} /* FD2880 3.5 ED */ +/* copied from Brian Reifsnyder's FORMAT, bpb.h */ + {SEC_SIZE, 2, 1, 2, 112, 720, 0xfd, 2, 9, 2}, /* FD360 5.25 DS */ + {SEC_SIZE, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2}, /* FD1200 5.25 HD */ + {SEC_SIZE, 2, 1, 2, 112, 1440, 0xf9, 3, 9, 2}, /* FD720 3.5 LD */ + {SEC_SIZE, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2}, /* FD1440 3.5 HD */ + {SEC_SIZE, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2} /* FD2880 3.5 ED */ }; -COUNT init_getdriveparm(UBYTE drive, bpb FAR *pbpbarray) +COUNT init_getdriveparm(UBYTE drive, bpb FAR * pbpbarray) { - static iregs regs; - REG UBYTE type; - - if (drive & 0x80) - return 5; - regs.a.b.h = 0x08; - regs.d.b.l = drive; - init_call_intr(0x13,®s); - type = regs.b.b.l - 1; - if (regs.flags & 1) - type = 0; /* return 320-360 for XTs */ - else if (type > 6) - type = 8; /* any odd ball drives get 8&7=0: the 320-360 table */ - else if (type == 5) - type = 4; /* 5 and 4 are both 2.88 MB */ - - fmemcpy(pbpbarray, &floppy_bpbs[type & 7], sizeof(floppy_bpb)); + static iregs regs; + REG UBYTE type; - if (type == 3) - return 7; /* 1.44 MB */ + if (drive & 0x80) + return 5; + regs.a.b.h = 0x08; + regs.d.b.l = drive; + init_call_intr(0x13, ®s); + type = regs.b.b.l - 1; + if (regs.flags & 1) + type = 0; /* return 320-360 for XTs */ + else if (type > 6) + type = 8; /* any odd ball drives get 8&7=0: the 320-360 table */ + else if (type == 5) + type = 4; /* 5 and 4 are both 2.88 MB */ - if (type == 4) - return 9; /* 2.88 almost forgot this one*/ - - /* 0=320-360kB, 1=1.2MB, 2=720kB, 8=any odd ball drives */ - return type; + fmemcpy(pbpbarray, &floppy_bpbs[type & 7], sizeof(floppy_bpb)); + + if (type == 3) + return 7; /* 1.44 MB */ + + if (type == 4) + return 9; /* 2.88 almost forgot this one */ + + /* 0=320-360kB, 1=1.2MB, 2=720kB, 8=any odd ball drives */ + return type; } /* @@ -350,21 +346,22 @@ COUNT init_getdriveparm(UBYTE drive, bpb FAR *pbpbarray) copied and pasted from dsk.c! */ -void init_LBA_to_CHS(struct CHS *chs, ULONG LBA_address, struct DriveParamS *driveparam) +void init_LBA_to_CHS(struct CHS *chs, ULONG LBA_address, + struct DriveParamS *driveparam) { - chs->Sector = LBA_address% driveparam->chs.Sector + 1; + chs->Sector = LBA_address % driveparam->chs.Sector + 1; - LBA_address /= driveparam->chs.Sector; + LBA_address /= driveparam->chs.Sector; - chs->Head = LBA_address % driveparam->chs.Head; - chs->Cylinder = LBA_address / driveparam->chs.Head; + chs->Head = LBA_address % driveparam->chs.Head; + chs->Cylinder = LBA_address / driveparam->chs.Head; } -void printCHS(char *title,struct CHS *chs) +void printCHS(char *title, struct CHS *chs) { - printf("%s",title); - printf("%4lu-%u-%u",chs->Cylinder, chs->Head, chs->Sector); -} + printf("%s", title); + printf("%4lu-%u-%u", chs->Cylinder, chs->Head, chs->Sector); +} /* reason for this modules existence: @@ -384,759 +381,751 @@ void printCHS(char *title,struct CHS *chs) Portions copyright 1992, 1993 Remy Card and 1991 Linus Torvalds */ -VOID CalculateFATData(ddt FAR *pddt, ULONG NumSectors, UBYTE FileSystem) +VOID CalculateFATData(ddt FAR * pddt, ULONG NumSectors, UBYTE FileSystem) { - ULONG fatlength, maxclust, clust; - UBYTE maxclustsize; - ULONG fatdata; - - bpb FAR *defbpb = &pddt->ddt_defbpb; - - /* FAT related items */ - defbpb->bpb_nfat = 2; - defbpb->bpb_ndirent = (FileSystem == FAT32 || FileSystem == FAT32_LBA) ? 0 : 512; - /* normal value of number of entries in root dir */ - defbpb->bpb_nreserved = (FileSystem == FAT32 || FileSystem == FAT32_LBA) ? 0x20 : 1; + ULONG fatlength, maxclust, clust; + UBYTE maxclustsize; + ULONG fatdata; - fatdata = NumSectors - cdiv (defbpb->bpb_ndirent * DIRENT_SIZE, defbpb->bpb_nbyte) - - defbpb->bpb_nreserved; - maxclustsize = 128; -#ifdef DEBUG - if (FileSystem!=FAT12) - DebugPrintf(( "%ld sectors for FAT+data, starting with %d sectors/cluster\n", - fatdata, defbpb->bpb_nsector )); -#endif - switch(FileSystem) { + bpb FAR *defbpb = &pddt->ddt_defbpb; + + /* FAT related items */ + defbpb->bpb_nfat = 2; + defbpb->bpb_ndirent = (FileSystem == FAT32 + || FileSystem == FAT32_LBA) ? 0 : 512; + /* normal value of number of entries in root dir */ + defbpb->bpb_nreserved = (FileSystem == FAT32 + || FileSystem == FAT32_LBA) ? 0x20 : 1; + + fatdata = + NumSectors - cdiv(defbpb->bpb_ndirent * DIRENT_SIZE, + defbpb->bpb_nbyte) - defbpb->bpb_nreserved; + maxclustsize = 128; +#ifdef DEBUG + if (FileSystem != FAT12) + DebugPrintf(("%ld sectors for FAT+data, starting with %d sectors/cluster\n", fatdata, defbpb->bpb_nsector)); +#endif + switch (FileSystem) + { case FAT12: - case FAT12_LBA: - /* in DOS, FAT12 defaults to 4096kb (8 sector) - clusters. */ - defbpb->bpb_nsector = 8; - /* Force maximal fatdata=32696 sectors since with our only possible sector - size (512 bytes) this is the maximum for 4k clusters. - #clus*secperclus+#fats*fatlength= 4077 * 8 + 2 * 12 = 32640. - max FAT12 size for FreeDOS = 16,728,064 bytes */ - if (fatdata > 32640) - fatdata = 32640; - /* The factor 2 below avoids cut-off errors for nr_fats == 1. - * The "defbpb->bpb_nfat*3" is for the reserved first two FAT entries */ - clust = 2*((ULONG) fatdata * defbpb->bpb_nbyte + defbpb->bpb_nfat*3) / - (2*(ULONG) defbpb->bpb_nsector * defbpb->bpb_nbyte + defbpb->bpb_nfat*3); - fatlength = cdiv (((clust+2) * 3 + 1) >> 1, defbpb->bpb_nbyte); + case FAT12_LBA: + /* in DOS, FAT12 defaults to 4096kb (8 sector) - clusters. */ + defbpb->bpb_nsector = 8; + /* Force maximal fatdata=32696 sectors since with our only possible sector + size (512 bytes) this is the maximum for 4k clusters. + #clus*secperclus+#fats*fatlength= 4077 * 8 + 2 * 12 = 32640. + max FAT12 size for FreeDOS = 16,728,064 bytes */ + if (fatdata > 32640) + fatdata = 32640; + /* The factor 2 below avoids cut-off errors for nr_fats == 1. + * The "defbpb->bpb_nfat*3" is for the reserved first two FAT entries */ + clust = + 2 * ((ULONG) fatdata * defbpb->bpb_nbyte + + defbpb->bpb_nfat * 3) / (2 * (ULONG) defbpb->bpb_nsector * + defbpb->bpb_nbyte + + defbpb->bpb_nfat * 3); + fatlength = cdiv(((clust + 2) * 3 + 1) >> 1, defbpb->bpb_nbyte); + /* Need to recalculate number of clusters, since the unused parts of the + * FATS and data area together could make up space for an additional, + * not really present cluster. */ + clust = + (fatdata - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector; + maxclust = (fatlength * 2 * defbpb->bpb_nbyte) / 3; + if (maxclust > FAT12MAX) + maxclust = FAT12MAX; + DebugPrintf(("FAT12: #clu=%lu, fatlen=%lu, maxclu=%lu, limit=%u\n", + clust, fatlength, maxclust, FATMAX12)); + if (clust > maxclust - 2) + { + clust = maxclust - 2; + DebugPrintf(("FAT12: too many clusters: setting to maxclu-2\n")); + } + defbpb->bpb_nfsect = fatlength; + fmemcpy(pddt->ddt_fstype, MSDOS_FAT12_SIGN, 8); + break; + + case FAT16SMALL: + case FAT16LARGE: + case FAT16_LBA: + /* FAT16: start at 4 sectors per cluster */ + defbpb->bpb_nsector = 4; + /* Force maximal fatdata=8387584 sectors (NumSectors=8387617) + since with our only possible sectorsize (512 bytes) this is the + maximum we can address with 64k clusters + #clus*secperclus+#fats*fatlength=65517 * 128 + 2 * 256=8386688. + max FAT16 size for FreeDOS = 4,293,984,256 bytes = 4GiB-983,040 */ + if (fatdata > 8386688ul) + fatdata = 8386688ul; + do + { + DebugPrintf(("Trying with %d sectors/cluster:\n", + defbpb->bpb_nsector)); + + clust = + ((ULONG) fatdata * defbpb->bpb_nbyte + + defbpb->bpb_nfat * 4) / ((ULONG) defbpb->bpb_nsector * + defbpb->bpb_nbyte + + defbpb->bpb_nfat * 2); + fatlength = cdiv((clust + 2) * 2, defbpb->bpb_nbyte); /* Need to recalculate number of clusters, since the unused parts of the * FATS and data area together could make up space for an additional, * not really present cluster. */ - clust = (fatdata - defbpb->bpb_nfat*fatlength)/defbpb->bpb_nsector; - maxclust = (fatlength * 2 * defbpb->bpb_nbyte) / 3; - if (maxclust > FAT12MAX) - maxclust = FAT12MAX; - DebugPrintf(( "FAT12: #clu=%lu, fatlen=%lu, maxclu=%lu, limit=%u\n", - clust, fatlength, maxclust, FATMAX12 )); - if (clust > maxclust-2) { - clust = maxclust-2; - DebugPrintf(( "FAT12: too many clusters: setting to maxclu-2\n" )); + clust = + (fatdata - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector; + maxclust = (fatlength * defbpb->bpb_nbyte) / 2; + if (maxclust > FAT16MAX) + maxclust = FAT16MAX; + DebugPrintf(("FAT16: #clu=%lu, fatlen=%lu, maxclu=%lu, limit=%u\n", + clust, fatlength, maxclust, FAT_MAGIC16)); + if (clust > maxclust - 2) + { + DebugPrintf(("FAT16: too many clusters\n")); + clust = 0; } - defbpb->bpb_nfsect = fatlength; - fmemcpy(pddt->ddt_fstype, MSDOS_FAT12_SIGN, 8); - break; - - case FAT16SMALL: - case FAT16LARGE: - case FAT16_LBA: - /* FAT16: start at 4 sectors per cluster */ - defbpb->bpb_nsector = 4; - /* Force maximal fatdata=8387584 sectors (NumSectors=8387617) - since with our only possible sectorsize (512 bytes) this is the - maximum we can address with 64k clusters - #clus*secperclus+#fats*fatlength=65517 * 128 + 2 * 256=8386688. - max FAT16 size for FreeDOS = 4,293,984,256 bytes = 4GiB-983,040 */ - if (fatdata > 8386688ul) - fatdata = 8386688ul; - do { - DebugPrintf(( "Trying with %d sectors/cluster:\n", defbpb->bpb_nsector )); - - clust = ((ULONG) fatdata *defbpb->bpb_nbyte + defbpb->bpb_nfat*4) / - ((ULONG) defbpb->bpb_nsector * defbpb->bpb_nbyte + defbpb->bpb_nfat*2); - fatlength = cdiv ((clust+2) * 2, defbpb->bpb_nbyte); - /* Need to recalculate number of clusters, since the unused parts of the - * FATS and data area together could make up space for an additional, - * not really present cluster. */ - clust = (fatdata - defbpb->bpb_nfat*fatlength)/defbpb->bpb_nsector; - maxclust = (fatlength * defbpb->bpb_nbyte) / 2; - if (maxclust > FAT16MAX) - maxclust = FAT16MAX; - DebugPrintf(( "FAT16: #clu=%lu, fatlen=%lu, maxclu=%lu, limit=%u\n", - clust, fatlength, maxclust, FAT_MAGIC16 )); - if (clust > maxclust-2) { - DebugPrintf(( "FAT16: too many clusters\n" )); - clust = 0; - } else if (clust <= FAT_MAGIC) { - /* The <= 4086 avoids that the filesystem will be misdetected as having a - * 12 bit FAT. */ - DebugPrintf(("FAT16: would be misdetected as FAT12\n")); - clust = 0; - } - if (clust) - break; - defbpb->bpb_nsector <<= 1; + else if (clust <= FAT_MAGIC) + { + /* The <= 4086 avoids that the filesystem will be misdetected as having a + * 12 bit FAT. */ + DebugPrintf(("FAT16: would be misdetected as FAT12\n")); + clust = 0; } - while (defbpb->bpb_nsector && defbpb->bpb_nsector <= maxclustsize); - defbpb->bpb_nfsect = fatlength; - fmemcpy(pddt->ddt_fstype, MSDOS_FAT16_SIGN, 8); - break; - + if (clust) + break; + defbpb->bpb_nsector <<= 1; + } + while (defbpb->bpb_nsector && defbpb->bpb_nsector <= maxclustsize); + defbpb->bpb_nfsect = fatlength; + fmemcpy(pddt->ddt_fstype, MSDOS_FAT16_SIGN, 8); + break; + #ifdef WITHFAT32 case FAT32: case FAT32_LBA: - /* For FAT32, use 4k clusters on sufficiently large file systems, - * otherwise 1 sector per cluster. This is also what M$'s format - * command does for FAT32. */ - defbpb->bpb_nsector = (NumSectors >= 512*1024ul ? 8 : 1); - do { - /* simple calculation - no long long available */ - clust = (ULONG)fatdata / defbpb->bpb_nsector; - /* this calculation below yields a smaller value - the above is non-optimal - but should not be dangerous */ - /* clust = ((long long) fatdata *defbpb->bpb_nbyte + defbpb->bpb_nfat*8) / - ((int) defbpb->bpb_nsector * defbpb->bpb_nbyte + defbpb->bpb_nfat*4); */ - fatlength = cdiv ((clust+2) * 4, defbpb->bpb_nbyte); - /* Need to recalculate number of clusters, since the unused parts of the - * FATS and data area together could make up space for an additional, - * not really present cluster. */ - clust = (fatdata - defbpb->bpb_nfat*fatlength)/defbpb->bpb_nsector; - maxclust = (fatlength * defbpb->bpb_nbyte) / 4; - if (maxclust > FAT32MAX) - maxclust = FAT32MAX; - DebugPrintf(( "FAT32: #clu=%u, fatlen=%u, maxclu=%u, limit=%u\n", - clust, fatlength, maxclust, FATMAX32 )); - if (clust > maxclust-2) - { - clust = 0; - DebugPrintf(( "FAT32: too many clusters\n" )); - } - if (clust) - break; - defbpb->bpb_nsector <<= 1; - } while (defbpb->bpb_nsector && defbpb->bpb_nsector <= maxclustsize); - defbpb->bpb_nfsect = 0; - defbpb->bpb_xnfsect = fatlength; - /* set up additional FAT32 fields */ - defbpb->bpb_xflags = 0; - defbpb->bpb_xfsversion = 0; - defbpb->bpb_xrootclst = 2; - defbpb->bpb_xfsinfosec = 1; - defbpb->bpb_xbackupsec = 6; - fmemcpy(pddt->ddt_fstype, MSDOS_FAT32_SIGN, 8); - break; + /* For FAT32, use 4k clusters on sufficiently large file systems, + * otherwise 1 sector per cluster. This is also what M$'s format + * command does for FAT32. */ + defbpb->bpb_nsector = (NumSectors >= 512 * 1024ul ? 8 : 1); + do + { + /* simple calculation - no long long available */ + clust = (ULONG) fatdata / defbpb->bpb_nsector; + /* this calculation below yields a smaller value - the above is non-optimal + but should not be dangerous */ + /* clust = ((long long) fatdata *defbpb->bpb_nbyte + defbpb->bpb_nfat*8) / + ((int) defbpb->bpb_nsector * defbpb->bpb_nbyte + defbpb->bpb_nfat*4); */ + fatlength = cdiv((clust + 2) * 4, defbpb->bpb_nbyte); + /* Need to recalculate number of clusters, since the unused parts of the + * FATS and data area together could make up space for an additional, + * not really present cluster. */ + clust = + (fatdata - defbpb->bpb_nfat * fatlength) / defbpb->bpb_nsector; + maxclust = (fatlength * defbpb->bpb_nbyte) / 4; + if (maxclust > FAT32MAX) + maxclust = FAT32MAX; + DebugPrintf(("FAT32: #clu=%u, fatlen=%u, maxclu=%u, limit=%u\n", + clust, fatlength, maxclust, FATMAX32)); + if (clust > maxclust - 2) + { + clust = 0; + DebugPrintf(("FAT32: too many clusters\n")); + } + if (clust) + break; + defbpb->bpb_nsector <<= 1; + } + while (defbpb->bpb_nsector && defbpb->bpb_nsector <= maxclustsize); + defbpb->bpb_nfsect = 0; + defbpb->bpb_xnfsect = fatlength; + /* set up additional FAT32 fields */ + defbpb->bpb_xflags = 0; + defbpb->bpb_xfsversion = 0; + defbpb->bpb_xrootclst = 2; + defbpb->bpb_xfsinfosec = 1; + defbpb->bpb_xbackupsec = 6; + fmemcpy(pddt->ddt_fstype, MSDOS_FAT32_SIGN, 8); + break; #endif - } - pddt->ddt_fstype[8] = '\0'; + } + pddt->ddt_fstype[8] = '\0'; } - void DosDefinePartition(struct DriveParamS *driveParam, - ULONG StartSector, struct PartTableEntry *pEntry, int extendedPartNo, int PrimaryNum) + ULONG StartSector, struct PartTableEntry *pEntry, + int extendedPartNo, int PrimaryNum) { - ddt FAR *pddt = DynAlloc("ddt", 1, sizeof(ddt)); - struct CHS chs; + ddt FAR *pddt = DynAlloc("ddt", 1, sizeof(ddt)); + struct CHS chs; - if ( nUnits >= NDEV) - { - printf("more Partitions detected then possible, max = %d\n", NDEV); - return; /* we are done */ - } + if (nUnits >= NDEV) + { + printf("more Partitions detected then possible, max = %d\n", NDEV); + return; /* we are done */ + } - pddt->ddt_driveno = driveParam->driveno; - pddt->ddt_logdriveno = nUnits; - pddt->ddt_LBASupported = driveParam->LBA_supported; - /* Turn of LBA if not forced and the partition is within 1023 cyls and of the right type */ - /* the FileSystem type was internally converted to LBA_xxxx if a non-LBA partition - above cylinder 1023 was found */ - if (!InitKernelConfig.ForceLBA && !IsLBAPartition(pEntry->FileSystem)) - pddt->ddt_LBASupported = FALSE; - pddt->ddt_WriteVerifySupported = driveParam->WriteVerifySupported; - pddt->ddt_ncyl = driveParam->chs.Cylinder; - - if (pddt->ddt_LBASupported) - DebugPrintf(("LBA enabled for drive %c:\n", 'A'+nUnits)); - - pddt->ddt_offset = StartSector; + pddt->ddt_driveno = driveParam->driveno; + pddt->ddt_logdriveno = nUnits; + pddt->ddt_LBASupported = driveParam->LBA_supported; + /* Turn of LBA if not forced and the partition is within 1023 cyls and of the right type */ + /* the FileSystem type was internally converted to LBA_xxxx if a non-LBA partition + above cylinder 1023 was found */ + if (!InitKernelConfig.ForceLBA && !IsLBAPartition(pEntry->FileSystem)) + pddt->ddt_LBASupported = FALSE; + pddt->ddt_WriteVerifySupported = driveParam->WriteVerifySupported; + pddt->ddt_ncyl = driveParam->chs.Cylinder; - pddt->ddt_defbpb.bpb_nbyte = SEC_SIZE; - pddt->ddt_defbpb.bpb_mdesc = 0xf8; - pddt->ddt_defbpb.bpb_nheads = driveParam->chs.Head; - pddt->ddt_defbpb.bpb_nsecs = driveParam->chs.Sector; - pddt->ddt_defbpb.bpb_nsize = 0; - pddt->ddt_defbpb.bpb_hidden = pEntry->RelSect; - if (pEntry->NumSect > 0xffff) - pddt->ddt_defbpb.bpb_huge = pEntry->NumSect; - else - pddt->ddt_defbpb.bpb_nsize = (UWORD)(pEntry->NumSect); + if (pddt->ddt_LBASupported) + DebugPrintf(("LBA enabled for drive %c:\n", 'A' + nUnits)); - /* sectors per cluster, sectors per FAT etc. */ - CalculateFATData(pddt, pEntry->NumSect, pEntry->FileSystem); - - pddt->ddt_serialno = 0x12345678l; - /* drive inaccessible until bldbpb successful */ - pddt->ddt_descflags = init_readdasd(pddt->ddt_driveno) | DF_NOACCESS; - pddt->ddt_type = 5; - fmemcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb)); + pddt->ddt_offset = StartSector; - /* Alain whishes to keep this in later versions, too - Tom likes this too, so he made it configurable by SYS CONFIG ... - */ + pddt->ddt_defbpb.bpb_nbyte = SEC_SIZE; + pddt->ddt_defbpb.bpb_mdesc = 0xf8; + pddt->ddt_defbpb.bpb_nheads = driveParam->chs.Head; + pddt->ddt_defbpb.bpb_nsecs = driveParam->chs.Sector; + pddt->ddt_defbpb.bpb_nsize = 0; + pddt->ddt_defbpb.bpb_hidden = pEntry->RelSect; + if (pEntry->NumSect > 0xffff) + pddt->ddt_defbpb.bpb_huge = pEntry->NumSect; + else + pddt->ddt_defbpb.bpb_nsize = (UWORD) (pEntry->NumSect); - if (InitKernelConfig.InitDiskShowDriveAssignment) - { - LBA_to_CHS(&chs,StartSector,driveParam); - - printf("%c: HD%d", - 'A' + nUnits, - (driveParam->driveno & 0x7f)+1); - - if (extendedPartNo) printf(" Ext:%d", extendedPartNo); - else printf(" Pri:%d", PrimaryNum + 1); - - printCHS(" CHS= ",&chs); - - printf(" start = %5luMB,size =%5lu", - StartSector/2048,pEntry->NumSect/2048); - - printf("\n"); - } + /* sectors per cluster, sectors per FAT etc. */ + CalculateFATData(pddt, pEntry->NumSect, pEntry->FileSystem); - - - nUnits++; + pddt->ddt_serialno = 0x12345678l; + /* drive inaccessible until bldbpb successful */ + pddt->ddt_descflags = init_readdasd(pddt->ddt_driveno) | DF_NOACCESS; + pddt->ddt_type = 5; + fmemcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb)); + + /* Alain whishes to keep this in later versions, too + Tom likes this too, so he made it configurable by SYS CONFIG ... + */ + + if (InitKernelConfig.InitDiskShowDriveAssignment) + { + LBA_to_CHS(&chs, StartSector, driveParam); + + printf("%c: HD%d", 'A' + nUnits, (driveParam->driveno & 0x7f) + 1); + + if (extendedPartNo) + printf(" Ext:%d", extendedPartNo); + else + printf(" Pri:%d", PrimaryNum + 1); + + printCHS(" CHS= ", &chs); + + printf(" start = %5luMB,size =%5lu", + StartSector / 2048, pEntry->NumSect / 2048); + + printf("\n"); + } + + nUnits++; } - /* Get the parameters of the hard disk */ -int LBA_Get_Drive_Parameters(int drive,struct DriveParamS *driveParam) +int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam) { - iregs regs; - - struct _bios_LBA_disk_parameterS lba_bios_parameters; + iregs regs; - if (driveParam->driveno) - return driveParam->driveno; + struct _bios_LBA_disk_parameterS lba_bios_parameters; - driveParam->LBA_supported = FALSE; + if (driveParam->driveno) + return driveParam->driveno; + driveParam->LBA_supported = FALSE; - drive |= 0x80; + drive |= 0x80; - /* for tests - disable LBA support, - even if exists */ - if (!InitKernelConfig.GlobalEnableLBAsupport) - { - goto StandardBios; - } - /* check for LBA support */ - regs.b.x = 0x55aa; - regs.a.b.h = 0x41; - regs.d.b.l = drive; + /* for tests - disable LBA support, + even if exists */ + if (!InitKernelConfig.GlobalEnableLBAsupport) + { + goto StandardBios; + } + /* check for LBA support */ + regs.b.x = 0x55aa; + regs.a.b.h = 0x41; + regs.d.b.l = drive; - init_call_intr(0x13,®s); + init_call_intr(0x13, ®s); + if (regs.b.x != 0xaa55 || (regs.flags & 0x01)) + { + goto StandardBios; + } - if (regs.b.x != 0xaa55 || (regs.flags & 0x01) ) - { - goto StandardBios; - } + /* by ralph : + if DAP cannot be used, don't use + LBA + */ + if ((regs.c.x & 1) == 0) + { + goto StandardBios; + } - /* by ralph : - if DAP cannot be used, don't use - LBA - */ - if ((regs.c.x & 1) == 0) - { - goto StandardBios; - } - - + /* drive supports LBA addressing */ - /* drive supports LBA addressing */ + /* version 1.0, 2.0 have different verify */ + if (regs.a.x < 0x2100) + LBA_WRITE_VERIFY = 0x4301; - /* version 1.0, 2.0 have different verify */ - if (regs.a.x < 0x2100) - LBA_WRITE_VERIFY = 0x4301; + memset(&lba_bios_parameters, 0, sizeof(lba_bios_parameters)); + lba_bios_parameters.size = sizeof(lba_bios_parameters); + regs.si = FP_OFF(&lba_bios_parameters); + regs.ds = FP_SEG(&lba_bios_parameters); + regs.a.b.h = 0x48; + regs.d.b.l = drive; + init_call_intr(0x13, ®s); - memset(&lba_bios_parameters, 0, sizeof(lba_bios_parameters)); - lba_bios_parameters.size = sizeof(lba_bios_parameters); + if (regs.flags & 0x01) + { + goto StandardBios; + } + /* verify maximum settings, we can't handle more */ - regs.si = FP_OFF(&lba_bios_parameters); - regs.ds = FP_SEG(&lba_bios_parameters); - regs.a.b.h = 0x48; - regs.d.b.l = drive; - init_call_intr(0x13,®s); + if (lba_bios_parameters.heads > 0xffff || + lba_bios_parameters.sectors > 0xffff || + lba_bios_parameters.totalSectHigh != 0) + { + printf("Drive is too large to handle, using only 1'st 8 GB\n" + " drive %02x heads %lu sectors %lu , total=0x%lx-%08lx\n", + drive, + (ULONG) lba_bios_parameters.heads, + (ULONG) lba_bios_parameters.sectors, + (ULONG) lba_bios_parameters.totalSect, + (ULONG) lba_bios_parameters.totalSectHigh); + goto StandardBios; + } - if (regs.flags & 0x01) - { - goto StandardBios; - } + if (lba_bios_parameters.information & 8) + { + driveParam->WriteVerifySupported = 1; + } + else + driveParam->WriteVerifySupported = 0; - /* verify maximum settings, we can't handle more */ + driveParam->total_sectors = lba_bios_parameters.totalSect; - if (lba_bios_parameters.heads > 0xffff || - lba_bios_parameters.sectors > 0xffff || - lba_bios_parameters.totalSectHigh != 0 ) - { - printf("Drive is too large to handle, using only 1'st 8 GB\n" - " drive %02x heads %lu sectors %lu , total=0x%lx-%08lx\n", + /* if we arrive here, success */ + driveParam->LBA_supported = TRUE; + +StandardBios: /* old way to get parameters */ + + regs.a.b.h = 0x08; + regs.d.b.l = drive; + + init_call_intr(0x13, ®s); + + if (regs.flags & 0x01) + goto ErrorReturn; + + driveParam->chs.Head = (regs.d.x >> 8) + 1; + driveParam->chs.Sector = (regs.c.x & 0x3f); + driveParam->chs.Cylinder = (regs.c.x >> 8) | ((regs.c.x & 0xc0) << 2); + + if (!driveParam->LBA_supported) + { + driveParam->total_sectors = + min(driveParam->chs.Cylinder, 1023) + * driveParam->chs.Head * driveParam->chs.Sector; + } + + driveParam->driveno = drive; + + DebugPrintf(("drive parameters %02x - %04lu-%u-%u", drive, - (ULONG)lba_bios_parameters.heads, - (ULONG)lba_bios_parameters.sectors, - (ULONG)lba_bios_parameters.totalSect, - (ULONG)lba_bios_parameters.totalSectHigh); - - goto StandardBios; - } - - if (lba_bios_parameters.information & 8) - { - driveParam->WriteVerifySupported = 1; - } - else - driveParam->WriteVerifySupported = 0; - - driveParam->total_sectors = lba_bios_parameters.totalSect; - - /* if we arrive here, success */ - driveParam->LBA_supported = TRUE; - - - - -StandardBios: /* old way to get parameters */ - - - regs.a.b.h = 0x08; - regs.d.b.l = drive; - - init_call_intr(0x13,®s); - - - if (regs.flags & 0x01) - goto ErrorReturn; - - - driveParam->chs.Head = (regs.d.x >> 8) + 1; - driveParam->chs.Sector = (regs.c.x & 0x3f); - driveParam->chs.Cylinder = (regs.c.x >> 8) | ((regs.c.x & 0xc0) << 2); - - - if (!driveParam->LBA_supported) - { - driveParam->total_sectors = - min(driveParam->chs.Cylinder,1023) - * driveParam->chs.Head - * driveParam->chs.Sector; - } - - driveParam->driveno = drive; - - DebugPrintf(("drive parameters %02x - %04lu-%u-%u", - drive, - driveParam->chs.Cylinder, - driveParam->chs.Head, - driveParam->chs.Sector)); - DebugPrintf((" total size %luMB\n\n",driveParam->total_sectors/2048)); - - + driveParam->chs.Cylinder, + driveParam->chs.Head, driveParam->chs.Sector)); + DebugPrintf((" total size %luMB\n\n", driveParam->total_sectors / 2048)); ErrorReturn: - return driveParam->driveno; + return driveParam->driveno; } - - - /* converts physical into logical representation of partition entry */ -ConvPartTableEntryToIntern(struct PartTableEntry *pEntry, UBYTE FAR * pDisk) +ConvPartTableEntryToIntern(struct PartTableEntry * pEntry, + UBYTE FAR * pDisk) { - int i; + int i; - if (pDisk[0x1fe] != 0x55 || pDisk[0x1ff] != 0xaa) - { - memset(pEntry,0, 4 * sizeof(struct PartTableEntry)); + if (pDisk[0x1fe] != 0x55 || pDisk[0x1ff] != 0xaa) + { + memset(pEntry, 0, 4 * sizeof(struct PartTableEntry)); - return FALSE; - } + return FALSE; + } - pDisk += 0x1be; + pDisk += 0x1be; - for (i = 0; i < 4; i++,pDisk += 16,pEntry++) - { + for (i = 0; i < 4; i++, pDisk += 16, pEntry++) + { - pEntry->Bootable = *(UBYTE FAR*)(pDisk+0); - pEntry->FileSystem = *(UBYTE FAR*)(pDisk+4); + pEntry->Bootable = *(UBYTE FAR *) (pDisk + 0); + pEntry->FileSystem = *(UBYTE FAR *) (pDisk + 4); - pEntry->Begin.Head = *(UBYTE FAR*)(pDisk+1); - pEntry->Begin.Sector = *(UBYTE FAR*)(pDisk+2) & 0x3f; - pEntry->Begin.Cylinder = *(UBYTE FAR*)(pDisk+3) + - ((UWORD) (0xc0 & *(UBYTE FAR*)(pDisk+2)) << 2); + pEntry->Begin.Head = *(UBYTE FAR *) (pDisk + 1); + pEntry->Begin.Sector = *(UBYTE FAR *) (pDisk + 2) & 0x3f; + pEntry->Begin.Cylinder = *(UBYTE FAR *) (pDisk + 3) + + ((UWORD) (0xc0 & *(UBYTE FAR *) (pDisk + 2)) << 2); - pEntry->End.Head = *(UBYTE FAR*)(pDisk+5); - pEntry->End.Sector = *(UBYTE FAR*)(pDisk+6) & 0x3f; - pEntry->End.Cylinder = *(UBYTE FAR*)(pDisk+7) + - ((UWORD) (0xc0 & *(UBYTE FAR*)(pDisk+6)) << 2); + pEntry->End.Head = *(UBYTE FAR *) (pDisk + 5); + pEntry->End.Sector = *(UBYTE FAR *) (pDisk + 6) & 0x3f; + pEntry->End.Cylinder = *(UBYTE FAR *) (pDisk + 7) + + ((UWORD) (0xc0 & *(UBYTE FAR *) (pDisk + 6)) << 2); - - pEntry->RelSect = *(ULONG FAR*)(pDisk+8); - pEntry->NumSect = *(ULONG FAR*)(pDisk+12); - } - return TRUE; + pEntry->RelSect = *(ULONG FAR *) (pDisk + 8); + pEntry->NumSect = *(ULONG FAR *) (pDisk + 12); + } + return TRUE; } -ScanForPrimaryPartitions(struct DriveParamS *driveParam,int scan_type, - struct PartTableEntry *pEntry, ULONG startSector, - int partitionsToIgnore, int extendedPartNo - ) +ScanForPrimaryPartitions(struct DriveParamS * driveParam, int scan_type, + struct PartTableEntry * pEntry, ULONG startSector, + int partitionsToIgnore, int extendedPartNo) { - int i; - struct CHS chs,end; - ULONG partitionStart; - char partitionName[12]; - + int i; + struct CHS chs, end; + ULONG partitionStart; + char partitionName[12]; - for (i = 0; i < 4; i++,pEntry++) - { - if (pEntry->FileSystem == 0) - continue; + for (i = 0; i < 4; i++, pEntry++) + { + if (pEntry->FileSystem == 0) + continue; - if (partitionsToIgnore & (1 << i)) - continue; + if (partitionsToIgnore & (1 << i)) + continue; + if (IsExtPartition(pEntry->FileSystem)) + continue; - if (IsExtPartition(pEntry->FileSystem)) - continue; + if (scan_type == SCAN_PRIMARYBOOT && !pEntry->Bootable) + continue; - if (scan_type == SCAN_PRIMARYBOOT && !pEntry->Bootable) - continue; + partitionStart = startSector + pEntry->RelSect; + if (!IsFATPartition(pEntry->FileSystem)) + { + continue; + } - partitionStart = startSector + pEntry->RelSect; + if (extendedPartNo) + sprintf(partitionName, "Ext:%d", extendedPartNo); + else + sprintf(partitionName, "Pri:%d", i + 1); - if (!IsFATPartition(pEntry->FileSystem)) - { - continue; - } + /* + some sanity checks, that partition + structure is OK + */ + LBA_to_CHS(&chs, partitionStart, driveParam); + LBA_to_CHS(&end, partitionStart + pEntry->NumSect - 1, driveParam); + /* some FDISK's enter for partitions + > 8 GB cyl = 1023, other (cyl&1023) + */ - - if (extendedPartNo) sprintf(partitionName, "Ext:%d", extendedPartNo); - else sprintf(partitionName, "Pri:%d",i+1); + if (((chs.Cylinder & 0x3ff) != pEntry->Begin.Cylinder && + 1023 != pEntry->Begin.Cylinder) || + chs.Head != pEntry->Begin.Head || + chs.Sector != pEntry->Begin.Sector) + { + printf("WARNING: using suspect partition %s FS %02x:", + partitionName, pEntry->FileSystem); + printCHS(" with calculated values ", &chs); + printCHS(" instead of ", &pEntry->Begin); + printf("\n"); + fmemcpy(&pEntry->Begin, &chs, sizeof(struct CHS)); + } - /* - some sanity checks, that partition - structure is OK - */ - LBA_to_CHS(&chs, partitionStart,driveParam); - LBA_to_CHS(&end, partitionStart+pEntry->NumSect-1,driveParam); + if (((end.Cylinder & 0x3ff) != pEntry->End.Cylinder && + 1023 != pEntry->End.Cylinder) || + end.Head != pEntry->End.Head || end.Sector != pEntry->End.Sector) + { + if (pEntry->NumSect == 0) + { + printf("Not using partition %s with 0 sectors\n", partitionName); + continue; + } + printf("WARNING: using suspect partition %s FS %02x:", + partitionName, pEntry->FileSystem); - /* some FDISK's enter for partitions - > 8 GB cyl = 1023, other (cyl&1023) - */ + printCHS(" with calculated values ", &end); + printCHS(" instead of ", &pEntry->End); + printf("\n"); + fmemcpy(&pEntry->End, &end, sizeof(struct CHS)); - if ( ((chs.Cylinder & 0x3ff) != pEntry->Begin.Cylinder && - 1023 != pEntry->Begin.Cylinder ) || - chs.Head != pEntry->Begin.Head || - chs.Sector != pEntry->Begin.Sector ) - { - printf("WARNING: using suspect partition %s FS %02x:", - partitionName, pEntry->FileSystem); - printCHS(" with calculated values ",&chs); - printCHS(" instead of ",&pEntry->Begin); - printf("\n"); - fmemcpy(&pEntry->Begin, &chs, sizeof(struct CHS)); + } - } + if (chs.Cylinder > 1023 || end.Cylinder > 1023) + { + if (!driveParam->LBA_supported) + { + printf + ("can't use LBA partition without LBA support - part %s FS %02x", + partitionName, pEntry->FileSystem); - if (((end.Cylinder & 0x3ff) != pEntry->End.Cylinder && - 1023 != pEntry->End.Cylinder ) || - end.Head != pEntry->End.Head || - end.Sector != pEntry->End.Sector ) - { - if (pEntry->NumSect == 0) - { - printf("Not using partition %s with 0 sectors\n", partitionName); - continue; - } - - printf("WARNING: using suspect partition %s FS %02x:", - partitionName, pEntry->FileSystem); + printCHS(" start ", &chs); + printCHS(", end ", &end); + printf("\n"); - printCHS(" with calculated values ",&end); - printCHS(" instead of ",&pEntry->End); - printf("\n"); - fmemcpy(&pEntry->End, &end, sizeof(struct CHS)); + continue; + } - } + if (!InitKernelConfig.ForceLBA + && !IsLBAPartition(pEntry->FileSystem)) + { + printf + ("WARNING: Partition ID does not suggest LBA - part %s FS %02x.\n" + "Please run FDISK to correct this - using LBA to access partition.\n", + partitionName, pEntry->FileSystem); + printCHS(" start ", &chs); + printCHS(", end ", &end); + printf("\n"); + pEntry->FileSystem = (pEntry->FileSystem == FAT12 ? FAT12_LBA : + pEntry->FileSystem == FAT32 ? FAT32_LBA : + /* pEntry->FileSystem == FAT16 ? */ + FAT16_LBA); + } - if (chs.Cylinder > 1023 || end.Cylinder > 1023) - { - - if (!driveParam->LBA_supported) - { - printf("can't use LBA partition without LBA support - part %s FS %02x", - partitionName, pEntry->FileSystem); - - printCHS(" start ",&chs); - printCHS(", end ", &end); - printf("\n"); - - continue; - } - - if (!InitKernelConfig.ForceLBA && !IsLBAPartition(pEntry->FileSystem)) - { - printf("WARNING: Partition ID does not suggest LBA - part %s FS %02x.\n" - "Please run FDISK to correct this - using LBA to access partition.\n", - partitionName, pEntry->FileSystem); - - printCHS(" start ",&chs); - printCHS(", end ", &end); - printf("\n"); - pEntry->FileSystem = (pEntry->FileSystem == FAT12 ? FAT12_LBA : - pEntry->FileSystem == FAT32 ? FAT32_LBA : - /* pEntry->FileSystem == FAT16 ? */ FAT16_LBA); - } - - /* else its a diagnostic message only */ + /* else its a diagnostic message only */ #ifdef DEBUG - printf("found and using LBA partition %s FS %02x", - partitionName, pEntry->FileSystem); - printCHS(" start ",&chs); - printCHS(", end ", &end); - printf("\n"); -#endif - } + printf("found and using LBA partition %s FS %02x", + partitionName, pEntry->FileSystem); + printCHS(" start ", &chs); + printCHS(", end ", &end); + printf("\n"); +#endif + } + /* + here we have a partition table in our hand !! + */ - /* - here we have a partition table in our hand !! - */ + partitionsToIgnore |= 1 << i; - partitionsToIgnore |= 1 << i; - - DosDefinePartition(driveParam,partitionStart, pEntry, - extendedPartNo, i); + DosDefinePartition(driveParam, partitionStart, pEntry, + extendedPartNo, i); - if (scan_type == SCAN_PRIMARYBOOT || - scan_type == SCAN_PRIMARY ) - { - return partitionsToIgnore; - } - } + if (scan_type == SCAN_PRIMARYBOOT || scan_type == SCAN_PRIMARY) + { + return partitionsToIgnore; + } + } - return partitionsToIgnore; + return partitionsToIgnore; } void BIOS_drive_reset(unsigned drive); -int Read1LBASector(struct DriveParamS *driveParam, unsigned drive, ULONG LBA_address, void FAR *buffer) +int Read1LBASector(struct DriveParamS *driveParam, unsigned drive, + ULONG LBA_address, void FAR * buffer) { - static struct _bios_LBA_address_packet dap = { - 16,0,0,0,0,0,0 - }; - - struct CHS chs; - iregs regs; - int num_retries; + static struct _bios_LBA_address_packet dap = { + 16, 0, 0, 0, 0, 0, 0 + }; + + struct CHS chs; + iregs regs; + int num_retries; /* disabled because this should not happen and if it happens the BIOS should complain; also there are weird disks around with CMOS geometry < real geometry */ #if 0 - if (LBA_address >= driveParam->total_sectors) - { - printf("LBA-Transfer error : address overflow = %lu > %lu max\n",LBA_address+1,driveParam->total_sectors); - return 1; - } + if (LBA_address >= driveParam->total_sectors) + { + printf("LBA-Transfer error : address overflow = %lu > %lu max\n", + LBA_address + 1, driveParam->total_sectors); + return 1; + } #endif - for ( num_retries = 0; num_retries < N_RETRY; num_retries++) - { - regs.d.b.l = drive | 0x80; - if (driveParam->LBA_supported) - { - dap.number_of_blocks = 1; - dap.buffer_address = buffer; - dap.block_address_high = 0; /* clear high part */ - dap.block_address = LBA_address; /* clear high part */ - - /* Load the registers and call the interrupt. */ - regs.a.x = LBA_READ; - regs.si = FP_OFF(&dap); - regs.ds = FP_SEG(&dap); - } - else - { /* transfer data, using old bios functions */ - init_LBA_to_CHS(&chs, LBA_address, driveParam); - /* avoid overflow at end of track */ - - if (chs.Cylinder > 1023) - { - printf("LBA-Transfer error : cylinder %u > 1023\n", chs.Cylinder); - return 1; - } - - regs.a.x = 0x0201; - regs.b.x = FP_OFF(buffer); - regs.c.x = ((chs.Cylinder&0xff) << 8) + ((chs.Cylinder&0x300) >> 2) + chs.Sector; - regs.d.b.h = chs.Head; - regs.es = FP_SEG(buffer); - } /* end of retries */ - init_call_intr(0x13, ®s); - if ((regs.flags & FLG_CARRY) == 0) break; - BIOS_drive_reset(driveParam->driveno); - } + for (num_retries = 0; num_retries < N_RETRY; num_retries++) + { + regs.d.b.l = drive | 0x80; + if (driveParam->LBA_supported) + { + dap.number_of_blocks = 1; + dap.buffer_address = buffer; + dap.block_address_high = 0; /* clear high part */ + dap.block_address = LBA_address; /* clear high part */ - return regs.flags & FLG_CARRY ? 1 : 0; -} + /* Load the registers and call the interrupt. */ + regs.a.x = LBA_READ; + regs.si = FP_OFF(&dap); + regs.ds = FP_SEG(&dap); + } + else + { /* transfer data, using old bios functions */ + init_LBA_to_CHS(&chs, LBA_address, driveParam); + /* avoid overflow at end of track */ + + if (chs.Cylinder > 1023) + { + printf("LBA-Transfer error : cylinder %u > 1023\n", chs.Cylinder); + return 1; + } + + regs.a.x = 0x0201; + regs.b.x = FP_OFF(buffer); + regs.c.x = + ((chs.Cylinder & 0xff) << 8) + ((chs.Cylinder & 0x300) >> 2) + + chs.Sector; + regs.d.b.h = chs.Head; + regs.es = FP_SEG(buffer); + } /* end of retries */ + init_call_intr(0x13, ®s); + if ((regs.flags & FLG_CARRY) == 0) + break; + BIOS_drive_reset(driveParam->driveno); + } + + return regs.flags & FLG_CARRY ? 1 : 0; +} /* Load the Partition Tables and get information on all drives */ int ProcessDisk(int scanType, unsigned drive, int PartitionsToIgnore) { - struct PartTableEntry PTable[4]; - ULONG RelSectorOffset; - ULONG ExtendedPartitionOffset; - int iPart; - int strangeHardwareLoop; - - int num_extended_found = 0; + struct PartTableEntry PTable[4]; + ULONG RelSectorOffset; + ULONG ExtendedPartitionOffset; + int iPart; + int strangeHardwareLoop; - struct DriveParamS driveParam; + int num_extended_found = 0; - /* Get the hard drive parameters and ensure that the drive exists. */ - /* If there was an error accessing the drive, skip that drive. */ + struct DriveParamS driveParam; - memset(&driveParam, 0, sizeof(driveParam)); - - if (!LBA_Get_Drive_Parameters(drive,&driveParam)) - { - printf("can't get drive parameters for drive %02x\n",drive); - return PartitionsToIgnore; - } + /* Get the hard drive parameters and ensure that the drive exists. */ + /* If there was an error accessing the drive, skip that drive. */ - RelSectorOffset = 0; /* boot sector */ - ExtendedPartitionOffset = 0; /* not found yet */ + memset(&driveParam, 0, sizeof(driveParam)); + if (!LBA_Get_Drive_Parameters(drive, &driveParam)) + { + printf("can't get drive parameters for drive %02x\n", drive); + return PartitionsToIgnore; + } + RelSectorOffset = 0; /* boot sector */ + ExtendedPartitionOffset = 0; /* not found yet */ - /* Read the Primary Partition Table. */ - + /* Read the Primary Partition Table. */ ReadNextPartitionTable: - strangeHardwareLoop = 0; + strangeHardwareLoop = 0; strange_restart: - - if (Read1LBASector(&driveParam, drive, RelSectorOffset, DiskTransferBuffer)) - { - printf("Error reading partition table drive %02x sector %lu",drive,RelSectorOffset); - return PartitionsToIgnore; - } - - if (!ConvPartTableEntryToIntern(PTable, DiskTransferBuffer)) - { - /* there is some strange hardware out in the world, - which returns OK on first read, but the data are - rubbish. simply retrying works fine. - there is no logic behind this, but it works TE */ - - if (++strangeHardwareLoop < 3) - goto strange_restart; - - printf("illegal partition table - drive %02x sector %lu\n",drive,RelSectorOffset); - return PartitionsToIgnore; - } - - if ( scanType==SCAN_PRIMARYBOOT || - scanType==SCAN_PRIMARY || - scanType==SCAN_PRIMARY2 || - num_extended_found !=0 ) - { - - PartitionsToIgnore = ScanForPrimaryPartitions(&driveParam,scanType, - PTable, RelSectorOffset,PartitionsToIgnore,num_extended_found); - } - - if (scanType != SCAN_EXTENDED) - { - return PartitionsToIgnore; - } - - /* scan for extended partitions now */ - PartitionsToIgnore = 0; - - - for (iPart=0; iPart < 4; iPart++) - { - if (IsExtPartition(PTable[iPart].FileSystem)) - { - RelSectorOffset = ExtendedPartitionOffset + PTable[iPart].RelSect; - - if (ExtendedPartitionOffset == 0) - { - ExtendedPartitionOffset = PTable[iPart].RelSect; - } - - num_extended_found++; - - if (num_extended_found > 30) - { - printf("found more then 30 extended partitions, terminated\n"); - return 0; - } - - goto ReadNextPartitionTable; - } - } - + if (Read1LBASector + (&driveParam, drive, RelSectorOffset, DiskTransferBuffer)) + { + printf("Error reading partition table drive %02x sector %lu", drive, + RelSectorOffset); return PartitionsToIgnore; -} + } + if (!ConvPartTableEntryToIntern(PTable, DiskTransferBuffer)) + { + /* there is some strange hardware out in the world, + which returns OK on first read, but the data are + rubbish. simply retrying works fine. + there is no logic behind this, but it works TE */ + + if (++strangeHardwareLoop < 3) + goto strange_restart; + + printf("illegal partition table - drive %02x sector %lu\n", drive, + RelSectorOffset); + return PartitionsToIgnore; + } + + if (scanType == SCAN_PRIMARYBOOT || + scanType == SCAN_PRIMARY || + scanType == SCAN_PRIMARY2 || num_extended_found != 0) + { + + PartitionsToIgnore = ScanForPrimaryPartitions(&driveParam, scanType, + PTable, RelSectorOffset, + PartitionsToIgnore, + num_extended_found); + } + + if (scanType != SCAN_EXTENDED) + { + return PartitionsToIgnore; + } + + /* scan for extended partitions now */ + PartitionsToIgnore = 0; + + for (iPart = 0; iPart < 4; iPart++) + { + if (IsExtPartition(PTable[iPart].FileSystem)) + { + RelSectorOffset = ExtendedPartitionOffset + PTable[iPart].RelSect; + + if (ExtendedPartitionOffset == 0) + { + ExtendedPartitionOffset = PTable[iPart].RelSect; + } + + num_extended_found++; + + if (num_extended_found > 30) + { + printf("found more then 30 extended partitions, terminated\n"); + return 0; + } + + goto ReadNextPartitionTable; + } + } + + return PartitionsToIgnore; +} int BIOS_nrdrives(void) { - iregs regs; + iregs regs; - regs.a.b.h = 0x08; - regs.d.b.l = 0x80; - init_call_intr(0x13,®s); + regs.a.b.h = 0x08; + regs.d.b.l = 0x80; + init_call_intr(0x13, ®s); - if (regs.flags & 1) - { - printf("no hard disks detected\n"); - return 0; - } + if (regs.flags & 1) + { + printf("no hard disks detected\n"); + return 0; + } - return regs.d.b.l; + return regs.d.b.l; } void BIOS_drive_reset(unsigned drive) { - iregs regs; - - regs.d.b.l = drive | 0x80; - regs.a.b.h = 0; + iregs regs; - init_call_intr(0x13,®s); + regs.d.b.l = drive | 0x80; + regs.a.b.h = 0; + + init_call_intr(0x13, ®s); } /* @@ -1152,13 +1141,11 @@ starting with any active primary partitions (if there is one), otherwise, scan the first primary partition on each drive. Assign next available letter starting with C: - Repeat scan for all fixed hard disks and removable (JAZ, MO) disks and assign drive letters to all logical drives in an extended partition, or the removable disk(s) as enumerated. Assign next available letter starting with C: - Finally, repeat scan for all fixed hard disk drives, and assign drive letters to all remaining primary partitions. Assign next available letter starting with C: @@ -1179,13 +1166,11 @@ to the first physical floppy disk drive that is found. If a second physical floppy disk drive is present, it is assigned drive letter B. If it is not present, a logical drive B is created that uses the first physical floppy disk drive. - Regardless of whether a second floppy disk drive is present, MS-DOS then assigns the drive letter C to the primary MS-DOS partition on the first physical hard disk, and then goes on to check for a second hard disk. - If a second physical hard disk is found, and a primary partition exists on the second physical drive, the primary MS-DOS partition on the second physical hard drive is assigned the letter D. MS-DOS version 5.0, which @@ -1195,12 +1180,10 @@ hard disk is found, and a primary partition exists on the third physical drive, the primary MS-DOS partition on the third physical hard drive is assigned the letter E. - MS-DOS returns to the first physical hard disk drive and assigns drive letters to any additional logical drives (in extended MS-DOS partitions) on that drive in sequence. - MS-DOS repeats this process for the second physical hard disk drive, if present. MS-DOS 5.0 will repeat this process for up to eight physical hard drives, if present. After all logical drives (in extended MS-DOS @@ -1211,7 +1194,6 @@ additional primary MS-DOS partitions. This support for multiple primary MS-DOS partitions was added to version 5.0 for backward compatibility with the previous OEM MS-DOS versions that support multiple primary partitions. - After all logical drives on the hard disk(s) have been assigned drive letters, drive letters are assigned to drives installed using DRIVER.SYS or created using RAMDRIVE.SYS in the order in which the drivers are loaded @@ -1238,112 +1220,109 @@ I don't know, if I did it right, but I tried to do it that way. TE void ReadAllPartitionTables(void) { - UBYTE foundPartitions[MAX_HARD_DRIVE]; + UBYTE foundPartitions[MAX_HARD_DRIVE]; - int HardDrive; - int nHardDisk = BIOS_nrdrives(); - int Unit; - ddt FAR *pddt; - static iregs regs; + int HardDrive; + int nHardDisk = BIOS_nrdrives(); + int Unit; + ddt FAR *pddt; + static iregs regs; - /* Setup media info and BPBs arrays for floppies */ - for (Unit = 0; Unit < nUnits; Unit++) - { - pddt = DynAlloc("ddt", 1, sizeof(ddt)); - - pddt->ddt_driveno = 0; - pddt->ddt_logdriveno = Unit; - pddt->ddt_type = init_getdriveparm(0, &pddt->ddt_defbpb); - pddt->ddt_ncyl = (pddt->ddt_type & 7) ? 80 : 40; - pddt->ddt_LBASupported = FALSE; - pddt->ddt_descflags = init_readdasd(0); - - pddt->ddt_offset = 0l; - pddt->ddt_serialno = 0x12345678l; - fmemcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb)); - } - - /* - this is a quick patch - see if B: exists - test for A: also, need not exist - */ - init_call_intr(0x11,®s); /* get equipment list */ - if ((regs.a.x & 1) && (regs.a.x & 0xc0)) { - pddt->ddt_driveno = 1; - pddt->ddt_type = init_getdriveparm(1, &pddt->ddt_defbpb); - pddt->ddt_descflags = init_readdasd(1); - pddt->ddt_ncyl = (pddt->ddt_type & 7) ? 80 : 40; - /* floppy drives installed and a B: drive */ - /*if ((r.a.x & 1)==0) */ /* no floppy drives installed */ - } else { /* set up the DJ method : multiple logical drives */ - (pddt-1)->ddt_descflags |= DF_CURLOG | DF_MULTLOG; - pddt->ddt_descflags |= DF_MULTLOG; - } + /* Setup media info and BPBs arrays for floppies */ + for (Unit = 0; Unit < nUnits; Unit++) + { + pddt = DynAlloc("ddt", 1, sizeof(ddt)); - nHardDisk = min(nHardDisk,MAX_HARD_DRIVE-1); + pddt->ddt_driveno = 0; + pddt->ddt_logdriveno = Unit; + pddt->ddt_type = init_getdriveparm(0, &pddt->ddt_defbpb); + pddt->ddt_ncyl = (pddt->ddt_type & 7) ? 80 : 40; + pddt->ddt_LBASupported = FALSE; + pddt->ddt_descflags = init_readdasd(0); - memset(foundPartitions,0,sizeof(foundPartitions)); + pddt->ddt_offset = 0l; + pddt->ddt_serialno = 0x12345678l; + fmemcpy(&pddt->ddt_bpb, &pddt->ddt_defbpb, sizeof(bpb)); + } + /* + this is a quick patch - see if B: exists + test for A: also, need not exist + */ + init_call_intr(0x11, ®s); /* get equipment list */ + if ((regs.a.x & 1) && (regs.a.x & 0xc0)) + { + pddt->ddt_driveno = 1; + pddt->ddt_type = init_getdriveparm(1, &pddt->ddt_defbpb); + pddt->ddt_descflags = init_readdasd(1); + pddt->ddt_ncyl = (pddt->ddt_type & 7) ? 80 : 40; + /* floppy drives installed and a B: drive */ +/*if ((r.a.x & 1)==0) *//* no floppy drives installed */ + } + else + { /* set up the DJ method : multiple logical drives */ + (pddt - 1)->ddt_descflags |= DF_CURLOG | DF_MULTLOG; + pddt->ddt_descflags |= DF_MULTLOG; + } + nHardDisk = min(nHardDisk, MAX_HARD_DRIVE - 1); + memset(foundPartitions, 0, sizeof(foundPartitions)); - DebugPrintf(("DSK init: found %d disk drives\n",nHardDisk)); + DebugPrintf(("DSK init: found %d disk drives\n", nHardDisk)); - /* Reset the drives */ + /* Reset the drives */ + for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) + BIOS_drive_reset(HardDrive); + + if (InitKernelConfig.DLASortByDriveNo == 0) + { + /* printf("Drive Letter Assignment - DOS order \n"); */ + + /* Process primary partition table 1 partition only */ for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) - BIOS_drive_reset(HardDrive); - - - - if (InitKernelConfig.DLASortByDriveNo == 0) { - /* printf("Drive Letter Assignment - DOS order \n"); */ - - - /* Process primary partition table 1 partition only */ - for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) - { - foundPartitions[HardDrive] = - ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0); - - if (foundPartitions[HardDrive] == 0) - foundPartitions[HardDrive] = ProcessDisk(SCAN_PRIMARY, HardDrive, 0); - } - - /* Process extended partition table */ - for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) - { - ProcessDisk(SCAN_EXTENDED, HardDrive , 0); - } - - /* Process primary a 2nd time */ - for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) - { - ProcessDisk(SCAN_PRIMARY2, HardDrive ,foundPartitions[HardDrive]); - } + foundPartitions[HardDrive] = + ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0); + + if (foundPartitions[HardDrive] == 0) + foundPartitions[HardDrive] = + ProcessDisk(SCAN_PRIMARY, HardDrive, 0); } - else - { - printf("Drive Letter Assignment - sorted by drive\n"); - - - /* Process primary partition table 1 partition only */ - for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) - { - foundPartitions[HardDrive] = - ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0); - - if (foundPartitions[HardDrive] == 0) - foundPartitions[HardDrive] = ProcessDisk(SCAN_PRIMARY, HardDrive, 0); - - /* Process extended partition table */ - ProcessDisk(SCAN_EXTENDED, HardDrive , 0); - - /* Process primary a 2nd time */ - ProcessDisk(SCAN_PRIMARY2, HardDrive ,foundPartitions[HardDrive]); - } - } + /* Process extended partition table */ + for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) + { + ProcessDisk(SCAN_EXTENDED, HardDrive, 0); + } + + /* Process primary a 2nd time */ + for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) + { + ProcessDisk(SCAN_PRIMARY2, HardDrive, foundPartitions[HardDrive]); + } + } + else + { + printf("Drive Letter Assignment - sorted by drive\n"); + + /* Process primary partition table 1 partition only */ + for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++) + { + foundPartitions[HardDrive] = + ProcessDisk(SCAN_PRIMARYBOOT, HardDrive, 0); + + if (foundPartitions[HardDrive] == 0) + foundPartitions[HardDrive] = + ProcessDisk(SCAN_PRIMARY, HardDrive, 0); + + /* Process extended partition table */ + ProcessDisk(SCAN_EXTENDED, HardDrive, 0); + + /* Process primary a 2nd time */ + ProcessDisk(SCAN_PRIMARY2, HardDrive, foundPartitions[HardDrive]); + } + } } /* disk initialization: returns number of units */ @@ -1352,20 +1331,19 @@ COUNT dsk_init() printf(" - InitDisk\n"); #ifdef DEBUG - { + { iregs regs; - regs.a.x = 0x1112; /* select 43 line mode - more space for partinfo */ + regs.a.x = 0x1112; /* select 43 line mode - more space for partinfo */ regs.b.x = 0; init_call_intr(0x10, ®s); - } + } #endif - + /* Reset the drives */ BIOS_drive_reset(0); /* Initial number of disk units */ nUnits = 2; - ReadAllPartitionTables(); diff --git a/kernel/inithma.c b/kernel/inithma.c index a68fcab..359285d 100644 --- a/kernel/inithma.c +++ b/kernel/inithma.c @@ -63,89 +63,80 @@ parameter is forced. */ - #include "portab.h" #include "init-mod.h" #include "init-dat.h" - - -extern BYTE - FAR _HMATextAvailable, /* first byte of available CODE area */ - FAR _HMATextStart[], /* first byte of HMAable CODE area */ - FAR _HMATextEnd[]; /* and the last byte of it */ +extern BYTE FAR _HMATextAvailable, /* first byte of available CODE area */ + FAR _HMATextStart[], /* first byte of HMAable CODE area */ + FAR _HMATextEnd[]; /* and the last byte of it */ #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif +BYTE DosLoadedInHMA = FALSE; /* set to TRUE if loaded HIGH */ +BYTE HMAclaimed = FALSE; /* set to TRUE if claimed from HIMEM */ +WORD HMAFree = 0; /* first byte in HMA not yet used */ -BYTE DosLoadedInHMA=FALSE; /* set to TRUE if loaded HIGH */ -BYTE HMAclaimed=FALSE; /* set to TRUE if claimed from HIMEM */ -WORD HMAFree = 0; /* first byte in HMA not yet used */ - - -extern BYTE FAR * DOSTEXTFAR ASMCFUNC XMSDriverAddress; +extern BYTE FAR *DOSTEXTFAR ASMCFUNC XMSDriverAddress; extern FAR ASMCFUNC _EnableA20(VOID); extern FAR ASMCFUNC _DisableA20(VOID); - extern void FAR *ASMCFUNC DetectXMSDriver(VOID); -extern int ASMCFUNC init_call_XMScall( void FAR * driverAddress, UWORD ax, UWORD dx); - -#ifdef DEBUG - #ifdef __TURBOC__ - #define int3() __int__(3); - #else - void int3() - { __asm int 3; - } - #endif -#else - #define int3() -#endif - +extern int ASMCFUNC init_call_XMScall(void FAR * driverAddress, UWORD ax, + UWORD dx); #ifdef DEBUG - #define HMAInitPrintf(x) printf x +#ifdef __TURBOC__ +#define int3() __int__(3); #else - #define HMAInitPrintf(x) -#endif +void int3() +{ + __asm int 3; +} +#endif +#else +#define int3() +#endif + +#ifdef DEBUG +#define HMAInitPrintf(x) printf x +#else +#define HMAInitPrintf(x) +#endif void MoveKernel(unsigned NewKernelSegment); - #ifdef DEBUG -VOID hdump(BYTE FAR *p) +VOID hdump(BYTE FAR * p) { - int loop; - HMAInitPrintf(("%p", p)); - - for (loop = 0; loop < 16; loop++) - HMAInitPrintf(("%02x ", p[loop])); - - printf("\n"); -} + int loop; + HMAInitPrintf(("%p", p)); + + for (loop = 0; loop < 16; loop++) + HMAInitPrintf(("%02x ", p[loop])); + + printf("\n"); +} #else - #define hdump(ptr) -#endif - +#define hdump(ptr) +#endif #define KeyboardShiftState() (*(BYTE FAR *)(MK_FP(0x40,0x17))) - /* of course, this should go to ASMSUPT */ -fmemcmp(BYTE far *s1, BYTE FAR *s2, unsigned len) +fmemcmp(BYTE far * s1, BYTE FAR * s2, unsigned len) { - for ( ; len ; s1++,s2++,--len) - { - if (*s1 - *s2) - return *s1-*s2; - } - return 0; + for (; len; s1++, s2++, --len) + { + if (*s1 - *s2) + return *s1 - *s2; + } + return 0; } - /* this tests, if the HMA area can be enabled. if so, it simply leaves it on @@ -153,39 +144,35 @@ fmemcmp(BYTE far *s1, BYTE FAR *s2, unsigned len) int EnableHMA(VOID) { - - _EnableA20(); - if (fmemcmp(MK_FP(0x0000,0x0000), MK_FP(0xffff,0x0010),128) == 0) - { - printf("HMA can't be enabled\n"); - return FALSE; - } - + _EnableA20(); - _DisableA20(); - - if (fmemcmp(MK_FP(0x0000,0x0000), MK_FP(0xffff,0x0010),128) != 0) - { - printf("HMA can't be disabled - no problem for us\n"); - } - - _EnableA20(); - if (fmemcmp(MK_FP(0x0000,0x0000), MK_FP(0xffff,0x0010),128) == 0) - { - printf("HMA can't be enabled second time\n"); - return FALSE; - } - - HMAInitPrintf(("HMA success - leaving enabled\n")); + if (fmemcmp(MK_FP(0x0000, 0x0000), MK_FP(0xffff, 0x0010), 128) == 0) + { + printf("HMA can't be enabled\n"); + return FALSE; + } + + _DisableA20(); + + if (fmemcmp(MK_FP(0x0000, 0x0000), MK_FP(0xffff, 0x0010), 128) != 0) + { + printf("HMA can't be disabled - no problem for us\n"); + } + + _EnableA20(); + if (fmemcmp(MK_FP(0x0000, 0x0000), MK_FP(0xffff, 0x0010), 128) == 0) + { + printf("HMA can't be enabled second time\n"); + return FALSE; + } + + HMAInitPrintf(("HMA success - leaving enabled\n")); + + return TRUE; - return TRUE; - } - - - /* move the kernel up to high memory this is very unportable @@ -196,70 +183,68 @@ int EnableHMA(VOID) #define HMAOFFSET 0x20 #define HMASEGMENT 0xffff - int MoveKernelToHMA() { - - if (DosLoadedInHMA) - { - return TRUE; - } - if ((XMSDriverAddress = DetectXMSDriver()) == NULL) - return FALSE; - -#ifdef DEBUG - /* A) for debugging purpose, suppress this, - if any shift key is pressed - */ - if (KeyboardShiftState() & 0x0f) - { - printf("Keyboard state is %0x, NOT moving to HMA\n",KeyboardShiftState()); - return FALSE; - } -#endif - - /* B) check out, if we can have HMA */ - - if (!EnableHMA()) - { - printf("Can't enable HMA area (the famous A20), NOT moving to HMA\n"); - - return FALSE; - } - - /* allocate HMA through XMS driver */ - - if (HMAclaimed == 0 && - (HMAclaimed = init_call_XMScall( XMSDriverAddress, 0x0100, 0xffff)) == 0) - { - printf("Can't reserve HMA area ??\n"); - - return FALSE; - } - - MoveKernel(0xffff); - - - { - /* E) up to now, nothing really bad was done. - but now, we reuse the HMA area. bad things will happen - - to find bugs early, - cause INT 3 on all accesses to this area - */ - - - DosLoadedInHMA = TRUE; - } - - /* report the fact we are running high thorugh int 21, ax=3306 */ - version_flags |= 0x10; - + if (DosLoadedInHMA) + { return TRUE; - -} + } + if ((XMSDriverAddress = DetectXMSDriver()) == NULL) + return FALSE; + +#ifdef DEBUG + /* A) for debugging purpose, suppress this, + if any shift key is pressed + */ + if (KeyboardShiftState() & 0x0f) + { + printf("Keyboard state is %0x, NOT moving to HMA\n", + KeyboardShiftState()); + return FALSE; + } +#endif + + /* B) check out, if we can have HMA */ + + if (!EnableHMA()) + { + printf("Can't enable HMA area (the famous A20), NOT moving to HMA\n"); + + return FALSE; + } + + /* allocate HMA through XMS driver */ + + if (HMAclaimed == 0 && + (HMAclaimed = + init_call_XMScall(XMSDriverAddress, 0x0100, 0xffff)) == 0) + { + printf("Can't reserve HMA area ??\n"); + + return FALSE; + } + + MoveKernel(0xffff); + + { + /* E) up to now, nothing really bad was done. + but now, we reuse the HMA area. bad things will happen + + to find bugs early, + cause INT 3 on all accesses to this area + */ + + DosLoadedInHMA = TRUE; + } + + /* report the fact we are running high thorugh int 21, ax=3306 */ + version_flags |= 0x10; + + return TRUE; + +} /* not necessary anymore : BO */ /* @@ -271,39 +256,40 @@ int MoveKernelToHMA() */ #if 0 void InstallVDISK(VOID) +{ + static struct { /* Boot-Sektor of a RAM-Disk */ + UBYTE dummy1[3]; /* HIMEM.SYS uses 3, but FDXMS uses 2 */ + char Name[5]; + BYTE dummy2[3]; + WORD BpS; + BYTE dummy3[6]; + WORD Sektoren; + BYTE dummy4; + } VDISK_BOOT_SEKTOR = { { - static struct { /* Boot-Sektor of a RAM-Disk */ - UBYTE dummy1[3]; /* HIMEM.SYS uses 3, but FDXMS uses 2 */ - char Name[5]; - BYTE dummy2[3]; - WORD BpS; - BYTE dummy3[6]; - WORD Sektoren; - BYTE dummy4; - } VDISK_BOOT_SEKTOR = - { - { 0xcf, ' ', ' '}, - { 'V', 'D', 'I', 'S', 'K'}, - { ' ', ' ', ' '}, - 512, - { 'F', 'D', 'O', 'S', ' ', ' '}, - 128, /* 128*512 = 64K */ - ' ' - }; + 0xcf, ' ', ' '}, + { + 'V', 'D', 'I', 'S', 'K'}, + { + ' ', ' ', ' '}, 512, + { + 'F', 'D', 'O', 'S', ' ', ' '}, 128, /* 128*512 = 64K */ + ' '}; - if (!DosLoadedInHMA) return; - if (HMAclaimed) return; - - - fmemcpy(MK_FP(0xffff,0x0010), &VDISK_BOOT_SEKTOR, sizeof(VDISK_BOOT_SEKTOR)); + if (!DosLoadedInHMA) + return; + if (HMAclaimed) + return; - setvec(0x19, MK_FP(0xffff,0x0010)); /* let INT 19 point to VDISK */ - - *(WORD FAR *)MK_FP(0xffff,0x002e) = 1024+64; - } + fmemcpy(MK_FP(0xffff, 0x0010), &VDISK_BOOT_SEKTOR, + sizeof(VDISK_BOOT_SEKTOR)); + + setvec(0x19, MK_FP(0xffff, 0x0010)); /* let INT 19 point to VDISK */ + + *(WORD FAR *) MK_FP(0xffff, 0x002e) = 1024 + 64; +} #endif - /* this should be called, after each device driver has been loaded with FALSE @@ -312,204 +298,210 @@ void InstallVDISK(VOID) will try to grab HMA; on finalize, will install a VDISK -*/ - -#if 0 /* not necessary anymore */ +*/ + +#if 0 /* not necessary anymore */ void HMAconfig(int finalize) { - ClaimHMA(); - - if (finalize) - InstallVDISK(); + ClaimHMA(); + + if (finalize) + InstallVDISK(); } #endif /* this allocates some bytes from the HMA area only available if DOS=HIGH was successful -*/ +*/ VOID FAR *HMAalloc(COUNT bytesToAllocate) { - VOID FAR *HMAptr; - - if (!DosLoadedInHMA) return NULL; + VOID FAR *HMAptr; - if (HMAFree >= 0xfff0 - bytesToAllocate) return NULL; - - HMAptr = MK_FP(0xffff, HMAFree); - - /* align on 16 byte boundary */ - HMAFree = (HMAFree + bytesToAllocate + 0xf) & 0xfff0; + if (!DosLoadedInHMA) + return NULL; - /*printf("HMA allocated %d byte at %x\n", bytesToAllocate, HMAptr); */ - - fmemset( HMAptr,0, bytesToAllocate); - - return HMAptr; + if (HMAFree >= 0xfff0 - bytesToAllocate) + return NULL; + + HMAptr = MK_FP(0xffff, HMAFree); + + /* align on 16 byte boundary */ + HMAFree = (HMAFree + bytesToAllocate + 0xf) & 0xfff0; + + /*printf("HMA allocated %d byte at %x\n", bytesToAllocate, HMAptr); */ + + fmemset(HMAptr, 0, bytesToAllocate); + + return HMAptr; } - - unsigned CurrentKernelSegment = 0; void MoveKernel(unsigned NewKernelSegment) { - UBYTE FAR *HMADest; - UBYTE FAR *HMASource; - unsigned len; + UBYTE FAR *HMADest; + UBYTE FAR *HMASource; + unsigned len; - int3(); - if (CurrentKernelSegment == 0) - CurrentKernelSegment = FP_SEG(_HMATextEnd); - - if (CurrentKernelSegment == 0xffff) - return; - - - HMASource = MK_FP(CurrentKernelSegment,(FP_OFF(_HMATextStart) & 0xfff0)); - HMADest = MK_FP(NewKernelSegment,0x0000); - - len = (FP_OFF(_HMATextEnd) | 0x000f) - (FP_OFF(_HMATextStart) & 0xfff0); - - if (NewKernelSegment == 0xffff) - { - HMASource += HMAOFFSET; - HMADest += HMAOFFSET; - len -= HMAOFFSET; - } - - HMAInitPrintf(("HMA moving %p up to %p for %04x bytes\n", - HMASource, HMADest, len)); + int3(); + if (CurrentKernelSegment == 0) + CurrentKernelSegment = FP_SEG(_HMATextEnd); - if (NewKernelSegment < CurrentKernelSegment || - NewKernelSegment == 0xffff) - { - unsigned i; UBYTE FAR *s,FAR *d; - - for (i = 0, s = HMASource,d = HMADest; i < len; i++) - d[i] = s[i]; - } - else { - /* might overlap */ - unsigned i; UBYTE FAR *s,FAR *d; - - for (i = len, s = HMASource,d = HMADest; i != 0; i--) - d[i] = s[i]; - } - - HMAFree = FP_OFF(HMADest)+len; /* first free byte after HMA_TEXT */ - - { - /* D) but it only makes sense, if we can relocate - all our entries to make use of HMA - */ - - /* this is for a - call near enableA20 - jmp far kernelentry - style table - */ - - struct RelocationTable { - UBYTE jmpFar; - UWORD jmpOffset; - UWORD jmpSegment; - UBYTE callNear; - UWORD callOffset; - }; - struct RelocatedEntry { - UBYTE callNear; - UWORD callOffset; - UBYTE jmpFar; - UWORD jmpOffset; - UWORD jmpSegment; - }; - extern struct RelocationTable - DOSTEXTFAR _HMARelocationTableStart[], - DOSTEXTFAR _HMARelocationTableEnd[]; - - struct RelocationTable FAR *rp, rtemp ; - - /* verify, that all entries are valid */ - - for (rp = _HMARelocationTableStart; rp < _HMARelocationTableEnd; rp++) - { - if (rp->jmpFar != 0xea || /* jmp FAR */ - rp->jmpSegment != CurrentKernelSegment || /* will only relocate HMA_TEXT */ - rp->callNear != 0xe8 || /* call NEAR */ - 0) - { - printf("illegal relocation entry # %d\n",(FP_OFF(rp) - FP_OFF(_HMARelocationTableStart))/sizeof(struct RelocationTable)); - int3(); - goto errorReturn; - } - } - - /* OK, all valid, go to relocate*/ - - for (rp = _HMARelocationTableStart; rp < _HMARelocationTableEnd; rp++) - { - if (NewKernelSegment == 0xffff) - { - struct RelocatedEntry FAR *rel = (struct RelocatedEntry FAR *)rp; - - fmemcpy(&rtemp, rp, sizeof(rtemp)); - - rel->jmpFar = rtemp.jmpFar; - rel->jmpSegment = NewKernelSegment; - rel->jmpOffset = rtemp.jmpOffset; - rel->callNear = rtemp.callNear; - rel->callOffset = rtemp.callOffset+5; /* near calls are relative */ - } - else - rp->jmpSegment = NewKernelSegment; - - } - } - { - struct initRelocationTable { - UBYTE callNear; - UWORD callOffset; - UBYTE jmpFar; - UWORD jmpOffset; - UWORD jmpSegment; - }; - extern struct initRelocationTable - _HMAinitRelocationTableStart[], - _HMAinitRelocationTableEnd[]; - struct initRelocationTable *rp; - - /* verify, that all entries are valid */ - - for (rp = _HMAinitRelocationTableStart; rp < _HMAinitRelocationTableEnd; rp++) - { - if ( - rp->callNear != 0xe8 || /* call NEAR */ - rp->jmpFar != 0xea || /* jmp FAR */ - rp->jmpSegment != CurrentKernelSegment || /* will only relocate HMA_TEXT */ - 0) - { - printf("illegal init relocation entry # %d\n", - rp - _HMAinitRelocationTableStart); - goto errorReturn; - } - } - - /* OK, all valid, go to relocate*/ - - for (rp = _HMAinitRelocationTableStart; rp < _HMAinitRelocationTableEnd; rp++) - { - rp->jmpSegment = NewKernelSegment; - } - } - - CurrentKernelSegment = NewKernelSegment; + if (CurrentKernelSegment == 0xffff) return; - + + HMASource = + MK_FP(CurrentKernelSegment, (FP_OFF(_HMATextStart) & 0xfff0)); + HMADest = MK_FP(NewKernelSegment, 0x0000); + + len = (FP_OFF(_HMATextEnd) | 0x000f) - (FP_OFF(_HMATextStart) & 0xfff0); + + if (NewKernelSegment == 0xffff) + { + HMASource += HMAOFFSET; + HMADest += HMAOFFSET; + len -= HMAOFFSET; + } + + HMAInitPrintf(("HMA moving %p up to %p for %04x bytes\n", + HMASource, HMADest, len)); + + if (NewKernelSegment < CurrentKernelSegment || + NewKernelSegment == 0xffff) + { + unsigned i; + UBYTE FAR *s, FAR * d; + + for (i = 0, s = HMASource, d = HMADest; i < len; i++) + d[i] = s[i]; + } + else + { + /* might overlap */ + unsigned i; + UBYTE FAR *s, FAR * d; + + for (i = len, s = HMASource, d = HMADest; i != 0; i--) + d[i] = s[i]; + } + + HMAFree = FP_OFF(HMADest) + len; /* first free byte after HMA_TEXT */ + + { + /* D) but it only makes sense, if we can relocate + all our entries to make use of HMA + */ + + /* this is for a + call near enableA20 + jmp far kernelentry + style table + */ + + struct RelocationTable { + UBYTE jmpFar; + UWORD jmpOffset; + UWORD jmpSegment; + UBYTE callNear; + UWORD callOffset; + }; + struct RelocatedEntry { + UBYTE callNear; + UWORD callOffset; + UBYTE jmpFar; + UWORD jmpOffset; + UWORD jmpSegment; + }; + extern struct RelocationTable + DOSTEXTFAR _HMARelocationTableStart[], + DOSTEXTFAR _HMARelocationTableEnd[]; + + struct RelocationTable FAR *rp, rtemp; + + /* verify, that all entries are valid */ + + for (rp = _HMARelocationTableStart; rp < _HMARelocationTableEnd; rp++) + { + if (rp->jmpFar != 0xea || /* jmp FAR */ + rp->jmpSegment != CurrentKernelSegment || /* will only relocate HMA_TEXT */ + rp->callNear != 0xe8 || /* call NEAR */ + 0) + { + printf("illegal relocation entry # %d\n", + (FP_OFF(rp) - + FP_OFF(_HMARelocationTableStart)) / + sizeof(struct RelocationTable)); + int3(); + goto errorReturn; + } + } + + /* OK, all valid, go to relocate */ + + for (rp = _HMARelocationTableStart; rp < _HMARelocationTableEnd; rp++) + { + if (NewKernelSegment == 0xffff) + { + struct RelocatedEntry FAR *rel = (struct RelocatedEntry FAR *)rp; + + fmemcpy(&rtemp, rp, sizeof(rtemp)); + + rel->jmpFar = rtemp.jmpFar; + rel->jmpSegment = NewKernelSegment; + rel->jmpOffset = rtemp.jmpOffset; + rel->callNear = rtemp.callNear; + rel->callOffset = rtemp.callOffset + 5; /* near calls are relative */ + } + else + rp->jmpSegment = NewKernelSegment; + + } + } + { + struct initRelocationTable { + UBYTE callNear; + UWORD callOffset; + UBYTE jmpFar; + UWORD jmpOffset; + UWORD jmpSegment; + }; + extern struct initRelocationTable + _HMAinitRelocationTableStart[], _HMAinitRelocationTableEnd[]; + struct initRelocationTable *rp; + + /* verify, that all entries are valid */ + + for (rp = _HMAinitRelocationTableStart; + rp < _HMAinitRelocationTableEnd; rp++) + { + if (rp->callNear != 0xe8 || /* call NEAR */ + rp->jmpFar != 0xea || /* jmp FAR */ + rp->jmpSegment != CurrentKernelSegment || /* will only relocate HMA_TEXT */ + 0) + { + printf("illegal init relocation entry # %d\n", + rp - _HMAinitRelocationTableStart); + goto errorReturn; + } + } + + /* OK, all valid, go to relocate */ + + for (rp = _HMAinitRelocationTableStart; + rp < _HMAinitRelocationTableEnd; rp++) + { + rp->jmpSegment = NewKernelSegment; + } + } + + CurrentKernelSegment = NewKernelSegment; + return; + errorReturn: - for (;;); + for (;;) ; } /* diff --git a/kernel/initoem.c b/kernel/initoem.c index 7c0112c..464a2f0 100644 --- a/kernel/initoem.c +++ b/kernel/initoem.c @@ -31,7 +31,8 @@ #include "init-mod.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif UWORD init_oem(void) @@ -42,7 +43,7 @@ UWORD init_oem(void) asm { int 0x12; - mov top_k,ax; + mov top_k, ax; } #else __int__(0x12); @@ -94,4 +95,3 @@ UWORD init_oem(void) * Rev 1.0 02 Jul 1995 8:31:54 patv * Initial revision. */ - diff --git a/kernel/inthndlr.c b/kernel/inthndlr.c index 00adcfd..2e24a5f 100644 --- a/kernel/inthndlr.c +++ b/kernel/inthndlr.c @@ -32,7 +32,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -BYTE *RcsId = "$Id$"; +BYTE *RcsId = + "$Id$"; #endif #ifdef TSC @@ -40,8 +41,8 @@ static VOID StartTrace(VOID); static bTraceNext = FALSE; #endif -#if 0 /* Very suspicious, passing structure by value?? - Deactivated -- 2000/06/16 ska*/ +#if 0 /* Very suspicious, passing structure by value?? + Deactivated -- 2000/06/16 ska */ /* Special entry for far call into the kernel */ #pragma argsused VOID FAR int21_entry(iregs UserRegs) @@ -51,8 +52,7 @@ VOID FAR int21_entry(iregs UserRegs) #endif /* Structures needed for int 25 / int 26 */ -struct HugeSectorBlock -{ +struct HugeSectorBlock { ULONG blkno; WORD nblks; BYTE FAR *buf; @@ -82,13 +82,12 @@ VOID ASMCFUNC int21_syscall(iregs FAR * irp) break_ena = irp->DL != 0; break; - case 0x02: /* andrew schulman: get/set extended control break */ - { - UBYTE tmp = break_ena; - irp->DL = break_ena; - break_ena = tmp != 0; - } - + case 0x02: /* andrew schulman: get/set extended control break */ + { + UBYTE tmp = break_ena; + irp->DL = break_ena; + break_ena = tmp != 0; + } /* Get Boot Drive */ case 0x05: @@ -100,14 +99,14 @@ VOID ASMCFUNC int21_syscall(iregs FAR * irp) irp->BL = os_major; irp->BH = os_minor; irp->DL = rev_number; - irp->DH = version_flags; /* bit3:runs in ROM,bit 4: runs in HMA*/ + irp->DH = version_flags; /* bit3:runs in ROM,bit 4: runs in HMA */ break; - - case 0x03: /* DOS 7 does not set AL */ - case 0x07: /* neither here */ - default: /* set AL=0xFF as error, NOT carry */ - irp->AL = 0xff; + case 0x03: /* DOS 7 does not set AL */ + case 0x07: /* neither here */ + + default: /* set AL=0xFF as error, NOT carry */ + irp->AL = 0xff; break; /* Toggle DOS-C rdwrblock trace dump */ @@ -153,20 +152,18 @@ VOID ASMCFUNC int21_syscall(iregs FAR * irp) } } - VOID ASMCFUNC int21_service(iregs FAR * r) { COUNT rc = 0; - void FAR *FP_DS_DX = MK_FP(r->DS, r->DX); /* this is saved so often, - that this saves ~100 bytes */ + void FAR *FP_DS_DX = MK_FP(r->DS, r->DX); /* this is saved so often, + that this saves ~100 bytes */ - #define CLEAR_CARRY_FLAG() r->FLAGS &= ~FLG_CARRY #define SET_CARRY_FLAG() r->FLAGS |= FLG_CARRY - ((psp FAR *)MK_FP(cu_psp, 0))->ps_stack = (BYTE FAR *) r; + ((psp FAR *) MK_FP(cu_psp, 0))->ps_stack = (BYTE FAR *) r; -#ifdef DEBUG +#ifdef DEBUG if (bDumpRegs) { fmemcpy(&error_regs, user_r, sizeof(iregs)); @@ -176,9 +173,9 @@ VOID ASMCFUNC int21_service(iregs FAR * r) } #endif - if(r->AH >=0x38 && r->AH <= 0x4F) - CLEAR_CARRY_FLAG(); - /* Clear carry by default for these functions */ + if (r->AH >= 0x38 && r->AH <= 0x4F) + CLEAR_CARRY_FLAG(); + /* Clear carry by default for these functions */ dispatch: @@ -212,11 +209,11 @@ dispatch: error_exit: r->AX = -rc; error_out: - CritErrCode = r->AX; /* Maybe set */ + CritErrCode = r->AX; /* Maybe set */ SET_CARRY_FLAG(); break; - /* case 0x00: --> Simulate a DOS-4C-00 */ + /* case 0x00: --> Simulate a DOS-4C-00 */ /* Read Keyboard with Echo */ case 0x01: @@ -231,26 +228,27 @@ dispatch: /* Auxiliary Input */ case 0x03: - { - COUNT scratch; - GenericRead(STDAUX, 1, (BYTE FAR *) & r->AL, (COUNT FAR *) & scratch, TRUE); - break; - } + { + COUNT scratch; + GenericRead(STDAUX, 1, (BYTE FAR *) & r->AL, + (COUNT FAR *) & scratch, TRUE); + break; + } /* Auxiliary Output */ case 0x04: - { - COUNT scratch; - DosWrite(STDAUX, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) &scratch); - break; - } + { + COUNT scratch; + DosWrite(STDAUX, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) & scratch); + break; + } /* Print Character */ case 0x05: - { - COUNT scratch; - DosWrite(STDPRN, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) &scratch); - break; - } + { + COUNT scratch; + DosWrite(STDPRN, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) & scratch); + break; + } /* Direct Console I/O */ case 0x06: @@ -281,11 +279,12 @@ dispatch: /* Display String */ case 0x09: { - BYTE FAR * q; + BYTE FAR *q; q = FP_DS_DX; while (*q != '$') ++q; - DosWrite(STDOUT, FP_OFF(q) - FP_OFF(FP_DS_DX), FP_DS_DX, (COUNT FAR *) & UnusedRetVal); + DosWrite(STDOUT, FP_OFF(q) - FP_OFF(FP_DS_DX), FP_DS_DX, + (COUNT FAR *) & UnusedRetVal); } r->AL = '$'; break; @@ -401,11 +400,11 @@ dispatch: default: #ifdef DEBUG - printf("Unsupported INT21 AH = 0x%x, AL = 0x%x.\n", r->AH, r->AL); + printf("Unsupported INT21 AH = 0x%x, AL = 0x%x.\n", r->AH, r->AL); #endif /* Fall through. */ - /* CP/M compatibility functions */ + /* CP/M compatibility functions */ case 0x18: case 0x1d: case 0x1e: @@ -440,8 +439,7 @@ dispatch: FatGetDrvData(0, (UCOUNT FAR *) & r->AX, (UCOUNT FAR *) & r->CX, - (UCOUNT FAR *) & r->DX, - (BYTE FAR **) & p); + (UCOUNT FAR *) & r->DX, (BYTE FAR **) & p); r->DS = FP_SEG(p); r->BX = FP_OFF(p); } @@ -455,8 +453,7 @@ dispatch: FatGetDrvData(r->DL, (UCOUNT FAR *) & r->AX, (UCOUNT FAR *) & r->CX, - (UCOUNT FAR *) & r->DX, - (BYTE FAR **) & p); + (UCOUNT FAR *) & r->DX, (BYTE FAR **) & p); r->DS = FP_SEG(p); r->BX = FP_OFF(p); } @@ -542,9 +539,7 @@ dispatch: BYTE FAR *lpFileName; lpFileName = MK_FP(r->DS, r->SI); - r->AL = FcbParseFname(r->AL, - &lpFileName, - MK_FP(r->ES, r->DI)); + r->AL = FcbParseFname(r->AL, &lpFileName, MK_FP(r->ES, r->DI)); r->DS = FP_SEG(lpFileName); r->SI = FP_OFF(lpFileName); } @@ -552,38 +547,34 @@ dispatch: /* Get Date */ case 0x2a: - DosGetDate( - (BYTE FAR *) & (r->AL), /* WeekDay */ - (BYTE FAR *) & (r->DH), /* Month */ - (BYTE FAR *) & (r->DL), /* MonthDay */ - (COUNT FAR *) & (r->CX)); /* Year */ + DosGetDate((BYTE FAR *) & (r->AL), /* WeekDay */ + (BYTE FAR *) & (r->DH), /* Month */ + (BYTE FAR *) & (r->DL), /* MonthDay */ + (COUNT FAR *) & (r->CX)); /* Year */ break; /* Set Date */ case 0x2b: - rc = DosSetDate( - r->DH, /* Month */ - r->DL, /* MonthDay */ - r->CX); /* Year */ + rc = DosSetDate(r->DH, /* Month */ + r->DL, /* MonthDay */ + r->CX); /* Year */ r->AL = (rc != SUCCESS ? 0xff : 0); break; /* Get Time */ case 0x2c: - DosGetTime( - (BYTE FAR *) & (r->CH), /* Hour */ - (BYTE FAR *) & (r->CL), /* Minutes */ - (BYTE FAR *) & (r->DH), /* Seconds */ - (BYTE FAR *) & (r->DL)); /* Hundredths */ + DosGetTime((BYTE FAR *) & (r->CH), /* Hour */ + (BYTE FAR *) & (r->CL), /* Minutes */ + (BYTE FAR *) & (r->DH), /* Seconds */ + (BYTE FAR *) & (r->DL)); /* Hundredths */ break; /* Set Date */ case 0x2d: - rc = DosSetTime( - r->CH, /* Hour */ - r->CL, /* Minutes */ - r->DH, /* Seconds */ - r->DL); /* Hundredths */ + rc = DosSetTime(r->CH, /* Hour */ + r->CL, /* Minutes */ + r->DH, /* Seconds */ + r->DL); /* Hundredths */ r->AL = (rc != SUCCESS ? 0xff : 0); break; @@ -606,34 +597,33 @@ dispatch: r->CH = REVISION_MAJOR; /* JPP */ r->CL = REVISION_MINOR; r->BL = REVISION_SEQ; - - if (ReturnAnyDosVersionExpected) + + if (ReturnAnyDosVersionExpected) { - /* TE for testing purpose only and NOT - to be documented: - return programs, who ask for version == XX.YY - exactly this XX.YY. - this makes most MS programs more happy. - */ + /* TE for testing purpose only and NOT + to be documented: + return programs, who ask for version == XX.YY + exactly this XX.YY. + this makes most MS programs more happy. + */ UBYTE FAR *retp = MK_FP(r->cs, r->ip); - - if ( retp[0] == 0x3d && /* cmp ax, xxyy */ - (retp[3] == 0x75 || retp[3] == 0x74)) /* je/jne error */ + + if (retp[0] == 0x3d && /* cmp ax, xxyy */ + (retp[3] == 0x75 || retp[3] == 0x74)) /* je/jne error */ { - r->AL = retp[1]; - r->AH = retp[2]; + r->AL = retp[1]; + r->AH = retp[2]; } - else if(retp[0] == 0x86 && /* xchg al,ah */ - retp[1] == 0xc4 && - retp[2] == 0x3d && /* cmp ax, xxyy */ - (retp[5] == 0x75 || retp[5] == 0x74)) /* je/jne error */ + else if (retp[0] == 0x86 && /* xchg al,ah */ + retp[1] == 0xc4 && retp[2] == 0x3d && /* cmp ax, xxyy */ + (retp[5] == 0x75 || retp[5] == 0x74)) /* je/jne error */ { - r->AL = retp[4]; - r->AH = retp[3]; - } - + r->AL = retp[4]; + r->AH = retp[3]; + } + } - + break; /* Keep Program (Terminate and stay resident) */ @@ -652,43 +642,44 @@ dispatch: /* r->DL is NOT changed by MS 6.22 */ /* INT21/32 is documented to reread the DPB */ { - struct dpb FAR *dpb; - UCOUNT drv = r->DL; - - if (drv == 0 || r->AH == 0x1f) drv = default_drive; - else drv--; + struct dpb FAR *dpb; + UCOUNT drv = r->DL; + + if (drv == 0 || r->AH == 0x1f) + drv = default_drive; + else + drv--; + + if (drv >= lastdrive) + { + r->AL = 0xFF; + CritErrCode = 0x0f; + break; + } + + dpb = CDSp->cds_table[drv].cdsDpb; + if (dpb == 0 || CDSp->cds_table[drv].cdsFlags & CDSNETWDRV) + { + r->AL = 0xFF; + CritErrCode = 0x0f; + break; + } + flush_buffers(dpb->dpb_unit); + dpb->dpb_flags = M_CHANGED; /* force flush and reread of drive BPB/DPB */ - if (drv >= lastdrive) - { - r->AL = 0xFF; - CritErrCode = 0x0f; - break; - } - - dpb = CDSp->cds_table[drv].cdsDpb; - if (dpb == 0 || - CDSp->cds_table[drv].cdsFlags & CDSNETWDRV) - { - r->AL = 0xFF; - CritErrCode = 0x0f; - break; - } - flush_buffers(dpb->dpb_unit); - dpb->dpb_flags = M_CHANGED; /* force flush and reread of drive BPB/DPB */ - #ifdef WITHFAT32 - if (media_check(dpb) < 0 || ISFAT32(dpb)) + if (media_check(dpb) < 0 || ISFAT32(dpb)) #else - if (media_check(dpb) < 0) + if (media_check(dpb) < 0) #endif - { + { r->AL = 0xff; CritErrCode = 0x0f; break; - } - r->DS = FP_SEG(dpb); - r->BX = FP_OFF(dpb); - r->AL = 0; + } + r->DS = FP_SEG(dpb); + r->BX = FP_OFF(dpb); + r->AL = 0; } break; @@ -720,12 +711,10 @@ dispatch: /* Dos Get Disk Free Space */ case 0x36: - DosGetFree( - r->DL, - (UCOUNT FAR *) & r->AX, - (UCOUNT FAR *) & r->BX, - (UCOUNT FAR *) & r->CX, - (UCOUNT FAR *) & r->DX); + DosGetFree(r->DL, + (UCOUNT FAR *) & r->AX, + (UCOUNT FAR *) & r->BX, + (UCOUNT FAR *) & r->CX, (UCOUNT FAR *) & r->DX); break; /* Undocumented Get/Set Switchar */ @@ -752,26 +741,29 @@ dispatch: /* Get/Set Country Info */ case 0x38: { - UWORD cntry = r->AL; + UWORD cntry = r->AL; - if(cntry == 0) - cntry = (UWORD)-1; - else if(cntry == 0xff) - cntry = r->BX; + if (cntry == 0) + cntry = (UWORD) - 1; + else if (cntry == 0xff) + cntry = r->BX; - if (0xffff == r->DX) { - /* Set Country Code */ - if((rc = DosSetCountry(cntry)) < 0) - goto error_invalid; - } else { - /* Get Country Information */ - if((rc = DosGetCountryInformation(cntry, FP_DS_DX)) < 0) - goto error_invalid; - /* HACK FIXME */ - if(cntry == (UWORD)-1) - cntry = 1; - /* END OF HACK */ - r->AX = r->BX = cntry; + if (0xffff == r->DX) + { + /* Set Country Code */ + if ((rc = DosSetCountry(cntry)) < 0) + goto error_invalid; + } + else + { + /* Get Country Information */ + if ((rc = DosGetCountryInformation(cntry, FP_DS_DX)) < 0) + goto error_invalid; + /* HACK FIXME */ + if (cntry == (UWORD) - 1) + cntry = 1; + /* END OF HACK */ + r->AX = r->BX = cntry; } } break; @@ -842,14 +834,16 @@ dispatch: /* Dos Seek */ case 0x42: { - ULONG lrc; - if ((rc = DosSeek(r->BX, (LONG) ((((LONG) (r->CX)) << 16) | r->DX), r->AL, &lrc)) < 0) - goto error_exit; - else - { - r->DX = (lrc >> 16); - r->AX = (UWORD)lrc; - } + ULONG lrc; + if ((rc = + DosSeek(r->BX, (LONG) ((((LONG) (r->CX)) << 16) | r->DX), + r->AL, &lrc)) < 0) + goto error_exit; + else + { + r->DX = (lrc >> 16); + r->AX = (UWORD) lrc; + } } break; @@ -860,7 +854,7 @@ dispatch: case 0x00: rc = DosGetFattr((BYTE FAR *) FP_DS_DX); if (rc >= SUCCESS) - r->CX = rc; + r->CX = rc; break; case 0x01: @@ -876,7 +870,7 @@ dispatch: /* Device I/O Control */ case 0x44: - rc = DosDevIOctl(r); /* can set critical error code! */ + rc = DosDevIOctl(r); /* can set critical error code! */ if (rc != SUCCESS) { @@ -913,7 +907,8 @@ dispatch: /* Allocate memory */ case 0x48: - if ((rc = DosMemAlloc(r->BX, mem_access_mode, &(r->AX), &(r->BX))) < 0) + if ((rc = + DosMemAlloc(r->BX, mem_access_mode, &(r->AX), &(r->BX))) < 0) { DosMemLargest(&(r->BX)); goto error_exit; @@ -958,8 +953,7 @@ dispatch: case 0x4b: break_flg = FALSE; - if ((rc = DosExec(r->AL, MK_FP(r->ES, r->BX), FP_DS_DX)) - != SUCCESS) + if ((rc = DosExec(r->AL, MK_FP(r->ES, r->BX), FP_DS_DX)) != SUCCESS) goto error_exit; break; @@ -1038,13 +1032,14 @@ dispatch: case 0x53: /* DOS 2+ internal - TRANSLATE BIOS PARAMETER BLOCK TO DRIVE PARAM BLOCK */ - bpb_to_dpb((bpb FAR *)MK_FP(r->DS, r->SI), (struct dpb FAR *)MK_FP(r->ES, r->BP) + bpb_to_dpb((bpb FAR *) MK_FP(r->DS, r->SI), + (struct dpb FAR *)MK_FP(r->ES, r->BP) #ifdef WITHFAT32 - ,(r->CX == 0x4558 && r->DX == 0x4152) + , (r->CX == 0x4558 && r->DX == 0x4152) #endif - ); + ); break; - + /* Get verify state */ case 0x54: r->AL = (verify_ena ? TRUE : FALSE); @@ -1059,7 +1054,8 @@ dispatch: /* Dos Rename */ case 0x56: - rc = DosRename((BYTE FAR *) FP_DS_DX, (BYTE FAR *) MK_FP(r->ES, r->DI)); + rc = DosRename((BYTE FAR *) FP_DS_DX, + (BYTE FAR *) MK_FP(r->ES, r->DI)); if (rc < SUCCESS) goto error_exit; else @@ -1072,19 +1068,17 @@ dispatch: switch (r->AL) { case 0x00: - rc = DosGetFtime( - (COUNT) r->BX, /* Handle */ - (date FAR *) & r->DX, /* FileDate */ - (time FAR *) & r->CX); /* FileTime */ + rc = DosGetFtime((COUNT) r->BX, /* Handle */ + (date FAR *) & r->DX, /* FileDate */ + (time FAR *) & r->CX); /* FileTime */ if (rc < SUCCESS) goto error_exit; break; case 0x01: - rc = DosSetFtime( - (COUNT) r->BX, /* Handle */ - (date) r->DX, /* FileDate */ - (time) r->CX); /* FileTime */ + rc = DosSetFtime((COUNT) r->BX, /* Handle */ + (date) r->DX, /* FileDate */ + (time) r->CX); /* FileTime */ if (rc < SUCCESS) goto error_exit; break; @@ -1105,38 +1099,38 @@ dispatch: break; case 0x01: - { + { switch (r->BL) { - case LAST_FIT: - case LAST_FIT_U: - case LAST_FIT_UO: - case BEST_FIT: - case BEST_FIT_U: - case BEST_FIT_UO: - case FIRST_FIT: - case FIRST_FIT_U: - case FIRST_FIT_UO: + case LAST_FIT: + case LAST_FIT_U: + case LAST_FIT_UO: + case BEST_FIT: + case BEST_FIT_U: + case BEST_FIT_UO: + case FIRST_FIT: + case FIRST_FIT_U: + case FIRST_FIT_UO: mem_access_mode = r->BL; break; - default: + default: goto error_invalid; } - } - break; + } + break; case 0x02: - r->AL = uppermem_link; - break; + r->AL = uppermem_link; + break; case 0x03: - if (uppermem_root) /* always error if not exists */ - { - DosUmbLink(r->BL); - break; - } - /* else fall through */ + if (uppermem_root) /* always error if not exists */ + { + DosUmbLink(r->BL); + break; + } + /* else fall through */ default: goto error_invalid; @@ -1150,13 +1144,13 @@ dispatch: /* Get Extended Error */ case 0x59: - r->AX = CritErrCode; - r->ES = FP_SEG(CritErrDev); - r->DI = FP_OFF(CritErrDev); - r->CH = CritErrLocus; - r->BH = CritErrClass; - r->BL = CritErrAction; - CLEAR_CARRY_FLAG(); + r->AX = CritErrCode; + r->ES = FP_SEG(CritErrDev); + r->DI = FP_OFF(CritErrDev); + r->CH = CritErrLocus; + r->BH = CritErrClass; + r->BL = CritErrAction; + CLEAR_CARRY_FLAG(); break; /* Create Temporary File */ @@ -1194,11 +1188,13 @@ dispatch: /* Lock/unlock file access */ case 0x5c: if ((rc = DosLockUnlock - (r->BX, - (((unsigned long)r->CX)<<16)|(((unsigned long)r->DX)&0xffffL), - (((unsigned long)r->SI)<<16)|(((unsigned long)r->DI)&0xffffL), - ((r->AX & 0xff) != 0))) != 0) - goto error_exit; + (r->BX, + (((unsigned long)r->CX) << 16) | (((unsigned long)r-> + DX) & 0xffffL), + (((unsigned long)r->SI) << 16) | (((unsigned long)r-> + DI) & 0xffffL), + ((r->AX & 0xff) != 0))) != 0) + goto error_exit; CLEAR_CARRY_FLAG(); break; /* /// End of additions for SHARE. - Ron Cemer */ @@ -1233,8 +1229,8 @@ dispatch: case 0x07: case 0x08: case 0x09: - rc = remote_printredir(r->DX, Int21AX); - if (rc != SUCCESS) + rc = remote_printredir(r->DX, Int21AX); + if (rc != SUCCESS) goto error_exit; CLEAR_CARRY_FLAG(); break; @@ -1256,9 +1252,11 @@ dispatch: break; default: - rc = remote_printset(r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX))); - if (rc != SUCCESS) goto error_exit; - r->AX=SUCCESS; + rc = remote_printset(r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), + r->SI, (MK_FP(r->DS, Int21AX))); + if (rc != SUCCESS) + goto error_exit; + r->AX = SUCCESS; break; } break; @@ -1268,15 +1266,17 @@ dispatch: switch (r->AL) { case 0x07: - if (r->DL < lastdrive) { + if (r->DL < lastdrive) + { CDSp->cds_table[r->DL].cdsFlags |= 0x100; - } + } break; case 0x08: - if (r->DL < lastdrive) { + if (r->DL < lastdrive) + { CDSp->cds_table[r->DL].cdsFlags &= ~0x100; - } + } break; default: @@ -1286,10 +1286,11 @@ dispatch: break;*/ rc = remote_doredirect(r->BX, r->CX, r->DX, - (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX))); - if (rc != SUCCESS) + (MK_FP(r->ES, r->DI)), r->SI, + (MK_FP(r->DS, Int21AX))); + if (rc != SUCCESS) goto error_exit; - r->AX=SUCCESS; + r->AX = SUCCESS; break; } break; @@ -1297,7 +1298,8 @@ dispatch: case 0x60: /* TRUENAME */ CLEAR_CARRY_FLAG(); if ((rc = truename(MK_FP(r->DS, r->SI), - adjust_far(MK_FP(r->ES, r->DI)), FALSE)) != SUCCESS) + adjust_far(MK_FP(r->ES, r->DI)), + FALSE)) != SUCCESS) goto error_exit; break; @@ -1323,96 +1325,96 @@ dispatch: #endif /* UNDOCUMENTED: return current psp - case 0x62: is in int21_syscall - r->BX = cu_psp; - break; - */ - + case 0x62: is in int21_syscall + r->BX = cu_psp; + break; + */ + /* UNDOCUMENTED: Double byte and korean tables */ case 0x63: { - static char dbcsTable[4] = - { + static char dbcsTable[4] = { 0, 0, 0, 0 }; r->DS = FP_SEG(&dbcsTable); r->SI = FP_OFF(&dbcsTable); #if 0 /* not really supported, but will pass. */ - r->AL = 0x00; /*jpp: according to interrupt list */ - /*Bart: fails for PQDI and WATCOM utilities: - use the above again */ + r->AL = 0x00; /*jpp: according to interrupt list */ + /*Bart: fails for PQDI and WATCOM utilities: + use the above again */ #endif break; } /* case 0x64: see above (invalid) -*/ +*/ /* Extended country info */ case 0x65: - switch(r->AL) { - case 0x20: /* upcase single character */ - r->DL = DosUpChar(r->DL); - break; - case 0x21: /* upcase memory area */ - DosUpMem(FP_DS_DX, r->CX); - break; - case 0x22: /* upcase ASCIZ */ - DosUpString(FP_DS_DX); - break; - case 0xA0: /* upcase single character of filenames */ - r->DL = DosUpFChar(r->DL); - break; - case 0xA1: /* upcase memory area of filenames */ - DosUpFMem(FP_DS_DX, r->CX); - break; - case 0xA2: /* upcase ASCIZ of filenames */ - DosUpFString(FP_DS_DX); - break; - case 0x23: /* check Yes/No response */ - r->AX = DosYesNo(r->DL); - break; - default: - if ((rc = DosGetData( - r->AL, r->BX, r->DX, r->CX, - MK_FP(r->ES, r->DI))) < 0) { -#ifdef NLS_DEBUG - printf("DosGetData() := %d\n", rc); -#endif - goto error_exit; - } -#ifdef NLS_DEBUG - printf("DosGetData() returned successfully\n", rc); -#endif - - break; - } - CLEAR_CARRY_FLAG(); - break; - - - /* Code Page functions */ - case 0x66: { - int rc; switch (r->AL) { - case 1: - rc = DosGetCodepage(&r->BX, &r->DX); - break; - case 2: - rc = DosSetCodepage(r->BX, r->DX); + case 0x20: /* upcase single character */ + r->DL = DosUpChar(r->DL); + break; + case 0x21: /* upcase memory area */ + DosUpMem(FP_DS_DX, r->CX); + break; + case 0x22: /* upcase ASCIZ */ + DosUpString(FP_DS_DX); + break; + case 0xA0: /* upcase single character of filenames */ + r->DL = DosUpFChar(r->DL); + break; + case 0xA1: /* upcase memory area of filenames */ + DosUpFMem(FP_DS_DX, r->CX); + break; + case 0xA2: /* upcase ASCIZ of filenames */ + DosUpFString(FP_DS_DX); + break; + case 0x23: /* check Yes/No response */ + r->AX = DosYesNo(r->DL); break; - default: - goto error_invalid; + if ((rc = DosGetData(r->AL, r->BX, r->DX, r->CX, + MK_FP(r->ES, r->DI))) < 0) + { +#ifdef NLS_DEBUG + printf("DosGetData() := %d\n", rc); +#endif + goto error_exit; + } +#ifdef NLS_DEBUG + printf("DosGetData() returned successfully\n", rc); +#endif + + break; } - if(rc != SUCCESS) - goto error_exit; CLEAR_CARRY_FLAG(); break; - } + + /* Code Page functions */ + case 0x66: + { + int rc; + switch (r->AL) + { + case 1: + rc = DosGetCodepage(&r->BX, &r->DX); + break; + case 2: + rc = DosSetCodepage(r->BX, r->DX); + break; + + default: + goto error_invalid; + } + if (rc != SUCCESS) + goto error_exit; + CLEAR_CARRY_FLAG(); + break; + } /* Set Max file handle count */ case 0x67: @@ -1434,17 +1436,19 @@ dispatch: if (rc < lastdrive) { UWORD saveCX = r->CX; - if (CDSp->cds_table[rc].cdsFlags & CDSNETWDRV) { + if (CDSp->cds_table[rc].cdsFlags & CDSNETWDRV) + { goto error_invalid; } - switch(r->AL){ - case 0x00: + switch (r->AL) + { + case 0x00: r->AL = 0x0d; r->CX = 0x0866; rc = DosDevIOctl(r); break; - case 0x01: + case 0x01: r->AL = 0x0d; r->CX = 0x0846; rc = DosDevIOctl(r); @@ -1462,136 +1466,140 @@ dispatch: /* case 0x6a: see case 0x68 case 0x6b: dummy func: return AL=0 -*/ - /* Extended Open-Creat, not fully functional. (bits 4,5,6 of BH) */ - case 0x6c: +*/ + /* Extended Open-Creat, not fully functional. (bits 4,5,6 of BH) */ + case 0x6c: { COUNT x = 0; - + if (r->AL != 0 || r->DH != 0 || - (r->DL&0x0f) > 0x2 || (r->DL&0xf0) > 0x10) - goto error_invalid; + (r->DL & 0x0f) > 0x2 || (r->DL & 0xf0) > 0x10) + goto error_invalid; CLEAR_CARRY_FLAG(); if ((rc = DosOpen(MK_FP(r->DS, r->SI), - (r->DL&0x0f) == 0x1 ? r->BL : 0)) < 0) + (r->DL & 0x0f) == 0x1 ? r->BL : 0)) < 0) { - if (r->DL < 0x10) - goto error_exit; - /* else try to create below */ - } - else switch (r->DL & 0x0f) - { - case 0x0: - /* fail if file exists */ - DosClose(rc); - rc = DE_FILEEXISTS; + if (r->DL < 0x10) goto error_exit; - case 0x1: - /* file exists and opened: OK */ - r->CX = 0x01; - goto break_out; - case 0x2: - /* file exists: replace/open */ - DosClose(rc); - x = 1; - break; + /* else try to create below */ } + else + switch (r->DL & 0x0f) + { + case 0x0: + /* fail if file exists */ + DosClose(rc); + rc = DE_FILEEXISTS; + goto error_exit; + case 0x1: + /* file exists and opened: OK */ + r->CX = 0x01; + goto break_out; + case 0x2: + /* file exists: replace/open */ + DosClose(rc); + x = 1; + break; + } /* cases 0x00, 0x01 are finished now */ if ((rc = DosCreat(MK_FP(r->DS, r->SI), r->CX)) < 0) - goto error_exit; - - r->CX = x+2; -break_out: + goto error_exit; + + r->CX = x + 2; + break_out: r->AX = rc; break; } - /* case 0x6d and above not implemented : see default; return AL=0 */ + /* case 0x6d and above not implemented : see default; return AL=0 */ #ifdef WITHFAT32 - /* DOS 7.0+ FAT32 extended funcitons */ - case 0x73: - { - switch(r->AL) - { - /* Get extended drive parameter block */ - case 0x02: - { - struct xdpbdata FAR *xddp = (struct xdpbdata FAR *)MK_FP(r->ES, r->DI); - struct dpb FAR *dpb; + /* DOS 7.0+ FAT32 extended funcitons */ + case 0x73: + { + switch (r->AL) + { + /* Get extended drive parameter block */ + case 0x02: + { + struct xdpbdata FAR *xddp = + (struct xdpbdata FAR *)MK_FP(r->ES, r->DI); + struct dpb FAR *dpb; - if (r->CX < sizeof(struct xdpbdata)) - { - r->AX = -DE_INVLDBUF; - goto error_out; - } + if (r->CX < sizeof(struct xdpbdata)) + { + r->AX = -DE_INVLDBUF; + goto error_out; + } dpb = GetDriveDPB(r->DL, &rc); - if (rc != SUCCESS) goto error_exit; + if (rc != SUCCESS) + goto error_exit; - flush_buffers(dpb->dpb_unit); - dpb->dpb_flags = M_CHANGED; /* force reread of drive BPB/DPB */ - - if (media_check(dpb) < 0) - { - r->AX = -DE_INVLDDRV; - goto error_out; - } + flush_buffers(dpb->dpb_unit); + dpb->dpb_flags = M_CHANGED; /* force reread of drive BPB/DPB */ - fmemcpy(&xddp->xdd_dpb, dpb, sizeof(struct dpb)); - xddp->xdd_dpbsize = sizeof(struct dpb); + if (media_check(dpb) < 0) + { + r->AX = -DE_INVLDDRV; + goto error_out; + } + + fmemcpy(&xddp->xdd_dpb, dpb, sizeof(struct dpb)); + xddp->xdd_dpbsize = sizeof(struct dpb); CLEAR_CARRY_FLAG(); - break; - } - /* Get extended free drive space */ + break; + } + /* Get extended free drive space */ case 0x03: - { + { struct xfreespace FAR *xfsp = - (struct xfreespace FAR *)MK_FP(r->ES, r->DI); - if (r->CX < sizeof(struct xfreespace)) - { - r->AX = -DE_INVLDBUF; - goto error_out; - } - CLEAR_CARRY_FLAG(); - rc = DosGetExtFree((BYTE FAR *)FP_DS_DX, xfsp); - if (rc != SUCCESS) - goto error_exit; + (struct xfreespace FAR *)MK_FP(r->ES, r->DI); + if (r->CX < sizeof(struct xfreespace)) + { + r->AX = -DE_INVLDBUF; + goto error_out; + } + CLEAR_CARRY_FLAG(); + rc = DosGetExtFree((BYTE FAR *) FP_DS_DX, xfsp); + if (rc != SUCCESS) + goto error_exit; xfsp->xfs_datasize = sizeof(struct xfreespace); xfsp->xfs_version.actual = 0; - break; - } + break; + } /* Set DPB to use for formatting */ case 0x04: { struct xdpbforformat FAR *xdffp = - (struct xdpbforformat FAR *)MK_FP(r->ES, r->DI); + (struct xdpbforformat FAR *)MK_FP(r->ES, r->DI); struct dpb FAR *dpb; - if (r->CX < sizeof(struct xdpbforformat)) - { - r->AX = -DE_INVLDBUF; - goto error_out; - } + if (r->CX < sizeof(struct xdpbforformat)) + { + r->AX = -DE_INVLDBUF; + goto error_out; + } dpb = GetDriveDPB(r->DL, &rc); - if (rc != SUCCESS) goto error_exit; + if (rc != SUCCESS) + goto error_exit; CLEAR_CARRY_FLAG(); xdffp->xdff_datasize = sizeof(struct xdpbforformat); xdffp->xdff_version.actual = 0; - switch ((UWORD)xdffp->xdff_function) - { + switch ((UWORD) xdffp->xdff_function) + { case 0x00: { DWORD nfreeclst = xdffp->xdff_f.setdpbcounts.nfreeclst; DWORD cluster = xdffp->xdff_f.setdpbcounts.cluster; if (ISFAT32(dpb)) { - if ((dpb->dpb_xfsinfosec == 0xffff && (nfreeclst != 0 || - cluster != 0)) || - nfreeclst == 1 || nfreeclst > dpb->dpb_xsize || - cluster == 1 || cluster > dpb->dpb_xsize) + if ((dpb->dpb_xfsinfosec == 0xffff + && (nfreeclst != 0 || cluster != 0)) + || nfreeclst == 1 || nfreeclst > dpb->dpb_xsize + || cluster == 1 || cluster > dpb->dpb_xsize) { r->AX = -DE_INVLDPARM; goto error_out; @@ -1600,10 +1608,10 @@ break_out: dpb->dpb_xcluster = cluster; write_fsinfo(dpb); } - else + else { if (nfreeclst == 1 || nfreeclst > dpb->dpb_size || - cluster == 1 || cluster > dpb->dpb_size) + cluster == 1 || cluster > dpb->dpb_size) { r->AX = -DE_INVLDPARM; goto error_out; @@ -1617,19 +1625,19 @@ break_out: { ddt *pddt = getddt(r->DL); fmemcpy(&pddt->ddt_bpb, xdffp->xdff_f.rebuilddpb.bpbp, - sizeof(bpb)); + sizeof(bpb)); } case 0x02: { -rebuild_dpb: - flush_buffers(dpb->dpb_unit); + rebuild_dpb: + flush_buffers(dpb->dpb_unit); dpb->dpb_flags = M_CHANGED; - + if (media_check(dpb) < 0) - { - r->AX = -DE_INVLDDRV; - goto error_out; - } + { + r->AX = -DE_INVLDDRV; + goto error_out; + } break; } @@ -1637,22 +1645,26 @@ rebuild_dpb: { struct buffer FAR *bp; bpb FAR *bpbp; - DWORD newmirroring = xdffp->xdff_f.setmirroring.newmirroring; + DWORD newmirroring = + xdffp->xdff_f.setmirroring.newmirroring; - if (newmirroring != -1 && (ISFAT32(dpb) && (newmirroring & ~(0xf | 0x80)))) - { - r->AX = -DE_INVLDPARM; - goto error_out; - } - xdffp->xdff_f.setmirroring.oldmirroring = (ISFAT32(dpb) ? dpb->dpb_xflags : 0); + if (newmirroring != -1 + && (ISFAT32(dpb) + && (newmirroring & ~(0xf | 0x80)))) + { + r->AX = -DE_INVLDPARM; + goto error_out; + } + xdffp->xdff_f.setmirroring.oldmirroring = + (ISFAT32(dpb) ? dpb->dpb_xflags : 0); if (newmirroring != -1 && ISFAT32(dpb)) - { - bp = getblock(1, dpb->dpb_unit); - bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT); - bp->b_flag |= BFR_VALID | BFR_DIRTY; - bpbp = (bpb FAR *)& bp->b_buffer[BT_BPB]; - bpbp->bpb_xflags = newmirroring; - } + { + bp = getblock(1, dpb->dpb_unit); + bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT); + bp->b_flag |= BFR_VALID | BFR_DIRTY; + bpbp = (bpb FAR *) & bp->b_buffer[BT_BPB]; + bpbp->bpb_xflags = newmirroring; + } goto rebuild_dpb; } case 0x04: @@ -1660,91 +1672,95 @@ rebuild_dpb: struct buffer FAR *bp; bpb FAR *bpbp; DWORD rootclst = xdffp->xdff_f.setroot.newrootclst; - if (!ISFAT32(dpb) || (rootclst != -1 && (rootclst == 1 || - rootclst > dpb->dpb_xsize))) - { - r->AX = -DE_INVLDPARM; - goto error_out; - } + if (!ISFAT32(dpb) + || (rootclst != -1 + && (rootclst == 1 + || rootclst > dpb->dpb_xsize))) + { + r->AX = -DE_INVLDPARM; + goto error_out; + } xdffp->xdff_f.setroot.oldrootclst = dpb->dpb_xrootclst; if (rootclst != -1) - { - bp = getblock(1, dpb->dpb_unit); - bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT); - bp->b_flag |= BFR_VALID | BFR_DIRTY; - bpbp = (bpb FAR *) & bp->b_buffer[BT_BPB]; - bpbp->bpb_xrootclst = rootclst; - } + { + bp = getblock(1, dpb->dpb_unit); + bp->b_flag &= ~(BFR_DATA | BFR_DIR | BFR_FAT); + bp->b_flag |= BFR_VALID | BFR_DIRTY; + bpbp = (bpb FAR *) & bp->b_buffer[BT_BPB]; + bpbp->bpb_xrootclst = rootclst; + } goto rebuild_dpb; } - } + } - break; + break; } - /* Extended absolute disk read/write */ + /* Extended absolute disk read/write */ /* TODO(vlp) consider using of the 13-14th bits of SI */ case 0x05: - { + { struct HugeSectorBlock FAR *SectorBlock = - (struct HugeSectorBlock FAR *)MK_FP(r->DS, r->BX); + (struct HugeSectorBlock FAR *)MK_FP(r->DS, r->BX); UBYTE mode; - - if (r->CX != 0xffff || ((r->SI & 1) == 0 && r->SI != 0) - || (r->SI & ~0x6001)) - { - r->AX = -DE_INVLDPARM; - goto error_out; - } - - if (r->DL - 1 >= lastdrive || r->DL == 0) - { - r->AX = 0x207; - goto error_out; - } - CLEAR_CARRY_FLAG(); - if (r->SI == 0) mode = DSKREAD; - else mode = DSKWRITE; + if (r->CX != 0xffff || ((r->SI & 1) == 0 && r->SI != 0) + || (r->SI & ~0x6001)) + { + r->AX = -DE_INVLDPARM; + goto error_out; + } + + if (r->DL - 1 >= lastdrive || r->DL == 0) + { + r->AX = 0x207; + goto error_out; + } + CLEAR_CARRY_FLAG(); + + if (r->SI == 0) + mode = DSKREAD; + else + mode = DSKWRITE; InDOS++; - r->AX=dskxfer(r->DL - 1, SectorBlock->blkno, SectorBlock->buf, - SectorBlock->nblks, mode); + r->AX = + dskxfer(r->DL - 1, SectorBlock->blkno, SectorBlock->buf, + SectorBlock->nblks, mode); if (mode == DSKWRITE) if (r->AX <= 0) - setinvld(r->DL - 1); + setinvld(r->DL - 1); if (r->AX > 0) - { - r->AX = 0x20c; - r->flags |= FLG_CARRY; - --InDOS; - return; - } - + { + r->AX = 0x20c; + r->flags |= FLG_CARRY; + --InDOS; + return; + } r->AX = 0; r->flags &= ~FLG_CARRY; --InDOS; - break; - } - } + break; + } + } break; - } + } #endif #ifdef WITHLFNAPI /* FreeDOS LFN helper API functions */ case 0x74: { - switch(r->AL) - { + switch (r->AL) + { /* Allocate LFN inode */ case 0x01: { r->AX = lfn_allocate_inode(); break; } - /* Free LFN inode */ + /* Free LFN inode */ case 0x02: { r->AX = lfn_free_inode(r->BX); @@ -1759,7 +1775,7 @@ rebuild_dpb: /* Create LFN entries */ case 0x04: { - r->AX = lfn_create_entries(r->BX, (lfn_inode_ptr)FP_DS_DX); + r->AX = lfn_create_entries(r->BX, (lfn_inode_ptr) FP_DS_DX); break; } /* Delete LFN entries */ @@ -1771,7 +1787,7 @@ rebuild_dpb: /* Read next LFN */ case 0x06: { - r->AX = lfn_dir_read(r->BX, (lfn_inode_ptr)FP_DS_DX); + r->AX = lfn_dir_read(r->BX, (lfn_inode_ptr) FP_DS_DX); break; } /* Write SFN pointed by LFN inode */ @@ -1780,26 +1796,28 @@ rebuild_dpb: r->AX = lfn_dir_write(r->BX); break; } - } + } break; } #endif } #ifdef DEBUG if (bDumpRegs) - { - fmemcpy(&error_regs, user_r, sizeof(iregs)); - dump_regs = TRUE; - dump(); - } + { + fmemcpy(&error_regs, user_r, sizeof(iregs)); + dump_regs = TRUE; + dump(); + } #endif } #if 0 - /* No kernel INT-23 handler required no longer -- 1999/04/15 ska */ + /* No kernel INT-23 handler required no longer -- 1999/04/15 ska */ /* ctrl-Break handler */ #pragma argsused -VOID INRPT FAR int23_handler(int es, int ds, int di, int si, int bp, int sp, int bx, int dx, int cx, int ax, int ip, int cs, int flags) +VOID INRPT FAR int23_handler(int es, int ds, int di, int si, int bp, + int sp, int bx, int dx, int cx, int ax, + int ip, int cs, int flags) { tsr = FALSE; return_mode = 1; @@ -1813,21 +1831,11 @@ VOID INRPT FAR int23_handler(int es, int ds, int di, int si, int bp, int sp, int } #endif -struct int25regs -{ - UWORD es, - ds; - UWORD di, - si, - bp, - sp; - UWORD bx, - dx, - cx, - ax; - UWORD flags, - ip, - cs; +struct int25regs { + UWORD es, ds; + UWORD di, si, bp, sp; + UWORD bx, dx, cx, ax; + UWORD flags, ip, cs; }; /* @@ -1837,12 +1845,14 @@ VOID ASMCFUNC int2526_handler(WORD mode, struct int25regs FAR * r) { ULONG blkno; UWORD nblks; - BYTE FAR *buf; + BYTE FAR *buf; UBYTE drv; - - if (mode == 0x26) mode = DSKWRITEINT26; - else mode = DSKREADINT25; - + + if (mode == 0x26) + mode = DSKWRITEINT26; + else + mode = DSKREADINT25; + drv = r->ax; if (drv >= lastdrive) @@ -1860,29 +1870,28 @@ VOID ASMCFUNC int2526_handler(WORD mode, struct int25regs FAR * r) r->flags |= FLG_CARRY; return; } -#endif +#endif nblks = r->cx; blkno = r->dx; - + buf = MK_FP(r->ds, r->bx); - + if (nblks == 0xFFFF) { - /*struct HugeSectorBlock FAR *lb = MK_FP(r->ds, r->bx);*/ + /*struct HugeSectorBlock FAR *lb = MK_FP(r->ds, r->bx); */ blkno = ((struct HugeSectorBlock FAR *)buf)->blkno; nblks = ((struct HugeSectorBlock FAR *)buf)->nblks; - buf = ((struct HugeSectorBlock FAR *)buf)->buf; + buf = ((struct HugeSectorBlock FAR *)buf)->buf; } - InDOS++; - r->ax=dskxfer(drv, blkno, buf, nblks, mode); + r->ax = dskxfer(drv, blkno, buf, nblks, mode); if (mode == DSKWRITE) if (r->ax <= 0) - setinvld(drv); + setinvld(drv); if (r->ax > 0) { @@ -1891,20 +1900,17 @@ VOID ASMCFUNC int2526_handler(WORD mode, struct int25regs FAR * r) return; } - r->ax = 0; r->flags &= ~FLG_CARRY; --InDOS; - + } + /* VOID int25_handler(struct int25regs FAR * r) { int2526_handler(DSKREAD,r); } VOID int26_handler(struct int25regs FAR * r) { int2526_handler(DSKWRITE,r); } */ - - - #ifdef TSC static VOID StartTrace(VOID) { @@ -1926,188 +1932,186 @@ static VOID StartTrace(VOID) this function is called from an assembler wrapper function and serves the internal dos calls - int2f/12xx */ -struct int2f12regs -{ - UWORD es,ds; - UWORD di,si,bp,bx,dx,cx,ax; - UWORD ip,cs,flags; - UWORD callerARG1; /* used if called from INT2F/12 */ +struct int2f12regs { + UWORD es, ds; + UWORD di, si, bp, bx, dx, cx, ax; + UWORD ip, cs, flags; + UWORD callerARG1; /* used if called from INT2F/12 */ }; VOID ASMCFUNC int2F_12_handler(volatile struct int2f12regs r) -{ - UWORD function = r.ax & 0xff; - - if (function > 0x31) - return; - - switch(function) - { - case 0x00: /* installation check */ - r.ax |= 0x00ff; - break; +{ + UWORD function = r.ax & 0xff; - case 0x03: /* get DOS data segment */ - r.ds = FP_SEG(&nul_dev); - break; + if (function > 0x31) + return; - case 0x06: /* invoke critical error */ + switch (function) + { + case 0x00: /* installation check */ + r.ax |= 0x00ff; + break; - /* code, drive number, error, device header */ - r.ax &= 0xff00; - r.ax |= CriticalError( - r.callerARG1 >> 8, - (r.callerARG1 & (EFLG_CHAR << 8)) ? 0 : r.callerARG1 & 0xff, - r.di, - MK_FP(r.bp,r.si)); - break; - - case 0x08: /* decrease SFT reference count */ - { - sft FAR *p = MK_FP(r.es,r.di); - - r.ax = p->sft_count; - - if (--p->sft_count == 0) --p->sft_count; - } - break; + case 0x03: /* get DOS data segment */ + r.ds = FP_SEG(&nul_dev); + break; - case 0x0c: /* perform "device open" for device, set owner for FCB */ + case 0x06: /* invoke critical error */ - if (lpCurSft->sft_flags & SFT_FDEVICE) - { - request rq; + /* code, drive number, error, device header */ + r.ax &= 0xff00; + r.ax |= CriticalError(r.callerARG1 >> 8, + (r.callerARG1 & (EFLG_CHAR << 8)) ? 0 : r. + callerARG1 & 0xff, r.di, MK_FP(r.bp, r.si)); + break; - rq.r_unit = 0; - rq.r_status = 0; - rq.r_command = C_OPEN; - rq.r_length = sizeof(request); - execrh((request FAR *) & rq, lpCurSft->sft_dev); - } + case 0x08: /* decrease SFT reference count */ + { + sft FAR *p = MK_FP(r.es, r.di); - /* just do it always, not just for FCBs */ - lpCurSft->sft_psp = cu_psp; - break; + r.ax = p->sft_count; - case 0x0d: /* get dos date/time */ + if (--p->sft_count == 0) + --p->sft_count; + } + break; - r.ax = dos_getdate(); - r.dx = dos_gettime(); - break; - - case 0x12: /* get length of asciiz string */ - - r.cx = fstrlen(MK_FP(r.es, r.di))+1; - - break; + case 0x0c: /* perform "device open" for device, set owner for FCB */ + if (lpCurSft->sft_flags & SFT_FDEVICE) + { + request rq; - case 0x16: /* get address of system file table entry - used by NET.EXE - BX system file table entry number ( such as returned from 2F/1220) - returns - ES:DI pointer to SFT entry */ - { - sft FAR *p = get_sft(r.bx); - - r.es = FP_SEG(p); - r.di = FP_OFF(p); - break; - } + rq.r_unit = 0; + rq.r_status = 0; + rq.r_command = C_OPEN; + rq.r_length = sizeof(request); + execrh((request FAR *) & rq, lpCurSft->sft_dev); + } - case 0x17: /* get current directory structure for drive - used by NET.EXE - STACK: drive (0=A:,1=B,...) - ; returns - ; CF set if error - ; DS:SI pointer to CDS for drive - ; - ; called like - ; push 2 (c-drive) - ; mov ax,1217 - ; int 2f - ; - ; probable use: get sizeof(CDSentry) - */ - { - UWORD drv = r.callerARG1 & 0xff; - - if (drv >= lastdrive) - r.flags |= FLG_CARRY; - else - { - r.ds = FP_SEG(CDSp); - r.si = FP_OFF(&CDSp->cds_table[drv]); - r.flags &= ~FLG_CARRY; - } - break; - } + /* just do it always, not just for FCBs */ + lpCurSft->sft_psp = cu_psp; + break; - case 0x18: /* get caller's registers */ - - r.ds = FP_SEG(user_r); - r.si = FP_OFF(user_r); - break; + case 0x0d: /* get dos date/time */ - case 0x1b: /* #days in February - valid until 2099.*/ - - r.ax = (r.ax & 0xff00) | (r.cx & 3 ? 28 : 29); - break; - - case 0x21: /* truename */ - - truename(MK_FP(r.ds,r.si), MK_FP(r.es,r.di),0); - - break; - - case 0x23: /* check if character device */ - { - struct dhdr FAR *dhp; + r.ax = dos_getdate(); + r.dx = dos_gettime(); + break; - dhp = IsDevice((BYTE FAR *)DirEntBuffer.dir_name); + case 0x12: /* get length of asciiz string */ - if (dhp) - { - r.bx = (r.bx & 0xff) | (dhp->dh_attr <<8); - r.flags &= ~FLG_CARRY; - } - else { - r.flags |= FLG_CARRY; - } + r.cx = fstrlen(MK_FP(r.es, r.di)) + 1; - } + break; - break; + case 0x16: /* get address of system file table entry - used by NET.EXE + BX system file table entry number ( such as returned from 2F/1220) + returns + ES:DI pointer to SFT entry */ + { + sft FAR *p = get_sft(r.bx); - case 0x25: /* get length of asciiz string */ - - r.cx = fstrlen(MK_FP(r.ds, r.si))+1; - break; - + r.es = FP_SEG(p); + r.di = FP_OFF(p); + break; + } - case 0x2a: /* Set FastOpen but does nothing. */ - - r.flags &= ~FLG_CARRY; - break; + case 0x17: /* get current directory structure for drive - used by NET.EXE + STACK: drive (0=A:,1=B,...) + ; returns + ; CF set if error + ; DS:SI pointer to CDS for drive + ; + ; called like + ; push 2 (c-drive) + ; mov ax,1217 + ; int 2f + ; + ; probable use: get sizeof(CDSentry) + */ + { + UWORD drv = r.callerARG1 & 0xff; - case 0x2c: /* added by James Tabor For Zip Drives - Return Null Device Pointer */ - /* by UDOS+RBIL: get header of SECOND device driver in device chain, - omitting the NUL device TE*/ - r.bx = FP_SEG(nul_dev.dh_next); - r.ax = FP_OFF(nul_dev.dh_next); - - break; + if (drv >= lastdrive) + r.flags |= FLG_CARRY; + else + { + r.ds = FP_SEG(CDSp); + r.si = FP_OFF(&CDSp->cds_table[drv]); + r.flags &= ~FLG_CARRY; + } + break; + } - case 0x2e: /* GET or SET error table addresse - ignored - called by MS debug with DS != DOSDS, printf - doesn't work!! */ - break; + case 0x18: /* get caller's registers */ - default: - printf("unimplemented internal dos function INT2F/12%02x\n",function); - r.flags |= FLG_CARRY; - break; + r.ds = FP_SEG(user_r); + r.si = FP_OFF(user_r); + break; - } + case 0x1b: /* #days in February - valid until 2099. */ + + r.ax = (r.ax & 0xff00) | (r.cx & 3 ? 28 : 29); + break; + + case 0x21: /* truename */ + + truename(MK_FP(r.ds, r.si), MK_FP(r.es, r.di), 0); + + break; + + case 0x23: /* check if character device */ + { + struct dhdr FAR *dhp; + + dhp = IsDevice((BYTE FAR *) DirEntBuffer.dir_name); + + if (dhp) + { + r.bx = (r.bx & 0xff) | (dhp->dh_attr << 8); + r.flags &= ~FLG_CARRY; + } + else + { + r.flags |= FLG_CARRY; + } + + } + + break; + + case 0x25: /* get length of asciiz string */ + + r.cx = fstrlen(MK_FP(r.ds, r.si)) + 1; + break; + + case 0x2a: /* Set FastOpen but does nothing. */ + + r.flags &= ~FLG_CARRY; + break; + + case 0x2c: /* added by James Tabor For Zip Drives + Return Null Device Pointer */ + /* by UDOS+RBIL: get header of SECOND device driver in device chain, + omitting the NUL device TE */ + r.bx = FP_SEG(nul_dev.dh_next); + r.ax = FP_OFF(nul_dev.dh_next); + + break; + + case 0x2e: /* GET or SET error table addresse - ignored + called by MS debug with DS != DOSDS, printf + doesn't work!! */ + break; + + default: + printf("unimplemented internal dos function INT2F/12%02x\n", + function); + r.flags |= FLG_CARRY; + break; + + } } diff --git a/kernel/intr.h b/kernel/intr.h index 2b6fd90..5aa624e 100644 --- a/kernel/intr.h +++ b/kernel/intr.h @@ -2,8 +2,8 @@ */ struct REGPACK { - unsigned r_ax, r_bx, r_cx, r_dx; - unsigned r_bp, r_di, r_si, r_ds, r_es, r_flags; + unsigned r_ax, r_bx, r_cx, r_dx; + unsigned r_bp, r_di, r_si, r_ds, r_es, r_flags; }; extern void ASMCFUNC intr(int intrnr, struct REGPACK *rp); diff --git a/kernel/ioctl.c b/kernel/ioctl.c index d0f876a..f5a8dbe 100644 --- a/kernel/ioctl.c +++ b/kernel/ioctl.c @@ -30,7 +30,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif /* @@ -53,21 +54,18 @@ static BYTE *RcsId = "$Id$"; */ - COUNT DosDevIOctl(iregs FAR * r) { sft FAR *s; struct dpb FAR *dpbp; COUNT nMode; - /* commonly used, shouldn't harm to do front up */ + /* commonly used, shouldn't harm to do front up */ CharReqHdr.r_length = sizeof(request); - CharReqHdr.r_trans = MK_FP(r->DS, r->DX); + CharReqHdr.r_trans = MK_FP(r->DS, r->DX); CharReqHdr.r_status = 0; - CharReqHdr.r_count = r->CX; - - + CharReqHdr.r_count = r->CX; /* Test that the handle is valid */ switch (r->AL) @@ -106,7 +104,7 @@ COUNT DosDevIOctl(iregs FAR * r) /* JPP - changed to use default drive if drive=0 */ /* JT Fixed it */ - CharReqHdr.r_unit = ( r->BL == 0 ? default_drive : r->BL - 1); + CharReqHdr.r_unit = (r->BL == 0 ? default_drive : r->BL - 1); if (CharReqHdr.r_unit >= lastdrive) return DE_INVLDDRV; @@ -133,12 +131,12 @@ COUNT DosDevIOctl(iregs FAR * r) { case 0x00: /* Get the flags from the SFT */ - if (s->sft_flags & SFT_FDEVICE) - r->AX = (s->sft_dev->dh_attr & 0xff00) | s->sft_flags_lo; - else - r->AX = s->sft_flags; + if (s->sft_flags & SFT_FDEVICE) + r->AX = (s->sft_dev->dh_attr & 0xff00) | s->sft_flags_lo; + else + r->AX = s->sft_flags; /* Undocumented result, Ax = Dx seen using Pcwatch */ - r->DX = r->AX; + r->DX = r->AX; break; case 0x01: @@ -165,36 +163,36 @@ COUNT DosDevIOctl(iregs FAR * r) nMode = C_IOCTLOUT; IoCharCommon: if ((s->sft_flags & SFT_FDEVICE) - || ((r->AL == 0x02 ) && (s->sft_dev->dh_attr & SFT_FIOCTL)) - || ((r->AL == 0x03 ) && (s->sft_dev->dh_attr & SFT_FIOCTL)) - || ((r->AL == 0x10) && (s->sft_dev->dh_attr & ATTR_QRYIOCTL)) - || ((r->AL == 0x0c) && (s->sft_dev->dh_attr & ATTR_GENIOCTL))) + || ((r->AL == 0x02) && (s->sft_dev->dh_attr & SFT_FIOCTL)) + || ((r->AL == 0x03) && (s->sft_dev->dh_attr & SFT_FIOCTL)) + || ((r->AL == 0x10) && (s->sft_dev->dh_attr & ATTR_QRYIOCTL)) + || ((r->AL == 0x0c) && (s->sft_dev->dh_attr & ATTR_GENIOCTL))) { - CharReqHdr.r_unit = 0; - CharReqHdr.r_command = nMode; - execrh((request FAR *) & CharReqHdr, s->sft_dev); + CharReqHdr.r_unit = 0; + CharReqHdr.r_command = nMode; + execrh((request FAR *) & CharReqHdr, s->sft_dev); - if (CharReqHdr.r_status & S_ERROR) - { - CritErrCode = (CharReqHdr.r_status & S_MASK) + 0x13; - return DE_DEVICE; - } + if (CharReqHdr.r_status & S_ERROR) + { + CritErrCode = (CharReqHdr.r_status & S_MASK) + 0x13; + return DE_DEVICE; + } - if (r->AL == 0x07) - { - r->AL = CharReqHdr.r_status & S_BUSY ? 00 : 0xff; + if (r->AL == 0x07) + { + r->AL = CharReqHdr.r_status & S_BUSY ? 00 : 0xff; - } - else if (r->AL == 0x02 || r->AL == 0x03) - { - r->AX = CharReqHdr.r_count; - } + } + else if (r->AL == 0x02 || r->AL == 0x03) + { + r->AX = CharReqHdr.r_count; + } - else if (r->AL == 0x0c || r->AL == 0x10) - { - r->AX = CharReqHdr.r_status; - } - break; + else if (r->AL == 0x0c || r->AL == 0x10) + { + r->AX = CharReqHdr.r_status; + } + break; } return DE_INVLDFUNC; @@ -210,44 +208,44 @@ COUNT DosDevIOctl(iregs FAR * r) case 0x05: nMode = C_IOCTLOUT; IoBlockCommon: - if(!dpbp) + if (!dpbp) { return DE_INVLDDRV; } - if ( ((r->AL == 0x04 ) && !(dpbp->dpb_device->dh_attr & ATTR_IOCTL)) - || ((r->AL == 0x05 ) && !(dpbp->dpb_device->dh_attr & ATTR_IOCTL)) - || ((r->AL == 0x11) && !(dpbp->dpb_device->dh_attr & ATTR_QRYIOCTL)) - || ((r->AL == 0x0d) && !(dpbp->dpb_device->dh_attr & ATTR_GENIOCTL))) + if (((r->AL == 0x04) && !(dpbp->dpb_device->dh_attr & ATTR_IOCTL)) + || ((r->AL == 0x05) && !(dpbp->dpb_device->dh_attr & ATTR_IOCTL)) + || ((r->AL == 0x11) + && !(dpbp->dpb_device->dh_attr & ATTR_QRYIOCTL)) + || ((r->AL == 0x0d) + && !(dpbp->dpb_device->dh_attr & ATTR_GENIOCTL))) { return DE_INVLDFUNC; } - CharReqHdr.r_command = nMode; - execrh((request FAR *) & CharReqHdr, - dpbp->dpb_device); + execrh((request FAR *) & CharReqHdr, dpbp->dpb_device); - if (CharReqHdr.r_status & S_ERROR) - { - CritErrCode = (CharReqHdr.r_status & S_MASK) + 0x13; - return DE_DEVICE; - } - if (r->AL == 0x08) - { - r->AX = (CharReqHdr.r_status & S_BUSY) ? 1 : 0; + if (CharReqHdr.r_status & S_ERROR) + { + CritErrCode = (CharReqHdr.r_status & S_MASK) + 0x13; + return DE_DEVICE; + } + if (r->AL == 0x08) + { + r->AX = (CharReqHdr.r_status & S_BUSY) ? 1 : 0; - } + } - else if (r->AL == 0x04 || r->AL == 0x05) - { - r->AX = CharReqHdr.r_count; + else if (r->AL == 0x04 || r->AL == 0x05) + { + r->AX = CharReqHdr.r_count; - } - else if (r->AL == 0x0d || r->AL == 0x11) - { - r->AX = CharReqHdr.r_status; - } - break; + } + else if (r->AL == 0x0d || r->AL == 0x11) + { + r->AX = CharReqHdr.r_status; + } + break; case 0x06: if (s->sft_flags & SFT_FDEVICE) @@ -268,7 +266,7 @@ COUNT DosDevIOctl(iregs FAR * r) break; case 0x08: - if(!dpbp) + if (!dpbp) { return DE_INVLDDRV; } @@ -280,21 +278,21 @@ COUNT DosDevIOctl(iregs FAR * r) return DE_INVLDFUNC; case 0x09: - if(CDSp->cds_table[CharReqHdr.r_unit].cdsFlags & CDSNETWDRV) + if (CDSp->cds_table[CharReqHdr.r_unit].cdsFlags & CDSNETWDRV) + { + r->DX = ATTR_REMOTE; + r->AX = S_DONE | S_BUSY; + } + else + { + if (!dpbp) { - r->DX = ATTR_REMOTE ; - r->AX = S_DONE|S_BUSY; + return DE_INVLDDRV; } - else - { - if(!dpbp) - { - return DE_INVLDDRV; - } /* Need to add subst bit 15 */ - r->DX = dpbp->dpb_device->dh_attr; - r->AX = S_DONE|S_BUSY; - } + r->DX = dpbp->dpb_device->dh_attr; + r->AX = S_DONE | S_BUSY; + } break; case 0x0a: @@ -308,17 +306,15 @@ COUNT DosDevIOctl(iregs FAR * r) case 0x0f: nMode = C_SETLDEV; IoLogCommon: - if(!dpbp) + if (!dpbp) { return DE_INVLDDRV; } if ((dpbp->dpb_device->dh_attr & ATTR_GENIOCTL)) { - CharReqHdr.r_command = nMode; - execrh((request FAR *) & CharReqHdr, - dpbp->dpb_device); + execrh((request FAR *) & CharReqHdr, dpbp->dpb_device); if (CharReqHdr.r_status & S_ERROR) { @@ -327,8 +323,8 @@ COUNT DosDevIOctl(iregs FAR * r) } else { - r->AL = CharReqHdr.r_unit; - return SUCCESS; + r->AL = CharReqHdr.r_unit; + return SUCCESS; } } return DE_INVLDFUNC; @@ -391,6 +387,3 @@ COUNT DosDevIOctl(iregs FAR * r) * Rev 1.0 02 Jul 1995 8:32:04 patv * Initial revision. */ - - - diff --git a/kernel/lfnapi.c b/kernel/lfnapi.c index b25b5f0..7a1c40c 100644 --- a/kernel/lfnapi.c +++ b/kernel/lfnapi.c @@ -10,7 +10,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *lfnaidRcsId = "$Id$"; +static BYTE *lfnaidRcsId = + "$Id$"; #endif #ifdef WITHLFNAPI @@ -27,7 +28,7 @@ static BYTE *lfnaidRcsId = "$Id$"; #define CHARS_IN_LFN_ENTRY 13 #define UNICODE_FILLER 0xffff -COUNT ufstrlen(REG UNICODE FAR *); /* fstrlen for UNICODE strings */ +COUNT ufstrlen(REG UNICODE FAR *); /* fstrlen for UNICODE strings */ UBYTE lfn_checksum(UBYTE *); COUNT extend_dir(f_node_ptr); COUNT remove_lfn_entries(f_node_ptr fnp); @@ -36,23 +37,24 @@ COUNT lfn_allocate_inode(VOID) { f_node_ptr fnp = get_f_node(); struct cds FAR *cdsp; - if (fnp == 0) return LHE_NOFREEHNDL; + if (fnp == 0) + return LHE_NOFREEHNDL; cdsp = &CDSp->cds_table[default_drive]; if (cdsp->cdsDpb == 0) - { - release_f_node(fnp); - return LHE_INVLDDRV; - } + { + release_f_node(fnp); + return LHE_INVLDDRV; + } fnp->f_dpb = cdsp->cdsDpb; if (media_check(fnp->f_dpb) < 0) - { - release_f_node(fnp); - return LHE_INVLDDRV; - } + { + release_f_node(fnp); + return LHE_INVLDDRV; + } return xlt_fnp(fnp); } @@ -60,7 +62,8 @@ COUNT lfn_allocate_inode(VOID) COUNT lfn_free_inode(COUNT handle) { f_node_ptr fnp = xlt_fd(handle); - if (fnp == 0 || fnp->f_count <= 0) return LHE_INVLDHNDL; + if (fnp == 0 || fnp->f_count <= 0) + return LHE_INVLDHNDL; release_f_node(fnp); @@ -70,7 +73,8 @@ COUNT lfn_free_inode(COUNT handle) COUNT lfn_setup_inode(COUNT handle, CLUSTER dirstart, ULONG diroff) { f_node_ptr fnp = xlt_fd(handle); - if (fnp == 0 || fnp->f_count <= 0) return LHE_INVLDHNDL; + if (fnp == 0 || fnp->f_count <= 0) + return LHE_INVLDHNDL; dir_init_fnode(fnp, dirstart); fnp->f_diroff = diroff; @@ -78,39 +82,46 @@ COUNT lfn_setup_inode(COUNT handle, CLUSTER dirstart, ULONG diroff) return SUCCESS; } -BOOL transfer_unicode(UNICODE FAR **dptr, UNICODE FAR **sptr, COUNT count) +BOOL transfer_unicode(UNICODE FAR ** dptr, UNICODE FAR ** sptr, + COUNT count) { COUNT j; BOOL found_zerro = FALSE; for (j = 0; j < count; j++, (*dptr)++, (*sptr)++) - { - if (found_zerro) **dptr = UNICODE_FILLER; - else **dptr = **sptr; - if (**sptr == 0) found_zerro = TRUE; - } + { + if (found_zerro) + **dptr = UNICODE_FILLER; + else + **dptr = **sptr; + if (**sptr == 0) + found_zerro = TRUE; + } return found_zerro; } -BOOL lfn_to_unicode(UNICODE FAR **name, struct lfn_entry FAR *lep) +BOOL lfn_to_unicode(UNICODE FAR ** name, struct lfn_entry FAR * lep) { UNICODE FAR *ptr; - + ptr = lep->lfn_name0_4; - if (!transfer_unicode(name, &ptr, 5)) return FALSE; + if (!transfer_unicode(name, &ptr, 5)) + return FALSE; ptr = lep->lfn_name5_10; - if (!transfer_unicode(name, &ptr, 6)) return FALSE; + if (!transfer_unicode(name, &ptr, 6)) + return FALSE; ptr = lep->lfn_name11_12; - if (!transfer_unicode(name, &ptr, 2)) return FALSE; + if (!transfer_unicode(name, &ptr, 2)) + return FALSE; return TRUE; } -VOID unicode_to_lfn(UNICODE FAR **name, struct lfn_entry FAR *lep) +VOID unicode_to_lfn(UNICODE FAR ** name, struct lfn_entry FAR * lep) { UNICODE FAR *ptr; - + ptr = lep->lfn_name0_4; transfer_unicode(&ptr, name, 5); ptr = lep->lfn_name5_10; @@ -127,45 +138,54 @@ COUNT lfn_dir_read(COUNT handle, lfn_inode_ptr lip) ULONG sfn_diroff; BOOL name_tail = FALSE; f_node_ptr fnp = xlt_fd(handle); - if (fnp == 0 || fnp->f_count <= 0) return LHE_INVLDHNDL; + if (fnp == 0 || fnp->f_count <= 0) + return LHE_INVLDHNDL; while (TRUE) + { + rc = dir_read(fnp); + if (rc == 0) + return SUCCESS; + else if (rc == DE_SEEK) + return LHE_SEEK; + else if (rc == DE_BLKINVLD) + return LHE_IOERROR; + if (fnp->f_dir.dir_name[0] != DELETED + && fnp->f_dir.dir_attrib != D_LFN) { - rc = dir_read(fnp); - if (rc == 0) return SUCCESS; - else if (rc == DE_SEEK) return LHE_SEEK; - else if (rc == DE_BLKINVLD) return LHE_IOERROR; - if (fnp->f_dir.dir_name[0] != DELETED && fnp->f_dir.dir_attrib != D_LFN) - { - fmemcpy(&lip->l_dir, &fnp->f_dir, sizeof(struct dirent)); - sfn_diroff = fnp->f_diroff; - break; - } - } + fmemcpy(&lip->l_dir, &fnp->f_dir, sizeof(struct dirent)); + sfn_diroff = fnp->f_diroff; + break; + } + } fnp->f_diroff = lip->l_diroff; fmemset(lip->name, 0, 256 * sizeof(UNICODE)); while (TRUE) + { + if (fnp->f_diroff == 0) + break; + fnp->f_diroff -= 2 * DIRENT_SIZE; + rc = dir_read(fnp); + if (rc == DE_BLKINVLD) + return LHE_IOERROR; + if (fnp->f_dir.dir_name[0] == DELETED + || fnp->f_dir.dir_attrib != D_LFN) + break; + name_tail = lfn_to_unicode(&lfn_name, lfn(fnp)); + real_id = lfn(fnp)->lfn_id; + if (real_id & 0x40) { - if (fnp->f_diroff == 0) break; - fnp->f_diroff -= 2*DIRENT_SIZE; - rc = dir_read(fnp); - if (rc == DE_BLKINVLD) return LHE_IOERROR; - if (fnp->f_dir.dir_name[0] == DELETED - || fnp->f_dir.dir_attrib != D_LFN) break; - name_tail = lfn_to_unicode(&lfn_name, lfn(fnp)); - real_id = lfn(fnp)->lfn_id; - if (real_id & 0x40) - { - if ((real_id | 0x40) != id) return LHE_DAMAGEDFS; - } - else - { - if (name_tail || real_id != id - || lfn(fnp)->lfn_checksum != lfn_checksum(fnp->f_dir.dir_name)) - return LHE_DAMAGEDFS; - } + if ((real_id | 0x40) != id) + return LHE_DAMAGEDFS; } + else + { + if (name_tail || real_id != id + || lfn(fnp)->lfn_checksum != lfn_checksum(fnp->f_dir.dir_name)) + return LHE_DAMAGEDFS; + } + } fnp->f_diroff = lip->l_diroff = sfn_diroff; fnp->f_flags.f_dnew = TRUE; @@ -176,16 +196,17 @@ COUNT lfn_dir_read(COUNT handle, lfn_inode_ptr lip) COUNT lfn_dir_write(COUNT handle) { f_node_ptr fnp = xlt_fd(handle); - if (fnp == 0 || fnp->f_count <= 0) return LHE_INVLDHNDL; + if (fnp == 0 || fnp->f_count <= 0) + return LHE_INVLDHNDL; if (!dir_write(fnp)) - { - lfn_allocate_inode(); /* protection against dir_write fault - * this must restore things to the state before - * the call */ - /* Yes, it's a hack! */ - return LHE_IOERROR; - } + { + lfn_allocate_inode(); /* protection against dir_write fault + * this must restore things to the state before + * the call */ + /* Yes, it's a hack! */ + return LHE_IOERROR; + } return SUCCESS; } @@ -196,52 +217,58 @@ COUNT lfn_create_entries(COUNT handle, lfn_inode_ptr lip) COUNT entries_needed, free_entries, i, rc; UNICODE FAR *lfn_name = lip->name; ULONG sfn_offset; - if (fnp == 0 || fnp->f_count <= 0) return LHE_INVLDHNDL; + if (fnp == 0 || fnp->f_count <= 0) + return LHE_INVLDHNDL; + + entries_needed = (ufstrlen(lfn_name) + CHARS_IN_LFN_ENTRY - 1) / CHARS_IN_LFN_ENTRY + 1; /* We want to create SFN entry too */ - entries_needed = (ufstrlen(lfn_name) + CHARS_IN_LFN_ENTRY - 1) - / CHARS_IN_LFN_ENTRY + 1; /* We want to create SFN entry too */ - /* Scan the directory from the very begining for the free directory entries */ lfn_setup_inode(handle, fnp->f_dirstart, 0); free_entries = 0; while ((rc = dir_read(fnp)) == 1) + { + if (fnp->f_dir.dir_name[0] == DELETED) { - if (fnp->f_dir.dir_name[0] == DELETED) - { - free_entries++; - if (free_entries == entries_needed) - break; - } - else free_entries = 0; + free_entries++; + if (free_entries == entries_needed) + break; } - if (rc == DE_BLKINVLD) return LHE_IOERROR; + else + free_entries = 0; + } + if (rc == DE_BLKINVLD) + return LHE_IOERROR; /* We have reached the end of the directory here. */ - - if (free_entries != entries_needed) free_entries = 0; + + if (free_entries != entries_needed) + free_entries = 0; while (free_entries != entries_needed) + { + rc = dir_read(fnp); + if (rc == 0) + free_entries++; + else if (rc == DE_BLKINVLD) + return LHE_IOERROR; + else if (rc == DE_SEEK && extend_dir(fnp) != SUCCESS) { - rc = dir_read(fnp); - if (rc == 0) free_entries++; - else if (rc == DE_BLKINVLD) return LHE_IOERROR; - else if (rc == DE_SEEK && extend_dir(fnp) != SUCCESS) - { - lfn_allocate_inode(); /* Another hack. */ - return LHE_IOERROR; - } + lfn_allocate_inode(); /* Another hack. */ + return LHE_IOERROR; } + } sfn_offset = fnp->f_diroff; fnp->f_diroff -= DIRENT_SIZE; for (i = entries_needed - 2; i >= 0; i++) - { - lfn_name = &lip->name[i * CHARS_IN_LFN_ENTRY]; - unicode_to_lfn(&lfn_name, lfn(fnp)); - fnp->f_dir.dir_attrib = D_LFN; - if (!dir_write(fnp)) return LHE_IOERROR; - fnp->f_diroff -= DIRENT_SIZE; - } - + { + lfn_name = &lip->name[i * CHARS_IN_LFN_ENTRY]; + unicode_to_lfn(&lfn_name, lfn(fnp)); + fnp->f_dir.dir_attrib = D_LFN; + if (!dir_write(fnp)) + return LHE_IOERROR; + fnp->f_diroff -= DIRENT_SIZE; + } + fnp->f_diroff = sfn_offset; return SUCCESS; @@ -250,15 +277,17 @@ COUNT lfn_create_entries(COUNT handle, lfn_inode_ptr lip) COUNT lfn_remove_entries(COUNT handle) { f_node_ptr fnp = xlt_fd(handle); - if (fnp == 0 || fnp->f_count <= 0) return LHE_INVLDHNDL; + if (fnp == 0 || fnp->f_count <= 0) + return LHE_INVLDHNDL; + + if (remove_lfn_entries(fnp) < 0) + return LHE_IOERROR; - if(remove_lfn_entries(fnp) < 0) return LHE_IOERROR; - return SUCCESS; } /* Calculate checksum for the 8.3 name */ -UBYTE lfn_checksum(UBYTE *sfn_name) +UBYTE lfn_checksum(UBYTE * sfn_name) { UBYTE sum; COUNT i; @@ -269,7 +298,7 @@ UBYTE lfn_checksum(UBYTE *sfn_name) return sum; } -COUNT ufstrlen(REG UNICODE FAR *s) +COUNT ufstrlen(REG UNICODE FAR * s) { REG COUNT cnt = 0; diff --git a/kernel/main.c b/kernel/main.c index f7d0cb3..322664b 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -30,16 +30,15 @@ #include "portab.h" #include "init-mod.h" #include "dyndata.h" -#include "init-dat.h" +#include "init-dat.h" -GLOBAL BYTE copyright[] = +GLOBAL BYTE copyright[] = "(C) Copyright 1995-2001 Pasquale J. Villani and The FreeDOS Project.\n" "All Rights Reserved. This is free software and comes with ABSOLUTELY NO\n" "WARRANTY; you can redistribute it and/or modify it under the terms of the\n" "GNU General Public License as published by the Free Software Foundation;\n" "either version 2, or (at your option) any later version.\n"; - /* These are the far variables from the DOS data segment that we need here. The init procedure uses a different default DS data segment, which is discarded @@ -48,45 +47,41 @@ GLOBAL BYTE copyright[] = -- Bart */ -extern UBYTE DOSFAR nblkdev, - DOSFAR lastdrive; /* value of last drive */ +extern UBYTE DOSFAR nblkdev, DOSFAR lastdrive; /* value of last drive */ -GLOBAL BYTE - DOSFAR os_major, /* major version number */ - DOSFAR os_minor, /* minor version number */ - DOSFAR dosidle_flag, - DOSFAR BootDrive, /* Drive we came up from */ - DOSFAR default_drive; /* default drive for dos */ +GLOBAL BYTE DOSFAR os_major, /* major version number */ + DOSFAR os_minor, /* minor version number */ + DOSFAR dosidle_flag, DOSFAR BootDrive, /* Drive we came up from */ + DOSFAR default_drive; /* default drive for dos */ GLOBAL BYTE DOSFAR os_release[]; /* GLOBAL BYTE DOSFAR copyright[]; */ -GLOBAL seg DOSFAR RootPsp; /* Root process -- do not abort */ +GLOBAL seg DOSFAR RootPsp; /* Root process -- do not abort */ -extern struct dpb FAR * DOSFAR DPBp; /* First drive Parameter Block */ -extern cdstbl FAR * DOSFAR CDSp; /* Current Directory Structure */ +extern struct dpb FAR *DOSFAR DPBp; /* First drive Parameter Block */ +extern cdstbl FAR *DOSFAR CDSp; /* Current Directory Structure */ -extern struct dhdr FAR * DOSFAR clock, /* CLOCK$ device */ - FAR * DOSFAR syscon; /* console device */ -extern struct dhdr DOSTEXTFAR con_dev, /* console device drive */ - DOSTEXTFAR clk_dev, /* Clock device driver */ - DOSTEXTFAR blk_dev; /* Block device (Disk) driver */ -extern UWORD - DOSFAR ram_top; /* How much ram in Kbytes */ -extern iregs FAR * DOSFAR user_r; /* User registers for int 21h call */ +extern struct dhdr FAR *DOSFAR clock, /* CLOCK$ device */ + FAR * DOSFAR syscon; /* console device */ +extern struct dhdr DOSTEXTFAR con_dev, /* console device drive */ + DOSTEXTFAR clk_dev, /* Clock device driver */ + DOSTEXTFAR blk_dev; /* Block device (Disk) driver */ +extern UWORD DOSFAR ram_top; /* How much ram in Kbytes */ +extern iregs FAR *DOSFAR user_r; /* User registers for int 21h call */ extern BYTE FAR _HMATextEnd[]; #ifdef VERSION_STRINGS -static BYTE *mainRcsId = "$Id$"; +static BYTE *mainRcsId = + "$Id$"; #endif -struct _KernelConfig InitKernelConfig = {"", 0, 0, 0, 0, 0, 0}; - +struct _KernelConfig InitKernelConfig = { "", 0, 0, 0, 0, 0, 0 }; extern WORD days[2][13]; -extern BYTE FAR * lpBase; -extern BYTE FAR * lpOldTop; -extern BYTE FAR * lpTop; -extern BYTE FAR * upBase; +extern BYTE FAR *lpBase; +extern BYTE FAR *lpOldTop; +extern BYTE FAR *lpTop; +extern BYTE FAR *upBase; extern BYTE _ib_start[], _ib_end[], _init_end[]; INIT VOID configDone(VOID); @@ -100,38 +95,36 @@ INIT VOID FsConfig(VOID); INIT VOID InitPrinters(VOID); #ifdef _MSC_VER - BYTE _acrtused = 0; -#endif - -#ifdef _MSC_VER -__segment DosDataSeg = 0; /* serves for all references to the DOS DATA segment - necessary for MSC+our funny linking model - */ -__segment DosTextSeg = 0; - +BYTE _acrtused = 0; #endif +#ifdef _MSC_VER +__segment DosDataSeg = 0; /* serves for all references to the DOS DATA segment + necessary for MSC+our funny linking model + */ +__segment DosTextSeg = 0; + +#endif INIT VOID ASMCFUNC FreeDOSmain(void) { -#ifdef _MSC_VER - extern FAR DATASTART; - extern FAR prn_dev; - DosDataSeg = (__segment)&DATASTART; - DosTextSeg = (__segment)&prn_dev; -#endif +#ifdef _MSC_VER + extern FAR DATASTART; + extern FAR prn_dev; + DosDataSeg = (__segment) & DATASTART; + DosTextSeg = (__segment) & prn_dev; +#endif - fmemcpy(&InitKernelConfig,&LowKernelConfig,sizeof(InitKernelConfig)); + fmemcpy(&InitKernelConfig, &LowKernelConfig, sizeof(InitKernelConfig)); + + setvec(0, int0_handler); /* zero divide */ + setvec(1, empty_handler); /* single step */ + setvec(3, empty_handler); /* debug breakpoint */ + setvec(6, empty_handler); /* invalid opcode */ + + /* clear the Init BSS area (what normally the RTL does */ + memset(_ib_start, 0, _ib_end - _ib_start); - - setvec(0, int0_handler); /* zero divide */ - setvec(1, empty_handler); /* single step */ - setvec(3, empty_handler); /* debug breakpoint */ - setvec(6, empty_handler); /* invalid opcode */ - - /* clear the Init BSS area (what normally the RTL does */ - memset(_ib_start, 0, _ib_end - _ib_start); - init_kernel(); #ifdef DEBUG @@ -155,19 +148,19 @@ INIT VOID ASMCFUNC FreeDOSmain(void) void InitializeAllBPBs(VOID) { static char filename[] = "A:-@JUNK@-.TMP"; - int drive,fileno; - for (drive = 'C'; drive < 'A'+nblkdev; drive++) - { - filename[0] = drive; - if ((fileno = open(filename, O_RDONLY)) >= 0) - close(fileno); - } -} + int drive, fileno; + for (drive = 'C'; drive < 'A' + nblkdev; drive++) + { + filename[0] = drive; + if ((fileno = open(filename, O_RDONLY)) >= 0) + close(fileno); + } +} INIT void init_kernel(void) { COUNT i; - + os_major = MAJOR_RELEASE; os_minor = MINOR_RELEASE; @@ -175,14 +168,14 @@ INIT void init_kernel(void) ram_top = init_oem(); /* move kernel to high conventional RAM, just below the init code */ - lpTop = MK_FP(ram_top * 64 - (FP_OFF(_init_end)+15)/16 - - (FP_OFF(_HMATextEnd)+15)/16, 0); - + lpTop = MK_FP(ram_top * 64 - (FP_OFF(_init_end) + 15) / 16 - + (FP_OFF(_HMATextEnd) + 15) / 16, 0); + MoveKernel(FP_SEG(lpTop)); lpOldTop = lpTop = MK_FP(FP_SEG(lpTop) - 0xfff, 0xfff0); /* Fake int 21h stack frame */ - user_r = (iregs FAR *) MK_FP(DOS_PSP,0xD0); + user_r = (iregs FAR *) MK_FP(DOS_PSP, 0xD0); #ifndef KDB for (i = 0x20; i <= 0x3f; i++) @@ -223,7 +216,7 @@ INIT void init_kernel(void) /* Number of units */ if (blk_dev.dh_name[0] > 0) - update_dcb(&blk_dev); + update_dcb(&blk_dev); /* Now config the temporary file system */ FsConfig(); @@ -235,7 +228,7 @@ INIT void init_kernel(void) /* Close all (device) files */ for (i = 0; i < lastdrive; i++) close(i); - + /* and do final buffer allocation. */ PostConfig(); nblkdev = 0; @@ -251,7 +244,7 @@ INIT void init_kernel(void) /* Close all (device) files */ for (i = 0; i < lastdrive; i++) close(i); - + /* Now config the final file system */ FsConfig(); @@ -274,7 +267,7 @@ INIT VOID FsConfig(VOID) dup2(STDIN, STDOUT); /* 2 is /dev/con (stderr) */ - dup2(STDIN, STDERR); + dup2(STDIN, STDERR); /* 3 is /dev/aux */ open("AUX", O_RDWR); @@ -288,15 +281,15 @@ INIT VOID FsConfig(VOID) dpb = DPBp; /* Initialize the current directory structures */ - for (i = 0; i < lastdrive ; i++) + for (i = 0; i < lastdrive; i++) { - struct cds FAR *pcds_table = &CDSp->cds_table[i]; + struct cds FAR *pcds_table = &CDSp->cds_table[i]; fmemcpy(pcds_table->cdsCurrentPath, "A:\\\0", 4); pcds_table->cdsCurrentPath[0] += i; - if (i < nblkdev && (ULONG)dpb != 0xffffffffl) + if (i < nblkdev && (ULONG) dpb != 0xffffffffl) { pcds_table->cdsDpb = dpb; pcds_table->cdsFlags = CDSPHYSDRV; @@ -318,39 +311,36 @@ INIT VOID FsConfig(VOID) INIT VOID signon() { - printf("\n%S" ,(void FAR *)os_release); + printf("\n%S", (void FAR *)os_release); - printf("Kernel compatibility %d.%d", - os_major, os_minor ); + printf("Kernel compatibility %d.%d", os_major, os_minor); #if defined(__TURBOC__) - printf(" - TURBOC"); + printf(" - TURBOC"); #elif defined(_MSC_VER) - printf(" - MSC"); + printf(" - MSC"); #elif defined(__WATCOMC__) - printf(" - WATCOMC"); + printf(" - WATCOMC"); #else - generate some bullshit error here, as the compiler should be known + generate some bullshit error here, as the compiler should be known +#endif +#if defined (I386) + printf(" - 80386 CPU required"); +#elif defined (I186) + printf(" - 80186 CPU required"); #endif -#if defined (I386) - printf(" - 80386 CPU required"); -#elif defined (I186) - printf(" - 80186 CPU required"); -#endif - #ifdef WITHFAT32 - printf(" - FAT32 support"); -#endif - printf("\n\n%S",(void FAR *)copyright); + printf(" - FAT32 support"); +#endif + printf("\n\n%S", (void FAR *)copyright); } INIT void kernel() { -#if 0 - BYTE FAR *ep, - *sp; -#endif +#if 0 + BYTE FAR *ep, *sp; +#endif exec_blk exb; CommandTail Cmd; int rc; @@ -365,7 +355,7 @@ INIT void kernel() #else #if 0 /* create the master environment area */ - + if (allocmem(0x2, &exb.exec.env_seg)) init_fatal("cannot allocate master environment space"); @@ -381,67 +371,60 @@ INIT void kernel() *((int FAR *)ep) = 0; ep += sizeof(int); #else - exb.exec.env_seg = DOS_PSP+8; + exb.exec.env_seg = DOS_PSP + 8; fmemcpy(MK_FP(exb.exec.env_seg, 0), master_env, sizeof(master_env)); -#endif -#endif +#endif +#endif - RootPsp = ~0; - - /* process 0 */ /* Execute command.com /P from the drive we just booted from */ - fstrncpy(Cmd.ctBuffer, Config.cfgInitTail, - sizeof(Config.cfgInitTail)-1); + fstrncpy(Cmd.ctBuffer, Config.cfgInitTail, + sizeof(Config.cfgInitTail) - 1); for (Cmd.ctCount = 0; Cmd.ctCount < 127; Cmd.ctCount++) if (Cmd.ctBuffer[Cmd.ctCount] == '\r') break; - - - - /* if stepping CONFIG.SYS (F5/F8), tell COMMAND.COM about it */ + /* if stepping CONFIG.SYS (F5/F8), tell COMMAND.COM about it */ if (Cmd.ctCount < 127 - 3) - { - extern int singleStep ; - extern int SkipAllConfig; - char *insertString = NULL; + { + extern int singleStep; + extern int SkipAllConfig; + char *insertString = NULL; - if (singleStep) insertString = " /Y"; /* single step AUTOEXEC */ - - if (SkipAllConfig) insertString = " /D"; /* disable AUTOEXEC */ - - if (insertString) + if (singleStep) + insertString = " /Y"; /* single step AUTOEXEC */ + + if (SkipAllConfig) + insertString = " /D"; /* disable AUTOEXEC */ + + if (insertString) + { + + /* insert /D, /Y as first argument */ + int cmdEnd, i, slen = strlen(insertString); + + for (cmdEnd = 0; cmdEnd < 127; cmdEnd++) { - - /* insert /D, /Y as first argument */ - int cmdEnd,i,slen = strlen(insertString); - - for (cmdEnd = 0;cmdEnd < 127; cmdEnd++) + if (Cmd.ctBuffer[cmdEnd] == ' ' || + Cmd.ctBuffer[cmdEnd] == '\t' || Cmd.ctBuffer[cmdEnd] == '\r') { - if (Cmd.ctBuffer[cmdEnd] == ' ' || - Cmd.ctBuffer[cmdEnd] == '\t' || - Cmd.ctBuffer[cmdEnd] == '\r') - { - for (i = 127 - slen; i >= cmdEnd; i--) - Cmd.ctBuffer[i+slen] = Cmd.ctBuffer[i]; - - fmemcpy(&Cmd.ctBuffer[cmdEnd], insertString,slen); + for (i = 127 - slen; i >= cmdEnd; i--) + Cmd.ctBuffer[i + slen] = Cmd.ctBuffer[i]; - Cmd.ctCount += slen; + fmemcpy(&Cmd.ctBuffer[cmdEnd], insertString, slen); - break; - } + Cmd.ctCount += slen; + + break; } - } + } + } } - - exb.exec.cmd_line = (CommandTail FAR *) & Cmd; exb.exec.fcb_1 = exb.exec.fcb_2 = (fcb FAR *) 0; @@ -449,13 +432,17 @@ INIT void kernel() printf("Process 0 starting: %s\n\n", Config.cfgInit); #endif - while ((rc = init_DosExec(Config.cfgP_0_startmode, &exb, Config.cfgInit)) != SUCCESS) + while ((rc = + init_DosExec(Config.cfgP_0_startmode, &exb, + Config.cfgInit)) != SUCCESS) { BYTE *pLine; - printf("\nBad or missing Command Interpreter: %d - %s\n", rc, Cmd.ctBuffer); - printf("\nPlease enter the correct location (for example C:\\COMMAND.COM):\n"); - rc = read(STDIN, Cmd.ctBuffer, sizeof(Cmd.ctBuffer)-1); - Cmd.ctBuffer[rc]='\0'; + printf("\nBad or missing Command Interpreter: %d - %s\n", rc, + Cmd.ctBuffer); + printf + ("\nPlease enter the correct location (for example C:\\COMMAND.COM):\n"); + rc = read(STDIN, Cmd.ctBuffer, sizeof(Cmd.ctBuffer) - 1); + Cmd.ctBuffer[rc] = '\0'; /* Get the string argument that represents the new init pgm */ pLine = GetStringArg(Cmd.ctBuffer, Config.cfgInit); @@ -466,8 +453,8 @@ INIT void kernel() /* and add a DOS new line just to be safe */ strcat(Cmd.ctBuffer, "\r\n"); - - Cmd.ctCount = rc-(pLine-Cmd.ctBuffer); + + Cmd.ctCount = rc - (pLine - Cmd.ctBuffer); #ifdef DEBUG printf("Process 0 starting: %s\n\n", Config.cfgInit); @@ -484,17 +471,20 @@ static VOID update_dcb(struct dhdr FAR * dhp) COUNT nunits = dhp->dh_name[0]; struct dpb FAR *dpb; - if (nblkdev==0) + if (nblkdev == 0) dpb = DPBp; - else { - for (dpb = DPBp; (ULONG)dpb->dpb_next != 0xffffffffl; dpb = dpb->dpb_next) + else + { + for (dpb = DPBp; (ULONG) dpb->dpb_next != 0xffffffffl; + dpb = dpb->dpb_next) ; - dpb = dpb->dpb_next = (struct dpb FAR *)KernelAlloc(nunits*sizeof(struct dpb)); + dpb = dpb->dpb_next = + (struct dpb FAR *)KernelAlloc(nunits * sizeof(struct dpb)); } - for(Index = 0; Index < nunits; Index++) - { - dpb->dpb_next = dpb+1; + for (Index = 0; Index < nunits; Index++) + { + dpb->dpb_next = dpb + 1; dpb->dpb_unit = nblkdev; dpb->dpb_subunit = Index; dpb->dpb_device = dhp; @@ -507,17 +497,17 @@ static VOID update_dcb(struct dhdr FAR * dhp) ++dpb; ++nblkdev; } - (dpb-1)->dpb_next = (void FAR *)0xFFFFFFFFl; + (dpb - 1)->dpb_next = (void FAR *)0xFFFFFFFFl; } - /* If cmdLine is NULL, this is an internal driver */ -BOOL init_device(struct dhdr FAR * dhp, BYTE FAR * cmdLine, COUNT mode, COUNT r_top) +BOOL init_device(struct dhdr FAR * dhp, BYTE FAR * cmdLine, COUNT mode, + COUNT r_top) { request rq; - UCOUNT maxmem = ((UCOUNT)r_top << 6) - FP_SEG(dhp); + UCOUNT maxmem = ((UCOUNT) r_top << 6) - FP_SEG(dhp); if (maxmem >= 0x1000) maxmem = 0xFFFF; @@ -540,25 +530,27 @@ BOOL init_device(struct dhdr FAR * dhp, BYTE FAR * cmdLine, COUNT mode, COUNT r_ if (rq.r_status & S_ERROR) return TRUE; - if(cmdLine){ + if (cmdLine) + { if (mode) { /* Don't link in device drivers which do not take up memory */ - if (rq.r_endaddr == (BYTE FAR *)dhp) + if (rq.r_endaddr == (BYTE FAR *) dhp) return TRUE; else upBase = rq.r_endaddr; } else { - if (rq.r_endaddr == (BYTE FAR *)dhp) + if (rq.r_endaddr == (BYTE FAR *) dhp) return TRUE; else lpBase = rq.r_endaddr; } } - if (!(dhp->dh_attr & ATTR_CHAR) && (rq.r_nunits != 0)) { + if (!(dhp->dh_attr & ATTR_CHAR) && (rq.r_nunits != 0)) + { dhp->dh_name[0] = rq.r_nunits; update_dcb(dhp); } @@ -571,7 +563,6 @@ BOOL init_device(struct dhdr FAR * dhp, BYTE FAR * cmdLine, COUNT mode, COUNT r_ return FALSE; } - INIT static void InitIO(void) { /* Initialize driver chain */ @@ -598,19 +589,19 @@ VOID init_fatal(BYTE * err_msg) INIT VOID InitPrinters(VOID) { - iregs r; - int num_printers,i; + iregs r; + int num_printers, i; - init_call_intr(0x11,&r); /* get equipment list */ + init_call_intr(0x11, &r); /* get equipment list */ - num_printers = (r.a.x >> 14) & 3; /* bits 15-14 */ - - for (i = 0;i < num_printers;i++) - { - r.a.x = 0x0100; /* initialize printer */ - r.d.x = i; - init_call_intr(0x17,&r); - } + num_printers = (r.a.x >> 14) & 3; /* bits 15-14 */ + + for (i = 0; i < num_printers; i++) + { + r.a.x = 0x0100; /* initialize printer */ + r.d.x = i; + init_call_intr(0x17, &r); + } } /* @@ -705,5 +696,3 @@ INIT VOID InitPrinters(VOID) * Rev 1.0 02 Jul 1995 8:33:18 patv * Initial revision. */ - - diff --git a/kernel/memmgr.c b/kernel/memmgr.c index 0eca209..54e673d 100644 --- a/kernel/memmgr.c +++ b/kernel/memmgr.c @@ -30,7 +30,8 @@ #include "globals.h" #ifdef VERSION_STRING -static BYTE *memmgrRcsId = "$Id$"; +static BYTE *memmgrRcsId = + "$Id$"; #endif VOID mcb_init(); @@ -40,9 +41,9 @@ VOID show_chain(); /*#define nxtMCBsize(mcb,size) \ MK_FP(far2para((VOID FAR *) (mcb)) + (size) + 1, 0) */ -void FAR *nxtMCBsize(mcb FAR *Mcb, int size) +void FAR *nxtMCBsize(mcb FAR * Mcb, int size) { - return MK_FP(far2para((VOID FAR *) (Mcb)) + (size) + 1, 0); + return MK_FP(far2para((VOID FAR *) (Mcb)) + (size) + 1, 0); } #define nxtMCB(mcb) nxtMCBsize((mcb), (mcb)->m_size) @@ -85,10 +86,10 @@ seg far2para(VOID FAR * p) seg long2para(ULONG size) { - UWORD high = size>>16; - if ((UWORD)size > 0xfff0) - high++; - return (((UWORD)size + 0x0f) >> 4) + (high << 12); + UWORD high = size >> 16; + if ((UWORD) size > 0xfff0) + high++; + return (((UWORD) size + 0x0f) >> 4) + (high << 12); } /* @@ -97,11 +98,12 @@ seg long2para(ULONG size) VOID FAR *add_far(VOID FAR * fp, ULONG off) { UWORD off2; - - if (FP_SEG(fp) == 0xffff) return ((BYTE FAR *)fp) + FP_OFF(off); - + + if (FP_SEG(fp) == 0xffff) + return ((BYTE FAR *) fp) + FP_OFF(off); + off += FP_OFF(fp); - off2 = ((off >> 16) << 12) + ((UWORD)off >> 4); + off2 = ((off >> 16) << 12) + ((UWORD) off >> 4); return MK_FP(FP_SEG(fp) + off2, (UWORD) off & 0xf); } @@ -113,16 +115,17 @@ VOID FAR *adjust_far(VOID FAR * fp) { /* and return an adddress adjusted to the nearest paragraph */ /* boundary. */ - - if (FP_SEG(fp) == 0xffff) return fp; - + + if (FP_SEG(fp) == 0xffff) + return fp; + return MK_FP(FP_SEG(fp) + (FP_OFF(fp) >> 4), FP_OFF(fp) & 0xf); } #undef REG #define REG -#if 1 /* #ifdef KERNEL KERNEL */ +#if 1 /* #ifdef KERNEL KERNEL */ /* Allocate a new memory area. *para is assigned to the segment of the MCB rather then the segment of the data portion */ /* If mode == LARGEST, asize MUST be != NULL and will always recieve the @@ -132,7 +135,8 @@ VOID FAR *adjust_far(VOID FAR * fp) size is the minimum size of the block to search for, even if mode == LARGEST. */ -COUNT DosMemAlloc(UWORD size, COUNT mode, seg FAR * para, UWORD FAR * asize) +COUNT DosMemAlloc(UWORD size, COUNT mode, seg FAR * para, + UWORD FAR * asize) { REG mcb FAR *p; mcb FAR *foundSeg; @@ -140,16 +144,16 @@ COUNT DosMemAlloc(UWORD size, COUNT mode, seg FAR * para, UWORD FAR * asize) /* Initialize */ searchAgain: - + p = para2far(first_mcb); biggestSeg = foundSeg = NULL; /* Hack to the Umb Region direct for now. Save time and program space. */ - if((mode != LARGEST) && (mode & (FIRST_FIT_UO | FIRST_FIT_U)) && - uppermem_link && uppermem_root) - p = para2far(uppermem_root); + if ((mode != LARGEST) && (mode & (FIRST_FIT_UO | FIRST_FIT_U)) && + uppermem_link && uppermem_root) + p = para2far(uppermem_root); /* Search through memory blocks */ FOREVER @@ -157,10 +161,10 @@ searchAgain: /* check for corruption */ if (!mcbValid(p)) return DE_MCBDESTRY; - + if (mcbFree(p)) { /* unused block, check if it applies to the rule */ - if (joinMCBs(p) != SUCCESS) /* join following unused blocks */ + if (joinMCBs(p) != SUCCESS) /* join following unused blocks */ return DE_MCBDESTRY; /* error */ if (!biggestSeg || biggestSeg->m_size < p->m_size) @@ -191,7 +195,7 @@ searchAgain: foundSeg = p; break; - case FIRST_FIT: /* first possible */ + case FIRST_FIT: /* first possible */ case FIRST_FIT_U: case FIRST_FIT_UO: foundSeg = p; @@ -212,11 +216,12 @@ searchAgain: if (!foundSeg || !foundSeg->m_size) { /* no block to fullfill the request */ - if((mode != LARGEST) && (mode & FIRST_FIT_U) && - uppermem_link && uppermem_root) { + if ((mode != LARGEST) && (mode & FIRST_FIT_U) && + uppermem_link && uppermem_root) + { mode &= ~FIRST_FIT_U; goto searchAgain; - } + } if (asize) *asize = biggestSeg ? biggestSeg->m_size : 0; return DE_NOMEM; @@ -230,7 +235,8 @@ stopIt: /* reached from FIRST_FIT on match */ /* foundSeg := pointer to allocated block p := pointer to MCB that will form the rest of the block */ - if ((mode == LAST_FIT)||(mode == LAST_FIT_UO)||(mode == LAST_FIT_U)) + if ((mode == LAST_FIT) || (mode == LAST_FIT_UO) + || (mode == LAST_FIT_U)) { /* allocate the block from the end of the found block */ p = foundSeg; @@ -283,9 +289,8 @@ COUNT DosMemLargest(UWORD FAR * size) REG mcb FAR *p; /* Initialize */ - p = ((mem_access_mode & (FIRST_FIT_UO | FIRST_FIT_U)) && uppermem_link && uppermem_root) - ? para2far(uppermem_root) - : para2far(first_mcb); + p = ((mem_access_mode & (FIRST_FIT_UO | FIRST_FIT_U)) && uppermem_link + && uppermem_root) ? para2far(uppermem_root) : para2far(first_mcb); /* Cycle through the whole MCB chain to find the largest unused area. Join all unused areas together. */ @@ -384,8 +389,7 @@ COUNT DosMemFree(UWORD para) */ COUNT DosMemChange(UWORD para, UWORD size, UWORD * maxSize) { - REG mcb FAR *p, - FAR * q; + REG mcb FAR *p, FAR * q; REG COUNT i; /* Initialize */ @@ -435,9 +439,9 @@ COUNT DosMemChange(UWORD para, UWORD size, UWORD * maxSize) /* MS network client NET.EXE: DosMemChange sets the PSP * * not tested, if always, or only on success TE* - * only on success seems more logical to me - Bart */ + * only on success seems more logical to me - Bart */ p->m_psp = cu_psp; - + return SUCCESS; } @@ -457,12 +461,12 @@ COUNT DosMemCheck(void) { /* check for corruption */ if (p->m_type != MCB_NORMAL) - { + { printf("dos mem corrupt, first_mcb=%04x\n", first_mcb); - hexd("prev " ,pprev,16); - hexd("notMZ",p,16); + hexd("prev ", pprev, 16); + hexd("notMZ", p, 16); return DE_MCBDESTRY; - } + } /* not corrupted - but not end, bump the pointer */ pprev = p; @@ -476,31 +480,31 @@ COUNT FreeProcessMem(UWORD ps) mcb FAR *p; BYTE oldumbstate = uppermem_link; - /* link in upper memory to free those , too */ + /* link in upper memory to free those , too */ DosUmbLink(1); /* Search through all memory blocks */ - for (p = para2far(first_mcb);; p = nxtMCB(p)) - { + for (p = para2far(first_mcb);; p = nxtMCB(p)) + { if (!mcbValid(p)) /* check for corruption */ - return DE_MCBDESTRY; + return DE_MCBDESTRY; if (p->m_psp == ps) - DosMemFree(FP_SEG(p)); - - if (p->m_type == MCB_LAST) - break; - } + DosMemFree(FP_SEG(p)); + + if (p->m_type == MCB_LAST) + break; + } + + DosUmbLink(oldumbstate); - DosUmbLink(oldumbstate); - return SUCCESS; } -#if 0 - /* seems to be superceeded by DosMemLargest - -- 1999/04/21 ska */ +#if 0 + /* seems to be superceeded by DosMemLargest + -- 1999/04/21 ska */ COUNT DosGetLargestBlock(UWORD FAR * block) { UWORD sz = 0; @@ -552,60 +556,57 @@ VOID mcb_print(mcb FAR * mcbp) fmemcpy((BYTE FAR *) buff, (BYTE FAR *) (mcbp->m_name), 8); buff[8] = '\0'; - printf("%04x:%04x -> |%s| m_type = 0x%02x '%c'; m_psp = 0x%04x; m_size = 0x%04x\n", - FP_SEG(mcbp), - FP_OFF(mcbp), - *buff == '\0' ? "*NO-ID*" : buff, - mcbp->m_type, mcbp->m_type > ' ' ? mcbp->m_type : ' ', - mcbp->m_psp, - mcbp->m_size); + printf + ("%04x:%04x -> |%s| m_type = 0x%02x '%c'; m_psp = 0x%04x; m_size = 0x%04x\n", + FP_SEG(mcbp), FP_OFF(mcbp), *buff == '\0' ? "*NO-ID*" : buff, + mcbp->m_type, mcbp->m_type > ' ' ? mcbp->m_type : ' ', mcbp->m_psp, + mcbp->m_size); } #endif VOID DosUmbLink(BYTE n) { - REG mcb FAR *p; - REG mcb FAR *q; - mcb FAR *end_of_conv_mem = para2far(ram_top*64-1); - - if (uppermem_root == 0) - return; + REG mcb FAR *p; + REG mcb FAR *q; + mcb FAR *end_of_conv_mem = para2far(ram_top * 64 - 1); - q = p = para2far(first_mcb); -/* like a xor thing! */ - if((uppermem_link == 1) && (n == 0)) - { - while ( p != end_of_conv_mem ) - { - if (mcbFree(p)) - joinMCBs(p); - if (!mcbValid(p)) - goto DUL_exit; - q = p; - p = nxtMCB(p); - } - - if(q->m_type == MCB_NORMAL) - q->m_type = MCB_LAST; - uppermem_link = n; - - } - else - if((uppermem_link == 0) && (n == 1)) - { - while( q->m_type != MCB_LAST) - { - if (!mcbValid(q)) - goto DUL_exit; - q = nxtMCB(q); - } - - if(q->m_type == MCB_LAST) - q->m_type = MCB_NORMAL; - uppermem_link = n; - } -DUL_exit: + if (uppermem_root == 0) return; + + q = p = para2far(first_mcb); +/* like a xor thing! */ + if ((uppermem_link == 1) && (n == 0)) + { + while (p != end_of_conv_mem) + { + if (mcbFree(p)) + joinMCBs(p); + if (!mcbValid(p)) + goto DUL_exit; + q = p; + p = nxtMCB(p); + } + + if (q->m_type == MCB_NORMAL) + q->m_type = MCB_LAST; + uppermem_link = n; + + } + else if ((uppermem_link == 0) && (n == 1)) + { + while (q->m_type != MCB_LAST) + { + if (!mcbValid(q)) + goto DUL_exit; + q = nxtMCB(q); + } + + if (q->m_type == MCB_LAST) + q->m_type = MCB_NORMAL; + uppermem_link = n; + } +DUL_exit: + return; } /* @@ -620,44 +621,42 @@ DUL_exit: */ #if 0 -BYTE INITDataSegmentClaimed = 1; /* must be enabled by CONFIG.SYS */ +BYTE INITDataSegmentClaimed = 1; /* must be enabled by CONFIG.SYS */ extern BYTE _INIT_DATA_START[], _INIT_DATA_END[]; VOID ClaimINITDataSegment() { - unsigned ilow,ihigh; - VOID FAR * p; + unsigned ilow, ihigh; + VOID FAR *p; - if (INITDataSegmentClaimed) - return; - INITDataSegmentClaimed = 1; + if (INITDataSegmentClaimed) + return; + INITDataSegmentClaimed = 1; + ilow = (unsigned)_INIT_DATA_START; + ilow = (ilow + 0x0f) & ~0x000f; + ihigh = (unsigned)_INIT_DATA_END; + ihigh = ((ihigh + 0x0f) & ~0x000f) - 0x20; - ilow = (unsigned)_INIT_DATA_START; - ilow = (ilow+0x0f) & ~0x000f; - ihigh = (unsigned)_INIT_DATA_END; - ihigh = ((ihigh + 0x0f) & ~0x000f) - 0x20; + if (ilow + 0x10 < ihigh) + { + printf("CLAIMING INIT_DATA memory - %u bytes\n", ihigh - ilow); + } - if (ilow +0x10 < ihigh) - { - printf("CLAIMING INIT_DATA memory - %u bytes\n",ihigh - ilow); - } + ((mcb *) ilow)->m_type = MCB_NORMAL; /* 'M' */ + ((mcb *) ilow)->m_psp = FREE_PSP; /* '0' */ + ((mcb *) ilow)->m_size = (ihigh - ilow - 0x10) >> 4; /* '0' */ + ((mcb *) ihigh)->m_type = MCB_NORMAL; /* 'M' */ + ((mcb *) ihigh)->m_psp = 0x0008; /* system */ - ((mcb*)ilow)->m_type = MCB_NORMAL; /* 'M' */ - ((mcb*)ilow)->m_psp = FREE_PSP; /* '0' */ - ((mcb*)ilow)->m_size = (ihigh-ilow-0x10)>>4; /* '0' */ + p = (void FAR *)(void *)ihigh; - ((mcb*)ihigh)->m_type = MCB_NORMAL; /* 'M' */ - ((mcb*)ihigh)->m_psp = 0x0008; /* system */ + ((mcb *) ihigh)->m_size = first_mcb - 1 - FP_SEG(p) - (FP_OFF(p) >> 4); - p = (void FAR*)(void*)ihigh; + p = (void FAR *)(void *)ilow; - ((mcb*)ihigh)->m_size = first_mcb -1 - FP_SEG(p) - (FP_OFF(p) >> 4); - - p = (void FAR*)(void*)ilow; - - first_mcb = FP_SEG(p) + (FP_OFF(p) >> 4); + first_mcb = FP_SEG(p) + (FP_OFF(p) >> 4); } #endif @@ -712,4 +711,3 @@ VOID ClaimINITDataSegment() * Rev 1.0 02 Jul 1995 8:33:08 patv * Initial revision. */ - diff --git a/kernel/misc.c b/kernel/misc.c index e4c4e30..c5f602e 100644 --- a/kernel/misc.c +++ b/kernel/misc.c @@ -29,7 +29,8 @@ #include "portab.h" #ifdef VERSION_STRINGS -static BYTE *miscRcsId = "$Id$"; +static BYTE *miscRcsId = + "$Id$"; #endif #include "globals.h" @@ -119,4 +120,3 @@ VOID fmemset(REG VOID FAR * s, REG int ch, REG COUNT n) * Rev 1.0 02 Jul 1995 8:06:28 patv * Initial revision. */ - diff --git a/kernel/network.c b/kernel/network.c index 75186d4..e411048 100644 --- a/kernel/network.c +++ b/kernel/network.c @@ -31,7 +31,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif /* see RBIL D-2152 and D-215D06 before attempting @@ -66,4 +67,3 @@ VOID set_machine_name(BYTE FAR * netname, UWORD name_num) * *** empty log message *** * */ - diff --git a/kernel/newstuff.c b/kernel/newstuff.c index 8c4fdd9..c16c5ec 100644 --- a/kernel/newstuff.c +++ b/kernel/newstuff.c @@ -26,7 +26,8 @@ /****************************************************************/ #ifdef VERSION_STRINGS -static BYTE *mainRcsId = "$Id$"; +static BYTE *mainRcsId = + "$Id$"; #endif #include "portab.h" @@ -39,8 +40,7 @@ static BYTE *mainRcsId = "$Id$"; */ int SetJFTSize(UWORD nHandles) { - UWORD block, - maxBlock; + UWORD block, maxBlock; psp FAR *ppsp = MK_FP(cu_psp, 0); UBYTE FAR *newtab; COUNT i; @@ -51,7 +51,8 @@ int SetJFTSize(UWORD nHandles) return SUCCESS; } - if ((DosMemAlloc((nHandles + 0xf) >> 4, mem_access_mode, &block, &maxBlock)) < 0) + if ((DosMemAlloc + ((nHandles + 0xf) >> 4, mem_access_mode, &block, &maxBlock)) < 0) return DE_NOMEM; ++block; @@ -74,13 +75,8 @@ int DosMkTmp(BYTE FAR * pathname, UWORD attr) { /* create filename from current date and time */ char FAR *ptmp = pathname; - BYTE wd, - month, - day; - BYTE h, - m, - s, - hund; + BYTE wd, month, day; + BYTE h, m, s, hund; WORD sh; WORD year; int rc; @@ -98,40 +94,39 @@ int DosMkTmp(BYTE FAR * pathname, UWORD attr) sh = s * 100 + hund; - for ( loop = 0; loop < 0xfff; loop++) - { - sprintf(name83,"%x%x%x%x%x%03x.%03x", + for (loop = 0; loop < 0xfff; loop++) + { + sprintf(name83, "%x%x%x%x%x%03x.%03x", + year & 0xf, month & 0xf, day & 0xf, h & 0xf, m & 0xf, + sh & 0xfff, loop & 0xfff); - year & 0xf,month & 0xf, day & 0xf,h & 0xf,m & 0xf, sh&0xfff, - loop & 0xfff); + fmemcpy(ptmp, name83, 13); - fmemcpy(ptmp, name83, 13); + if ((rc = DosOpen(pathname, 0)) < 0 && rc != DE_ACCESS /* subdirectory ?? */ + /* todo: sharing collision on + network drive + */ + ) + break; - if ((rc = DosOpen(pathname, 0)) < 0 && - rc != DE_ACCESS /* subdirectory ?? */ - /* todo: sharing collision on - network drive - */ - ) - break; + if (rc >= 0) + DosClose(rc); + } - if (rc >= 0) DosClose(rc); - } - - if (rc == DE_FILENOTFND) - { - rc = DosCreat(pathname, attr); - } - return rc; + if (rc == DE_FILENOTFND) + { + rc = DosCreat(pathname, attr); + } + return rc; } -COUNT get_verify_drive(char FAR *src) +COUNT get_verify_drive(char FAR * src) { UBYTE drive; /* Do we have a drive? */ if (src[1] == ':') - drive = ((src[0]-1) | 0x20) - ('a'-1); + drive = ((src[0] - 1) | 0x20) - ('a' - 1); else return default_drive; if (drive < lastdrive && CDSp->cds_table[drive].cdsFlags & CDSVALID) @@ -147,7 +142,7 @@ COUNT get_verify_drive(char FAR *src) * MSD returns \\D.\A.\????????.??? with SHSUCDX. So, this code is not * compatible MSD Func 60h. */ - + /*TE TODO: experimenting with NUL on MSDOS 7.0 (win95) @@ -161,13 +156,13 @@ COUNT get_verify_drive(char FAR *src) TRUENAME A:NUL A:/NUL OK TRUENAME A:\NUL A:\NUL -*/ - +*/ + COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) { static char buf[128] = "A:\\\0\0\0\0\0\0\0\0\0"; char *bufp = buf + 3; - COUNT i, rootEndPos = 2; /* renamed x to rootEndPos - Ron Cemer */ + COUNT i, rootEndPos = 2; /* renamed x to rootEndPos - Ron Cemer */ struct dhdr FAR *dhp; BYTE FAR *froot; WORD d; @@ -176,10 +171,10 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) i = get_verify_drive(src); if (i < 0) - return DE_INVLDDRV; - + return DE_INVLDDRV; + buf[0] = i + 'A'; - buf[1] = ':'; /* Just to be sure */ + buf[1] = ':'; /* Just to be sure */ /* First, adjust the source pointer */ src = adjust_far(src); @@ -193,42 +188,51 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) MSD returns X:/CON for truename con. Not X:\CON */ /* check for a device */ - - if ((*src != '.') && (*src != '\\') && (*src != '/') && ((dhp = IsDevice(src)) != NULL)) - { - + + if ((*src != '.') && (*src != '\\') && (*src != '/') + && ((dhp = IsDevice(src)) != NULL)) + { + froot = get_root(src); /* /// Bugfix: NUL.LST is the same as NUL. This is true for all - devices. On a device name, the extension is irrelevant - as long as the name matches. - - Ron Cemer */ - - buf[2] ='/'; - /* /// Bug: should be only copying up to first space. - - Ron Cemer */ - - for (d = 0; d < FNAME_SIZE && dhp->dh_name[d] != 0 && dhp->dh_name[d] != ' '; d++) - *bufp++ = dhp->dh_name[d]; - /* /// DOS will return C:/NUL.LST if you pass NUL.LST in. - DOS will also return C:/NUL.??? if you pass NUL.* in. - Code added here to support this. - - Ron Cemer */ - while ( (*froot != '.') && (*froot != '\0') ) froot++; - if (*froot) froot++; - if (*froot) { - *bufp++ = '.'; - for (i = 0; i < FEXT_SIZE; i++) { - if ( (*froot == '\0') || (*froot == '.') ) - break; - if (*froot == '*') { - for (; i < FEXT_SIZE; i++) *bufp++ = '?'; - break; - } - *bufp++ = *froot++; + devices. On a device name, the extension is irrelevant + as long as the name matches. + - Ron Cemer */ + + buf[2] = '/'; + /* /// Bug: should be only copying up to first space. + - Ron Cemer */ + + for (d = 0; + d < FNAME_SIZE && dhp->dh_name[d] != 0 && dhp->dh_name[d] != ' '; + d++) + *bufp++ = dhp->dh_name[d]; + /* /// DOS will return C:/NUL.LST if you pass NUL.LST in. + DOS will also return C:/NUL.??? if you pass NUL.* in. + Code added here to support this. + - Ron Cemer */ + while ((*froot != '.') && (*froot != '\0')) + froot++; + if (*froot) + froot++; + if (*froot) + { + *bufp++ = '.'; + for (i = 0; i < FEXT_SIZE; i++) + { + if ((*froot == '\0') || (*froot == '.')) + break; + if (*froot == '*') + { + for (; i < FEXT_SIZE; i++) + *bufp++ = '?'; + break; } + *bufp++ = *froot++; + } } - /* /// End of code additions. - Ron Cemer */ + /* /// End of code additions. - Ron Cemer */ goto exit_tn; } @@ -240,28 +244,33 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) * path to the executable file. * Jun 11, 2000 - rbc */ /* /// Changed to "while" from "if". - Ron Cemer */ - while ( (src[0] == '.') && (src[1] == '\\') ) src += 2; - + while ((src[0] == '.') && (src[1] == '\\')) + src += 2; + current_ldt = &CDSp->cds_table[i]; /* Always give the redirector a chance to rewrite the filename */ fstrncpy(bufp - 1, src, sizeof(buf) - (bufp - buf)); - if ((t == FALSE) && (QRemote_Fn(buf, dest) == SUCCESS) && (dest[0] != '\0')) { + if ((t == FALSE) && (QRemote_Fn(buf, dest) == SUCCESS) + && (dest[0] != '\0')) + { return SUCCESS; - } else { + } + else + { bufp[-1] = '\\'; } - if (t == FALSE) - { - fstrncpy(buf, current_ldt->cdsCurrentPath, current_ldt->cdsJoinOffset); - bufp = buf + current_ldt->cdsJoinOffset; - rootEndPos = current_ldt->cdsJoinOffset; /* renamed x to rootEndPos - Ron Cemer */ - *bufp++ = '\\'; - } - - if (*src != '\\' && *src != '/') /* append current dir */ + if (t == FALSE) { - DosGetCuDir((UBYTE)(i+1), bufp); + fstrncpy(buf, current_ldt->cdsCurrentPath, current_ldt->cdsJoinOffset); + bufp = buf + current_ldt->cdsJoinOffset; + rootEndPos = current_ldt->cdsJoinOffset; /* renamed x to rootEndPos - Ron Cemer */ + *bufp++ = '\\'; + } + + if (*src != '\\' && *src != '/') /* append current dir */ + { + DosGetCuDir((UBYTE) (i + 1), bufp); if (*bufp) { while (*bufp) @@ -274,16 +283,16 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) /*move_name:*/ - /* /// The block inside the "#if (0) ... #endif" is - seriously broken. New code added below to replace it. - This eliminates many serious bugs, specifically - with FreeCOM where truename is required to work - according to the DOS specification in order for - the COPY and other file-related commands to work - properly. - This should be a major improvement to all apps which - use truename. - - Ron Cemer */ + /* /// The block inside the "#if (0) ... #endif" is + seriously broken. New code added below to replace it. + This eliminates many serious bugs, specifically + with FreeCOM where truename is required to work + according to the DOS specification in order for + the COPY and other file-related commands to work + properly. + This should be a major improvement to all apps which + use truename. + - Ron Cemer */ #if (0) /* @@ -291,14 +300,14 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) * function are operating with in normal parms. * jt */ - n = 9; + n = 9; /* convert all forward slashes to backslashes, and uppercase all characters */ while (*src) { char c; c = *src++; - if(!n) - return DE_PATHNOTFND; /* do this for now */ + if (!n) + return DE_PATHNOTFND; /* do this for now */ n--; switch (c) { @@ -327,9 +336,10 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) case '/': /* convert to backslash */ case '\\': - if (bufp[-1] != '\\'){ - *bufp++ = '\\'; - n = 9; + if (bufp[-1] != '\\') + { + *bufp++ = '\\'; + n = 9; } break; @@ -343,7 +353,7 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) for (bufp -= 2; *bufp != '\\'; bufp--) { - if (bufp < buf + rootEndPos) /* '..' illegal in root dir */ + if (bufp < buf + rootEndPos) /* '..' illegal in root dir */ return DE_PATHNOTFND; } src++; @@ -351,20 +361,20 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) bufp++; } else if (*src == '/' || *src == '\\' || *src == 0) - break; - /* --bufp;*/ - else - return DE_PATHNOTFND; + break; + /* --bufp; */ + else + return DE_PATHNOTFND; + } + else if (*src == '/' || *src == '\\' || *src == 0) + { + break; + } + else + { + n = 4; + *bufp++ = c; } - else if ( *src == '/' || *src == '\\' || *src == 0) - { - break; - } - else - { - n = 4; - *bufp++ = c; - } break; default: @@ -379,110 +389,138 @@ COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t) #endif /* /// Beginning of new code. - Ron Cemer */ - bufp--; + bufp--; + { + char c, *bufend = buf + (sizeof(buf) - 1); + int gotAnyWildcards = 0; + int seglen, copylen, state; + while ((*src) && (bufp < bufend)) { - char c, *bufend = buf+(sizeof(buf)-1); - int gotAnyWildcards = 0; - int seglen, copylen, state; - while ( (*src) && (bufp < bufend) ) { - /* Skip duplicated slashes. */ - while ( (*src == '/') || (*src == '\\') ) src++; - if (!(*src)) break; - /* Find the end of this segment in the source string. */ - for (seglen = 0; ; seglen++) { - c = src[seglen]; - if ( (c == '\0') || (c == '/') || (c == '\\') ) - break; + /* Skip duplicated slashes. */ + while ((*src == '/') || (*src == '\\')) + src++; + if (!(*src)) + break; + /* Find the end of this segment in the source string. */ + for (seglen = 0;; seglen++) + { + c = src[seglen]; + if ((c == '\0') || (c == '/') || (c == '\\')) + break; + } + if (seglen > 0) + { + /* Ignore all ".\" or "\." path segments. */ + if ((seglen != 1) || (*src != '.')) + { + /* Apply ".." to the path by removing + last path segment from buf. */ + if ((seglen == 2) && (src[0] == '.') && (src[1] == '.')) + { + if (bufp > (buf + rootEndPos)) + { + bufp--; + while ((bufp > (buf + rootEndPos)) + && (*bufp != '/') && (*bufp != '\\')) + bufp--; } - if (seglen > 0) { - /* Ignore all ".\" or "\." path segments. */ - if ( (seglen != 1) || (*src != '.') ) { - /* Apply ".." to the path by removing - last path segment from buf. */ - if ( (seglen==2) && (src[0] == '.') && (src[1] == '.') ) { - if (bufp > (buf+rootEndPos)) { - bufp--; - while ( (bufp > (buf+rootEndPos)) - && (*bufp != '/') - && (*bufp != '\\') ) - bufp--; - } else { - /* .. in root dir illegal */ - return DE_PATHNOTFND; - } - } else { - /* New segment. If any wildcards in previous - segment(s), this is an invalid path. */ - if (gotAnyWildcards || src[0]=='.') return DE_PATHNOTFND; - /* Append current path segment to result. */ - *(bufp++) = '\\'; - if (bufp >= bufend) break; - copylen = state = 0; - for (i=0; ( (i < seglen) && (bufp < bufend) ); i++) { - c = src[i]; - gotAnyWildcards |= ( (c == '?') || (c == '*') ); - switch (state) { - case 0: /* Copying filename (excl. extension) */ - if (c == '*') { - while (copylen < FNAME_SIZE) { - *(bufp++) = '?'; - if (bufp >= bufend) break; - copylen++; - } - copylen = 0; - state = 1; /* Go wait for dot */ - break; - } - if (c == '.') { - if (src[i+1] != '.' && i+1 < seglen) *(bufp++) = '.'; - copylen = 0; - state = 2; /* Copy extension next */ - break; - } - *(bufp++) = c; - copylen++; - if (copylen >= FNAME_SIZE) { - copylen = 0; - state = 1; /* Go wait for dot */ - break; - } - break; - case 1: /* Looking for dot so we can copy exten */ - if (src[i] == '.' && src[i+1] != '.' && i+1 < seglen) { - *(bufp++) = '.'; - state = 2; - } - break; - case 2: /* Copying extension */ - if (c == '*') { - while (copylen < FEXT_SIZE) { - *(bufp++) = '?'; - if (bufp >= bufend) break; - copylen++; - } - i = seglen; /* Done with segment */ - break; - } - if (c == '.') { - i = seglen; /* Done with segment */ - break; - } - *(bufp++) = c; - copylen++; - if (copylen >= FEXT_SIZE) { - i = seglen; /* Done with segment */ - break; - } - break; - } - } + else + { + /* .. in root dir illegal */ + return DE_PATHNOTFND; + } + } + else + { + /* New segment. If any wildcards in previous + segment(s), this is an invalid path. */ + if (gotAnyWildcards || src[0] == '.') + return DE_PATHNOTFND; + /* Append current path segment to result. */ + *(bufp++) = '\\'; + if (bufp >= bufend) + break; + copylen = state = 0; + for (i = 0; ((i < seglen) && (bufp < bufend)); i++) + { + c = src[i]; + gotAnyWildcards |= ((c == '?') || (c == '*')); + switch (state) + { + case 0: /* Copying filename (excl. extension) */ + if (c == '*') + { + while (copylen < FNAME_SIZE) + { + *(bufp++) = '?'; + if (bufp >= bufend) + break; + copylen++; } - } - } /* if (seglen > 0) */ - src += seglen; - if (*src) src++; - } /* while ( (*src) && (bufp < bufend) ) */ - } + copylen = 0; + state = 1; /* Go wait for dot */ + break; + } + if (c == '.') + { + if (src[i + 1] != '.' && i + 1 < seglen) + *(bufp++) = '.'; + copylen = 0; + state = 2; /* Copy extension next */ + break; + } + *(bufp++) = c; + copylen++; + if (copylen >= FNAME_SIZE) + { + copylen = 0; + state = 1; /* Go wait for dot */ + break; + } + break; + case 1: /* Looking for dot so we can copy exten */ + if (src[i] == '.' && src[i + 1] != '.' && i + 1 < seglen) + { + *(bufp++) = '.'; + state = 2; + } + break; + case 2: /* Copying extension */ + if (c == '*') + { + while (copylen < FEXT_SIZE) + { + *(bufp++) = '?'; + if (bufp >= bufend) + break; + copylen++; + } + i = seglen; /* Done with segment */ + break; + } + if (c == '.') + { + i = seglen; /* Done with segment */ + break; + } + *(bufp++) = c; + copylen++; + if (copylen >= FEXT_SIZE) + { + i = seglen; /* Done with segment */ + break; + } + break; + } + } + } + } + } /* if (seglen > 0) */ + src += seglen; + if (*src) + src++; + } /* while ( (*src) && (bufp < bufend) ) */ + } /* /// End of new code. - Ron Cemer */ if (bufp == buf + 2) @@ -553,4 +591,3 @@ exit_tn: * Rev 1.1 22 Jan 1997 13:21:22 patv * pre-0.92 Svante Frey bug fixes. */ - diff --git a/kernel/nls.c b/kernel/nls.c index bc1cb96..28de454 100644 --- a/kernel/nls.c +++ b/kernel/nls.c @@ -39,7 +39,8 @@ #include #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif /* @@ -50,8 +51,10 @@ static BYTE *RcsId = "$Id$"; #ifdef NLS_DEBUG #define assertDSeqSS() if(_DS != _SS) assertDSneSS(); void assertDSneSS(void) -{ panic("DS unequal to SS"); +{ + panic("DS unequal to SS"); } + #define log(a) printf a #define log1(a) printf a #else @@ -64,25 +67,23 @@ void assertDSneSS(void) #endif #endif - struct nlsInfoBlock nlsInfo = { - (char FAR *)0 /* filename to COUNTRY.SYS */ - ,437 /* system code page */ - /* Implementation flags */ - ,0 + (char FAR *)0 /* filename to COUNTRY.SYS */ + , 437 /* system code page */ + /* Implementation flags */ + , 0 #ifdef NLS_MODIFYABLE_DATA - | NLS_CODE_MODIFYABLE_DATA + | NLS_CODE_MODIFYABLE_DATA #endif #ifdef NLS_REORDER_POINTERS - | NLS_CODE_REORDER_POINTERS + | NLS_CODE_REORDER_POINTERS #endif - ,&nlsPackageHardcoded /* hardcoded first package */ - ,&nlsPackageHardcoded /* first item in chain */ + , &nlsPackageHardcoded /* hardcoded first package */ + , &nlsPackageHardcoded /* first item in chain */ }; - - /* getTableX return the pointer to the X'th table; X==subfct */ - /* subfct 2: normal upcase table; 4: filename upcase table */ + /* getTableX return the pointer to the X'th table; X==subfct */ + /* subfct 2: normal upcase table; 4: filename upcase table */ #ifdef NLS_REORDER_POINTERS #define getTable2(nls) ((nls)->nlsPointers[0].pointer) #define getTable4(nls) ((nls)->nlsPointers[1].pointer) @@ -91,74 +92,74 @@ struct nlsInfoBlock nlsInfo = { #define getTable4(nls) getTable(4, (nls)) #define NEED_GET_TABLE #endif - /*== both chartables must be 128 bytes long and lower range is + /*== both chartables must be 128 bytes long and lower range is identical to 7bit-US-ASCII ==ska*/ #define getCharTbl2(nls) \ (((struct nlsCharTbl FAR*)getTable2(nls))->tbl - 0x80) #define getCharTbl4(nls) \ (((struct nlsCharTbl FAR*)getTable4(nls))->tbl - 0x80) - /******************************************************************** ***** MUX calling functions **************************************** ********************************************************************/ /*== DS:SI _always_ points to global NLS info structure <-> no * subfct can use these registers for anything different. ==ska*/ -STATIC COUNT muxGo(int subfct, iregs *rp) +STATIC COUNT muxGo(int subfct, iregs * rp) { -log( ("NLS: muxGo(): subfct=%x, cntry=%u, cp=%u, ES:DI=%04x:%04x\n", subfct - , rp->DX, rp->BX, rp->ES, rp->DI) ); - rp->SI = FP_OFF(&nlsInfo); - rp->DS = FP_SEG(&nlsInfo); - rp->AX = 0x1400 | subfct; - intr(0x2f, rp); -log( ("NLS: muxGo(): return value = %d\n", rp->AX) ); - return rp->AX; + log(("NLS: muxGo(): subfct=%x, cntry=%u, cp=%u, ES:DI=%04x:%04x\n", + subfct, rp->DX, rp->BX, rp->ES, rp->DI)); + rp->SI = FP_OFF(&nlsInfo); + rp->DS = FP_SEG(&nlsInfo); + rp->AX = 0x1400 | subfct; + intr(0x2f, rp); + log(("NLS: muxGo(): return value = %d\n", rp->AX)); + return rp->AX; } /* * Call NLSFUNC to load the NLS package */ COUNT muxLoadPkg(UWORD cp, UWORD cntry) -{ iregs r; +{ + iregs r; - assertDSeqSS(); /* because "&r" */ + assertDSeqSS(); /* because "&r" */ - /* 0x1400 == not installed, ok to install */ - /* 0x1401 == not installed, not ok to install */ - /* 0x14FF == installed */ + /* 0x1400 == not installed, ok to install */ + /* 0x1401 == not installed, not ok to install */ + /* 0x14FF == installed */ - r.BX = 0; /* make sure the NLSFUNC ID is updated */ - if(muxGo(0, &r) != 0x14ff) - return DE_FILENOTFND; /* No NLSFUNC --> no load */ - if(r.BX != NLS_FREEDOS_NLSFUNC_ID) /* FreeDOS NLSFUNC will return */ - return DE_INVLDACC; /* This magic number */ + r.BX = 0; /* make sure the NLSFUNC ID is updated */ + if (muxGo(0, &r) != 0x14ff) + return DE_FILENOTFND; /* No NLSFUNC --> no load */ + if (r.BX != NLS_FREEDOS_NLSFUNC_ID) /* FreeDOS NLSFUNC will return */ + return DE_INVLDACC; /* This magic number */ - /* OK, the correct NLSFUNC is available --> load pkg */ - /* If BX == -1 on entry, NLSFUNC updates BX to the codepage loaded - into memory. The system must then change to this one later */ - r.DX = cntry; - r.BX = cp; - return muxGo(NLSFUNC_LOAD_PKG, &r); + /* OK, the correct NLSFUNC is available --> load pkg */ + /* If BX == -1 on entry, NLSFUNC updates BX to the codepage loaded + into memory. The system must then change to this one later */ + r.DX = cntry; + r.BX = cp; + return muxGo(NLSFUNC_LOAD_PKG, &r); } -STATIC int muxBufGo(int subfct, int bp, UWORD cp, UWORD cntry, UWORD bufsize - , VOID FAR *buf) -{ iregs r; +STATIC int muxBufGo(int subfct, int bp, UWORD cp, UWORD cntry, + UWORD bufsize, VOID FAR * buf) +{ + iregs r; - assertDSeqSS(); /* because "&r" */ + assertDSeqSS(); /* because "&r" */ -log( ("NLS: muxBufGo(): subfct=%x, BP=%u, cp=%u, cntry=%u, len=%u, buf=%04x:%04x\n", - subfct, bp, cp, cntry, bufsize, FP_SEG(buf), FP_OFF(buf)) ); + log(("NLS: muxBufGo(): subfct=%x, BP=%u, cp=%u, cntry=%u, len=%u, buf=%04x:%04x\n", subfct, bp, cp, cntry, bufsize, FP_SEG(buf), FP_OFF(buf))); - r.DX = cntry; - r.BX = cp; - r.ES = FP_SEG(buf); - r.DI = FP_OFF(buf); - r.CX = bufsize; - r.BP = bp; - return muxGo(subfct, &r); + r.DX = cntry; + r.BX = cp; + r.ES = FP_SEG(buf); + r.DI = FP_OFF(buf); + r.CX = bufsize; + r.BP = bp; + return muxGo(subfct, &r); } #define mux65(s,cp,cc,bs,b) muxBufGo(2, (s), (cp), (cc), (bs), (b)) @@ -170,40 +171,41 @@ log( ("NLS: muxBufGo(): subfct=%x, BP=%u, cp=%u, cntry=%u, len=%u, buf=%04x:%04x ***** Helper functions********************************************** ********************************************************************/ - /* * Search for the NLS package within the chain * Also resolves the default values (-1) into the currently * active codepage/country code. */ STATIC struct nlsPackage FAR *searchPackage(UWORD cp, UWORD cntry) -{ struct nlsPackage FAR *nls; +{ + struct nlsPackage FAR *nls; - if(cp == NLS_DEFAULT) - cp = nlsInfo.actPkg->cp; - if(cntry == NLS_DEFAULT) - cntry = nlsInfo.actPkg->cntry; + if (cp == NLS_DEFAULT) + cp = nlsInfo.actPkg->cp; + if (cntry == NLS_DEFAULT) + cntry = nlsInfo.actPkg->cntry; - nls = nlsInfo.chain; - while((nls->cp != cp || nls->cntry != cntry) - && (nls = nls->nxt) != NULL); + nls = nlsInfo.chain; + while ((nls->cp != cp || nls->cntry != cntry) + && (nls = nls->nxt) != NULL) ; - return nls; + return nls; } /* For various robustnesses reasons and to simplify the implementation at other places, locateSubfct() returns NULL (== "not found"), if nls == NULL on entry. */ -STATIC VOID FAR *locateSubfct(struct nlsPackage FAR *nls, int subfct) -{ int cnt; - struct nlsPointer FAR *p; +STATIC VOID FAR *locateSubfct(struct nlsPackage FAR * nls, int subfct) +{ + int cnt; + struct nlsPointer FAR *p; - if(nls) for(cnt = nls->numSubfct, p = &nls->nlsPointers[0] - ; cnt--; ++p) - if(p->subfct == (UBYTE)subfct) - return p; + if (nls) + for (cnt = nls->numSubfct, p = &nls->nlsPointers[0]; cnt--; ++p) + if (p->subfct == (UBYTE) subfct) + return p; - return NULL; + return NULL; } #ifdef NEED_GET_TABLE @@ -213,19 +215,23 @@ STATIC VOID FAR *locateSubfct(struct nlsPackage FAR *nls, int subfct) function is guaranteed to return valid pointers, rather than to let the user (some kernel function) deal with non-existing tables -- 2000/02/26 ska*/ -STATIC VOID FAR *getTable(UBYTE subfct, struct nlsPackage FAR *nls) -{ struct nlsPointer FAR *poi; +STATIC VOID FAR *getTable(UBYTE subfct, struct nlsPackage FAR * nls) +{ + struct nlsPointer FAR *poi; - if((poi = locateSubfct(nls, subfct)) != NULL) - return poi; + if ((poi = locateSubfct(nls, subfct)) != NULL) + return poi; - /* Failed --> return the hardcoded table */ - switch(subfct) { - case 2: return &nlsUpHardcodedTable; - case 4: return &nlsFnameUpHardcodedTable; - /* case 5: return &nlsFnameTermHardcodedTable; */ - /* case 6: return &nlsCollHardcodedTable; */ - } + /* Failed --> return the hardcoded table */ + switch (subfct) + { + case 2: + return &nlsUpHardcodedTable; + case 4: + return &nlsFnameUpHardcodedTable; + /* case 5: return &nlsFnameTermHardcodedTable; */ + /* case 6: return &nlsCollHardcodedTable; */ + } } #endif @@ -239,36 +245,36 @@ STATIC VOID FAR *getTable(UBYTE subfct, struct nlsPackage FAR *nls) * the code to push bufsize, buf, call cpyBuf() and return its result. * The parameter were ordered to allow this code optimization. */ -STATIC COUNT cpyBuf(VOID FAR *dst, UWORD dstlen - , VOID FAR *src, UWORD srclen) +STATIC COUNT cpyBuf(VOID FAR * dst, UWORD dstlen, VOID FAR * src, + UWORD srclen) { - if(srclen <= dstlen) { - fmemcpy(dst, src, srclen); - return SUCCESS; - } - return DE_INVLDFUNC; /* buffer too small */ + if (srclen <= dstlen) + { + fmemcpy(dst, src, srclen); + return SUCCESS; + } + return DE_INVLDFUNC; /* buffer too small */ } - - /* * This function assumes that 'map' is adjusted such that * map[0x80] is the uppercase of character 0x80. *== 128 byte chartables, lower range conform to 7bit-US-ASCII ==ska*/ -STATIC VOID upMMem(UBYTE FAR *map, UBYTE FAR * str, unsigned len) +STATIC VOID upMMem(UBYTE FAR * map, UBYTE FAR * str, unsigned len) { REG unsigned c; #ifdef NLS_DEBUG - UBYTE FAR *oldStr; - unsigned oldLen; + UBYTE FAR *oldStr; + unsigned oldLen; - oldStr = str; - oldLen = len; -log( ("NLS: upMMem(): len=%u, %04x:%04x=\"", len, FP_SEG(str), FP_OFF(str)) ); - for(c = 0; c < len; ++c) - printf("%c", str[c] > 32? str[c]: '.'); - printf("\"\n"); + oldStr = str; + oldLen = len; + log(("NLS: upMMem(): len=%u, %04x:%04x=\"", len, FP_SEG(str), + FP_OFF(str))); + for (c = 0; c < len; ++c) + printf("%c", str[c] > 32 ? str[c] : '.'); + printf("\"\n"); #endif if (len) do @@ -281,14 +287,13 @@ log( ("NLS: upMMem(): len=%u, %04x:%04x=\"", len, FP_SEG(str), FP_OFF(str)) ); } while (--len); #ifdef NLS_DEBUG -printf("NLS: upMMem(): result=\""); - for(c = 0; c < oldLen; ++c) - printf("%c", oldStr[c] > 32? oldStr[c]: '.'); - printf("\"\n"); + printf("NLS: upMMem(): result=\""); + for (c = 0; c < oldLen; ++c) + printf("%c", oldStr[c] > 32 ? oldStr[c] : '.'); + printf("\"\n"); #endif } - /******************************************************************** ***** Lowlevel interface ******************************************* ********************************************************************/ @@ -297,52 +302,53 @@ printf("NLS: upMMem(): result=\""); the direct-access interface. subfct == NLS_DOS_38 is a value > 0xff in order to not clash with subfunctions valid to be passed as DOS-65-XX. */ -STATIC int nlsGetData(struct nlsPackage FAR *nls, int subfct, UBYTE FAR *buf - , unsigned bufsize) -{ VOID FAR *poi; +STATIC int nlsGetData(struct nlsPackage FAR * nls, int subfct, + UBYTE FAR * buf, unsigned bufsize) +{ + VOID FAR *poi; -log( ("NLS: nlsGetData(): subfct=%x, bufsize=%u, cp=%u, cntry=%u\n", - subfct, bufsize, nls->cp, nls->cntry) ); + log(("NLS: nlsGetData(): subfct=%x, bufsize=%u, cp=%u, cntry=%u\n", + subfct, bufsize, nls->cp, nls->cntry)); - /* Theoretically tables 1 and, if NLS_REORDER_POINTERS is enabled, - 2 and 4 could be hard-coded, because their - data is located at predictable (calculatable) locations. - However, 1 and subfct NLS_DOS_38 are to handle the same - data and the "locateSubfct()" call has to be implemented anyway, - in order to handle all subfunctions. - Also, NLS is often NOT used in any case, so this code is more - size than speed optimized. */ - if((poi = locateSubfct(nls, subfct)) != NULL) { -log( ("NLS: nlsGetData(): subfunction found\n") ); - switch(subfct) { - case 1: /* Extended Country Information */ - return cpyBuf(buf, bufsize, poi - , ((struct nlsExtCntryInfo FAR*)poi)->size + 3); - case NLS_DOS_38: /* Normal Country Information */ - return cpyBuf(buf, bufsize - , &(((struct nlsExtCntryInfo FAR*)poi)->dateFmt) - , 24); /* standard cinfo has no more 34 _used_ bytes */ - /* don't copy 34, copy only 0x18 instead, - see comment at DosGetCountryInformation TE */ - default: - /* All other subfunctions just return the found nlsPoinerInf - structure */ - return cpyBuf(buf, bufsize, poi, sizeof(struct nlsPointer)); - } - } + /* Theoretically tables 1 and, if NLS_REORDER_POINTERS is enabled, + 2 and 4 could be hard-coded, because their + data is located at predictable (calculatable) locations. + However, 1 and subfct NLS_DOS_38 are to handle the same + data and the "locateSubfct()" call has to be implemented anyway, + in order to handle all subfunctions. + Also, NLS is often NOT used in any case, so this code is more + size than speed optimized. */ + if ((poi = locateSubfct(nls, subfct)) != NULL) + { + log(("NLS: nlsGetData(): subfunction found\n")); + switch (subfct) + { + case 1: /* Extended Country Information */ + return cpyBuf(buf, bufsize, poi, + ((struct nlsExtCntryInfo FAR *)poi)->size + 3); + case NLS_DOS_38: /* Normal Country Information */ + return cpyBuf(buf, bufsize, &(((struct nlsExtCntryInfo FAR *)poi)->dateFmt), 24); /* standard cinfo has no more 34 _used_ bytes */ + /* don't copy 34, copy only 0x18 instead, + see comment at DosGetCountryInformation TE */ + default: + /* All other subfunctions just return the found nlsPoinerInf + structure */ + return cpyBuf(buf, bufsize, poi, sizeof(struct nlsPointer)); + } + } - /* The requested subfunction could not been located within the - NLS pkg --> error. Because the data corresponds to the subfunction - number passed to the API, the failure is the same as that a wrong - API function has been called. */ -log( ("NLS: nlsGetData(): Subfunction not found\n") ); - return DE_INVLDFUNC; + /* The requested subfunction could not been located within the + NLS pkg --> error. Because the data corresponds to the subfunction + number passed to the API, the failure is the same as that a wrong + API function has been called. */ + log(("NLS: nlsGetData(): Subfunction not found\n")); + return DE_INVLDFUNC; } VOID nlsCPchange(UWORD cp) { - UNREFERENCED_PARAMETER(cp); - printf("\7\nchange codepage not yet done ska\n"); + UNREFERENCED_PARAMETER(cp); + printf("\7\nchange codepage not yet done ska\n"); } /* @@ -366,74 +372,75 @@ VOID nlsCPchange(UWORD cp) * appropriate codepage on its own. */ -STATIC COUNT nlsSetPackage(struct nlsPackage FAR *nls) +STATIC COUNT nlsSetPackage(struct nlsPackage FAR * nls) { - if(nls->cp != nlsInfo.actPkg->cp) /* Codepage gets changed --> - inform all character drivers thereabout. - If this fails, it would be possible that the old - NLS pkg had been removed from memory by NLSFUNC. */ - nlsCPchange(nls->cp); + if (nls->cp != nlsInfo.actPkg->cp) /* Codepage gets changed --> + inform all character drivers thereabout. + If this fails, it would be possible that the old + NLS pkg had been removed from memory by NLSFUNC. */ + nlsCPchange(nls->cp); - nlsInfo.actPkg = nls; + nlsInfo.actPkg = nls; - return SUCCESS; + return SUCCESS; } STATIC COUNT DosSetPackage(UWORD cp, UWORD cntry) -{ struct nlsPackage FAR*nls; /* NLS package to use to return the info from */ - - /* nls := NLS package of cntry/codepage */ - if((nls = searchPackage(cp, cntry)) != NULL) - /* OK the NLS pkg is loaded --> activate it */ - return nlsSetPackage(nls); - - /* not loaded --> invoke NLSFUNC to load it */ - return muxLoadPkg(cp, cntry); -} - -STATIC void nlsUpMem(struct nlsPackage FAR *nls, VOID FAR *str, int len) { -log( ("NLS: nlsUpMem()\n") ); - upMMem(getCharTbl2(nls), (UBYTE FAR*)str, len); -} -STATIC void nlsFUpMem(struct nlsPackage FAR *nls, VOID FAR *str, int len) -{ -log( ("NLS: nlsFUpMem()\n") ); - upMMem(getCharTbl4(nls), (UBYTE FAR*)str, len); + struct nlsPackage FAR *nls; /* NLS package to use to return the info from */ + + /* nls := NLS package of cntry/codepage */ + if ((nls = searchPackage(cp, cntry)) != NULL) + /* OK the NLS pkg is loaded --> activate it */ + return nlsSetPackage(nls); + + /* not loaded --> invoke NLSFUNC to load it */ + return muxLoadPkg(cp, cntry); } -STATIC VOID xUpMem(struct nlsPackage FAR *nls, VOID FAR * str, unsigned len) +STATIC void nlsUpMem(struct nlsPackage FAR * nls, VOID FAR * str, int len) +{ + log(("NLS: nlsUpMem()\n")); + upMMem(getCharTbl2(nls), (UBYTE FAR *) str, len); +} +STATIC void nlsFUpMem(struct nlsPackage FAR * nls, VOID FAR * str, int len) +{ + log(("NLS: nlsFUpMem()\n")); + upMMem(getCharTbl4(nls), (UBYTE FAR *) str, len); +} + +STATIC VOID xUpMem(struct nlsPackage FAR * nls, VOID FAR * str, + unsigned len) /* upcase a memory area */ { -log( ("NLS: xUpMem(): cp=%u, cntry=%u\n", nls->cp, nls->cntry) ); + log(("NLS: xUpMem(): cp=%u, cntry=%u\n", nls->cp, nls->cntry)); - if(nls->flags & NLS_FLAG_DIRECT_UPCASE) - nlsUpMem(nls, str, len); - else - muxBufGo(NLSFUNC_UPMEM, 0, nls->cp, nls->cntry, len, str); + if (nls->flags & NLS_FLAG_DIRECT_UPCASE) + nlsUpMem(nls, str, len); + else + muxBufGo(NLSFUNC_UPMEM, 0, nls->cp, nls->cntry, len, str); } -STATIC int nlsYesNo(struct nlsPackage FAR *nls, unsigned char ch) +STATIC int nlsYesNo(struct nlsPackage FAR * nls, unsigned char ch) { - assertDSeqSS(); /* because "&ch" */ + assertDSeqSS(); /* because "&ch" */ -log( ("NLS: nlsYesNo(): in ch=%u (%c)\n", ch, ch>32? ch: ' ') ); + log(("NLS: nlsYesNo(): in ch=%u (%c)\n", ch, ch > 32 ? ch : ' ')); - xUpMem(nls, &ch, 1); /* Upcase character */ - /* Cannot use DosUpChar(), because - maybe: nls != current NLS pkg - However: Upcase character within lowlevel - function to allow a yesNo() function - catched by external MUX-14 handler, which - does NOT upcase character. */ -log( ("NLS: nlsYesNo(): upcased ch=%u (%c)\n", ch, ch>32? ch: ' ') ); - if(ch == nls->yeschar) - return 1; - if(ch == nls->nochar) - return 0; - return 2; + xUpMem(nls, &ch, 1); /* Upcase character */ + /* Cannot use DosUpChar(), because + maybe: nls != current NLS pkg + However: Upcase character within lowlevel + function to allow a yesNo() function + catched by external MUX-14 handler, which + does NOT upcase character. */ + log(("NLS: nlsYesNo(): upcased ch=%u (%c)\n", ch, ch > 32 ? ch : ' ')); + if (ch == nls->yeschar) + return 1; + if (ch == nls->nochar) + return 0; + return 2; } - /******************************************************************** ***** DOS API ****************************************************** ********************************************************************/ @@ -441,16 +448,16 @@ log( ("NLS: nlsYesNo(): upcased ch=%u (%c)\n", ch, ch>32? ch: ' ') ); BYTE DosYesNo(unsigned char ch) /* returns: 0: ch == "No", 1: ch == "Yes", 2: ch crap */ { - if(nlsInfo.actPkg->flags & NLS_FLAG_DIRECT_YESNO) - return nlsYesNo(nlsInfo.actPkg, ch); - else - return muxYesNo(ch); + if (nlsInfo.actPkg->flags & NLS_FLAG_DIRECT_YESNO) + return nlsYesNo(nlsInfo.actPkg, ch); + else + return muxYesNo(ch); } - #ifndef DosUpMem VOID DosUpMem(VOID FAR * str, unsigned len) -{ xUpMem(nlsInfo.actPkg, str, len); +{ + xUpMem(nlsInfo.actPkg, str, len); } #endif @@ -463,47 +470,48 @@ VOID DosUpMem(VOID FAR * str, unsigned len) unsigned char ASMCFUNC DosUpChar(unsigned char ch) /* upcase a single character */ { - assertDSeqSS(); /* because "&ch" */ -log( ("NLS: DosUpChar(): in ch=%u (%c)\n", ch, ch>32? ch: ' ') ); - DosUpMem((UBYTE FAR*)&ch, 1); -log( ("NLS: DosUpChar(): upcased ch=%u (%c)\n", ch, ch>32? ch: ' ') ); - return ch; + assertDSeqSS(); /* because "&ch" */ + log(("NLS: DosUpChar(): in ch=%u (%c)\n", ch, ch > 32 ? ch : ' ')); + DosUpMem((UBYTE FAR *) & ch, 1); + log(("NLS: DosUpChar(): upcased ch=%u (%c)\n", ch, ch > 32 ? ch : ' ')); + return ch; } -VOID DosUpString(char FAR *str) +VOID DosUpString(char FAR * str) /* upcase a string */ { - DosUpMem(str, fstrlen(str)); + DosUpMem(str, fstrlen(str)); } -VOID DosUpFMem(VOID FAR *str, unsigned len) +VOID DosUpFMem(VOID FAR * str, unsigned len) /* upcase a memory area for file names */ { #ifdef NLS_DEBUG - unsigned c; -log( ("NLS: DosUpFMem(): len=%u, %04x:%04x=\"", len, FP_SEG(str), FP_OFF(str)) ); - for(c = 0; c < len; ++c) - printf("%c", str[c] > 32? str[c]: '.'); - printf("\"\n"); + unsigned c; + log(("NLS: DosUpFMem(): len=%u, %04x:%04x=\"", len, FP_SEG(str), + FP_OFF(str))); + for (c = 0; c < len; ++c) + printf("%c", str[c] > 32 ? str[c] : '.'); + printf("\"\n"); #endif - if(nlsInfo.actPkg->flags & NLS_FLAG_DIRECT_FUPCASE) - nlsFUpMem(nlsInfo.actPkg, str, len); - else - muxUpMem(NLSFUNC_FILE_UPMEM, str, len); + if (nlsInfo.actPkg->flags & NLS_FLAG_DIRECT_FUPCASE) + nlsFUpMem(nlsInfo.actPkg, str, len); + else + muxUpMem(NLSFUNC_FILE_UPMEM, str, len); } unsigned char DosUpFChar(unsigned char ch) /* upcase a single character for file names */ { - assertDSeqSS(); /* because "&ch" */ - DosUpFMem((UBYTE FAR*)&ch, 1); - return ch; + assertDSeqSS(); /* because "&ch" */ + DosUpFMem((UBYTE FAR *) & ch, 1); + return ch; } -VOID DosUpFString(char FAR *str) +VOID DosUpFString(char FAR * str) /* upcase a string for file names */ { - DosUpFMem(str, fstrlen(str)); + DosUpFMem(str, fstrlen(str)); } /* @@ -514,34 +522,35 @@ VOID DosUpFString(char FAR *str) * loaded, MUX-14 is invoked; otherwise the pkg's NLS_Fct_buf * function is invoked. */ -COUNT DosGetData(int subfct, UWORD cp, UWORD cntry - , UWORD bufsize, VOID FAR * buf) -{ struct nlsPackage FAR*nls; /* NLS package to use to return the info from */ +COUNT DosGetData(int subfct, UWORD cp, UWORD cntry, UWORD bufsize, + VOID FAR * buf) +{ + struct nlsPackage FAR *nls; /* NLS package to use to return the info from */ -log( ("NLS: GetData(): subfct=%x, cp=%u, cntry=%u, bufsize=%u\n", - subfct, cp, cntry, bufsize) ); + log(("NLS: GetData(): subfct=%x, cp=%u, cntry=%u, bufsize=%u\n", + subfct, cp, cntry, bufsize)); - if(!buf || !bufsize) - return DE_INVLDDATA; - if(subfct == 0) /* Currently not supported */ - return DE_INVLDFUNC; + if (!buf || !bufsize) + return DE_INVLDDATA; + if (subfct == 0) /* Currently not supported */ + return DE_INVLDFUNC; - /* nls := NLS package of cntry/codepage */ - if((nls = searchPackage(cp, cntry)) == NULL - || (nls->flags & NLS_FLAG_DIRECT_GETDATA) == 0) { - /* If the NLS pkg is not loaded into memory or the - direct-access flag is disabled, the request must - be passed through MUX */ - return (subfct == NLS_DOS_38) - ? mux38(nls->cp, nls->cntry, bufsize, buf) - : mux65(subfct, nls->cp, nls->cntry, bufsize, buf); - } + /* nls := NLS package of cntry/codepage */ + if ((nls = searchPackage(cp, cntry)) == NULL + || (nls->flags & NLS_FLAG_DIRECT_GETDATA) == 0) + { + /* If the NLS pkg is not loaded into memory or the + direct-access flag is disabled, the request must + be passed through MUX */ + return (subfct == NLS_DOS_38) + ? mux38(nls->cp, nls->cntry, bufsize, buf) + : mux65(subfct, nls->cp, nls->cntry, bufsize, buf); + } - /* Direct access to the data */ - return nlsGetData(nls, subfct, buf, bufsize); + /* Direct access to the data */ + return nlsGetData(nls, subfct, buf, bufsize); } - /* * Called for DOS-38 get info * @@ -556,10 +565,11 @@ log( ("NLS: GetData(): subfct=%x, cp=%u, cntry=%u, bufsize=%u\n", * RBIL documents 0x18 bytes and calls 10 bytes 'reserved' * so we change the amount of copied bytes to 0x18 */ - + #ifndef DosGetCountryInformation -COUNT DosGetCountryInformation(UWORD cntry, VOID FAR *buf) -{ return DosGetData(NLS_DOS_38, NLS_DEFAULT, cntry, 0x18, buf); +COUNT DosGetCountryInformation(UWORD cntry, VOID FAR * buf) +{ + return DosGetData(NLS_DOS_38, NLS_DEFAULT, cntry, 0x18, buf); } #endif @@ -568,17 +578,19 @@ COUNT DosGetCountryInformation(UWORD cntry, VOID FAR *buf) */ #ifndef DosSetCountry COUNT DosSetCountry(UWORD cntry) -{ return DosSetPackage(NLS_DEFAULT, cntry); +{ + return DosSetPackage(NLS_DEFAULT, cntry); } #endif /* * Called for DOS-66-01 get CP */ -COUNT DosGetCodepage(UWORD FAR* actCP, UWORD FAR* sysCP) -{ *sysCP = nlsInfo.sysCodePage; - *actCP = nlsInfo.actPkg->cp; - return SUCCESS; +COUNT DosGetCodepage(UWORD FAR * actCP, UWORD FAR * sysCP) +{ + *sysCP = nlsInfo.sysCodePage; + *actCP = nlsInfo.actPkg->cp; + return SUCCESS; } /* @@ -587,9 +599,10 @@ COUNT DosGetCodepage(UWORD FAR* actCP, UWORD FAR* sysCP) * to specify it, is lost to me. (2000/02/13 ska) */ COUNT DosSetCodepage(UWORD actCP, UWORD sysCP) -{ if(sysCP == NLS_DEFAULT || sysCP == nlsInfo.sysCodePage) - return DosSetPackage(actCP, NLS_DEFAULT); - return DE_INVLDDATA; +{ + if (sysCP == NLS_DEFAULT || sysCP == nlsInfo.sysCodePage) + return DosSetPackage(actCP, NLS_DEFAULT); + return DE_INVLDDATA; } /******************************************************************** @@ -608,57 +621,59 @@ COUNT DosSetCodepage(UWORD actCP, UWORD sysCP) if AL == 0, Carry must be cleared, otherwise set */ UWORD ASMCFUNC syscall_MUX14(DIRECT_IREGS) -{ struct nlsPackage FAR*nls; /* addressed NLS package */ +{ + struct nlsPackage FAR *nls; /* addressed NLS package */ - UNREFERENCED_PARAMETER (flags); - UNREFERENCED_PARAMETER (cs); - UNREFERENCED_PARAMETER (ip); - UNREFERENCED_PARAMETER (ds); - UNREFERENCED_PARAMETER (es); - UNREFERENCED_PARAMETER (si); + UNREFERENCED_PARAMETER(flags); + UNREFERENCED_PARAMETER(cs); + UNREFERENCED_PARAMETER(ip); + UNREFERENCED_PARAMETER(ds); + UNREFERENCED_PARAMETER(es); + UNREFERENCED_PARAMETER(si); -log( ("NLS: MUX14(): subfct=%x, cp=%u, cntry=%u\n", - AL, BX, DX) ); + log(("NLS: MUX14(): subfct=%x, cp=%u, cntry=%u\n", AL, BX, DX)); - if((nls = searchPackage(BX, DX)) == NULL) - return DE_INVLDFUNC; /* no such package */ + if ((nls = searchPackage(BX, DX)) == NULL) + return DE_INVLDFUNC; /* no such package */ -log( ("NLS: MUX14(): NLS pkg found\n") ); + log(("NLS: MUX14(): NLS pkg found\n")); - switch(AL) { - case NLSFUNC_INSTALL_CHECK: - BX = NLS_FREEDOS_NLSFUNC_ID; - return SUCCESS; /* kernel just simulates default functions */ - case NLSFUNC_DOS38: - return nlsGetData(nls, NLS_DOS_38, MK_FP(ES, DI), 34); - case NLSFUNC_GETDATA: - return nlsGetData(nls, BP, MK_FP(ES, DI), CX); - case NLSFUNC_DRDOS_GETDATA: - /* Does not pass buffer length */ - return nlsGetData(nls, CL, MK_FP(ES, DI), 512); - case NLSFUNC_LOAD_PKG: - case NLSFUNC_LOAD_PKG2: - return nlsSetPackage(nls); - case NLSFUNC_YESNO: - return nlsYesNo(nls, CL); - case NLSFUNC_UPMEM: - nlsUpMem(nls, MK_FP(ES, DI), CX); - return SUCCESS; - case NLSFUNC_FILE_UPMEM: + switch (AL) + { + case NLSFUNC_INSTALL_CHECK: + BX = NLS_FREEDOS_NLSFUNC_ID; + return SUCCESS; /* kernel just simulates default functions */ + case NLSFUNC_DOS38: + return nlsGetData(nls, NLS_DOS_38, MK_FP(ES, DI), 34); + case NLSFUNC_GETDATA: + return nlsGetData(nls, BP, MK_FP(ES, DI), CX); + case NLSFUNC_DRDOS_GETDATA: + /* Does not pass buffer length */ + return nlsGetData(nls, CL, MK_FP(ES, DI), 512); + case NLSFUNC_LOAD_PKG: + case NLSFUNC_LOAD_PKG2: + return nlsSetPackage(nls); + case NLSFUNC_YESNO: + return nlsYesNo(nls, CL); + case NLSFUNC_UPMEM: + nlsUpMem(nls, MK_FP(ES, DI), CX); + return SUCCESS; + case NLSFUNC_FILE_UPMEM: #ifdef NLS_DEBUG -{ unsigned j; - BYTE FAR *p; -log( ("NLS: MUX14(FILE_UPMEM): len=%u, %04x:%04x=\"", CX, ES, DI) ); - for(j = 0, p = MK_FP(ES, DI); j < CX; ++j) - printf("%c", p[j] > 32? p[j]: '.'); - printf("\"\n"); -} + { + unsigned j; + BYTE FAR *p; + log(("NLS: MUX14(FILE_UPMEM): len=%u, %04x:%04x=\"", CX, ES, DI)); + for (j = 0, p = MK_FP(ES, DI); j < CX; ++j) + printf("%c", p[j] > 32 ? p[j] : '.'); + printf("\"\n"); + } #endif - nlsFUpMem(nls, MK_FP(ES, DI), CX); - return SUCCESS; - } -log( ("NLS: MUX14(): Invalid function %x\n", AL) ); - return DE_INVLDFUNC; /* no such function */ + nlsFUpMem(nls, MK_FP(ES, DI), CX); + return SUCCESS; + } + log(("NLS: MUX14(): Invalid function %x\n", AL)); + return DE_INVLDFUNC; /* no such function */ } /* @@ -668,4 +683,3 @@ log( ("NLS: MUX14(): Invalid function %x\n", AL) ); * Initial revision * */ - diff --git a/kernel/nls_load.c b/kernel/nls_load.c index 43b7a52..96994fe 100644 --- a/kernel/nls_load.c +++ b/kernel/nls_load.c @@ -28,14 +28,14 @@ /* Cambridge, MA 02139, USA. */ /****************************************************************/ - #include "portab.h" #include "globals.h" //#include "pcb.h" #include #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif #define filename Config.cfgCSYS_fnam @@ -44,79 +44,87 @@ static BYTE *RcsId = "$Id$"; static int err(void) { - printf("Syntax error in or invalid COUNTRY.SYS: \"%s\"\n" - , filename); - return 0; + printf("Syntax error in or invalid COUNTRY.SYS: \"%s\"\n", filename); + return 0; } #define readStruct(s) readStructure(&(s), sizeof(s), fd) static int readStructure(void *buf, int size, COUNT fd) -{ if(DosRead(fd, buf, size) == size) - return 1; +{ + if (DosRead(fd, buf, size) == size) + return 1; - return err(); + return err(); } - /* Evaluate each argument only once */ + + /* Evaluate each argument only once */ #define readFct(p,f) readFct_((p), (f), fd) int readFct_(void *buf, struct csys_function *fct, COUNT fd) -{ if(DosLseek(fd, fct->csys_rpos, 0) >= 0) - return readStructure(buf, fct->csys_length, fd); - return err(); +{ + if (DosLseek(fd, fct->csys_rpos, 0) >= 0) + return readStructure(buf, fct->csys_length, fd); + return err(); } #define seek(n) rseek((LONG)(n), fd) static rseek(LONG rpos, COUNT fd) -{ if(DosLseek(fd, rpos, 1) >= 0) - return 1; +{ + if (DosLseek(fd, rpos, 1) >= 0) + return 1; - return err(); + return err(); } - COUNT csysOpen(void) -{ COUNT fd; - struct nlsCSys_fileHeader header; +{ + COUNT fd; + struct nlsCSys_fileHeader header; - if((fd = DosOpen((BYTE FAR*)filename, 0)) < 0) { - printf("Cannot open: \"%s\"\n", filename); - return 1; - } + if ((fd = DosOpen((BYTE FAR *) filename, 0)) < 0) + { + printf("Cannot open: \"%s\"\n", filename); + return 1; + } - if(DosRead(fd, &header, sizeof(header)) != sizeof(header); - || strcmp(header.csys_idstring, CSYS_FD_IDSTRING) != 0 - || DosLseek(fd, (LONG)sizeof(csys_completeFileHeader), 0) - != (LONG)sizeof(csys_completeFileHeader)) { - printf("No valid COUNTRY.SYS: \"%s\"\n\nTry NLSFUNC /i %s\n" - , filename, filename); - DosClose(fd); - return -1; - } + if (DosRead(fd, &header, sizeof(header)) != sizeof(header); + ||strcmp(header.csys_idstring, CSYS_FD_IDSTRING) != 0 + || DosLseek(fd, (LONG) sizeof(csys_completeFileHeader), 0) + != (LONG) sizeof(csys_completeFileHeader)) + { + printf("No valid COUNTRY.SYS: \"%s\"\n\nTry NLSFUNC /i %s\n", filename, + filename); + DosClose(fd); + return -1; + } - return fd; + return fd; } /* Searches for function definition of table #fctID and moves it at index idx */ -static int chkTable(int idx, int fctID, struct csys_function *fcts - , int numFct) -{ struct csys_function *fct, hfct; - int i; +static int chkTable(int idx, int fctID, struct csys_function *fcts, + int numFct) +{ + struct csys_function *fct, hfct; + int i; - for(i = 0, fct = fcts; i < numFct; ++i, ++fct) - if(fct->csys_fctID == fctID) { - /* function found */ - if(i == idx) /* already best place */ - return 1; - /* Swap both places */ - memcpy(&hfct, fct, sizeof(hfct)); - memcpy(fct, &fcts[idx], sizeof(hfct)); - memcpy(&fcts[idx], &hfct, sizeof(hfct)); - return 1; - } + for (i = 0, fct = fcts; i < numFct; ++i, ++fct) + if (fct->csys_fctID == fctID) + { + /* function found */ + if (i == idx) /* already best place */ + return 1; + /* Swap both places */ + memcpy(&hfct, fct, sizeof(hfct)); + memcpy(fct, &fcts[idx], sizeof(hfct)); + memcpy(&fcts[idx], &hfct, sizeof(hfct)); + return 1; + } - printf("Mandatory table %u not found.\n", fctID); - return 0; + printf("Mandatory table %u not found.\n", fctID); + return 0; } + /* * Description of the algorithm the COUNTRY= information is loaded. @@ -172,7 +180,6 @@ a) The area containing the S3 structures, and b) probably the last loaded data could be found within the memory already, so the nlsPackage structure is larger than necessary. - 8) But the memory allocation in pass 1 is temporary anyway, because in the PostConfig() phase, all memory allocations are revoked and created anew. At this point -- immediately after revoking all memory and @@ -197,187 +204,208 @@ indicates that the FP_OFF(...) is the offset base-relative to the data offset; which is base-relative to the "nls" pointer. */ int csysLoadPackage(COUNT fd) -{ struct csys_numEntries entries; - struct csys_ccDefinition entry; - struct csys_function *fcts; - struct nlsPackage *nls; - struct nlsPointer *poi; - int highmark, numFct, i, j; - int totalSize; +{ + struct csys_numEntries entries; + struct csys_ccDefinition entry; + struct csys_function *fcts; + struct nlsPackage *nls; + struct nlsPointer *poi; + int highmark, numFct, i, j; + int totalSize; #ifndef NLS_MODIFYABLE_DATA - BYTE FAR * p; + BYTE FAR *p; #endif #define numE entries.csys_entries #define bufp(offset) (((BYTE*)nls) + (offset)) #define fct fcts[numFct] - /* When this function is called, the position of the file is - at offset 128 (number of country/codepage pairs) */ - if(!readStruct(entries)) - return 0; - while(numE--) { - if(!readStruct(entry)) - return 0; - if(entry.csys_cntry == cntry - && (cp == NLS_DEFAULT || entry.csys_cp == cp)) { - /* Requested entry found! */ - if(!seek(entry.csys_rpos) - || !readStruct(entries)) - return 0; - /* Now reading the function definitions at this position */ - if(numE < 5) { - printf("Syntax error in COUNTRY.SYS: Too few subfunctions\n"); - return 0; - } - /* If the file structure is good, each but one entry (0x23) is - one item within nlsPointers[] array */ - fcts = KernelAlloc(sizeof(struct csys_function) * numE); - numFct = 0; /* number of already loaded fct definition */ - totalSize = 0; - { - if(!readStruct(fct)) - return 0; - switch(fct.csys_fctID) { - case 0: case 0x20: case 0x21: case 0x22: - case 0xA0: case 0xA1: case 0xA2: - printf("Invalid subfunction %u ignored", fct.csys_fctID); - continue; - case 0x23: - if(fct.csys_length != 2) { - printf("Pseudo-table 35 length mismatch\n"); - continue; - } - } - /* Search if the subfunction is already there */ - for(j = 0; j < numFcts && fcts[j].csys_fctID != fct.csys_fctID - ; ++j); - if(j != numFct) { - printf("Subfunction %u defined multiple times, ignored\n" - , fct.csys_fctID); - continue; - } + /* When this function is called, the position of the file is + at offset 128 (number of country/codepage pairs) */ + if (!readStruct(entries)) + return 0; + while (numE--) + { + if (!readStruct(entry)) + return 0; + if (entry.csys_cntry == cntry + && (cp == NLS_DEFAULT || entry.csys_cp == cp)) + { + /* Requested entry found! */ + if (!seek(entry.csys_rpos) || !readStruct(entries)) + return 0; + /* Now reading the function definitions at this position */ + if (numE < 5) + { + printf("Syntax error in COUNTRY.SYS: Too few subfunctions\n"); + return 0; + } + /* If the file structure is good, each but one entry (0x23) is + one item within nlsPointers[] array */ + fcts = KernelAlloc(sizeof(struct csys_function) * numE); + numFct = 0; /* number of already loaded fct definition */ + totalSize = 0; + { + if (!readStruct(fct)) + return 0; + switch (fct.csys_fctID) + { + case 0: + case 0x20: + case 0x21: + case 0x22: + case 0xA0: + case 0xA1: + case 0xA2: + printf("Invalid subfunction %u ignored", fct.csys_fctID); + continue; + case 0x23: + if (fct.csys_length != 2) + { + printf("Pseudo-table 35 length mismatch\n"); + continue; + } + } + /* Search if the subfunction is already there */ + for (j = 0; j < numFcts && fcts[j].csys_fctID != fct.csys_fctID; + ++j) ; + if (j != numFct) + { + printf("Subfunction %u defined multiple times, ignored\n", + fct.csys_fctID); + continue; + } - /* OK --> update the rpos member */ - fct.csys_rpos += DosLtell(fd); - totalSize += fct.csys_length; - ++numFct; - } while(--numE); + /* OK --> update the rpos member */ + fct.csys_rpos += DosLtell(fd); + totalSize += fct.csys_length; + ++numFct; + } + while (--numE) ; - /* i is the number of available function definition */ - /* check if all mandatory tables are loaded, at the same - time re-order the function definitions like that: - 0x23, 1, 2, 4, 5 - */ + /* i is the number of available function definition */ + /* check if all mandatory tables are loaded, at the same + time re-order the function definitions like that: + 0x23, 1, 2, 4, 5 + */ - /* That's automatically a check that more than 3 definitions - are available */ - if(!chkTable(0, 0x23, fcts, numFct) /* pseudo-table 0x23 yes/no */ - || !chkTable(1, 1, fcts, numFct) /* ext cntry info */ - || !chkTable(2, 2, fcts, numFct) /* normal upcase */ - || !chkTable(3, 4, fcts, numFct) /* filename upcase */ - || !chkTable(4, 5, fcts, numFct)) /* filename terminator chars */ - return 0; + /* That's automatically a check that more than 3 definitions + are available */ + if (!chkTable(0, 0x23, fcts, numFct) /* pseudo-table 0x23 yes/no */ + || !chkTable(1, 1, fcts, numFct) /* ext cntry info */ + || !chkTable(2, 2, fcts, numFct) /* normal upcase */ + || !chkTable(3, 4, fcts, numFct) /* filename upcase */ + || !chkTable(4, 5, fcts, numFct)) /* filename terminator chars */ + return 0; - /* Begin the loading process by to allocate memory as if - we had to load every byte */ - /* One nlsPointers structure is already part of nlsPackage; - two function definitions need no nlsPointers entry (0x32, 1); - one additional byte is required by table 1, but which is - already within totalSize as the length of pseudo-table - 0x23 has been counted. */ - nls = KernelAlloc((data = sizeof(nlsPackage) - + (numFct - 3) * sizeof(struct nlsPointer)) + totalSize); - /* data := first byte not used by the control area of - the nlsPackage structure; at this point it is the - offset where table #1 is to be loaded to*/ + /* Begin the loading process by to allocate memory as if + we had to load every byte */ + /* One nlsPointers structure is already part of nlsPackage; + two function definitions need no nlsPointers entry (0x32, 1); + one additional byte is required by table 1, but which is + already within totalSize as the length of pseudo-table + 0x23 has been counted. */ + nls = KernelAlloc((data = sizeof(nlsPackage) + + (numFct - 3) * sizeof(struct nlsPointer)) + + totalSize); + /* data := first byte not used by the control area of + the nlsPackage structure; at this point it is the + offset where table #1 is to be loaded to */ - /* Install pseudo-table 0x23 */ - if(!readFct((BYTE*)&nls->yeschar, fcts)) - return 0; - nls->numSubfct = numFct - 1; /* pseudo-table 0x23 */ + /* Install pseudo-table 0x23 */ + if (!readFct((BYTE *) & nls->yeschar, fcts)) + return 0; + nls->numSubfct = numFct - 1; /* pseudo-table 0x23 */ - /* Install table #1 has it must overlay the last nlsPointers[] - item */ - *bufp(data) = 1; /* table #1 starts with the subfctID - then the data from the file follows */ - if(!readFct(bufp(++data), ++fcts)) - return 0; - data += fcts->csys_length; /* first byte of local data area */ - highmark = data; /* first unused byte */ + /* Install table #1 has it must overlay the last nlsPointers[] + item */ + *bufp(data) = 1; /* table #1 starts with the subfctID + then the data from the file follows */ + if (!readFct(bufp(++data), ++fcts)) + return 0; + data += fcts->csys_length; /* first byte of local data area */ + highmark = data; /* first unused byte */ - for(j = 0, poi = nls->nlsPointers; j < numFct - 1; ++j, ++poi) { - /* consecutively load all functions */ - if(!readFct(bufp(data), ++fcts)) - return 0; - poi->subfct = fcts->csys_fctID; - /* Now the function data is located at the current top of - used memory and, if allowed, the other memory is - tested, if such image is already loaded */ + for (j = 0, poi = nls->nlsPointers; j < numFct - 1; ++j, ++poi) + { + /* consecutively load all functions */ + if (!readFct(bufp(data), ++fcts)) + return 0; + poi->subfct = fcts->csys_fctID; + /* Now the function data is located at the current top of + used memory and, if allowed, the other memory is + tested, if such image is already loaded */ #ifndef NLS_MODIFYABLE_DATA - /* Try to locate the contents of the buffer */ - /** brute force **/ - /* For the standard tables one need to match tables - 2 and 4 only. */ - for(i = data; i + fcts->csys_length < highmark; ++i) { - if(memcmp(bufp(i), bufp(highmark), fcts->csys_length) - == 0) { - /* found! */ - /* ==> leave highmark untouch, but modify pointer */ - poi->pointer = MK_FP(0, i); - /* the segment portion == 0 identifies this pointer - as local within the current data area */ - goto nxtEntry; - } - } - /* Now try the hardcoded area */ - for(p = hcTablesStart; p < hcTablesEnd - fcts->csys_length - ; ++p) { - if(fmemcmp(p, bufp(highmark), fcts->csys_length) == 0) { - /* found! */ - /* ==> leave highmark untouch, but modify pointer */ - poi->pointer = p; - /* the segment portion != 0 identifies this is an - absolute pointer */ - goto nxtEntry; - } - } + /* Try to locate the contents of the buffer */ + /** brute force **/ + /* For the standard tables one need to match tables + 2 and 4 only. */ + for (i = data; i + fcts->csys_length < highmark; ++i) + { + if (memcmp(bufp(i), bufp(highmark), fcts->csys_length) == 0) + { + /* found! */ + /* ==> leave highmark untouch, but modify pointer */ + poi->pointer = MK_FP(0, i); + /* the segment portion == 0 identifies this pointer + as local within the current data area */ + goto nxtEntry; + } + } + /* Now try the hardcoded area */ + for (p = hcTablesStart; p < hcTablesEnd - fcts->csys_length; ++p) + { + if (fmemcmp(p, bufp(highmark), fcts->csys_length) == 0) + { + /* found! */ + /* ==> leave highmark untouch, but modify pointer */ + poi->pointer = p; + /* the segment portion != 0 identifies this is an + absolute pointer */ + goto nxtEntry; + } + } #endif - /* Either not found or modifyable data allowed */ - poi->pointer = MK_FP(0, highmark); /* local address */ - highmark += fcts->csys_length; /* need to keep the data */ - nxtEntry: - } - /* how many memory is really required */ - Country.cfgCSYS_memory = highmark; - Country.cfgCSYS_data = nls; - return 1; - } - } + /* Either not found or modifyable data allowed */ + poi->pointer = MK_FP(0, highmark); /* local address */ + highmark += fcts->csys_length; /* need to keep the data */ + nxtEntry: + } + /* how many memory is really required */ + Country.cfgCSYS_memory = highmark; + Country.cfgCSYS_data = nls; + return 1; + } + } #undef numE - if(cp == NLS_DEFAULT) - printf("No definition of country ID %u in file \"%s\"\n", - cntry, filename); - else - printf("No definition of country ID %u for codepage %u in file \"%s\"\n", - cntry, cp, filename); + if (cp == NLS_DEFAULT) + printf("No definition of country ID %u in file \"%s\"\n", + cntry, filename); + else + printf + ("No definition of country ID %u for codepage %u in file \"%s\"\n", + cntry, cp, filename); - return 0; + return 0; } INIT BOOL LoadCountryInfo(char *fnam) -{ COUNT fd; - int rc; +{ + COUNT fd; + int rc; - if(strlen(fnam) < sizeof(filename)) { - strcpy(filename, fnam); - if((fd = csysOpen()) >= 0) { - rc = csysLoadPackage(fd); - DosClose(fd); - return rc; - } - } else - printf("Filename too long\n"); - return 0; + if (strlen(fnam) < sizeof(filename)) + { + strcpy(filename, fnam); + if ((fd = csysOpen()) >= 0) + { + rc = csysLoadPackage(fd); + DosClose(fd); + return rc; + } + } + else + printf("Filename too long\n"); + return 0; } /* @@ -387,4 +415,3 @@ INIT BOOL LoadCountryInfo(char *fnam) * Add new files and update cvs with patches and changes * */ - diff --git a/kernel/prf.c b/kernel/prf.c index 499f1ef..8e112e0 100644 --- a/kernel/prf.c +++ b/kernel/prf.c @@ -41,11 +41,11 @@ #define hexd init_hexd #endif -COUNT ASMCFUNC fstrlen (BYTE FAR * s); /* don't want globals.h, sorry */ - +COUNT ASMCFUNC fstrlen(BYTE FAR * s); /* don't want globals.h, sorry */ #ifdef VERSION_STRINGS -static BYTE *prfRcsId = "$Id$"; +static BYTE *prfRcsId = + "$Id$"; #endif static BYTE *charp = 0; @@ -70,45 +70,44 @@ VOID cso(); #endif #ifdef FORSYS -COUNT fstrlen (BYTE FAR * s) /* don't want globals.h, sorry */ +COUNT fstrlen(BYTE FAR * s) /* don't want globals.h, sorry */ { - int i = 0; + int i = 0; - while (*s++) - i++; + while (*s++) + i++; - return i; + return i; } #endif /* special console output routine */ -VOID -put_console(COUNT c) +VOID put_console(COUNT c) { if (c == '\n') put_console('\r'); #ifdef FORSYS - write(1,&c,1); /* write character to stdout */ -#else -#if defined(__TURBOC__) + write(1, &c, 1); /* write character to stdout */ +#else +#if defined(__TURBOC__) _AX = 0x0e00 | c; _BX = 0x0070; __int__(0x10); #else - __asm { - mov al, byte ptr c; - mov ah, 0x0e; - mov bx, 0x0070; - int 0x10; - } -#endif /* __TURBO__*/ -#endif + __asm + { + mov al, byte ptr c; + mov ah, 0x0e; + mov bx, 0x0070; + int 0x10; + } +#endif /* __TURBO__ */ +#endif } /* special handler to switch between sprintf and printf */ -static VOID - handle_char(COUNT c) +static VOID handle_char(COUNT c) { if (charp == 0) put_console(c); @@ -117,34 +116,33 @@ static VOID } /* ltob -- convert an long integer to a string in any base (2-16) */ -BYTE * - ltob(LONG n, BYTE * s, COUNT base) +BYTE *ltob(LONG n, BYTE * s, COUNT base) { ULONG u; BYTE *p, *q; - int c; + int c; - u = n; + u = n; if (base == -10) /* signals signed conversion */ - { + { base = 10; - if (n < 0 ) - { - u = -n; - *s++ = '-'; - } - } - + if (n < 0) + { + u = -n; + *s++ = '-'; + } + } + p = q = s; do { /* generate digits in reverse order */ - static char hexDigits[] = "0123456789abcdef"; - - *p++ = hexDigits[(UWORD)(u % base)]; + static char hexDigits[] = "0123456789abcdef"; + + *p++ = hexDigits[(UWORD) (u % base)]; } while ((u /= base) > 0); - + *p = '\0'; /* terminate the string */ while (q < --p) { /* reverse the digits */ @@ -155,7 +153,6 @@ BYTE * return s; } - #define LEFT 0 #define RIGHT 1 @@ -165,9 +162,9 @@ WORD printf(CONST BYTE * fmt, ...) { WORD ret; - static char buff[80]; /* adjust if necessary */ + static char buff[80]; /* adjust if necessary */ charp = buff; - ret = do_printf(fmt, (BYTE **)&fmt + 1); + ret = do_printf(fmt, (BYTE **) & fmt + 1); handle_char(NULL); _ES = FP_SEG(buff); _DX = FP_OFF(buff); @@ -179,20 +176,20 @@ WORD printf(CONST BYTE * fmt, ...) WORD printf(CONST BYTE * fmt, ...) { charp = 0; - return do_printf(fmt, (BYTE **)&fmt + 1); + return do_printf(fmt, (BYTE **) & fmt + 1); } #endif -WORD -sprintf(BYTE * buff, CONST BYTE * fmt, ...) +WORD sprintf(BYTE * buff, CONST BYTE * fmt, ...) { WORD ret; charp = buff; - ret = do_printf(fmt, (BYTE **)&fmt + 1); + ret = do_printf(fmt, (BYTE **) & fmt + 1); handle_char(NULL); return ret; } + /* ULONG FAR retcs(int i) { @@ -202,19 +199,14 @@ ULONG FAR retcs(int i) return *(ULONG *)p; } */ -COUNT - do_printf(CONST BYTE * fmt, BYTE ** arg) +COUNT do_printf(CONST BYTE * fmt, BYTE ** arg) { int base; - BYTE s[11], - FAR *p; - int c, - flag, - size, - fill; - int longarg; + BYTE s[11], FAR * p; + int c, flag, size, fill; + int longarg; long currentArg; - + /* long cs = retcs(1); put_console("0123456789ABCDEF"[(cs >> 28) & 0x0f]); @@ -235,154 +227,148 @@ COUNT continue; } - longarg = FALSE; - size = 0; + longarg = FALSE; + size = 0; flag = RIGHT; fill = ' '; - if ( *fmt == '-') + if (*fmt == '-') { flag = LEFT; fmt++; } - - if ( *fmt == '0') + + if (*fmt == '0') { fill = '0'; fmt++; } - while (*fmt >= '0' && *fmt <= '9') - { + while (*fmt >= '0' && *fmt <= '9') + { size = size * 10 + (*fmt++ - '0'); - } - - + } if (*fmt == 'l') { - longarg = TRUE; - fmt++; + longarg = TRUE; + fmt++; } - c = *fmt++; switch (c) { - case '\0': - return 0; - + case '\0': + return 0; + case 'c': - handle_char(*(COUNT *) arg++); - continue; + handle_char(*(COUNT *) arg++); + continue; case 'p': - { - UWORD w[2]; - static char pointerFormat[] = "%04x:%04x"; - w[1] = *((UWORD *) arg); - arg += sizeof(UWORD)/sizeof(BYTE *); - w[0] = *((UWORD *) arg); - arg += sizeof(UWORD)/sizeof(BYTE *); - do_printf(pointerFormat,(BYTE**)&w); - continue; - } + { + UWORD w[2]; + static char pointerFormat[] = "%04x:%04x"; + w[1] = *((UWORD *) arg); + arg += sizeof(UWORD) / sizeof(BYTE *); + w[0] = *((UWORD *) arg); + arg += sizeof(UWORD) / sizeof(BYTE *); + do_printf(pointerFormat, (BYTE **) & w); + continue; + } case 's': - p = *arg++; - goto do_outputstring; - + p = *arg++; + goto do_outputstring; + case 'F': - fmt++; - /* we assume %Fs here */ + fmt++; + /* we assume %Fs here */ case 'S': - p = *((BYTE FAR **) arg); - arg += sizeof(BYTE FAR *)/sizeof(BYTE *); - goto do_outputstring; + p = *((BYTE FAR **) arg); + arg += sizeof(BYTE FAR *) / sizeof(BYTE *); + goto do_outputstring; case 'i': case 'd': - base = -10; - goto lprt; + base = -10; + goto lprt; case 'o': - base = 8; - goto lprt; + base = 8; + goto lprt; case 'u': - base = 10; - goto lprt; + base = 10; + goto lprt; case 'X': case 'x': - base = 16; + base = 16; - lprt: - if (longarg) - { - currentArg = *((LONG *) arg); - arg += sizeof(LONG)/sizeof(BYTE *); - } - else - { - if (base < 0) - { - currentArg = *((int*) arg); - arg += sizeof(int)/sizeof(BYTE *); - } - else - { - currentArg = *((unsigned int*) arg); - arg += sizeof(unsigned int)/sizeof(BYTE *); - } - } - - ltob(currentArg, s, base); + lprt: + if (longarg) + { + currentArg = *((LONG *) arg); + arg += sizeof(LONG) / sizeof(BYTE *); + } + else + { + if (base < 0) + { + currentArg = *((int *)arg); + arg += sizeof(int) / sizeof(BYTE *); + } + else + { + currentArg = *((unsigned int *)arg); + arg += sizeof(unsigned int) / sizeof(BYTE *); + } + } - p = s; -do_outputstring: - - size -= fstrlen(p); - - if (flag == RIGHT ) - { - for ( ; size > 0; size--) - handle_char(fill); - } - for (; *p != '\0'; p++) - handle_char(*p); + ltob(currentArg, s, base); - for ( ; size > 0; size--) - handle_char(fill); - - continue; + p = s; + do_outputstring: - default: - handle_char('?'); - - handle_char(c); - break; + size -= fstrlen(p); + if (flag == RIGHT) + { + for (; size > 0; size--) + handle_char(fill); + } + for (; *p != '\0'; p++) + handle_char(*p); + + for (; size > 0; size--) + handle_char(fill); + + continue; + + default: + handle_char('?'); + + handle_char(c); + break; } } return 0; } -void hexd(char *title,UBYTE FAR *p,COUNT numBytes) +void hexd(char *title, UBYTE FAR * p, COUNT numBytes) { - int loop; - printf("%s%04x|", title, FP_SEG(p)); - for (loop = 0; loop < numBytes; loop++) - printf("%02x ", p[loop]); - printf("|"); - - for (loop = 0; loop < numBytes; loop++) - printf("%c", p[loop] < 0x20 ? '.' : p[loop]); - printf("\n"); -} - + int loop; + printf("%s%04x|", title, FP_SEG(p)); + for (loop = 0; loop < numBytes; loop++) + printf("%02x ", p[loop]); + printf("|"); + for (loop = 0; loop < numBytes; loop++) + printf("%c", p[loop] < 0x20 ? '.' : p[loop]); + printf("\n"); +} #ifdef TEST /* @@ -397,83 +383,108 @@ void hexd(char *title,UBYTE FAR *p,COUNT numBytes) */ #include -void cso(char c) { putch(c); } +void cso(char c) +{ + putch(c); +} +struct { + char *should; + char *format; + unsigned lowint; + unsigned highint; -struct { - char *should; - char *format; - unsigned lowint; - unsigned highint; - -} testarray[] = - { - { "hello world", "%s %s", (unsigned)"hello",(unsigned)"world"}, - { "hello", "%3s", (unsigned)"hello",0}, - { " hello", "%7s", (unsigned)"hello",0}, - { "hello ", "%-7s", (unsigned)"hello",0}, - { "hello", "%s", (unsigned)"hello",0}, - - - - { "1", "%d", 1, 0}, - { "-1", "%d", -1,0}, - { "65535", "%u", -1,0}, - { "-32768", "%d", 0x8000,0}, - { "32767", "%d", 0x7fff,0}, - { "-32767", "%d", 0x8001,0}, - - {"8000", "%x", 0x8000, 0}, - {" 1", "%4x", 1, 0}, - {"0001", "%04x", 1, 0}, - {"1 ", "%-4x", 1, 0}, - {"1000", "%-04x", 1, 0}, +} testarray[] = { + { + "hello world", "%s %s", (unsigned)"hello", (unsigned)"world"}, + { + "hello", "%3s", (unsigned)"hello", 0}, + { + " hello", "%7s", (unsigned)"hello", 0}, + { + "hello ", "%-7s", (unsigned)"hello", 0}, + { + "hello", "%s", (unsigned)"hello", 0}, + { + "1", "%d", 1, 0}, + { + "-1", "%d", -1, 0}, + { + "65535", "%u", -1, 0}, + { + "-32768", "%d", 0x8000, 0}, + { + "32767", "%d", 0x7fff, 0}, + { + "-32767", "%d", 0x8001, 0}, + { + "8000", "%x", 0x8000, 0}, + { + " 1", "%4x", 1, 0}, + { + "0001", "%04x", 1, 0}, + { + "1 ", "%-4x", 1, 0}, + { + "1000", "%-04x", 1, 0}, + { + "1", "%ld", 1, 0}, + { + "-1", "%ld", -1, -1}, + { + "65535", "%ld", -1, 0}, + { + "65535", "%u", -1, 0}, + { + "8000", "%lx", 0x8000, 0}, + { + "80000000", "%lx", 0, 0x8000}, + { + " 1", "%4lx", 1, 0}, + { + "0001", "%04lx", 1, 0}, + { + "1 ", "%-4lx", 1, 0}, + { + "1000", "%-04lx", 1, 0}, + { + "-2147483648", "%ld", 0, 0x8000}, + { + "2147483648", "%lu", 0, 0x8000}, + { + "2147483649", "%lu", 1, 0x8000}, + { + "-2147483647", "%ld", 1, 0x8000}, + { + "32767", "%ld", 0x7fff, 0}, + { +"ptr 1234:5678", "ptr %p", 0x5678, 0x1234}, 0}; - { "1", "%ld", 1, 0}, - { "-1", "%ld", -1,-1}, - { "65535", "%ld", -1,0}, - { "65535", "%u", -1,0}, - {"8000", "%lx", 0x8000, 0}, - {"80000000", "%lx", 0,0x8000}, - {" 1", "%4lx", 1, 0}, - {"0001", "%04lx", 1, 0}, - {"1 ", "%-4lx", 1, 0}, - {"1000", "%-04lx", 1, 0}, - - { "-2147483648", "%ld", 0,0x8000}, - { "2147483648", "%lu", 0,0x8000}, - { "2147483649", "%lu", 1,0x8000}, - { "-2147483647", "%ld", 1,0x8000}, - { "32767", "%ld", 0x7fff,0}, - - { "ptr 1234:5678", "ptr %p", 0x5678,0x1234}, - - - - 0 - }; - test(char *should, char *format, unsigned lowint, unsigned highint) { - char b[100]; - - sprintf(b, format, lowint,highint); - - printf("'%s' = '%s'\n", should, b); - - if (strcmp(b,should)) { printf("\nhit the ANYKEY\n"); getch(); } -} + char b[100]; + sprintf(b, format, lowint, highint); + + printf("'%s' = '%s'\n", should, b); + + if (strcmp(b, should)) + { + printf("\nhit the ANYKEY\n"); + getch(); + } +} main() { - int i; - printf("hello world\n"); - - for (i = 0; testarray[i].should; i++) - { - test(testarray[i].should,testarray[i].format, testarray[i].lowint, testarray[i].highint); - } + int i; + printf("hello world\n"); + + for (i = 0; testarray[i].should; i++) + { + test(testarray[i].should, testarray[i].format, testarray[i].lowint, + testarray[i].highint); + } } #endif @@ -517,4 +528,3 @@ main() * Rev 1.0 02 Jul 1995 8:05:10 patv * Initial revision. */ - diff --git a/kernel/proto.h b/kernel/proto.h index 9789168..31ea757 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -28,15 +28,15 @@ #ifdef MAIN #ifdef VERSION_STRINGS -static BYTE *Proto_hRcsId = "$Id$"; +static BYTE *Proto_hRcsId = + "$Id$"; #endif #endif - /* blockio.c */ ULONG getblkno(struct buffer FAR *); VOID setblkno(struct buffer FAR *, ULONG); -struct buffer FAR *getblock (ULONG blkno, COUNT dsk); +struct buffer FAR *getblock(ULONG blkno, COUNT dsk); struct buffer FAR *getblockOver(ULONG blkno, COUNT dsk); VOID setinvld(REG COUNT dsk); BOOL flush_buffers(REG COUNT dsk); @@ -45,7 +45,8 @@ BOOL flush(void); BOOL fill(REG struct buffer FAR * bp, ULONG blkno, COUNT dsk); BOOL DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk); /* *** Changed on 9/4/00 BER */ -UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, COUNT mode); +UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, + COUNT mode); /* *** End of change */ /* chario.c */ @@ -66,19 +67,20 @@ sft FAR *get_sft(UCOUNT); /* dosfns.c */ #ifdef WITHFAT32 -struct dpb FAR *GetDriveDPB(UBYTE drive, COUNT *rc); +struct dpb FAR *GetDriveDPB(UBYTE drive, COUNT * rc); #endif BYTE FAR *get_root(BYTE FAR *); BOOL fnmatch(BYTE FAR *, BYTE FAR *, COUNT, COUNT); BOOL check_break(void); -UCOUNT GenericReadSft(sft far *sftp, UCOUNT n, BYTE FAR * bp, COUNT FAR * err, - BOOL force_binary); -COUNT SftSeek(sft FAR *sftp, LONG new_pos, COUNT mode); +UCOUNT GenericReadSft(sft far * sftp, UCOUNT n, BYTE FAR * bp, + COUNT FAR * err, BOOL force_binary); +COUNT SftSeek(sft FAR * sftp, LONG new_pos, COUNT mode); /* COUNT DosRead(COUNT hndl, UCOUNT n, BYTE FAR * bp, COUNT FAR * err); */ #define GenericRead(hndl, n, bp, err, t) GenericReadSft(get_sft(hndl), n, bp, err, t) #define DosRead(hndl, n, bp, err) GenericRead(hndl, n, bp, err, FALSE) #define DosReadSft(sftp, n, bp, err) GenericReadSft(sftp, n, bp, err, FALSE) -UCOUNT DosWriteSft(sft FAR *sftp, UCOUNT n, BYTE FAR * bp, COUNT FAR * err); +UCOUNT DosWriteSft(sft FAR * sftp, UCOUNT n, BYTE FAR * bp, + COUNT FAR * err); #define DosWrite(hndl, n, bp, err) DosWriteSft(get_sft(hndl), n, bp, err) COUNT DosSeek(COUNT hndl, LONG new_pos, COUNT mode, ULONG * set_pos); COUNT DosCreat(BYTE FAR * fname, COUNT attrib); @@ -90,8 +92,9 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode); COUNT DosOpenSft(BYTE * fname, COUNT mode); COUNT DosClose(COUNT hndl); COUNT DosCloseSft(WORD sft_idx); -BOOL DosGetFree(UBYTE drive, UCOUNT FAR * spc, UCOUNT FAR * navc, UCOUNT FAR * bps, UCOUNT FAR * nc); -COUNT DosGetExtFree(BYTE FAR *DriveString, struct xfreespace FAR *xfsp); +BOOL DosGetFree(UBYTE drive, UCOUNT FAR * spc, UCOUNT FAR * navc, + UCOUNT FAR * bps, UCOUNT FAR * nc); +COUNT DosGetExtFree(BYTE FAR * DriveString, struct xfreespace FAR * xfsp); COUNT DosGetCuDir(UBYTE drive, BYTE FAR * s); COUNT DosChangeDir(BYTE FAR * s); COUNT DosFindFirst(UCOUNT attr, BYTE FAR * name); @@ -102,12 +105,12 @@ COUNT DosSetFtimeSft(WORD sft_idx, date dp, time tp); COUNT DosGetFattr(BYTE FAR * name); COUNT DosSetFattr(BYTE FAR * name, UWORD attrp); UBYTE DosSelectDrv(UBYTE drv); -COUNT DosDelete(BYTE FAR *path); +COUNT DosDelete(BYTE FAR * path); COUNT DosRename(BYTE FAR * path1, BYTE FAR * path2); COUNT DosRenameTrue(BYTE * path1, BYTE * path2); COUNT DosMkdir(BYTE FAR * dir); COUNT DosRmdir(BYTE FAR * dir); -struct dhdr FAR * IsDevice(BYTE FAR * FileName); +struct dhdr FAR *IsDevice(BYTE FAR * FileName); BOOL IsShareInstalled(void); COUNT DosLockUnlock(COUNT hndl, LONG pos, LONG len, COUNT unlock); sft FAR *idx_to_sft(COUNT SftIndex); @@ -140,11 +143,11 @@ BOOL dir_write(REG f_node_ptr fnp); VOID dir_close(REG f_node_ptr fnp); COUNT dos_findfirst(UCOUNT attr, BYTE * name); COUNT dos_findnext(void); -void ConvertName83ToNameSZ(BYTE FAR *destSZ, BYTE FAR *srcFCBName); -int FileName83Length(BYTE *filename83); +void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName); +int FileName83Length(BYTE * filename83); /* fatfs.c */ -ULONG clus2phys(CLUSTER cl_no, struct dpb FAR *dpbp); +ULONG clus2phys(CLUSTER cl_no, struct dpb FAR * dpbp); COUNT dos_open(BYTE * path, COUNT flag); BOOL fcmp(BYTE * s1, BYTE * s2, COUNT n); BOOL fcmp_wild(BYTE FAR * s1, BYTE FAR * s2, COUNT n); @@ -169,7 +172,7 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err); COUNT dos_read(COUNT fd, VOID FAR * buffer, UCOUNT count); COUNT dos_write(COUNT fd, VOID FAR * buffer, UCOUNT count); LONG dos_lseek(COUNT fd, LONG foffset, COUNT origin); -CLUSTER dos_free(struct dpb FAR *dpbp); +CLUSTER dos_free(struct dpb FAR * dpbp); VOID trim_path(BYTE FAR * s); @@ -180,27 +183,31 @@ VOID release_f_node(f_node_ptr fnp); VOID dos_setdta(BYTE FAR * newdta); COUNT dos_getfattr(BYTE * name); COUNT dos_setfattr(BYTE * name, UWORD attrp); -COUNT media_check(REG struct dpb FAR *dpbp); +COUNT media_check(REG struct dpb FAR * dpbp); f_node_ptr xlt_fd(COUNT fd); COUNT xlt_fnp(f_node_ptr fnp); struct dhdr FAR *select_unit(COUNT drive); #ifdef WITHFAT32 -VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp, BOOL extended); +VOID bpb_to_dpb(bpb FAR * bpbp, REG struct dpb FAR * dpbp, BOOL extended); #else -VOID bpb_to_dpb(bpb FAR *bpbp, REG struct dpb FAR * dpbp); +VOID bpb_to_dpb(bpb FAR * bpbp, REG struct dpb FAR * dpbp); #endif /* fattab.c */ -void read_fsinfo(struct dpb FAR *dpbp); -void write_fsinfo(struct dpb FAR *dpbp); -UCOUNT link_fat(struct dpb FAR *dpbp, CLUSTER Cluster1, REG CLUSTER Cluster2); -UCOUNT link_fat32(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2); -UCOUNT link_fat16(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2); -UCOUNT link_fat12(struct dpb FAR *dpbp, CLUSTER Cluster1, CLUSTER Cluster2); -CLUSTER next_cluster(struct dpb FAR *dpbp, REG CLUSTER ClusterNum); -CLUSTER next_cl32(struct dpb FAR *dpbp, REG CLUSTER ClusterNum); -CLUSTER next_cl16(struct dpb FAR *dpbp, REG CLUSTER ClusterNum); -CLUSTER next_cl12(struct dpb FAR *dpbp, REG CLUSTER ClusterNum); +void read_fsinfo(struct dpb FAR * dpbp); +void write_fsinfo(struct dpb FAR * dpbp); +UCOUNT link_fat(struct dpb FAR * dpbp, CLUSTER Cluster1, + REG CLUSTER Cluster2); +UCOUNT link_fat32(struct dpb FAR * dpbp, CLUSTER Cluster1, + CLUSTER Cluster2); +UCOUNT link_fat16(struct dpb FAR * dpbp, CLUSTER Cluster1, + CLUSTER Cluster2); +UCOUNT link_fat12(struct dpb FAR * dpbp, CLUSTER Cluster1, + CLUSTER Cluster2); +CLUSTER next_cluster(struct dpb FAR * dpbp, REG CLUSTER ClusterNum); +CLUSTER next_cl32(struct dpb FAR * dpbp, REG CLUSTER ClusterNum); +CLUSTER next_cl16(struct dpb FAR * dpbp, REG CLUSTER ClusterNum); +CLUSTER next_cl12(struct dpb FAR * dpbp, REG CLUSTER ClusterNum); /* fcbfns.c */ VOID DosOutputString(BYTE FAR * s); @@ -209,21 +216,25 @@ int DosCharInput(VOID); VOID DosDirectConsoleIO(iregs FAR * r); VOID DosCharOutput(COUNT c); VOID DosDisplayOutput(COUNT c); -VOID FatGetDrvData(UCOUNT drive, UCOUNT FAR * spc, UCOUNT FAR * bps, UCOUNT FAR * nc, BYTE FAR ** mdp); +VOID FatGetDrvData(UCOUNT drive, UCOUNT FAR * spc, UCOUNT FAR * bps, + UCOUNT FAR * nc, BYTE FAR ** mdp); WORD FcbParseFname(int wTestMode, BYTE FAR ** lpFileName, fcb FAR * lpFcb); BYTE FAR *ParseSkipWh(BYTE FAR * lpFileName); BOOL TestCmnSeps(BYTE FAR * lpFileName); BOOL TestFieldSeps(BYTE FAR * lpFileName); -BYTE FAR *GetNameField(BYTE FAR * lpFileName, BYTE FAR * lpDestField, COUNT nFieldSize, BOOL * pbWildCard); +BYTE FAR *GetNameField(BYTE FAR * lpFileName, BYTE FAR * lpDestField, + COUNT nFieldSize, BOOL * pbWildCard); BOOL FcbRead(xfcb FAR * lpXfcb, COUNT * nErrorCode); BOOL FcbWrite(xfcb FAR * lpXfcb, COUNT * nErrorCode); BOOL FcbGetFileSize(xfcb FAR * lpXfcb); BOOL FcbSetRandom(xfcb FAR * lpXfcb); BOOL FcbCalcRec(xfcb FAR * lpXfcb); -BOOL FcbRandomBlockRead(xfcb FAR * lpXfcb, COUNT nRecords, COUNT * nErrorCode); -BOOL FcbRandomBlockWrite(xfcb FAR * lpXfcb, COUNT nRecords, COUNT * nErrorCode); +BOOL FcbRandomBlockRead(xfcb FAR * lpXfcb, COUNT nRecords, + COUNT * nErrorCode); +BOOL FcbRandomBlockWrite(xfcb FAR * lpXfcb, COUNT nRecords, + COUNT * nErrorCode); BOOL FcbRandomIO(xfcb FAR * lpXfcb, COUNT * nErrorCode, - BOOL (*FcbFunc)(xfcb FAR *, COUNT *)); + BOOL(*FcbFunc) (xfcb FAR *, COUNT *)); BOOL FcbCreate(xfcb FAR * lpXfcb); void FcbNameInit(fcb FAR * lpFcb, BYTE * pszBuffer, COUNT * pCurDrive); BOOL FcbOpen(xfcb FAR * lpXfcb); @@ -242,7 +253,8 @@ seg far2para(VOID FAR * p); seg long2para(ULONG size); VOID FAR *add_far(VOID FAR * fp, ULONG off); VOID FAR *adjust_far(VOID FAR * fp); -COUNT DosMemAlloc(UWORD size, COUNT mode, seg FAR * para, UWORD FAR * asize); +COUNT DosMemAlloc(UWORD size, COUNT mode, seg FAR * para, + UWORD FAR * asize); COUNT DosMemLargest(UWORD FAR * size); COUNT DosMemFree(UWORD para); COUNT DosMemChange(UWORD para, UWORD size, UWORD * maxSize); @@ -258,7 +270,7 @@ VOID strcpy(REG BYTE * d, REG BYTE * s); VOID ASMCFUNC fmemcpy(REG VOID FAR * d, REG VOID FAR * s, REG COUNT n); VOID ASMCFUNC fstrcpy(REG BYTE FAR * d, REG BYTE FAR * s); VOID ASMCFUNC fstrcpy(REG BYTE FAR * d, REG BYTE FAR * s); -void ASMCFUNC memcpy(REG void * d, REG VOID * s, REG COUNT n); +void ASMCFUNC memcpy(REG void *d, REG VOID * s, REG COUNT n); void ASMCFUNC fmemset(REG VOID FAR * s, REG int ch, REG COUNT n); void ASMCFUNC memset(REG VOID * s, REG int ch, REG COUNT n); @@ -280,27 +292,27 @@ BYTE DosYesNo(unsigned char ch); VOID DosUpMem(VOID FAR * str, unsigned len); #endif unsigned char ASMCFUNC DosUpChar(unsigned char ch); -VOID DosUpString(char FAR *str); -VOID DosUpFMem(VOID FAR *str, unsigned len); +VOID DosUpString(char FAR * str); +VOID DosUpFMem(VOID FAR * str, unsigned len); unsigned char DosUpFChar(unsigned char ch); -VOID DosUpFString(char FAR *str); -COUNT DosGetData(int subfct, UWORD cp, UWORD cntry - , UWORD bufsize, VOID FAR * buf); +VOID DosUpFString(char FAR * str); +COUNT DosGetData(int subfct, UWORD cp, UWORD cntry, UWORD bufsize, + VOID FAR * buf); #ifndef DosGetCountryInformation -COUNT DosGetCountryInformation(UWORD cntry, VOID FAR *buf); +COUNT DosGetCountryInformation(UWORD cntry, VOID FAR * buf); #endif #ifndef DosSetCountry COUNT DosSetCountry(UWORD cntry); #endif -COUNT DosGetCodepage(UWORD FAR* actCP, UWORD FAR* sysCP); +COUNT DosGetCodepage(UWORD FAR * actCP, UWORD FAR * sysCP); COUNT DosSetCodepage(UWORD actCP, UWORD sysCP); UWORD ASMCFUNC syscall_MUX14(DIRECT_IREGS); /* prf.c */ VOID put_console(COUNT c); -WORD printf(CONST BYTE * fmt,...); +WORD printf(CONST BYTE * fmt, ...); WORD sprintf(BYTE * buff, CONST BYTE * fmt, ...); -VOID hexd(char *title,VOID FAR *p,COUNT numBytes); +VOID hexd(char *title, VOID FAR * p, COUNT numBytes); /* strings.c */ COUNT ASMCFUNC strlen(REG BYTE * s); @@ -318,7 +330,7 @@ void fsncopy(REG BYTE FAR * s, REG BYTE FAR * d, COUNT l); void ASMCFUNC fstrncpy(REG BYTE FAR * d, REG BYTE FAR * s, COUNT l); #define fsncopy(s,d,l) fstrncpy(d,s,l) -BYTE * ASMCFUNC strchr(BYTE * s, BYTE c); +BYTE *ASMCFUNC strchr(BYTE * s, BYTE c); /* sysclk.c */ WORD FAR ASMCFUNC clk_driver(rqptr rp); @@ -341,18 +353,19 @@ WORD con_driver(rqptr rp); VOID break_handler(void); /* systime.c */ -VOID DosGetTime(BYTE FAR * hp, BYTE FAR * mp, BYTE FAR * sp, BYTE FAR * hdp); +VOID DosGetTime(BYTE FAR * hp, BYTE FAR * mp, BYTE FAR * sp, + BYTE FAR * hdp); COUNT DosSetTime(BYTE h, BYTE m, BYTE s, BYTE hd); -VOID DosGetDate(BYTE FAR * wdp, BYTE FAR * mp, BYTE FAR * mdp, COUNT FAR * yp); +VOID DosGetDate(BYTE FAR * wdp, BYTE FAR * mp, BYTE FAR * mdp, + COUNT FAR * yp); COUNT DosSetDate(UWORD Month, UWORD DayOfMonth, UWORD Year); -UWORD *is_leap_year_monthdays(UWORD year); +UWORD *is_leap_year_monthdays(UWORD year); UWORD DaysFromYearMonthDay(UWORD Year, UWORD Month, UWORD DayOfMonth); - - /* task.c */ -COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, char far * pathname); +COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, + char far * pathname); VOID new_psp(psp FAR * p, int psize); VOID return_user(void); COUNT DosExec(COUNT mode, exec_blk FAR * ep, BYTE FAR * lp); @@ -366,8 +379,10 @@ COUNT get_verify_drive(char FAR * src); COUNT ASMCFUNC truename(char FAR * src, char FAR * dest, COUNT t); /* network.c */ -COUNT ASMCFUNC remote_doredirect(UWORD b, UCOUNT n, UWORD d, VOID FAR * s, UWORD i, VOID FAR * data); -COUNT ASMCFUNC remote_printset(UWORD b, UCOUNT n, UWORD d, VOID FAR * s, UWORD i, VOID FAR * data); +COUNT ASMCFUNC remote_doredirect(UWORD b, UCOUNT n, UWORD d, VOID FAR * s, + UWORD i, VOID FAR * data); +COUNT ASMCFUNC remote_printset(UWORD b, UCOUNT n, UWORD d, VOID FAR * s, + UWORD i, VOID FAR * data); COUNT ASMCFUNC remote_rename(VOID); COUNT ASMCFUNC remote_delete(VOID); COUNT ASMCFUNC remote_chdir(VOID); @@ -376,18 +391,18 @@ COUNT ASMCFUNC remote_rmdir(VOID); COUNT ASMCFUNC remote_close_all(VOID); COUNT ASMCFUNC remote_process_end(VOID); COUNT ASMCFUNC remote_flushall(VOID); -COUNT ASMCFUNC remote_findfirst(VOID FAR *s); -COUNT ASMCFUNC remote_findnext(VOID FAR *s); +COUNT ASMCFUNC remote_findfirst(VOID FAR * s); +COUNT ASMCFUNC remote_findnext(VOID FAR * s); COUNT ASMCFUNC remote_getfattr(VOID); -COUNT ASMCFUNC remote_getfree(VOID FAR *s, VOID *d); -COUNT ASMCFUNC remote_open(sft FAR *s, COUNT mode); -LONG ASMCFUNC remote_lseek(sft FAR *s, LONG new_pos); -UCOUNT ASMCFUNC remote_read(sft FAR *s, UCOUNT n, COUNT * err); -UCOUNT ASMCFUNC remote_write(sft FAR *s, UCOUNT n, COUNT * err); -COUNT ASMCFUNC remote_creat(sft FAR *s, COUNT attr); +COUNT ASMCFUNC remote_getfree(VOID FAR * s, VOID * d); +COUNT ASMCFUNC remote_open(sft FAR * s, COUNT mode); +LONG ASMCFUNC remote_lseek(sft FAR * s, LONG new_pos); +UCOUNT ASMCFUNC remote_read(sft FAR * s, UCOUNT n, COUNT * err); +UCOUNT ASMCFUNC remote_write(sft FAR * s, UCOUNT n, COUNT * err); +COUNT ASMCFUNC remote_creat(sft FAR * s, COUNT attr); COUNT ASMCFUNC remote_setfattr(COUNT attr); COUNT ASMCFUNC remote_printredir(UCOUNT dx, UCOUNT ax); -COUNT ASMCFUNC remote_close(sft FAR *s); +COUNT ASMCFUNC remote_close(sft FAR * s); COUNT ASMCFUNC QRemote_Fn(char FAR * s, char FAR * d); UWORD get_machine_name(BYTE FAR * netname); @@ -399,7 +414,6 @@ VOID ASMCFUNC exec_user(iregs FAR * irp); /* detect.c */ unsigned long FAR is_dosemu(void); - /* new by TE */ /* @@ -413,10 +427,10 @@ unsigned long FAR is_dosemu(void); #define ASSERT_CONST(x) { typedef struct { char _xx[x ? 1 : -1]; } xx ; } #if defined(WATCOM) && 0 -ULONG FAR ASMCFUNC MULULUS(ULONG mul1, UWORD mul2); /* MULtiply ULong by UShort */ -ULONG FAR ASMCFUNC MULULUL(ULONG mul1, ULONG mul2); /* MULtiply ULong by ULong */ -ULONG FAR ASMCFUNC DIVULUS(ULONG mul1, UWORD mul2); /* DIVide ULong by UShort */ -ULONG FAR ASMCFUNC DIVMODULUS(ULONG mul1, UWORD mul2,UWORD *rem); /* DIVide ULong by UShort */ +ULONG FAR ASMCFUNC MULULUS(ULONG mul1, UWORD mul2); /* MULtiply ULong by UShort */ +ULONG FAR ASMCFUNC MULULUL(ULONG mul1, ULONG mul2); /* MULtiply ULong by ULong */ +ULONG FAR ASMCFUNC DIVULUS(ULONG mul1, UWORD mul2); /* DIVide ULong by UShort */ +ULONG FAR ASMCFUNC DIVMODULUS(ULONG mul1, UWORD mul2, UWORD * rem); /* DIVide ULong by UShort */ #endif /* diff --git a/kernel/strings.c b/kernel/strings.c index bf7967c..3c69f1a 100644 --- a/kernel/strings.c +++ b/kernel/strings.c @@ -29,7 +29,8 @@ #include "portab.h" #ifdef VERSION_STRINGS -static BYTE *stringsRcsId = "$Id$"; +static BYTE *stringsRcsId = + "$Id$"; #endif #ifndef I86 @@ -187,4 +188,3 @@ BYTE *strchr(BYTE * s, BYTE c) * Rev 1.0 02 Jul 1995 8:33:46 patv * Initial revision. */ - diff --git a/kernel/sysclk.c b/kernel/sysclk.c index 867c7cb..d7ae465 100644 --- a/kernel/sysclk.c +++ b/kernel/sysclk.c @@ -30,7 +30,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif #ifdef PROTO @@ -54,8 +55,7 @@ VOID DayToBcd(); /* */ /* WARNING - THIS DRIVER IS NON-PORTABLE!!!! */ /* */ -extern UWORD days[2][13]; /* this is defined by SYSTIME.C */ - +extern UWORD days[2][13]; /* this is defined by SYSTIME.C */ static struct ClockRecord clk; @@ -82,42 +82,35 @@ static COUNT BcdToByte(COUNT x) WORD FAR ASMCFUNC clk_driver(rqptr rp) { - COUNT - c; + COUNT c; UWORD *pdays; - BYTE bcd_days[4], - bcd_minutes, - bcd_hours, - bcd_seconds; + BYTE bcd_days[4], bcd_minutes, bcd_hours, bcd_seconds; ULONG Ticks; - UWORD Month, - Day, - Year; - - - + UWORD Month, Day, Year; + switch (rp->r_command) { case C_INIT: /* If AT clock exists, copy AT clock time to system clock */ if (!ReadATClock(bcd_days, &bcd_hours, &bcd_minutes, &bcd_seconds)) { - DaysSinceEpoch = DaysFromYearMonthDay( - 100 * BcdToByte(bcd_days[3]) + BcdToByte(bcd_days[2]), - BcdToByte(bcd_days[1]), - BcdToByte(bcd_days[0]) ); + DaysSinceEpoch = + DaysFromYearMonthDay(100 * BcdToByte(bcd_days[3]) + + BcdToByte(bcd_days[2]), + BcdToByte(bcd_days[1]), + BcdToByte(bcd_days[0])); - /* - * This is a rather tricky calculation. The number of timer ticks per - * second is not exactly 18.2, but rather 0x1800b0 / 86400 = 19663 / 1080 - * (the timer interrupt updates the midnight flag when the tick count - * reaches 0x1800b0). Fortunately, 86400 * 19663 = 1698883200 < ULONG_MAX, - * so we can simply multiply the number of seconds by 19663 without - * worrying about overflow. :) -- ror4 - */ + /* + * This is a rather tricky calculation. The number of timer ticks per + * second is not exactly 18.2, but rather 0x1800b0 / 86400 = 19663 / 1080 + * (the timer interrupt updates the midnight flag when the tick count + * reaches 0x1800b0). Fortunately, 86400 * 19663 = 1698883200 < ULONG_MAX, + * so we can simply multiply the number of seconds by 19663 without + * worrying about overflow. :) -- ror4 + */ Ticks = (3600ul * BcdToByte(bcd_hours) + - 60ul * BcdToByte(bcd_minutes) + - BcdToByte(bcd_seconds)) * 19663ul / 1080ul; + 60ul * BcdToByte(bcd_minutes) + + BcdToByte(bcd_seconds)) * 19663ul / 1080ul; WritePCClock(Ticks); } rp->r_endaddr = device_end(); @@ -126,8 +119,7 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) case C_INPUT: { - ULONG remainder, - hs; + ULONG remainder, hs; if (ReadPCClock(&Ticks)) ++DaysSinceEpoch; clk.clkDays = DaysSinceEpoch; @@ -138,7 +130,7 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) * (100 x 86400) / 0x1800b0 = 108000 / 19663. -- ror4 */ hs = 0; -#if 0 +#if 0 if (Ticks >= 64 * 19663ul) { hs += 64 * 108000ul; @@ -175,14 +167,14 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) Ticks -= 19663ul; } #else - { - UWORD q1 = Ticks/19663ul; + { + UWORD q1 = Ticks / 19663ul; - Ticks -= q1*19663ul; - hs = q1*108000ul; - } - -#endif + Ticks -= q1 * 19663ul; + hs = q1 * 108000ul; + } + +#endif /* * Now Ticks < 19663, so Ticks * 108000 < 2123604000 < ULONG_MAX. * *phew* -- ror4 @@ -195,12 +187,13 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) clk.clkSeconds = remainder / 100ul; clk.clkHundredths = remainder % 100ul; } - - fmemcpy(rp->r_trans, &clk, min(sizeof(struct ClockRecord),rp->r_count )); + + fmemcpy(rp->r_trans, &clk, + min(sizeof(struct ClockRecord), rp->r_count)); return S_DONE; case C_OUTPUT: - rp->r_count = min(rp->r_count,sizeof(struct ClockRecord)); + rp->r_count = min(rp->r_count, sizeof(struct ClockRecord)); fmemcpy(&clk, rp->r_trans, rp->r_count); /* Set PC Clock first */ @@ -209,10 +202,9 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) ULONG hs; hs = 360000ul * clk.clkHours + 6000ul * clk.clkMinutes + - 100ul * clk.clkSeconds + - clk.clkHundredths; + 100ul * clk.clkSeconds + clk.clkHundredths; Ticks = 0; -#if 0 +#if 0 if (hs >= 64 * 108000ul) { Ticks += 64 * 19663ul; @@ -248,15 +240,15 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) Ticks += 19663ul; hs -= 108000ul; } -#else - { - UWORD q1 = hs/108000ul; +#else + { + UWORD q1 = hs / 108000ul; - hs -= q1*108000ul; - Ticks = q1*19663ul; - } - -#endif + hs -= q1 * 108000ul; + Ticks = q1 * 19663ul; + } + +#endif Ticks += hs * 19663ul / 108000ul; } WritePCClock(Ticks); @@ -264,7 +256,7 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) /* Now set AT clock */ /* Fix year by looping through each year, subtracting */ /* the appropriate number of days for that year. */ - for (Year = 1980, c = clk.clkDays; ;) + for (Year = 1980, c = clk.clkDays;;) { pdays = is_leap_year_monthdays(Year); if (c >= pdays[12]) @@ -286,8 +278,7 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) break; } } - - + DayToBcd((BYTE *) bcd_days, &Month, &Day, &Year); bcd_minutes = ByteToBcd(clk.clkMinutes); bcd_hours = ByteToBcd(clk.clkHours); @@ -304,7 +295,7 @@ WORD FAR ASMCFUNC clk_driver(rqptr rp) case C_OSTAT: case C_ISTAT: default: - return failure(E_FAILURE); /* general failure */ + return failure(E_FAILURE); /* general failure */ } } @@ -364,4 +355,3 @@ VOID DayToBcd(BYTE * x, UWORD * mon, UWORD * day, UWORD * yr) * Rev 1.0 02 Jul 1995 8:32:30 patv * Initial revision. */ - diff --git a/kernel/syspack.c b/kernel/syspack.c index 41aede4..2e4adef 100644 --- a/kernel/syspack.c +++ b/kernel/syspack.c @@ -31,7 +31,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *syspackRcsId = "$Id$"; +static BYTE *syspackRcsId = + "$Id$"; #endif #ifdef NONNATIVE @@ -55,7 +56,8 @@ VOID getbyte(VOID * vp, BYTE * bp) VOID fgetword(REG VOID FAR * vp, WORD FAR * wp) { - *wp = (((BYTE FAR *) vp)[0] & 0xff) + ((((BYTE FAR *) vp)[1] & 0xff) << 8); + *wp = + (((BYTE FAR *) vp)[0] & 0xff) + ((((BYTE FAR *) vp)[1] & 0xff) << 8); } VOID fgetlong(REG VOID FAR * vp, LONG FAR * lp) diff --git a/kernel/systime.c b/kernel/systime.c index dd96ab9..e6afc78 100644 --- a/kernel/systime.c +++ b/kernel/systime.c @@ -32,43 +32,43 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif -UWORD days[2][13] = -{ +UWORD days[2][13] = { {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366} }; -extern request - ClkReqHdr; - +extern request ClkReqHdr; + /* return a pointer to an array with the days for that year -*/ +*/ UWORD *is_leap_year_monthdays(UWORD y) { - /* this is correct in a strict mathematical sense - return ((y) & 3 ? days[0] : (y) % 100 ? days[1] : (y) % 400 ? days[0] : days[1]); */ - - /* this will work until 2200 - long enough for me - and saves 0x1f bytes */ - - if ((y & 3) || y == 2100) return days[0]; - - return days[1]; + /* this is correct in a strict mathematical sense + return ((y) & 3 ? days[0] : (y) % 100 ? days[1] : (y) % 400 ? days[0] : days[1]); */ + + /* this will work until 2200 - long enough for me - and saves 0x1f bytes */ + + if ((y & 3) || y == 2100) + return days[0]; + + return days[1]; } UWORD DaysFromYearMonthDay(UWORD Year, UWORD Month, UWORD DayOfMonth) { - if (Year < 1980) return 0; - + if (Year < 1980) + return 0; + return DayOfMonth - 1 + is_leap_year_monthdays(Year)[Month - 1] - + ((Year - 1980) * 365) - + ((Year - 1980 + 3) / 4); - + + ((Year - 1980) * 365) + ((Year - 1980 + 3) / 4); + } /* common - call the clock driver */ @@ -80,14 +80,13 @@ void ExecuteClockDriverRequest(BYTE command) ClkReqHdr.r_trans = (BYTE FAR *) (&ClkRecord); ClkReqHdr.r_status = 0; execrh((request FAR *) & ClkReqHdr, (struct dhdr FAR *)clock); -} +} - - -VOID DosGetTime(BYTE FAR * hp, BYTE FAR * mp, BYTE FAR * sp, BYTE FAR * hdp) +VOID DosGetTime(BYTE FAR * hp, BYTE FAR * mp, BYTE FAR * sp, + BYTE FAR * hdp) { ExecuteClockDriverRequest(C_INPUT); - + if (ClkReqHdr.r_status & S_ERROR) return; @@ -99,8 +98,9 @@ VOID DosGetTime(BYTE FAR * hp, BYTE FAR * mp, BYTE FAR * sp, BYTE FAR * hdp) COUNT DosSetTime(BYTE h, BYTE m, BYTE s, BYTE hd) { - BYTE Month, DayOfMonth, DayOfWeek; COUNT Year; - + BYTE Month, DayOfMonth, DayOfWeek; + COUNT Year; + DosGetDate((BYTE FAR *) & DayOfWeek, (BYTE FAR *) & Month, (BYTE FAR *) & DayOfMonth, (COUNT FAR *) & Year); @@ -119,21 +119,19 @@ COUNT DosSetTime(BYTE h, BYTE m, BYTE s, BYTE hd) } VOID DosGetDate(wdp, mp, mdp, yp) -BYTE FAR *wdp, - FAR * mp, - FAR * mdp; +BYTE FAR *wdp, FAR * mp, FAR * mdp; COUNT FAR *yp; { UWORD c; - UWORD *pdays; - UWORD Year,Month; + UWORD *pdays; + UWORD Year, Month; ExecuteClockDriverRequest(C_INPUT); if (ClkReqHdr.r_status & S_ERROR) return; - for (Year = 1980, c = ClkRecord.clkDays; ;) + for (Year = 1980, c = ClkRecord.clkDays;;) { pdays = is_leap_year_monthdays(Year); if (c >= pdays[12]) @@ -154,7 +152,7 @@ COUNT FAR *yp; } *mp = Month; - *mdp = c - pdays[Month-1] + 1; + *mdp = c - pdays[Month - 1] + 1; *yp = Year; /* Day of week is simple. Take mod 7, add 2 (for Tuesday */ @@ -164,19 +162,15 @@ COUNT FAR *yp; } COUNT DosSetDate(Month, DayOfMonth, Year) -UWORD Month, - DayOfMonth, - Year; +UWORD Month, DayOfMonth, Year; { UWORD *pdays; - pdays = is_leap_year_monthdays(Year); - + pdays = is_leap_year_monthdays(Year); + if (Year < 1980 || Year > 2099 || Month < 1 || Month > 12 - || DayOfMonth < 1 - || DayOfMonth > pdays[Month] - pdays[Month-1]) + || DayOfMonth < 1 || DayOfMonth > pdays[Month] - pdays[Month - 1]) return DE_INVLDDATA; - DosGetTime((BYTE FAR *) & ClkRecord.clkHours, (BYTE FAR *) & ClkRecord.clkMinutes, diff --git a/kernel/task.c b/kernel/task.c index 214e5ef..303cd25 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -30,7 +30,8 @@ #include "globals.h" #ifdef VERSION_STRINGS -static BYTE *RcsId = "$Id$"; +static BYTE *RcsId = + "$Id$"; #endif #define toupper(c) ((c) >= 'a' && (c) <= 'z' ? (c) + ('A' - 'a') : (c)) @@ -46,11 +47,11 @@ static exe_header header; #define CHUNK 32256 #define MAXENV 32768u #define ENV_KEEPFREE 83 /* keep unallocated by environment variables */ - /* The '65' added to nEnvSize does not cover the additional stuff: - + 2 bytes: number of strings - + 80 bytes: maximum absolute filename - + 1 byte: '\0' - -- 1999/04/21 ska */ + /* The '65' added to nEnvSize does not cover the additional stuff: + + 2 bytes: number of strings + + 80 bytes: maximum absolute filename + + 1 byte: '\0' + -- 1999/04/21 ska */ #ifndef PROTO COUNT ChildEnv(exec_blk FAR *, UWORD *, char far *); @@ -88,7 +89,8 @@ LONG DosGetFsize(COUNT hndl) return dos_getfsize(s->sft_status); } -COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, char far * pathname) +COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, + char far * pathname) { BYTE FAR *pSrc; BYTE FAR *pDest; @@ -101,14 +103,12 @@ COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, char far * pathname) /* copy parent's environment if exec.env_seg == 0 */ pSrc = exp->exec.env_seg ? - MK_FP(exp->exec.env_seg, 0) : - MK_FP(ppsp->ps_environ, 0); + MK_FP(exp->exec.env_seg, 0) : MK_FP(ppsp->ps_environ, 0); #if 0 /* Every process requires an environment because of argv[0] -- 1999/04/21 ska */ - */ - if (!pSrc) /* no environment to copy */ + */if (!pSrc) /* no environment to copy */ { *pChildEnvSeg = 0; return SUCCESS; @@ -120,15 +120,15 @@ COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, char far * pathname) -- 1999/04/21 ska */ if (pSrc) { /* if no environment is available, one byte is required */ - - for (nEnvSize = 0; ; nEnvSize++) + + for (nEnvSize = 0;; nEnvSize++) { - /* Test env size and abort if greater than max */ - if (nEnvSize >= MAXENV - ENV_KEEPFREE) - return DE_INVLDENV; - - if (*(UWORD FAR *)(pSrc+nEnvSize) == 0) - break; + /* Test env size and abort if greater than max */ + if (nEnvSize >= MAXENV - ENV_KEEPFREE) + return DE_INVLDENV; + + if (*(UWORD FAR *) (pSrc + nEnvSize) == 0) + break; } nEnvSize += 2; /* account for trailing \0\0 */ } @@ -136,7 +136,7 @@ COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, char far * pathname) /* allocate enough space for env + path */ if ((RetCode = DosMemAlloc(long2para(nEnvSize + ENV_KEEPFREE), mem_access_mode, (seg FAR *) pChildEnvSeg, - NULL /*(UWORD FAR *) MaxEnvSize ska */ )) < 0) + NULL /*(UWORD FAR *) MaxEnvSize ska */ )) < 0) return RetCode; pDest = MK_FP(*pChildEnvSeg + 1, 0); @@ -152,12 +152,13 @@ COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, char far * pathname) else *pDest++ = '\0'; /* create an empty environment */ - /* initialize 'extra strings' count */ + /* initialize 'extra strings' count */ *((UWORD FAR *) pDest) = 1; - pDest += sizeof(UWORD)/sizeof(BYTE); + pDest += sizeof(UWORD) / sizeof(BYTE); /* copy complete pathname */ - if ((RetCode = truename(pathname, pDest, TRUE)) != SUCCESS) { + if ((RetCode = truename(pathname, pDest, TRUE)) != SUCCESS) + { return RetCode; } @@ -172,7 +173,7 @@ COUNT ChildEnv(exec_blk FAR * exp, UWORD * pChildEnvSeg, char far * pathname) /* The following code is 8086 dependant */ VOID new_psp(psp FAR * p, int psize) { - REG COUNT i; + REG COUNT i; psp FAR *q = MK_FP(cu_psp, 0); /* Clear out new psp first */ @@ -225,7 +226,7 @@ VOID new_psp(psp FAR * p, int psize) p->ps_filetab = p->ps_files; /* clone the file table */ - if (p!=q) + if (p != q) { REG COUNT i; @@ -250,7 +251,7 @@ VOID new_psp(psp FAR * p, int psize) RootPsp = FP_SEG(p); } -STATIC UWORD patchPSP(UWORD pspseg, UWORD envseg, exec_blk FAR *exb, +STATIC UWORD patchPSP(UWORD pspseg, UWORD envseg, exec_blk FAR * exb, BYTE FAR * fnam) { psp FAR *psp; @@ -302,29 +303,33 @@ set_name: pspmcb->m_name[i] = '\0'; /* return value: AX value to be passed based on FCB values */ - return ((psp->ps_fcb1.fcb_drivecds_table[psp->ps_fcb1.fcb_drive].cdsFlags & CDSVALID) ? 0 : 0xff) + - ((psp->ps_fcb2.fcb_drivecds_table[psp->ps_fcb2.fcb_drive].cdsFlags & CDSVALID) ? 0 : 0xff) * 0x100; + return ((psp->ps_fcb1.fcb_drive < lastdrive && + CDSp->cds_table[psp->ps_fcb1.fcb_drive]. + cdsFlags & CDSVALID) ? 0 : 0xff) + ((psp->ps_fcb2.fcb_drive < + lastdrive + && CDSp->cds_table[psp-> + ps_fcb2. + fcb_drive]. + cdsFlags & CDSVALID) ? 0 : + 0xff) * 0x100; } COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) { COUNT rc - /* err */ - /*,env_size*/; + /* err */ + /*,env_size */ ; COUNT nread; UWORD mem; - UWORD env, - asize; + UWORD env, asize; BYTE FAR *sp; psp FAR *p; psp FAR *q = MK_FP(cu_psp, 0); iregs FAR *irp; LONG com_size; - int ModeLoadHigh = mode & 0x80; - UBYTE UMBstate = uppermem_link; + int ModeLoadHigh = mode & 0x80; + UBYTE UMBstate = uppermem_link; mode &= 0x7f; @@ -335,9 +340,9 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) { return rc; } - - /* COMFILES will always be loaded in largest area. is that true TE*/ - + + /* COMFILES will always be loaded in largest area. is that true TE */ + /* Now find out how many paragraphs are available */ if ((rc = DosMemLargest((seg FAR *) & asize)) != SUCCESS) { @@ -345,48 +350,49 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) return rc; } com_size = asize; - - if ( ModeLoadHigh ) - { - DosUmbLink(1); /* link in UMB's */ - } - - /* Allocate our memory and pass back any errors */ - if ((rc = DosMemAlloc((seg) com_size, mem_access_mode, (seg FAR *) & mem - ,(UWORD FAR *) & asize)) < 0) + + if (ModeLoadHigh) { - if (rc == DE_NOMEM) + DosUmbLink(1); /* link in UMB's */ + } + + /* Allocate our memory and pass back any errors */ + if ((rc = + DosMemAlloc((seg) com_size, mem_access_mode, (seg FAR *) & mem, + (UWORD FAR *) & asize)) < 0) + { + if (rc == DE_NOMEM) + { + if ((rc = + DosMemAlloc(0, LARGEST, (seg FAR *) & mem, + (UWORD FAR *) & asize)) < 0) { - if ((rc = DosMemAlloc(0, LARGEST, (seg FAR *) & mem - ,(UWORD FAR *) & asize)) < 0) - { - DosMemFree(env); - return rc; - } - /* This should never happen, but ... */ - if (asize < com_size) - { - DosMemFree(mem); - DosMemFree(env); - return rc; - } + DosMemFree(env); + return rc; } - else + /* This should never happen, but ... */ + if (asize < com_size) { - DosMemFree(env); /* env may be 0 */ - return rc; + DosMemFree(mem); + DosMemFree(env); + return rc; } + } + else + { + DosMemFree(env); /* env may be 0 */ + return rc; + } } ++mem; } else mem = exp->load.load_seg; - - if ( ModeLoadHigh ) - { - DosUmbLink(UMBstate); /* restore link state */ - } - + + if (ModeLoadHigh) + { + DosUmbLink(UMBstate); /* restore link state */ + } /* Now load the executable */ /* If file not found - error */ @@ -401,20 +407,19 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) if (mode == OVERLAY) /* memory already allocated */ sp = MK_FP(mem, 0); else - { /* test the filesize against the allocated memory */ - + { /* test the filesize against the allocated memory */ + sp = MK_FP(mem, sizeof(psp)); /* This is a potential problem, what to do with .COM files larger than the allocated memory? MS DOS always only loads the very first 64KB - sizeof(psp) bytes. -- 1999/04/21 ska */ - - /* BUG !! in case of LH, memory may be smaller then 64K TE*/ - - - if (com_size > ((LONG)asize << 4)) /* less memory than the .COM file has */ - com_size = (LONG)asize << 4; + + /* BUG !! in case of LH, memory may be smaller then 64K TE */ + + if (com_size > ((LONG) asize << 4)) /* less memory than the .COM file has */ + com_size = (LONG) asize << 4; } do { @@ -433,7 +438,7 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) setvec(0x22, (VOID(INRPT FAR *) (VOID)) MK_FP(user_r->CS, user_r->IP)); new_psp(p, mem + asize); - asize = patchPSP(mem - 1, env, exp, namep); /* asize=fcbcode for ax */ + asize = patchPSP(mem - 1, env, exp, namep); /* asize=fcbcode for ax */ /* Transfer control to the executable */ p->ps_parent = cu_psp; @@ -447,14 +452,13 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) { case LOADNGO: { - /* BUG !! - this works only, if COMSIZE >= 64K - in case of LH, this is not necessarily true - */ - - + /* BUG !! + this works only, if COMSIZE >= 64K + in case of LH, this is not necessarily true + */ + *((UWORD FAR *) MK_FP(mem, 0xfffe)) = (UWORD) 0; - + /* build the user area on the stack */ irp = MK_FP(mem, (0xfffe - sizeof(iregs))); @@ -462,13 +466,8 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) irp->ES = irp->DS = mem; irp->CS = mem; irp->IP = 0x100; - irp->AX = asize; /* fcbcode */ - irp->BX = - irp->CX = - irp->DX = - irp->SI = - irp->DI = - irp->BP = 0; + irp->AX = asize; /* fcbcode */ + irp->BX = irp->CX = irp->DX = irp->SI = irp->DI = irp->BP = 0; irp->FLAGS = 0x200; if (InDOS) @@ -476,12 +475,12 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) exec_user(irp); /* We should never be here - fatal("KERNEL RETURNED!!!"); */ + fatal("KERNEL RETURNED!!!"); */ break; } case LOAD: exp->exec.stack = MK_FP(mem, 0xfffe); - *((UWORD FAR *)exp->exec.stack) = asize; + *((UWORD FAR *) exp->exec.stack) = asize; exp->exec.start_addr = MK_FP(mem, 0x100); return SUCCESS; } @@ -491,8 +490,7 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) VOID return_user(void) { - psp FAR *p, - FAR * q; + psp FAR *p, FAR * q; REG COUNT i; iregs FAR *irp; /* long j;*/ @@ -506,8 +504,8 @@ VOID return_user(void) setvec(0x24, p->ps_isv24); /* And free all process memory if not a TSR return */ - remote_process_end(); /* might be a good idea to do that after closing - but doesn't help NET either TE */ + remote_process_end(); /* might be a good idea to do that after closing + but doesn't help NET either TE */ if (!tsr) { remote_close_all(); @@ -518,7 +516,6 @@ VOID return_user(void) FcbCloseAll(); FreeProcessMem(cu_psp); } - cu_psp = p->ps_parent; q = MK_FP(cu_psp, 0); @@ -536,20 +533,16 @@ VOID return_user(void) COUNT DosExeLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) { - COUNT rc; - /*err, */ - /*env_size,*/ - - UWORD mem, - env, - asize, - start_seg; + COUNT rc; + /*err, */ + /*env_size, */ - int ModeLoadHigh = mode & 0x80; + UWORD mem, env, asize, start_seg; + + int ModeLoadHigh = mode & 0x80; UBYTE UMBstate = uppermem_link; mode &= 0x7f; - /* Clone the environement and create a memory arena */ if (mode != OVERLAY) @@ -559,126 +552,123 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) } else mem = exp->load.load_seg; - { - ULONG image_size; - ULONG image_offset; - LONG exe_size; - mcb FAR *mp; - + ULONG image_size; + ULONG image_offset; + LONG exe_size; + mcb FAR *mp; - /* compute image offset from the header */ - image_offset = (ULONG)header.exHeaderSize * 16; + /* compute image offset from the header */ + image_offset = (ULONG) header.exHeaderSize * 16; - /* compute image size by removing the offset from the */ - /* number pages scaled to bytes plus the remainder and */ - /* the psp */ - /* First scale the size */ - image_size = (ULONG)header.exPages * 512; - /* remove the offset */ - image_size -= image_offset; + /* compute image size by removing the offset from the */ + /* number pages scaled to bytes plus the remainder and */ + /* the psp */ + /* First scale the size */ + image_size = (ULONG) header.exPages * 512; + /* remove the offset */ + image_size -= image_offset; - /* and finally add in the psp size */ - if (mode != OVERLAY) - image_size += sizeof(psp); /*TE 03/20/01*/ - - if (mode != OVERLAY) - { - if ( ModeLoadHigh ) + /* and finally add in the psp size */ + if (mode != OVERLAY) + image_size += sizeof(psp); /*TE 03/20/01 */ + + if (mode != OVERLAY) { - DosUmbLink(1); /* link in UMB's */ - mem_access_mode |= ModeLoadHigh; - } - - /* Now find out how many paragraphs are available */ - if ((rc = DosMemLargest((seg FAR *) & asize)) != SUCCESS) - { - DosMemFree(env); - return rc; - } + if (ModeLoadHigh) + { + DosUmbLink(1); /* link in UMB's */ + mem_access_mode |= ModeLoadHigh; + } - exe_size = (LONG) long2para(image_size) + header.exMinAlloc; - - - /* + long2para((LONG) sizeof(psp)); ?? see above - image_size += sizeof(psp) -- 1999/04/21 ska */ - if (exe_size > asize && (mem_access_mode & 0x80)) - { - /* First try low memory */ - mem_access_mode &= ~0x80; - rc = DosMemLargest((seg FAR *) & asize); - mem_access_mode |= 0x80; - if (rc != SUCCESS) + /* Now find out how many paragraphs are available */ + if ((rc = DosMemLargest((seg FAR *) & asize)) != SUCCESS) { DosMemFree(env); return rc; } - } - if (exe_size > asize) - { - DosMemFree(env); - return DE_NOMEM; - } - exe_size = (LONG) long2para(image_size) + header.exMaxAlloc; - /* + long2para((LONG) sizeof(psp)); ?? -- 1999/04/21 ska */ - if (exe_size > asize) - exe_size = asize; - - /* TE if header.exMinAlloc == header.exMaxAlloc == 0, - DOS will allocate the largest possible memory area - and load the image as high as possible into it. - discovered (and after that found in RBIL), when testing NET */ - - if ((header.exMinAlloc | header.exMaxAlloc ) == 0) - exe_size = asize; - - - /* /// Removed closing curly brace. We should not attempt to allocate - memory if we are overlaying the current process, because the new - process will simply re-use the block we already have allocated. - This was causing execl() to fail in applications which use it to - overlay (replace) the current exe file with a new one. - Jun 11, 2000 - rbc - } */ + exe_size = (LONG) long2para(image_size) + header.exMinAlloc; - /* Allocate our memory and pass back any errors */ - /* We can still get an error on first fit if the above */ - /* returned size was a bet fit case */ - /* ModeLoadHigh = 80 = try high, then low */ - if ((rc = DosMemAlloc((seg) exe_size, mem_access_mode | ModeLoadHigh, (seg FAR *) & mem - ,(UWORD FAR *) & asize)) < 0) - { - if (rc == DE_NOMEM) - { - if ((rc = DosMemAlloc(0, LARGEST, (seg FAR *) & mem - ,(UWORD FAR *) & asize)) < 0) + /* + long2para((LONG) sizeof(psp)); ?? see above + image_size += sizeof(psp) -- 1999/04/21 ska */ + if (exe_size > asize && (mem_access_mode & 0x80)) + { + /* First try low memory */ + mem_access_mode &= ~0x80; + rc = DosMemLargest((seg FAR *) & asize); + mem_access_mode |= 0x80; + if (rc != SUCCESS) + { + DosMemFree(env); + return rc; + } + } + if (exe_size > asize) { DosMemFree(env); - return rc; + return DE_NOMEM; } - /* This should never happen, but ... */ - if (asize < exe_size) - { - DosMemFree(mem); - DosMemFree(env); - return rc; - } - } - else - { - DosMemFree(env); - return rc; - } - } - else - /* with no error, we got exactly what we asked for */ - asize = exe_size; + exe_size = (LONG) long2para(image_size) + header.exMaxAlloc; + /* + long2para((LONG) sizeof(psp)); ?? -- 1999/04/21 ska */ + if (exe_size > asize) + exe_size = asize; -#ifdef DEBUG - printf("loading '%S' at %04x\n", namep, mem); -#endif + /* TE if header.exMinAlloc == header.exMaxAlloc == 0, + DOS will allocate the largest possible memory area + and load the image as high as possible into it. + discovered (and after that found in RBIL), when testing NET */ + + if ((header.exMinAlloc | header.exMaxAlloc) == 0) + exe_size = asize; + + /* /// Removed closing curly brace. We should not attempt to allocate + memory if we are overlaying the current process, because the new + process will simply re-use the block we already have allocated. + This was causing execl() to fail in applications which use it to + overlay (replace) the current exe file with a new one. + Jun 11, 2000 - rbc + } */ + + /* Allocate our memory and pass back any errors */ + /* We can still get an error on first fit if the above */ + /* returned size was a bet fit case */ + /* ModeLoadHigh = 80 = try high, then low */ + if ((rc = + DosMemAlloc((seg) exe_size, mem_access_mode | ModeLoadHigh, + (seg FAR *) & mem, (UWORD FAR *) & asize)) < 0) + { + if (rc == DE_NOMEM) + { + if ((rc = + DosMemAlloc(0, LARGEST, (seg FAR *) & mem, + (UWORD FAR *) & asize)) < 0) + { + DosMemFree(env); + return rc; + } + /* This should never happen, but ... */ + if (asize < exe_size) + { + DosMemFree(mem); + DosMemFree(env); + return rc; + } + } + else + { + DosMemFree(env); + return rc; + } + } + else + /* with no error, we got exactly what we asked for */ + asize = exe_size; + +#ifdef DEBUG + printf("loading '%S' at %04x\n", namep, mem); +#endif /* /// Added open curly brace and "else" clause. We should not attempt to allocate memory if we are overlaying the current process, because @@ -686,114 +676,118 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) This was causing execl() to fail in applications which use it to overlay (replace) the current exe file with a new one. Jun 11, 2000 - rbc */ - } - else - asize = exe_size; -/* /// End of additions. Jun 11, 2000 - rbc */ - - if ( ModeLoadHigh ) - { - mem_access_mode &= ~ModeLoadHigh; /* restore old situation */ - DosUmbLink(UMBstate); /* restore link state */ - } - - - if (mode != OVERLAY) - { - /* memory found large enough - continue processing */ - mp = MK_FP(mem, 0); - ++mem; - } - else - mem = exp->load.load_seg; - - /* create the start seg for later computations */ - if (mode == OVERLAY) - start_seg = mem; - else - { - start_seg = mem + long2para((LONG) sizeof(psp)); - } - - /* Now load the executable */ - /* If file not found - error */ - /* NOTE - this is fatal because we lost it in transit */ - /* from DosExec! */ - if ((rc = DosOpen(namep, 0)) < 0) - { - fatal("(DosExeLoader) exe file lost in transit"); - } - /* offset to start of image */ - if (doslseek(rc, image_offset, 0) != image_offset) - { - if (mode != OVERLAY) - { - DosMemFree(--mem); - DosMemFree(env); - } - return DE_INVLDDATA; - } - - /* read in the image in 32K chunks */ - if (mode != OVERLAY) - { - exe_size = image_size - sizeof(psp); - } - else - exe_size = image_size; - - if (exe_size > 0) - { - UCOUNT nBytesRead; - BYTE FAR *sp; - - if (mode != OVERLAY) - { - if ((header.exMinAlloc == 0) && (header.exMaxAlloc == 0)) - { - /* then the image should be placed as high as possible */ - start_seg = start_seg + mp->m_size - (image_size + 15) / 16; - } - } - - sp = MK_FP(start_seg, 0x0); - - do - { - nBytesRead = DosRead((COUNT) rc, (COUNT) (exe_size < CHUNK ? exe_size : CHUNK), (VOID FAR *) sp, &UnusedRetVal); - sp = add_far((VOID FAR *) sp, (ULONG) nBytesRead); - exe_size -= nBytesRead; - } - while (nBytesRead && exe_size > 0); - } - } - - { /* relocate the image for new segment */ - COUNT i; - UWORD reloc[2]; - seg FAR *spot; - - doslseek(rc, (LONG) header.exRelocTable, 0); - for (i = 0; i < header.exRelocItems; i++) - { - if (DosRead(rc, sizeof(reloc), (VOID FAR *) & reloc[0], &UnusedRetVal) != sizeof(reloc)) - { - return DE_INVLDDATA; - } - if (mode == OVERLAY) - { - spot = MK_FP(reloc[1] + mem, reloc[0]); - *spot += exp->load.reloc; } else + asize = exe_size; +/* /// End of additions. Jun 11, 2000 - rbc */ + + if (ModeLoadHigh) { - /* spot = MK_FP(reloc[1] + mem + 0x10, reloc[0]); */ - spot = MK_FP(reloc[1] + start_seg, reloc[0]); - *spot += start_seg; + mem_access_mode &= ~ModeLoadHigh; /* restore old situation */ + DosUmbLink(UMBstate); /* restore link state */ + } + + if (mode != OVERLAY) + { + /* memory found large enough - continue processing */ + mp = MK_FP(mem, 0); + ++mem; + } + else + mem = exp->load.load_seg; + + /* create the start seg for later computations */ + if (mode == OVERLAY) + start_seg = mem; + else + { + start_seg = mem + long2para((LONG) sizeof(psp)); + } + + /* Now load the executable */ + /* If file not found - error */ + /* NOTE - this is fatal because we lost it in transit */ + /* from DosExec! */ + if ((rc = DosOpen(namep, 0)) < 0) + { + fatal("(DosExeLoader) exe file lost in transit"); + } + /* offset to start of image */ + if (doslseek(rc, image_offset, 0) != image_offset) + { + if (mode != OVERLAY) + { + DosMemFree(--mem); + DosMemFree(env); + } + return DE_INVLDDATA; + } + + /* read in the image in 32K chunks */ + if (mode != OVERLAY) + { + exe_size = image_size - sizeof(psp); + } + else + exe_size = image_size; + + if (exe_size > 0) + { + UCOUNT nBytesRead; + BYTE FAR *sp; + + if (mode != OVERLAY) + { + if ((header.exMinAlloc == 0) && (header.exMaxAlloc == 0)) + { + /* then the image should be placed as high as possible */ + start_seg = start_seg + mp->m_size - (image_size + 15) / 16; + } + } + + sp = MK_FP(start_seg, 0x0); + + do + { + nBytesRead = + DosRead((COUNT) rc, + (COUNT) (exe_size < CHUNK ? exe_size : CHUNK), + (VOID FAR *) sp, &UnusedRetVal); + sp = add_far((VOID FAR *) sp, (ULONG) nBytesRead); + exe_size -= nBytesRead; + } + while (nBytesRead && exe_size > 0); } } + + { /* relocate the image for new segment */ + COUNT i; + UWORD reloc[2]; + seg FAR *spot; + + doslseek(rc, (LONG) header.exRelocTable, 0); + for (i = 0; i < header.exRelocItems; i++) + { + if (DosRead + (rc, sizeof(reloc), (VOID FAR *) & reloc[0], + &UnusedRetVal) != sizeof(reloc)) + { + return DE_INVLDDATA; + } + if (mode == OVERLAY) + { + spot = MK_FP(reloc[1] + mem, reloc[0]); + *spot += exp->load.reloc; + } + else + { + /* spot = MK_FP(reloc[1] + mem + 0x10, reloc[0]); */ + spot = MK_FP(reloc[1] + start_seg, reloc[0]); + *spot += start_seg; + } + } } - + /* and finally close the file */ DosClose(rc); @@ -801,64 +795,61 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) if (mode == OVERLAY) return SUCCESS; - { - psp FAR *p; - psp FAR *q = MK_FP(cu_psp, 0); + psp FAR *p; + psp FAR *q = MK_FP(cu_psp, 0); - /* point to the PSP so we can build it */ - p = MK_FP(mem, 0); - setvec(0x22, (VOID(INRPT FAR *) (VOID)) MK_FP(user_r->CS, user_r->IP)); - new_psp(p, mem + asize); + /* point to the PSP so we can build it */ + p = MK_FP(mem, 0); + setvec(0x22, (VOID(INRPT FAR *) (VOID)) MK_FP(user_r->CS, user_r->IP)); + new_psp(p, mem + asize); - asize = patchPSP(mem - 1, env, exp, namep); /* asize = fcbcode */ + asize = patchPSP(mem - 1, env, exp, namep); /* asize = fcbcode */ - /* Transfer control to the executable */ - p->ps_parent = cu_psp; - p->ps_prevpsp = (BYTE FAR *) MK_FP(cu_psp, 0); - q->ps_stack = (BYTE FAR *) user_r; - user_r->FLAGS &= ~FLG_CARRY; + /* Transfer control to the executable */ + p->ps_parent = cu_psp; + p->ps_prevpsp = (BYTE FAR *) MK_FP(cu_psp, 0); + q->ps_stack = (BYTE FAR *) user_r; + user_r->FLAGS &= ~FLG_CARRY; - switch (mode) - { - case LOADNGO: + switch (mode) { - /* build the user area on the stack */ - iregs FAR *irp = MK_FP(header.exInitSS + start_seg, - ((header.exInitSP - sizeof(iregs)) & 0xffff)); + case LOADNGO: + { + /* build the user area on the stack */ + iregs FAR *irp = MK_FP(header.exInitSS + start_seg, + ((header.exInitSP - + sizeof(iregs)) & 0xffff)); - /* start allocating REGs */ - /* Note: must match es & ds memory segment */ - irp->ES = irp->DS = mem; - irp->CS = header.exInitCS + start_seg; - irp->IP = header.exInitIP; - irp->AX = asize; /* asize = fcbcode */ - irp->BX = - irp->CX = - irp->DX = - irp->SI = - irp->DI = - irp->BP = 0; - irp->FLAGS = 0x200; + /* start allocating REGs */ + /* Note: must match es & ds memory segment */ + irp->ES = irp->DS = mem; + irp->CS = header.exInitCS + start_seg; + irp->IP = header.exInitIP; + irp->AX = asize; /* asize = fcbcode */ + irp->BX = irp->CX = irp->DX = irp->SI = irp->DI = irp->BP = 0; + irp->FLAGS = 0x200; - cu_psp = mem; - dta = p->ps_dta; + cu_psp = mem; + dta = p->ps_dta; - if (InDOS) - --InDOS; - exec_user(irp); - /* We should never be here - fatal("KERNEL RETURNED!!!"); */ - break; + if (InDOS) + --InDOS; + exec_user(irp); + /* We should never be here + fatal("KERNEL RETURNED!!!"); */ + break; + } + + case LOAD: + cu_psp = mem; + exp->exec.stack = + MK_FP(header.exInitSS + start_seg, header.exInitSP); + *((UWORD FAR *) exp->exec.stack) = asize; /* fcbcode */ + exp->exec.start_addr = + MK_FP(header.exInitCS + start_seg, header.exInitIP); + return SUCCESS; } - - case LOAD: - cu_psp = mem; - exp->exec.stack = MK_FP(header.exInitSS + start_seg, header.exInitSP); - *((UWORD FAR *) exp->exec.stack) = asize; /* fcbcode */ - exp->exec.start_addr = MK_FP(header.exInitCS + start_seg, header.exInitIP); - return SUCCESS; - } } return DE_INVLDFMT; } @@ -885,7 +876,6 @@ COUNT DosExec(COUNT mode, exec_blk FAR * ep, BYTE FAR * lp) return DE_FILENOTFND; } - if (DosRead(rc, sizeof(exe_header), (VOID FAR *) & header, &UnusedRetVal) != sizeof(exe_header)) { @@ -995,4 +985,3 @@ COUNT DosExec(COUNT mode, exec_blk FAR * ep, BYTE FAR * lp) * Rev 1.0 02 Jul 1995 8:34:06 patv * Initial revision. */ - diff --git a/sys/bin2c.c b/sys/bin2c.c index f53b3a7..eb70f4a 100644 --- a/sys/bin2c.c +++ b/sys/bin2c.c @@ -8,7 +8,8 @@ int main(int argc, char **argv) if (argc < 4) { - fprintf(stderr, "Usage: bin2c \n"); + fprintf(stderr, + "Usage: bin2c \n"); return 1; } diff --git a/sys/fdkrncfg.c b/sys/fdkrncfg.c index d1dd706..21f2d65 100644 --- a/sys/fdkrncfg.c +++ b/sys/fdkrncfg.c @@ -15,11 +15,9 @@ /* This source compiled & tested with Borland C/C++ 3.1 + TC 2.01*/ - char VERSION[] = "v1.00"; char PROGRAM[] = "SYS CONFIG"; -char KERNEL[] = "KERNEL.SYS"; - +char KERNEL[] = "KERNEL.SYS"; #include #include @@ -30,8 +28,7 @@ char KERNEL[] = "KERNEL.SYS"; #define FAR far #include "kconfig.h" -KernelConfig cfg = {0}; - +KernelConfig cfg = { 0 }; typedef unsigned char byte; typedef signed char sbyte; @@ -40,45 +37,39 @@ typedef signed short sword; typedef unsigned long dword; typedef signed long sdword; - /* These structures need to be byte packed, if your compiler does not do this by default, add the appropriate command, such as #pragma pack(1) here, protected with #ifdefs of course. */ - - /* Displays command line syntax */ void showUsage(void) { printf("Usage: \n" - " %s \n" - " %s [/help | /?]\n" - " %s [ [drive:][path]%s] [option=value ...] \n", - PROGRAM, PROGRAM, PROGRAM, KERNEL); + " %s \n" + " %s [/help | /?]\n" + " %s [ [drive:][path]%s] [option=value ...] \n", + PROGRAM, PROGRAM, PROGRAM, KERNEL); printf("\n"); printf(" If no options are given, the current values are shown.\n"); printf(" /help or /? displays this usage information.\n" - " [drive:][path]KERNEL.SYS specifies the kernel file to\n" - " modify, if not given defaults to %s\n", - KERNEL); + " [drive:][path]KERNEL.SYS specifies the kernel file to\n" + " modify, if not given defaults to %s\n", KERNEL); printf("\n"); - printf(" option=value ... specifies one or more options and the values\n" - " to set each to. If an option is given multiple times,\n" - " the value set will be the rightmost one.\n"); + printf + (" option=value ... specifies one or more options and the values\n" + " to set each to. If an option is given multiple times,\n" + " the value set will be the rightmost one.\n"); printf(" Current Options are: DLASORT=0|1, SHOWDRIVEASSIGNMENT=0|1\n" " SKIPCONFIGSECONDS=#, FORCELBA=0|1\n" " GLOBALENABLELBASUPPORT=0|1\n"); } - - /* simply reads in current configuration values, exiting program with an error message and error code unable to, otherwise cfg & kfile are valid on return. */ - /* Reads in the current kernel configuration settings, return 0 on success, nonzero on error. If there was an actual error the return value is positive, if there @@ -92,35 +83,34 @@ void showUsage(void) not point to allocated memory on entry, as that memory will not be used, and will likely not be freed as a result). */ -int readConfigSettings(int kfile, char *kfilename, KernelConfig *cfg) +int readConfigSettings(int kfile, char *kfilename, KernelConfig * cfg) { int ch; int configBlkFound; word cfgSize; - /* Seek to start of kernel file */ - if (lseek(kfile, 2, SEEK_SET) != 2) - printf("can't seek to offset 2\n"),exit(1); + if (lseek(kfile, 2, SEEK_SET) != 2) + printf("can't seek to offset 2\n"), exit(1); - if (read(kfile,cfg,sizeof(KernelConfig)) != sizeof(KernelConfig)) - printf("can't read %u bytes\n",sizeof(KernelConfig)),exit(1); + if (read(kfile, cfg, sizeof(KernelConfig)) != sizeof(KernelConfig)) + printf("can't read %u bytes\n", sizeof(KernelConfig)), exit(1); - if (memcmp(cfg->CONFIG, "CONFIG", 6) != 0) - { - printf("Error: no CONFIG section found in kernel file <%s>\n", kfilename); - printf("Only FreeDOS kernels after 2025 contain a CONFIG section!\n"); - exit(1); - } - - return 1; -} + if (memcmp(cfg->CONFIG, "CONFIG", 6) != 0) + { + printf("Error: no CONFIG section found in kernel file <%s>\n", + kfilename); + printf("Only FreeDOS kernels after 2025 contain a CONFIG section!\n"); + exit(1); + } + return 1; +} /* Writes config values out to file. Returns 0 on success, nonzero on error. */ -int writeConfigSettings(int kfile, KernelConfig *cfg) +int writeConfigSettings(int kfile, KernelConfig * cfg) { /* Seek to CONFIG section at start of options of kernel file */ @@ -135,53 +125,59 @@ int writeConfigSettings(int kfile, KernelConfig *cfg) return 0; } - /* Displays kernel configuration information */ -void displayConfigSettings(KernelConfig *cfg) +void displayConfigSettings(KernelConfig * cfg) { /* print known options and current value - only if available */ if (cfg->ConfigSize >= 1) { - printf("DLASORT=0x%02X Sort disks by drive order: *0=no, 1=yes\n", - cfg->DLASortByDriveNo); + printf + ("DLASORT=0x%02X Sort disks by drive order: *0=no, 1=yes\n", + cfg->DLASortByDriveNo); } if (cfg->ConfigSize >= 2) { - printf("SHOWDRIVEASSIGNMENT=0x%02X Show how drives assigned: *1=yes 0=no\n", - cfg->InitDiskShowDriveAssignment); + printf + ("SHOWDRIVEASSIGNMENT=0x%02X Show how drives assigned: *1=yes 0=no\n", + cfg->InitDiskShowDriveAssignment); } if (cfg->ConfigSize >= 3) { - printf("SKIPCONFIGSECONDS=%-3d time to wait for F5/F8 : *2 sec (skip < 0)\n", - cfg->SkipConfigSeconds); + printf + ("SKIPCONFIGSECONDS=%-3d time to wait for F5/F8 : *2 sec (skip < 0)\n", + cfg->SkipConfigSeconds); } if (cfg->ConfigSize >= 4) { - printf("FORCELBA=0x%02X Always use LBA if possible: *0=no, 1=yes\n", - cfg->ForceLBA); + printf + ("FORCELBA=0x%02X Always use LBA if possible: *0=no, 1=yes\n", + cfg->ForceLBA); } if (cfg->ConfigSize >= 5) { - printf("GLOBALENABLELBASUPPORT=0x%02X Enable LBA support: *1=yes, 0=no\n", - cfg->GlobalEnableLBAsupport); + printf + ("GLOBALENABLELBASUPPORT=0x%02X Enable LBA support: *1=yes, 0=no\n", + cfg->GlobalEnableLBAsupport); } -#if 0 /* we assume that SYS is as current as the kernel */ +#if 0 /* we assume that SYS is as current as the kernel */ /* Print value any options added that are unknown as hex dump */ if (cfg->configHdr.configSize > sizeof(ConfigData)) { printf("Additional options are available, they are not currently\n" - "supported by this tool. The current extra values are (in Hex):\n"); - for (i = 0; i < (cfg->configSize-sizeof(ConfigData)); i++) + "supported by this tool. The current extra values are (in Hex):\n"); + for (i = 0; i < (cfg->configSize - sizeof(ConfigData)); i++) { - if ((i%32) == 0) printf("\n"); - else if ((i%4) == 0) printf(" "); + if ((i % 32) == 0) + printf("\n"); + else if ((i % 4) == 0) + printf(" "); printf("%02X", (unsigned int)cfg->extra[i]); } printf("\n"); @@ -190,8 +186,6 @@ void displayConfigSettings(KernelConfig *cfg) printf("\n"); } - - /* Note: The setXXXOption functions will set the config option of type XXX to the value given. It will display a warning, but allow probably invalid values to be used (cause I believe in @@ -205,7 +199,8 @@ void displayConfigSettings(KernelConfig *cfg) /* Sets the given location to an unsigned byte value if different, displays warning if values exceeds max */ -void setByteOption(byte *option, char *value, word max, int *updated, char *name) +void setByteOption(byte * option, char *value, word max, int *updated, + char *name) { unsigned long optionValue; @@ -215,17 +210,17 @@ void setByteOption(byte *option, char *value, word max, int *updated, char *name if (optionValue > 255) { printf("Warning: Option %s: Value <0x%02lX> will be truncated!\n", - name, optionValue); + name, optionValue); } - if ((byte)optionValue > max) + if ((byte) optionValue > max) { printf("Warning: Option %s: Value <0x%02X> may be invalid!\n", - name, (unsigned int)((byte)optionValue)); + name, (unsigned int)((byte) optionValue)); } /* Don't bother updating if same value */ - if ((byte)optionValue != *option) + if ((byte) optionValue != *option) { - *option = (byte)optionValue; + *option = (byte) optionValue; *updated = 1; } } @@ -233,36 +228,38 @@ void setByteOption(byte *option, char *value, word max, int *updated, char *name /* Sets the given location to a signed byte value if different, displays warning if values exceeds max or is less than min */ -void setSByteOption(sbyte *option, char *value, sword min, sword max, int *updated, char *name) +void setSByteOption(sbyte * option, char *value, sword min, sword max, + int *updated, char *name) { signed long optionValue; /* optionValue = atoi(value); Use strtol instead of atoi/atol as it detects base */ optionValue = strtol(value, NULL, 0); - if ( (optionValue < -128) || (optionValue > 127) ) + if ((optionValue < -128) || (optionValue > 127)) { printf("Warning: Option %s: Value <0x%02lX> will be truncated!\n", - name, optionValue); + name, optionValue); } - if ( ((sbyte)optionValue > max) || ((sbyte)optionValue < min) ) + if (((sbyte) optionValue > max) || ((sbyte) optionValue < min)) { printf("Warning: Option %s: Value <0x%02X> may be invalid!\n", - name, (signed int)((byte)optionValue)); + name, (signed int)((byte) optionValue)); } /* Don't bother updating if same value */ - if ((sbyte)optionValue != *option) + if ((sbyte) optionValue != *option) { - *option = (sbyte)optionValue; + *option = (sbyte) optionValue; *updated = 1; } } -#if 0 /* disable until there are (un)signed word configuration values */ +#if 0 /* disable until there are (un)signed word configuration values */ /* Sets the given location to an unsigned word value if different, displays warning if values exceeds max */ -void setWordOption(word *option, char *value, dword max, int *updated, char *name) +void setWordOption(word * option, char *value, dword max, int *updated, + char *name) { unsigned long optionValue; @@ -272,17 +269,17 @@ void setWordOption(word *option, char *value, dword max, int *updated, char *nam if (optionValue > 65535) { printf("Warning: Option %s: Value <0x%02lX> will be truncated!\n", - name, optionValue); + name, optionValue); } - if ((word)optionValue > max) + if ((word) optionValue > max) { printf("Warning: Option %s: Value <0x%02X> may be invalid!\n", - name, (unsigned int)optionValue); + name, (unsigned int)optionValue); } /* Don't bother updating if same value */ - if ((word)optionValue != *option) + if ((word) optionValue != *option) { - *option = (word)optionValue; + *option = (word) optionValue; *updated = 1; } } @@ -290,174 +287,166 @@ void setWordOption(word *option, char *value, dword max, int *updated, char *nam /* Sets the given location to a signed byte value if different, displays warning if values exceeds max or is less than min */ -void setSWordOption(sword *option, char *value, sdword min, sdword max, int *updated, char *name) +void setSWordOption(sword * option, char *value, sdword min, sdword max, + int *updated, char *name) { signed long optionValue; /* optionValue = atol(value); Use strtol instead of atoi/atol as it allows 0xFF and 255 */ optionValue = strtol(value, NULL, 0); - if ( (optionValue < -32768) || (optionValue > 32767) ) + if ((optionValue < -32768) || (optionValue > 32767)) { printf("Warning: Option %s: Value <0x%02lX> will be truncated!\n", - name, optionValue); + name, optionValue); } - if ( ((sword)optionValue > max) || ((sword)optionValue < min) ) + if (((sword) optionValue > max) || ((sword) optionValue < min)) { printf("Warning: Option %s: Value <0x%02X> may be invalid!\n", - name, (signed int)optionValue); + name, (signed int)optionValue); } /* Don't bother updating if same value */ - if ((sword)optionValue != *option) + if ((sword) optionValue != *option) { - *option = (sword)optionValue; + *option = (sword) optionValue; *updated = 1; } } #endif - /* Main, processes command line options and calls above functions as required. */ -int FDKrnConfigMain(int argc,char **argv) +int FDKrnConfigMain(int argc, char **argv) { - char *kfilename = KERNEL; + char *kfilename = KERNEL; int kfile; - int updates = 0; /* flag used to indicate if we need to update kernel */ - int argstart,i; + int updates = 0; /* flag used to indicate if we need to update kernel */ + int argstart, i; char *cptr; char *argptr; printf("FreeDOS Kernel Configuration %s\n", VERSION); - /* 1st go through and just process arguments (help/filename/etc) */ - for (i = 2; i < argc; i++) + for (i = 2; i < argc; i++) + { + argptr = argv[i]; + + /* is it an argument or an option specifier */ + if (argptr[0] == '-' || argptr[0] == '/') { - argptr = argv[i]; - - /* is it an argument or an option specifier */ - if (argptr[0] == '-' || argptr[0] == '/') - { - switch(argptr[1]) - { - case 'H': - case 'h': - case '?': - showUsage(); - exit(0); - - default: - printf("Invalid argument found <%s>.\nUse %s /help for usage.\n", - argptr, PROGRAM); - exit(1); - } - } - } - - argstart = 2; + switch (argptr[1]) + { + case 'H': + case 'h': + case '?': + showUsage(); + exit(0); - argptr = argv[argstart]; + default: + printf("Invalid argument found <%s>.\nUse %s /help for usage.\n", + argptr, PROGRAM); + exit(1); + } + } + } -#if 0 /* No arguments is acceptable, just displays current settings using default kernel file */ - if (argptr == 0) - { - showUsage(); - exit(1); - } + argstart = 2; + + argptr = argv[argstart]; + +#if 0 /* No arguments is acceptable, just displays current settings using default kernel file */ + if (argptr == 0) + { + showUsage(); + exit(1); + } #endif - /* the first argument may be the kernel name */ - if ( (argstart < argc) && (strchr(argptr, '=') == NULL) ) - { - kfilename = argptr; - argstart++; - } + /* the first argument may be the kernel name */ + if ((argstart < argc) && (strchr(argptr, '=') == NULL)) + { + kfilename = argptr; + argstart++; + } + kfile = open(kfilename, O_RDWR | O_BINARY); - kfile = open(kfilename, O_RDWR | O_BINARY); + if (kfile < 0) + printf("Error: unable to open kernel file <%s>\n", kfilename), exit(1); - if (kfile < 0) - printf("Error: unable to open kernel file <%s>\n", kfilename),exit(1); + /* now that we know the filename (default or given) get config info */ + readConfigSettings(kfile, kfilename, &cfg); + for (i = argstart; i < argc; i++) + { + argptr = argv[i]; - /* now that we know the filename (default or given) get config info */ - readConfigSettings(kfile, kfilename, &cfg); + if ((cptr = strchr(argptr, '=')) == NULL) + goto illegal_arg; - for (i = argstart; i < argc; i++) - { - argptr = argv[i]; + /* split argptr into 2 pieces and make cptr point to 2nd one */ + *cptr = '\0'; + cptr++; - if ((cptr = strchr(argptr,'=')) == NULL) - goto illegal_arg; - - /* split argptr into 2 pieces and make cptr point to 2nd one */ - *cptr = '\0'; - cptr++; - - /* allow 3 valid characters */ - if (memicmp(argptr, "DLASORT",3) == 0) - { - setByteOption(&(cfg.DLASortByDriveNo), - cptr, 1, &updates, "DLASORT"); - } - else if (memicmp(argptr, "SHOWDRIVEASSIGNMENT",3) == 0) - { - setByteOption(&(cfg.InitDiskShowDriveAssignment), - cptr, 1, &updates, "SHOWDRIVEASSIGNMENT"); - } - else if (memicmp(argptr, "SKIPCONFIGSECONDS",3) == 0) - { - setSByteOption(&(cfg.SkipConfigSeconds), - cptr, -128, 127, &updates, "SKIPCONFIGSECONDS"); - } - else if (memicmp(argptr, "FORCELBA",3) == 0) - { - setByteOption(&(cfg.ForceLBA), - cptr, 1, &updates, "FORCELBA"); - } - else if (memicmp(argptr, "GLOBALENABLELBASUPPORT",3) == 0) - { - setByteOption(&(cfg.GlobalEnableLBAsupport), - cptr, 1, &updates, "GLOBALENABLELBASUPPORT"); - } - else - { -illegal_arg: - printf("Unknown option found <%s>.\nUse %s /help for usage.\n", - argptr, PROGRAM); - exit(1); - } - } - - /* write out new config values if modified */ - if (updates) + /* allow 3 valid characters */ + if (memicmp(argptr, "DLASORT", 3) == 0) { - /* update it */ - if (writeConfigSettings(kfile, &cfg)) - { - printf("Error: Unable to write configuration changes to kernel!\n"); - printf(" <%s>\n", kfilename); - close(kfile); - exit(1); - } - - - /* display new settings */ - printf("\nUpdated Kernel settings.\n"); + setByteOption(&(cfg.DLASortByDriveNo), cptr, 1, &updates, "DLASORT"); + } + else if (memicmp(argptr, "SHOWDRIVEASSIGNMENT", 3) == 0) + { + setByteOption(&(cfg.InitDiskShowDriveAssignment), + cptr, 1, &updates, "SHOWDRIVEASSIGNMENT"); + } + else if (memicmp(argptr, "SKIPCONFIGSECONDS", 3) == 0) + { + setSByteOption(&(cfg.SkipConfigSeconds), + cptr, -128, 127, &updates, "SKIPCONFIGSECONDS"); + } + else if (memicmp(argptr, "FORCELBA", 3) == 0) + { + setByteOption(&(cfg.ForceLBA), cptr, 1, &updates, "FORCELBA"); + } + else if (memicmp(argptr, "GLOBALENABLELBASUPPORT", 3) == 0) + { + setByteOption(&(cfg.GlobalEnableLBAsupport), + cptr, 1, &updates, "GLOBALENABLELBASUPPORT"); } else - printf("\nCurrent Kernel settings.\n"); + { + illegal_arg: + printf("Unknown option found <%s>.\nUse %s /help for usage.\n", + argptr, PROGRAM); + exit(1); + } + } + /* write out new config values if modified */ + if (updates) + { + /* update it */ + if (writeConfigSettings(kfile, &cfg)) + { + printf("Error: Unable to write configuration changes to kernel!\n"); + printf(" <%s>\n", kfilename); + close(kfile); + exit(1); + } + + /* display new settings */ + printf("\nUpdated Kernel settings.\n"); + } + else + printf("\nCurrent Kernel settings.\n"); /* display current settings */ - displayConfigSettings(&cfg); + displayConfigSettings(&cfg); - /* and done */ - close(kfile); + /* and done */ + close(kfile); - return 0; + return 0; } - diff --git a/sys/sys.c b/sys/sys.c index 5392904..37f52a8 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -46,9 +46,9 @@ #include #include #ifdef __TURBOC__ - #include +#include #else - #include +#include #endif #include /*#include */ @@ -69,16 +69,14 @@ BOOL copy(COUNT drive, BYTE * srcPath, BYTE * rootPath, BYTE * file); COUNT DiskRead(WORD, WORD, WORD, WORD, WORD, BYTE FAR *); COUNT DiskWrite(WORD, WORD, WORD, WORD, WORD, BYTE FAR *); - #define SEC_SIZE 512 #define COPY_SIZE 32768u #ifdef _MSC_VER - #pragma pack(1) +#pragma pack(1) #endif -struct bootsectortype -{ +struct bootsectortype { UBYTE bsJump[3]; char OemName[8]; UWORD bsBytesPerSec; @@ -106,8 +104,7 @@ struct bootsectortype ULONG sysDataStart; /* first data sector */ }; -struct bootsectortype32 -{ +struct bootsectortype32 { UBYTE bsJump[3]; char OemName[8]; UWORD bsBytesPerSec; @@ -134,7 +131,7 @@ struct bootsectortype32 UBYTE bsReserved3; UBYTE bsExtendedSignature; ULONG bsSerialNumber; - char bsVolumeLabel[11]; + char bsVolumeLabel[11]; char bsFileSystemID[8]; ULONG sysFatStart; ULONG sysDataStart; @@ -144,19 +141,17 @@ struct bootsectortype32 UBYTE newboot[SEC_SIZE], oldboot[SEC_SIZE]; - #define SBOFFSET 11 #define SBSIZE (sizeof(struct bootsectortype) - SBOFFSET) #define SBSIZE32 (sizeof(struct bootsectortype32) - SBOFFSET) /* essentially - verify alignment on byte boundaries at compile time */ -struct VerifyBootSectorSize -{ - char failure1[sizeof(struct bootsectortype) == 78 ? 1 : -1]; - char failure2[sizeof(struct bootsectortype) == 78 ? 1 : 0]; +struct VerifyBootSectorSize { + char failure1[sizeof(struct bootsectortype) == 78 ? 1 : -1]; + char failure2[sizeof(struct bootsectortype) == 78 ? 1 : 0]; }; -int FDKrnConfigMain(int argc,char **argv); +int FDKrnConfigMain(int argc, char **argv); int main(int argc, char **argv) { @@ -169,26 +164,26 @@ int main(int argc, char **argv) WORD slen; printf("FreeDOS System Installer " SYS_VERSION "\n\n"); - - if (argc > 1 && memicmp(argv[1],"CONFIG",6) == 0) - { - exit(FDKrnConfigMain(argc,argv)); - } + + if (argc > 1 && memicmp(argv[1], "CONFIG", 6) == 0) + { + exit(FDKrnConfigMain(argc, argv)); + } srcPath[0] = '\0'; if (argc > 1 && argv[1][1] == ':' && argv[1][2] == '\0') drivearg = 1; - + if (argc > 2 && argv[2][1] == ':' && argv[2][2] == '\0') { drivearg = 2; - strncpy(srcPath, argv[1], MAXPATH-12); + strncpy(srcPath, argv[1], MAXPATH - 12); /* leave room for COMMAND.COM\0 */ - srcPath[MAXPATH-13] = '\0'; + srcPath[MAXPATH - 13] = '\0'; /* make sure srcPath + "file" is a valid path */ slen = strlen(srcPath); - if ( (srcPath[slen-1] != ':') && - ((srcPath[slen-1] != '\\') || (srcPath[slen-1] != '/')) ) + if ((srcPath[slen - 1] != ':') && + ((srcPath[slen - 1] != '\\') || (srcPath[slen - 1] != '/'))) { srcPath[slen] = '\\'; slen++; @@ -199,48 +194,52 @@ int main(int argc, char **argv) if (drivearg == 0) { printf("Usage: %s [source] drive: [bootsect [BOTH]]\n", pgm); - printf(" source = A:,B:,C:\\KERNEL\\BIN\\,etc., or current directory if not given\n"); + printf + (" source = A:,B:,C:\\KERNEL\\BIN\\,etc., or current directory if not given\n"); printf(" drive = A,B,etc.\n"); - printf(" bootsect = name of 512-byte boot sector file image for drive:\n"); + printf + (" bootsect = name of 512-byte boot sector file image for drive:\n"); printf(" to write to instead of real boot sector\n"); - printf(" BOTH : write to both the real boot sector and the image file\n"); - printf("%s CONFIG /help\n",pgm); + printf + (" BOTH : write to both the real boot sector and the image file\n"); + printf("%s CONFIG /help\n", pgm); exit(1); } drive = toupper(argv[drivearg][0]) - 'A'; if (drive < 0 || drive >= 26) { - printf( "%s: drive %c must be A:..Z:\n", pgm,*argv[(argc == 3 ? 2 : 1)]); + printf("%s: drive %c must be A:..Z:\n", pgm, + *argv[(argc == 3 ? 2 : 1)]); exit(1); } - /* Get source drive */ - if ((strlen(srcPath) > 1) && (srcPath[1] == ':')) /* src specifies drive */ + /* Get source drive */ + if ((strlen(srcPath) > 1) && (srcPath[1] == ':')) /* src specifies drive */ srcDrive = toupper(*srcPath) - 'A'; - else /* src doesn't specify drive, so assume current drive */ - { + else /* src doesn't specify drive, so assume current drive */ + { #ifdef __TURBOC__ srcDrive = getdisk(); -#else +#else _dos_getdrive(&srcDrive); -#endif - } +#endif + } /* Don't try root if src==dst drive or source path given */ - if ( (drive == srcDrive) || (*srcPath && ((srcPath[1] != ':') || ((srcPath[1] == ':') && srcPath[2]))) ) + if ((drive == srcDrive) + || (*srcPath + && ((srcPath[1] != ':') || ((srcPath[1] == ':') && srcPath[2])))) *rootPath = '\0'; else sprintf(rootPath, "%c:\\", 'A' + srcDrive); - if (!check_space(drive, oldboot)) { printf("%s: Not enough space to transfer system files\n", pgm); exit(1); } - printf("\nCopying KERNEL.SYS...\n"); if (!copy(drive, srcPath, rootPath, "kernel.sys")) { @@ -255,13 +254,14 @@ int main(int argc, char **argv) exit(1); } - if (argc > drivearg+1) - bsFile = argv[drivearg+1]; - + if (argc > drivearg + 1) + bsFile = argv[drivearg + 1]; + printf("\nWriting boot sector...\n"); put_boot(drive, bsFile, - (argc > drivearg+2) && memicmp(argv[drivearg+2], "BOTH", 4) == 0); - + (argc > drivearg + 2) + && memicmp(argv[drivearg + 2], "BOTH", 4) == 0); + printf("\nSystem transferred.\n"); return 0; } @@ -269,78 +269,77 @@ int main(int argc, char **argv) #ifdef DDEBUG VOID dump_sector(unsigned char far * sec) { - COUNT x, y; - char c; + COUNT x, y; + char c; - for (x = 0; x < 32; x++) + for (x = 0; x < 32; x++) + { + printf("%03X ", x * 16); + for (y = 0; y < 16; y++) { - printf("%03X ", x * 16); - for (y = 0; y < 16; y++) - { - printf("%02X ", sec[x * 16 + y]); - } - for (y = 0; y < 16; y++) - { - c = oldboot[x * 16 + y]; - if (isprint(c)) - printf( "%c", c); - else - printf( "."); - } - printf( "\n"); - } + printf("%02X ", sec[x * 16 + y]); + } + for (y = 0; y < 16; y++) + { + c = oldboot[x * 16 + y]; + if (isprint(c)) + printf("%c", c); + else + printf("."); + } + printf("\n"); + } - printf( "\n"); + printf("\n"); } #endif - /* TC absRead not functional on MSDOS 6.2, large disks MSDOS requires int25, CX=ffff for drives > 32MB */ -int MyAbsReadWrite(int DosDrive, int count, ULONG sector, void *buffer, unsigned intno) +int MyAbsReadWrite(int DosDrive, int count, ULONG sector, void *buffer, + unsigned intno) { - struct { - unsigned long sectorNumber; - unsigned short count; - void far *address; - } diskReadPacket; - int retval; - union REGS regs; + struct { + unsigned long sectorNumber; + unsigned short count; + void far *address; + } diskReadPacket; + int retval; + union REGS regs; + diskReadPacket.sectorNumber = sector; + diskReadPacket.count = count; + diskReadPacket.address = buffer; - diskReadPacket.sectorNumber = sector; - diskReadPacket.count = count; - diskReadPacket.address = buffer; + regs.h.al = (BYTE) DosDrive; + regs.x.bx = (short)&diskReadPacket; + regs.x.cx = 0xffff; - regs.h.al = (BYTE)DosDrive; + if (intno != 0x25 && intno != 0x26) + return 0xff; + + int86(intno, ®s, ®s); + +#ifdef WITHFAT32 + if (regs.x.cflag) + { + regs.x.ax = 0x7305; + regs.h.dl = DosDrive + 1; regs.x.bx = (short)&diskReadPacket; regs.x.cx = 0xffff; - - if (intno != 0x25 && intno != 0x26) return 0xff; - - int86(intno,®s,®s); - -#ifdef WITHFAT32 - if (regs.x.cflag) - { - regs.x.ax = 0x7305; - regs.h.dl = DosDrive + 1; - regs.x.bx = (short)&diskReadPacket; - regs.x.cx = 0xffff; - regs.x.si = intno - 0x25; - int86(0x21, ®s, ®s); - } + regs.x.si = intno - 0x25; + int86(0x21, ®s, ®s); + } #endif - return regs.x.cflag ? 0xff : 0; -} + return regs.x.cflag ? 0xff : 0; +} - -VOID put_boot(COUNT drive, BYTE *bsFile, BOOL both) +VOID put_boot(COUNT drive, BYTE * bsFile, BOOL both) { COUNT i, z; WORD head, track, sector, ret; @@ -355,25 +354,23 @@ VOID put_boot(COUNT drive, BYTE *bsFile, BOOL both) struct SREGS sregs; char drivename[] = "A:\\"; unsigned char x[0x40]; - #ifdef DEBUG - printf("Reading old bootsector from drive %c:\n",drive+'A'); -#endif + printf("Reading old bootsector from drive %c:\n", drive + 'A'); +#endif - if (MyAbsReadWrite(drive, 1, 0, oldboot,0x25) != 0) - { - printf("can't read old boot sector for drive %c:\n", drive +'A'); + if (MyAbsReadWrite(drive, 1, 0, oldboot, 0x25) != 0) + { + printf("can't read old boot sector for drive %c:\n", drive + 'A'); exit(1); - } - + } #ifdef DDEBUG printf("Old Boot Sector:\n"); dump_sector(oldboot); #endif - bs = (struct bootsectortype *) & oldboot; + bs = (struct bootsectortype *)&oldboot; if ((bs->bsFileSysType[4] == '6') && (bs->bsBootSignature == 0x29)) { fs = 16; @@ -388,78 +385,81 @@ VOID put_boot(COUNT drive, BYTE *bsFile, BOOL both) FS detection method to GetFreeDiskSpace(). this should work, as the disk was writeable, so GetFreeDiskSpace should work. */ - - regs.h.ah = 0x36; /* get drive free space */ - regs.h.dl = drive+1; /* 1 = 'A',... */ - int86(0x21,®s,®s); - - if (regs.x.ax == 0xffff) - { - printf("can't get free disk space for %c:\n", drive+'A'); - exit(1); - } - if (regs.x.dx <= 0xff6) - { - if (fs != 12) printf("warning : new detection overrides old detection\a\n"); - fs = 12; - } - else { - - if (fs != 16) printf("warning : new detection overrides old detection\a\n"); - fs = 16; + regs.h.ah = 0x36; /* get drive free space */ + regs.h.dl = drive + 1; /* 1 = 'A',... */ + int86(0x21, ®s, ®s); - /* fs = 16/32. - we don't want to crash a FAT32 drive - */ + if (regs.x.ax == 0xffff) + { + printf("can't get free disk space for %c:\n", drive + 'A'); + exit(1); + } - segread(&sregs); - sregs.es = sregs.ds; - - regs.x.ax = 0x7303; /* get extended drive free space */ - - drivename[0] = 'A' + drive; - regs.x.dx = (unsigned)&drivename; - regs.x.di = (unsigned)&x; - regs.x.cx = sizeof(x); - - int86x(0x21,®s,®s,&sregs); - - if (regs.x.cflag) /* error --> no Win98 --> no FAT32 */ - { - printf("get extended drive space not supported --> no FAT32\n"); - } - else { - if (*(unsigned long *)(x+0x2c) /* total number of clusters */ - > (unsigned)65526l) - { - fs = 32; - } - } - } + if (regs.x.dx <= 0xff6) + { + if (fs != 12) + printf("warning : new detection overrides old detection\a\n"); + fs = 12; + } + else + { + if (fs != 16) + printf("warning : new detection overrides old detection\a\n"); + fs = 16; - if (fs == 16) - { - memcpy(newboot, b_fat16, SEC_SIZE); /* copy FAT16 boot sector */ - printf("FAT type: FAT16\n"); - } - else if (fs == 12) - { - memcpy(newboot, b_fat12, SEC_SIZE); /* copy FAT12 boot sector */ - printf("FAT type: FAT12\n"); - } + /* fs = 16/32. + we don't want to crash a FAT32 drive + */ + + segread(&sregs); + sregs.es = sregs.ds; + + regs.x.ax = 0x7303; /* get extended drive free space */ + + drivename[0] = 'A' + drive; + regs.x.dx = (unsigned)&drivename; + regs.x.di = (unsigned)&x; + regs.x.cx = sizeof(x); + + int86x(0x21, ®s, ®s, &sregs); + + if (regs.x.cflag) /* error --> no Win98 --> no FAT32 */ + { + printf("get extended drive space not supported --> no FAT32\n"); + } else - { - printf("FAT type: FAT32\n"); + { + if (*(unsigned long *)(x + 0x2c) /* total number of clusters */ + > (unsigned)65526l) + { + fs = 32; + } + } + } + + if (fs == 16) + { + memcpy(newboot, b_fat16, SEC_SIZE); /* copy FAT16 boot sector */ + printf("FAT type: FAT16\n"); + } + else if (fs == 12) + { + memcpy(newboot, b_fat12, SEC_SIZE); /* copy FAT12 boot sector */ + printf("FAT type: FAT12\n"); + } + else + { + printf("FAT type: FAT32\n"); #ifdef WITHFAT32 - memcpy(newboot, b_fat32, SEC_SIZE); /* copy FAT32 boot sector */ + memcpy(newboot, b_fat32, SEC_SIZE); /* copy FAT32 boot sector */ #else - printf("SYS hasn't been compiled with FAT32 support."); - printf("Consider using -DWITHFAT32 option.\n"); - exit(1); + printf("SYS hasn't been compiled with FAT32 support."); + printf("Consider using -DWITHFAT32 option.\n"); + exit(1); #endif - } + } /* Copy disk parameter from old sector to new sector */ #ifdef WITHFAT32 @@ -469,31 +469,32 @@ VOID put_boot(COUNT drive, BYTE *bsFile, BOOL both) #endif memcpy(&newboot[SBOFFSET], &oldboot[SBOFFSET], SBSIZE); - bs = (struct bootsectortype *) & newboot; - - memcpy(bs->OemName, "FreeDOS ",8); + bs = (struct bootsectortype *)&newboot; + + memcpy(bs->OemName, "FreeDOS ", 8); #ifdef WITHFAT32 if (fs == 32) - { - bs32 = (struct bootsectortype32 *) & newboot; - - temp = bs32->bsHiddenSecs + bs32->bsResSectors; - bs32->sysFatStart = temp; - - bs32->sysDataStart = temp + bs32->bsBigFatSize * bs32->bsFATs; - bs32->sysFatSecMask = bs32->bsBytesPerSec / 4 - 1; - - temp = bs32->sysFatSecMask + 1; - for (bs32->sysFatSecShift = 0; temp != 1; bs32->sysFatSecShift++, temp >>= 1); - } + { + bs32 = (struct bootsectortype32 *)&newboot; + + temp = bs32->bsHiddenSecs + bs32->bsResSectors; + bs32->sysFatStart = temp; + + bs32->sysDataStart = temp + bs32->bsBigFatSize * bs32->bsFATs; + bs32->sysFatSecMask = bs32->bsBytesPerSec / 4 - 1; + + temp = bs32->sysFatSecMask + 1; + for (bs32->sysFatSecShift = 0; temp != 1; + bs32->sysFatSecShift++, temp >>= 1) ; + } #ifdef DEBUG if (fs == 32) - { - printf( "FAT starts at sector %lx = (%lx + %x)\n", bs32->sysFatStart, - bs32->bsHiddenSecs, bs32->bsResSectors); - printf("DATA starts at sector %lx\n", bs32->sysDataStart); - } + { + printf("FAT starts at sector %lx = (%lx + %x)\n", bs32->sysFatStart, + bs32->bsHiddenSecs, bs32->bsResSectors); + printf("DATA starts at sector %lx\n", bs32->sysDataStart); + } #endif else #endif @@ -502,39 +503,39 @@ VOID put_boot(COUNT drive, BYTE *bsFile, BOOL both) /* TE thinks : never, see above */ /* temporary HACK for the load segment (0x0060): it is in unused */ /* only needed for older kernels */ - *((UWORD *)(bs->unused)) = *((UWORD *)(((struct bootsectortype *)&b_fat16)->unused)); + *((UWORD *) (bs->unused)) = + *((UWORD *) (((struct bootsectortype *)&b_fat16)->unused)); /* end of HACK */ - /* root directory sectors */ + /* root directory sectors */ bs->sysRootDirSecs = bs->bsRootDirEnts / 16; - /* sector FAT starts on */ + /* sector FAT starts on */ temp = bs->bsHiddenSecs + bs->bsResSectors; bs->sysFatStart = temp; - - /* sector root directory starts on */ + + /* sector root directory starts on */ temp = temp + bs->bsFATsecs * bs->bsFATs; bs->sysRootDirStart = temp; - - /* sector data starts on */ + + /* sector data starts on */ temp = temp + bs->sysRootDirSecs; bs->sysDataStart = temp; } - + #ifdef DEBUG printf("Root dir entries = %u\n", bs->bsRootDirEnts); printf("Root dir sectors = %u\n", bs->sysRootDirSecs); - printf( "FAT starts at sector %lu = (%lu + %u)\n", bs->sysFatStart, - bs->bsHiddenSecs, bs->bsResSectors); + printf("FAT starts at sector %lu = (%lu + %u)\n", bs->sysFatStart, + bs->bsHiddenSecs, bs->bsResSectors); printf("Root directory starts at sector %lu = (PREVIOUS + %u * %u)\n", - bs->sysRootDirStart, bs->bsFATsecs, bs->bsFATs); + bs->sysRootDirStart, bs->bsFATsecs, bs->bsFATs); printf("DATA starts at sector %lu = (PREVIOUS + %u)\n", bs->sysDataStart, - bs->sysRootDirSecs); + bs->sysRootDirSecs); #endif #endif - #ifdef DDEBUG printf("\nNew Boot Sector:\n"); dump_sector(newboot); @@ -542,30 +543,32 @@ VOID put_boot(COUNT drive, BYTE *bsFile, BOOL both) if ((bsFile == NULL) || both) { - -#ifdef DEBUG - printf("writing new bootsector to drive %c:\n",drive+'A'); -#endif - if (MyAbsReadWrite(drive, 1, 0, newboot,0x26) != 0) +#ifdef DEBUG + printf("writing new bootsector to drive %c:\n", drive + 'A'); +#endif + + if (MyAbsReadWrite(drive, 1, 0, newboot, 0x26) != 0) { - printf("Can't write new boot sector to drive %c:\n", drive +'A'); + printf("Can't write new boot sector to drive %c:\n", drive + 'A'); exit(1); } } - + if (bsFile != NULL) { int fd; - + #ifdef DEBUG printf("writing new bootsector to file %s\n", bsFile); -#endif +#endif /* write newboot to bsFile */ - if ((fd = open(bsFile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY,S_IREAD|S_IWRITE)) < 0) + if ((fd = + open(bsFile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, + S_IREAD | S_IWRITE)) < 0) { - printf( " %s: can't create\"%s\"\nDOS errnum %d", pgm, bsFile, errno); + printf(" %s: can't create\"%s\"\nDOS errnum %d", pgm, bsFile, errno); exit(1); } if (write(fd, newboot, SEC_SIZE) != SEC_SIZE) @@ -579,15 +582,13 @@ VOID put_boot(COUNT drive, BYTE *bsFile, BOOL both) } } - BOOL check_space(COUNT drive, BYTE * BlkBuffer) { - /* this should check, if on destination is enough space - to hold command.com+ kernel.sys */ - - UNREFERENCED_PARAMETER(drive); - UNREFERENCED_PARAMETER(BlkBuffer); - + /* this should check, if on destination is enough space + to hold command.com+ kernel.sys */ + + UNREFERENCED_PARAMETER(drive); + UNREFERENCED_PARAMETER(BlkBuffer); return TRUE; } @@ -602,13 +603,13 @@ BOOL copy(COUNT drive, BYTE * srcPath, BYTE * rootPath, BYTE * file) int fdin, fdout; ULONG copied = 0; struct stat fstatbuf; - + sprintf(dest, "%c:\\%s", 'A' + drive, file); sprintf(source, "%s%s", srcPath, file); if (stat(source, &fstatbuf)) { - printf( "%s: \"%s\" not found\n", pgm, source); + printf("%s: \"%s\" not found\n", pgm, source); if ((rootPath != NULL) && (*rootPath) /* && (errno == ENOENT) */ ) { @@ -616,38 +617,40 @@ BOOL copy(COUNT drive, BYTE * srcPath, BYTE * rootPath, BYTE * file) printf("%s: Trying \"%s\"\n", pgm, source); if (stat(source, &fstatbuf)) { - printf( "%s: \"%s\" not found\n", pgm, source); + printf("%s: \"%s\" not found\n", pgm, source); return FALSE; } } else return FALSE; } - - if ((fdin = open(source, O_RDONLY|O_BINARY)) < 0) + + if ((fdin = open(source, O_RDONLY | O_BINARY)) < 0) { - printf( "%s: failed to open \"%s\"\n", pgm, source); + printf("%s: failed to open \"%s\"\n", pgm, source); return FALSE; } - if ((fdout = open(dest, O_RDWR | O_TRUNC | O_CREAT | O_BINARY,S_IREAD|S_IWRITE)) < 0) + if ((fdout = + open(dest, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, + S_IREAD | S_IWRITE)) < 0) { - printf( " %s: can't create\"%s\"\nDOS errnum %d", pgm, dest, errno); + printf(" %s: can't create\"%s\"\nDOS errnum %d", pgm, dest, errno); close(fdin); return FALSE; } - while ((ret = read(fdin, copybuffer,COPY_SIZE)) > 0) + while ((ret = read(fdin, copybuffer, COPY_SIZE)) > 0) + { + if (write(fdout, copybuffer, ret) != ret) { - if (write(fdout, copybuffer, ret) != ret) - { - printf("Can't write %u bytes to %s\n", ret, dest); - close(fdout); - unlink(dest); - break; - } - copied += ret; - } + printf("Can't write %u bytes to %s\n", ret, dest); + close(fdout); + unlink(dest); + break; + } + copied += ret; + } #ifdef __TURBOC__ { @@ -655,24 +658,23 @@ BOOL copy(COUNT drive, BYTE * srcPath, BYTE * rootPath, BYTE * file) getftime(fdin, &ftime); setftime(fdout, &ftime); } -#endif +#endif close(fdin); close(fdout); - + #ifdef _MSV_VER { - #include - struct utimbuf utimb; +#include + struct utimbuf utimb; - utimb.actime = /* access time */ - utimb.modtime = fstatbuf.st_mtime; /* modification time */ - utime(dest,&utimb); + utimb.actime = /* access time */ + utimb.modtime = fstatbuf.st_mtime; /* modification time */ + utime(dest, &utimb); }; #endif - printf("%lu Bytes transferred", copied); return TRUE; @@ -755,4 +757,3 @@ BOOL copy(COUNT drive, BYTE * srcPath, BYTE * rootPath, BYTE * file) * it create a .COM file. * */ - diff --git a/utils/patchobj.c b/utils/patchobj.c index 478f571..92eeee8 100644 --- a/utils/patchobj.c +++ b/utils/patchobj.c @@ -16,200 +16,188 @@ #include #include -#ifndef TRUE - #define TRUE (1==1) - #define FALSE (0==1) -#endif - +#ifndef TRUE +#define TRUE (1==1) +#define FALSE (0==1) +#endif struct { - char *sin,*sout; - } repl[100]; + char *sin, *sout; +} repl[100]; int repl_count; - -void quit(char *s,...) +void quit(char *s, ...) { - vprintf(s,(void*)((char *)&s+sizeof(s))); - exit(1); + vprintf(s, (void *)((char *)&s + sizeof(s))); + exit(1); } void define_replace(char *sin) { - char *s; - - if (repl_count >= 99) - quit("too many replacements"); - - if ((s = strchr(sin, '=')) == NULL) - quit("illegal replacement <%s>, missing '='", sin); + char *s; - *s = 0; - repl[repl_count].sin = sin; - repl[repl_count].sout = s+1; - - repl_count++; + if (repl_count >= 99) + quit("too many replacements"); + + if ((s = strchr(sin, '=')) == NULL) + quit("illegal replacement <%s>, missing '='", sin); + + *s = 0; + repl[repl_count].sin = sin; + repl[repl_count].sout = s + 1; + + repl_count++; } int main(int argc, char *argv[]) { - char *argptr; - int argloop; - int cont; - int file = 0; - FILE *fd,*fdo; - char *inname=0,*outname= "~patchob.tmp"; + char *argptr; + int argloop; + int cont; + int file = 0; + FILE *fd, *fdo; + char *inname = 0, *outname = "~patchob.tmp"; - int use_temp_file = TRUE; + int use_temp_file = TRUE; - argc--,argv++; + argc--, argv++; - for (; argc != 0; argc--,argv++) - { - argptr = *argv; - - if (*argptr != '-' && *argptr != '-') - { - if (inname == 0) { inname = argptr; continue;} - define_replace(argptr); - continue; - } - switch (toupper(argptr[1])) - { - case 'O': - outname = argptr+2; - use_temp_file = FALSE; - break; - default: - quit("illegal argument <%s>\n",argptr); - break; - } - } + for (; argc != 0; argc--, argv++) + { + argptr = *argv; - + if (*argptr != '-' && *argptr != '-') + { + if (inname == 0) + { + inname = argptr; + continue; + } + define_replace(argptr); + continue; + } + switch (toupper(argptr[1])) + { + case 'O': + outname = argptr + 2; + use_temp_file = FALSE; + break; + default: + quit("illegal argument <%s>\n", argptr); + break; + } + } - if (inname == 0) - quit("Inputfile must be specified\n"); + if (inname == 0) + quit("Inputfile must be specified\n"); - if (repl_count == 0) - quit("no replacements defined"); + if (repl_count == 0) + quit("no replacements defined"); + if ((fd = fopen(inname, "rb")) == NULL) /* open for READ/WRITE */ + quit("can't read %s\n", inname); - if ((fd = fopen(inname,"rb")) == NULL) /* open for READ/WRITE */ - quit("can't read %s\n",inname); + if ((fdo = fopen(outname, "wb")) == NULL) /* open for READ/WRITE */ + quit("can't write %s\n", outname); - if ((fdo = fopen(outname,"wb")) == NULL) /* open for READ/WRITE */ - quit("can't write %s\n",outname); + go_records(fd, fdo); - go_records(fd,fdo); + fclose(fd); + fclose(fdo); + if (use_temp_file) + { + unlink(inname); + rename(outname, inname); + } - fclose(fd); - fclose(fdo); - if (use_temp_file) - { - unlink(inname); - rename(outname,inname); - } - - return 0; + return 0; } usage() { - fputs( - "DELSYM V1.0 5'95by tom ehlert, SIG Aachen\n" - " delete symbolic info in object files\n" - "usage:\n" - " DELSYM infile [outfile]\n" - ,stderr); - exit(1); + fputs("DELSYM V1.0 5'95by tom ehlert, SIG Aachen\n" + " delete symbolic info in object files\n" + "usage:\n" " DELSYM infile [outfile]\n", stderr); + exit(1); } -struct record - { - unsigned char rectyp; - unsigned datalen; - unsigned char buffer[0x2000]; - } Record,Outrecord; +struct record { + unsigned char rectyp; + unsigned datalen; + unsigned char buffer[0x2000]; +} Record, Outrecord; +go_records(FILE * fdin, FILE * fdo) +{ + unsigned char stringlen; + unsigned char *string, *s; + int i, j; + unsigned char chksum; -go_records(FILE *fdin,FILE *fdo) -{ - unsigned char stringlen; - unsigned char *string,*s; - int i,j; - unsigned char chksum; + do + { + if (fread(&Record, 1, 3, fdin) != 3) + { /* read type and reclen */ + /* printf("end of fdin read\n"); */ + break; + } + if (Record.datalen > sizeof(Record.buffer)) + quit("record to large : length %u Bytes \n", Record.datalen); -do { - if (fread(&Record,1,3,fdin) != 3) { /* read type and reclen*/ - /* printf("end of fdin read\n"); */ - break; - } - if (Record.datalen > sizeof(Record.buffer)) - quit ("record to large : length %u Bytes \n",Record.datalen); + if (fread(Record.buffer, 1, Record.datalen, fdin) != Record.datalen) + { + printf("invalid record format\n"); + quit("can't continue\n"); + } - if (fread(Record.buffer,1,Record.datalen,fdin) != Record.datalen) - { - printf("invalid record format\n"); - quit ("can't continue\n"); - } + if (Record.rectyp != 0x96) /* we are only interested in LNAMES */ + { + fwrite(&Record, 1, 3 + Record.datalen, fdo); + continue; + } - - - if (Record.rectyp != 0x96) /* we are only interested in LNAMES */ - { - fwrite(&Record,1,3+Record.datalen,fdo); - continue; - } + Outrecord.rectyp = 0x96; + Outrecord.datalen = 0; - Outrecord.rectyp = 0x96; - Outrecord.datalen= 0; + for (i = 0; i < Record.datalen - 1;) + { + stringlen = Record.buffer[i]; + i++; + string = &Record.buffer[i]; + i += stringlen; - - + if (i > Record.datalen) + quit("invalid lnames record"); - - for (i = 0; i < Record.datalen-1; ) - { - stringlen = Record.buffer[i]; - i++; - - string = &Record.buffer[i]; - i += stringlen; - - - if (i > Record.datalen) - quit("invalid lnames record"); - - - for (j = 0; j < repl_count; j++) - if (memcmp(string,repl[j].sin,stringlen) == 0 - && strlen(repl[j].sin) == stringlen) - { - string = repl[j].sout; - stringlen = strlen(repl[j].sout); - } - Outrecord.buffer[Outrecord.datalen] = stringlen; - Outrecord.datalen++; - memcpy(Outrecord.buffer+Outrecord.datalen,string,stringlen); - Outrecord.datalen += stringlen; - } + for (j = 0; j < repl_count; j++) + if (memcmp(string, repl[j].sin, stringlen) == 0 + && strlen(repl[j].sin) == stringlen) + { + string = repl[j].sout; + stringlen = strlen(repl[j].sout); + } + Outrecord.buffer[Outrecord.datalen] = stringlen; + Outrecord.datalen++; + memcpy(Outrecord.buffer + Outrecord.datalen, string, stringlen); + Outrecord.datalen += stringlen; + } - chksum = 0; - for (s = (unsigned char *)&Outrecord; s < &Outrecord.buffer[Outrecord.datalen]; s++) - chksum += *s; - - Outrecord.buffer[Outrecord.datalen] = ~chksum; - Outrecord.datalen++; - - /* printf("^sum = %02x - %02x\n",chksum,~chksum); */ - - - fwrite(&Outrecord,1,3+Outrecord.datalen,fdo); - - } while (Record.rectyp != 0x00 /*ENDFIL*/); + chksum = 0; + for (s = (unsigned char *)&Outrecord; + s < &Outrecord.buffer[Outrecord.datalen]; s++) + chksum += *s; -printf("\n"); + Outrecord.buffer[Outrecord.datalen] = ~chksum; + Outrecord.datalen++; + + /* printf("^sum = %02x - %02x\n",chksum,~chksum); */ + + fwrite(&Outrecord, 1, 3 + Outrecord.datalen, fdo); + + } + while (Record.rectyp != 0x00 /*ENDFIL*/); + + printf("\n"); } diff --git a/utils/relocinf.c b/utils/relocinf.c index 1de577e..89d778f 100644 --- a/utils/relocinf.c +++ b/utils/relocinf.c @@ -18,23 +18,19 @@ ** *****************************************************************************/ - -*/ - +* / #include #include #include - typedef unsigned short UWORD; -typedef unsigned long ULONG; +typedef unsigned long ULONG; #ifndef _MSC_VER - #define const - #define __cdecl cdecl +#define const +#define __cdecl cdecl #endif /* from EXE.H */ -typedef struct -{ +typedef struct { UWORD exSignature; UWORD exExtraBytes; UWORD exPages; @@ -49,115 +45,118 @@ typedef struct UWORD exInitCS; UWORD exRelocTable; UWORD exOverlay; -} -exe_header; +} exe_header; #define MAGIC 0x5a4d -struct relocEntry{ - UWORD off; - UWORD seg; - UWORD refseg; - }; +struct relocEntry { + UWORD off; + UWORD seg; + UWORD refseg; +}; int __cdecl compReloc(const void *p1, const void *p2) - { - struct relocEntry *r1 = (struct relocEntry*)p1; - struct relocEntry *r2 = (struct relocEntry*)p2; - - if (r1->refseg > r2->refseg) return 1; - if (r1->refseg < r2->refseg) return -1; - - if (r1->seg > r2->seg) return 1; - if (r1->seg < r2->seg) return -1; - - if (r1->off > r2->off) return 1; - if (r1->off < r2->off) return -1; - - return 0; - } - - - -main(int argc,char *argv[]) { - FILE *fdin; - exe_header header; - struct relocEntry *reloc; + struct relocEntry *r1 = (struct relocEntry *)p1; + struct relocEntry *r2 = (struct relocEntry *)p2; - int i; - ULONG image_offset; - - - if (argc < 2 || (fdin = fopen(argv[1],"rb")) == NULL) - { - printf("can't open %s\n",argv[1]); - exit(1); - } + if (r1->refseg > r2->refseg) + return 1; + if (r1->refseg < r2->refseg) + return -1; - if (fread(&header, sizeof(header),1,fdin) != 1 || - header.exSignature != MAGIC) - { - printf("%s is no EXE file\n"); - exit(1); - } + if (r1->seg > r2->seg) + return 1; + if (r1->seg < r2->seg) + return -1; - printf("%u relocation entries found\n", header.exRelocItems); - - if (header.exRelocItems > 0x8000/sizeof(*reloc)) - { - printf("too many relocation entries \n"); - exit(1); - } + if (r1->off > r2->off) + return 1; + if (r1->off < r2->off) + return -1; - if ((reloc = malloc(header.exRelocItems*sizeof(*reloc))) == NULL) - { - printf("can't alloc memory\n"); - exit(1); - } - - if (fseek(fdin, header.exRelocTable, 0)) - { - printf("can't seek\n"); - exit(1); - } + return 0; +} - for (i = 0; i < header.exRelocItems; i++) - if (fread(reloc+i, 4,1,fdin) != 1) - { - printf("can't read reloc info\n"); - exit(1); - } +main(int argc, char *argv[]) +{ + FILE *fdin; + exe_header header; + struct relocEntry *reloc; - for (i = 0; i < header.exRelocItems; i++) - { - image_offset = (ULONG)header.exHeaderSize * 16; + int i; + ULONG image_offset; - image_offset += ((ULONG)reloc[i].seg << 4) + reloc[i].off; + if (argc < 2 || (fdin = fopen(argv[1], "rb")) == NULL) + { + printf("can't open %s\n", argv[1]); + exit(1); + } - if (fseek(fdin, image_offset, 0)) - { - printf("can't seek reloc data\n"); - exit(1); - } + if (fread(&header, sizeof(header), 1, fdin) != 1 || + header.exSignature != MAGIC) + { + printf("%s is no EXE file\n"); + exit(1); + } - if (fread(&reloc[i].refseg, 2,1,fdin) != 1) - { - printf("can't read rel data for item %d\n",i); - exit(1); - } - /* printf("%04x:%04x -> %04x\n", reloc[i].seg, reloc[i].off, reloc[i].refseg); */ - } + printf("%u relocation entries found\n", header.exRelocItems); - /* sort reloc entries */ + if (header.exRelocItems > 0x8000 / sizeof(*reloc)) + { + printf("too many relocation entries \n"); + exit(1); + } - qsort(reloc, header.exRelocItems, sizeof(*reloc), compReloc); + if ((reloc = malloc(header.exRelocItems * sizeof(*reloc))) == NULL) + { + printf("can't alloc memory\n"); + exit(1); + } - for (i = 0; i < header.exRelocItems; i++) - { - if (i == 0) - printf("# seg:off references data in -->\n"); - printf("%3d %04x:%04x -> %04x\n", i,reloc[i].seg, reloc[i].off, reloc[i].refseg); - } - -} \ No newline at end of file + if (fseek(fdin, header.exRelocTable, 0)) + { + printf("can't seek\n"); + exit(1); + } + + for (i = 0; i < header.exRelocItems; i++) + if (fread(reloc + i, 4, 1, fdin) != 1) + { + printf("can't read reloc info\n"); + exit(1); + } + + for (i = 0; i < header.exRelocItems; i++) + { + image_offset = (ULONG) header.exHeaderSize * 16; + + image_offset += ((ULONG) reloc[i].seg << 4) + reloc[i].off; + + if (fseek(fdin, image_offset, 0)) + { + printf("can't seek reloc data\n"); + exit(1); + } + + if (fread(&reloc[i].refseg, 2, 1, fdin) != 1) + { + printf("can't read rel data for item %d\n", i); + exit(1); + } + /* printf("%04x:%04x -> %04x\n", reloc[i].seg, reloc[i].off, reloc[i].refseg); */ + } + + /* sort reloc entries */ + + qsort(reloc, header.exRelocItems, sizeof(*reloc), compReloc); + + for (i = 0; i < header.exRelocItems; i++) + { + if (i == 0) + printf("# seg:off references data in -->\n"); + printf("%3d %04x:%04x -> %04x\n", i, reloc[i].seg, reloc[i].off, + reloc[i].refseg); + } + +}