Add function to check if we have access to IsoFileSource contents.

This commit is contained in:
Vreixo Formoso 2007-12-29 16:30:13 +01:00
parent c915c6e3f4
commit 5c22069d19
2 changed files with 69 additions and 0 deletions

View File

@ -13,6 +13,9 @@
#include "fsource.h"
#include "error.h"
/* for eaccess, define in unistd.h */
#define __USE_GNU
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -141,6 +144,45 @@ int lfs_stat(IsoFileSource *src, struct stat *info)
return ISO_SUCCESS;
}
static
int lfs_access(IsoFileSource *src)
{
_LocalFsFileSource *data;
if (src == NULL) {
return ISO_NULL_POINTER;
}
data = src->data;
if (eaccess(data->path, R_OK) != 0) {
int err;
/* error, choose an appropriate return code */
switch (errno) {
case EACCES:
err = ISO_FILE_ACCESS_DENIED;
break;
case ENOTDIR:
case ENAMETOOLONG:
case ELOOP:
err = ISO_FILE_BAD_PATH;
break;
case ENOENT:
err = ISO_FILE_DOESNT_EXIST;
break;
case EFAULT:
case ENOMEM:
err = ISO_MEM_ERROR;
break;
default:
err = ISO_FILE_ERROR;
break;
}
return err;
}
return ISO_SUCCESS;
}
static
int lfs_open(IsoFileSource *src)
{
@ -394,6 +436,7 @@ IsoFileSourceIface lfs_class = {
lfs_get_name,
lfs_lstat,
lfs_stat,
lfs_access,
lfs_open,
lfs_close,
lfs_read,

View File

@ -119,6 +119,26 @@ typedef struct IsoFileSource_Iface
*/
int (*stat)(IsoFileSource *src, struct stat *info);
/**
* Check if the process has access to read file contents. Note that this
* is not necessarily related with (l)stat functions. For example, in a
* filesystem implementation to deal with an ISO image, if the user has
* read access to the image it will be able to read all files inside it,
* despite of the particular permission of each file in the RR tree, that
* are what the above functions return.
*
* @return
* 1 if process has read access, < 0 on error
* Error codes:
* ISO_FILE_ACCESS_DENIED
* ISO_FILE_BAD_PATH
* ISO_FILE_DOESNT_EXIST
* ISO_MEM_ERROR
* ISO_FILE_ERROR
* ISO_NULL_POINTER
*/
int (*access)(IsoFileSource *src);
/**
* Opens the source.
* @return 1 on success, < 0 on error
@ -263,6 +283,12 @@ int iso_file_source_lstat(IsoFileSource *src, struct stat *info)
return src->class->lstat(src, info);
}
extern inline
int iso_file_source_access(IsoFileSource *src)
{
return src->class->access(src);
}
extern inline
int iso_file_source_stat(IsoFileSource *src, struct stat *info)
{