Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
tkchia

Homepage

02.02.2021, 14:35
 

Good way to check if file already opened? (GW-BASIC porting) (Developers)

Hi all,

I am trying to port the CHKFOP routine in Microsoft's GW-BASIC sources, to work with MS-DOS 2+ file descriptors rather than DOS 1.x FCBs.

The routine is supposed to check whether a named file is currently open, so that e.g. the KILL and NAME commands can prevent one from deleting or renaming an open file.

Any ideas on how I might do this?

The 1983 implementation basically looks through GW-BASIC's own table of open files, and compares drive letters, file names, and file extensions. I suppose this is enough under DOS 1.x, but it is not quite enough under DOS 2+ which may have subdirectories, network paths, etc.

Thanks!

---
https://gitlab.com/tkchia · https://codeberg.org/tkchia · 😴 "MOV AX,0D500H+CMOS_REG_D+NMI"

Ringding

02.02.2021, 20:57

@ tkchia
 

Good way to check if file already opened? (GW-BASIC porting)

> The 1983 implementation basically looks through GW-BASIC's own table of
> open files, and compares drive letters, file names, and file extensions. I
> suppose this is enough under DOS 1.x, but it is not quite enough under DOS
> 2+ which may have subdirectories, network paths, etc.

A good excuse to go and play with GW-BASIC :-D. Interestingly, the current version seems to do exactly the same thing and only look at the file name. I get the "File already open" error (might not be the exact wording, I seem to have a German version of GW-BASIC) when trying to remove a file with the same name as another one I'm keeping open in another directory.

tkchia

Homepage

04.02.2021, 09:05

@ Ringding
 

Good way to check if file already opened? (GW-BASIC porting)

Hello Ringding,

> A good excuse to go and play with GW-BASIC :-D. Interestingly, the current
> version seems to do exactly the same thing and only look at the file name.
> I get the "File already open" error (might not be the exact wording, I seem
> to have a German version of GW-BASIC) when trying to remove a file with the
> same name as another one I'm keeping open in another directory.

Interesting indeed. Well, I guess I can also do the same thing, if I just want to be bug-for-bug compatible with existing GW-BASIC implementations... :-)

Thank you!

---
https://gitlab.com/tkchia · https://codeberg.org/tkchia · 😴 "MOV AX,0D500H+CMOS_REG_D+NMI"

rr

Homepage E-mail

Berlin, Germany,
02.02.2021, 21:16

@ tkchia
 

Good way to check if file already opened? (GW-BASIC porting)

> I am trying to port the
> CHKFOP
> routine in Microsoft's GW-BASIC sources, to work with MS-DOS 2+ file
> descriptors rather than DOS 1.x FCBs.
>
> The routine is supposed to check whether a named file is currently open, so
> that e.g. the KILL and NAME commands can prevent one from deleting or
> renaming an open file.
>
> Any ideas on how I might do this?

I think, you have to walk the System File Table(s).
See RBIL 04h DWORD -> first System File Table (see #01639,#01640,#01641,#01642)

---
Forum admin

Laaca

Homepage

Czech republic,
02.02.2021, 22:18

@ tkchia
 

Good way to check if file already opened? (GW-BASIC porting)

You can use the exclusive file access. You probable open files via INT21h/AX=3Dh
If you can control all access to files you can set the AL register to 12h
(exclusive file access in R/W mode)

The next attempts for accessing this file will generate DOS errors 5h or 56h
Implementation in pascal:

var f1,f2:file;
    i:integer;
    s:string;
begin
{$I-}
Filemode:=$12;

write('Enter filename for open: ');
readln(s);

Assign(f1,s);
Reset(f1);

if IOresult<>0 then begin writeln('Error in opening file.');Halt(2);end;

write('Again enter filename (the same one or other one) for open: ');
readln(s);

Assign(f2,s);
Reset(f2);
i:=IOresult;
if i=5 then writeln('The file was already opened before!') else
if i=0 then writeln('Both files was opened OK.')
   else writeln('The first file was opened but the second file not.');
end.

---
DOS-u-akbar!

tkchia

Homepage

13.02.2021, 19:23

@ Laaca
 

Good way to check if file already opened? (GW-BASIC porting)

Hello Laaca,

> You can use the exclusive file access. You probable open files via
> INT21h/AX=3Dh
> If you can control all access to files you can set the AL register to 12h
> (exclusive file access in R/W mode)

Thanks, that would be the neatest solution if it works.

Unfortunately the access control only works if share.exe (or share.com) functionality happens to be installed. If I try to open files with int 0x21, ax = 0x3d12 (say) on a system without share.exe, DOS basically just ignores the access control bits and always allows the file to be opened.

So it might be that I will have to mess with the internal List of Lists (!), as Robert suggested.

Thank you!

---
https://gitlab.com/tkchia · https://codeberg.org/tkchia · 😴 "MOV AX,0D500H+CMOS_REG_D+NMI"

Back to index page
Thread view  Board view
22049 Postings in 2034 Threads, 396 registered users, 189 users online (0 registered, 189 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum