Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a17427cb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Convert fuse.c to C++."

parents 2703425d f08ba055
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := sdcard.cpp fuse.c
LOCAL_SRC_FILES := sdcard.cpp fuse.cpp
LOCAL_MODULE := sdcard
LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror
LOCAL_SHARED_LIBRARIES := libbase liblog libcutils libpackagelistparser
+56 −54
Original line number Diff line number Diff line
@@ -336,18 +336,18 @@ struct node *create_node_locked(struct fuse* fuse,
        return NULL;
    }

    node = calloc(1, sizeof(struct node));
    node = static_cast<struct node*>(calloc(1, sizeof(struct node)));
    if (!node) {
        return NULL;
    }
    node->name = malloc(namelen + 1);
    node->name = static_cast<char*>(malloc(namelen + 1));
    if (!node->name) {
        free(node);
        return NULL;
    }
    memcpy(node->name, name, namelen + 1);
    if (strcmp(name, actual_name)) {
        node->actual_name = malloc(namelen + 1);
        node->actual_name = static_cast<char*>(malloc(namelen + 1));
        if (!node->actual_name) {
            free(node->name);
            free(node);
@@ -377,13 +377,13 @@ static int rename_node_locked(struct node *node, const char *name,
    /* make the storage bigger without actually changing the name
     * in case an error occurs part way */
    if (namelen > node->namelen) {
        char* new_name = realloc(node->name, namelen + 1);
        char* new_name = static_cast<char*>(realloc(node->name, namelen + 1));
        if (!new_name) {
            return -ENOMEM;
        }
        node->name = new_name;
        if (need_actual_name && node->actual_name) {
            char* new_actual_name = realloc(node->actual_name, namelen + 1);
            char* new_actual_name = static_cast<char*>(realloc(node->actual_name, namelen + 1));
            if (!new_actual_name) {
                return -ENOMEM;
            }
@@ -394,7 +394,7 @@ static int rename_node_locked(struct node *node, const char *name,
    /* update the name, taking care to allocate storage before overwriting the old name */
    if (need_actual_name) {
        if (!node->actual_name) {
            node->actual_name = malloc(namelen + 1);
            node->actual_name = static_cast<char*>(malloc(namelen + 1));
            if (!node->actual_name) {
                return -ENOMEM;
            }
@@ -414,7 +414,7 @@ static struct node *lookup_node_by_id_locked(struct fuse *fuse, __u64 nid)
    if (nid == FUSE_ROOT_ID) {
        return &fuse->global->root;
    } else {
        return id_to_ptr(nid);
        return static_cast<struct node*>(id_to_ptr(nid));
    }
}

@@ -877,6 +877,7 @@ static int handle_rename(struct fuse* fuse, struct fuse_handler* handler,
    char old_child_path[PATH_MAX];
    char new_child_path[PATH_MAX];
    const char* new_actual_name;
    int search;
    int res;

    pthread_mutex_lock(&fuse->global->lock);
@@ -913,7 +914,7 @@ static int handle_rename(struct fuse* fuse, struct fuse_handler* handler,
     * differing only by case.  In this case we don't want to look for a case
     * insensitive match.  This allows commands like "mv foo FOO" to work as expected.
     */
    int search = old_parent_node != new_parent_node
    search = old_parent_node != new_parent_node
            || strcasecmp(old_name, new_name);
    if (!(new_actual_name = find_file_within(new_parent_path, new_name,
            new_child_path, sizeof(new_child_path), search))) {
@@ -979,7 +980,7 @@ static int handle_open(struct fuse* fuse, struct fuse_handler* handler,
            open_flags_to_access_mode(req->flags))) {
        return -EACCES;
    }
    h = malloc(sizeof(*h));
    h = static_cast<struct handle*>(malloc(sizeof(*h)));
    if (!h) {
        return -ENOMEM;
    }
@@ -1005,7 +1006,7 @@ static int handle_open(struct fuse* fuse, struct fuse_handler* handler,
static int handle_read(struct fuse* fuse, struct fuse_handler* handler,
        const struct fuse_in_header* hdr, const struct fuse_read_in* req)
{
    struct handle *h = id_to_ptr(req->fh);
    struct handle *h = static_cast<struct handle*>(id_to_ptr(req->fh));
    __u64 unique = hdr->unique;
    __u32 size = req->size;
    __u64 offset = req->offset;
@@ -1034,7 +1035,7 @@ static int handle_write(struct fuse* fuse, struct fuse_handler* handler,
        const void* buffer)
{
    struct fuse_write_out out;
    struct handle *h = id_to_ptr(req->fh);
    struct handle *h = static_cast<struct handle*>(id_to_ptr(req->fh));
    int res;
    __u8 aligned_buffer[req->size] __attribute__((__aligned__(PAGE_SIZE)));

@@ -1089,7 +1090,7 @@ static int handle_statfs(struct fuse* fuse, struct fuse_handler* handler,
static int handle_release(struct fuse* fuse, struct fuse_handler* handler,
        const struct fuse_in_header* hdr, const struct fuse_release_in* req)
{
    struct handle *h = id_to_ptr(req->fh);
    struct handle *h = static_cast<struct handle*>(id_to_ptr(req->fh));

    TRACE("[%d] RELEASE %p(%d)\n", handler->token, h, h->fd);
    close(h->fd);
@@ -1105,16 +1106,16 @@ static int handle_fsync(struct fuse* fuse, struct fuse_handler* handler,

    int fd = -1;
    if (is_dir) {
      struct dirhandle *dh = id_to_ptr(req->fh);
      struct dirhandle *dh = static_cast<struct dirhandle*>(id_to_ptr(req->fh));
      fd = dirfd(dh->d);
    } else {
      struct handle *h = id_to_ptr(req->fh);
      struct handle *h = static_cast<struct handle*>(id_to_ptr(req->fh));
      fd = h->fd;
    }

    TRACE("[%d] %s %p(%d) is_data_sync=%d\n", handler->token,
            is_dir ? "FSYNCDIR" : "FSYNC",
            id_to_ptr(req->fh), fd, is_data_sync);
            static_cast<struct node*>(id_to_ptr(req->fh)), fd, is_data_sync);
    int res = is_data_sync ? fdatasync(fd) : fsync(fd);
    if (res == -1) {
        return -errno;
@@ -1149,7 +1150,7 @@ static int handle_opendir(struct fuse* fuse, struct fuse_handler* handler,
    if (!check_caller_access_to_node(fuse, hdr, node, R_OK)) {
        return -EACCES;
    }
    h = malloc(sizeof(*h));
    h = static_cast<struct dirhandle*>(malloc(sizeof(*h)));
    if (!h) {
        return -ENOMEM;
    }
@@ -1178,7 +1179,7 @@ static int handle_readdir(struct fuse* fuse, struct fuse_handler* handler,
    char buffer[8192];
    struct fuse_dirent *fde = (struct fuse_dirent*) buffer;
    struct dirent *de;
    struct dirhandle *h = id_to_ptr(req->fh);
    struct dirhandle *h = static_cast<struct dirhandle*>(id_to_ptr(req->fh));

    TRACE("[%d] READDIR %p\n", handler->token, h);
    if (req->offset == 0) {
@@ -1204,7 +1205,7 @@ static int handle_readdir(struct fuse* fuse, struct fuse_handler* handler,
static int handle_releasedir(struct fuse* fuse, struct fuse_handler* handler,
        const struct fuse_in_header* hdr, const struct fuse_release_in* req)
{
    struct dirhandle *h = id_to_ptr(req->fh);
    struct dirhandle *h = static_cast<struct dirhandle*>(id_to_ptr(req->fh));

    TRACE("[%d] RELEASEDIR %p\n", handler->token, h);
    closedir(h->d);
@@ -1266,51 +1267,51 @@ static int handle_fuse_request(struct fuse *fuse, struct fuse_handler* handler,
{
    switch (hdr->opcode) {
    case FUSE_LOOKUP: { /* bytez[] -> entry_out */
        const char* name = data;
        const char *name = static_cast<const char*>(data);
        return handle_lookup(fuse, handler, hdr, name);
    }

    case FUSE_FORGET: {
        const struct fuse_forget_in *req = data;
        const struct fuse_forget_in *req = static_cast<const struct fuse_forget_in*>(data);
        return handle_forget(fuse, handler, hdr, req);
    }

    case FUSE_GETATTR: { /* getattr_in -> attr_out */
        const struct fuse_getattr_in *req = data;
        const struct fuse_getattr_in *req = static_cast<const struct fuse_getattr_in*>(data);
        return handle_getattr(fuse, handler, hdr, req);
    }

    case FUSE_SETATTR: { /* setattr_in -> attr_out */
        const struct fuse_setattr_in *req = data;
        const struct fuse_setattr_in *req = static_cast<const struct fuse_setattr_in*>(data);
        return handle_setattr(fuse, handler, hdr, req);
    }

//    case FUSE_READLINK:
//    case FUSE_SYMLINK:
    case FUSE_MKNOD: { /* mknod_in, bytez[] -> entry_out */
        const struct fuse_mknod_in *req = data;
        const struct fuse_mknod_in *req = static_cast<const struct fuse_mknod_in*>(data);
        const char *name = ((const char*) data) + sizeof(*req);
        return handle_mknod(fuse, handler, hdr, req, name);
    }

    case FUSE_MKDIR: { /* mkdir_in, bytez[] -> entry_out */
        const struct fuse_mkdir_in *req = data;
        const struct fuse_mkdir_in *req = static_cast<const struct fuse_mkdir_in*>(data);
        const char *name = ((const char*) data) + sizeof(*req);
        return handle_mkdir(fuse, handler, hdr, req, name);
    }

    case FUSE_UNLINK: { /* bytez[] -> */
        const char* name = data;
        const char *name = static_cast<const char*>(data);
        return handle_unlink(fuse, handler, hdr, name);
    }

    case FUSE_RMDIR: { /* bytez[] -> */
        const char* name = data;
        const char *name = static_cast<const char*>(data);
        return handle_rmdir(fuse, handler, hdr, name);
    }

    case FUSE_RENAME: { /* rename_in, oldname, newname ->  */
        const struct fuse_rename_in *req = data;
        const struct fuse_rename_in *req = static_cast<const struct fuse_rename_in*>(data);
        const char *old_name = ((const char*) data) + sizeof(*req);
        const char *new_name = old_name + strlen(old_name) + 1;
        return handle_rename(fuse, handler, hdr, req, old_name, new_name);
@@ -1318,17 +1319,17 @@ static int handle_fuse_request(struct fuse *fuse, struct fuse_handler* handler,

//    case FUSE_LINK:
    case FUSE_OPEN: { /* open_in -> open_out */
        const struct fuse_open_in *req = data;
        const struct fuse_open_in *req = static_cast<const struct fuse_open_in*>(data);
        return handle_open(fuse, handler, hdr, req);
    }

    case FUSE_READ: { /* read_in -> byte[] */
        const struct fuse_read_in *req = data;
        const struct fuse_read_in *req = static_cast<const struct fuse_read_in*>(data);
        return handle_read(fuse, handler, hdr, req);
    }

    case FUSE_WRITE: { /* write_in, byte[write_in.size] -> write_out */
        const struct fuse_write_in *req = data;
        const struct fuse_write_in *req = static_cast<const struct fuse_write_in*>(data);
        const void* buffer = (const __u8*)data + sizeof(*req);
        return handle_write(fuse, handler, hdr, req, buffer);
    }
@@ -1338,13 +1339,13 @@ static int handle_fuse_request(struct fuse *fuse, struct fuse_handler* handler,
    }

    case FUSE_RELEASE: { /* release_in -> */
        const struct fuse_release_in *req = data;
        const struct fuse_release_in *req = static_cast<const struct fuse_release_in*>(data);
        return handle_release(fuse, handler, hdr, req);
    }

    case FUSE_FSYNC:
    case FUSE_FSYNCDIR: {
        const struct fuse_fsync_in *req = data;
        const struct fuse_fsync_in *req = static_cast<const struct fuse_fsync_in*>(data);
        return handle_fsync(fuse, handler, hdr, req);
    }

@@ -1357,22 +1358,22 @@ static int handle_fuse_request(struct fuse *fuse, struct fuse_handler* handler,
    }

    case FUSE_OPENDIR: { /* open_in -> open_out */
        const struct fuse_open_in *req = data;
        const struct fuse_open_in *req = static_cast<const struct fuse_open_in*>(data);
        return handle_opendir(fuse, handler, hdr, req);
    }

    case FUSE_READDIR: {
        const struct fuse_read_in *req = data;
        const struct fuse_read_in *req = static_cast<const struct fuse_read_in*>(data);
        return handle_readdir(fuse, handler, hdr, req);
    }

    case FUSE_RELEASEDIR: { /* release_in -> */
        const struct fuse_release_in *req = data;
        const struct fuse_release_in *req = static_cast<const struct fuse_release_in*>(data);
        return handle_releasedir(fuse, handler, hdr, req);
    }

    case FUSE_INIT: { /* init_in -> init_out */
        const struct fuse_init_in *req = data;
        const struct fuse_init_in *req = static_cast<const struct fuse_init_in*>(data);
        return handle_init(fuse, handler, hdr, req);
    }

@@ -1404,7 +1405,8 @@ void handle_fuse_requests(struct fuse_handler* handler)
            continue;
        }

        const struct fuse_in_header *hdr = (void*)handler->request_buffer;
        const struct fuse_in_header* hdr =
            reinterpret_cast<const struct fuse_in_header*>(handler->request_buffer);
        if (hdr->len != (size_t)len) {
            ERROR("[%d] malformed header: len=%zu, hdr->len=%u\n",
                    handler->token, (size_t)len, hdr->len);
+0 −8
Original line number Diff line number Diff line
@@ -38,10 +38,6 @@

#include <private/android_filesystem_config.h>

#ifdef __cplusplus
extern "C" {
#endif

#define FUSE_TRACE 0

#if FUSE_TRACE
@@ -196,8 +192,4 @@ struct fuse_handler {
void handle_fuse_requests(struct fuse_handler* handler);
void derive_permissions_recursive_locked(struct fuse* fuse, struct node *parent);

#ifdef __cplusplus
}; /* extern "C" */
#endif

#endif  /* FUSE_H_ */