CreateFile \\\\.\\x: non-root

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
szivibuvi
Newbie
Newbie
Posts: 2
Joined: Wed Mar 24, 2010 10:40 am

CreateFile \\\\.\\x: non-root

Post by szivibuvi »

Hello,

I have a usb data aquisition device interfaced by mass storage protocol. I open it like:

hEcgDrive=CreateFile("\\\\.\\g:",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING |
FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED,
NULL);

for communication I use

DeviceIoControl(hEcgDrive,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
....
with a 'custom' scsi operation code as wrapper.

On Wine-1.1.30. under UHU linux (2.6.23.9-1) the program can open the device only if run as root. If run as plain user, CreateFile gives ERROR_ACCESS_DENIED (5).

I also tried with FILE_ALL_ACCESS, no luck.

I would appreciate any experience shared to solve this access issue!

The device has a basic filesystem with a txt file, so it is mapped under dosdevices, ok.

And an other question:
is it possible to open "\\\\.\\PHYSICALDISK2, this way no filesystem is needed, and the user is not confused with the apperance of a new drive. Under windows I follow the later strategy with success!

Thank you,
Gyula
Thunderbird
Level 5
Level 5
Posts: 336
Joined: Mon Nov 24, 2008 8:10 am

Post by Thunderbird »

Wine is layered on top of normal Linux APIs and thus has all the limitations of a normal Linux app. If a program requires raw device access to lets say /dev/sda, the user either needs root permissions or needs to be a member of a group which has raw device access.
Thunderbird
Level 5
Level 5
Posts: 336
Joined: Mon Nov 24, 2008 8:10 am

Post by Thunderbird »

Since you have source code, I don't think you should Wine for the device access part at all. I would recommend to split the USB interfacing code in a dll e.g. myusb.dll. Using winelib (read about winelib, winegcc in the documentation and in other places) you can build a myusb.dll.so which exports the same functions. Inside that winelib dll you can use BOTH win32 and Linux code. In this case I would just use pure Linux code to directly open your usb device and not use any win32 code. Your win32 app can just stay a win32 app but when it is loaded using wine it can pick up myusb.dll.so transparently and then use Linux usb calls. Then you can also directly access /dev/sda (or whatever the device is; probably you want to hook it up to libusb or /proc or /sys to figure out which device you need) and don't have to mount it.
James McKenzie

CreateFile \\\\.\\x: non-root

Post by James McKenzie »

szivibuvi wrote:
Hello,

I have a usb data aquisition device interfaced by mass storage protocol. I open it like:

hEcgDrive=CreateFile("\\\\.\\g:",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING |
FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED,
NULL);

for communication I use

DeviceIoControl(hEcgDrive,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
....
with a 'custom' scsi operation code as wrapper.

On Wine-1.1.30. under UHU linux (2.6.23.9-1) the program can open the device only if run as root. If run as plain user, CreateFile gives ERROR_ACCESS_DENIED (5).
This is the clue you need. You need to change permissions of the device
ioctl (/dev entry) so that your user can access it OR add your user to
the groups with permissions to the device mount point.

James McKenzie
szivibuvi
Newbie
Newbie
Posts: 2
Joined: Wed Mar 24, 2010 10:40 am

Post by szivibuvi »

Thanks, after changing the permissions (chmod 666 /dev/sdb) now the CreateFile succeeds, but now DeviceIoControl stops with ERROR_NOACCESS (998). For non-root, ofcourse. For root it still works.
Where should I try to change further permissions?

Thanks,
Gyula
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

szivibuvi wrote:Thanks, after changing the permissions (chmod 666 /dev/sdb) now the CreateFile succeeds, but now DeviceIoControl stops with ERROR_NOACCESS (998). For non-root, ofcourse. For root it still works.
Where should I try to change further permissions?
Try with newer Wine. Also try without these flags: FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING
Locked