Tvůrce webu je i pro tebe! Postav třeba web. Bez grafika. Bez kodéra. Hned.
wz

<< Zpět

česky: , English:

FILE

Soubory

Litos8 podporuje souborové systémy FAT12 a FAT16. K zařízením a adresářům může přistupovat stejným způsobem jako k souborům, tj. sekvenčně z nich číst a zapisovat. Proto je při použití souborových funkcí potřebná zvýšená opatrnost, aby nedošlo k nežádoucímu zápisu do adresáře, disku nebo paměti.

Jména zařízení:

Jména zařízení jsou vždy ukončena dvojtečkou ":". Na velikosti písmen ve jménu zařízení nezáleží. Adresáře lze uvádět pouze u systémových disků (A: .. P:). Např. "C:\" otevře root adresář disku C:.

Cestu k souboru lze zadávat buď absolutně (např. "C:\TEST\List.txt") nebo relativně k aktuálnímu adresáři. Při relativním zápisu označuje zápis "." aktuální adresář a ".." nadřazený adresář. Na velikosti písmen ve jménech souborů a adresářů nezáleží. V cestě lze používat jako oddělovač jak znaky "/", tak znaky "\", systém však přednostně používá znaky "\" (podle konvencí DOS).

Ve jménech souborů a adresářů lze používat zástupné symboly "*" (=hvězdička, jakákoliv skupina znaků) a "?" (=jakýkoliv jeden znak). Jméno souboru může mít 1 až 8 znaků. Za oddělovací tečkou následuje přípona 0 až 3 znaky. Zástupné symboly mohou být použity i v cestě nebo při otvírání souboru - v tom případě se použije první vyhovující položka.

Na rozdíl od systému DOS se používá pro všechny disky jeden aktuální globální adresář. Proto uvedením označení disku v cestě se automaticky přednastaví root adresář disku (zápis "C:test.txt" má stejný význam jako "C:\test.txt").

Pozor na rozdíly: "HD1:" otevře fyzický disk 80h (včetně jeho master boot sektoru), "C:" otevře systémový disk na první partition (počínaje boot sektorem na první partition), "C:\" otevře root adresář disku C:, "C:\TEST" otevře adresář TEST na disku C:, "C:\TEST\List.txt" otevře soubor v adresáři C:\TEST. Zda se jedná o zařízení, adresář nebo soubor, lze testovat atributy DIR_Device a DIR_DIR v popisovači otevřeného souboru.

V systému není nijak řešen vícenásobný přístup k souboru (např. uzamykání přístupu k souboru) ani opožděný zápis na disk. Po zápisu do souboru je nutné soubor uzavřít (nebo vyprázdnit pomocí FlushFile), aby se změny v adresářové položce přenesly na disk. Počet otevřených souborů není nijak omezen. Otevřením souboru se jen vyplní informace o souboru v uživatelském popisovači FILE, žádné další evidence o souborech si systém nevede.


GetCurPath - get current path

OUTPUT:
BX = pointer to
CTEXT with current path


SetCurPath - set current path

INPUT:
BX = pointer to
TEXT with new current path

OUTPUT:
CY = error


AbsPath - absolutize path

INPUT:
BX = pointer to
TEXT with relative path

OUTPUT:
AX = new
TEXT with absolute path (without ending "\", uppercase)
CY = error (AX = 0 on error)


OpenFile - open file

INPUT:
BX =
TEXT file name (with path)
DI = pointer to destination
FILE structure

OUTPUT:
CY = error, file not found


CreateFileDir - create and open file or directory

INPUT:
BX =
TEXT filename (with path)
DL =
attributes (incl. DIR_DIR)
DI = pointer to destination
FILE structure

OUTPUT:
CY = error


CreateFile - create and open file

INPUT:
BX =
TEXT filename (with path)
DI = pointer to destination
FILE structures

OUTPUT:
CY = error


CreateDir - create directory

INPUT:
BX =
TEXT dir name (with path)

OUTPUT:
CY = error


DeleteFileDir - delete file or directory

INPUT:
BX =
TEXT filename (with path)
DL = required
attributes
DH = mask of
attributes

OUTPUT:
CY = error


DeleteFile - delete file

INPUT:
BX =
TEXT file name (with path)

OUTPUT:
CY = error or file is R/O.


DeleteDir - delete directory

INPUT:
BX =
TEXT directory name (with path)

OUTPUT:
CY = error, directory is R/O or it is not empty.


RenameFileDir - rename file or directory (in place)

INPUT:
BX =
TEXT file name (with path)
AX =
TEXT file new name (without path, can contain ? and *)

OUTPUT:
CY = error (new name cannot be with path)


MoveFile - move file

INPUT:
BX =
TEXT file name (with path)
AX =
TEXT file new name (with path, cannot contain ? or *)

OUTPUT:
CY = error (cannot move to another disk)


ReadFile - read from file

INPUT:
DI = pointer to
FILE structure (must be open)
SI = destination buffer
CX = number of bytes

OUTPUT:
CY = error
CX = successfully readed bytes


WriteFile - write to file

INPUT:
DI = pointer to
FILE structure (must be open)
SI = source buffer
CX = number of bytes

OUTPUT:
CY = error
CX = successfully written bytes


FlushFile - flush file (write directory entry if needed)

INPUT:
DI = pointer to
FILE structure (must be open)

OUTPUT:
CY = error


CloseFile - close file

INPUT:
DI = pointer to
FILE structure (must be open)

OUTPUT:
CY = error


OpenDir - open directory

INPUT:
BX =
TEXT file name (with path)
DI = pointer to destination
FILE structure

OUTPUT:
CY = error, file not found


FindFiles - search files or directories

INPUT:
BX = TEXT filename (with path)
DL = required
attributes (incl. DIR_THISDIR and DIR_UPDIR)
DH = mask of
attributes (incl. DIR_THISDIR and DIR_UPDIR)
DI = array of
FILE structures (NULL = only get number of files)
BP = max. number of files (0 = no limit)

OUTPUT:
CY = error, file not found or some error
BP = number of files

NOTES: Deleted entry is found only if mask starts with FATDELCHAR.


FileExist - check if file or directory exists

INPUT:
BX =
TEXT directory name (with path)

OUTPUT:
CY = error, file not found
AX = number of files


FileAttr - get file attributes from FILE structure

INPUT:
DI = pointer to
FILE structure

OUTPUT:
AL = file
attributes (including DIR_THISDIR and DIR_UPDIR)


GetFileAttr - get file attributes

INPUT:
BX =
TEXT file or directory name (with path)

OUTPUT:
CY = error, file not found (AL = 0)
AL = file
attributes (incl.DIR_THISDIR and DIR_UPDIR,0 on err.)


SetFileAttr - set file attributes

INPUT:
BX =
TEXT file or directory name (with path)
AL = new file
attributes (cannot change DIR attribute)

OUTPUT:
CY = error


FileSize - get file size from FILE structure

INPUT:
DI = pointer to
FILE structure

OUTPUT:
DX:AX = file size

NOTES: Does not modify flags.


GetFileSize - get file size

INPUT:
BX =
TEXT file or directory name (with path)

OUTPUT:
CY = error, file not found (DX:AX = 0)
DX:AX = file size (0 on error)


SetFileSize - set file size

INPUT:
DI = pointer to
FILE structure
DX:AX = new file size

OUTPUT:
CY = error

NOTES: Does not initialize content of new clusters. Directory size only growths, not decreases.


FileDateTime - get file date and time from FILE structure

INPUT:
DI = pointer to
FILE structure

OUTPUT:
AL = second (0..58, can be 0..62, only even second)
CL = minute (0..59, can be 0..63)
CH = hour (0..23, can be 0..31)
DL = day (1..31, can be 0..31)
DH = month (1..12, can be 0..15)
SI = year (1980..2117)


GetFileDateTime - get file date and time

INPUT:
BX =
TEXT file or directory name (with path)

OUTPUT:
CY = error, file not found (all entries = 0)
AL = second (0..58, can be 0..62, only even second)
CL = minute (0..59, can be 0..63)
CH = hour (0..23, can be 0..31)
DL = day (1..31, can be 0..31)
DH = month (1..12, can be 0..15)
SI = year (1980..2117)


SetFileDateTime - set file date and time

INPUT:
BX =
TEXT file or directory name (with path)
AL = second (0..58, can be 0..62, only even second)
CL = minute (0..59, can be 0..63)
CH = hour (0..23, can be 0..31)
DL = day (1..31, can be 0..31)
DH = month (1..12, can be 0..15)
SI = year (1980..2117)

OUTPUT:
CY = error


FilePos - get file seek position

INPUT:
DI = pointer to
FILE structure

OUTPUT:
DX:AX = offset in file (0 on error)
CY = error (DX:AX = 0)


FileSeek - set file seek position

INPUT:
DX:AX = offset in file or in device (0 on error)
DI = pointer to
FILE structure
CL =
seek mode (SEEK_BEG, SEEK_CUR, SEEK_END)

OUTPUT:
CY = error

NOTES: Can seek behind end of file.


FileSetPos - set file seek position from begin

INPUT:
DX:AX = offset in file or in device from begin (0 on error)
DI = pointer to
FILE structure

OUTPUT:
CY = error

NOTES: Can seek behind end of file.


FileReset - reset file position to begin

INPUT:
DI = pointer to
FILE structure

OUTPUT:
CY = error


AddFileName - add filename from FILE structure

INPUT:
SI = pointer to
FILE structure
BX = destination
TEXT (filename will be added after old text)

OUTPUT:
BX = old or new pointer to
TEXT structure
CY = memory error


OpenRoot - open root directory

INPUT:
AL = system disk (0..)
DI = pointer to destination
FILE structure

OUTPUT: CY = error


ClearFileDesc - clear FILE descriptor

INPUT:
DI = pointer to
FILE structure


GetClustSect - get first absolute sector of cluster

INPUT:
AX = cluster (0=root)
BX = pointer to
SDD descriptor

OUTPUT:
DX:AX = absolute sector


PrepFileMask - prepare filename mask

INPUT:
CX = filename length
SI = filename
DI = file mask buffer (length 11 bytes: 8 name + 3 extension)

OUTPUT:
CY = mask contains "?" characters


FileSDD - get SDD descriptor from FILE structure

INPUT:
DI = pointer to
FILE structure

OUTPUT:
BX = pointer to
SDD descriptor (or NULL on CY error)
CY = error, invalid disk number (returns BX = NULL)


GetNextClust - get next FAT entry

INPUT:
AX = current cluster
BX = pointer to
SDD descriptor

OUTPUT:
AX = new cluster (-1 = end of file)
CY = error (AX undefined)


SetNextClust - set next FAT entry

INPUT:
AX = next cluster (use FAT16 constants)
DX = current cluster
BX = pointer to
SDD descriptor

OUTPUT:
CY = error

NOTES: FlushFAT need to be called after FAT operations.


FindFreeClust - find free cluster

INPUT:
BX = pointer to
SDD descriptor

OUTPUT:
AX = free cluster
CY = error (AX undefined)

NOTES: Searching from LastFreeClust position.


SetLastFree - set last free cluster

INPUT:
AX = last free cluster (2..)
BX = pointer to
SDD descriptor

NOTES: Used by FindFreeClust function.


ReadFAT - read FAT sector into cache

INPUT:
AX = relative FAT sector
BX = pointer to
SDD descriptor

OUTPUT:
SI = sector buffer SectBuf
CY = read error

NOTES: FAT buffer will be flushed if other FAT sector is needed.


WriteFAT - write FAT sector from cache

INPUT:
BX = pointer to
SDD descriptor

OUTPUT:
CY = write error (all FAT copies are invalid)

NOTES: FlushFAT should be called after all writes.


FlushFAT - write FAT sector, if it was modified

INPUT:
BX = pointer to
SDD descriptor

OUTPUT:
CY = write error (all FAT copies are invalid)


DiskFree - get free space on disk

INPUT:
AL = disk number (0..)

OUTPUT:
DX:AX = free space on disk (in bytes, 0 on error)
BX:CX = used space on disk (in bytes, 0 on error)
CY = error (DX:AX, BX:CX = 0 on error)


Some constants:

PATHCHAR: (="\") path separator
PATHCHAR2: (="/") alternative path separator
PATHMAX: (=260) max. length of current path
FATDELCHAR: (=0e5h) delete character


file seek mode:

SEEK_BEG: (=0) seek from start of file
SEEK_CUR: (=1) seek from current position
SEEK_END: (=2) seek from end


DOS directory entry DIR:

DIR_Name: (8 bytes) filename
DIR_Ext: (3 bytes) extension
DIR_Attr: (byte) attributes (see below)
DIR_Res: (10 bytes) ...reserved
DIR_Time: (word) last write time
DIR_Date: (word) last write date
DIR_Cluster: (word) start cluster
DIR_Size: (dword) file size

directory special mark (first byte of filename):

DIR_FREE: (=0) free entry
DIR_ERASE: (=0e5h) erased entry

DOS file attributes:

DIR_RO: (=B0) Read-Only
DIR_HID: (=B1) Hidden
DIR_SYS: (=B2) System
DIR_VOL: (=B3) Volume Label
DIR_DIR: (=B4) Directory
DIR_ARC: (=B5) Archive
DIR_Mask: (=B0+B1+B2+B3+B4+B5) mask of valid attributes
DIR_Device: (=B6) system internal - device
DIR_Dirty: (=B7) system internal - file is dirty
DIR_THISDIR: (=B6) search files - this directory "."
DIR_UPDIR: (=B7) search files - upper directory ".."


FILE descriptor (compatible with DIR entry):

FILE_Name: (8 bytes) filename ("\"=root, " "=closed) or device name (without ":")
FILE_Ext: (3 bytes) extension
FILE_Attr: (byte) attributes and flags (incl. DIR_Device, DIR_Dirty)
FILE_DirDW:
FILE_DirL: (word) sector with directory entry LOW
FILE_DirH: (byte) sector with directory entry HIGH
FILE_DirInx: (byte) dir entry in sector and disk;
- file: bit 0..3: index of entry in dir, bit 4..7: system disk 0..15;
- device: bit 0..3: device type (0=SYS) (bit 3: 1=char device), bit 4..7: device index 0..15
FILE_ClustDisk: (word) current abs. cluster on disk, 0 = device or root, -1 = unknown
FILE_Off: (dword, union with FILE_ClustOff and FILE_ClustFile) block device or root: current offset
FILE_ClustOff: (word) current offset in cluster
FILE_ClustFile: (word) current rel. cluster in file
FILE_Time: (word) last write time
FILE_Date: (word) last write date
FILE_Cluster: (word) start cluster (0=root)
FILE_Size: (dword) file size


Zdrojový kód FILE.ASM

<< Zpět