📄 rtfsinit.c
字号:
/******************************************************************************
PC_ERTFS_INIT() - Configure ERTFS drive letter/device mapping and initialize
device drivers.
The user must modify this code to assign parameters and bind device
driver entry points to ERTFS drive structures. The source code contains
examples for configuring each of the stock device drivers.
This routine initializes ERTFS resources and binds device drivers to drive
letters so it must must be called before any other calls to the ERTFS
API are made.
Device driver configuration block.
The ERTFS drive structure (struct ddrive) contains a section that must be
initialized by the user.
The following fields must be initialized -
register_file_address - IO address pointer that may be used by the
device driver to access the controller. For the stock set of drivers
only the IDE/ATAPI driver use this parameter.
interrupt_number - Interrupt vector number that the controller
will interrupt on.
drive_flags - The user sets bits in this field to tell ERTFS
and the device driver about the drive's properties. The device driver
uses this field to keep track of the device status.
These two bits may be set by the user in the main body of the
the pc_ertfs_init routine.
DRIVE_FLAGS_PARTITIONED - Set this bit if the device is a partitioned
device.
DRIVE_FLAGS_PCMCIA - Set this bit if the device is a pcmcia device.
ERTFS does not look at this bit. It is used ony by the device drivers.
These bits are set by device driver.
DRIVE_FLAGS_VALID - Set by the driver in the WARMSTART IO Control
call if initialization succeeded. If this flags is not set then ERTFS
will not call the driver again.
DRIVE_FLAGS_REMOVABLE - Set by the device driver init routine if the
device is removable. If this bit is set then the driver must implement
the DEVCTL_CHECKSTATUS ioctrl function.
DRIVE_FLAGS_INSERTED - This bit is used by the device driver to maintain
state information. This bit is used by the PCMCIA drivers in the
following way. The default value is ZERO. If this value is zero when the
check status IOCTRL call is made then the driver attempts to map the
device through the pcmcia controller. The pcmcia management interrupt
routine clears this bit when a card removal occurs.
partition_number - If DRIVE_FLAGS_PARTITIONED is set in the
drive_flags field then this must be initialized with the partition
number. 0,1,2 etc.
lock_unit - ERTFS maintains a set of lock semaphores to protect
controller code from code re-entrancy. This value must be initialized by
the user with the semaphore number to lock before accessing this device,
(0 to (NDRIVES-1)). If two device drivers must share the same resource and
access to that resource is not re-entrant then they should use the same
lock unit.
pcmcia_slot_number - If DRIVE_FLAGS_PCMCIA is set then this tells which
pcmcia slot. Must be (0 or 1) for the supplied PCMCIA subsystem.
pcmcia_controller_number - If DRIVE_FLAGS_PCMCIA is set then this tells
which controller. Must be (0) for the supplied PCMCIA subsystem.
pcmcia_cfg_opt_value - This is the value to be place in the card's
configuration option register by the pcmcia driver after power up.
controller_number - This is set by the user in init and used by
driver to access controller specific information. For example the ide
device driver supports two controllers. This value is used by the driver
to store controller specific data and calculate controller specific
addresses and values.
logical_unit_number - This is a logical unit number that is used only
by the device driver. For example the IDE driver uses logical unit
number 1 to access the slave drive. The floppy disk uses logical
unit 1 to access the secondary floppy.
driveno - This is the drive number that the user wishes ERTFS to access
this device as. 0 = A:, 1 = B: etc.
dev_table_drive_io - This is the io function for the device. The
function must perform the requested read or write operation and
return the correct status (TRUE for success, FALSE for failure).
By example here is the ide drive io function.
BOOLEAN ide_io(driveno, sector, buffer, count, BOOLEAN reading)
int driveno - 0 to NDRIVES == A:,B:,.. the driver calls
pc_drno_to_drive_struct(driveno) to access the drive structure.
dword sector- Starting sector number to read or write
void *buffer- Buffer to read to write from.
word count - Number of sectors to transfer
reading - True for a read request, False for a write request.
dev_table_perform_device_ioctl - This is the control interface to the
device driver.
By example here is the ide drive io control function.
int ide_perform_device_ioctl(driveno, opcode, pargs)
int driveno - 0 to NDRIVES == A:,B:,.. the driver calls
pc_drno_to_drive_struct(driveno) to access the drive structure.
int opcode - One of the following:
DEVCTL_CHECKSTATUS
DEVCTL_WARMSTART
DEVCTL_POWER_RESTORE
DEVCTL_POWER_LOSS
DEVCTL_GET_GEOMETRY
DEVCTL_FORMAT
DEVCTL_REPORT_REMOVE
PFVOID pargs - void pointer to arguments. See details below.
Here are detailed descriptions of each OPCODE and its relation
to pargs.
DEVCTL_CHECKSTATUS - Return the status of device. ERTFS calls
the driver with this opcode before it performs IO.
Note: For the CHECKSTATUS call. ERTFS will pass a BOOLEAN value
to the driver to indicate if the volume in question has unwritten
cached data that will be lost if the driver returns anything but
DEVTEST_NOCHANGE. If this value is true then the driver may
make more aggresive efforts to correct media changes. For example
by asking the user to re-insert the correct diskette or card.
The driver must return one of the following values:
DEVTEST_NOCHANGE - The device is available and no media change
has been detected since the previous CHECKSTATUS call.
DEVTEST_NOMEDIA - The device contains no media.
DEVTEST_UNKMEDIA - The device contains media but the driver
can not read or write to it.
DEVTEST_CHANGED - The device is available to but a media change
has been detected since the previous CHECKSTATUS call. ERTFS will
close out the current logical volume and re-mount the device.
DEVCTL_WARMSTART - The device driver is called with this opcode
once at startup. For non removable media the device should verify
that the device is accessable and if so set the DRIVE_FLAGS_VALID
bit. For removable media the device should verify that the device
controller is accessable and if so set the DRIVE_FLAGS_VALID and
DRIVE_FLAGS_REMOVABLE bits. pargs is not used.
DEVCTL_POWER_RESTORE - Tell the device driver that system power
has been restored. The driver should attempt to restore the
device to the "UP" state. ERTFS never calls the driver with this
opcode. System integrators may call it to inform the driver of
power restore. pargs is not used.
DEVCTL_POWER_LOSS - Tell the device driver that system power
has been lost or will soon be lost. The driver should attempt to
go into low power mode. ERTFS never calls the driver with this
opcode. System integrators may call it to inform the driver of
power loss. pargs is not used.
DEVCTL_GET_GEOMETRY - ERTFS calls this routine to get the values
it will use to partition and format volumes.
pargs points to a structure of type DEV_GEOMETRY. The driver
should fill in the values as defined below.
typedef struct dev_geometry {
- Geometry in HCN format
int dev_geometry_heads; - Must be < 256
int dev_geometry_cylinders; - Must be < 1024
int dev_geometry_secptrack; - Must be < 64
BOOLEAN fmt_parms_valid; If the device io control call sets
this TRUE then it it telling the
the format parameters are valid
and should be used. This is a way to
format floppy disks exactly as they
are formatted by dos.
FMTPARMS fmt;
} DEV_GEOMETRY;
DEVCTL_FORMAT - ERTFS calls this routine to physically
format the device. pargs points to the DEV_GEOMETRY structure
that was returned from the GET_GEOMETRY call. The device driver
should physically format the device if needed.
DEVCTL_REPORT_REMOVE - This can be called by an external
interrupt to tell the driver that the device has been removed.
The pcmcia management interrupt calls this and the pcmcia aware
drivers, PCMSRAM.C and IDE_DRV.C, clear the DRIVE_FLAGS_INSERTED
bit in the drive structure. They later query this from the
CHECKSTATUS code. pargs is not used.
*/
#include "pcdisk.h"
/* This is used only in this file set it to 0 if you don't want to
print the names of the drivers as they are mounted */
#define PRINT_DEVNAMES 1
#if (PRINT_DEVNAMES)
char *dev_name[NDRIVES];
#define SAVE_NAME(LOGIGAL_DRIVE_NUMBER,STRING) dev_name[LOGIGAL_DRIVE_NUMBER] = STRING;
#endif
BOOLEAN pc_ertfs_init(void)
{
int j;
DDRIVE *pdr;
int lock_unit = 0;
word logical_drive_number;
if (!pc_memory_init())
return(FALSE);
#if (PRINT_DEVNAMES)
for (j = 0; j < NDRIVES; j++, pdr++)
dev_name[j] = 0;
#endif
pdr = mem_drives_structures;
/* User initialization section */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -