Ejemplo n.º 1
0
/**
 * Contracts the size of the file containing the product-index map and
 * memory-maps it.
 *
 * @param[in] newSize      New size for the file in bytes. Must be less than
 *                         the current size of the file.
 * @retval    0            Success.
 * @retval    LDM7_SYSTEM  System error. `log_add()` called. The state of the
 *                         file is unspecified.
 */
static Ldm7Status
contractMapAndMap(
        const size_t newSize)
{
    /*
     * The file must be memory-mapped before it can be consolidated; thus, the
     * steps are: map, consolidate, shift, unmap, decrease size, and (re)map.
     */
    int status;

    (status = mapMap()) ||
    (status = consolidateMap(maxSigs)) ||
    (status = shiftMapDown(maxSigsFromFileSize(newSize))) ||
    (status = unmapMap()) ||
    (status = truncateMap(newSize)) ||
    (status = mapMap());

    return status;
}
Ejemplo n.º 2
0
/**
 * Adjusts, if necessary, the size of the previously-existing file containing
 * the file-identifier map and memory-maps it.
 *
 * @param[in]  maxSigs      Maximum number of data-product signatures.
 * @retval     0            Success.
 * @retval     LDM7_SYSTEM  System error. `log_add()` called. The state of the
 *                          file is unspecified.
 */
static Ldm7Status
vetMapSizeAndMap(
        const size_t  maxSigs)
{
    const size_t newSize = fileSizeFromNumSigs(maxSigs);
    int          status = (newSize > fileSize)
        ? expandMapAndMap(newSize)
        : (newSize < fileSize)
            ? contractMapAndMap(newSize)
            : mapMap();

    return status;
}
Ejemplo n.º 3
0
/**
 * Expands the size of the file containing the product-index map and
 * memory-maps it.
 *
 * @param[in] newSize      New size for the file in bytes. Must be greater than
 *                         the current size of the file.
 * @retval    0            Success.
 * @retval    LDM7_SYSTEM  System error. `log_add()` called. The state of the
 *                         file is unspecified.
 */
static Ldm7Status
expandMapAndMap(
        const size_t newSize)
{
    const size_t oldSize = fileSize;
    int          status = truncateMap(newSize);

    if (0 == status) {
        if (0 == (status = mapMap())) {
            consolidateMap(maxSigsFromFileSize(oldSize));
        } // file is memory-mapped
    } // file size was increased

    return status;
}
Ejemplo n.º 4
0
/**
 * Initializes and memory-maps the newly-created file that will contain the
 * product-index map for reading and writing.
 *
 * @param[in]  max          Maximum number of data-product signatures for the
 *                          map.
 * @retval     0            Success.
 * @retval     LDM7_SYSTEM  System error. `log_add()` called.
 */
static Ldm7Status
initNewMapAndMap(
        const size_t max)
{
    const size_t size = fileSizeFromNumSigs(max);
    int          status = truncateMap(size);

    if (0 == status) {
        fileSize = size;
        status = mapMap();

        if (0 == status) {
            clearMap();
            maxSigs = max;
        }
    }

    return status;
}