Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

38
Wind River Systems, Inc. 1997 Chapter - 11 Chapter - 11 Local File Systems

Transcript of Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

Page 1: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

Wind River Systems, Inc. 1997

Chapter - 11Chapter - 11

Local File Systems

Page 2: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-2

Local File Systems

11.1 Overview

DOS File System

Raw File System

SCSI Devices

Page 3: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-3

File Systems

Page 4: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-4

Local File Systems

Available block device drivers:

ramDrv Simulates a disk in memory.

scsiLib Supports SCSI random-access devices.

xxDrv Third party block drivers.

Available file system libraries:

dosFsLib MS-DOS compatible.

rawFsLib Supports disk as a single file.

rt11FsLib For backward compatibility.

Page 5: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-5

Initialization and Use

Page 6: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-6

Creating a RAM Disk

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. Define INCLUDE_RAMDRV to include ramDrv in your vxWorks

image.

Page 7: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-7

A Simple Example

-> pBlkDev = ramDevCreate (0, 512, 400, 400, 0)

-> dosFsMkfs (“/RAM1”, pBlkDev)

/* Create and write to a file. Flush to RAM disk */

-> fd = creat(“/RAM1/myFile”, 2)

-> writeBuf = “This is a string.\n”

-> write(fd, writeBuf, strlen(writeBuf)+1)

-> close(fd)

/* Open file and read contents. */

-> readBuf = malloc(100)

-> fd = open(“/RAM1/myFile”, 2)

-> read(fd, readBuf, 100)

-> printf readBuf

This is a string.

Page 8: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-8

Local File Systems

Overview

11.2 DOS File System

Raw File System

SCSI Devices

Page 9: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-9

DOS File System

Hierarchical file system.

Restrictive file names.

Compatible with MS-DOS file systems up to release 6.2.

Disks are interchangeable with those created on PC’s, using MS-

DOS (if configured properly).

Page 10: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-10

Configuring dosFs

Define INCLUDE_DOSFS in config.h (excluded by default). Configure maximum number of dosFs files that can be open at a time

with NUM_DOSFS_FILES (default of 20 defined in configAll.h). Specify volume configuration information in a DOS_VOL_CONFIG

data structure: Disk layout. VxWorks options.

Page 11: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-11

Caveat: 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 partition’s 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).

Page 12: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-12

Caveat: DOS file names

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. UNIX-style file names are not PC compatible.

Page 13: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-13

Caveats: PC Compatibility

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.

Page 14: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-14

Configuration: New 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);

Page 15: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-15

Configuration: New File System

To create a new DOS file system with default configuration

parameters:

1. pBlkDev = xxDevCreate(...);

2. dosFsMkfs (“/DOS”, pBlkDev);

Page 16: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-16

Configuration: Using an Existing FileSystem

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.

Page 17: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-17

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)

Page 18: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-18

Local File Systems

Overview

DOS File System

11.3 Raw File System

SCSI Devices

Page 19: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-19

Introduction to the Raw File System

Wind River Systems defined. Fastest, least structured file system. Handles device (partition) as one file.

Analogous to the UNIX raw interface to a block device. No directories or other structure on disk.

Page 20: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-20

Configuring the Raw File System

Define INCLUDE_RAWFS in config.h (excluded by default). Specify the maximum number of rawFs files that can be open at a

time with NUM_RAWFS_FILES (default of 5 is defined in configAll.h).

Page 21: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-21

Raw FS Initialization

To initialize a raw device:

rawFsDevInit (devName, pBlkDev)

devName Name of raw file system device

being created.

pBlkDev Pointer to the BLK_DEV returned

from xxDevCreate( ).

Returns NULL on error. To low-level format the disk:

Open a file descriptor on the rawFs device. Call the FIODISKFORMAT ioctl.

With no structure on the disk to initialize, there is no diskInit( ) routine.

Page 22: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-22

Local File Systems

Overview

DOS File System

Raw File System

11.4 SCSI Devices

Page 23: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-23

SCSI Overview

SCSI - Small Computer System Interface.

ANSI standard providing device independence.

All devices “speak the same language.”

Less driver writing is required.

Support for SCSI-1 and SCSI-2 devices.

Support for general and block devices is provided by scsiLib.

Support for sequential devices is provided by scsiSeqLib.

Page 24: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-24

SCSI Bus

Page 25: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-25

SCSI-1 Restrictions

VxWorks must be the sole initiator. Only SCSI I random-access block devices conforming to the

Common Command Set are supported. Disconnect/reconnect is not supported. Synchronous transfers are not supported. Drivers for non-random-access devices (e.g., tape drives) must be

written by the user: scsiLib provides routines to put commonly used SCSI commands

on the bus. scsiIoctl( ) allows arbitrary SCSI commands to be put on the bus.

Page 26: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-26

SCSI-1 Support Configuration

To configure vxWorks for SCSI-1 support, selectively define the appropriate macro(s) by moving them outside the #if FALSE block in wind/target/config/bspName/config.h :

. . .#if FALSE

#define INCLUDE_SCSI

#define INCLUDE_SCSI_BOOT

#define INCLUDE_SCSI_DMA /* if supported by BSP */

#define INCLUDE_DOSFS

#define INCLUDE_TAPEFS /* SCSI-2 only */

#define SYS_SCSI_CONFIG

#endif

. . .

Page 27: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-27

SCSI-2 Features

Supports all mandatory features of the SCSI-2 protocol, and many optional features.

SCSI-2 features not supported by SCSI-1: Multiple initiators Disconnect/reconnect Mandatory direct access commands Mandatory sequential access commands Identify message Synchronous data transfer Fast SCSI Wide SCSI Tagged command queuing

Page 28: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-28

SCSI-2 Support Configuration

To include SCSI-2 support, the macro INCLUDE_SCSI2 (as well as INCLUDE_SCSI) must be defined in wind/target/config/target/config.h .

INCLUDE_SCSI2 must be defined before the include control line for the BSP header file bspName.h:

#define INCLUDE_SCSI2

#include “configAll.h”

#include “ bspName.h” Access to SCSI-2 devices:

DOS or RAW file systems on direct-access devices. Tape File System on sequential-access devices.

Page 29: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-29

Initializing SCSI Block Devices

Page 30: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-30

Configuration of SCSI Devices

When support for SCSI is enabled, system initialization code will: Initialize the SCSI controller. Configure SCSI peripherals.

Peripheral configuration call chain: usrRoot( ) => usrScsiConfig( ) => sysScsiConfig( ) sysScsiConfig( ) is called only if SYS_SCSI_CONFIG is defined.

Configuring specific peripherals requires writing the sysScsiConfig( ) function.

The sysScsiConfig( ) function should be placed in sysScsi.c (preferably) or sysLib.c in the BSP directory. Do not modify wind/target/src/config/usrScsi.c.

Page 31: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-31

Configuration: Hard Disks

Page 32: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-32

Initializing SCSI Sequential Devices

Page 33: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-33

Sequential Devices

SEQ_DEV * scsiSeqDevCreate

(pScsiPhysDev)

pScsiPhysDev pointer to SCSI_PHYS_DEV structure

returned by scsiPhysDevCreate( ) Returns a pointer to a SEQ_DEV structure describing the sequential

device, or NULL on error. Need to define INCLUDE_SCSI and INCLUDE_SCSI2 in config.h. Sequential devices allow blocks of data to be read and written

sequentially.

Page 34: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-34

The Tape File System

To access a sequential device create a tape file system. Can be configured for fixed block size transfers or variable size block

transfers. No directory structure. No file names used. The sequential device is accessed through the standard I/O interface. Define INCLUDE_TAPEFS in config.h.

Page 35: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-35

Tape File System Initialization

TAPE_VOL_DESC * tapeFsDevInit

(devName, pSeqDev, pTapeConfig)

devName Volume name of tape file system

device being created.

pSeqDev Pointer to a SEQ_DEV returned from

sequential device creation routine.

pTapeConfig Pointer to a tape configuration

structure TAPE_CONFIG. TAPE_VOL_DESC used to reference the file system.

Page 36: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-36

Configuration: Sequential Devices

1 /* configure Exabyte 8mm tape drive at busId = 4, LUN = 0 */2 if ((pSpd40 = scsiPhysDevCreate3 (pSysScsiCtrl, 4, 0, 0, NONE, 0, 0, 0))4 == (SCSI_PHYS_DEV *) NULL)5 {6 SCSI_DEBUG_MSG (“usrScsiConfig:”\7 “ scsiPhysDevCreate failed.\n”);8 return (ERROR);9 }10 /* configure the SEQ_DEV for this physical device */11 if ((pSd0 = scsiSeqDevCreate (pSpd40))12 == (SEQ_DEV *) NULL)13 {14 SCSI_DEBUG_MSG (“usrScsiConfig:”\15 “ scsiSeqDevCreate failed.\n”);16 return (ERROR);17 }18 /* initialize a tapeFs volume */19 ...20 if (tapeFsDevInit (“/tape1”, pSd0, pTapeConfig) == NULL)21 return (ERROR);

Page 37: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-37

Debugging Tools

-> scsiShowID LUN VendorId ProductID Rev. Type Blocks BlkSize scsiPhysDev

-- --- --------- ------------- ---------- ---- ------ ------- -----------5 0 ARCHIVE VIPER 150 21247 -005 1R 0 0 0x003cf654

When first starting out, define SCSI_AUTO_CONFIG in

wind/target/config/target/config.h. Calls scsiPhysDevCreate( ) for each bus Id and LUN. Calls scsiShow( ) when done.

If you don’t see all your peripherals attached: Check cable connections. Check SCSI bus termination. Make sure your peripheral supports the SCSI protocol being used. In sysScsiConfig( ) set the global scsiDebug = TRUE.

Page 38: Wind River Systems, Inc. 1997 Chapter - 11 Local File Systems.

11-38

Summary

DOS and RAW file systems for: RAM disk. SCSI devices. Custom block devices.

SCSI-1 device support for: Direct-access devices.

SCSI-2 device support for: Direct-access devices. Sequential-access devices. Tape file system.