Class WinDir
WinDriver.HEADER_LENGTH
bytes long. The first entry in the directory contains rubbish,
as that would be the file header of this directory (file).
The content (structure) of the file entry/header is explained below but it contains at least the length of the file and its name. The length of the file in the directory entry comprises that of the file header.
In a directory entry, if a file has a length of 0, then this is an empty entry in the directory, since a valid file always has a length of, at least,
WinDriver.HEADER_LENGTH
bytes (length of the header).
When the fileheader is returned to SMSQE, WinDriver.HEADER_LENGTH
bytes are deducted from the length of the file as contained in the
directory header to make the "real" length of the file as SMSQE sees it.
Creating a directory should go as follows : open file with opentype #2. call trap #3 with $4d, close file.
Directories may grow, but they never shrink (unless, if entirely empty, they are totally deleted).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from class drivers.win.WinFile
buffer, clusterchain, dir, dirChanged, drive, fileChanged, filePosition, fileSize, index, isDir, mapChanged, readOnly, setDate
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
checkFile
(boolean[] flags, byte[] fname) This checks whether a file of that name already exists in this dir.void
closeFile
(int entry, boolean dirChanged, boolean setDate) Does what is necessary when a file is closed: set file size, date etc...int
deleteFile
(int entry) Deletes a file from this directory (and thus from the disk).boolean
fileIsDir
(int index) Checks whether the file at (index) is a directory.int
Finds the first free entry in my buffer.findInDirs
(byte[] fname) Finds out whether a file belongs in this dir or any of its subdirs.Gets the ByteBuffer containing the data in this dir.int
getFileDate
(int whatDate) Gets the date of the file.int
getFileLength
(int index) Gets the length of a file at (index).int
getFileVersion
(int entry) Gets the version of the file.byte[]
getName()
Gets the name of this directory.byte[]
Gets the lower cased name of this file.boolean
makeDirectory
(int entry, ArrayList<Integer> cchain, ByteBuffer buf) This converts an existing file contained in a parent directory (this object) into a subdirectory thereof.openFile
(int entry, byte[] filename, int openType, MC68000Cpu cpu) Opens a file.void
Recursively removes all subdirectories from ythis dir (and all subdirs).void
removeFromList
(WinDir toRemove) Remove a dir from my dir list.void
renameFile
(WinDir oldDir, WinFile wFile, byte[] fname) Renames/moves a file from an old directory to this new one.void
setFileDate
(int entry, int mdate) Sets the date of the file.void
setFileHeader
(int entry, MC68000Cpu cpu, int length) Sets the header for a file (always 14 bytes).void
setFileVersion
(int entry, int version) Sets the version of the file.void
setInHeader
(int offset, int longword) Sets a long word in a header.Methods inherited from class drivers.win.WinFile
close, getDir, getIndex, handleTrap3, setDir, setDirAndFatChanged, setDirStatus, setIndex, writeFile
-
Field Details
-
HDR_FLEN
public static final int HDR_FLEN- See Also:
-
HDR_ACCS
public static final int HDR_ACCS- See Also:
-
HDR_TYPE
public static final int HDR_TYPE- See Also:
-
HDRTEXE
public static final int HDRTEXE- See Also:
-
HDRTREL
public static final int HDRTREL- See Also:
-
HDRTLDR
public static final int HDRTLDR- See Also:
-
HDRTDIR
public static final int HDRTDIR- See Also:
-
HDR_INFO
public static final int HDR_INFO- See Also:
-
HDR_DATA
public static final int HDR_DATA- See Also:
-
HDR_XTRA
public static final int HDR_XTRA- See Also:
-
HDR_NAME
public static final int HDR_NAME- See Also:
-
HDRNAMEL
public static final int HDRNAMEL- See Also:
-
HDRNAME
public static final int HDRNAME- See Also:
-
HDRNMLN
public static final int HDRNMLN- See Also:
-
HDR_DATE
public static final int HDR_DATE- See Also:
-
HDR_VERS
public static final int HDR_VERS- See Also:
-
HDR_FLID
public static final int HDR_FLID- See Also:
-
HDR_BKUP
public static final int HDR_BKUP- See Also:
-
HDR_END
public static final int HDR_END- See Also:
-
-
Constructor Details
-
WinDir
public WinDir(WinDrive drive, WinDir parentDir, int index, ByteBuffer buf, ArrayList<Integer> cchain, byte[] name, byte[] normalizedName) This creates the directory object.- Parameters:
drive
- the drive on which this dir lies.parentDir
- the dir containing this dir, will be null if this is the root directory.index
- index into the parent dir (offset from start of parent dir buffer to my header). Will be 0 isf this is the root directory.buf
- the ByteBuffer containg this entire dir.cchain
- the clusterchain for this directory.name
- the name for this dir.normalizedName
- the name of this dir in SMSQE lower case.
-
-
Method Details
-
openFile
Opens a file. The caller has checked that the type of open requested is possible.- Parameters:
entry
- the index into the buffer of the file to open - 0 if the file doesn't exist yet.filename
- the name of the file as it appears in the open call. The length will be 0 for the main directory.openType
- the type of open wished.cpu
- the cpu to be used.- Returns:
- the file if file open went ok, else null.
-
closeFile
public void closeFile(int entry, boolean dirChanged, boolean setDate) Does what is necessary when a file is closed: set file size, date etc...- Parameters:
entry
- entry in this bufferdirChanged
- =true
if this dir should save itself to disk since something in it has changed.setDate
- set totrue
if the file date should be set in the file's header (which it shouldn't if the file is read only).
-
deleteFile
public int deleteFile(int entry) Deletes a file from this directory (and thus from the disk). The drive object itself handles whether or not its map should be saved.- Parameters:
entry
- the entry to delete. If this is 0, the dir is supposed to delete itself.- Returns:
- either Types.ERR_xxxx values if unsuccessful (all smaller than 0) or the 1st cluster of the file to be deleted.
-
makeDirectory
This converts an existing file contained in a parent directory (this object) into a subdirectory thereof. The caller MUST already have checked that the file in question CAN legally be converted into a dir.This is NOT checked here again!!!!
- Parameters:
entry
- where this file header is in the parent dir's buffer.cchain
- the file's clusterchain - this might have to be increased.buf
- the file's buffer (i.e. the file's data on the disk) -I might have to increase this.- Returns:
false
if error,true
if conversion file to dir went OK.
-
renameFile
Renames/moves a file from an old directory to this new one. Note the current object (=this) is the new dir.- Parameters:
oldDir
- the directory currently holding this file.wFile
- the file to be renamed.fname
- the new name of the file.
-
setFileHeader
Sets the header for a file (always 14 bytes).- Parameters:
entry
- where in the dir buffer is the header to be set.cpu
- the SMSQ/E CPU - A1 points to the data for the file header. MUST BE AT AN EVEN ADDRESS!!!!!!length
- the length of the file.
-
setInHeader
public void setInHeader(int offset, int longword) Sets a long word in a header.- Parameters:
offset
- where to set the element (i.e. index+entry in header).longword
- what to set.
-
fileIsDir
public boolean fileIsDir(int index) Checks whether the file at (index) is a directory.- Parameters:
index
- index into this buffer, where the file to check lies (should be multiple of Windriver.HEADER_LENGTH).- Returns:
true
if this is a (sub)directory, elsefalse
-
getFileLength
public int getFileLength(int index) Gets the length of a file at (index).- Parameters:
index
- where the file lies in the directory.- Returns:
- the length of the file or 0 if the index would be beyond the end of the file.
-
getFileVersion
public int getFileVersion(int entry) Gets the version of the file.- Parameters:
entry
- where the file lies in the directory.- Returns:
- the file version.
-
setFileVersion
public void setFileVersion(int entry, int version) Sets the version of the file.- Parameters:
entry
- where the file lies in the directory.version
- the file version to set.
-
getFileDate
public int getFileDate(int whatDate) Gets the date of the file.- Parameters:
whatDate
- what date to get (i.e. index+date to get -upate or backup date).- Returns:
- the date.
-
setFileDate
public void setFileDate(int entry, int mdate) Sets the date of the file.- Parameters:
entry
- what date to set (i.e. index+date to get -upate or backup date).mdate
- the date in QL format.
-
findInDirs
Finds out whether a file belongs in this dir or any of its subdirs. This does not mean that the file ACTUALLY EXISTS in this dir, but if it were to exists on the drive it would be here.- Parameters:
fname
- the lower cased name of the file.- Returns:
- the dir this file belongs in, null if not in this dir or any of its subdirs.
-
checkFile
public int checkFile(boolean[] flags, byte[] fname) This checks whether a file of that name already exists in this dir.- Parameters:
flags
- a (return) array of booleans which will be filled in this method : [0] true if file exists in this dir. [1] true if file is a dir. [2] true if file can't be written to. [3] true if file has channels open to it. This method does NOT check that the flag array is of a correct size!!fname
- : the uncased name of the file (SMSQE lower case)- Returns:
- the entry in this dir (=offset from start of buffer) or 0 if file is not found in this directory. Note the side-effect of filling the flags array.
-
findFreeEntryInDir
public int findFreeEntryInDir()Finds the first free entry in my buffer. An entry is considered to be free if : length of file=0 and length of filename=0. If no entry is free, the fileSize may grow either by using the remaining space in the buffer, or by adding a new cluster to the dir.- Returns:
- the index into the buffer where the first free entry lies, or -1 if no free entry could be found.
-
removeFromList
Remove a dir from my dir list. This means that that dir is no longer a subdir of mine.- Parameters:
toRemove
- the WinDir to remove.
-
getName
public byte[] getName()Gets the name of this directory.- Returns:
- the name as an array of bytes.
-
getUncasedName
public byte[] getUncasedName()Gets the lower cased name of this file.- Returns:
- the name as an array of SMSQE lower cased bytes.
-
getDirBuffer
Gets the ByteBuffer containing the data in this dir. Be careful what you do with that.- Returns:
- this directory's ByteBuffer.
-
removeAllSubdirs
public void removeAllSubdirs()Recursively removes all subdirectories from ythis dir (and all subdirs).
-