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.

Advanced topics<br />

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

// create the output string<br />

string = ocb -> attr -> inode - 1 + ’A’;<br />

// return it to the client<br />

MsgReply (ctp -> rcvid, nbytes,<br />

&string + ocb -> offset,<br />

nbytes);<br />

// update flags and offset<br />

ocb -> attr -> flags |= IOFUNC_ATTR_ATIME<br />

| IOFUNC_ATTR_DIRTY_TIME;<br />

ocb -> offset += nbytes;<br />

} else {<br />

// nothing to return, indicate End Of File<br />

MsgReply (ctp -> rcvid, EOK, NULL, 0);<br />

}<br />

}<br />

// already done the reply ourselves<br />

return (_RESMGR_NOREPLY);<br />

dirent_size()<br />

The helper routine dirent_size() simply calculates the number of bytes required for the<br />

struct dirent, given the alignment constraints. Again, this is slight overkill for our<br />

simple resource manager, because we know how big each directory entry is going to<br />

be — all filenames are exactly one byte in length. However, it’s a useful utility routine.<br />

int<br />

dirent_size (char *fname)<br />

{<br />

return (ALIGN (sizeof (struct dirent) - 4 + strlen (fname)));<br />

}<br />

dirent_fill()<br />

Finally, the helper routine dirent_fill() is used to stuff the values passed to it (namely,<br />

the inode, offset and fname fields) into the directory entry also passed. As an added<br />

bonus, it returns a pointer to where the next directory entry should begin, taking into<br />

account alignment.<br />

struct dirent *<br />

dirent_fill (struct dirent *dp, int inode, int offset,<br />

char *fname)<br />

{<br />

dp -> d_ino = inode;<br />

dp -> d_offset = offset;<br />

strcpy (dp -> d_name, fname);<br />

dp -> d_namelen = strlen (dp -> d_name);<br />

dp -> d_reclen = ALIGN (sizeof (struct dirent) - 4<br />

+ dp -> d_namelen);<br />

return ((struct dirent *) ((char *) dp +<br />

dp -> d_reclen));<br />

}<br />

282 Chapter 5 • Resource Managers April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!