c - 使用 FUSE 列出目录

标签 c filesystems fuse ext2

这是我一直在努力解决的问题,但没有任何进展。希望你能帮帮我!

我在目录('home/fsc')中安装 FUSE 没有问题,甚至按以下方式列出它的父目录(/home):

在/home .. ls -l

并且 getattr 操作工作得很好。

当我打开目录 ('cd fsc') 时出现问题,它正确打开并调试操作我可以看到 fuse 如何请求 '/' 文件属性,但是当我尝试列出该目录中的文件时,fuse在无限循环中请求 '/tls' 的属性,在断开连接之前总是收到错误 '2','没有这样的文件或目录'。

我发现更奇怪的是,它从未像我预期的那样进入 readdir 操作。

知道为什么会发生这种情况吗?为什么 fuse 要求 '/tls' 属性而不是执行 '/' 的 readdir?

非常感谢您在这里的帮助,我需要一个解决方案来解决我需要尽快开展的大学项目,非常感谢您的帮助!

问候,

编辑:

我刚刚注意到它在这个循环中还要求'/i686'、'/sse2'、'/cmov'、'/librt.so.1'的文件属性,然后再次返回到'/TL'

2.-编辑:

获取操作

int client_getattr(const char* c_ruta, struct stat* ptr_est_salida) {

int error = 0;
size_t size_structStat = sizeof(struct stat);
t_conexion* ptr_conexionLibre = poolConexion_obtenerConexion();
char out_key[50];
char s_stat[sizeof(struct stat)];
_ArmaKeyRC_fsc(c_ruta,GET_ATTR,out_key);

if (!strcmp((char*) configuracion_estadoRC(),"ON")){
    if (rc_get_static(out_key, s_stat, &size_structStat) != 0) {

        logger_info("Acierto en RC (Getattr) Se omite comunicacion con RFS...");
        // TODO
        return error;

    } else {

        logger_info("No hubo acierto en RC (Getattr) Inicia comunicacion con RFS...");
    }
}

error = nipc_invocar_getattr(ptr_conexionLibre, c_ruta, ptr_est_salida);

if (!error){
    logger_info("La operacion getattr fue realizada con éxito");

    if (!strcmp((char*) configuracion_estadoRC(),"ON")){
        logger_info("Almacenando getattr en RC...");

        _serializaStructStat(*ptr_est_salida,s_stat);
        rc_store(out_key, s_stat, sizeof(struct stat));
    }
}

poolConexion_conexionDisponible(ptr_conexionLibre);

return error;

READDIR 操作

int client_readdir(const char* c_ruta, void* ptr_salida,
    fuse_fill_dir_t fn_llenadorDeElementosEnBuffer, off_t offset,
    struct fuse_file_info* ptr_est_infoArchivo) {

int error = 0;

t_conexion* ptr_conexionLibre = poolConexion_obtenerConexion();

if (!strcmp((char*) configuracion_estadoRC(),"ON")){
    if (rc_get(c_ruta) != 0) {

        logger_info("Acierto en RC (Readdir) Se omite comunicacion con RFS...");

        return error;

    } else {

        logger_info("No hubo acierto en RC (Readdir) Inicia comunicacion con RFS...");
    }
}

char** ptr_datos=NULL;
size_t cantidadLeida = 0;
error = nipc_invocar_readDir(ptr_conexionLibre, c_ruta,
        ptr_est_infoArchivo->fh, &ptr_datos, &cantidadLeida);
off_t filler_offset;

while (strcmp( ptr_datos[filler_offset],"")==0){
    fn_llenadorDeElementosEnBuffer(ptr_salida,(const char*) ptr_datos[filler_offset],NULL,0);
    filler_offset = filler_offset + 256;
}

if (!error){
    logger_info("La operacion readdir fue realizada con éxito");

    if (!strcmp((char*) configuracion_estadoRC(),"ON")){
        logger_info("Almacenando readdir en RC...");

        //char out_key[50];
        //_ArmaKeyRC_fsc(c_ruta, GET_ATTR, out_key);
        //rc_store(out_key, (char*) ptr_est_salida, sizeof(struct stat));
    }
}

poolConexion_conexionDisponible(ptr_conexionLibre);

return error;

主 fuse

#include "fuse_interface.h"
#include <stddef.h>
#include <stdlib.h>
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include "cliente.h"

// Estructura auxiliar que se usa para pasarle parámetros
// por línea de comando a la función principal de FUSE
struct t_runtime_options {
    char* welcome_msg;
} runtime_options;

// Esta macro sirve para definir nuestros propios parámetros
#define CUSTOM_FUSE_OPT_KEY(t, p, v) { t, offsetof(struct t_runtime_options, p), v }

// Estructura de operaciones de FUSE, contiene
// punteros a las funciones que debe ejecutar FUSE
// según se solicite.

static struct fuse_operations client_operations = { .getattr = client_getattr,
        .readdir = client_readdir, .open = client_open, .read = client_read,
        .unlink = client_unlink, .release = client_release, .rmdir =
                client_rmdir, .truncate = client_truncate,
        .write = client_write, .create = client_create, .mkdir = client_mkdir, };

/** keys for FUSE_OPT_ options */
enum {
    KEY_VERSION, KEY_HELP,
};

//Esta estructura es utilizada para decirle a la biblioteca de FUSE que
// parametro puede recibir y donde tiene que guardar el valor de estos
static struct fuse_opt fuse_options[] = {

        // Este es un parámetro definido por la cátedra de SISOP
        CUSTOM_FUSE_OPT_KEY("--welcome-msg %s", welcome_msg, 0),

        // Estos son parametros por defecto que ya tiene FUSE
        FUSE_OPT_KEY("-V", KEY_VERSION), FUSE_OPT_KEY("--version", KEY_VERSION),
                FUSE_OPT_KEY("-h", KEY_HELP), FUSE_OPT_KEY("--help", KEY_HELP),
        FUSE_OPT_END, };

int main(int argc, char *argv[]) {

    if (argc < 2) {
        perror("FSC:falta indicar la ruta del archivo de configuracion");
        exit(-1);
    }

    char c_config[256];
    strcpy(c_config, argv[1]);

    cliente_iniciar(c_config);

    int fuse_argc = 3;
    char nombrePrograma[256];
    strcpy(nombrePrograma, argv[0]);
    char puntoMontaje[256];
    strcpy(puntoMontaje, configuracion_pathMontajeFS());
    char parametro[256];
    strcpy(parametro, "-f");

    char* fuse_argv[3];
    fuse_argv[0]=nombrePrograma;
    fuse_argv[1]=puntoMontaje;
    fuse_argv[2]=parametro;


    printf("Iniciando Fuse: Mount Point: %s", configuracion_pathMontajeFS());
    // Inicializo la estructura de argumentos de FUSE
    struct fuse_args args = FUSE_ARGS_INIT(fuse_argc, fuse_argv);

    // Limpio la estructura que va a contener los parametros
    memset(&runtime_options, 0, sizeof(struct t_runtime_options));

    // Esta funcion de FUSE lee los parametros recibidos y los intepreta
    if (fuse_opt_parse(&args, &runtime_options, fuse_options, NULL) == -1) {
        perror("Fuse dice: Argumentos Invalidos");
        return EXIT_FAILURE;
    }

    // Si se paso el parametro --welcome-msg
    // el campo welcome_msg deberia tener el
    // valor pasado
    if (runtime_options.welcome_msg != NULL) {
        printf("%s\n", runtime_options.welcome_msg);
    } else {
    }

    // Esta es la funcion principal de FUSE, es la que se encarga
    // de realizar el montaje, comuniscarse con el kernel, delegar las cosas
    // en varios threads
    return fuse_main(args.argc, args.argv, &client_operations, NULL);

}

最佳答案

我认为这与 debian bug report 747941 中描述的问题相同 基本上就是动态库搜索路径的问题。

关于c - 使用 FUSE 列出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11496581/

相关文章:

c - C 中十六进制字符串转换为整数

image - 用于在社交网站中存储图像的文件层次结构?

filesystems - 如何根据文件系统了解文件名的字符编码

c - 在 C 中融合解析自定义参数

c - pthread 段错误发生在哪里?

c - 在二维矩阵的上下文中 C 中 ** 和 &** 之间的区别

android - SIGSEGV memcpy 和 memmove

c++ - 没有 Qt 的 C++ 中的 os.path 等效吗?

Golang cmd.Start() 有时卡在 fuse 安装目录上

docker - Riofs - 未找到 fuse 装置