* commit 'b91e700544e0fca378a7fb5f8c807842bb284986': recovery: Switch fuse_* to C++.
This commit is contained in:
+2
-2
@@ -16,7 +16,7 @@ LOCAL_PATH := $(call my-dir)
|
|||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_SRC_FILES := fuse_sideload.c
|
LOCAL_SRC_FILES := fuse_sideload.cpp
|
||||||
LOCAL_CLANG := true
|
LOCAL_CLANG := true
|
||||||
LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter
|
LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter
|
||||||
LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
|
LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
|
||||||
@@ -33,7 +33,7 @@ LOCAL_SRC_FILES := \
|
|||||||
asn1_decoder.cpp \
|
asn1_decoder.cpp \
|
||||||
bootloader.cpp \
|
bootloader.cpp \
|
||||||
device.cpp \
|
device.cpp \
|
||||||
fuse_sdcard_provider.c \
|
fuse_sdcard_provider.cpp \
|
||||||
install.cpp \
|
install.cpp \
|
||||||
recovery.cpp \
|
recovery.cpp \
|
||||||
roots.cpp \
|
roots.cpp \
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ struct file_data {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size) {
|
static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32_t fetch_size) {
|
||||||
struct file_data* fd = (struct file_data*)cookie;
|
file_data* fd = reinterpret_cast<file_data*>(cookie);
|
||||||
|
|
||||||
off64_t offset = ((off64_t) block) * fd->block_size;
|
off64_t offset = ((off64_t) block) * fd->block_size;
|
||||||
if (TEMP_FAILURE_RETRY(lseek64(fd->fd, offset, SEEK_SET)) == -1) {
|
if (TEMP_FAILURE_RETRY(lseek64(fd->fd, offset, SEEK_SET)) == -1) {
|
||||||
@@ -56,7 +56,7 @@ static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void close_file(void* cookie) {
|
static void close_file(void* cookie) {
|
||||||
struct file_data* fd = (struct file_data*)cookie;
|
file_data* fd = reinterpret_cast<file_data*>(cookie);
|
||||||
close(fd->fd);
|
close(fd->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ struct token {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void* run_sdcard_fuse(void* cookie) {
|
static void* run_sdcard_fuse(void* cookie) {
|
||||||
struct token* t = (struct token*)cookie;
|
token* t = reinterpret_cast<token*>(cookie);
|
||||||
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (stat(t->path, &sb) < 0) {
|
if (stat(t->path, &sb) < 0) {
|
||||||
@@ -100,7 +100,7 @@ static void* run_sdcard_fuse(void* cookie) {
|
|||||||
#define SDCARD_INSTALL_TIMEOUT 10
|
#define SDCARD_INSTALL_TIMEOUT 10
|
||||||
|
|
||||||
void* start_sdcard_fuse(const char* path) {
|
void* start_sdcard_fuse(const char* path) {
|
||||||
struct token* t = malloc(sizeof(struct token));
|
token* t = new token;
|
||||||
|
|
||||||
t->path = path;
|
t->path = path;
|
||||||
pthread_create(&(t->th), NULL, run_sdcard_fuse, t);
|
pthread_create(&(t->th), NULL, run_sdcard_fuse, t);
|
||||||
@@ -128,7 +128,7 @@ void* start_sdcard_fuse(const char* path) {
|
|||||||
|
|
||||||
void finish_sdcard_fuse(void* cookie) {
|
void finish_sdcard_fuse(void* cookie) {
|
||||||
if (cookie == NULL) return;
|
if (cookie == NULL) return;
|
||||||
struct token* t = (struct token*)cookie;
|
token* t = reinterpret_cast<token*>(cookie);
|
||||||
|
|
||||||
// Calling stat() on this magic filename signals the fuse
|
// Calling stat() on this magic filename signals the fuse
|
||||||
// filesystem to shut down.
|
// filesystem to shut down.
|
||||||
@@ -136,5 +136,5 @@ void finish_sdcard_fuse(void* cookie) {
|
|||||||
stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
|
stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
|
||||||
|
|
||||||
pthread_join(t->th, NULL);
|
pthread_join(t->th, NULL);
|
||||||
free(t);
|
delete t;
|
||||||
}
|
}
|
||||||
@@ -17,13 +17,7 @@
|
|||||||
#ifndef __FUSE_SDCARD_PROVIDER_H
|
#ifndef __FUSE_SDCARD_PROVIDER_H
|
||||||
#define __FUSE_SDCARD_PROVIDER_H
|
#define __FUSE_SDCARD_PROVIDER_H
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
|
||||||
|
|
||||||
void* start_sdcard_fuse(const char* path);
|
void* start_sdcard_fuse(const char* path);
|
||||||
void finish_sdcard_fuse(void* token);
|
void finish_sdcard_fuse(void* token);
|
||||||
|
|
||||||
__END_DECLS
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ static void fuse_reply(struct fuse_data* fd, __u64 unique, const void *data, siz
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int handle_init(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
static int handle_init(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
||||||
const struct fuse_init_in* req = data;
|
const struct fuse_init_in* req = reinterpret_cast<const struct fuse_init_in*>(data);
|
||||||
struct fuse_init_out out;
|
struct fuse_init_out out;
|
||||||
size_t fuse_struct_size;
|
size_t fuse_struct_size;
|
||||||
|
|
||||||
@@ -170,8 +170,7 @@ static void fill_attr(struct fuse_attr* attr, struct fuse_data* fd,
|
|||||||
attr->mode = mode;
|
attr->mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_getattr(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
static int handle_getattr(void* /* data */, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
||||||
const struct fuse_getattr_in* req = data;
|
|
||||||
struct fuse_attr_out out;
|
struct fuse_attr_out out;
|
||||||
memset(&out, 0, sizeof(out));
|
memset(&out, 0, sizeof(out));
|
||||||
out.attr_valid = 10;
|
out.attr_valid = 10;
|
||||||
@@ -197,12 +196,12 @@ static int handle_lookup(void* data, struct fuse_data* fd,
|
|||||||
out.entry_valid = 10;
|
out.entry_valid = 10;
|
||||||
out.attr_valid = 10;
|
out.attr_valid = 10;
|
||||||
|
|
||||||
if (strncmp(FUSE_SIDELOAD_HOST_FILENAME, data,
|
if (strncmp(FUSE_SIDELOAD_HOST_FILENAME, reinterpret_cast<const char*>(data),
|
||||||
sizeof(FUSE_SIDELOAD_HOST_FILENAME)) == 0) {
|
sizeof(FUSE_SIDELOAD_HOST_FILENAME)) == 0) {
|
||||||
out.nodeid = PACKAGE_FILE_ID;
|
out.nodeid = PACKAGE_FILE_ID;
|
||||||
out.generation = PACKAGE_FILE_ID;
|
out.generation = PACKAGE_FILE_ID;
|
||||||
fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444);
|
fill_attr(&(out.attr), fd, PACKAGE_FILE_ID, fd->file_size, S_IFREG | 0444);
|
||||||
} else if (strncmp(FUSE_SIDELOAD_HOST_EXIT_FLAG, data,
|
} else if (strncmp(FUSE_SIDELOAD_HOST_EXIT_FLAG, reinterpret_cast<const char*>(data),
|
||||||
sizeof(FUSE_SIDELOAD_HOST_EXIT_FLAG)) == 0) {
|
sizeof(FUSE_SIDELOAD_HOST_EXIT_FLAG)) == 0) {
|
||||||
out.nodeid = EXIT_FLAG_ID;
|
out.nodeid = EXIT_FLAG_ID;
|
||||||
out.generation = EXIT_FLAG_ID;
|
out.generation = EXIT_FLAG_ID;
|
||||||
@@ -215,9 +214,7 @@ static int handle_lookup(void* data, struct fuse_data* fd,
|
|||||||
return (out.nodeid == EXIT_FLAG_ID) ? NO_STATUS_EXIT : NO_STATUS;
|
return (out.nodeid == EXIT_FLAG_ID) ? NO_STATUS_EXIT : NO_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_open(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
static int handle_open(void* /* data */, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
||||||
const struct fuse_open_in* req = data;
|
|
||||||
|
|
||||||
if (hdr->nodeid == EXIT_FLAG_ID) return -EPERM;
|
if (hdr->nodeid == EXIT_FLAG_ID) return -EPERM;
|
||||||
if (hdr->nodeid != PACKAGE_FILE_ID) return -ENOENT;
|
if (hdr->nodeid != PACKAGE_FILE_ID) return -ENOENT;
|
||||||
|
|
||||||
@@ -292,7 +289,7 @@ static int fetch_block(struct fuse_data* fd, uint32_t block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int handle_read(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
static int handle_read(void* data, struct fuse_data* fd, const struct fuse_in_header* hdr) {
|
||||||
const struct fuse_read_in* req = data;
|
const struct fuse_read_in* req = reinterpret_cast<const struct fuse_read_in*>(data);
|
||||||
struct fuse_out_header outhdr;
|
struct fuse_out_header outhdr;
|
||||||
struct iovec vec[3];
|
struct iovec vec[3];
|
||||||
int vec_used;
|
int vec_used;
|
||||||
@@ -17,10 +17,6 @@
|
|||||||
#ifndef __FUSE_SIDELOAD_H
|
#ifndef __FUSE_SIDELOAD_H
|
||||||
#define __FUSE_SIDELOAD_H
|
#define __FUSE_SIDELOAD_H
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
|
||||||
|
|
||||||
// define the filenames created by the sideload FUSE filesystem
|
// define the filenames created by the sideload FUSE filesystem
|
||||||
#define FUSE_SIDELOAD_HOST_MOUNTPOINT "/sideload"
|
#define FUSE_SIDELOAD_HOST_MOUNTPOINT "/sideload"
|
||||||
#define FUSE_SIDELOAD_HOST_FILENAME "package.zip"
|
#define FUSE_SIDELOAD_HOST_FILENAME "package.zip"
|
||||||
@@ -39,6 +35,4 @@ struct provider_vtab {
|
|||||||
int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,
|
int run_fuse_sideload(struct provider_vtab* vtab, void* cookie,
|
||||||
uint64_t file_size, uint32_t block_size);
|
uint64_t file_size, uint32_t block_size);
|
||||||
|
|
||||||
__END_DECLS
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user