Пример #1
0
//
// Used dpns_readdir to return the list of files
// in a directory without the deleted ones
//
dir_contents* getDirList (char* path)
{
    dpns_DIR * dir;
    struct dpns_direnstat * dsentry;

    if ( path == NULL || strlen (path) == 0 )
        return NULL;

    dir = dpns_opendir (path);
    if ( dir == NULL ) return NULL;

    dir_contents* dc = malloc (sizeof(dir_contents));
    dc->size = 0;

    serrno = 0;
    while ( dsentry = dpns_readdirx (dir) )
    {
        if ( dsentry->status != 'D' )
        {
            strcpy ((dc->list)[dc->size], dsentry->d_name);
            ++(dc->size);
        }
        if ( dc->size == 256 )
            break;
    }
    if ( dsentry == NULL && serrno != 0 )
    {
        free (dc);
        dpns_closedir (dir);
        return NULL;
    }
    dpns_closedir (dir);

    return dc;
}
Пример #2
0
/*
 * Opens a directory for reading its content.
 *     
 * \param dir_handle (input)
 *         the handle of the directory to be opened.
 * \param p_context (input)
 *         Permission context for the operation (user, export context...).
 * \param dir_descriptor (output)
 *         pointer to an allocated structure that will receive
 *         directory stream informations, on successfull completion.
 * \param dir_attributes (optional output)
 *         On successfull completion,the structure pointed
 *         by dir_attributes receives the new directory attributes.
 *         Can be NULL.
 * 
 * \return Major error codes :
 *        - ERR_FSAL_NO_ERROR     (no error)
 *        - ERR_FSAL_ACCESS       (user does not have read permission on directory)
 *        - ERR_FSAL_STALE        (dir_handle does not address an existing object)
 *        - ERR_FSAL_FAULT        (a NULL pointer was passed as mandatory argument)
 *        - Other error codes can be returned :
 *          ERR_FSAL_IO, ...
 */
fsal_status_t dpmfsal_opendir(fsal_handle_t * dir_handle, // IN
                              fsal_op_context_t * p_context, // IN
                              fsal_dir_t * dir_descriptor, // OUT
                              fsal_attrib_list_t * dir_attributes // IN / OUT
)
{
    int rc;
    fsal_status_t st;
    struct dpns_filestat dpnsstat;
    struct stat buffstat;
    fsal_path_t dir_path;
    struct dpns_fileid dpnsfileid;

    // Sanity checks
    if (!dir_handle || !p_context || !dir_descriptor)
        Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_opendir);

    LogInfo(COMPONENT_FSAL, "dpmfsal_opendir: start :: %d", dir_handle->data.id);

    if (dpns_startsess(getenv("DPNS_HOST"), "nfs opendir") < 0) {
    	LogDebug(COMPONENT_FSAL, "dpmfsal_opendir: start session");
    	Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_opendir);
    }

    // Get the equivalent dir path
    st = fsal_internal_Handle2Path(p_context, dir_handle, &dir_path);
    if (FSAL_IS_ERROR(st))
        	ReturnStatus(st, INDEX_FSAL_opendir);

    // Fetch the directory properties (stat)
    TakeTokenFSCall();
    rc = dpns_lstat(dir_path.path, &dpnsstat);
    ReleaseTokenFSCall();
    if (rc)
        Return(dpns2fsal_error(serrno), serrno, INDEX_FSAL_opendir);

    // Open the directory (opendir)
    LogInfo(COMPONENT_FSAL, "dpmfsal_opendir: opening :: %s", dir_path.path);
    serrno = 0;
    TakeTokenFSCall();
    dir_descriptor->p_dir = dpns_opendir(dir_path.path);
    ReleaseTokenFSCall();
    if (serrno)
        Return(dpns2fsal_error(serrno), serrno, INDEX_FSAL_opendir);

    // Store directory in the given dir_descriptor
    memcpy(&(dir_descriptor->context), p_context, sizeof(fsal_op_context_t));
    memcpy(&(dir_descriptor->path), dir_path.path, sizeof(fsal_path_t));
    memcpy(&(dir_descriptor->handle), dir_handle, sizeof(fsal_handle_t));

    // If requested, fill in directory attributes
    if (dir_attributes) {
        st = dpns2fsal_attributes(&dpnsstat, dir_attributes);
        if (FSAL_IS_ERROR(st)) {
            // In case of error, fill appropriate bit mask
            FSAL_CLEAR_MASK(dir_attributes->asked_attributes);
            FSAL_SET_MASK(dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
        }
    }

    Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_opendir);
}