Exemplo n.º 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;
}
Exemplo n.º 2
0
/*
 * Read the entries of an opened directory.
 *     
 * \param dir_descriptor (input):
 *        Pointer to the directory descriptor filled by FSAL_opendir.
 * \param start_position (input):
 *        Cookie that indicates the first object to be read during
 *        this readdir operation.
 *        This should be :
 *        - FSAL_READDIR_FROM_BEGINNING for reading the content
 *          of the directory from the beginning.
 *        - The end_position parameter returned by the previous
 *          call to FSAL_readdir.
 * \param get_attr_mask (input)
 *        Specify the set of attributes to be retrieved for directory entries.
 * \param buffersize (input)
 *        The size (in bytes) of the buffer where
 *        the direntries are to be stored.
 * \param pdirent (output)
 *        Adresse of the buffer where the direntries are to be stored.
 * \param end_position (output)
 *        Cookie that indicates the current position in the directory.
 * \param nb_entries (output)
 *        Pointer to the number of entries read during the call.
 * \param end_of_dir (output)
 *        Pointer to a boolean that indicates if the end of dir
 *        has been reached during the call.
 * 
 * \return Major error codes :
 *        - ERR_FSAL_NO_ERROR     (no error)
 *        - ERR_FSAL_FAULT        (a NULL pointer was passed as mandatory argument) 
 *        - Other error codes can be returned :
 *          ERR_FSAL_IO, ...
 */
fsal_status_t dpmfsal_readdir(dpmfsal_dir_t * dir_descriptor, // IN
							  dpmfsal_cookie_t start_position, // IN
							  fsal_attrib_mask_t get_attr_mask, // IN
							  fsal_mdsize_t buffersize, // IN
							  fsal_dirent_t * pdirent, // OUT
							  dpmfsal_cookie_t * end_position, // OUT
							  fsal_count_t * nb_entries, // OUT
							  fsal_boolean_t * end_of_dir // OUT
)
{
    int rc;
    struct dpns_direnstat * denstat;
    fsal_status_t st;
    unsigned long max_entries;

    // Sanity checks
    if (!dir_descriptor || !pdirent || !end_position || !nb_entries || !end_of_dir)
        Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_readdir);

    // How many entries should we read?
    max_entries = (buffersize / sizeof(fsal_dirent_t));

    LogInfo(COMPONENT_FSAL, "dpmfsal_readdir: start :: %s :: up to %d entries",
    		dir_descriptor->path.path, start_position, max_entries);

    // We might want to rewind
    serrno = 0;
    if (start_position.data.cookie == 0) {
    	LogDebug(COMPONENT_FSAL, "dpmfsal_readdir: cookie == 0 :: rewind");
        dpns_rewinddir(dir_descriptor->p_dir);
    } else { // Or simply move forward in the directory
    	LogDebug(COMPONENT_FSAL, "dpmfsal_opendir: cookie == %d :: seek");
    	// dpns_seekdir(dir_descriptor->p_dir, start_position.cookie); (does not exist)
    }
	if (serrno)
		Return(dpns2fsal_error(serrno), serrno, INDEX_FSAL_readdir);

    // Read the directory entries
    TakeTokenFSCall();
    *nb_entries = 0;
    while (*nb_entries < max_entries) {
        fsal_handle_t entry_handle;
        fsal_path_t entry_path;

        // Fetch the entry
        denstat = dpns_readdirx(dir_descriptor->p_dir);

        // Are we done?
        if (denstat == NULL) {
        	LogDebug(COMPONENT_FSAL, "dpmfsal_readdir: (end of dir) after %d entries", *nb_entries);
        	*end_of_dir = 1;
			break;
        }

        // Get the fsal_path_t struct corresponding to the entry name
        st = FSAL_str2name(denstat->d_name, FSAL_MAX_NAME_LEN, &(pdirent[*nb_entries].name));
        if (FSAL_IS_ERROR(st))
            ReturnStatus(st, INDEX_FSAL_readdir);
        strcpy(entry_path.path, dir_descriptor->path.path);
        fsal_internal_appendNameToPath(&entry_path, &(pdirent[*nb_entries].name));

        // Set the direntry object handle
        dpnsDirEntry2fsal_handle(denstat, &entry_path, dir_descriptor,
                &(pdirent[*nb_entries].handle));

        // Fill in the entry attributes
        pdirent[*nb_entries].attributes.asked_attributes = get_attr_mask;
        st = dpns2fsal_attributes(denstat, &pdirent[*nb_entries].attributes);
        if (FSAL_IS_ERROR(st)) {
            FSAL_CLEAR_MASK(pdirent[*nb_entries].attributes.asked_attributes);
            FSAL_SET_MASK(pdirent[*nb_entries].attributes.asked_attributes,
                    FSAL_ATTR_RDATTR_ERR);
        }

        pdirent[*nb_entries].cookie.data.cookie = start_position.data.cookie + *nb_entries;
        pdirent[*nb_entries].nextentry = NULL;
        if (*nb_entries)
            pdirent[*nb_entries - 1].nextentry = &(pdirent[*nb_entries]);
        (*end_position) = pdirent[*nb_entries].cookie;

        LogDebug(COMPONENT_FSAL, "dpmfsal_readdir: entry %d :: %d",
        		*nb_entries, pdirent[*nb_entries].handle.data.id);

        (*nb_entries)++;
    }
    ReleaseTokenFSCall();

    LogDebug(COMPONENT_FSAL, "dpmfsal_readdir: read %d entries :: end position is %d",
    		*nb_entries, end_position->data.cookie);

    Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_readdir);
}