26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Writing a resource manager<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

Putting in your own functions<br />

all the “middle” resource managers, whereby newer ones are placed in front of other,<br />

existing “middle” ones.<br />

However, in reality, there are very few cases where you’d actually mount more than<br />

one, and even fewer cases where you’d mount more than two resource managers at the<br />

same mountpoint. Here’s a design tip: expose the ability to set the flags at the<br />

command line of the resource manager so that the end-user of your resource manager<br />

is able to specify, for example, -b to use the “before” flag, and -a to use the “after”<br />

flag, <strong>with</strong> no command-line option specified to indicate that a zero should be passed as<br />

the flag.<br />

Keep in mind that this discussion applies only to resource managers mounted <strong>with</strong> the<br />

same mountpoint. Mounting “/nfs” <strong>with</strong> a “before” flag and “/disk2” <strong>with</strong> an<br />

“after” flag will have no effect on each other; only if you were to then mount another<br />

“/nfs”or“/disk2” would these flags (and rules) come into play.<br />

Finally, the resmgr_attach() function returns a small integer handle on success (or -1<br />

for failure). This handle can then be used subsequently to detach the pathname from<br />

the process manager’s internal pathname tables.<br />

When designing your very first resource manager, you’ll most likely want to take an<br />

incremental design approach. It can be very frustrating to write thousands of lines of<br />

code only to run into a fundamental misunderstanding and then having to make the<br />

ugly decision of whether to try to kludge (er, I mean “fix”) all that code, or scrap it and<br />

start from scratch.<br />

The recommended approach for getting things running is to use the iofunc_func_init()<br />

POSIX-layer default initializer function to fill the connect and I/O tables <strong>with</strong> the<br />

POSIX-layer default functions. This means that you can literally write your initial cut<br />

of your resource manager as we did above, in a few function calls.<br />

Which function you’ll want to implement first really depends on what kind of resource<br />

manager you’re writing. If it’s a filesystem type of resource manager where you’re<br />

taking over a mountpoint and everything below it, you’ll most likely be best off<br />

starting <strong>with</strong> the io_open() function. On the other hand, if it’s a discretely manifested<br />

resource manager that does “traditional” I/O operations (i.e., you primarily access it<br />

<strong>with</strong> client calls like read() and write()), then the best place to start would be the<br />

io_read() and/or io_write() functions. The third possibility is that it’s a discretely<br />

manifested resource manager that doesn’t do traditional I/O operations, but instead<br />

relies on devctl() or ioctl() client calls to perform the majority of its functionality. In<br />

that case, you’d start at the io_devctl() function.<br />

Regardless of where you start, you’ll want to make sure that your functions are getting<br />

called in the expected manner. The really cool thing about the POSIX-layer default<br />

functions is that they can be placed directly into the connect or I/O functions table.<br />

This means that if you simply want to gain control, perform a printf() to say “I’m here<br />

in the io_open!”, and then “do whatever should be done,” you’re going to have an easy<br />

214 Chapter 5 • Resource Managers April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!