[Next] [Previous] | Chapter 4 - I |
|
The FAT directory entries take up 32 bytes (20 hex) and are represented
by Table 4.1.
Most DOS files will have the reserved bits 0C to 15 set to zero. This is the area that is utilized to attach the Extended Attributes to the files in OS/2. The EA allocation clusters use the 14h and 15h bytes, and thus may appear illegal to some DOS applications. In order to avoid DOS compatibility problems, another file entry is maintained called EA DATA. SF; this file "pretends" to own all of the loose EA clusters on the hard disk, thus eliminating "lost clusters" messages from chkdsk.exe and similar messages from other disk managing utilities. Two references to all EA clusters exist: one that is maintained with the 14h- and 15h-byte directory entries, and one that is "assigned" to the EA DATA.SF. This implementation creates a source of confusion for users who are not familiar with EAs. For example, when using EA unaware backup utilities or when copying files from an OS/2 partition under DOS. most users do not know what to do wish the EA DATA.SF file. Users must realize that the EA clusters referenced by that file belong to several different applications. In order to maintain the EAs properly, it is best to use the OS/2 EAUTIL. program to separate EAs from their owners, then copy them as separate files and later reunite them for a happy ending. Generally the EAs take up a substantial amount of disk space; if space is at a premium, EAs not associated with a critical attribute can usually be deleted. In such cases, the presence of the EA is not critical to the application's correct execution and thus it can be removed. Users must take care in determining which EAs can be removed, as some applications will not work correctly afterward. |
A more thorough discussion of EA API and a detailed discussion of the API structures for the FAT and HPFS can be found in the OS/2 Programming Guide and various other IBM technical publications. The short description offered here is merely for the benefit of the programming examples and to help the programmer understand the API syntax used to attain the EA information. Extended attributes will appear foreign to DOS users and programmers, and their usefulness generally is questioned almost immediately. Only upon closer inspection does it become evident that EAs are quite important and really constitute a must-have feature , especially in high-end operating systems such as OS/2. Basically the Extended Attributes are nothing more than a storage area of information no more than 64K in sire that are available for applications to use as they please. OS/2 defines several standard types of EAs that are available for general use. Also, the programmer can define application-specific extended attributes. The only restriction is that the total EA size s cannot exceed 64K. Standard EAs are called SEAs, and by convention starts with a period [.]. They include:
.ASSOCTABLEIt is a good idea to not use the preceding [.] character in your own applications. The operating system reserves the right to use [.] as the first character of the EA name types. Nothing prevents users from implementing the same convention, but if OS/2 designers decide to add another standard type that happens to use your EA name, some unpredictable behavior may result. The type of data that is stored within an SEA is representative of the SEA name. For example, the .ICON SEA will contain the icon data, while the .TYPE SEA will contain the file object's type. This type can represent an executable, data, metafile, C code, bitmap, icon, resource file, object code, DOS binary, and so on. As you might have guessed, the .TYPE SEA is one of the more frequently used attributes of a file object. Note that extended attributes are associated not only with files but also with subdirectories. In fact, the subdirectory containing the Workplace Shell desktop information contains subdirectories that have many, many EAs.
.CODEPAGE
.COMMENTS
.HISTORY
.ICON
.KEYPHRASES
.LONGNAME
.SUBJECT
.TYPE
.VERSION
LIBPATH.C
LIBPATH.MAK
LIBPATH.DEF
The first step is to find the system boot drive. In order to do this, use DosQuerySysInfo and specify the arguments corresponding to the boot drive information. DosQuerySysInfo takes three input parameters and one output parameter, and returns the values of the system's static variables:
APIRET DosQuerySysInfo (
ULONG uStartIndex;
/* Ordinal of the first system variable to return. */
ULONG uLastIndex;
/* Ordinal of the last system variable to return. */
PVOID pDataBuf;
/* Address of the data buffer where the system returns the
variable values. */
ULONG ulDataBufLen);/*
Length, in bytes, of the data buffer. */
/* APIRET Return
Code. */
This call can return a single value or a range of values, depending on the ulSrartIndex, ulLastIndex. As is evident by the example, in order to obtain a single value, the ulStartIndex and ulLastIndex are set to the same input value:
arReturn = DosQuerySysInfo(The QSV_BOOT_DRIVE constant is defined by the BSEDOS.H header file, which is part of the set standard header files provided by she Programmer's Toolkit. Table 4.1 defines the additional values. The third parameter is the data buffer that DosQuerySysInfo uses to place the returned values into. The parameter is the size of the data buffer.
QSV_BOOT_DRIVE,
QSV_BOOT_DRIVE,
&ulDrive,
sizeof( ulDrive) );
Description | Value | Meaning |
QSV_MAX_PATH_LENGTH | 1 | Maximum path name length in bytes |
Q_MAX_PATH_LENGTH | 1 | = QSV_MAX_PATH_LENGTH |
QSV_MAX_TEXT_SESSIONS | 2 | Maximum number or text sessions |
QSV_MAX_PM_SESSIONS | 3 | Maximum number of PM sessions |
QSV_MAX_VDM_SESSIONS | 4 | Maximum number of virtual DOS machine (VDM) sessions |
QSV_BOOT_DRIVE | 5 | Boot drive value ( 1=A:, 2=B:, etc. ) |
QSV_DYN_PRI_VARIATION | 6 | Dynamic/Absolute priority (0=Absolute, 1=Dynamic ) |
QSV_MAX_WAIT | 7 | Maximum wait time in seconds |
QSV_MIN_SLICE | 8 | Minimum time slice allowed in milliseconds |
QSV_MAX_SLICE | 9 | Maximum time slice allowed in milliseconds |
QSV_PAGE_SIZE | 10 | Default page size (4K) |
QSV_VERSION_MAJOR | 11 | Major version number (20 for OS/2 2.0, 2.1, 2.11, 3.0, 4.0) |
QSV_VERSION_MINOR | 12 | Minor version number (00, 10, 11, 30,40 for OS/2 2.0, 2.1, 2.11, 3.0, 4.0 respectively) |
QSV_VERSION_REVISION | 13 | Revision version letter |
QSV_MS_COUNT | 14 | Free running millisecond 32-bit counter (value=0 at boot time) |
QSV_TIME_LOW | 15 | Lower 32 bits of time since 01-01-1970 in seconds |
QSV_TIME_HIGH | 16 | Upper 32 bits of times since 01-01-1970 in seconds |
QSV_TOTPHYSMEM | 17 | Total number of bytes of physical memory |
QSV_TOTRESMEM | 18 | Total number of system-resident memory |
QSV_TOTAVAILMEM | 19 | (Available memory for all processes)
Maximum number of bytes of memory that can be allocated by all processes in the system. This number is advisory and is not guaranteed, since system conditions change constantly. |
QSV_MAXPRMEM | 20 | (Avail private mem for calling proc)
Maximum number of bytes of memory that this process can allocate in its private arena. This number is advisory and is not guaranteed, since system conditions change constantly. |
QSV_MAXSHMEM | 21 | ( Avail shared mem for calling proc )
Maximum number of bytes of memory that a process can allocate in the shared arena. This number is advisory and is not guaranteed, since system conditions change constantly. |
QSV_TIMER_INTERVAL | 22 | Timer interval in tenths of millisecond |
QSV_MAX_COMP_LENGTH | 23 | Maximum length, in bytes, of one component in a path name. |
QSV_FOREGROUND_FS_SESSION | 24 | Session ID of current fgnd FS session
Session ID of the current foreground full-screen session. Note that this only applies to full-screen sessions. The Presentation Manager session (which displays Vio-windowed, PM, and windowed DOS Sessions) is full-screen session ID 1. |
QSV_FOREGROUND_PROCESS | 25 | Process ID of the current foreground process. |
QSV_NUMPROCESSORS | 26 | Number of processors in the machine |
QSV_MAXHPRMEM | 27 | Maximum amount of free space in process's high private arena |
QSV_MAXHSHMEM | 28 | Maximum amount of free space in process's high shared arena |
QSV_MAXPROCESSES | 29 | Maximum number of concurrent processes supported |
QSV_VIRTUALADDRESSLIMIT | 30 | Size of the user's address space in megabytes |
QSV_INT10ENABLED | 31 | INT10ENABLED |
QSV_MAX | = QSV_INT10ENABLED |
Gotcha!
An application that is intended to be used in the HPFS/FAT environment should make the DosQuerySysInfo call and determine the maximum value of the legal file name length: QSV_MAX_COMP_LENGTH. For HPFS, this value is much greater than FAT (255). The application should issue this call in its initialization section and remember the pertinent values for future DosFindFirst, DosFindNext buffer sire allocation values. |
arReturn = DosQueryPathInfo(
pchFile,
FIL_STANDARD,
&fsStatus,
sizeof( fsStatus) );
pchBuffer = malloc (fsStatus.cbFile +1);
DosQueryPathInfo is used to determine the size
of CONFIG.SYS. The function is designed to get file information for a file
or subdirectory. The first parameter, pchFile, is the fully qualified path
for the file. The second parameter is the level of information required.
All we need for this example is standard file information, FIL_STANDARD.
The information level determines the third parameter. If FIL_STANDARD is
specified, a pointer to a FILESTATUS3 structure is used. The structure
looks like this:
typedef struct _FILESTATUS3 {
FDATE
fdateCreation; /* Date of file creation. */
FTIME
ftimeCreation; /* Time of file creation. */
FDATE
fdateLastAccess; /* Date of last access. */
FTIME
ftimeLastAccess; /* Time of last access. */
FDATE
fdateLastWrite; /* Date of last write. */
FTIME
ftimeLastWrite; /* Time of last write. */
ULONG
cbFile; /*
File size (end of data). */
ULONG
cbFileAlloc; /* File allocated size.
*/
ULONG
attrFile; /* Attributes
of the file. */
} FILESTATUS3;
The FILESTATUS3 structure contains two fields of interest: cbFile and cbFileAlloc. The cbFiIe element contains the actual size of the file, start to finish, in bytes. The cbFileAlloc, on the other hand, contains the file size, based on system allocation unit (AU) size, whose value can be a multiple of 512, 2K, 4K, 8K, l6K,32K. and so on, depending on the type of magnetic media used. HPFS and diskettes use 512-byte AUs, while the FAT AU size depends on the volume size. cbFileAlloc is of minimal value in applications, and the cbFile value should be used to allocate the required storage. Thus, cbFile size value is used in the next call to allocate the memory buffer needed to read the whole CONFIG.SYS at once, plus an extra byte for a NULL character.
This memory allocation does not have to be performed. It is possible
to read one character at a time and parse the output using a 1-byte storage
area. The method used in CHKEA was used for ease of implementation as well
as performance reasons. Reading the whole file is much quicker. (Since
the CONFIG.SYS is generally smaller than 4K in size, it should easily fit
into a single page of memory, which is the smallest allocation allowed
in 32-bit OS/2.) The parsing can be achieved more rapidly as well. Memory
operations are much quicker than storage disk I/O.
arReturn = DosOpen (
pchFile,
&hfFile,
&ulAction,
0,
FILE_NORMAL,
FILE_OPEN,
OPEN_FLAGS_FAIL_ON_ERROR |
OPEN_FLAGS_SEQUENTIAL |
OPEN_SHARE_DENYNONE |
OPEN_ACCESS_READONLY,
NULL);
arReturn = DosRead(DosRead is the function to read not only flies but any devices. The first parameter, hfFile, is the file handle returned from DosOpen . The buffer, pchBuffer, is the second parameter. The third parameter is the number of bytes to read. In our case, the entire file size is used. The last parameter is a pointer to a ULONG. The number of bytes actually placed into the buffer is returned in a variable, ulBytesRead.
hfFile,
pchBuffer,
fsStatus.cbFile,
&ulBytesRead);
Note: In DOS and OS/2 it is possible to get a good return code (arReturn = 0) and not have the DosRead/DosWrite API complete as expected. It is a good idea to check for the return code first, then check for the BytesRead value and compare it with the expected number.Once in memory, the last character of the CONFIG.SYS file is set to NULL. This is done so that string operations can be performed more easily. The last step is parsing the file in order to find the LIBPATH information. Once the LIBPATH is found, it is displayed with a straightforward printf. The cleanup is accomplished by freeing the memory and using DosClose to close the file.
arReturn = DosClose( hfFile );
printf( "\n%s\n", pchLibpath);
free(pchBuffer);
[ Next ] [ Previous ] | Chapter 4 - I |