summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2014-09-16 14:53:39 -0700
committerChristopher Ferris <cferris@google.com>2014-09-17 17:10:41 -0700
commit1d30c2fe19fdbdfd6e5f52102247cf01b87e586e (patch)
tree3f46ac3107116bb56b8f696faf909543afe73159
parent52ae67d659e92bdd32c7c2a6b4d09dfe94e987fe (diff)
downloadbootable_recovery-1d30c2fe19fdbdfd6e5f52102247cf01b87e586e.zip
bootable_recovery-1d30c2fe19fdbdfd6e5f52102247cf01b87e586e.tar.gz
bootable_recovery-1d30c2fe19fdbdfd6e5f52102247cf01b87e586e.tar.bz2
Use the correct fuse_init_out structure size.
Kernel 2.6.16 is the first stable kernel with struct fuse_init_out defined (fuse version 7.6). The structure is the same from 7.6 through 7.22. Beginning with 7.23, the structure increased in size and added new parameters. If the kernel only works on minor revs older than or equal to 22, then use the older structure size since this code only uses the 7.22 version of the structure. Change-Id: I00d7530e01e6b4718dcd04ad2484959d12ef4a65
-rw-r--r--fuse_sideload.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/fuse_sideload.c b/fuse_sideload.c
index ab91def..4e11e01 100644
--- a/fuse_sideload.c
+++ b/fuse_sideload.c
@@ -53,6 +53,7 @@
#include <string.h>
#include <sys/inotify.h>
#include <sys/mount.h>
+#include <sys/param.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/statfs.h>
@@ -117,15 +118,40 @@ 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) {
const struct fuse_init_in* req = data;
struct fuse_init_out out;
+ size_t fuse_struct_size;
+
+
+ /* Kernel 2.6.16 is the first stable kernel with struct fuse_init_out
+ * defined (fuse version 7.6). The structure is the same from 7.6 through
+ * 7.22. Beginning with 7.23, the structure increased in size and added
+ * new parameters.
+ */
+ if (req->major != FUSE_KERNEL_VERSION || req->minor < 6) {
+ printf("Fuse kernel version mismatch: Kernel version %d.%d, Expected at least %d.6",
+ req->major, req->minor, FUSE_KERNEL_VERSION);
+ return -1;
+ }
+
+ out.minor = MIN(req->minor, FUSE_KERNEL_MINOR_VERSION);
+ fuse_struct_size = sizeof(out);
+#if defined(FUSE_COMPAT_22_INIT_OUT_SIZE)
+ /* FUSE_KERNEL_VERSION >= 23. */
+
+ /* If the kernel only works on minor revs older than or equal to 22,
+ * then use the older structure size since this code only uses the 7.22
+ * version of the structure. */
+ if (req->minor <= 22) {
+ fuse_struct_size = FUSE_COMPAT_22_INIT_OUT_SIZE;
+ }
+#endif
out.major = FUSE_KERNEL_VERSION;
- out.minor = FUSE_KERNEL_MINOR_VERSION;
out.max_readahead = req->max_readahead;
out.flags = 0;
out.max_background = 32;
out.congestion_threshold = 32;
out.max_write = 4096;
- fuse_reply(fd, hdr->unique, &out, sizeof(out));
+ fuse_reply(fd, hdr->unique, &out, fuse_struct_size);
return NO_STATUS;
}