2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
11 #include <aros/debug.h>
12 #include <aros/symbolsets.h>
13 #include <exec/errors.h>
14 #include <proto/exec.h>
16 #include "unixio_device.h"
18 static int unixdevice_Open(struct UnixDevice
*unixioDev
, struct IOStdReq
*ioreq
, STRPTR unitname
, ULONG flags
)
20 struct UnitData
*unit
;
22 D(bug("unixio.device: open UnitData %s\n", unitname
));
24 ObtainSemaphore(&unixioDev
->sigsem
);
26 unit
= (struct UnitData
*)FindName(&unixioDev
->units
, unitname
);
30 /* TODO: Check sharing permission here */
32 ReleaseSemaphore(&unixioDev
->sigsem
);
34 ioreq
->io_Unit
= (struct Unit
*)unit
;
36 ioreq
->io_Message
.mn_Node
.ln_Type
= NT_REPLYMSG
;
38 DOPEN(bug("unixio.device: in libopen func. Unit is already open\n"));
42 DOPEN(bug("unixio.device: in libopen func. Creating new UnitData ...\n"));
44 unit
= (struct UnitData
*)AllocVec(sizeof(struct UnitData
) + strlen(unitname
), MEMF_PUBLIC
);
47 unit
->fd
= Hidd_UnixIO_Open(unixioDev
->unixio
, unitname
, O_RWDR
|O_NONBLOCK
, 0755, NULL
);
50 unit
->unitNode
.ln_Name
= unit
->unitName
;
51 unit
->unixio
= unixioDev
->unixio
;
53 unit
->writeLength
= 0;
54 unit
->stopped
= FALSE
;
55 unit
->eofmode
= FALSE
;
56 NEWLIST(&unit
->readQueue
);
57 NEWLIST(&unit
->writeQueue
);
58 strcpy(unit
->unitName
, unitname
);
60 AddTail((struct List
*)&unixioDev
->units
, &UnitData
->n
);
61 ReleaseSemaphore(&unixioDev
->sigsem
);
63 ioreq
->io_Unit
= (struct Unit
*)unit
;
65 ioreq
->io_Message
.mn_Node
.ln_Type
= NT_REPLYMSG
;
71 ReleaseSemaphore(&unixioDev
->sigsem
);
72 ioreq
->io_Error
= IOERR_OPENFAIL
;
77 ADD2OPENDEV(unixdevice_Open
, 0);
79 /****************************************************************************************/
81 static int unixdevice_Close((struct UnixDevice
*unixioDev
, struct IOStdReq
*ioreq
)
83 struct UnitData
*unit
= (struct UnitData
*)ioreq
->io_Unit
;
86 D(bug("unixio.device: close unit %s\n", unit
->n
.ln_Name
));
88 ObtainSemaphore(&unixioDev
->sigsem
);
90 usecnt
= --unit
->usecount
;
93 D(bug("unixio.device: Unit is no more in use, disposing...\n"));
95 Remove(&unit
->unitNode
);
98 ReleaseSemaphore(&unixioDev
->sigsem
);
102 Hidd_UnixIO_CloseFile(unixioDev
->unixio
, unit
->fd
, NULL
);
109 ADD2CLOSEDEV(unixdevice_Close
, 0);
111 /****************************************************************************************/