3 Replies Latest reply: Dec 18, 2008 6:31 PM by 807567 RSS

    How to determine which file descriptor opened my driver?

    807567
      Suppose a user process opens my driver twice. How does open() determine which file descriptor opened the device? In Linux, the kernel will pass a pointer to a structure which represents the open file descriptor. However, Solaris only passes the device number to open(), so I can only determine my device was opened, but not which file. I need this information because my driver needs to keep track of all file descriptors opened for the device.

      Thanks!
      -Darren
        • 1. Re: How to determine which file descriptor opened my driver?
          807567
          I think you'll need a better explanation. You statement
          Solaris only passes the device number to open(), so I can only determine my device was opened, but not which file.
          doesn't make any sense, unless you are asking if you can figure out what path is being used - if you need that, I think you are out of luck, since I don't think there's anyway to distinguish mknod devices if they have the same major and minor numbers. If you are asking how to keep track of instances, you might want to look at streams devices (like /dev/tcp) as an example.
          • 2. Re: How to determine which file descriptor opened my driver?
            807567
            Thanks for the reply!

            A more specific description of the problem is: If the device is opened multiple times by a single process, then how do I determine which of the user's open file descriptors called the device operation?

            For now, we've decided to limit one open file descriptor per user process, then determine the user with ddi_get_pid().
            • 3. Re: How to determine which file descriptor opened my driver?
              807567
              I'm still at a loss why you need to know the file descriptor value (unless the app is sufficiently spaghettied that it has to query the driver to figure out what it opened with what). It's like asking what filename was used to open the device (which you can't get either). Since Solaris is based on a Streams framework, it would be bad to have drivers to even think it has a direct mapping into user space. It would be the same in asking (using /bin/sh):
              prog3 4>&1 3>&1 2>&1 | prog2 | prog1

              and you want to know from prog1 what descriptor prog3 wrote to. I don't see how linux even does this properly, since any given file open can have multiple file descriptors (via dup).