Skip to content

Commit

Permalink
Change the mechanism to access mounted files (Konamiman#93)
Browse files Browse the repository at this point in the history
Change the mechanism to access mounted files from file based to sector based.

- A new restriction is introduced: a file needs to be stored across consecutive sectors in disk in order to be mountable.
- Message for error .ICLUS has been changed from "Invalid cluster number" to "Invalid cluster number or sequence".
- New BASIC error code introduced: code 82, message "Invalid cluster sequence".
- The _GDLI function call will now return two extra values for a drive that has a mounted file: "start cluster" and "start sector"
  • Loading branch information
Konamiman authored and vipoo committed Oct 2, 2023
1 parent ec763e3 commit 0334c7a
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 526 deletions.
35 changes: 27 additions & 8 deletions docs/Nextor 2.1 Programmers Reference.md
Expand Up @@ -88,9 +88,13 @@

[8. Change history](#8-change-history)

[8.1. v2.1.0 beta 2](#81-v210-beta-2)
[8.1. v2.1.1 beta 2](#81-v211-beta-2)

[8.2. v2.1.0 beta 1](#82-v210-beta-1)
[8.2. v2.1.0 RC 1](#82-v210-rc-1)

[8.3. v2.1.0 beta 2](#83-v210-beta-2)

[8.4. v2.1.0 beta 1](#84-v210-beta-1)


## 1. Introduction
Expand Down Expand Up @@ -440,20 +444,25 @@ The information returned in the data buffer is as follows:
+10..+63: Reserved (currently always zero)
```

If a file is mounted in the drive, the information returned in the data buffer is insetad as follows:
If a file is mounted in the drive, the information returned in the data buffer is instead as follows:

```
+1: Drive where the mounted file is located (0 = A:, etc)
+2: Flags:
bit 0: mount mode, 0 = read and write, 1 = read-only
+3: Always 0
+4: Filename in printable format (up to 12 characters, plus a terminating zero)
+17: Start cluster of the file, 2 bytes (0 if not available)
+19: Start sector of the file, 4 bytes (0 if not available)
```

If a drive larger than the maximum drive number supported by the system is specified, an .IDRV error will be returned. Note that if a drive number is specified which is legal in Nextor, but is currently not assigned to any driver, then no error will be returned, but an empty information block will be returned (the drive status byte should be checked).

The "first device sector number" is the absolute device sector number that is treated as the first logical sector for the drive; usually it is either the starting sector of a device partition, or the device absolute sector zero, if the device has no partitions. Note that you can't test this value against zero to check whether the drive is assigned to a block device on a device-based driver or not (use the “drive status” field for this purpose).

The "start cluster" and "start sector" fields for mounted files were introduced in Nextor 2.1.1. Currently, they will always contain meaningful information, but in future versions of Nextor this could not be true (because non-FAT filesystems with no concept of "clusters" get supported, or for any other reason) and in these cases the fields will have a value of zero. These fields will also be returned as zero in versions of Nextor older than 2.1.1, therefore application programs using this function call should always verify that the values of these fields are non-zero before using them.


### 3.10. Get information about a device partition (_GPART, 7Ah)

```
Expand Down Expand Up @@ -611,7 +620,7 @@ When invoked in MSX-DOS 1 mode, the following restrictions apply to this functio
* The new mapping information may specify a different partition and/or device, but the driver slot must be the same that was assigned to the drive at boot time. This is not an issue if there is only one Nextor kernel in the system.
These restrictions are imposed by the Nextor architecture.

If B=3 at input, the file whose name or FIB is passed in HL will be mounted in the drive; file mounting is available since Nextor 2.1.0. A .BFSZ error will be returned if the file is too small or too big.
If B=3 at input, the file whose name or FIB is passed in HL will be mounted in the drive; file mounting is available since Nextor 2.1.0, and since Nextor 2.1.1 a file needs to be stored across consecutive sectors in its host filesystem to be mountable. A .BFSZ error will be returned if the file is too small (less than 512 bytes) or too big (more than 32 MBytes). A .ICLUS error will be returned if the file is not stored across consecutive sectors.


### 3.13. Enable or disable the Z80 access mode for a driver (_Z80MODE, 7Dh)
Expand Down Expand Up @@ -754,9 +763,9 @@ An attempt to open or alter a mounted file, or to perform any other disallowed o

Attempt to mount a file that is smaller than 512 bytes or larger than 32 MBytes.

* Invalid cluster number (.ICLUS, 0B0h)
* Invalid cluster number or sequence (.ICLUS, 0B0h)

The cluster number supplied to the [_GETCLUS](#314-get-information-for-a-cluster-on-a-fat-drive-_getclus-7eh) function doesn't exist in the drive.
The cluster number supplied to the [_GETCLUS](#314-get-information-for-a-cluster-on-a-fat-drive-_getclus-7eh) function doesn't exist in the drive, or a file was supplied to [_MAPDRV](#312-map-a-drive-letter-to-a-driver-and-device-_mapdrv-7ch) to be mounted but the file is not stored across consecutive sectors in its host filesystem.


## 5. Extended mapper support routines
Expand Down Expand Up @@ -1001,11 +1010,21 @@ This section contains the change history for the different versions of Nextor. O

This list contains the changes for the 2.1 branch only. For the change history of the 2.0 branch see the _[Nextor 2.0 Programmers Reference](../../../blob/v2.0/docs/Nextor%202.0%20Programmers%20Reference.md#7-change-history)_ document.

### 8.1. v2.1.0 beta 2
### 8.1. v2.1.1 beta 2

* [_GDLI](#39-get-information-about-a-drive-letter-_gdli-79h) returns two new fields, "start cluster" and "start sector", when a file is mounted.

### 8.2. v2.1.0 RC 1

* [_GETCLUS](#314-get-information-for-a-cluster-on-a-fat-drive-_getclus-7eh) function call introduced.
* [UNAPI RAAM helper compatible routines](#5-extended-mapper-support-routines) have been added.
* Extra mapper support routines `ALL_BK` and `FRE_BK` have been removed.

### 8.3. v2.1.0 beta 2

* [_GPART](#310-get-information-about-a-device-partition-_gpart-7ah) now returns the status byte of the partition, and allows to retrieve the device sector number that holds the partition table entry instead of information about the partition.

### 8.2. v2.1.0 beta 1
### 8.4. v2.1.0 beta 1

* [_GDRVR](#38-get-information-about-a-device-driver-_gdrvr-78h) now returns an extra flag that tells if the driver implements the DRV_CONFIG routine.

Expand Down
8 changes: 7 additions & 1 deletion docs/Nextor 2.1 User Manual.md
Expand Up @@ -966,6 +966,10 @@ An attempt to open or alter a mounted file, or to perform any other disallowed o

Thrown by the CALL MAPDRV command when attempting to mount a file that is smaller than 512 bytes or larger than 32 MBytes.

* Invalid cluster sequence (82)

Thrown by the CALL MAPDRV command when attempting to mount a file that is not stored across consecutive sectors in its host filesystem.


### 3.8. Mounting files

Expand All @@ -975,7 +979,9 @@ To mount a file, use [the MAPDRV tool](#341-mapdrv-the-drive-mapping-tool) with

This feature has some restrictions:

* To be mountable a disk image file must have a size of at least 512 bytes and at most 32 MBytes.
* The file must have a size of at least 512 bytes and at most 32 MBytes.

* The file must be stored across consecutive sectors in its host filesystem (since Nextor 2.1.1).

* The file is expected to contain a proper FAT filesystem already, it is not possible to apply the FORMAT command on a mounted drive.

Expand Down
8 changes: 4 additions & 4 deletions source/kernel/bank0/dosboot.mac
Expand Up @@ -318,14 +318,14 @@ retry_dos2:
;
msxdos_bootok:
ld de,100h
ld hl,3F00h ;Try to read the file in at
ld c,_READ## ; 100h up to the top of
ld hl,3F00h ;Try to read the file in at
ld c,_READ## ; 100h up to the top of
push bc ; page-0.
call BOOT_BDOS
pop bc
push af
ld c,_CLOSE##
call BOOT_BDOS ;Close the file handle
call BOOT_BDOS ;Close the file handle
pop af
jr nz,msxdos_fail ;Jump if the read was no good
;
Expand All @@ -341,7 +341,7 @@ endif
jp 100h ;Start up MSXDOS.SYS
;
msxdos_fail:
ret
ret
;
;
BOOT_NAME: db "\NEXTOR.SYS",0
Expand Down
7 changes: 5 additions & 2 deletions source/kernel/bank0/dskbasic.mac
Expand Up @@ -3555,7 +3555,7 @@ DBABORT_ROUTINE:
;
; Analyze errors returned from BDOS call
;
.FRSTER equ 0B1h ;0BAh ; lowest MSXDOS2 error code supported
.FRSTER equ 0B0h ;0BAh ; lowest MSXDOS2 error code supported
;
DERNUM macro ERRNAM
ifidn <ERRNAM>,<*>
Expand All @@ -3570,6 +3570,7 @@ QQQQ defl .FRSTER
;
DERR_TAB:

DERNUM ERRICL ; Invalid cluster sequence
DERNUM ERRBFS ; Bad file size
DERNUM ERRFIM ; File is mounted

Expand Down Expand Up @@ -3728,6 +3729,7 @@ QQQQ defl DERFST

DERMAK ERRFIM ; File is mounted
DERMAK ERRBFS ; Bad file size
DERMAK ERRICL ; Invalid cluster sequence
;
DERLST equ QQQQ-1 ;
;
Expand Down Expand Up @@ -4126,8 +4128,9 @@ DERMSG: defb 0

defb 'File is mounted', 0
defb 'Bad file size', 0
defb 'Invalid cluster sequence',0

; '----+----1----+----2----'
; '----+----1----+----2----'
;
MAXMSGLEN equ 24+2 ;2 extra spaces are for terminators

Expand Down
8 changes: 0 additions & 8 deletions source/kernel/bank1/mapinit.mac
Expand Up @@ -223,14 +223,6 @@ zero_p2_loop: ld (hl),0 ; data segment up to the
ld (RAM_PTR##),hl ; to point to an end of chain
; marker at the bottom of all
; the fixed variables.
ld hl,0
ld (MHANDLES##),hl
ld (MHANDLES##+2),hl
ld (MHANDLES##+4),hl
ld (MHANDLES##+6),hl
ld a,h
ld (RW_LEVEL##),a
ld (BF_LEVEL##),a
;
;
; ***** SETUP MAP_TBL AND SEGMENT LISTS IN PAGE-2 *****
Expand Down
4 changes: 2 additions & 2 deletions source/kernel/bank1/msg.mac
Expand Up @@ -239,7 +239,7 @@ ERR_MSG_TABLE:
err .PUSED, <"Partition is already in use">
err .FMNT, <"File is mounted">
err .BFSZ, <"Bad file size">
err .ICLUS, <"Invalid cluster number">
err .ICLUS, <"Invalid cluster number or sequence">
;
;
; The following are errors which the KBDOS may pass to the ABORT routine.
Expand Down Expand Up @@ -439,7 +439,7 @@ ERR_KMSG_TABLE:
err .PUSED, <"�p�[�e�B�V�������g�p���ł�"> ;<"Partition is already in use">
err .FMNT, <"�t�@�C�����}�E���g����Ă��܂�"> ;<"File is mounted">
err .BFSZ, <"�����ȃt�@�C���T�C�Y"> ;<"Bad file size">
err .ICLUS, <"�����ȃN���X�^�[�ԍ�"> ;<"Invalid cluster number">
err .ICLUS, <"�����ȃN���X�^�[�ԍ��܂��̓V�[�P���X"> ;<"Invalid cluster number or sequence">
;
;
; The following are errors which the KBDOS may pass to the ABORT routine.
Expand Down
63 changes: 3 additions & 60 deletions source/kernel/bank2/buf.mac
Expand Up @@ -117,8 +117,6 @@ endif
;
pop hl ;HL -> first buffer on chain

call ADJ_BUF_NUM

inc hl
inc hl
bit 7,(hl) ;Look at unit number and
Expand Down Expand Up @@ -220,7 +218,7 @@ bf_multi_read: push de ;Save registers which are
;===== end mod DOS2.50
ld a,RD_CMD## ;Get READ command code

call DO_RW ;Try to read the sector
pcall RW_UNIT ;Try to read the sector

pop bc ;Get copy count & separation
pop de ;Get sector number back
Expand Down Expand Up @@ -256,9 +254,7 @@ already_in_buf: pop bc ;Clean up stack
set FF_DBUF,(iy+@FAT_FLAGS##);Directory buffer not cached
ld (B_CACHE##),hl ;Record buffer as cache

ld a,(BF_LEVEL##)
or a
call z,BF_END ;Put buffer on end of chain
call BF_END ;Put buffer on end of chain
;
xor a
ret ;Return Z-set (for DIRTY_DISK)
Expand Down Expand Up @@ -708,8 +704,6 @@ bf_find_loop: ld e,(hl) ;Get next buffer address (BD_LINK)
; BD_EX_SECT=8
;
;
call ADJ_BUF_NUM

set FF_DBUF,(iy+@FAT_FLAGS##) ;Set directory buffer flag
;
push hl ;Save buffer pointer
Expand Down Expand Up @@ -786,7 +780,7 @@ bf_flush_loop: push de ;Save registers which are
;; ld c,a
;===== end mod DOS2.50
ld a,WR_CMD## ;A:=write command code
call DO_RW ;Call the unit handler
pcall RW_UNIT ;Call the unit handler
pop bc
pop de ;Restore parameters
;
Expand Down Expand Up @@ -844,57 +838,6 @@ pop_hl_ret: pop hl ;Restore buffer pointer
;
;------------------------------------------------------------------------------
;
;Read or write unit with adjustment of BF_LEVEL.
;
;If a file is mounted, the call to RW_UNIT por pre-read/write
;will cause the BF_FLUSH or BF_SECTOR routine to re-enter.
;We use the BF_LEVEL variable to keep track of when that happens
;and act accordingly (see ADJ_BUF_NUM below).
;
;Input, output, modifies: same as RW_UNIT.
DO_RW:
push af
ld a,(BF_LEVEL##)
inc a
ld (BF_LEVEL##),a ;To support re-enter check
pop af

pcall RW_UNIT ;Try to read the sector

push af
ld a,(BF_LEVEL##)
dec a
ld (BF_LEVEL##),a
pop af

ret


;Adjust sector buffer pointer if necessary.
;
;If a file is mounted, the call to RW_UNIT por pre-read/write
;will cause the BF_FLUSH or BF_SECTOR routine to re-enter.
;In that case, the first buffer in the chain will end up having
;a wrong combination of unit+sector number and actual sector data.
;To prevent this, we check if we are re-entering,
;and in this case we use the second buffer in the chain
;instead of the first one.
;
;Input: HL = Pointer to sector buffer.
;Output: HL = Pointer to same sector buffer,
; if case of routine re-entrance.
;Modifies: AF

ADJ_BUF_NUM:
ld a,(BF_LEVEL##)
or a
ret z
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
ret

finish <BUF>
end
;

0 comments on commit 0334c7a

Please sign in to comment.