mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
connect getattr and readdir to hashtbl
This commit is contained in:
@@ -16,11 +16,16 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <inttypes.h>
|
#include <sys/stat.h>
|
||||||
|
#include <fuse/fuse.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "hashtbl.h"
|
#include "hashtbl.h"
|
||||||
#include "../mfapi/mfconn.h"
|
#include "../mfapi/mfconn.h"
|
||||||
@@ -204,8 +209,7 @@ static h_entry *folder_tree_lookup_key(folder_tree * tree, const char *key)
|
|||||||
*
|
*
|
||||||
* the path must start with a slash
|
* the path must start with a slash
|
||||||
*/
|
*/
|
||||||
/*
|
static h_entry *folder_tree_lookup_path(folder_tree * tree, const char *path)
|
||||||
static h_entry *folder_tree_lookup_path(folder_tree *tree, const char *path)
|
|
||||||
{
|
{
|
||||||
char *tmp_path;
|
char *tmp_path;
|
||||||
char *new_path;
|
char *new_path;
|
||||||
@@ -226,9 +230,8 @@ static h_entry *folder_tree_lookup_path(folder_tree *tree, const char *path)
|
|||||||
if (strcmp(path, "/") == 0) {
|
if (strcmp(path, "/") == 0) {
|
||||||
return curr_dir;
|
return curr_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// strip off the leading slash
|
// strip off the leading slash
|
||||||
new_path = strdup(path+1);
|
new_path = strdup(path + 1);
|
||||||
tmp_path = new_path;
|
tmp_path = new_path;
|
||||||
result = NULL;
|
result = NULL;
|
||||||
|
|
||||||
@@ -265,10 +268,10 @@ static h_entry *folder_tree_lookup_path(folder_tree *tree, const char *path)
|
|||||||
if (strcmp(curr_dir->children[i]->name, tmp_path) == 0) {
|
if (strcmp(curr_dir->children[i]->name, tmp_path) == 0) {
|
||||||
// test if a file matched
|
// test if a file matched
|
||||||
if (curr_dir->children[i]->atime != 0) {
|
if (curr_dir->children[i]->atime != 0) {
|
||||||
fprintf(stderr, "A file can only be at the end of a path\n");
|
fprintf(stderr,
|
||||||
|
"A file can only be at the end of a path\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// a directory matched, break out of this loop and recurse
|
// a directory matched, break out of this loop and recurse
|
||||||
// deeper in the next iteration
|
// deeper in the next iteration
|
||||||
curr_dir = curr_dir->children[i];
|
curr_dir = curr_dir->children[i];
|
||||||
@@ -282,7 +285,6 @@ static h_entry *folder_tree_lookup_path(folder_tree *tree, const char *path)
|
|||||||
if (!success) {
|
if (!success) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// point tmp_path to the character after the last found slash
|
// point tmp_path to the character after the last found slash
|
||||||
tmp_path = slash_pos + 1;
|
tmp_path = slash_pos + 1;
|
||||||
}
|
}
|
||||||
@@ -291,7 +293,61 @@ static h_entry *folder_tree_lookup_path(folder_tree *tree, const char *path)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
int folder_tree_getattr(folder_tree * tree, const char *path,
|
||||||
|
struct stat *stbuf)
|
||||||
|
{
|
||||||
|
h_entry *entry;
|
||||||
|
|
||||||
|
entry = folder_tree_lookup_path(tree, path);
|
||||||
|
|
||||||
|
if (entry == NULL) {
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
stbuf->st_uid = geteuid();
|
||||||
|
stbuf->st_gid = getegid();
|
||||||
|
stbuf->st_ctime = entry->ctime;
|
||||||
|
stbuf->st_mtime = entry->ctime;
|
||||||
|
if (entry->atime == 0) {
|
||||||
|
/* folder */
|
||||||
|
stbuf->st_mode = S_IFDIR | 0755;
|
||||||
|
stbuf->st_nlink = entry->num_children + 2;
|
||||||
|
stbuf->st_atime = entry->ctime;
|
||||||
|
stbuf->st_size = 1024;
|
||||||
|
} else {
|
||||||
|
/* file */
|
||||||
|
stbuf->st_mode = S_IFREG | 0666;
|
||||||
|
stbuf->st_nlink = 1;
|
||||||
|
stbuf->st_atime = entry->atime;
|
||||||
|
stbuf->st_size = entry->fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int folder_tree_readdir(folder_tree * tree, const char *path, void *buf,
|
||||||
|
fuse_fill_dir_t filldir)
|
||||||
|
{
|
||||||
|
h_entry *entry;
|
||||||
|
uint64_t i;
|
||||||
|
|
||||||
|
entry = folder_tree_lookup_path(tree, path);
|
||||||
|
|
||||||
|
/* either directory not found or found entry is not a directory */
|
||||||
|
if (entry == NULL || entry->atime != 0) {
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
filldir(buf, ".", NULL, 0);
|
||||||
|
filldir(buf, "..", NULL, 0);
|
||||||
|
|
||||||
|
for (i = 0; i < entry->num_children; i++) {
|
||||||
|
filldir(buf, entry->children[i]->name, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When adding an existing key, the old key is overwritten.
|
* When adding an existing key, the old key is overwritten.
|
||||||
@@ -326,6 +382,7 @@ static h_entry *folder_tree_add_file(folder_tree * tree, mffile * file)
|
|||||||
strncpy(entry->name, file_get_name(file), sizeof(entry->name));
|
strncpy(entry->name, file_get_name(file), sizeof(entry->name));
|
||||||
entry->revision = file_get_revision(file);
|
entry->revision = file_get_revision(file);
|
||||||
entry->ctime = file_get_created(file);
|
entry->ctime = file_get_created(file);
|
||||||
|
entry->fsize = file_get_size(file);
|
||||||
|
|
||||||
/* mark this h_entry as a file if its atime is not set yet */
|
/* mark this h_entry as a file if its atime is not set yet */
|
||||||
if (entry->atime == 0)
|
if (entry->atime == 0)
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#ifndef _MFFUSE_HASHTBL_H_
|
#ifndef _MFFUSE_HASHTBL_H_
|
||||||
#define _MFFUSE_HASHTBL_H_
|
#define _MFFUSE_HASHTBL_H_
|
||||||
|
|
||||||
|
#include <fuse/fuse.h>
|
||||||
|
|
||||||
#include "../mfapi/mfconn.h"
|
#include "../mfapi/mfconn.h"
|
||||||
|
|
||||||
typedef struct folder_tree folder_tree;
|
typedef struct folder_tree folder_tree;
|
||||||
@@ -35,4 +37,10 @@ void folder_tree_housekeep(folder_tree * tree);
|
|||||||
void folder_tree_debug(folder_tree * tree, h_entry * ent,
|
void folder_tree_debug(folder_tree * tree, h_entry * ent,
|
||||||
int depth);
|
int depth);
|
||||||
|
|
||||||
|
int folder_tree_getattr(folder_tree * tree, const char *path,
|
||||||
|
struct stat *stbuf);
|
||||||
|
|
||||||
|
int folder_tree_readdir(folder_tree * tree, const char *path,
|
||||||
|
void *buf, fuse_fill_dir_t filldir);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
28
fuse/main.c
28
fuse/main.c
@@ -18,14 +18,11 @@
|
|||||||
|
|
||||||
#define FUSE_USE_VERSION 30
|
#define FUSE_USE_VERSION 30
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fuse/fuse.h>
|
#include <fuse/fuse.h>
|
||||||
#include <fuse/fuse_opt.h>
|
#include <fuse/fuse_opt.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "../mfapi/mfconn.h"
|
#include "../mfapi/mfconn.h"
|
||||||
@@ -37,6 +34,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
mfconn *conn;
|
mfconn *conn;
|
||||||
|
folder_tree *tree;
|
||||||
|
|
||||||
struct mediafirefs_user_options {
|
struct mediafirefs_user_options {
|
||||||
char *username;
|
char *username;
|
||||||
@@ -90,32 +88,17 @@ static void usage(const char *progname)
|
|||||||
|
|
||||||
static int mediafirefs_getattr(const char *path, struct stat *stbuf)
|
static int mediafirefs_getattr(const char *path, struct stat *stbuf)
|
||||||
{
|
{
|
||||||
// uid and gid are the one of the effective fuse user
|
return folder_tree_getattr(tree, path, stbuf);
|
||||||
stbuf->st_uid = geteuid();
|
|
||||||
stbuf->st_gid = getegid();
|
|
||||||
if (!strcmp(path, "/")) {
|
|
||||||
stbuf->st_mode = S_IFDIR | 0755;
|
|
||||||
// FIXME: calculate number of directory entries
|
|
||||||
stbuf->st_nlink = 2;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -ENOSYS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mediafirefs_readdir(const char *path, void *buf,
|
static int mediafirefs_readdir(const char *path, void *buf,
|
||||||
fuse_fill_dir_t filldir, off_t offset,
|
fuse_fill_dir_t filldir, off_t offset,
|
||||||
struct fuse_file_info *info)
|
struct fuse_file_info *info)
|
||||||
{
|
{
|
||||||
(void)path;
|
|
||||||
(void)offset;
|
(void)offset;
|
||||||
(void)info;
|
(void)info;
|
||||||
|
|
||||||
filldir(buf, ".", NULL, 0);
|
return folder_tree_readdir(tree, path, buf, filldir);
|
||||||
filldir(buf, "..", NULL, 0);
|
|
||||||
|
|
||||||
// FIXME: add entries for all files and directories
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct fuse_operations mediafirefs_oper = {
|
static struct fuse_operations mediafirefs_oper = {
|
||||||
@@ -164,7 +147,6 @@ mediafirefs_opt_proc(void *data, const char *arg, int key,
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
folder_tree *tree;
|
|
||||||
int ret;
|
int ret;
|
||||||
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
|
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
|
||||||
|
|
||||||
@@ -207,7 +189,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
folder_tree_debug(tree, NULL, 0);
|
folder_tree_debug(tree, NULL, 0);
|
||||||
|
|
||||||
folder_tree_destroy(tree);
|
//folder_tree_destroy(tree);
|
||||||
|
|
||||||
//return fuse_main(args.argc, args.argv, &mediafirefs_oper, NULL);
|
return fuse_main(args.argc, args.argv, &mediafirefs_oper, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user