From file to device …

Interesting question arose last week from one of the media developers at QNX working with a third party library.  The API that the third party was providing to him involved him providing a file path to the library, that was then stored and passed back to him as a plugin that he was supposed to use for some specialized device access (in this case a custom CD drive handling).

The problem, other than the not so elegant API required by this third party library, was that while the library needed a filename to work with, his plugin needed to send drive level control commands in the form of custom devctl()‘s.

 This reminded me of some control commands that had been put in to the block/filesystem level in the early days of Neutrino.  Hunting around I found the devctl() commands I was looking for in <sys/dcmd_blk.h>:

#define DCMD_FSYS_MOUNTED_ON  __DIOF(_DCMD_FSYS,  16, char[256]) 
#define DCMD_FSYS_MOUNTED_AT  __DIOF(_DCMD_FSYS,  17, char[256]) 
#define DCMD_FSYS_MOUNTED_BY  __DIOF(_DCMD_FSYS,  18, char[256])

When you have a file descriptor that points to something handled by of of the block oriented filesystems or block driver (ie devb-*), then you can use these handy commands to dig down or up or to determine where an entry is mounted in the filesystem.

DCMD_FSYS_MOUNTED_ON
This command will return the pathname of the underlying device, partition or file the current entry was mounted on. For example a file descriptor to a filesystem file will generally point back to a partition (or the raw block device), a partition file descriptor will point back to the raw device. In this way you can burrow your way down to the controlling device.

DCMD_FSYS_MOUNTED_BY
This command tries to root out and determine where the file descriptor you are referencing has been mounted if it is a singular mount point such as a partition. This is an upward version of MOUNTED_ON, but since multiple users can exist for a single device, it isn’t as generally useful as the MOUNTED_ON command.

DCMD_FSYS_MOUNTED_AT
This command tells you where the object that you are referencing was mounted at. This is similar to the type of information that you get back from the mount utility, but in this case the MOUNTED_AT command is a specific command for the block filesystem.

Due to the overlay nature of the Neutrino pathname space, these commands are really only applicable for file entries since directory entry resolution isn’t as explicit as for files*, but can come in handy if you are in a pinch like we were with this silly third party library API.

Thomas


* We’ll leave the magic of mountpoints, overlays and the contents of the /proc/mount directory for a rain(ier) day I think.

Advertisements

1 comment so far

  1. George on

    Hey there, I know that maybe this is not the best place for ask questions, but I have a problem that in the openqnx could not resolve yet, I hope you can help me.
    I am using QNX 4.25, I am trying to mount a usb memory, I follow this steps:

    Download and install usb drivers
    Fatfsys &
    io-usb &
    Fsys.umass &
    mount -p /dev/hd1
    mount -t dos /dev/hd1t111 /mnt/usb
    But it says: the device has no space left
    The memory is just 512mb and is almost empty
    I am missing something?

    Thanx


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: