GetFileRegions
Calculates offsets and lengths of a specified number of regions in a data file, accounting for resource locations, such that starting region offsets correspond to an active or deleted record at the time this function is called. A region is defined by a starting data file offset and the region length in bytes. (V11.8 and later)
Type
ISAM Function
NINT ctDECL GetFileRegions (pFILE_REGION_REQUEST pFileRegionRequest);
Description
Description
Structure Definitions
typedef struct fileRegionRequest_t {
COUNT structVersion;
FILNO dataFileNumber;
LONG numberOfRegions;
pFILE_REGION fileRegions;
} FILE_REGION_REQUEST, *pFILE_REGION_REQUEST;
fileRegions must have enough memory for that number of FILE_REGION structures.
Offset and length values are set on successful output.
Note: Your code is responsible for allocating before calling the function and deallocating afterwards.
typedef struct fileRegion_t {
ULONG8 offset;
ULONG8 length;
} FILE_REGION, *pFILE_REGION;
Region Definition
FairCom DB calculates the starting offset of each region by dividing the data file into equally sized regions corresponding to the number of regions specified by numberOfRegions in the fileRegionRequest_t structure. It aligns the offset of each region in fileRegion_t to the record offset of the first record in the region. It aligns the length to the offset of the last byte of the last record in the region.
Because the data file may contain resources, FairCom DB determines the locations of resource records in the data file. If any region offset lands on or within a resource record, FairCom DB adjusts the offset to start on the first record after the resource.
If the adjusted starting offset is no longer inside the specified region (which is only likely for small files), the offset and length of the region are returned as zero. Thus, you must ignore regions with zero length.
Example
NINT numberOfRegions = 10; /* specify number of regions */
pFILE_REGION fileRegions = NULL; /* array returned with region information */
FILNO datno; /* data file number */
/* structure used to request and receive region information */
FILE_REGION_REQUEST fileRegionRequest;
NINT i, rc;
/* Allocate memory for the array of regions that GetFileRegions() will populate */
if (!(fileRegions = (pFILE_REGION) mballc(numberOfRegions, sizeof(FILE_REGION)))) {
printf("Error: Failed to allocate memory for the region array.\n");
return -1;
}
/* Open the data file */
if ((datno = OPNRFIL(-1, "MyDataFile.dat", ctSHARED)) < 0) {
rc = isam_err;
printf("Error: failed to open file: %d\n", rc);
if (fileRegions)
mbfree(fileRegions);
return -1;
}
/* Prepare structure returning file regions */
fileRegionRequest.structVersion = FILE_REGION_REQUEST_VERS_V01;
fileRegionRequest.dataFileNumber = datno; /* The data file */
fileRegionRequest.numberOfRegions = numberOfRegions; /* Requested regions */
fileRegionRequest.fileRegions = fileRegions; /* Allocated array */
if ((rc = GetFileRegions(&fileRegionRequest))) {
printf("Error: failed to get region information: %d\n", rc);
if (fileRegions)
mbfree(fileRegions);
return -1;
}
/* Now print the region information */
printf("offset length\n");
for (i=0; i<numberOfRegions; i++) {
printf(ctLLnd(10) " " ctLLnd(10) "\n",fileRegions[i].offset,fileRegions[i].length);
}
if (fileRegions)
mbfree(fileRegions); /* Free region array */
return(0);
Limitations
Coding Considerations
Return
Programming Errors
Incorrect File Usage Errors
Handleable File Errors
See FairCom DB Error Codes for a complete listing of valid FairCom DB error values.
Compatibility Note: This new functionality involves changes to both the client library and the server, so, in addition to installing a new server executable, the client program must be re-linked.