# Porting Linux IOCTL based applications



## kantor (Nov 17, 2008)

Hi, I wrote a program in Linux that uses specific IOCTL's specifically from the Linux SCSI subsystem the SG_IO and some other CD-ROM IOCTL's (like ejecting/closing the tray and such).
The project is at sourceforge, If you want to take a look here is the project homepage: http://odman.sourceforge.net
I'm using Linux at home, and sometimes FreeBSD. (In the last time I started to use FreeBSD more). But I have no advanced knowledge about the FreeBSD SCSI subsystem and I have no idea if it is possible to port such a program to FreeBSD, but if it's possible I would like to do it (maybe with some help).


----------



## rdivacky@ (Nov 18, 2008)

we do support linux sg device (in the native form), can your app use that?


----------



## kantor (Nov 18, 2008)

yes, and no. For instance in the program there are functionalities like reading the identify information from the device controller, or sending close/eject and such commands. In this case you can use the an sg device. But there is a transfer rate test included too. With the test you need to use a block device, the sg driver is a character device so you can't use the sg driver/device to read data from the CD/DVD. (at least this is in linux)


----------



## rdivacky@ (Nov 18, 2008)

I know no details but there are two positive news for you 

1) we dont distinguish block/char devices in fbsd anymore so it might "just work"

2) there is some ioctl translation support in the linuxulator, I dont know it might be sufficient, there are some CDROM related ioctls

just go and try that


----------



## kantor (Nov 19, 2008)

Maybe I need to do some background research in this field but I don't know if it worth's. I do not want to do useless work like porting the software to FreeBSD but nobody gonna use it


----------



## rdivacky@ (Nov 19, 2008)

well.. cant help you with that...

good luck anyway!


----------



## Mel_Flynn (Nov 19, 2008)

kantor said:
			
		

> Maybe I need to do some background research in this field but I don't know if it worth's. I do not want to do useless work like porting the software to FreeBSD but nobody gonna use it



I would start by browsing cdrecord source. Things like eject, transfer rate and so on are covered and it's written highly portable.
A good follow up may be investigating FreeBSD's camcontrol(8) sources and the cam(4) interface in general.

It would help if you posted some details about what your program can do and/or look through FreeBSD ports sysutils/ category (cdrecord, dvd+rwtools, k3b to name a few).


----------



## kantor (Nov 21, 2008)

Mel_Flynn said:
			
		

> It would help if you posted some details about what your program can do and/or look through FreeBSD ports sysutils/ category (cdrecord, dvd+rwtools, k3b to name a few).



The program uses the SG_IO ioctl or if that is too old or if it is not present falls back to CDROM_SEND_PACKET ioctl (this is in linux) 
The program can do the followings:
 - enable/disable auto eject mode
 - lock/unlock the tray
 - close/eject the tray
 - kernel level device debugging
 - device resets
 - getting the identification information from the controller
   including supported DMA/PIO modes, supported/enabled
   device features, S-ATA specific informations, and a lot more
 - getting the Multi-Media informations like read/write
   capabilities, writing modes, buffer size, model, firmware,
   serial number . . .
 - transfer rate test with direct/indirect IO, adjustable buffer
   size and such . . . 
 - and some other functionalities . . . 


I would like to port it but, I don't know if such an utility is useful for the FreeBSD users


----------



## halplus (May 14, 2009)

> I would like to port it but, I don't know if such an utility is useful for the FreeBSD users



It is usefull for Linux users? Why wouldn't be for us? Of course we would prefer BSD/Beerware license and eventually somebody will feel unconftable enought with GPL to replace it just because of that.


----------

