TOC PREV NEXT INDEX

QNX Logo


7 Working with QNX 6 Files

[Author's Comments: also see /usr/help/product/neutrino_qrp_en/sys_arch/fsys.html]

This chapter covers the following topics:

Introduction

[Author's Comments: Talk about the Linux filesystem layout & why it is mentioned in "Welcome"? See package in http://support.qnx.com/support/docs/neutrino_qrp/sys_arch/fsys.html What's it for? What will it do for me?)]

[Author's Comments: explain types of files: regular, directory, char dev, block.... Also, How do you change file permission?) - see Utilities Reference, chmod]

QNX 6 comes with a rich set of utilities and shell commands that let you perform a wide range of operations on files and directories. To help you work with these commands, this chapter provides basic information on filename and pathname conventions in QNX; it also describes the directory structure of a typical QNX filesystem. For more in-depth information, see System Architecture.

Filenames

A filename is the symbolic name that lets you identify and access a file. In RTP, a filename may be up to 48 characters in length.

You can create filenames with all the characters in the computer's character set except for the following (all values in hex):

Portable filenames

If you anticipate moving your programs and data to other systems, you can make your files more portable by naming them only with those characters defined by POSIX for filenames:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789_.-

Filenames starting with a dot (e.g. .profile) are used for hidden files.

You can't use the dash (-) as the first character of a portable filename.

Filename suffixes

Applications, e.g. make, use filename suffix conventions such as .c, .o, and.y, but filename suffixes (e.g. txt in myfile.txt) have no special meaning in RTP. The "." character is treated the same as any other character in a filename.

Pathnames

RTP lets you group related files into directories. Directories can also contain other directories, so that you can implement a hierarchical filesystem.

Each filesystem has its own root directory. This root is at the top of the directory hierarchy, and it is where RTP starts looking for other directories and files. The typical name for the root directory of the default filesystem on a hard disk is /. If a hard disk has more than one filesystem, the choice of names for filesystems is up to the system administrator. These may include names such as /hd2, /hd3, etc., or perhaps /home2, /home3, etc. To locate a file, you specify the path from the root directory to the file. Other directories in the path to a file are also separated by slashes. Thus, to get to the file sysinit.1 in the /etc/system directory, you would specify this path:

/etc/system/sysinit.1

Network pathnames

You sometimes need to specify which computer (or node) on the network contains the file you want. All computers connected on an RTP network are identified by name; each one has a unique nodename. To refer to any networked computer, you use the network prefix (nominally /net) and the nodename of the computer you are interested in. So to access testfile on a node with the nodename remote-node, you would simply refer to the pathname: /net/remote-node/testfile.

Qnet, the native QNX 6 network manager resolves network pathnames. In Qnet, the nodename is the computer's hostname. For more information on Qnet, see the Neutrino Technical Note on Qnet.

[Author's Comments: include the QNET technote in this book]

Pathname prefixes

From the Photon File Manager, /net looks like a directory. But it isn't, it just looks like one. It isn't a part of the file system, it is only a pathname prefix that Qnet registered with the QNX 6 process manager; it exists as a resource only as long as Qnet is running. Qnet owns the /net pathname space, when it is done with it, it disappears. This is the way the QNX 6 process manager allocates and keeps track of all resources (for a detailed explanation of the way QNX 6 manages the pathname space, see the section on Pathname management in System Architecture.

Current working directory

To save you from constantly specifying complete pathnames to access a file, QNX provides a shortcut: the current working directory.

You don't have to specify a fully qualified path to access files in or below your current working directory. If you don't specify a full path, RTP assumes you are referring to your current working directory by default. For example, if you're positioned in the directory /home/gbbell and you want to access the file prog1.c, you don't need to specify: /home/gbbell/proc1.c. Instead, you could specify only the filename itself: proc1.c.

[Author's Comments: explain that the enver PATH needs to have the colon added (export PATH=$PATH:)?check need for this]

You can use the ../ shortcut to refer to the directory above your current working directory.

Home directory

When you first log in to RTP, your initial current working directory is as assigned by the system administrator. [Author's Comments: how does this get assigned?] By default, this directory, known as your home directory, is set in the $HOME environment variable. No matter where you are, you can always return to your home directory by entering the change directory command, cd.

For more information on the pathname space in RTP, see the section on Pathname management in System Architecture.

[Author's Comments: check this later]

A typical directory structure

[Author's Comments: answer user's queries: What does the directory structure look like? How do I find my way around the file system)]

QNX 6 follows most of the UNIX conventions for storing standard files.

The following table gives you an idea of the types of files you'll find under the main directories:

Directory:
Description:
/bin
Command executables
/dev
Device entries for I/O devices such as terminals and disks
/etc
Initialization and other files
/fs
Other filesystems
/home
Users' home directories (configurable by the system administrator)
/lib
Library files, including shared objects
/proc
Information about processes
/root
Home directory for root
/sbin
System executables (root only)
/tmp
Default location for temporary files
/usr
Standard programs
/var
Files that are likely to change in size, such as spoolers, and log and accounting files

Commonly used utilities

The following tables list the utilities you use to perform common operations. For more information, see the Utilities Reference.

Working with directories

If you want to:
Use this utility:
Change your current working directory
cd
Change file access permissions
chmod
Create directories
mkdir
Create links
ln
Display your current working directory
pwd
List the contents of a directory
ls
Remove directories
rmdir
Remove links
rm

Working with files

If you want to:
Use this utility:
Compare two files
diff
Concatenate files
cat
Copy files
cp
Count the number of words, lines, or bytes in a file
wc
Display the contents of a file
more, less, or cat
Print the contents of a file
lp
Rename or move files
mv
Remove files
rm
Search for string patterns in files
grep
Sort or merge lines in a file
sort

Other commands

If you want to:
Use this utility:
Display processes that are currently running
ps, sin, pidin
Find files
find

Package filesystem

[Author's Comments: also include info from pkg mgr technote here]

The package filesystem capitalizes on the QNX 6 pathname space and resource manager concepts. It is a filesystem manager that presents a customized, virtual view of a set of real files and directories.

In a networked environment, where a centralized server maintains groups of files (corresponding to packages) that are accessible by any client machine, different client machines may have different package manager configurations, enabling them to see different versions of the same packages or entirely different packages. In a single-node environment, the package filesystem facilitates version management.

You can use other approaches to accomplish the same thing, either by instantiating (copying) all the files for all the packages into directories, with one directory per machine, or by creating a vast number of symbolic links. But these approaches:

The package filesystem manager alleviates these problems.

What's in a package?

A package consists of a number of files and directories. These files are related to each other by virtue of being part of a product, a particular release, or a patch to a product. For example, the QNX 6 operating system, including its binary files and documentation, is considered a package. A set of updates (called a patch) to the OS might contain only selected files and documentation (i.e. the ones that have changed); this would be a different package.

The purpose of the package filesystem is to manage these packages in a manner such that various nodes can pick and choose which particular packages they want to use. For example, one node might be an x86 box running with Photon version 2.0 patch level "A" and Neutrino version 2.1, while another node might be a PowerPC box running Photon version 2.0 with no patch level applied and Neutrino version 2.1 as well. However, since these boxes are different CPU types, we need to give each of them not only different types of executables in their /bin directories (one set of x86 executables and one set of PowerPC executables) but also different contents based on which version of the software is desired and which patch levels have been applied.

In a nutshell, the package filesystem presents, on each node, a virtual filesystem that contains only selected files from the master package database. The selection is controlled by a control file, which indicates the packages that should be presented, the location of the master package database, and also where the virtual filesystem should be rooted.

This means that when it comes time to change the package lineup on a particular node, this can be accomplished by a simple and fast change to the control file.

[Author's Comments: The contents of the packages are read-only. Certain files in the package may be marked as "copy-on-write", which means that if the client writes to the file, a copy is written to the backing store (if present; if not present, an error is generated). The new version (on backing store) is then used from that point forward.]

Package layout example

Let's consider two views of the same package:

Source view

At the topmost directory level, the tree consists of the root of the packages (a typical name is /pkgs/repository), with a set of subdirectories representing different vendors, e.g. qnx for QNX Software Systems Limited:

Package repository directory structure

[Author's Comments: get these diagrams updated to show QNX 6 defaults] Underneath each vendor's directory is the list of packages provided by the vendor. In the case of QSSL, some of the packages present might be:

Vendor directory structure.

In the diagram above, there are seven packages (for three products):

The packages listed above are available, but not necessarily active on a given node.

Let's examine the structure of, for example, the osrt-2.00 package:

Source view of Neutrino OS Runtime 2.00 package structure.

The three top-level directories, bin, etc, and usr represent platform-independent directories; examples include shell scripts in bin and configuration files in etc.

For platform-specific files, the CPU type is encoded as part of the pathname (e.g. for x86-specific binaries, the pathname x86/bin is used).

Patches

When patches are issued (between releases), the files for the patch are placed into a package as well. In the diagram above, the package osrt-2.00-patcha represents the "A" level patch of the Neutrino OS runtime package for version 2.0. In the case of a patch, however, the package doesn't necessarily contain the full product, generally only files that have changed since the last full release.

The package filesystem allows files from one package to supersede files from other packages.

Client's view

By using the package filesystem manager (see fs-pkg in Utilities Reference), a client node can control which packages it sees.

The client creates a configuration file typically called /etc/system/packages or /etc/host_cfg/$HOSTNAME/etc/system/packages, where $HOSTNAME is the name of the client node. This file tells the package filesystem which packages are to be presented to the client node and where they should be placed.

For example, a client node may wish to select a lineup consisting of the Neutrino OS Runtime version 2.1 and the Photon Runtime version 2.0, with no other packages (or patches) installed. In that case, the package filesystem manager would read the client's configuration file and would manifest only the selected files in the client's pathname space:

Client's view of virtual filesystem (simple).

Spilling - modifying a package's contents

The package filesystem's contents are read-only; if you modify a file that's in the client-view of a package, you're actually changing a copy of it, called a spill file, that the package filesystem automatically creates in the appropriate directory.

You can modify the spilled copy in whatever ways its permissions allow you can even delete it. The package doesn't change in the package filesystem.

To return to the original version of the file, use the -r to the pkgctl utility (see pkgctl in the Utilities Reference).

Using floppy disks

The driver for the floppy disk interface is devb-fdc. This utility automatically detects your floppy disk interface at address 0x3f0, using interrupt line IRQ 6, and DMA channel 2. If you have different settings from these defaults, you can specify them using the fdc options of devb-fdc (see how in the Utilities Reference).

Formatting floppy disks

Type fdformat followed by the name of the disk drive containing the floppy disk you want to format, e.g.

fdformat /dev/fd0 

Starting Floppy disk drivers

The enumerators should have found your floppy drive and started the appropriate drivers when you booted RTP (if they have, you will see fd0 in /dev/), so all you have to do to start using the floppies is to mount them.

How do I mount a floppy

As root, use the mount command (see Utilities Reference). When you mount the floppy, you have to tell the utility what type of file system is installed on the disk (unless it is the default, QNX4) using the -t option; you also have to tell it the mount point (the pathname you want to use to access the floppy). For example, suppose you have inserted a floppy disk containing MS-DOS files into the drive and you want to access these files using the pathname /fs/msdos-floppy, you would type:

mount -tdos /dev/fd0 /fs/msdos-floppy

Now, you can see the contents of the floppy disk in the directory structure under the pathname you selected. When you have finished with these files and before you remove the disk, unmount this drive by typing:

umount /fs/msdos-floppy

[Author's Comments: what happens if you remove the disk without unmounting it?]

The /fs/msdos-floppy pathname is gone and you are back where you started from.

If the floppy won't mount

Here are some possibilities for you to check:

[Author's Comments: find out if anything else can go wrong]

Mounting a floppy on startup

If you want to mount a floppy when you boot RTP, add the mount command to the local startup script (/etc/rc.d/rc.local).

Your scripted mount command won't work until the enumerators have found the floppy drive and this might take a quite a while, so you must add some conditional delay in your script. The following code gives the enumerators up to 60 seconds to find the floppy disk drive, then mounts the drive as an MS-DOS type:
on -W60 -w /dev/fd0
if [ -e "/dev/fd0" ] then
 echo "Floppy drive found OK, mounting as /fs/msdos-floppy"
 /bin/mount -t dos /dev/fd0 fs/msdos-floppy
else
 echo "No floppy drive found, no mount possible"
fi 

Some FAQs

[Author's Comments: should answer users' queries: What is a boot image? and what can I do with it? (see /usr/help/product/neutrino_qrp/building_nto.html) What is root? How do you log in as root (some background)? What is enumeration? Does this book cover enumeration stuff? And how do I override the defaults/disable autodetect (where to look to change default parameters, how to start nonstandard hardware like a third serial port). What is a repository?)]


QNX Software Systems Ltd.
http://www.qnx.com
Voice: +1 613 591 0931
Fax: +1 613 591 3579
info@qnx.com
TOC PREV NEXT INDEX