0% found this document useful (0 votes)
55 views28 pages

IO File System

The document discusses I/O and file systems in VxWorks. It covers driver installation, device creation, file descriptors, basic I/O routines like open(), read(), write(), buffered and formatted I/O, block drivers, file systems configuration and initialization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views28 pages

IO File System

The document discusses I/O and file systems in VxWorks. It covers driver installation, device creation, file descriptors, basic I/O routines like open(), read(), write(), buffered and formatted I/O, block drivers, file systems configuration and initialization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

11-2

I/O and File System


11.1 Introduction
Character I/O
Block I/O

11-3
I/O System Interface

11-4
Driver Installation
A device driver must be installed in the I/O system.
Then VxWorks can call driver-specific routines when
generic routines are called: e.g. calling xxRead( ) when
read( ) is called on an XX device.
Installation done automatically for VxWorks drivers
included in VxWorks image:
ttyDrv( ).
pipeDrv( ).
Must call drivers xxDrv( ) routine before using a third
party driver.

11-5
Device Creation







These routines each initialize instances of a particular
device type.

11-6
File Descriptors
Integer that identifies a file (file or device).
Assigned by open( ) or creat( ).
Used by read( ), write( ), ioctl( ) and close( ) to specify file.
File descriptor table is global.
Table size defined by the symbolic constant NUM_FILES
(default 50). This is a parameter of the component
/operating system components/IO system components/IO system.

11-7
I/O System
Introduction
11.2 Character I/O
Block I/O

11-8
Standard Input, Standard Output, and
Standard Error
The first three file descriptors are predefined by the
system and are never reassigned by the system.






These three file descriptors (0 - 2) are never returned by
creat( ) or open( ).
reserved
file
descriptors
File Descriptor
Table

11-9
Basic I/O Routines
int open (name, flags, mode)
flags: O_RDONLY, O_WRONLY, O_RDWR, O_TRUNC, O_CREAT
mode: Permissions for NFS device
STATUS close (fd)
Tasks must close files when they are no longer needed. File
descriptor table is fixed size.
int read (fd, buffer, nBytes)
int write (fd, buffer, nBytes)
May block; returns number of bytes read or written.
int ioctl (fd, command, arg)
Allows execution of a device specific command. Valid ioctl()
commands are listed in driver help page.

11-10
Select
select( ) allows a task to wait for activity on a set of file
descriptors.
Requires driver support:
VxWorks pipes, sockets and serial device drivers support
select( ).
Third party drivers may also support select( ).
Also used to pend with a timeout.
tServer




pipe,
socket,
or serial
port
select()

11-11
Select
int select (width, pReadFds, pWriteFds,
pExceptFds, pTimeOut)

width Number of bits to examine in pReadFds and
pWriteFds.
pReadFds struct fd_set pointer for the file descriptors we
wish to read.
pWriteFds struct fd_set pointer for the file descriptors we
wish to write.
pExceptFds Not implemented.
pTimeOut Pointer to a struct timeval, or NULL to wait
forever.
Returns number of active devices, or ERROR.
@

11-12
Standard I/O

11-13
Buffered I/O and File Pointers
ansiStdio routines use file pointers (pointers to FILE
structures) instead of file descriptors. The FILE data
structure, typedefed in stdio.h, contains:
The underlying file descriptor.
Pointers, etc., for managing the file buffers.
Stdio buffers are not protected with semaphores. Two
tasks should not use the same fp at the same time.

11-14
Why Are the Buffers Used?
Private buffers minimize driver access:








Stdio buffers are not protected with semaphores

11-15
Formatted I/O
fioLib contains routines for non-buffered formatted
I/O.
Includes printf( ) and sprintf( ) which are normally part of
stdio.
fioLib allows ansiStdio to be excluded without losing
functionality.

11-16
Standard I/O and FIO Components

Other ANSI library components can be found in /operating
system components/ANSI C components (libc)/. For example,
ansiCtype, ansiString, ansiAssert, ansiTime, and
ansiMath. These libraries conform to ANSI X3.159-1989.

11-17
I/O System
Introduction
Character I/O
11.3 Block I/O

11-18
File Systems

11-19
Local File Systems
Available block device drivers:
ramDrv Simulates a disk in memory.
scsiLib Supports SCSI random-access devices.
tffsDrv True Flash File System (TrueFFS)
(optional product)
xxDrv Third party block drivers.
Available file system libraries:
dosFsLib MS-DOS compatible.
rawFsLib Supports disk as a single file.
rt11FsLib For backward compatibility.
cdromFsLib ISO 9660 CD-ROM read-only file
system.
tapeFsLib For SCSI sequential devices.

11-20
Initialization and Use

11-21
Block Driver Example
BLK_DEV * ramDevCreate (ramAddr,
bytesPerBlk, blksPerTrack, nBlocks, blkOffset)
ramAddr Memory location of ram disk (0 = malloc( )).
bytesPerBlk Number of bytes per block.
blksPerTrack Number of blocks per track.
nBlocks Size of disk in blocks.
blkOffset Number of blocks to skip. Typically zero.
Returns a pointer to a BLK_DEV structure describing the
RAM disk, or NULL on error.
ramDrv configured by adding the component /operating
system components/IO system components/RAM disk driver.

11-22
Configuring Local File Systems?

11-23
Configuration: New DOS File System
To create a new DOS file system with custom
configuration parameters:
1. pBlkDev = xxDevCreate(...);
2. Initialize DOS_VOL_CONFIG structure.
3. dosFsDevInit (/DOS, pBlkDev, pConfig);
4. fd = open (/DOS, O_WRONLY, 0);
5. ioctl (fd, FIODISKFORMAT, 0); /* if necessary */
6. ioctl (fd, FIODISKINIT, 0);
7. close (fd);

11-24
Configuration: Using an Existing DOS
File System
To remount an existing file system:
1. pBlkDev = xxDevCreate(...);
2. pDesc = dosFsDevInit (/DOS, pBlkDev, NULL);
3. dosFsVolOptionsSet (pDesc, options); /*if needed*/
Typically, file systems are configured in startup code.

11-25
Contiguous File Support
To pre-allocate contiguous disk space for a file:
ioctl (fd, FIOCONTIG, numBytes)
Must be called before anything is written to file.
Example:
fd = creat (/dos1/myDir/myFile, O_RDWR);
status = ioctl (fd, FIOCONTIG, 0x10000);
To obtain the largest contiguous block available, set
numBytes to CONTIG_MAX.
Pre-allocated space may be reclaimed with:
ioctl (fd, FIOTRUNC, newLength)

11-26
Caveat: DOS Data Integrity
To improve performance, FAT and directory changes are
not flushed to disk immediately.
To flush FAT and directory changes (before removing
media), use dosFsVolUnmount( ).
Alternatively, set options in the dosvc_options field of a
partitions DOS_VOL_CONFIG structure:
DOS_OPT_AUTOSYNC Flush FAT and directory
changes.
DOS_OPT_CHANGENOWARN Remount dosFs on open( )
or creat( ).
Setting these options will degrade performance.
Flush file changes with ioctl (fd, FIOSYNC, 0).

11-27
Caveat: DOS file names and PC
Compatibility
By default, standard 8+3 DOS file names are used.
Enable UNIX-style file names by setting
DOS_OPT_LONGNAMES option bit in DOS_VOL_CONFIG
data structure.
A disk initialized on a PC will work with VxWorks.
For PC compatibility, a disk initialized with VxWorks
Must use correct media byte.
Cannot have UNIX-style file names enabled with
DOS_OPT_LONGNAMES.

11-28
Summary
Basic I/O routines:
open( ) close( )
read( ) write( )
ioctl( ) creat( )
remove( )
select() allows a task to pend, with timeout, waiting for
read or write activity on a set of file descriptors.
Buffered I/O (ansiStdio) built on top of basic I/O using file
pointers. Not reentrant.
Formatted Non-buffered I/O (fioLib). Smaller than
ansiStdio and reentrant.












11-29
Summary
DOS and RAW file systems for:
RAM disk.
SCSI devices.
Custom block devices.
Initialization of a file system on a block device:
Create block device
Configure file system using BLK_DEV structure returned by
xxDevCreate().
Format disk (if necessary)

You might also like