06.08.2013 Views

pSOSystem System Calls - Read

pSOSystem System Calls - Read

pSOSystem System Calls - Read

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

pHILE+ <strong>System</strong> <strong>Calls</strong> get_fn<br />

Usage<br />

Hex Mnemonic Description<br />

0x200E E_FORD Directory file expected.<br />

0x2025 E_IDN Illegal device name.<br />

0x2050 E_BADNFS NFS volume; illegal operation.<br />

One usage of get_fn() is to get the current directory. In the example below, the<br />

current directory’s FN is returned in dir_fn.<br />

unsigned long dir_fn; /*current directory */<br />

if (get_fn(“.”, &dir_fn) != 0) {<br />

}<br />

/*Insert some error processing here */;<br />

The pseudocode below shows how to get the current directory’s full pathname,<br />

rather than just the FN.<br />

1. Get the directory’s FN in dir_fn with get_fn(“.”) as above.<br />

2. Open the parent directory (“..”) with open_dir().<br />

3. Search the parent directory for the directory entry of the current directory.<br />

a. <strong>Read</strong> a directory entry with read_dir().<br />

b. Compare the directory entry’s d_filno with the FN of the current directory.<br />

c. Repeat steps a and b until they match.<br />

d. Remember the matching directory entry’s d_name. It is the last component<br />

of the current directory’s pathname.<br />

4. Close the open directory with close_dir().<br />

5. Repeat steps 1-4 for the parent directory of the current directory, the<br />

grandparent of the current directory, etc., until reaching the root directory. The<br />

root directory is reached when either get_fn() of the parent directory is an<br />

error, or get_fn() of the parent directory is the same as get_fn() of the<br />

directory.<br />

<strong>pSO<strong>System</strong></strong> <strong>System</strong> <strong>Calls</strong> 2-47<br />

2

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

Saved successfully!

Ooh no, something went wrong!