• No se han encontrado resultados

Sistema de timones Schilling VecTwin

Sistema de la hélice y línea de ejes Línea de ejes

5.4. Sistema de gobierno

5.4.1. Sistema de timones Schilling VecTwin

With the exception of keyed files, all file access methods use the same set of basic function calls. The method of access is determined by parameters passed to these functions. In general, each function returns a specified value ≥0 on success or a value of –1 on failure. On failure, errno is set to a specific error code to indicate the failure.

Open Files The open() function uses attributes to accomplish the following:

Create new files

Open existing files for writing

Position a seek pointer within an existing file

Create New Files

To create a new file, the O_CREAT attribute must be included in the call to open() specify O_WRONLY or O_RDWR to update the new file.

If the combination O_CREAT|O_TRUNC is used, an empty file is guaranteed. If you do not wish to write to the file following its opening, omit the O_RDWR or O_WRONLY flags and close the file immediately.

If you call open() with O_CREAT and specify an existing filename, O_CREAT is ignored and the file is simply opened using any additional read/write attributes specified in the call. In this case, a write operation may overwrite existing data in the file—a potentially destructive situation. To ensure that a new file is actually created, include the O_EXCL attribute in the open() call. If the file exists, an error value returns to the application with errno set to EEXIST.

To create a log file to record activity, specify the attributes O_WRONLY|O_APPEND|

O_CREAT with the open() call. Log files do not have seek activity during recording.

Open Files for Writing

Write access to a file is not implied. It must be specifically requested in the open() function by passing O_WRONLY or O_RDWR. O_APPEND can only be used in

conjunction with a file that has requested write access.

Seeking with lseek(), seek_cvlr(), and seek_vlr() can move the file pointer away from the end of a file; however, each write to a file opened with O_APPEND performs a seek to the end before writing data. Files opened for O_APPEND have their seek pointers moved to the end of the file.

FILE MANAGEMENT

File Access Function Calls

File Positioning

Positioning within a file is accomplished using an internal seek pointer—a long integer value—maintained by the file system that contains the byte or record address to use in the next read(), write(), insert(), or delete() operation. The seek pointer is allocated when the file is first opened and is therefore unique per handle. When a file is first opened, the seek pointer is set to a known state (typically zero) at the beginning of the file. As noted earlier, if O_APPEND is specified in the open() call, the seek pointer is positioned at the end of the file. Applications can modify the seek pointer using the lseek(),

seek_vlr(), and seek_cvlr() functions.

open()

open()

Allocates and returns an integer file handle used in all subsequent file operations.

Before a file can be accessed, it must be open.

Prototype int open (const char *filename, int attributes);

Parameters

Return Values

A single file can be opened multiple times (up to 30 files can be open

simultaneously; multiple opens of the same file are included). The number of files that can be open is set by the *FILE variable in the CONFIG.SYS file.

Each call to open() returns a unique handle with access attributes specified by that open(). Thus, a file can have multiple seek pointers in different locations in the file. The programmer is responsible for the consequences of adding or deleting data from a file that has been opened multiple times. The integrity of the file is maintained, but in some cases it may be difficult to predict where the seek pointers are positioned.

filename Pointer to a NULL-terminated string, up to 32 bytes long.

attributes An integer that indicates the access attribute:

O_RDONLY Opens the file for read-only access; the file cannot be written.

O_WRONLY Opens the file for write-only access; the file cannot be read.

O_RDWR Opens the file for read/write access; records can be read, written, inserted, or deleted.

O_APPEND Opens the file with the file position pointer initially set to the end of the file.

O_CREAT Opens a new file for write access.

O_TRUNC Opens an existing file, truncates its length to zero, deletes previous contents.

O_EXCL Returns error value if the file already exists; used with O_CREAT.

O_CODEFILE Specifies that the file contains executable code. Normally this attribute is used by the download module and is not used by applications.

Success: A positive integer is a handle that can be used for subsequent access to the file: read, write, and so on.

Failure: –1 with errno set to ENODEV.

FILE MANAGEMENT

open()

Note that there are several independent file systems in Verix V-based terminals.

The most commonly used file system exists in SRAM. The RAM-based file system can be updated as well as read.

The flash-based file system can also be updated. Since the flash-based file system behaves identically to the RAM-based system in nearly all respects (except that it cannot be changed as easily), it is not explicitly mentioned, except in the few cases where its behavior is unique. Files in the flash-based file system are identified with the prefix F:.

NOTE Since file handles are a limited resource, care should be taken in their allocation and use.

open()

Read Files The read(), read_vlr(), and read_cvlr() functions transfer data from a file opened for reading to a buffer within the application’s data area.

FILE MANAGEMENT

read(), read_vlr(), and read_cvlr()

read(), read_vlr(), and read_cvlr()

A successful call to these functions copies up to count bytes from the file to the address specified by buffer.

Prototype int read(int handle, char *buffer, int count);

int read_vlr (int handle, char *buffer, int count);

int read_cvlr (int handle, char *buffer, int count);

Parameters

Return Values

handle Handle of the calling device.

buffer Pointer to an array where the data is stored.

count Determines the maximum value to read.

read() Points to bytes_read bytes past its location before read() executed.

read_vlr(), read_cvlr()

Point to the next variable-length or compressed variable-length record in the file.

Failure: –1 with errno set to EBADF: file not open (bad handle) or file currently locked by another user.

–1 with errno set to EACCES: caller's buffer is not writable (for example, bad buffer address).

–1 with errno set to EINVAL: the count parameter is too large.

bytes_read Return value shows the actual number of bytes placed in the buffer; this value may be smaller if the end of file is encountered before the read reaches the count value.

read(), read_vlr(), and read_cvlr()

Write Files The write(), write_vlr(), and write_cvlr() functions transfer data from an application’s buffer to a file open for writing.

FILE MANAGEMENT

write(), write_vlr(), and write_cvlr()

write(), write_vlr(), and write_cvlr()

A successful call to these functions copies up to count bytes from the buffer into the file. write_vlr() and write_cvlr() either create new records in the file or overwrite existing records, depending on the position of the seek pointer.

If the file was opened with the O_APPEND attribute bit set, all writes are done at the end of the file, regardless of prior calls to lseek(), seek_vlr(), or seek_cvlr(). When a read function follows a seek function, all data at that file location transfers to the application’s buffer. O_APPEND means always append.

Prototype int write(int handle, const char *buffer, int count);

int write_vlr (int handle, const char *buffer, int count);

int write_cvlr (int handle, const char *buffer, int count);

Parameters

Return Values

handle Handle of the calling device.

buffer Pointer to an array where the data is stored.

count Determines the maximum value to write.

write() Points to bytes_written bytes past its location before write() executed.

write_vlr() write_cvlr()

Point to the next record in the file. If the seek pointer is positioned within the file (that is, when overwriting existing data), then the file manager assumes that the intention is to overwrite an existing VLR/

CVLR record at this point. The file manager reads the byte at the current location to determine the size of the existing record, deletes this record, then replaces it with the new VLR or CVLR record.

Failure: –1 with errno set to EBADF: File not open (bad handle) or file currently locked by another user.

–1 with errno set to ENOSPC: Not enough memory to complete the request.

–1 with errno set to EACCES: Caller's buffer is not readable (for example, bad buffer address).

–1 with errno set to EINVAL: count parameter is too large.

–1 with errno set to EFBIG: File expansion area is full. See

write(), write_vlr(), and write_cvlr()

File Positioning The lseek(), seek_vlr(), and seek_cvlr() functions set the file position pointer of an open file to a specified location.

FILE MANAGEMENT

lseek(), seek_vlr(), and seek_cvlr()

lseek(), seek_vlr(), and seek_cvlr()

To position the seek pointer within a file, pass the start location and an offset (long integer) value to the function lseek, seek_vlr(), or seek_cvlr(), depending on which access method is used. Start locations can be:

SEEK_SET—Beginning of file

SEEK_CUR—Current seek pointer location

SEEK_END—End of file

If SEEK_SET or SEEK_END is used, the system moves the seek pointer to this location and then moves it again, based on the offset value. If SEEK_CUR is used, the pointer is moved from its current location by the offset value.

Prototype int lseek(int handle, long offset, int origin);

int seek_vlr (int handle, long offset, int origin);

int seek_cvlr (int handle, long offset, int origin);

Parameters

Return Values The return value from these functions is the absolute number of bytes (not records for seek_vlr() and seek_cvlr()) from the beginning of the file. In a generic file, this value coincides with the pointer position in the file. For other file types, this value is meaningless because it also counts bytes (which include record headers) instead of records.

handle Handle of the calling device.

offset Specifies the number of bytes to move the seek pointer from the specified starting point; used with lseek(); can be positive or negative.

lseek() can be positive or negative, and it specifies the number of bytes to seek forward or backward from the specified origin.

For the functions seek_vlr() and seek_cvlr() the offset value must be positive, and it specifies the number of records to seek into the file.

NOTE

Backwards seeks in record files are not supported.

lseek(), seek_vlr(), and seek_cvlr()

Example bytes=lseek(handle,4L,SEEK_SET);

Failure -1 with errno set to EBADF: file not open (bad handle), or file currently locked by another user

-1 with errno set to EINVAL: The origin is not SEEK_SET, SEEK_CUR, or SEEK_END, offset is too large, or (for seek_vlr or seek_cvlr) offset is negative.

FILE MANAGEMENT

lseek(), seek_vlr(), and seek_cvlr()

Insert and Delete Data

The insert(), insert_vlr(), and insert_cvlr() functions insert data into a file opened for write access at the location of the file position pointer. The delete(),

delete_vlr(), and delete_cvlr() functions delete data from a file opened for write access at the location of the file position pointer.

TIP When adding or deleting data from a file, it is important to remember that any files or data stored in memory after this file may move. While normally imperceptible, the amount of time required to perform this move increases with the amount of data being moved.

Place frequently updated files after large data-storage files and limit the number and frequency of operations that change the size of a file. When updating records of the same length, overwrite the previous data rather than deleting the old record and writing the new data. Fixed length records and padding can prevent changing the size of file records during management operations. This should be carefully considered if the overhead significantly impacts transaction storage requirements.

The file extension feature (see Support for File Extension Areas, page 76) can be used to modify or eliminate the recommended restrictions.

insert(), insert_vlr(), and insert_cvlr()

insert(), insert_vlr(), and insert_cvlr()

A successful call to these functions inserts up to size bytes from the buffer into the file. The file position pointer is moved to the end of the inserted data.

Prototype int insert(int handle, const char *buffer, int size);

int insert_vlr (int handle, const char *buffer, int size);

int insert_cvlr (int handle, const char *buffer, int size);

Parameters

Return Values

handle Handle of the calling device.

buffer Pointer to an array where the data is stored.

size Determines the maximum value to insert; used with the insert_cvlr() function.

bytes_inserted Return value shows actual number of bytes inserted; this value can be smaller because insert_cvlr() uses compression.

Failure: –1 with errno set to EBADF: File not open (bad handle) or file currently locked by another user.

–1 with errno set to ENOSPC: Not enough memory to complete the request.

–1 with errno set to EACCES: Caller's buffer is not readable (for example, bad buffer address).

–1 with errno set to EINVAL: count parameter is too large.

–1 with errno set to EFBIG: File expansion area is full. See set_file_max().

FILE MANAGEMENT

delete(), delete_vlr(), and delete_cvlr()

delete(), delete_vlr(), and delete_cvlr()

Deletes data from a file opened for write access at the location of the file position pointer. Any data following the deleted data is moved to fill the gap. The file position pointer is not modified by these functions. If fewer than count bytes follow the current position, all data to the end of file is deleted. The file size shrinks by the number of deleted bytes. The call is not valid for pipes or devices.

Prototype int delete(int handle, unsigned int count);

int delete_vlr (int handle, unsigned int count);

int delete_cvlr (int handle, unsigned int count);

Parameters

Return Values

handle Handle of the calling device.

count For delete(): The number of bytes to delete.

For delete_vlr() and delete_cvlr(): The number of VLR (or CVLR) records to delete. The size of each record is read from the file.

Success: 0

Failure -1 and errno set to EBADF: file not open (bad handle), or file currently locked by another user.

-1 and errno set to EINVAL: Invalid count value (negative).

delete_()

delete_()

Identical to delete(), but providing an alternate name for the function that does not conflict with the C++ delete keyword.

Prototype int delete_ (int handle, unsigned int count);

Parameters

Return Values

handle Handle of the calling device.

count Determines the maximum value to delete.

Success: 0

Failure -1 and errno set to EBADF: Invalid handle.

-1 and errno set to EINVAL: Invalid count value (negative).

FILE MANAGEMENT

delete_()

Retrieve File Information

The get_file_size() function returns information about the file size. get_file_date() returns information about the last update to the file. See also dir_get_file_size() and dir_get_file_date().