Convert drivers/ and servers/ over to bsdmake
-Move libdriver to lib/ -Install all boot image services on filesystem to aid restartability
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
.include <minix.own.mk>
|
||||
|
||||
SUBDIR= csu libc libcurses libend libedit libm libsys libtimers libutil
|
||||
SUBDIR= csu libc libcurses libdriver libend libedit libm libsys \
|
||||
libtimers libutil
|
||||
|
||||
.if ${COMPILER_TYPE} == "ack"
|
||||
SUBDIR+= ack/libd ack/libe ack/libfp ack/liby
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Makefile for libdriver
|
||||
|
||||
LIB= driver
|
||||
|
||||
SRCS= driver.c drvlib.c mq.c
|
||||
|
||||
.include <minix.lib.mk>
|
||||
@@ -0,0 +1,483 @@
|
||||
/* This file contains device independent device driver interface.
|
||||
*
|
||||
* Changes:
|
||||
* Jul 25, 2005 added SYS_SIG type for signals (Jorrit N. Herder)
|
||||
* Sep 15, 2004 added SYN_ALARM type for timeouts (Jorrit N. Herder)
|
||||
* Jul 23, 2004 removed kernel dependencies (Jorrit N. Herder)
|
||||
* Apr 02, 1992 constructed from AT wini and floppy driver (Kees J. Bot)
|
||||
*
|
||||
*
|
||||
* The drivers support the following operations (using message format m2):
|
||||
*
|
||||
* m_type DEVICE IO_ENDPT COUNT POSITION HIGHPOS IO_GRANT
|
||||
* ----------------------------------------------------------------------------
|
||||
* | DEV_OPEN | device | proc nr | | | | |
|
||||
* |---------------+--------+---------+---------+--------+--------+-----------|
|
||||
* | DEV_CLOSE | device | proc nr | | | | |
|
||||
* |---------------+--------+---------+---------+--------+--------+-----------|
|
||||
* | DEV_READ_S | device | proc nr | bytes | off lo | off hi i buf grant |
|
||||
* |---------------+--------+---------+---------+--------+--------+-----------|
|
||||
* | DEV_WRITE_S | device | proc nr | bytes | off lo | off hi | buf grant |
|
||||
* |---------------+--------+---------+---------+--------+--------+-----------|
|
||||
* | DEV_GATHER_S | device | proc nr | iov len | off lo | off hi | iov grant |
|
||||
* |---------------+--------+---------+---------+--------+--------+-----------|
|
||||
* | DEV_SCATTER_S | device | proc nr | iov len | off lo | off hi | iov grant |
|
||||
* |---------------+--------+---------+---------+--------+--------+-----------|
|
||||
* | DEV_IOCTL_S | device | proc nr | request | | | buf grant |
|
||||
* |---------------+--------+---------+---------+--------+--------+-----------|
|
||||
* | CANCEL | device | proc nr | r/w | | | |
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* The file contains the following entry points:
|
||||
*
|
||||
* driver_task: called by the device dependent task entry
|
||||
* init_buffer: initialize a DMA buffer
|
||||
* mq_queue: queue an incoming message for later processing
|
||||
*/
|
||||
|
||||
|
||||
#include <minix/drivers.h>
|
||||
#include <sys/ioc_disk.h>
|
||||
#include <minix/mq.h>
|
||||
#include <minix/endpoint.h>
|
||||
#include <minix/driver.h>
|
||||
|
||||
/* Claim space for variables. */
|
||||
u8_t *tmp_buf = NULL; /* the DMA buffer eventually */
|
||||
phys_bytes tmp_phys; /* phys address of DMA buffer */
|
||||
|
||||
FORWARD _PROTOTYPE( void asyn_reply, (message *mess, int proc_nr, int r) );
|
||||
FORWARD _PROTOTYPE( int do_rdwt, (struct driver *dr, message *mp) );
|
||||
FORWARD _PROTOTYPE( int do_vrdwt, (struct driver *dr, message *mp) );
|
||||
|
||||
int device_caller;
|
||||
PRIVATE mq_t *queue_head = NULL;
|
||||
|
||||
/*===========================================================================*
|
||||
* asyn_reply *
|
||||
*===========================================================================*/
|
||||
PRIVATE void asyn_reply(mess, proc_nr, r)
|
||||
message *mess;
|
||||
int proc_nr;
|
||||
int r;
|
||||
{
|
||||
/* Send a reply using the new asynchronous character device protocol.
|
||||
*/
|
||||
message reply_mess;
|
||||
|
||||
switch (mess->m_type) {
|
||||
case DEV_OPEN:
|
||||
reply_mess.m_type = DEV_REVIVE;
|
||||
reply_mess.REP_ENDPT = proc_nr;
|
||||
reply_mess.REP_STATUS = r;
|
||||
break;
|
||||
|
||||
case DEV_CLOSE:
|
||||
reply_mess.m_type = DEV_CLOSE_REPL;
|
||||
reply_mess.REP_ENDPT = proc_nr;
|
||||
reply_mess.REP_STATUS = r;
|
||||
break;
|
||||
|
||||
case DEV_READ_S:
|
||||
case DEV_WRITE_S:
|
||||
if (r == SUSPEND)
|
||||
printf("driver_task: reviving %d with SUSPEND\n", proc_nr);
|
||||
|
||||
reply_mess.m_type = DEV_REVIVE;
|
||||
reply_mess.REP_ENDPT = proc_nr;
|
||||
reply_mess.REP_IO_GRANT = (cp_grant_id_t) mess->IO_GRANT;
|
||||
reply_mess.REP_STATUS = r;
|
||||
break;
|
||||
|
||||
case CANCEL:
|
||||
/* The original request should send a reply. */
|
||||
return;
|
||||
|
||||
case DEV_SELECT:
|
||||
reply_mess.m_type = DEV_SEL_REPL1;
|
||||
reply_mess.DEV_MINOR = mess->DEVICE;
|
||||
reply_mess.DEV_SEL_OPS = r;
|
||||
break;
|
||||
|
||||
default:
|
||||
reply_mess.m_type = TASK_REPLY;
|
||||
reply_mess.REP_ENDPT = proc_nr;
|
||||
/* Status is # of bytes transferred or error code. */
|
||||
reply_mess.REP_STATUS = r;
|
||||
break;
|
||||
}
|
||||
|
||||
r= asynsend(device_caller, &reply_mess);
|
||||
if (r != OK)
|
||||
{
|
||||
printf("driver_task: unable to asynsend to %d: %d\n",
|
||||
device_caller, r);
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* driver_task *
|
||||
*===========================================================================*/
|
||||
PUBLIC void driver_task(dp, type)
|
||||
struct driver *dp; /* Device dependent entry points. */
|
||||
int type; /* Driver type (DRIVER_STD or DRIVER_ASYN) */
|
||||
{
|
||||
/* Main program of any device driver task. */
|
||||
|
||||
int r, proc_nr;
|
||||
message mess;
|
||||
sigset_t set;
|
||||
|
||||
/* Init MQ library. */
|
||||
mq_init();
|
||||
|
||||
/* Here is the main loop of the disk task. It waits for a message, carries
|
||||
* it out, and sends a reply.
|
||||
*/
|
||||
while (TRUE) {
|
||||
/* Any queued messages? Oldest are at the head. */
|
||||
if(queue_head) {
|
||||
mq_t *mq;
|
||||
mq = queue_head;
|
||||
memcpy(&mess, &mq->mq_mess, sizeof(mess));
|
||||
queue_head = queue_head->mq_next;
|
||||
mq_free(mq);
|
||||
} else {
|
||||
int s;
|
||||
/* Wait for a request to read or write a disk block. */
|
||||
if ((s=sef_receive(ANY, &mess)) != OK)
|
||||
panic("sef_receive() failed: %d", s);
|
||||
}
|
||||
|
||||
device_caller = mess.m_source;
|
||||
proc_nr = mess.IO_ENDPT;
|
||||
|
||||
/* Now carry out the work. */
|
||||
if (is_notify(mess.m_type)) {
|
||||
switch (_ENDPOINT_P(mess.m_source)) {
|
||||
case HARDWARE:
|
||||
/* leftover interrupt or expired timer. */
|
||||
if(dp->dr_hw_int) {
|
||||
(*dp->dr_hw_int)(dp, &mess);
|
||||
}
|
||||
break;
|
||||
case CLOCK:
|
||||
(*dp->dr_alarm)(dp, &mess);
|
||||
break;
|
||||
default:
|
||||
if(dp->dr_other)
|
||||
r = (*dp->dr_other)(dp, &mess);
|
||||
else
|
||||
r = EINVAL;
|
||||
goto send_reply;
|
||||
}
|
||||
|
||||
/* done, get a new message */
|
||||
continue;
|
||||
}
|
||||
switch(mess.m_type) {
|
||||
case DEV_OPEN: r = (*dp->dr_open)(dp, &mess); break;
|
||||
case DEV_CLOSE: r = (*dp->dr_close)(dp, &mess); break;
|
||||
case DEV_IOCTL_S: r = (*dp->dr_ioctl)(dp, &mess); break;
|
||||
case CANCEL: r = (*dp->dr_cancel)(dp, &mess);break;
|
||||
case DEV_SELECT: r = (*dp->dr_select)(dp, &mess);break;
|
||||
case DEV_READ_S:
|
||||
case DEV_WRITE_S: r = do_rdwt(dp, &mess); break;
|
||||
case DEV_GATHER_S:
|
||||
case DEV_SCATTER_S: r = do_vrdwt(dp, &mess); break;
|
||||
|
||||
default:
|
||||
if(dp->dr_other)
|
||||
r = (*dp->dr_other)(dp, &mess);
|
||||
else
|
||||
r = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
send_reply:
|
||||
/* Clean up leftover state. */
|
||||
(*dp->dr_cleanup)();
|
||||
|
||||
/* Finally, prepare and send the reply message. */
|
||||
if (r == EDONTREPLY)
|
||||
continue;
|
||||
|
||||
switch (type) {
|
||||
case DRIVER_STD:
|
||||
mess.m_type = TASK_REPLY;
|
||||
mess.REP_ENDPT = proc_nr;
|
||||
/* Status is # of bytes transferred or error code. */
|
||||
mess.REP_STATUS = r;
|
||||
|
||||
/* Changed from sendnb() to asynsend() by dcvmoole on 20091129.
|
||||
* This introduces a potential overflow if a single process is
|
||||
* flooding us with requests, but we need reliable delivery of
|
||||
* reply messages for the 'filter' driver. A possible solution
|
||||
* would be to allow only one pending asynchronous reply to a
|
||||
* single process at any time. FIXME.
|
||||
*/
|
||||
r= asynsend(device_caller, &mess);
|
||||
if (r != OK)
|
||||
{
|
||||
printf("driver_task: unable to send reply to %d: %d\n",
|
||||
device_caller, r);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DRIVER_ASYN:
|
||||
asyn_reply(&mess, proc_nr, r);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
panic("unknown driver type: %d", type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*===========================================================================*
|
||||
* init_buffer *
|
||||
*===========================================================================*/
|
||||
PUBLIC void init_buffer(void)
|
||||
{
|
||||
/* Select a buffer that can safely be used for DMA transfers. It may also
|
||||
* be used to read partition tables and such. Its absolute address is
|
||||
* 'tmp_phys', the normal address is 'tmp_buf'.
|
||||
*/
|
||||
|
||||
if(!(tmp_buf = alloc_contig(2*DMA_BUF_SIZE, AC_ALIGN4K, &tmp_phys)))
|
||||
panic("can't allocate tmp_buf: %d", DMA_BUF_SIZE);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* do_rdwt *
|
||||
*===========================================================================*/
|
||||
PRIVATE int do_rdwt(dp, mp)
|
||||
struct driver *dp; /* device dependent entry points */
|
||||
message *mp; /* pointer to read or write message */
|
||||
{
|
||||
/* Carry out a single read or write request. */
|
||||
iovec_t iovec1;
|
||||
int r, opcode;
|
||||
u64_t position;
|
||||
|
||||
/* Disk address? Address and length of the user buffer? */
|
||||
if (mp->COUNT < 0) return(EINVAL);
|
||||
|
||||
/* Prepare for I/O. */
|
||||
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
|
||||
|
||||
/* Create a one element scatter/gather vector for the buffer. */
|
||||
if(mp->m_type == DEV_READ_S) opcode = DEV_GATHER_S;
|
||||
else opcode = DEV_SCATTER_S;
|
||||
|
||||
iovec1.iov_addr = (vir_bytes) mp->IO_GRANT;
|
||||
iovec1.iov_size = mp->COUNT;
|
||||
|
||||
/* Transfer bytes from/to the device. */
|
||||
position= make64(mp->POSITION, mp->HIGHPOS);
|
||||
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, position, &iovec1, 1);
|
||||
|
||||
/* Return the number of bytes transferred or an error code. */
|
||||
return(r == OK ? (mp->COUNT - iovec1.iov_size) : r);
|
||||
}
|
||||
|
||||
/*==========================================================================*
|
||||
* do_vrdwt *
|
||||
*==========================================================================*/
|
||||
PRIVATE int do_vrdwt(dp, mp)
|
||||
struct driver *dp; /* device dependent entry points */
|
||||
message *mp; /* pointer to read or write message */
|
||||
{
|
||||
/* Carry out an device read or write to/from a vector of user addresses.
|
||||
* The "user addresses" are assumed to be safe, i.e. FS transferring to/from
|
||||
* its own buffers, so they are not checked.
|
||||
*/
|
||||
static iovec_t iovec[NR_IOREQS];
|
||||
phys_bytes iovec_size;
|
||||
unsigned nr_req;
|
||||
int r, opcode;
|
||||
u64_t position;
|
||||
|
||||
nr_req = mp->COUNT; /* Length of I/O vector */
|
||||
|
||||
/* Copy the vector from the caller to kernel space. */
|
||||
if (nr_req > NR_IOREQS) nr_req = NR_IOREQS;
|
||||
iovec_size = (phys_bytes) (nr_req * sizeof(iovec[0]));
|
||||
|
||||
if (OK != sys_safecopyfrom(mp->m_source, (vir_bytes) mp->IO_GRANT,
|
||||
0, (vir_bytes) iovec, iovec_size, D)) {
|
||||
panic("bad I/O vector by: %d", mp->m_source);
|
||||
}
|
||||
|
||||
/* Prepare for I/O. */
|
||||
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
|
||||
|
||||
/* Transfer bytes from/to the device. */
|
||||
opcode = mp->m_type;
|
||||
position= make64(mp->POSITION, mp->HIGHPOS);
|
||||
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, position, iovec, nr_req);
|
||||
|
||||
/* Copy the I/O vector back to the caller. */
|
||||
if (OK != sys_safecopyto(mp->m_source, (vir_bytes) mp->IO_GRANT,
|
||||
0, (vir_bytes) iovec, iovec_size, D)) {
|
||||
panic("couldn't return I/O vector: %d", mp->m_source);
|
||||
}
|
||||
|
||||
return(r);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* no_name *
|
||||
*===========================================================================*/
|
||||
PUBLIC char *no_name()
|
||||
{
|
||||
/* Use this default name if there is no specific name for the device. This was
|
||||
* originally done by fetching the name from the task table for this process:
|
||||
* "return(tasktab[proc_number(proc_ptr) + NR_TASKS].name);", but currently a
|
||||
* real "noname" is returned. Perhaps, some system information service can be
|
||||
* queried for a name at a later time.
|
||||
*/
|
||||
static char name[] = "noname";
|
||||
return name;
|
||||
}
|
||||
|
||||
/*============================================================================*
|
||||
* do_nop *
|
||||
*============================================================================*/
|
||||
PUBLIC int do_nop(dp, mp)
|
||||
struct driver *dp;
|
||||
message *mp;
|
||||
{
|
||||
/* Nothing there, or nothing to do. */
|
||||
|
||||
switch (mp->m_type) {
|
||||
case DEV_OPEN: return(ENODEV);
|
||||
case DEV_CLOSE: return(OK);
|
||||
case DEV_IOCTL_S:
|
||||
default: printf("nop: ignoring code %d\n", mp->m_type);
|
||||
return(EIO);
|
||||
}
|
||||
}
|
||||
|
||||
/*============================================================================*
|
||||
* nop_ioctl *
|
||||
*============================================================================*/
|
||||
PUBLIC int nop_ioctl(dp, mp)
|
||||
struct driver *dp;
|
||||
message *mp;
|
||||
{
|
||||
return(ENOTTY);
|
||||
}
|
||||
|
||||
/*============================================================================*
|
||||
* nop_alarm *
|
||||
*============================================================================*/
|
||||
PUBLIC void nop_alarm(dp, mp)
|
||||
struct driver *dp;
|
||||
message *mp;
|
||||
{
|
||||
/* Ignore the leftover alarm. */
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* nop_prepare *
|
||||
*===========================================================================*/
|
||||
PUBLIC struct device *nop_prepare(device)
|
||||
{
|
||||
/* Nothing to prepare for. */
|
||||
return(NIL_DEV);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* nop_cleanup *
|
||||
*===========================================================================*/
|
||||
PUBLIC void nop_cleanup()
|
||||
{
|
||||
/* Nothing to clean up. */
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* nop_cancel *
|
||||
*===========================================================================*/
|
||||
PUBLIC int nop_cancel(struct driver *dr, message *m)
|
||||
{
|
||||
/* Nothing to do for cancel. */
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* nop_select *
|
||||
*===========================================================================*/
|
||||
PUBLIC int nop_select(struct driver *dr, message *m)
|
||||
{
|
||||
/* Nothing to do for select. */
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/*============================================================================*
|
||||
* do_diocntl *
|
||||
*============================================================================*/
|
||||
PUBLIC int do_diocntl(dp, mp)
|
||||
struct driver *dp;
|
||||
message *mp; /* pointer to ioctl request */
|
||||
{
|
||||
/* Carry out a partition setting/getting request. */
|
||||
struct device *dv;
|
||||
struct partition entry;
|
||||
int s;
|
||||
|
||||
if (mp->REQUEST != DIOCSETP && mp->REQUEST != DIOCGETP) {
|
||||
if(dp->dr_other) {
|
||||
return dp->dr_other(dp, mp);
|
||||
} else return(ENOTTY);
|
||||
}
|
||||
|
||||
/* Decode the message parameters. */
|
||||
if ((dv = (*dp->dr_prepare)(mp->DEVICE)) == NIL_DEV) return(ENXIO);
|
||||
|
||||
if (mp->REQUEST == DIOCSETP) {
|
||||
/* Copy just this one partition table entry. */
|
||||
s=sys_safecopyfrom(mp->IO_ENDPT, (vir_bytes) mp->IO_GRANT,
|
||||
0, (vir_bytes) &entry, sizeof(entry), D);
|
||||
if(s != OK)
|
||||
return s;
|
||||
dv->dv_base = entry.base;
|
||||
dv->dv_size = entry.size;
|
||||
} else {
|
||||
/* Return a partition table entry and the geometry of the drive. */
|
||||
entry.base = dv->dv_base;
|
||||
entry.size = dv->dv_size;
|
||||
(*dp->dr_geometry)(&entry);
|
||||
s=sys_safecopyto(mp->IO_ENDPT, (vir_bytes) mp->IO_GRANT,
|
||||
0, (vir_bytes) &entry, sizeof(entry), D);
|
||||
if (OK != s)
|
||||
return s;
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* mq_queue *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mq_queue(message *m)
|
||||
{
|
||||
mq_t *mq, *mi;
|
||||
|
||||
if(!(mq = mq_get()))
|
||||
panic("mq_queue: mq_get failed");
|
||||
memcpy(&mq->mq_mess, m, sizeof(mq->mq_mess));
|
||||
mq->mq_next = NULL;
|
||||
if(!queue_head) {
|
||||
queue_head = mq;
|
||||
} else {
|
||||
for(mi = queue_head; mi->mq_next; mi = mi->mq_next)
|
||||
;
|
||||
mi->mq_next = mq;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
/* IBM device driver utility functions. Author: Kees J. Bot
|
||||
* 7 Dec 1995
|
||||
* Entry point:
|
||||
* partition: partition a disk to the partition table(s) on it.
|
||||
*/
|
||||
|
||||
#include <minix/driver.h>
|
||||
#include <minix/drvlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Extended partition? */
|
||||
#define ext_part(s) ((s) == 0x05 || (s) == 0x0F)
|
||||
|
||||
FORWARD _PROTOTYPE( void extpartition, (struct driver *dp, int extdev,
|
||||
unsigned long extbase) );
|
||||
FORWARD _PROTOTYPE( int get_part_table, (struct driver *dp, int device,
|
||||
unsigned long offset, struct part_entry *table));
|
||||
FORWARD _PROTOTYPE( void sort, (struct part_entry *table) );
|
||||
|
||||
#ifndef CD_SECTOR_SIZE
|
||||
#define CD_SECTOR_SIZE 2048
|
||||
#endif
|
||||
|
||||
/*============================================================================*
|
||||
* partition *
|
||||
*============================================================================*/
|
||||
PUBLIC void partition(dp, device, style, atapi)
|
||||
struct driver *dp; /* device dependent entry points */
|
||||
int device; /* device to partition */
|
||||
int style; /* partitioning style: floppy, primary, sub. */
|
||||
int atapi; /* atapi device */
|
||||
{
|
||||
/* This routine is called on first open to initialize the partition tables
|
||||
* of a device. It makes sure that each partition falls safely within the
|
||||
* device's limits. Depending on the partition style we are either making
|
||||
* floppy partitions, primary partitions or subpartitions. Only primary
|
||||
* partitions are sorted, because they are shared with other operating
|
||||
* systems that expect this.
|
||||
*/
|
||||
struct part_entry table[NR_PARTITIONS], *pe;
|
||||
int disk, par;
|
||||
struct device *dv;
|
||||
unsigned long base, limit, part_limit;
|
||||
|
||||
/* Get the geometry of the device to partition */
|
||||
if ((dv = (*dp->dr_prepare)(device)) == NIL_DEV
|
||||
|| cmp64u(dv->dv_size, 0) == 0) return;
|
||||
base = div64u(dv->dv_base, SECTOR_SIZE);
|
||||
limit = base + div64u(dv->dv_size, SECTOR_SIZE);
|
||||
|
||||
/* Read the partition table for the device. */
|
||||
if(!get_part_table(dp, device, 0L, table)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Compute the device number of the first partition. */
|
||||
switch (style) {
|
||||
case P_FLOPPY:
|
||||
device += MINOR_fd0p0;
|
||||
break;
|
||||
case P_PRIMARY:
|
||||
sort(table); /* sort a primary partition table */
|
||||
device += 1;
|
||||
break;
|
||||
case P_SUB:
|
||||
disk = device / DEV_PER_DRIVE;
|
||||
par = device % DEV_PER_DRIVE - 1;
|
||||
device = MINOR_d0p0s0 + (disk * NR_PARTITIONS + par) * NR_PARTITIONS;
|
||||
}
|
||||
|
||||
/* Find an array of devices. */
|
||||
if ((dv = (*dp->dr_prepare)(device)) == NIL_DEV) return;
|
||||
|
||||
/* Set the geometry of the partitions from the partition table. */
|
||||
for (par = 0; par < NR_PARTITIONS; par++, dv++) {
|
||||
/* Shrink the partition to fit within the device. */
|
||||
pe = &table[par];
|
||||
part_limit = pe->lowsec + pe->size;
|
||||
if (part_limit < pe->lowsec) part_limit = limit;
|
||||
if (part_limit > limit) part_limit = limit;
|
||||
if (pe->lowsec < base) pe->lowsec = base;
|
||||
if (part_limit < pe->lowsec) part_limit = pe->lowsec;
|
||||
|
||||
dv->dv_base = mul64u(pe->lowsec, SECTOR_SIZE);
|
||||
dv->dv_size = mul64u(part_limit - pe->lowsec, SECTOR_SIZE);
|
||||
|
||||
if (style == P_PRIMARY) {
|
||||
/* Each Minix primary partition can be subpartitioned. */
|
||||
if (pe->sysind == MINIX_PART)
|
||||
partition(dp, device + par, P_SUB, atapi);
|
||||
|
||||
/* An extended partition has logical partitions. */
|
||||
if (ext_part(pe->sysind))
|
||||
extpartition(dp, device + par, pe->lowsec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*============================================================================*
|
||||
* extpartition *
|
||||
*============================================================================*/
|
||||
PRIVATE void extpartition(dp, extdev, extbase)
|
||||
struct driver *dp; /* device dependent entry points */
|
||||
int extdev; /* extended partition to scan */
|
||||
unsigned long extbase; /* sector offset of the base extended partition */
|
||||
{
|
||||
/* Extended partitions cannot be ignored alas, because people like to move
|
||||
* files to and from DOS partitions. Avoid reading this code, it's no fun.
|
||||
*/
|
||||
struct part_entry table[NR_PARTITIONS], *pe;
|
||||
int subdev, disk, par;
|
||||
struct device *dv;
|
||||
unsigned long offset, nextoffset;
|
||||
|
||||
disk = extdev / DEV_PER_DRIVE;
|
||||
par = extdev % DEV_PER_DRIVE - 1;
|
||||
subdev = MINOR_d0p0s0 + (disk * NR_PARTITIONS + par) * NR_PARTITIONS;
|
||||
|
||||
offset = 0;
|
||||
do {
|
||||
if (!get_part_table(dp, extdev, offset, table)) return;
|
||||
sort(table);
|
||||
|
||||
/* The table should contain one logical partition and optionally
|
||||
* another extended partition. (It's a linked list.)
|
||||
*/
|
||||
nextoffset = 0;
|
||||
for (par = 0; par < NR_PARTITIONS; par++) {
|
||||
pe = &table[par];
|
||||
if (ext_part(pe->sysind)) {
|
||||
nextoffset = pe->lowsec;
|
||||
} else
|
||||
if (pe->sysind != NO_PART) {
|
||||
if ((dv = (*dp->dr_prepare)(subdev)) == NIL_DEV) return;
|
||||
|
||||
dv->dv_base = mul64u(extbase + offset + pe->lowsec,
|
||||
SECTOR_SIZE);
|
||||
dv->dv_size = mul64u(pe->size, SECTOR_SIZE);
|
||||
|
||||
/* Out of devices? */
|
||||
if (++subdev % NR_PARTITIONS == 0) return;
|
||||
}
|
||||
}
|
||||
} while ((offset = nextoffset) != 0);
|
||||
}
|
||||
|
||||
/*============================================================================*
|
||||
* get_part_table *
|
||||
*============================================================================*/
|
||||
PRIVATE int get_part_table(dp, device, offset, table)
|
||||
struct driver *dp;
|
||||
int device;
|
||||
unsigned long offset; /* sector offset to the table */
|
||||
struct part_entry *table; /* four entries */
|
||||
{
|
||||
/* Read the partition table for the device, return true iff there were no
|
||||
* errors.
|
||||
*/
|
||||
iovec_t iovec1;
|
||||
u64_t position;
|
||||
static unsigned char partbuf[CD_SECTOR_SIZE];
|
||||
|
||||
position = mul64u(offset, SECTOR_SIZE);
|
||||
iovec1.iov_addr = (vir_bytes) partbuf;
|
||||
iovec1.iov_size = CD_SECTOR_SIZE;
|
||||
if ((*dp->dr_prepare)(device) != NIL_DEV) {
|
||||
(void) (*dp->dr_transfer)(SELF, DEV_GATHER_S, position, &iovec1, 1);
|
||||
}
|
||||
if (iovec1.iov_size != 0) {
|
||||
return 0;
|
||||
}
|
||||
if (partbuf[510] != 0x55 || partbuf[511] != 0xAA) {
|
||||
/* Invalid partition table. */
|
||||
return 0;
|
||||
}
|
||||
memcpy(table, (partbuf + PART_TABLE_OFF), NR_PARTITIONS * sizeof(table[0]));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sort *
|
||||
*===========================================================================*/
|
||||
PRIVATE void sort(table)
|
||||
struct part_entry *table;
|
||||
{
|
||||
/* Sort a partition table. */
|
||||
struct part_entry *pe, tmp;
|
||||
int n = NR_PARTITIONS;
|
||||
|
||||
do {
|
||||
for (pe = table; pe < table + NR_PARTITIONS-1; pe++) {
|
||||
if (pe[0].sysind == NO_PART
|
||||
|| (pe[0].lowsec > pe[1].lowsec
|
||||
&& pe[1].sysind != NO_PART)) {
|
||||
tmp = pe[0]; pe[0] = pe[1]; pe[1] = tmp;
|
||||
}
|
||||
}
|
||||
} while (--n > 0);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
inet/mq.c
|
||||
|
||||
Created: Jan 3, 1992 by Philip Homburg
|
||||
|
||||
Copyright 1995 Philip Homburg
|
||||
*/
|
||||
|
||||
#include <ansi.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <minix/config.h>
|
||||
#include <minix/const.h>
|
||||
#include <minix/type.h>
|
||||
#include <minix/ipc.h>
|
||||
#include <minix/mq.h>
|
||||
|
||||
#define MQ_SIZE 128
|
||||
|
||||
PRIVATE mq_t mq_list[MQ_SIZE];
|
||||
PRIVATE mq_t *mq_freelist;
|
||||
|
||||
void mq_init()
|
||||
{
|
||||
int i;
|
||||
|
||||
mq_freelist= NULL;
|
||||
for (i= 0; i<MQ_SIZE; i++)
|
||||
{
|
||||
mq_list[i].mq_next= mq_freelist;
|
||||
mq_freelist= &mq_list[i];
|
||||
mq_list[i].mq_allocated= 0;
|
||||
}
|
||||
}
|
||||
|
||||
mq_t *mq_get()
|
||||
{
|
||||
mq_t *mq;
|
||||
|
||||
mq= mq_freelist;
|
||||
assert(mq != NULL);
|
||||
|
||||
mq_freelist= mq->mq_next;
|
||||
mq->mq_next= NULL;
|
||||
assert(mq->mq_allocated == 0);
|
||||
mq->mq_allocated= 1;
|
||||
return mq;
|
||||
}
|
||||
|
||||
void mq_free(mq)
|
||||
mq_t *mq;
|
||||
{
|
||||
mq->mq_next= mq_freelist;
|
||||
mq_freelist= mq;
|
||||
assert(mq->mq_allocated == 1);
|
||||
mq->mq_allocated= 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: mq.c,v 1.7 1998/10/23 20:10:47 philip Exp $
|
||||
*/
|
||||
Reference in New Issue
Block a user