From 77e49f87c763016be34cb436337ddbae90bb7585 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Mon, 23 Jul 2001 12:47:42 +0000 Subject: [PATCH] FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@267 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/chario.c | 10 +- kernel/dosfns.c | 320 ++++++++++++++++++------------------- kernel/fatdir.c | 41 ++--- kernel/fcbfns.c | 394 +++++++++++++++------------------------------- kernel/initdisk.c | 7 +- kernel/inthndlr.c | 5 +- kernel/proto.h | 17 +- kernel/task.c | 116 +++++++------- 8 files changed, 402 insertions(+), 508 deletions(-) diff --git a/kernel/chario.c b/kernel/chario.c index ffbc3b6..337a271 100644 --- a/kernel/chario.c +++ b/kernel/chario.c @@ -36,6 +36,9 @@ static BYTE *charioRcsId = "$Id$"; /* * $Log$ + * Revision 1.10 2001/07/23 12:47:42 bartoldeman + * FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf + * * Revision 1.9 2001/06/03 14:16:17 bartoldeman * BUFFERS tuning and misc bug fixes/cleanups (2024c). * @@ -185,9 +188,7 @@ VOID cso(COUNT c) VOID sto(COUNT c) { - static COUNT scratch; /* make this static to save stack space */ - - DosWrite(STDOUT, 1, (BYTE FAR *) & c, (COUNT FAR *) &scratch); + DosWrite(STDOUT, 1, (BYTE FAR *) & c, (COUNT FAR *) &UnusedRetVal); } VOID mod_sto(REG UCOUNT c) @@ -224,13 +225,12 @@ VOID Do_DosIdle_loop(void) UCOUNT _sti(void) { - static COUNT scratch; UBYTE c; /* * XXX: If there's a read error, this will just keep retrying the read until * the error disappears. Maybe it should do something else instead. -- ror4 */ - while (GenericRead(STDIN, 1, (BYTE FAR *) & c, (COUNT FAR *) & scratch, TRUE) + while (GenericRead(STDIN, 1, (BYTE FAR *) & c, (COUNT FAR *) & UnusedRetVal, TRUE) != 1) ; return c; } diff --git a/kernel/dosfns.c b/kernel/dosfns.c index f1c1bbe..4e522e4 100644 --- a/kernel/dosfns.c +++ b/kernel/dosfns.c @@ -37,6 +37,9 @@ static BYTE *dosfnsRcsId = "$Id$"; * /// Added SHARE support. 2000/09/04 Ron Cemer * * $Log$ + * Revision 1.21 2001/07/23 12:47:42 bartoldeman + * FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf + * * Revision 1.20 2001/07/22 01:58:58 bartoldeman * Support for Brian's FORMAT, DJGPP libc compilation, cleanups, MSCDEX * @@ -182,9 +185,8 @@ static BYTE *dosfnsRcsId = "$Id$"; #include "globals.h" -sft FAR *get_sft(UCOUNT); -WORD get_free_hndl(VOID); -sft FAR *get_free_sft(WORD FAR *); +COUNT get_free_hndl(VOID); +sft FAR *get_free_sft(COUNT *); BOOL cmatch(COUNT, COUNT, COUNT); f_node_ptr xlt_fd(COUNT); @@ -257,34 +259,41 @@ static VOID DosGetFile(BYTE * lpszPath, BYTE FAR * lpszDosFileName) fbcopy((BYTE FAR *) szLclExt, &lpszDosFileName[FNAME_SIZE], FEXT_SIZE); } -sft FAR *get_sft(UCOUNT hndl) +sft FAR *idx_to_sft(COUNT SftIndex) { - psp FAR *p = MK_FP(cu_psp, 0); - WORD sys_idx; sfttbl FAR *sp; - if (hndl >= p->ps_maxfiles) + if (SftIndex < 0) return (sft FAR *) - 1; /* Get the SFT block that contains the SFT */ - if (p->ps_filetab[hndl] == 0xff) - return (sft FAR *) - 1; - - sys_idx = p->ps_filetab[hndl]; - for (sp = sfthead; sp != (sfttbl FAR *) - 1; sp = sp->sftt_next) + for (sp = sfthead; sp != (sfttbl FAR *) - 1; + sp = sp->sftt_next) { - if (sys_idx < sp->sftt_count) - break; + if (SftIndex < sp->sftt_count) + /* finally, point to the right entry */ + return (sft FAR *) & (sp->sftt_table[SftIndex]); else - sys_idx -= sp->sftt_count; + SftIndex -= sp->sftt_count; } - /* If not found, return an error */ - if (sp == (sfttbl FAR *) - 1) - return (sft FAR *) - 1; + return (sft FAR *) - 1; +} - /* finally, point to the right entry */ - return (sft FAR *) & (sp->sftt_table[sys_idx]); +STATIC COUNT get_sft_idx(UCOUNT hndl) +{ + psp FAR *p = MK_FP(cu_psp, 0); + + if (hndl >= p->ps_maxfiles) + return DE_INVLDHNDL; + + return p->ps_filetab[hndl] == 0xff ? DE_INVLDHNDL : p->ps_filetab[hndl]; +} + +sft FAR *get_sft(UCOUNT hndl) +{ + /* Get the SFT block that contains the SFT */ + return idx_to_sft(get_sft_idx(hndl)); } /* @@ -298,17 +307,8 @@ UCOUNT GenericRead(COUNT hndl, UCOUNT n, BYTE FAR * bp, COUNT FAR * err, BOOL force_binary) { sft FAR *s; -/* WORD sys_idx;*/ -/*sfttbl FAR *sp;*/ UCOUNT ReadCount; - /* Test that the handle is valid */ - if (hndl < 0) - { - *err = DE_INVLDHNDL; - return 0; - } - /* Get the SFT block that contains the SFT */ if ((s = get_sft(hndl)) == (sft FAR *) - 1) { @@ -436,17 +436,8 @@ UCOUNT DosRead(COUNT hndl, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) UCOUNT DosWrite(COUNT hndl, UCOUNT n, BYTE FAR * bp, COUNT FAR * err) { sft FAR *s; -/* WORD sys_idx;*/ -/*sfttbl FAR *sp;*/ UCOUNT WriteCount; - /* Test that the handle is valid */ - if (hndl < 0) - { - *err = DE_INVLDHNDL; - return 0; - } - /* Get the SFT block that contains the SFT */ if ((s = get_sft(hndl)) == (sft FAR *) - 1) { @@ -685,10 +676,6 @@ COUNT DosSeek(COUNT hndl, LONG new_pos, COUNT mode, ULONG * set_pos) sft FAR *s; COUNT result; - /* Test that the handle is valid */ - if (hndl < 0) - return DE_INVLDHNDL; - /* Get the SFT block that contains the SFT */ if ((s = get_sft(hndl)) == (sft FAR *) - 1) return DE_INVLDHNDL; @@ -700,7 +687,7 @@ COUNT DosSeek(COUNT hndl, LONG new_pos, COUNT mode, ULONG * set_pos) return result; } -STATIC WORD get_free_hndl(void) +STATIC COUNT get_free_hndl(void) { psp FAR *p = MK_FP(cu_psp, 0); WORD hndl; @@ -710,12 +697,12 @@ STATIC WORD get_free_hndl(void) if (p->ps_filetab[hndl] == 0xff) return hndl; } - return 0xff; + return DE_TOOMANY; } -sft FAR *get_free_sft(WORD FAR * sft_idx) +sft FAR *get_free_sft(COUNT *sft_idx) { - WORD sys_idx = 0; + COUNT sys_idx = 0; sfttbl FAR *sp; /* Get the SFT block that contains the SFT */ @@ -773,15 +760,13 @@ BOOL fnmatch(BYTE FAR * s, BYTE FAR * d, COUNT n, COUNT mode) return TRUE; } -COUNT DosCreat(BYTE FAR * fname, COUNT attrib) +COUNT DosCreatSft(BYTE * fname, COUNT attrib) { - psp FAR *p = MK_FP(cu_psp, 0); - WORD hndl, sft_idx; + COUNT sft_idx; sft FAR *sftp; struct dhdr FAR *dhp; -/* BYTE FAR *froot;*/ -/* WORD i;*/ - COUNT result, drive; + WORD result; + COUNT drive; /* NEVER EVER allow directories to be created */ if (attrib & ~(D_RDONLY|D_HIDDEN|D_SYSTEM|D_ARCHIVE)) @@ -789,30 +774,28 @@ COUNT DosCreat(BYTE FAR * fname, COUNT attrib) return DE_ACCESS; } - /* get a free handle */ - if ((hndl = get_free_hndl()) == 0xff) + /* now get a free system file table entry */ + if ((sftp = get_free_sft(&sft_idx)) == (sft FAR *) - 1) return DE_TOOMANY; - /* now get a free system file table entry */ - if ((sftp = get_free_sft((WORD FAR *) & sft_idx)) == (sft FAR *) - 1) - return DE_TOOMANY; + fmemset(sftp, 0, sizeof(sft)); 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_mode = SFT_MRDWR; - sftp->sft_attrib = attrib; sftp->sft_flags = ((dhp->dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF; - sftp->sft_psp = cu_psp; fbcopy((BYTE FAR *) SecPathName, sftp->sft_name, FNAME_SIZE + FEXT_SIZE); sftp->sft_dev = dhp; - p->ps_filetab[hndl] = sft_idx; - return hndl; + return sft_idx; } drive = get_verify_drive(fname); @@ -820,27 +803,21 @@ COUNT DosCreat(BYTE FAR * fname, COUNT attrib) return drive; } - result = truename(fname, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } - if (CDSp->cds_table[drive].cdsFlags & CDSNETWDRV) { lpCurSft = (sfttbl FAR *)sftp; sftp->sft_mode = attrib; result = -int2f_Remote_call(REM_CREATE, 0, 0, 0, (VOID FAR *) sftp, 0, MK_FP(0, attrib)); - if (result == SUCCESS) { - sftp->sft_count += 1; - p->ps_filetab[hndl] = sft_idx; - return hndl; - } + if (result == SUCCESS) { + sftp->sft_count += 1; + return sft_idx; + } return result; } /* /// Added for SHARE. - Ron Cemer */ if (IsShareInstalled()) { if ((sftp->sft_shroff = share_open_check - ((char far *)PriPathName, + ((char far *)fname, cu_psp, 0x02, /* read-write */ 0)) < 0) /* compatibility mode */ @@ -848,17 +825,13 @@ COUNT DosCreat(BYTE FAR * fname, COUNT attrib) } /* /// End of additions for SHARE. - Ron Cemer */ - sftp->sft_status = dos_creat(PriPathName, attrib); + sftp->sft_status = dos_creat(fname, attrib); if (sftp->sft_status >= 0) { - p->ps_filetab[hndl] = sft_idx; sftp->sft_count += 1; - sftp->sft_mode = SFT_MRDWR; - sftp->sft_attrib = attrib; sftp->sft_flags = drive; - sftp->sft_psp = cu_psp; - DosGetFile(PriPathName, sftp->sft_name); - return hndl; + DosGetFile(fname, sftp->sft_name); + return sft_idx; } else { /* /// Added for SHARE *** CURLY BRACES ADDED ALSO!!! ***. - Ron Cemer */ if (IsShareInstalled()) { @@ -870,6 +843,29 @@ COUNT DosCreat(BYTE FAR * fname, COUNT attrib) } } +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) { + return result; + } + + sft_idx = DosCreatSft(PriPathName, attrib); + + if (sft_idx < SUCCESS) + return sft_idx; + + p->ps_filetab[hndl] = sft_idx; + return hndl; +} + COUNT CloneHandle(COUNT hndl) { sft FAR *sftp; @@ -900,8 +896,8 @@ COUNT DosDup(COUNT Handle) return DE_INVLDHNDL; /* now get a free handle */ - if ((NewHandle = get_free_hndl()) == 0xff) - return DE_TOOMANY; + if ((NewHandle = get_free_hndl()) < 0) + return NewHandle; /* If everything looks ok, bump it up. */ if ((Sftp->sft_flags & (SFT_FDEVICE | SFT_FSHARED)) || (Sftp->sft_status >= 0)) @@ -948,40 +944,30 @@ COUNT DosForceDup(COUNT OldHandle, COUNT NewHandle) return DE_INVLDHNDL; } -COUNT DosOpen(BYTE FAR * fname, COUNT mode) +COUNT DosOpenSft(BYTE * fname, COUNT mode) { - psp FAR *p = MK_FP(cu_psp, 0); - WORD hndl; - WORD sft_idx; + COUNT sft_idx; sft FAR *sftp; struct dhdr FAR *dhp; COUNT drive, result; -/* /// Added to adjust for filenames which begin with ".\" - The problem was manifesting itself in the inability - to run an program whose filename (without the extension) - was longer than six characters and the PATH variable - contained ".", unless you explicitly specified the full - path to the executable file. - Jun 11, 2000 - rbc */ - if ( (fname[0] == '.') && ((fname[1] == '\\') || (fname[1] == '/'))) fname += 2; + OpenMode = (BYTE) mode; /* test if mode is in range */ if ((mode & ~SFT_OMASK) != 0) return DE_INVLDACC; mode &= 3; - /* get a free handle */ - if ((hndl = get_free_hndl()) == 0xff) - return DE_TOOMANY; OpenMode = (BYTE) mode; /* now get a free system file table entry */ - if ((sftp = get_free_sft((WORD FAR *) & sft_idx)) == (sft FAR *) - 1) + if ((sftp = get_free_sft(&sft_idx)) == (sft FAR *) - 1) return DE_TOOMANY; fmemset(sftp, 0, sizeof(sft)); + sftp->sft_psp = cu_psp; + sftp->sft_mode = mode; /* check for a device */ dhp = IsDevice(fname); @@ -989,18 +975,15 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode) { sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ - sftp->sft_mode = mode; sftp->sft_count += 1; sftp->sft_flags = ((dhp->dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF; - sftp->sft_psp = cu_psp; fbcopy((BYTE FAR *) SecPathName, sftp->sft_name, FNAME_SIZE + FEXT_SIZE); sftp->sft_dev = dhp; sftp->sft_date = dos_getdate(); sftp->sft_time = dos_gettime(); - p->ps_filetab[hndl] = sft_idx; - return hndl; + return sft_idx; } drive = get_verify_drive(fname); @@ -1008,29 +991,21 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode) return drive; } - result = truename(fname, PriPathName, FALSE); - if (result != SUCCESS) { - return result; - } - if (CDSp->cds_table[drive].cdsFlags & CDSNETWDRV) { lpCurSft = (sfttbl FAR *)sftp; result = -int2f_Remote_call(REM_OPEN, 0, 0, 0, (VOID FAR *) sftp, 0, MK_FP(0, mode)); if (result == SUCCESS) { sftp->sft_count += 1; - p->ps_filetab[hndl] = sft_idx; - return hndl; + return sft_idx; } return result; } sftp->sft_shroff = -1; /* /// Added for SHARE - Ron Cemer */ - sftp->sft_mode = mode; - -/* /// Added for SHARE. - Ron Cemer */ + /* /// Added for SHARE. - Ron Cemer */ if (IsShareInstalled()) { if ((sftp->sft_shroff = share_open_check - ((char far *)PriPathName, + ((char far *)fname, (unsigned short)cu_psp, mode & 0x03, (mode >> 2) & 0x07)) < 0) @@ -1038,7 +1013,7 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode) } /* /// End of additions for SHARE. - Ron Cemer */ - sftp->sft_status = dos_open(PriPathName, mode); + sftp->sft_status = dos_open(fname, mode); if (sftp->sft_status >= 0) { @@ -1052,14 +1027,16 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode) { return DE_ACCESS; } - p->ps_filetab[hndl] = sft_idx; + sftp->sft_size = dos_getfsize(sftp->sft_status); + dos_getftime(sftp->sft_status, + (date FAR *) & sftp->sft_date, + (time FAR *) & sftp->sft_time); sftp->sft_count += 1; sftp->sft_mode = mode; sftp->sft_flags = drive; - sftp->sft_psp = cu_psp; - DosGetFile(PriPathName, sftp->sft_name); - return hndl; + DosGetFile(fname, sftp->sft_name); + return sft_idx; } else { /* /// Added for SHARE *** CURLY BRACES ADDED ALSO!!! ***. - Ron Cemer */ if (IsShareInstalled()) { @@ -1071,33 +1048,47 @@ COUNT DosOpen(BYTE FAR * fname, COUNT mode) } } -COUNT DosClose(COUNT hndl) +COUNT DosOpen(BYTE FAR * fname, COUNT mode) { psp FAR *p = MK_FP(cu_psp, 0); - sft FAR *s; + COUNT sft_idx, result, hndl; - /* Test that the handle is valid */ - if (hndl < 0) - return DE_INVLDHNDL; + /* get a free handle */ + if ((hndl = get_free_hndl()) < 0) + return hndl; - /* Get the SFT block that contains the SFT */ - if ((s = get_sft(hndl)) == (sft FAR *) - 1) + result = truename(fname, PriPathName, FALSE); + if (result != SUCCESS) { + return result; + } + + sft_idx = DosOpenSft(PriPathName, mode); + + if (sft_idx < SUCCESS) + return sft_idx; + + p->ps_filetab[hndl] = sft_idx; + return hndl; +} + +COUNT DosCloseSft(WORD sft_idx) +{ + sft FAR *s = idx_to_sft(sft_idx); + + if (s == (sft FAR *) - 1) return DE_INVLDHNDL; /* If this is not opened another error */ - if (s->sft_count == 0) + /* The second condition is a sanity check and necessary for FcbCloseAll */ + if (s->sft_count == 0 || (s->sft_count == 1 && s->sft_psp != cu_psp)) return DE_ACCESS; lpCurSft = (sfttbl FAR *) s; /* remote sub sft_count. */ - p->ps_filetab[hndl] = 0xff; if (s->sft_flags & SFT_FSHARED) - { - int2f_Remote_call(REM_CLOSE, 0, 0, 0, (VOID FAR *) s, 0, 0); - return SUCCESS; - } + return -int2f_Remote_call(REM_CLOSE, 0, 0, 0, (VOID FAR *) s, 0, 0); /* now just drop the count if a device, else */ /* call file system handler */ @@ -1120,6 +1111,18 @@ COUNT DosClose(COUNT hndl) } } +COUNT DosClose(COUNT hndl) +{ + psp FAR *p = MK_FP(cu_psp, 0); + COUNT ret; + + /* Get the SFT block that contains the SFT */ + ret = DosCloseSft(get_sft_idx(hndl)); + if (ret != DE_INVLDHNDL && ret != DE_ACCESS) + p->ps_filetab[hndl] = 0xff; + return ret; +} + VOID DosGetFree(UBYTE drive, COUNT FAR * spc, COUNT FAR * navc, COUNT FAR * bps, COUNT FAR * nc) { struct dpb FAR *dpbp; @@ -1332,10 +1335,6 @@ COUNT DosGetFtime(COUNT hndl, date FAR * dp, time FAR * tp) sft FAR *s; /*sfttbl FAR *sp;*/ - /* Test that the handle is valid */ - if (hndl < 0) - return DE_INVLDHNDL; - /* Get the SFT block that contains the SFT */ if ((s = get_sft(hndl)) == (sft FAR *) - 1) return DE_INVLDHNDL; @@ -1356,17 +1355,12 @@ COUNT DosGetFtime(COUNT hndl, date FAR * dp, time FAR * tp) return dos_getftime(s->sft_status, dp, tp); } -COUNT DosSetFtime(COUNT hndl, date FAR * dp, time FAR * tp) +COUNT DosSetFtimeSft(WORD sft_idx, date FAR * dp, time FAR * tp) { - sft FAR *s; -/*sfttbl FAR *sp;*/ - - /* Test that the handle is valid */ - if (hndl < 0) - return DE_INVLDHNDL; - /* Get the SFT block that contains the SFT */ - if ((s = get_sft(hndl)) == (sft FAR *) - 1) + sft FAR *s = idx_to_sft(sft_idx); + + if (s == (sft FAR *) - 1) return DE_INVLDHNDL; /* If this is not opened another error */ @@ -1544,33 +1538,42 @@ COUNT DosDelete(BYTE FAR *path) } } -COUNT DosRename(BYTE FAR * path1, BYTE FAR * path2) +COUNT DosRenameTrue(BYTE * path1, BYTE * path2) { - COUNT result, drive1, drive2; + COUNT drive1, drive2; 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 (CDSp->cds_table[drive1].cdsFlags & CDSNETWDRV) { + return -int2f_Remote_call(REM_RENAME, 0, 0, 0, 0, 0, 0); + } else { + return dos_rename(PriPathName, SecPathName); + } +} + +COUNT DosRename(BYTE FAR * path1, BYTE FAR * path2) +{ + COUNT result; + result = truename(path1, PriPathName, FALSE); if (result != SUCCESS) { return result; } - drive2 = get_verify_drive(path2); + result = truename(path2, SecPathName, FALSE); if (result != SUCCESS) { return result; } - if ((drive1 != drive2) || (drive1 < 0)) { - return DE_INVLDDRV; - } - current_ldt = &CDSp->cds_table[drive1]; - if (CDSp->cds_table[drive1].cdsFlags & CDSNETWDRV) { - return -int2f_Remote_call(REM_RENAME, 0, 0, 0, 0, 0, 0); - } else { - return dos_rename(PriPathName, SecPathName); - } + + return DosRenameTrue(PriPathName, SecPathName); } COUNT DosMkdir(BYTE FAR * dir) @@ -1630,9 +1633,6 @@ COUNT DosLockUnlock(COUNT hndl, LONG pos, LONG len, COUNT unlock) /* Invalid function unless SHARE is installed. */ if (!IsShareInstalled()) return DE_INVLDFUNC; - /* Test that the handle is valid */ - if (hndl < 0) return DE_INVLDHNDL; - /* Get the SFT block that contains the SFT */ if ((s = get_sft(hndl)) == (sft FAR *) -1) return DE_INVLDHNDL; diff --git a/kernel/fatdir.c b/kernel/fatdir.c index 48ff914..5c13261 100644 --- a/kernel/fatdir.c +++ b/kernel/fatdir.c @@ -36,6 +36,9 @@ static BYTE *fatdirRcsId = "$Id$"; /* * $Log$ + * Revision 1.19 2001/07/23 12:47:42 bartoldeman + * FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf + * * Revision 1.18 2001/07/22 01:58:58 bartoldeman * Support for Brian's FORMAT, DJGPP libc compilation, cleanups, MSCDEX * @@ -358,6 +361,7 @@ COUNT dir_read(REG f_node_ptr fnp) /* REG j; */ struct buffer FAR *bp; + REG UWORD secsize = fnp->f_dpb->dpb_secsize; /* Directories need to point to their current offset, not for */ /* next op. Therefore, if it is anything other than the first */ @@ -382,7 +386,7 @@ COUNT dir_read(REG f_node_ptr fnp) { if (fnp->f_flags.f_droot) { - if ((fnp->f_diroff / fnp->f_dpb->dpb_secsize + if ((fnp->f_diroff / secsize + fnp->f_dpb->dpb_dirstrt) >= fnp->f_dpb->dpb_data) { @@ -390,18 +394,15 @@ COUNT dir_read(REG f_node_ptr fnp) return 0; } - bp = getblock((ULONG) (fnp->f_diroff / fnp->f_dpb->dpb_secsize + bp = getblock((ULONG) (fnp->f_diroff / secsize + fnp->f_dpb->dpb_dirstrt), fnp->f_dpb->dpb_unit); - bp->b_flag &= ~(BFR_DATA | BFR_FAT); - bp->b_flag |= BFR_DIR | BFR_VALID; #ifdef DISPLAY_GETBLOCK printf("DIR (dir_read)\n"); #endif } else { - REG UWORD secsize = fnp->f_dpb->dpb_secsize; /* Do a "seek" to the directory position */ fnp->f_offset = fnp->f_diroff; @@ -444,8 +445,6 @@ COUNT dir_read(REG f_node_ptr fnp) fnp->f_dpb->dpb_data) + fnp->f_sector, fnp->f_dpb->dpb_unit); - bp->b_flag &= ~(BFR_DATA | BFR_FAT); - bp->b_flag |= BFR_DIR | BFR_VALID; #ifdef DISPLAY_GETBLOCK printf("DIR (dir_read)\n"); #endif @@ -453,15 +452,18 @@ COUNT dir_read(REG f_node_ptr fnp) /* Now that we have the block for our entry, get the */ /* directory entry. */ - if (bp != NULL) - getdirent((BYTE FAR *) & bp->b_buffer[((UWORD)fnp->f_diroff) % fnp->f_dpb->dpb_secsize], - (struct dirent FAR *)&fnp->f_dir); - else + if (bp == NULL) { fnp->f_flags.f_dfull = TRUE; return 0; } + bp->b_flag &= ~(BFR_DATA | BFR_FAT); + bp->b_flag |= BFR_DIR | BFR_VALID; + + getdirent((BYTE FAR *) & bp->b_buffer[((UWORD)fnp->f_diroff) % fnp->f_dpb->dpb_secsize], + (struct dirent FAR *)&fnp->f_dir); + /* Update the fnode's directory info */ fnp->f_flags.f_dfull = FALSE; fnp->f_flags.f_dmod = FALSE; @@ -479,6 +481,7 @@ COUNT dir_read(REG f_node_ptr fnp) COUNT dir_write(REG f_node_ptr fnp) { struct buffer FAR *bp; + REG UWORD secsize = fnp->f_dpb->dpb_secsize; /* Update the entry if it was modified by a write or create... */ if (fnp->f_flags.f_dmod) @@ -488,11 +491,9 @@ COUNT dir_write(REG f_node_ptr fnp) if (fnp->f_flags.f_droot) { bp = getblock( - (ULONG) ((UWORD)fnp->f_diroff / fnp->f_dpb->dpb_secsize + (ULONG) ((UWORD)fnp->f_diroff / secsize + fnp->f_dpb->dpb_dirstrt), fnp->f_dpb->dpb_unit); - bp->b_flag &= ~(BFR_DATA | BFR_FAT); - bp->b_flag |= BFR_DIR | BFR_VALID; #ifdef DISPLAY_GETBLOCK printf("DIR (dir_write)\n"); #endif @@ -503,7 +504,6 @@ COUNT dir_write(REG f_node_ptr fnp) /* can continually update the same directory entry. */ else { - REG UWORD secsize = fnp->f_dpb->dpb_secsize; /* Do a "seek" to the directory position */ /* and convert the fnode to a directory fnode. */ @@ -558,8 +558,10 @@ COUNT dir_write(REG f_node_ptr fnp) return 0; } putdirent((struct dirent FAR *)&fnp->f_dir, - (VOID FAR *) & bp->b_buffer[(UWORD)fnp->f_diroff % fnp->f_dpb->dpb_secsize]); - bp->b_flag |= BFR_DIRTY | BFR_VALID; + (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; } return DIRENT_SIZE; } @@ -801,16 +803,19 @@ COUNT dos_findnext(void) /* If found, transfer it to the dmatch structure */ if (found) { +#if 0 extern VOID FAR *FcbFindFirstDirPtr; - if (FcbFindFirstDirPtr) { /* this works MUCH better, then converting 83 -> ASCIIZ ->83; specifically ".", ".." + + But completely bypasses the network case! */ fmemcpy(FcbFindFirstDirPtr, &fnp->f_dir, 32); } +#endif pop_dmp(dmp, fnp); } diff --git a/kernel/fcbfns.c b/kernel/fcbfns.c index 858e82d..b510188 100644 --- a/kernel/fcbfns.c +++ b/kernel/fcbfns.c @@ -35,6 +35,9 @@ static BYTE *RcsId = "$Id$"; /* * $Log$ + * Revision 1.14 2001/07/23 12:47:42 bartoldeman + * FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf + * * Revision 1.13 2001/07/22 01:58:58 bartoldeman * Support for Brian's FORMAT, DJGPP libc compilation, cleanups, MSCDEX * @@ -144,18 +147,14 @@ static BYTE *RcsId = "$Id$"; fcb FAR *ExtFcbToFcb(xfcb FAR * lpExtFcb); fcb FAR *CommonFcbInit(xfcb FAR * lpExtFcb, BYTE * pszBuffer, COUNT * pCurDrive); void FcbNameInit(fcb FAR * lpFcb, BYTE * pszBuffer, COUNT * pCurDrive); -sft FAR *FcbGetSft(COUNT SftIndex); VOID FcbNextRecord(fcb FAR * lpFcb); -/* sft FAR *FcbGetFreeSft(WORD FAR * sft_idx); */ BOOL FcbCalcRec(xfcb FAR * lpXfcb); -VOID MoveDirInfo(dmatch FAR * lpDmatch, struct dirent FAR * lpDir); +VOID MoveDirInfo(dmatch * lpDmatch, fcb FAR * lpDir); #else fcb FAR *ExtFcbToFcb(); fcb FAR *CommonFcbInit(); void FcbNameInit(); -sft FAR *FcbGetSft(); VOID FcbNextRecord(); -/* sft FAR *FcbGetFreeSft(); */ BOOL FcbCalcRec(); VOID MoveDirInfo(); #endif @@ -166,7 +165,7 @@ VOID MoveDirInfo(); static dmatch Dmatch; -VOID FAR *FcbFindFirstDirPtr = NULL; +/* VOID FAR *FcbFindFirstDirPtr = NULL; */ VOID FatGetDrvData(UCOUNT drive, COUNT FAR * spc, COUNT FAR * bps, @@ -274,6 +273,19 @@ WORD FcbParseFname(int wTestMode, BYTE FAR ** lpFileName, fcb FAR * lpFcb) *lpFileName += 2; } + /* special cases: '.' and '..' */ + if (**lpFileName == '.') + { + lpFcb->fcb_fname[0]='.'; + ++*lpFileName; + if (**lpFileName == '.') + { + lpFcb->fcb_fname[1]='.'; + ++*lpFileName; + } + 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); @@ -352,26 +364,6 @@ BYTE FAR *GetNameField(BYTE FAR * lpFileName, BYTE FAR * lpDestField, return lpFileName; } -static sft FAR *FcbGetSft(COUNT SftIndex) -{ - /* Get the SFT block that contains the SFT */ - for (lpCurSft = sfthead; lpCurSft != (sfttbl FAR *) - 1; - lpCurSft = lpCurSft->sftt_next) - { - if (SftIndex < lpCurSft->sftt_count) - break; - else - SftIndex -= lpCurSft->sftt_count; - } - - /* If not found, return an error */ - if (lpCurSft == (sfttbl FAR *) - 1) - return (sft FAR *) - 1; - - /* finally, point to the right entry */ - return (sft FAR *) & (lpCurSft->sftt_table[SftIndex]); -} - static VOID FcbNextRecord(fcb FAR * lpFcb) { if (++lpFcb->fcb_curec > 128) @@ -399,7 +391,7 @@ BOOL FcbRead(xfcb FAR * lpXfcb, COUNT * nErrorCode) lpFcb = ExtFcbToFcb(lpXfcb); /* Get the SFT block that contains the SFT */ - if ((s = FcbGetSft(lpFcb->fcb_sftno)) == (sft FAR *) - 1) + if ((s = idx_to_sft(lpFcb->fcb_sftno)) == (sft FAR *) - 1) return FALSE; /* If this is not opened another error */ @@ -470,7 +462,7 @@ BOOL FcbWrite(xfcb FAR * lpXfcb, COUNT * nErrorCode) lpFcb = ExtFcbToFcb(lpXfcb); /* Get the SFT block that contains the SFT */ - if ((s = FcbGetSft(lpFcb->fcb_sftno)) == (sft FAR *) - 1) + if ((s = idx_to_sft(lpFcb->fcb_sftno)) == (sft FAR *) - 1) return FALSE; /* If this is not opened another error */ @@ -517,24 +509,23 @@ BOOL FcbWrite(xfcb FAR * lpXfcb, COUNT * nErrorCode) BOOL FcbGetFileSize(xfcb FAR * lpXfcb) { - COUNT FcbDrive, - FileNum; + COUNT FcbDrive, hndl; /* Build a traditional DOS file name */ - lpFcb = CommonFcbInit(lpXfcb, PriPathName, &FcbDrive); + lpFcb = CommonFcbInit(lpXfcb, SecPathName, &FcbDrive); /* check for a device */ - if (IsDevice(PriPathName) || (lpFcb->fcb_recsiz == 0)) + if (IsDevice(SecPathName) || (lpFcb->fcb_recsiz == 0)) { return FALSE; } - FileNum = dos_open(PriPathName, O_RDONLY); - if (FileNum >= 0) + hndl = DosOpen(SecPathName, O_RDONLY); + if (hndl >= 0) { LONG fsize; /* Get the size */ - fsize = dos_getfsize(FileNum); + fsize = DosGetFsize(hndl); /* compute the size and update the fcb */ lpFcb->fcb_rndm = fsize / lpFcb->fcb_recsiz; @@ -542,7 +533,7 @@ BOOL FcbGetFileSize(xfcb FAR * lpXfcb) ++lpFcb->fcb_rndm; /* close the file and leave */ - return dos_close(FileNum) == SUCCESS; + return DosClose(hndl) == SUCCESS; } else return FALSE; @@ -631,47 +622,33 @@ BOOL FcbRandomIO(xfcb FAR * lpXfcb, COUNT * nErrorCode, } /* -static sft FAR *FcbGetFreeSft(WORD FAR * sft_idx) +static sft FAR *FcbGetFreeSft(COUNT * sft_idx) see get_free_sft in dosfns.c */ BOOL FcbCreate(xfcb FAR * lpXfcb) { - WORD sft_idx; - sft FAR *sftp; + COUNT sft_idx, FcbDrive; struct dhdr FAR *dhp; - COUNT FcbDrive; - - /* get a free system file table entry */ - if ((sftp = get_free_sft((WORD FAR *) & sft_idx)) == (sft FAR *) - 1) - return DE_TOOMANY; /* Build a traditional DOS file name */ lpFcb = CommonFcbInit(lpXfcb, PriPathName, &FcbDrive); + sft_idx = DosCreatSft(PriPathName, 0); + if (sft_idx < 0) + return FALSE; + /* check for a device */ dhp = IsDevice(PriPathName); - if (dhp || ((sftp->sft_status = dos_creat(PriPathName, 0)) >= 0)) - { - sftp->sft_count += 1; - sftp->sft_mode = O_RDWR; - sftp->sft_attrib = 0; - sftp->sft_flags = dhp ? - ((dhp->dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF : 0; - sftp->sft_psp = cu_psp; - fbcopy(lpFcb->fcb_fname, sftp->sft_name, FNAME_SIZE + FEXT_SIZE); - sftp->sft_dev = dhp; - lpFcb->fcb_sftno = sft_idx; - lpFcb->fcb_curec = 0; - lpFcb->fcb_recsiz = (dhp ? 0 : 128); - if (!dhp) lpFcb->fcb_drive = FcbDrive; - lpFcb->fcb_fsize = 0; - lpFcb->fcb_date = dos_getdate(); - lpFcb->fcb_time = dos_gettime(); - lpFcb->fcb_rndm = 0; - return TRUE; - } - return FALSE; + lpFcb->fcb_sftno = sft_idx; + lpFcb->fcb_curec = 0; + lpFcb->fcb_recsiz = (dhp ? 0 : 128); + if (!dhp) lpFcb->fcb_drive = FcbDrive; + lpFcb->fcb_fsize = 0; + lpFcb->fcb_date = dos_getdate(); + lpFcb->fcb_time = dos_gettime(); + lpFcb->fcb_rndm = 0; + return TRUE; } STATIC fcb FAR *ExtFcbToFcb(xfcb FAR * lpExtFcb) @@ -697,8 +674,11 @@ STATIC fcb FAR *CommonFcbInit(xfcb FAR * lpExtFcb, BYTE * pszBuffer, return lpFcb; } -void FcbNameInit(fcb FAR * lpFcb, BYTE * pszBuffer, COUNT * pCurDrive) +void FcbNameInit(fcb FAR * lpFcb, BYTE * szBuffer, COUNT * pCurDrive) { + BYTE loc_szBuffer[FNAME_SIZE+1+FEXT_SIZE+1]; + BYTE *pszBuffer = loc_szBuffer; + /* Build a traditional DOS file name */ if (lpFcb->fcb_drive != 0) { @@ -711,107 +691,46 @@ void FcbNameInit(fcb FAR * lpFcb, BYTE * pszBuffer, COUNT * pCurDrive) { *pCurDrive = default_drive + 1; } - ConvertName83ToNameSZ((BYTE FAR *)pszBuffer, (BYTE FAR *) lpFcb->fcb_fname); - -/* - lpszFcbFname = (BYTE FAR *) lpFcb->fcb_fname; - for (loop = FNAME_SIZE; --loop >= 0; ) - { - if (*lpszFcbFname != ' ') - *pszBuffer++ = *lpszFcbFname++; - else - break; - } - - lpszFcbFext = (BYTE FAR *) lpFcb->fcb_fext; - if (*lpszFcbFext != ' ') - { - *pszBuffer++ = '.'; - for (loop = FEXT_SIZE; --loop >= 0; ) - { - if (*lpszFcbFext != ' ') - *pszBuffer++ = *lpszFcbFext++; - else - break; - } - } - *pszBuffer = '\0'; -*/ + truename(loc_szBuffer, szBuffer, FALSE); + /* XXX fix truename error handling */ } BOOL FcbOpen(xfcb FAR * lpXfcb) { - WORD sft_idx; sft FAR *sftp; struct dhdr FAR *dhp; - COUNT FcbDrive; - - /* get a free system file table entry */ - if ((sftp = get_free_sft((WORD FAR *) & sft_idx)) == (sft FAR *) - 1) - return DE_TOOMANY; + COUNT FcbDrive, sft_idx; /* Build a traditional DOS file name */ lpFcb = CommonFcbInit(lpXfcb, PriPathName, &FcbDrive); + sft_idx = DosOpenSft(PriPathName, O_RDWR); + if (sft_idx < 0) + return FALSE; + /* check for a device */ + lpFcb->fcb_curec = 0; + lpFcb->fcb_rndm = 0; + lpFcb->fcb_sftno = sft_idx; dhp = IsDevice(PriPathName); if (dhp ) { - sftp->sft_count += 1; - sftp->sft_mode = O_RDWR; - sftp->sft_attrib = 0; - sftp->sft_flags = - ((dhp->dh_attr & ~SFT_MASK) & ~SFT_FSHARED) | SFT_FDEVICE | SFT_FEOF; - sftp->sft_psp = cu_psp; - fbcopy(lpFcb->fcb_fname, sftp->sft_name, FNAME_SIZE + FEXT_SIZE); - sftp->sft_dev = dhp; - lpFcb->fcb_sftno = sft_idx; - lpFcb->fcb_curec = 0; - lpFcb->fcb_recsiz = 0; - lpFcb->fcb_fsize = 0; - lpFcb->fcb_date = dos_getdate(); - lpFcb->fcb_time = dos_gettime(); - lpFcb->fcb_rndm = 0; - return TRUE; - } - fbcopy((BYTE FAR *) & lpFcb->fcb_fname, (BYTE FAR *) & sftp->sft_name, FNAME_SIZE + FEXT_SIZE); - if ((UCOUNT)FcbDrive >= lastdrive) { - return DE_INVLDDRV; - } - if (CDSp->cds_table[FcbDrive].cdsFlags & CDSNETWDRV) { - COUNT result; - lpCurSft = (sfttbl FAR *)sftp; - result = -int2f_Remote_call(REM_OPEN, 0, 0, 0, (VOID FAR *) sftp, 0, MK_FP(0, O_RDWR)); - sftp->sft_status = result; - } - else { - sftp->sft_status = dos_open(PriPathName, O_RDWR); - sftp->sft_size = dos_getfsize(sftp->sft_status); - dos_getftime(sftp->sft_status, - (date FAR *) & sftp->sft_date, - (time FAR *) & sftp->sft_time); - - } - if (sftp->sft_status >= 0) - { - lpFcb->fcb_drive = FcbDrive; - lpFcb->fcb_sftno = sft_idx; - lpFcb->fcb_curec = 0; - lpFcb->fcb_recsiz = 128; - lpFcb->fcb_fsize = sftp->sft_size; - lpFcb->fcb_date = sftp->sft_date; - lpFcb->fcb_time = sftp->sft_time; - lpFcb->fcb_rndm = 0; - sftp->sft_count += 1; - sftp->sft_mode = O_RDWR; - sftp->sft_attrib = 0; - sftp->sft_flags = 0; - sftp->sft_psp = cu_psp; - return TRUE; + lpFcb->fcb_recsiz = 0; + lpFcb->fcb_fsize = 0; + lpFcb->fcb_date = dos_getdate(); + lpFcb->fcb_time = dos_gettime(); } else - return FALSE; + { + sftp = idx_to_sft(sft_idx); + 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; } BOOL FcbDelete(xfcb FAR * lpXfcb) @@ -819,18 +738,14 @@ BOOL FcbDelete(xfcb FAR * lpXfcb) COUNT FcbDrive; /* Build a traditional DOS file name */ - CommonFcbInit(lpXfcb, PriPathName, &FcbDrive); + CommonFcbInit(lpXfcb, SecPathName, &FcbDrive); if ((UCOUNT)FcbDrive >= lastdrive) { return DE_INVLDDRV; } - current_ldt = &CDSp->cds_table[FcbDrive]; - if (CDSp->cds_table[FcbDrive].cdsFlags & CDSNETWDRV) { - return -int2f_Remote_call(REM_DELETE, 0, 0, 0, 0, 0, 0); - } /* check for a device */ - if (IsDevice(PriPathName)) + if (IsDevice(SecPathName)) { return FALSE; } @@ -840,20 +755,21 @@ BOOL FcbDelete(xfcb FAR * lpXfcb) dmatch Dmatch; dta = (BYTE FAR *) & Dmatch; - if (dos_findfirst(D_ALL, PriPathName[1] == ':' ? &PriPathName[2] : PriPathName) != SUCCESS) + if (DosFindFirst(D_ALL, SecPathName[1] == ':' ? &SecPathName[2] : SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; } do { - if (dos_delete(Dmatch.dm_name) != SUCCESS) + truename(Dmatch.dm_name, SecPathName, FALSE); + if (DosDelete(SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; } } - while (dos_findnext() == SUCCESS); + while (DosFindNext() == SUCCESS); dta = lpOldDta; return TRUE; } @@ -865,10 +781,10 @@ BOOL FcbRename(xfcb FAR * lpXfcb) COUNT FcbDrive; /* Build a traditional DOS file name */ - lpRenameFcb = (rfcb FAR *) CommonFcbInit(lpXfcb, PriPathName, &FcbDrive); + lpRenameFcb = (rfcb FAR *) CommonFcbInit(lpXfcb, SecPathName, &FcbDrive); /* check for a device */ - if (IsDevice(PriPathName)) + if (IsDevice(SecPathName)) { return FALSE; } @@ -878,7 +794,7 @@ BOOL FcbRename(xfcb FAR * lpXfcb) dmatch Dmatch; dta = (BYTE FAR *) & Dmatch; - if (dos_findfirst(D_ALL, PriPathName[1] == ':' ? &PriPathName[2] : PriPathName) != SUCCESS) + if (DosFindFirst(D_ALL, SecPathName[1] == ':' ? &SecPathName[2] : SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; @@ -942,74 +858,38 @@ BOOL FcbRename(xfcb FAR * lpXfcb) /* now to build a dos name again */ LocalFcb.fcb_drive = 0; - FcbNameInit((fcb FAR *) & LocalFcb, PriPathName, &FcbDrive); + FcbNameInit((fcb FAR *) & LocalFcb, SecPathName, &FcbDrive); - if (dos_rename(Dmatch.dm_name, - PriPathName[1] == ':' ? &PriPathName[2] : PriPathName) != SUCCESS) + truename(Dmatch.dm_name, PriPathName, FALSE); + + if (DosRenameTrue(PriPathName, SecPathName) != SUCCESS) { dta = lpOldDta; return FALSE; } } - while (dos_findnext() == SUCCESS); + while (DosFindNext() == SUCCESS); dta = lpOldDta; return TRUE; } } -#if 0 /* TE:the MoveDirInfo() is now done by simply copying the dirEntry into the FCB this prevents problems with ".", ".." and saves code + BO:use FcbParseFname: avoid redirector problems and is there anyway */ - -void MoveDirInfo(dmatch FAR * lpDmatch, struct dirent FAR * lpDir) +VOID MoveDirInfo(dmatch * lpDmatch, fcb FAR * lpDir) { - BYTE FAR *lpToName, - FAR * lpszFrom; - COUNT nIndex; - + BYTE FAR *lpszFrom = lpDmatch->dm_name; /* First, expand the find match into dir style */ - /* file name entry */ - /* Fill with blanks first */ - - fmemset(lpDir->dir_name, ' ', FNAME_SIZE); - fmemset(lpDir->dir_ext , ' ', FEXT_SIZE ); - - /* next move in the file name while overwriting */ - /* the filler blanks */ - lpszFrom = lpDmatch->dm_name; - lpToName = (BYTE FAR *)lpDir->dir_name; - for (nIndex = 0; nIndex < FNAME_SIZE; nIndex++) - { - if (*lpszFrom != 0 && *lpszFrom != '.') - *lpToName++ = *lpszFrom++; - else - break; - } - - if (*lpszFrom != '\0') - { - if (*lpszFrom == '.') - ++lpszFrom; - lpToName = (BYTE FAR *)lpDir->dir_ext; - for (nIndex = 0; nIndex < FEXT_SIZE; nIndex++) - { - if (*lpszFrom != '\0') - *lpToName++ = *lpszFrom++; - else - break; - } - } - for (nIndex = 0; nIndex < 10; nIndex++) - lpDir->dir_reserved[nIndex] = 0; - lpDir->dir_attrib = lpDmatch->dm_attr_fnd; - lpDir->dir_time = lpDmatch->dm_time; - lpDir->dir_date = lpDmatch->dm_date; - lpDir->dir_start = lpDmatch->dm_cluster; - lpDir->dir_size = lpDmatch->dm_size; + FcbParseFname(PARSE_DFLT_DRIVE | PARSE_SEP_STOP, &lpszFrom, lpDir); + /* lpDir->dir_attrib = lpDmatch->dm_attr_fnd; XXX for extended fcb! */ + lpDir->fcb_time = lpDmatch->dm_time; + lpDir->fcb_date = lpDmatch->dm_date; + lpDir->fcb_dirclst = lpDmatch->dm_cluster; + lpDir->fcb_fsize = lpDmatch->dm_size; } -#endif BOOL FcbClose(xfcb FAR * lpXfcb) { @@ -1019,52 +899,37 @@ BOOL FcbClose(xfcb FAR * lpXfcb) lpFcb = ExtFcbToFcb(lpXfcb); /* Get the SFT block that contains the SFT */ - if ((s = FcbGetSft(lpFcb->fcb_sftno)) == (sft FAR *) - 1) + if ((s = idx_to_sft(lpFcb->fcb_sftno)) == (sft FAR *) - 1) return FALSE; - /* If this is not opened another error */ - if (s->sft_count == 0) - return FALSE; + /* change time and set file size */ + s->sft_size = lpFcb->fcb_fsize; + if (!(s->sft_flags & SFT_FSHARED)) + dos_setfsize(s->sft_status, lpFcb->fcb_fsize); + DosSetFtimeSft(lpFcb->fcb_sftno, (date FAR *) &lpFcb->fcb_date, (time FAR *) &lpFcb->fcb_time); + return DosCloseSft(lpFcb->fcb_sftno) == SUCCESS; +} - if (s->sft_flags & SFT_FSHARED) - { - int2f_Remote_call(REM_CLOSE, 0, 0, 0, (VOID FAR *) s, 0, 0); - } +/* close all files opened by FCBs + DosCloseSft checks the open count (has to be 1) and current psp + */ +VOID FcbCloseAll() +{ + COUNT idx = 0; - /* now just drop the count if a device, else */ - /* call file system handler */ - if (s->sft_flags & SFT_FDEVICE) - { - s->sft_count -= 1; - return TRUE; - } - else - { - s->sft_count -= 1; - if (s->sft_count > 0) - return SUCCESS; - else - { - /* change time and set file size */ - dos_setftime(s->sft_status, - (date FAR *) & lpFcb->fcb_date, - (time FAR *) & lpFcb->fcb_time); - dos_setfsize(s->sft_status, - lpFcb->fcb_fsize); - return dos_close(s->sft_status) == SUCCESS; - } - } + for (idx = 0; DosCloseSft(idx) != DE_INVLDHNDL; idx++) + ; } BOOL FcbFindFirst(xfcb FAR * lpXfcb) { - BYTE FAR *lpDir; + fcb FAR *lpDir; COUNT FcbDrive; psp FAR *lpPsp = MK_FP(cu_psp, 0); /* First, move the dta to a local and change it around to match */ /* our functions. */ - lpDir = (BYTE FAR *) dta; + lpDir = (fcb FAR *) dta; dta = (BYTE FAR *) & Dmatch; /* Next initialze local variables by moving them from the fcb */ @@ -1072,28 +937,28 @@ BOOL FcbFindFirst(xfcb FAR * lpXfcb) if (lpXfcb->xfcb_flag == 0xff) { wAttr = lpXfcb->xfcb_attrib; - fbcopy(lpXfcb, lpDir, 7); + /* fbcopy(lpXfcb, lpDir, 7); lpDir += 7; + BO:WHY??? + */ } else wAttr = D_ALL; - *lpDir++ = FcbDrive; + /* *lpDir++ = FcbDrive; */ - FcbFindFirstDirPtr = lpDir; + /* FcbFindFirstDirPtr = lpDir; */ - if (dos_findfirst(wAttr, SecPathName) != SUCCESS) + if (DosFindFirst(wAttr, SecPathName) != SUCCESS) { - FcbFindFirstDirPtr = NULL; + /* FcbFindFirstDirPtr = NULL;*/ dta = lpPsp->ps_dta; return FALSE; } - FcbFindFirstDirPtr = NULL; + /* FcbFindFirstDirPtr = NULL; */ -/* - MoveDirInfo((dmatch FAR *) & Dmatch, (struct dirent FAR *)lpDir); -*/ + MoveDirInfo(&Dmatch, lpDir); lpFcb->fcb_dirclst = Dmatch.dm_dirstart; lpFcb->fcb_strtclst = Dmatch.dm_entry; @@ -1115,13 +980,13 @@ BOOL FcbFindFirst(xfcb FAR * lpXfcb) BOOL FcbFindNext(xfcb FAR * lpXfcb) { - BYTE FAR *lpDir; + fcb FAR *lpDir; COUNT FcbDrive; psp FAR *lpPsp = MK_FP(cu_psp, 0); /* First, move the dta to a local and change it around to match */ /* our functions. */ - lpDir = (BYTE FAR *) dta; + lpDir = (fcb FAR *) dta; dta = (BYTE FAR *) & Dmatch; /* Next initialze local variables by moving them from the fcb */ @@ -1129,14 +994,17 @@ BOOL FcbFindNext(xfcb FAR * lpXfcb) if ((xfcb FAR *) lpFcb != lpXfcb) { wAttr = lpXfcb->xfcb_attrib; + /* fbcopy(lpXfcb, lpDir, 7); lpDir += 7; + BO:WHY??? + */ } else wAttr = D_ALL; /* Reconstrct the dirmatch structure from the fcb */ - *lpDir++ = FcbDrive; + /* *lpDir++ = FcbDrive; */ Dmatch.dm_drive = lpFcb->fcb_sftno; fbcopy(lpFcb->fcb_fname, (BYTE FAR *) Dmatch.dm_name_pat, FNAME_SIZE + FEXT_SIZE); @@ -1147,20 +1015,18 @@ BOOL FcbFindNext(xfcb FAR * lpXfcb) Dmatch.dm_cluster = lpFcb->fcb_dirclst; Dmatch.dm_dirstart= lpFcb->fcb_dirclst; - FcbFindFirstDirPtr = lpDir; + /* FcbFindFirstDirPtr = lpDir; */ - if (dos_findnext() != SUCCESS) + if (DosFindNext() != SUCCESS) { - FcbFindFirstDirPtr = NULL; + /* FcbFindFirstDirPtr = NULL; */ dta = lpPsp->ps_dta; CritErrCode = 0x12; return FALSE; } - FcbFindFirstDirPtr = NULL; + /*FcbFindFirstDirPtr = NULL;*/ -/* - MoveDirInfo((dmatch FAR *) & Dmatch, (struct dirent FAR *)lpDir); -*/ + MoveDirInfo(&Dmatch, lpDir); lpFcb->fcb_dirclst = Dmatch.dm_dirstart; lpFcb->fcb_strtclst = Dmatch.dm_entry; diff --git a/kernel/initdisk.c b/kernel/initdisk.c index 20b7f18..a7c8ac2 100644 --- a/kernel/initdisk.c +++ b/kernel/initdisk.c @@ -567,9 +567,10 @@ StandardBios: /* old way to get parameters */ driveParam->driveno = drive; DebugPrintf(("drive parameters %02x - %04lu-%u-%u", - drive,driveParam->chs.Cylinder, - drive,driveParam->chs.Head, - drive,driveParam->chs.Sector)); + drive, + driveParam->chs.Cylinder, + driveParam->chs.Head, + driveParam->chs.Sector)); DebugPrintf((" total size %luMB\n\n",driveParam->total_sectors/2048)); diff --git a/kernel/inthndlr.c b/kernel/inthndlr.c index 34180b2..4351550 100644 --- a/kernel/inthndlr.c +++ b/kernel/inthndlr.c @@ -37,6 +37,9 @@ BYTE *RcsId = "$Id$"; /* * $Log$ + * Revision 1.27 2001/07/23 12:47:42 bartoldeman + * FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf + * * Revision 1.26 2001/07/22 01:58:58 bartoldeman * Support for Brian's FORMAT, DJGPP libc compilation, cleanups, MSCDEX * @@ -1174,8 +1177,6 @@ dispatch: || ((psp FAR *) (MK_FP(cu_psp, 0)))->ps_parent == cu_psp) break; tsr = FALSE; - int2f_Remote_call(REM_PROCESS_END, 0, 0, 0, 0, 0, 0); - int2f_Remote_call(REM_CLOSEALL, 0, 0, 0, 0, 0, 0); if (ErrorMode) { ErrorMode = FALSE; diff --git a/kernel/proto.h b/kernel/proto.h index 84bd96e..0b2ecbb 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -34,6 +34,9 @@ static BYTE *Proto_hRcsId = "$Id$"; /* * $Log$ + * Revision 1.19 2001/07/23 12:47:42 bartoldeman + * FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf + * * Revision 1.18 2001/07/22 01:58:58 bartoldeman * Support for Brian's FORMAT, DJGPP libc compilation, cleanups, MSCDEX * @@ -219,29 +222,35 @@ COUNT SftSeek(sft FAR *sftp, LONG new_pos, COUNT mode); UCOUNT DosWrite(COUNT hndl, UCOUNT n, BYTE FAR * bp, COUNT FAR * err); COUNT DosSeek(COUNT hndl, LONG new_pos, COUNT mode, ULONG * set_pos); COUNT DosCreat(BYTE FAR * fname, COUNT attrib); +COUNT DosCreatSft(BYTE * fname, COUNT attrib); COUNT CloneHandle(COUNT hndl); COUNT DosDup(COUNT Handle); COUNT DosForceDup(COUNT OldHandle, COUNT NewHandle); COUNT DosOpen(BYTE FAR * fname, COUNT mode); +COUNT DosOpenSft(BYTE * fname, COUNT mode); COUNT DosClose(COUNT hndl); +COUNT DosCloseSft(WORD sft_idx); VOID DosGetFree(UBYTE drive, COUNT FAR * spc, COUNT FAR * navc, COUNT FAR * bps, COUNT FAR * nc); COUNT DosGetCuDir(UBYTE drive, BYTE FAR * s); COUNT DosChangeDir(BYTE FAR * s); COUNT DosFindFirst(UCOUNT attr, BYTE FAR * name); COUNT DosFindNext(void); COUNT DosGetFtime(COUNT hndl, date FAR * dp, time FAR * tp); -COUNT DosSetFtime(COUNT hndl, date FAR * dp, time FAR * tp); +COUNT DosSetFtimeSft(WORD sft_idx, date FAR * dp, time FAR * tp); +#define DosSetFtime(hndl, dp, tp) DosSetFtimeSft(get_sft_idx(hndl), (dp), (tp)) COUNT DosGetFattr(BYTE FAR * name); COUNT DosSetFattr(BYTE FAR * name, UWORD attrp); UBYTE DosSelectDrv(UBYTE drv); 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); BOOL IsShareInstalled(void); COUNT DosLockUnlock(COUNT hndl, LONG pos, LONG len, COUNT unlock); -sft FAR *get_free_sft(WORD FAR * sft_idx); +sft FAR *idx_to_sft(COUNT SftIndex); +COUNT get_sft_idx(UCOUNT hndl); /*dosidle.asm */ VOID DosIdle_int(void); @@ -348,8 +357,9 @@ void FcbNameInit(fcb FAR * lpFcb, BYTE * pszBuffer, COUNT * pCurDrive); BOOL FcbOpen(xfcb FAR * lpXfcb); BOOL FcbDelete(xfcb FAR * lpXfcb); BOOL FcbRename(xfcb FAR * lpXfcb); -void MoveDirInfo(dmatch FAR * lpDmatch, struct dirent FAR * lpDir); +VOID MoveDirInfo(dmatch * lpDmatch, fcb FAR * lpDir); BOOL FcbClose(xfcb FAR * lpXfcb); +VOID FcbCloseAll(VOID); BOOL FcbFindFirst(xfcb FAR * lpXfcb); BOOL FcbFindNext(xfcb FAR * lpXfcb); @@ -476,6 +486,7 @@ 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); +LONG DosGetFsize(COUNT hndl); VOID InitPSP(VOID); /* newstuff.c */ diff --git a/kernel/task.c b/kernel/task.c index 1e8ff9b..eeb377f 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -35,6 +35,9 @@ static BYTE *RcsId = "$Id$"; /* * $Log$ + * Revision 1.16 2001/07/23 12:47:42 bartoldeman + * FCB fixes and clean-ups, exec int21/ax=4b01, initdisk.c printf + * * Revision 1.15 2001/07/22 01:58:58 bartoldeman * Support for Brian's FORMAT, DJGPP libc compilation, cleanups, MSCDEX * @@ -207,10 +210,6 @@ LONG DosGetFsize(COUNT hndl) sft FAR *s; /* sfttbl FAR *sp;*/ - /* Test that the handle is valid */ - if (hndl < 0) - return DE_INVLDHNDL; - /* Get the SFT block that contains the SFT */ if ((s = get_sft(hndl)) == (sft FAR *) - 1) return DE_INVLDHNDL; @@ -389,8 +388,8 @@ VOID new_psp(psp FAR * p, int psize) RootPsp = FP_SEG(p); } -static VOID patchPSP(UWORD pspseg, UWORD envseg, CommandTail FAR * cmdline - ,BYTE FAR * fnam) +static UWORD patchPSP(UWORD pspseg, UWORD envseg, exec_blk FAR *exb, + BYTE FAR * fnam) { psp FAR *psp; mcb FAR *pspmcb; @@ -401,9 +400,11 @@ static VOID patchPSP(UWORD pspseg, UWORD envseg, CommandTail FAR * cmdline ++pspseg; psp = MK_FP(pspseg, 0); - /* complete the psp by adding the command line */ - fbcopy(cmdline->ctBuffer, psp->ps_cmd, 127); - psp->ps_cmd_count = cmdline->ctCount; + /* complete the psp by adding the command line and FCBs */ + fbcopy(exb->exec.cmd_line->ctBuffer, psp->ps_cmd, 127); + fbcopy(exb->exec.fcb_1, &psp->ps_fcb1, 16); + fbcopy(exb->exec.fcb_2, &psp->ps_fcb2, 16); + psp->ps_cmd_count = exb->exec.cmd_line->ctCount; /* identify the mcb as this functions' */ pspmcb->m_psp = pspseg; @@ -438,6 +439,11 @@ set_name: if (i < 8) 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; } COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) @@ -559,37 +565,37 @@ 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); - patchPSP(mem - 1, env, exp->exec.cmd_line, namep); - - /* build the user area on the stack */ - *((UWORD FAR *) MK_FP(mem, 0xfffe)) = (UWORD) 0; - irp = MK_FP(mem, (0xfffe - sizeof(iregs))); - - /* start allocating REGs */ - irp->ES = irp->DS = mem; - irp->CS = mem; - irp->IP = 0x100; - irp->AX = 0xffff; /* for now, until fcb code is in */ - irp->BX = - irp->CX = - irp->DX = - irp->SI = - irp->DI = - irp->BP = 0; - irp->FLAGS = 0x200; + asize = patchPSP(mem - 1, env, exp, namep); /* asize=fcbcode for ax */ /* 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; + cu_psp = mem; + dta = p->ps_dta; switch (mode) { case LOADNGO: { - cu_psp = mem; - dta = p->ps_dta; + *((UWORD FAR *) MK_FP(mem, 0xfffe)) = (UWORD) 0; + + /* build the user area on the stack */ + irp = MK_FP(mem, (0xfffe - sizeof(iregs))); + + /* start allocating REGs */ + 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->FLAGS = 0x200; if (InDOS) --InDOS; @@ -600,9 +606,9 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) break; } case LOAD: - cu_psp = mem; - exp->exec.stack = (BYTE FAR *) irp; - exp->exec.start_addr = MK_FP(irp->CS, irp->IP); + exp->exec.stack = MK_FP(mem, 0xfffe); + *((UWORD FAR *)exp->exec.stack) = asize; + exp->exec.start_addr = MK_FP(mem, 0x100); return SUCCESS; } @@ -626,12 +632,15 @@ VOID return_user(void) setvec(0x24, p->ps_isv24); /* And free all process memory if not a TSR return */ + int2f_Remote_call(REM_PROCESS_END, 0, 0, 0, 0, 0, 0); if (!tsr) { + int2f_Remote_call(REM_CLOSEALL, 0, 0, 0, 0, 0, 0); for (i = 0; i < p->ps_maxfiles; i++) { DosClose(i); } + FcbCloseAll(); FreeProcessMem(cu_psp); } @@ -917,25 +926,7 @@ COUNT DosExeLoader(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); - patchPSP(mem - 1, env, exp->exec.cmd_line, namep); - - /* build the user area on the stack */ - 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 = 0xffff; /* for now, until fcb code is in */ - irp->BX = - irp->CX = - irp->DX = - irp->SI = - irp->DI = - irp->BP = 0; - irp->FLAGS = 0x200; + asize = patchPSP(mem - 1, env, exp, namep); /* asize = fcbcode */ /* Transfer control to the executable */ p->ps_parent = cu_psp; @@ -946,6 +937,24 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) switch (mode) { case LOADNGO: + /* build the user area on the stack */ + 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; + cu_psp = mem; dta = p->ps_dta; @@ -958,8 +967,9 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk FAR * exp, COUNT mode) case LOAD: cu_psp = mem; - exp->exec.stack = (BYTE FAR *) irp; - exp->exec.start_addr = MK_FP(irp->CS, irp->IP); + 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;