1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#include "operations.h" // This header includes the fuse.h header.
#include "headers.h"
#include "support/gutils.h"
#include "support/gstring.h"
#include "support/gstats.h"
#include "externs.h"
#include "errors.h"
#include "retriever/retriever.h"
#include "layout/core.h"
// public:
int revs_getattr(const char *path, struct stat *stbuf){
struct stats *stats;
memset(stbuf, 0, sizeof(struct stat));
debug(1, "Attributes for path %s;\n", path);
if (get_file(file_system_info, path, &stats) != 0) {
debug(1, "Failed to retrieve stats;\n");
return -1;
}
stbuf->st_size = stats->size;
if (stats->type == S_IFDIR)
stbuf->st_mode = stats->type | 0555;
else
stbuf->st_mode = stats->type | 0444;
stbuf->st_nlink = stats->nlink;
stbuf->st_mtime = stats->ctime;
stbuf->st_ctime = stats->ctime;
stbuf->st_atime = stats->atime;
gstrdel(stats->path);
free(stats);
debug(1, "Retrieved attributes\n");
return 0;
};
int revs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){
(void) offset;
(void) fi;
int i = 0;
struct stats *stats = NULL;
debug(1, "Received path %s;\n", path);
if (get_file(file_system_info, path, &stats) != 0)
return -ENOENT;
gstrdel(stats->path);
free(stats);
filler(buf, ".", NULL, 0);
filler(buf, "..", NULL, 0);
debug(1, "Reading content of the eturned directory\n");
char **content = get_children(file_system_info, path);
if (content == NULL){
debug(1, "Error occured while looking for children;");
return 0;
}
for (i = 0; content[i] != 0; i++)
filler(buf, content[i], NULL, 0);
debug(1, "There were %d children in this directory;\n", i);
for (i = 0; content[i] != 0; i++)
free(content[i]);
free(content);
return 0;
};
int revs_readlink(const char *path, char *buf, size_t size){
(void) size;
struct stats *stats;
if ((get_file(file_system_info, path, &stats) != 0) || (stats->type != S_IFLNK))
return -1;
strcpy(buf, stats->link);
return 0;
};
int revs_open(const char *path, struct fuse_file_info *fi){
(void) fi;
struct stats *stats;
if (get_file(file_system_info, path, &stats) == -1)
return -1;
if (stats->type & S_IFDIR)
return -1;
int result = retrieve(file_system_info, stats);
gstrdel(stats->path);
free(stats);
return result;
};
int revs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi){
(void) fi;
#define revs_read_finish(value) { \
close(descriptor); \
return value; \
}
struct stats *stats = NULL;
int descriptor = 0;
int result = 0;
debug(1, "Reading file %s;\n", path);
if (get_file(file_system_info, path, &stats) == -1)
return -1;
if (stats->type & S_IFDIR)
return -1;
char *tmp_path = get_tmp_path(stats->path);
debug(1, "Retrieved stats for path %s with tmp path %s\n", stats->path, tmp_path);
gstrdel(stats->path);
free(stats);
if (!tmp_path)
return -1;
if ((descriptor = open(tmp_path, O_RDONLY)) == -1)
return -1;
if ((result = lseek(descriptor, offset, SEEK_SET)) != offset)
revs_read_finish(-1);
if ((result = read(descriptor, buf, size)) == -1)
revs_read_finish(-1);
debug(1, "%d bytes have been read;\n", result);
revs_read_finish(result);
}
int revs_release(const char *path, struct fuse_file_info *fi){
(void) fi;
struct stats *stats = NULL;
get_file(file_system_info, path, &stats);
if (stats == NULL){
gstrdel(stats->path);
free(stats);
return -1;
}
int result = release(file_system_info, stats);
gstrdel(stats->path);
free(stats);
return result;
};
void revs_destroy(void *ptr){
(void) ptr;
DIR *dir = NULL;
char *path = NULL;
struct dirent *entry = NULL;
if (data_dir == NULL)
return;
dir = opendir(data_dir);
if (dir == NULL)
return;
for (entry = readdir(dir); entry != NULL; entry = readdir(dir)){
gmstrcpy(&path, data_dir, "/", entry->d_name, 0);
unlink(path);
};
closedir(dir);
debug(1, "Deleting temporary directory %s;\n", data_dir);
rmdir(data_dir);
gstrdel(path);
};
|