Add function to check if we have access to IsoFileSource contents.
This commit is contained in:
parent
c915c6e3f4
commit
5c22069d19
@ -13,6 +13,9 @@
|
|||||||
#include "fsource.h"
|
#include "fsource.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
|
/* for eaccess, define in unistd.h */
|
||||||
|
#define __USE_GNU
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -141,6 +144,45 @@ int lfs_stat(IsoFileSource *src, struct stat *info)
|
|||||||
return ISO_SUCCESS;
|
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
|
static
|
||||||
int lfs_open(IsoFileSource *src)
|
int lfs_open(IsoFileSource *src)
|
||||||
{
|
{
|
||||||
@ -394,6 +436,7 @@ IsoFileSourceIface lfs_class = {
|
|||||||
lfs_get_name,
|
lfs_get_name,
|
||||||
lfs_lstat,
|
lfs_lstat,
|
||||||
lfs_stat,
|
lfs_stat,
|
||||||
|
lfs_access,
|
||||||
lfs_open,
|
lfs_open,
|
||||||
lfs_close,
|
lfs_close,
|
||||||
lfs_read,
|
lfs_read,
|
||||||
|
@ -119,6 +119,26 @@ typedef struct IsoFileSource_Iface
|
|||||||
*/
|
*/
|
||||||
int (*stat)(IsoFileSource *src, struct stat *info);
|
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.
|
* Opens the source.
|
||||||
* @return 1 on success, < 0 on error
|
* @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);
|
return src->class->lstat(src, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern inline
|
||||||
|
int iso_file_source_access(IsoFileSource *src)
|
||||||
|
{
|
||||||
|
return src->class->access(src);
|
||||||
|
}
|
||||||
|
|
||||||
extern inline
|
extern inline
|
||||||
int iso_file_source_stat(IsoFileSource *src, struct stat *info)
|
int iso_file_source_stat(IsoFileSource *src, struct stat *info)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user