Exemplo n.º 1
0
int fb_iterator_init(Bool type){
	file_or_dir = type;
	fb_iterator_reset();

	// if no navigator available, return an error
	if ((iterator_navid = fsaccess_alloc_nav_id()) < 0) return ERROR_NO_NAV_ID;

	fsaccess_take_mutex();

	// select the navigator
	nav_select( iterator_navid );

	// navigate to folder
    if(nav_setcwd((FS_STRING)currentDirectory, FALSE, FALSE) == FALSE){
    	fsaccess_free_nav_id(iterator_navid);
    	return ERROR_NOT_A_DIRECTORY;
    }

    //select top of list
    if(nav_filelist_first(type)==FALSE){
    	fsaccess_free_nav_id(iterator_navid);
    	return ERROR_UNKNOWN;
    }

    nav_filelist_single_enable( type );

    filecount = nav_filelist_nb(file_or_dir);
    return 0;
}
Exemplo n.º 2
0
/*!
 * \brief Is a directory present?
 *
 * \param pcStringDirName Input. Directory name string.
 *
 * \return 1 if the directory exists, 0 if the directory doesn't exist, else -1
 */
int8_t fsaccess_IsDirPresent( const char *pcStringDirName )
{
    signed short TempoNavId;
    int8_t           RetVal;


    fsaccess_take_mutex(); // Take the mutex on the file system access.

    TempoNavId = fsaccess_alloc_nav_id(); // Get a navigator.
    if( -1 == TempoNavId ) // No navigator.
    {
        // give the mutex for nav access
        fsaccess_give_mutex();
        return( -1 );
    }

    // select the navigator
    nav_select( TempoNavId );

    // Try to enter in the directory.
    RetVal = (int8_t)nav_setcwd( (FS_STRING)pcStringDirName, true, false );

    fsaccess_free_nav_id( TempoNavId ); // mark NavId as free
    fsaccess_give_mutex(); // give the mutex for nav access

    return( RetVal );
}
Exemplo n.º 3
0
int fb_ls_ext(const char *ext){
	int CurrentNavId = -1;

	// if no navigator available, return an error
	if ((CurrentNavId = fsaccess_alloc_nav_id()) < 0) return ERROR_NO_NAV_ID;

	// select the navigator
	nav_select( CurrentNavId );

	// navigate to folder
    if(nav_setcwd((FS_STRING)currentDirectory, FALSE, FALSE) == FALSE){
    	fsaccess_free_nav_id(CurrentNavId);
    	return ERROR_NOT_A_DIRECTORY;
    }
    if(nav_filelist_first(FS_FILE)==FALSE){
    	fsaccess_free_nav_id(CurrentNavId);
    	return ERROR_UNKNOWN;
    }
    char filename[255];
    if(nav_file_getname(filename,sizeof(filename))==FALSE){
    	fsaccess_free_nav_id(CurrentNavId);
    	return ERROR_UNKNOWN;
    }


    seprintf("Contents of folder %s:\n\n",currentDirectory);

    nav_filelist_single_enable( FS_DIR );
    int filecount = nav_filelist_nb(FS_DIR);

    short a;
    for(a=0; a < filecount; a++){
    	if(nav_filelist_goto(a)==FALSE)return ERROR_UNKNOWN;
        char filename[255];
        if(nav_file_getname(filename,sizeof(filename))==FALSE){
        	fsaccess_free_nav_id(CurrentNavId);
        	return ERROR_UNKNOWN;
        }

        seprintf("%d: %s\n",a,filename);
    }
    nav_filelist_single_enable( FS_FILE );
    filecount = nav_filelist_nb(FS_FILE);
    for(a=0; a < filecount; a++){
    	if(nav_filelist_goto(a)==FALSE)return ERROR_UNKNOWN;
    	if(!nav_file_checkext(ext))continue;
        char filename[255];
        if(nav_file_getname(filename,sizeof(filename))==FALSE){
        	fsaccess_free_nav_id(CurrentNavId);
        	return ERROR_UNKNOWN;
        }

        seprintf("%d: %s\n",a,filename);
    }

    fsaccess_free_nav_id(CurrentNavId);
    return 0;
}
Exemplo n.º 4
0
//!
//! This function closes a file.
//!
//! @param fd    file descriptor.
//!
//! @return int : -1 if error, 0 otherwise
//!
int close(int fd)
{
    if (fd < 0)
    {
        return (-1);
    }
    // take the mutex for nav access
    fsaccess_take_mutex();

    nav_select( fd );

    file_close();


    fsaccess_free_nav_id(fd);

    // give the mutex for nav access
    fsaccess_give_mutex();

    return (0);
}
Exemplo n.º 5
0
void fb_iterator_terminate(){
	fsaccess_free_nav_id(iterator_navid);
	fsaccess_give_mutex();
}
Exemplo n.º 6
0
//!
//! This function opens a file.
//!
//! @param pathname   path of the file to open.
//! @param flags      flags to give file access rights
//!                   should be O_CREAT  : create file if not exist
//!                             O_APPEND : add data to the end of file
//!                             O_RDONLY : Read Only
//!                             O_WRONLY : Write Only
//!                             O_RDWR   : Read/Write
//! @return int : file descriptor (>= 0 if OK (NavID), -1 otherwise)
//!
int open(const char *pathname, int flags, ...)
{
    int CurrentNavId = -1;


    // take the mutex for nav access
    fsaccess_take_mutex();

    // if no navigator available, return an error
    if ((CurrentNavId = fsaccess_alloc_nav_id()) < 0) goto error_exit;

    // select the navigator
    nav_select( CurrentNavId );

    // the filesystem is now at the root directory
    if ((flags & O_CREAT) == O_CREAT)
    {
        // try to create, the flag is set
        if(nav_setcwd((FS_STRING)pathname, false, true) == false)
        {
            goto error_free_nav;
        }
    }
    else
    {
        // do not try to create, if it doesn't exist, error
        if(nav_setcwd((FS_STRING)pathname, false, false) == false)
        {
            goto error_free_nav;
        }
    }

    // if user wants to append in file
    if ((flags & O_APPEND) == O_APPEND)
    {
        // open the file
        if (file_open(FOPEN_MODE_APPEND) == false) goto error_free_nav;
    }
    else if ((flags & O_RDWR) == O_RDWR)
    {
        // open as read/write
        if (file_open(FOPEN_MODE_R_PLUS) == false) goto error_free_nav;
    }
    else if ((flags & O_WRONLY) == O_WRONLY)
    {
        // open as write
        if (file_open(FOPEN_MODE_W) == false) goto error_free_nav;
    }
    else
    {
        // open as read
        if (file_open(FOPEN_MODE_R) == false) goto error_free_nav;
    }

    // give the mutex for nav access
    fsaccess_give_mutex();

    return (CurrentNavId);

error_free_nav:
    // mark NavId as free
    fsaccess_free_nav_id(CurrentNavId);
error_exit:
    // give the mutex for nav access
    fsaccess_give_mutex();
    return(-1);
}