2009-05-02 23:03:37 +02:00
|
|
|
/*
|
2009-05-03 00:28:34 +02:00
|
|
|
* Copyright (C) 2002-2007 The DOSBox Team
|
2009-05-02 23:03:37 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-05-03 00:02:15 +02:00
|
|
|
* GNU General Public License for more details.
|
2009-05-02 23:03:37 +02:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
/* $Id: dos_system.h,v 1.39 2007/01/21 16:21:22 c2woody Exp $ */
|
2009-05-03 00:18:08 +02:00
|
|
|
|
|
|
|
#ifndef DOSBOX_DOS_SYSTEM_H
|
|
|
|
#define DOSBOX_DOS_SYSTEM_H
|
2009-05-02 23:43:00 +02:00
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
#include <vector>
|
2009-05-03 00:18:08 +02:00
|
|
|
#ifndef DOSBOX_DOSBOX_H
|
2009-05-02 23:20:05 +02:00
|
|
|
#include "dosbox.h"
|
2009-05-03 00:18:08 +02:00
|
|
|
#endif
|
|
|
|
#ifndef DOSBOX_CROSS_H
|
2009-05-02 23:35:44 +02:00
|
|
|
#include "cross.h"
|
2009-05-03 00:18:08 +02:00
|
|
|
#endif
|
2009-05-03 00:28:34 +02:00
|
|
|
#ifndef DOSBOX_SUPPORT_H
|
|
|
|
#include "support.h"
|
|
|
|
#endif
|
|
|
|
#ifndef DOSBOX_MEM_H
|
|
|
|
#include "mem.h"
|
|
|
|
#endif
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
#define DOS_NAMELENGTH 12
|
2009-05-02 23:20:05 +02:00
|
|
|
#define DOS_NAMELENGTH_ASCII (DOS_NAMELENGTH+1)
|
|
|
|
#define DOS_FCBNAME 15
|
|
|
|
#define DOS_DIRDEPTH 8
|
|
|
|
#define DOS_PATHLENGTH 80
|
2009-05-02 23:03:37 +02:00
|
|
|
#define DOS_TEMPSIZE 1024
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DOS_ATTR_READ_ONLY= 0x01,
|
|
|
|
DOS_ATTR_HIDDEN= 0x02,
|
|
|
|
DOS_ATTR_SYSTEM= 0x04,
|
|
|
|
DOS_ATTR_VOLUME= 0x08,
|
|
|
|
DOS_ATTR_DIRECTORY= 0x10,
|
|
|
|
DOS_ATTR_ARCHIVE= 0x20
|
|
|
|
};
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
struct FileStat_Block {
|
|
|
|
Bit32u size;
|
2009-05-02 23:03:37 +02:00
|
|
|
Bit16u time;
|
|
|
|
Bit16u date;
|
2009-05-02 23:20:05 +02:00
|
|
|
Bit16u attr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DOS_DTA;
|
2009-05-02 23:03:37 +02:00
|
|
|
|
|
|
|
class DOS_File {
|
|
|
|
public:
|
2009-05-03 00:28:34 +02:00
|
|
|
DOS_File():flags(0) { name=0; refCtr = 0; hdrive=0xff; };
|
2009-05-03 00:08:43 +02:00
|
|
|
DOS_File(const DOS_File& orig);
|
|
|
|
DOS_File & operator= (const DOS_File & orig);
|
2009-05-03 00:02:15 +02:00
|
|
|
virtual ~DOS_File(){if(name) delete [] name;};
|
2009-05-02 23:35:44 +02:00
|
|
|
virtual bool Read(Bit8u * data,Bit16u * size)=0;
|
|
|
|
virtual bool Write(Bit8u * data,Bit16u * size)=0;
|
|
|
|
virtual bool Seek(Bit32u * pos,Bit32u type)=0;
|
|
|
|
virtual bool Close()=0;
|
|
|
|
virtual Bit16u GetInformation(void)=0;
|
|
|
|
virtual void SetName(const char* _name) { if (name) delete[] name; name = new char[strlen(_name)+1]; strcpy(name,_name); }
|
|
|
|
virtual char* GetName(void) { return name; };
|
|
|
|
virtual bool IsOpen() { return open; };
|
2009-05-03 00:28:34 +02:00
|
|
|
virtual bool IsName(const char* _name) { if (!name) return false; return strcasecmp(name,_name)==0; };
|
2009-05-02 23:43:00 +02:00
|
|
|
virtual void AddRef() { refCtr++; };
|
|
|
|
virtual Bits RemoveRef() { return --refCtr; };
|
2009-05-03 00:02:15 +02:00
|
|
|
virtual bool UpdateDateTimeFromHost() { return true; }
|
2009-05-03 00:28:34 +02:00
|
|
|
void SetDrive(Bit8u drv) { hdrive=drv;}
|
|
|
|
Bit8u GetDrive(void) { return hdrive;}
|
2009-05-02 23:20:05 +02:00
|
|
|
Bit8u type;
|
|
|
|
Bit32u flags;
|
|
|
|
Bit16u time;
|
|
|
|
Bit16u date;
|
|
|
|
Bit16u attr;
|
|
|
|
Bit32u size;
|
2009-05-02 23:43:00 +02:00
|
|
|
Bits refCtr;
|
2009-05-02 23:35:44 +02:00
|
|
|
bool open;
|
|
|
|
char* name;
|
2009-05-02 23:03:37 +02:00
|
|
|
/* Some Device Specific Stuff */
|
2009-05-03 00:28:34 +02:00
|
|
|
private:
|
|
|
|
Bit8u hdrive;
|
2009-05-02 23:03:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class DOS_Device : public DOS_File {
|
|
|
|
public:
|
2009-05-03 00:28:34 +02:00
|
|
|
DOS_Device(const DOS_Device& orig):DOS_File(orig) {
|
|
|
|
devnum=orig.devnum;
|
|
|
|
open=true;
|
|
|
|
}
|
2009-05-03 00:08:43 +02:00
|
|
|
DOS_Device & operator= (const DOS_Device & orig) {
|
|
|
|
DOS_File::operator=(orig);
|
|
|
|
devnum=orig.devnum;
|
2009-05-03 00:28:34 +02:00
|
|
|
open=true;
|
2009-05-03 00:08:43 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
DOS_Device():DOS_File(),devnum(0){};
|
|
|
|
virtual bool Read(Bit8u * data,Bit16u * size);
|
|
|
|
virtual bool Write(Bit8u * data,Bit16u * size);
|
|
|
|
virtual bool Seek(Bit32u * pos,Bit32u type);
|
|
|
|
virtual bool Close();
|
|
|
|
virtual Bit16u GetInformation(void);
|
2009-05-03 00:28:34 +02:00
|
|
|
virtual bool ReadFromControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode);
|
|
|
|
virtual bool WriteToControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode);
|
2009-05-03 00:08:43 +02:00
|
|
|
void SetDeviceNumber(Bitu num) { devnum=num;}
|
|
|
|
private:
|
|
|
|
Bitu devnum;
|
2009-05-02 23:03:37 +02:00
|
|
|
};
|
|
|
|
|
2009-05-03 00:28:34 +02:00
|
|
|
/* The following variable can be lowered to free up some memory.
|
|
|
|
* The negative side effect: The stored searches will be turned over faster.
|
|
|
|
* Should not have impact on systems with few directory entries. */
|
2009-05-03 00:02:15 +02:00
|
|
|
#define MAX_OPENDIRS 2048
|
|
|
|
//Can be high as it's only storage (16 bit variable)
|
2009-05-03 00:28:34 +02:00
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
class DOS_Drive_Cache {
|
|
|
|
public:
|
|
|
|
DOS_Drive_Cache (void);
|
|
|
|
DOS_Drive_Cache (const char* path);
|
|
|
|
~DOS_Drive_Cache (void);
|
|
|
|
|
|
|
|
typedef enum TDirSort { NOSORT, ALPHABETICAL, DIRALPHABETICAL, ALPHABETICALREV, DIRALPHABETICALREV };
|
|
|
|
|
|
|
|
void SetBaseDir (const char* path);
|
|
|
|
void SetDirSort (TDirSort sort) { sortDirType = sort; };
|
|
|
|
bool OpenDir (const char* path, Bit16u& id);
|
|
|
|
bool ReadDir (Bit16u id, char* &result);
|
|
|
|
|
|
|
|
void ExpandName (char* path);
|
|
|
|
char* GetExpandName (const char* path);
|
|
|
|
bool GetShortName (const char* fullname, char* shortname);
|
|
|
|
|
2009-05-03 00:02:15 +02:00
|
|
|
bool FindFirst (char* path, Bitu& id);
|
2009-05-02 23:43:00 +02:00
|
|
|
bool FindNext (Bitu id, char* &result);
|
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
void CacheOut (const char* path, bool ignoreLastDir = false);
|
|
|
|
void AddEntry (const char* path, bool checkExist = false);
|
|
|
|
void DeleteEntry (const char* path, bool ignoreLastDir = false);
|
|
|
|
|
|
|
|
void EmptyCache (void);
|
2009-05-03 00:08:43 +02:00
|
|
|
void SetLabel (const char* name,bool allowupdate=true);
|
2009-05-02 23:43:00 +02:00
|
|
|
char* GetLabel (void) { return label; };
|
2009-05-02 23:35:44 +02:00
|
|
|
|
|
|
|
class CFileInfo {
|
|
|
|
public:
|
2009-05-02 23:53:27 +02:00
|
|
|
CFileInfo(void) {
|
|
|
|
orgname[0] = shortname[0] = 0;
|
2009-05-03 00:02:15 +02:00
|
|
|
nextEntry = shortNr = 0;
|
2009-05-02 23:53:27 +02:00
|
|
|
isDir = false;
|
|
|
|
}
|
2009-05-02 23:35:44 +02:00
|
|
|
~CFileInfo(void) {
|
|
|
|
for (Bit32u i=0; i<fileList.size(); i++) delete fileList[i];
|
|
|
|
fileList.clear();
|
|
|
|
longNameList.clear();
|
|
|
|
};
|
|
|
|
char orgname [CROSS_LEN];
|
|
|
|
char shortname [DOS_NAMELENGTH_ASCII];
|
|
|
|
bool isDir;
|
|
|
|
Bitu nextEntry;
|
|
|
|
Bitu shortNr;
|
|
|
|
// contents
|
|
|
|
std::vector<CFileInfo*> fileList;
|
|
|
|
std::vector<CFileInfo*> longNameList;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool RemoveTrailingDot (char* shortname);
|
2009-05-03 00:02:15 +02:00
|
|
|
Bits GetLongName (CFileInfo* info, char* shortname);
|
2009-05-02 23:35:44 +02:00
|
|
|
void CreateShortName (CFileInfo* dir, CFileInfo* info);
|
|
|
|
Bit16u CreateShortNameID (CFileInfo* dir, const char* name);
|
2009-05-03 00:02:15 +02:00
|
|
|
int CompareShortname (const char* compareName, const char* shortName);
|
|
|
|
bool SetResult (CFileInfo* dir, char * &result, Bit16u entryNr);
|
|
|
|
bool IsCachedIn (CFileInfo* dir);
|
|
|
|
CFileInfo* FindDirInfo (const char* path, char* expandedPath);
|
2009-05-02 23:35:44 +02:00
|
|
|
bool RemoveSpaces (char* str);
|
2009-05-03 00:02:15 +02:00
|
|
|
bool OpenDir (CFileInfo* dir, const char* path, Bit16u& id);
|
|
|
|
void CreateEntry (CFileInfo* dir, const char* name);
|
|
|
|
Bit16u GetFreeID (CFileInfo* dir);
|
|
|
|
void Clear (void);
|
2009-05-02 23:35:44 +02:00
|
|
|
|
|
|
|
CFileInfo* dirBase;
|
|
|
|
char dirPath [CROSS_LEN];
|
|
|
|
char basePath [CROSS_LEN];
|
|
|
|
bool dirFirstTime;
|
|
|
|
TDirSort sortDirType;
|
|
|
|
CFileInfo* save_dir;
|
|
|
|
char save_path [CROSS_LEN];
|
|
|
|
char save_expanded [CROSS_LEN];
|
|
|
|
|
|
|
|
Bit16u srchNr;
|
|
|
|
CFileInfo* dirSearch [MAX_OPENDIRS];
|
|
|
|
char dirSearchName [MAX_OPENDIRS];
|
|
|
|
bool free [MAX_OPENDIRS];
|
2009-05-02 23:43:00 +02:00
|
|
|
CFileInfo* dirFindFirst [MAX_OPENDIRS];
|
2009-05-03 00:02:15 +02:00
|
|
|
Bitu nextFreeFindFirst;
|
2009-05-02 23:35:44 +02:00
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
char label [CROSS_LEN];
|
2009-05-03 00:08:43 +02:00
|
|
|
bool updatelabel;
|
2009-05-02 23:35:44 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
class DOS_Drive {
|
|
|
|
public:
|
|
|
|
DOS_Drive();
|
2009-05-02 23:20:05 +02:00
|
|
|
virtual ~DOS_Drive(){};
|
2009-05-02 23:03:37 +02:00
|
|
|
virtual bool FileOpen(DOS_File * * file,char * name,Bit32u flags)=0;
|
|
|
|
virtual bool FileCreate(DOS_File * * file,char * name,Bit16u attributes)=0;
|
2009-05-02 23:20:05 +02:00
|
|
|
virtual bool FileUnlink(char * _name)=0;
|
|
|
|
virtual bool RemoveDir(char * _dir)=0;
|
|
|
|
virtual bool MakeDir(char * _dir)=0;
|
|
|
|
virtual bool TestDir(char * _dir)=0;
|
2009-05-03 00:02:15 +02:00
|
|
|
virtual bool FindFirst(char * _dir,DOS_DTA & dta,bool fcb_findfirst=false)=0;
|
2009-05-02 23:20:05 +02:00
|
|
|
virtual bool FindNext(DOS_DTA & dta)=0;
|
2009-05-02 23:03:37 +02:00
|
|
|
virtual bool GetFileAttr(char * name,Bit16u * attr)=0;
|
|
|
|
virtual bool Rename(char * oldname,char * newname)=0;
|
2009-05-02 23:27:47 +02:00
|
|
|
virtual bool AllocationInfo(Bit16u * _bytes_sector,Bit8u * _sectors_cluster,Bit16u * _total_clusters,Bit16u * _free_clusters)=0;
|
2009-05-02 23:20:05 +02:00
|
|
|
virtual bool FileExists(const char* name)=0;
|
|
|
|
virtual bool FileStat(const char* name, FileStat_Block * const stat_block)=0;
|
|
|
|
virtual Bit8u GetMediaByte(void)=0;
|
2009-05-02 23:35:44 +02:00
|
|
|
virtual void SetDir(const char* path) { strcpy(curdir,path); };
|
|
|
|
virtual void EmptyCache(void) { dirCache.EmptyCache(); };
|
2009-05-02 23:53:27 +02:00
|
|
|
virtual bool isRemote(void)=0;
|
2009-05-03 00:08:43 +02:00
|
|
|
virtual bool isRemovable(void)=0;
|
2009-05-03 00:28:34 +02:00
|
|
|
virtual Bits UnMount(void)=0;
|
|
|
|
|
2009-05-02 23:03:37 +02:00
|
|
|
char * GetInfo(void);
|
|
|
|
char curdir[DOS_PATHLENGTH];
|
|
|
|
char info[256];
|
2009-05-03 00:18:08 +02:00
|
|
|
/* Can be overridden for example in iso images */
|
|
|
|
virtual char const * GetLabel(){return dirCache.GetLabel();};
|
2009-05-03 00:28:34 +02:00
|
|
|
|
2009-05-02 23:35:44 +02:00
|
|
|
DOS_Drive_Cache dirCache;
|
2009-05-03 00:28:34 +02:00
|
|
|
|
|
|
|
// disk cycling functionality (request resources)
|
|
|
|
virtual void Activate(void) {};
|
2009-05-02 23:03:37 +02:00
|
|
|
};
|
|
|
|
|
2009-05-02 23:43:00 +02:00
|
|
|
enum { OPEN_READ=0,OPEN_WRITE=1,OPEN_READWRITE=2, DOS_NOT_INHERIT=128};
|
2009-05-02 23:03:37 +02:00
|
|
|
enum { DOS_SEEK_SET=0,DOS_SEEK_CUR=1,DOS_SEEK_END=2};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
A multiplex handler should read the registers to check what function is being called
|
|
|
|
If the handler returns false dos will stop checking other handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef bool (MultiplexHandler)(void);
|
|
|
|
void DOS_AddMultiplexHandler(MultiplexHandler * handler);
|
2009-05-03 00:18:08 +02:00
|
|
|
void DOS_DelMultiplexHandler(MultiplexHandler * handler);
|
2009-05-02 23:03:37 +02:00
|
|
|
|
2009-05-03 00:18:08 +02:00
|
|
|
/* AddDevice stores the pointer to a created device */
|
2009-05-02 23:03:37 +02:00
|
|
|
void DOS_AddDevice(DOS_Device * adddev);
|
2009-05-03 00:18:08 +02:00
|
|
|
/* DelDevice destroys the device that is pointed to. */
|
|
|
|
void DOS_DelDevice(DOS_Device * dev);
|
|
|
|
|
2009-05-02 23:20:05 +02:00
|
|
|
void VFILE_Register(const char * name,Bit8u * data,Bit32u size);
|
2009-05-02 23:03:37 +02:00
|
|
|
#endif
|