适配DSS接口与错误码修改

This commit is contained in:
liuzhanfeng2
2023-08-13 14:23:41 +08:00
committed by chendong76
parent 8a37df6d12
commit bc2f2d8eaf
11 changed files with 35 additions and 62 deletions

View File

@ -44,9 +44,7 @@ typedef int (*dss_trucate_device)(int handle, long keep_size);
typedef int (*dss_create_device)(const char *name, int flags);
typedef int (*dss_remove_device)(const char *name);
typedef int (*dss_close_device)(int handle);
typedef int (*dss_exist_device)(const char *name, bool *result);
typedef int (*dss_create_device_dir)(const char *name);
typedef int (*dss_exist_device_dir)(const char *name, bool *result);
typedef dss_dir_handle (*dss_open_device_dir)(const char *name);
typedef int (*dss_read_device_dir)(dss_dir_handle dir, dss_dirent_t *item, dss_dir_item_t *result);
typedef int (*dss_close_device_dir)(dss_dir_handle dir);
@ -56,7 +54,6 @@ typedef int (*dss_check_device_size)(int size);
typedef int (*dss_align_device_size)(int size);
typedef int (*dss_link_device)(const char *oldpath, const char *newpath);
typedef int (*dss_unlink_device)(const char *path);
typedef int (*dss_exist_device_link)(const char *path, bool *result);
typedef int (*dss_device_name)(int handle, char *fname, size_t fname_size);
typedef int (*dss_read_device_link)(const char *path, char *buf, int bufsize);
typedef int (*dss_stat_device)(const char *path, dss_stat_info_t item);
@ -85,9 +82,7 @@ typedef struct st_dss_device_op_t {
dss_seek_device dss_seek;
dss_trucate_device dss_truncate;
dss_close_device dss_close;
dss_exist_device dss_exist;
dss_create_device_dir dss_create_dir;
dss_exist_device_dir dss_exist_dir;
dss_rename_device dss_rename;
dss_check_device_size dss_check_size;
dss_align_device_size dss_align_size;
@ -100,7 +95,6 @@ typedef struct st_dss_device_op_t {
dss_remove_device_dir dss_remove_dir;
dss_link_device dss_link;
dss_unlink_device dss_unlink;
dss_exist_device_link dss_exist_link;
dss_read_device_link dss_read_link;
dss_stat_device dss_stat;
dss_lstat_device dss_lstat;

View File

@ -34,10 +34,8 @@
void dss_device_register(dss_device_op_t *dss_device_op, bool enable_dss);
void dss_set_errno(int *errcode);
bool dss_exist_file(const char *file_name);
int dss_access_file(const char *file_name, int mode);
int dss_create_dir(const char *name, mode_t mode);
bool dss_exist_dir(const char *name);
int dss_open_dir(const char *name, DIR **dir_handle);
int dss_read_dir(DIR *dir_handle, struct dirent **result);
int dss_close_dir(DIR *dir_handle);
@ -66,7 +64,6 @@ off_t dss_get_file_size(const char *fname);
int dss_fallocate_file(int handle, int mode, off_t offset, off_t len);
int dss_link(const char *src, const char *dst);
int dss_unlink_target(const char *name);
bool dss_exist_link(const char *name);
ssize_t dss_read_link(const char *path, char *buf, size_t buf_size);
int dss_setvbuf(FILE *stream, char *buf, int mode, size_t size);
int dss_feof(FILE *stream);

View File

@ -166,10 +166,10 @@ static inline int fallocate_dev(int fd, int mode, off_t offset, off_t len)
static inline int access_dev(const char *pathname, int mode)
{
if (is_dss_file(pathname)) {
if (!dss_exist_file(pathname) && !dss_exist_dir(pathname)) {
if (dss_access_file(pathname, mode) != GS_SUCCESS) {
return -1;
}
return dss_access_file(pathname, mode);
return 0;
} else {
return access(pathname, mode);
}
@ -215,7 +215,8 @@ static inline int symlink_dev(const char *target, const char *linkpath)
static inline ssize_t readlink_dev(const char *pathname, char *buf, size_t bufsiz)
{
if (is_dss_file(pathname)) {
if (!dss_exist_link(pathname)) {
struct stat st;
if (dss_lstat_file(pathname, &st) != GS_SUCCESS || !S_ISLNK(st.st_mode)) {
return -1;
}
@ -249,11 +250,13 @@ static inline int unlink_dev(const char *pathname)
static inline int lstat_dev(const char * pathname, struct stat * statbuf)
{
if (is_dss_file(pathname)) {
if (!dss_exist_file(pathname) && !dss_exist_dir(pathname)) {
errno = ENOENT;
if (dss_lstat_file(pathname, statbuf) != GS_SUCCESS) {
if (errno == ERR_DSS_FILE_NOT_EXIST) {
errno = ENOENT;
}
return -1;
}
return dss_lstat_file(pathname, statbuf);
return GS_SUCCESS;
} else {
return lstat(pathname, statbuf);
}
@ -262,11 +265,13 @@ static inline int lstat_dev(const char * pathname, struct stat * statbuf)
static inline int stat_dev(const char *pathname, struct stat *statbuf)
{
if (is_dss_file(pathname)) {
if (!dss_exist_file(pathname) && !dss_exist_dir(pathname)) {
errno = ENOENT;
if (dss_stat_file(pathname, statbuf) != GS_SUCCESS) {
if (errno == ERR_DSS_FILE_NOT_EXIST) {
errno = ENOENT;
}
return -1;
}
return dss_stat_file(pathname, statbuf);
return GS_SUCCESS;
} else {
return stat(pathname, statbuf);
}