13 #include <sys/types.h>
16 #include "adf_nativ.h"
19 extern struct Env adfEnv
;
24 * must fill 'dev->size'
26 static RETCODE
myInitDevice(struct Device
* dev
, char* name
,BOOL ro
)
28 struct nativeDevice
* nDev
;
32 fd
= open(name
, (ro
? O_RDONLY
: O_RDWR
));
34 (*adfEnv
.eFct
)("myInitDevice : open");
38 nDev
= (struct nativeDevice
*)malloc(sizeof(struct nativeDevice
));
40 (*adfEnv
.eFct
)("myInitDevice : malloc");
43 dev
->nativeDev
= nDev
;
45 /* check if device is writable, if not, force readOnly to TRUE */
46 dev
->readOnly
= FALSE
;
48 /* mount device as read only */
51 nDev
->fd
= fdopen(fd
, ro
? "rb" : "wb+");
52 size
= lseek(fd
, 0, SEEK_END
);
56 dev
->cylinders
= size
/ 512 / dev
->sectors
/ dev
->heads
;
57 dev
->size
= dev
->cylinders
* dev
->heads
* dev
->sectors
* 512;
58 dev
->isNativeDev
= TRUE
;
68 static RETCODE
myReadSector(struct Device
*dev
, long n
, int size
, unsigned char* buf
)
70 struct nativeDevice
*nDev
= dev
->nativeDev
;
71 int fd
= fileno(nDev
->fd
);
73 if (lseek(fd
, (off_t
)n
* 512, SEEK_SET
) != (off_t
)-1)
74 if (read(fd
, buf
, size
) == size
)
85 static RETCODE
myWriteSector(struct Device
*dev
, long n
, int size
, unsigned char* buf
)
87 struct nativeDevice
*nDev
= dev
->nativeDev
;
88 int fd
= fileno(nDev
->fd
);
90 if (lseek(fd
, (off_t
)n
* 512, SEEK_SET
) != (off_t
)-1)
91 if (write(fd
, buf
, size
) == size
)
103 static RETCODE
myReleaseDevice(struct Device
*dev
)
105 struct nativeDevice
* nDev
;
107 nDev
= (struct nativeDevice
*)dev
->nativeDev
;
120 BOOL
myIsDevNative(char *devName
)
122 return (strncmp(devName
,"/dev/",5)==0);
129 void adfInitNativeFct()
131 struct nativeFunctions
*nFct
;
133 nFct
= (struct nativeFunctions
*)adfEnv
.nativeFct
;
135 nFct
->adfInitDevice
= myInitDevice
;
136 nFct
->adfNativeReadSector
= myReadSector
;
137 nFct
->adfNativeWriteSector
= myWriteSector
;
138 nFct
->adfReleaseDevice
= myReleaseDevice
;
139 nFct
->adfIsDevNative
= myIsDevNative
;
142 /*##########################################################################*/