English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 28 November 2022, 06:40   #1
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
DOS Questions

  1. What's the difference between a file handle and a lock?
  2. How do I create a FileInfoBlock usable by ExamineFH?

Thanks in advance.
Steam Ranger is offline  
Old 28 November 2022, 07:04   #2
Steady
Registered User
 
Join Date: May 2021
Location: Melbourne, Australia
Posts: 43
A file handle is used to refer to a file (stream) that has been opened. Opening it implies a lock.

A lock can refer to things other than files (such as directories or volumes) and do not require opening.

See this link to the appropriate documentation. It is for OS4 but the concept is basically the same for OS3.

https://wiki.amigaos.net/wiki/AmigaD...s#File_Handles

Finally, creating a FileInfoBlock in an AmigaDOS compatible way is best done with the following code:

Code:
struct FileInfoBlock *fib = (struct FileInfoBlock *)AllocDosObjectTags(DOS_FIB, TAG_DONE);
Don't forget to
Code:
FreeDosObject(DOS_FIB, fib);
when you are done.

If you are writing code for a version of the OS that is too old, you can also use
Code:
AllocMem(sizeof(struct FileInfoBlock), 0);
because it will ensure that the allocation is longword aligned which is required for AmigaDOS structures such as FileInfoBlock.

What you definitely DON'T want to do is reserve space on the stack because that probably isn't longword aligned and will cause a crash.
Steady is offline  
Old 28 November 2022, 09:16   #3
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
If I write to a file once, do I need to seek to the start of it to write again?

Last edited by Steam Ranger; 28 November 2022 at 09:26.
Steam Ranger is offline  
Old 28 November 2022, 19:03   #4
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,319
I am sorry, but I do not quite understand which problem you attempt to solve. If you open a file for writing (MODE_NEWFILE), then if there is a file of the same name exists, it will be erased first, and you will write from offset 0 on. For any other mode, the file contents remains untouched, and you start overwriting from offset 0 on, leaving all bytes behind your current write position untouched. Thus, the pointer into the file is always at 0 after opening a file.

If a file is already open, the write pointer advances by the number of bytes you write. Thus, if you then seek backwards to offset 0, you start overwriting what you have written, without actually truncating the file.
Thomas Richter is offline  
Old 28 November 2022, 19:55   #5
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,659
AmigaDev is a great resource, but only for reference if you already have some experience with how the OS works. For how to, the System Programmer's Guide has examples (in Assembler) with texts that explain the concepts.
Photon is offline  
Old 28 November 2022, 20:00   #6
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,659
AmigaDev is a great resource, but only for reference if you already have some experience with how the OS works. For how to, the System Programmer's Guide has examples (in Assembler) with texts that explain the concepts.

Seeking is rarely done unless you are dealing with a multi-megabyte file. In older computers this sometimes had to be done also for smaller files (due to many reasons, slow media and little RAM being the most relevant). The typical flow is to get a file handle, then open, read or write the complete file, and close.
Photon is offline  
Old 28 November 2022, 23:49   #7
Steam Ranger
Registered User
 
Steam Ranger's Avatar
 
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 208
Ok. So to overwrite an open file multiple times, you need to seek. Thanks.

I'll also check out the links.
Steam Ranger is offline  
Old 29 November 2022, 07:16   #8
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,319
In that generality, no. If you want to overwrite a file, close the file handle of the file. Re-open the file with MODE_NEWFILE. No seeking necessary.

Note that if you keep the file open, and you seek back, you do not truncate it. The data that is in there remains in there, you are just overwriting what is there.
Thomas Richter is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apollo 1240 - Questions about questions StompinSteve Hardware mods 19 19 July 2021 02:05
PCMCIA fault: DOS error code 225 - Not a valid DOS disk 4am support.Hardware 2 07 April 2012 10:20
Amiga DOS aragon127 support.WinUAE 1 22 April 2004 03:26
For those of you that must run old MS-DOS games, DOS Box has been ported Pyromania Amiga scene 19 06 June 2003 11:44
cross dos help fastflange request.Apps 2 19 June 2002 17:56

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:51.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09000 seconds with 15 queries