Ejemplo n.º 1
0
/*! \details This function opens a directory.
 *
 * \return a pointer to the directory or NULL with errno (see \ref ERRNO) set to:
 * - ENOMEM: not enough memory
 * - ENOENT: \a dirname was not found
 * - EACCES: read access to \a dirname is not allowed
 * - ENAMETOOLONG: \a dirname exceeds \a PATH_MAX or an element of \a dirname exceeds \a NAME_MAX
 *
 */
DIR * opendir(const char * dirname){
	int err;
	DIR * dirp;
	const sysfs_t * fs;

	if ( sysfs_ispathinvalid(dirname) == true ){
		return NULL;
	}

	fs = sysfs_find(dirname, false); //see which filesystem we are working with first
	if ( fs == NULL ){ //if no filesystem is found for the path, return no entity
		errno = ENOENT;
		return NULL;
	}

	dirp = malloc(sizeof(DIR));
	if ( dirp == NULL ){
		errno = ENOMEM;
		return NULL;
	}

	//Open the directory and check for errors
	err = fs->opendir(fs->cfg, &(dirp->handle), sysfs_stripmountpath(fs, dirname));
	if ( err < 0 ){
		free(dirp);
		return NULL;
	}

	//Initialize the DIR structure
	dirp->fs = fs;
	dirp->loc = 0;

	//Return the pointer to the table
	return dirp;
}
Ejemplo n.º 2
0
int lstat(const char * path, struct stat *buf){
	const sysfs_t * fs;

	if ( sysfs_ispathinvalid(path) == true ){
		return -1;
	}

	fs = sysfs_find(path, true);
	if ( fs != NULL ){
		return fs->lstat(fs->cfg, sysfs_stripmountpath(fs, path), buf);
	}
	errno = ENOENT;
	return -1;
}
Ejemplo n.º 3
0
/*! \cond */
int _stat(const char * path, struct stat *buf){
	const sysfs_t * fs;

	if ( sysfs_ispathinvalid(path) == true ){
		return -1;
	}

	fs = sysfs_find(path, true);
	if ( fs != NULL ){
        int ret = fs->stat(fs->config, sysfs_stripmountpath(fs, path), buf);
        SYSFS_PROCESS_RETURN(ret);
        return ret;
	}
	errno = ENOENT;
	return -1;
}