aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fuse_lowlevel.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fuse_lowlevel.c')
-rw-r--r--lib/fuse_lowlevel.c78
1 files changed, 72 insertions, 6 deletions
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index cb046aa..1276a0f 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -1994,6 +1994,77 @@ static bool want_flags_valid(uint64_t capable, uint64_t want)
return true;
}
+/**
+ * Get the wanted capability flags, converting from old format if necessary
+ */
+int fuse_convert_to_conn_want_ext(struct fuse_conn_info *conn)
+{
+ struct fuse_session *se = container_of(conn, struct fuse_session, conn);
+
+ /*
+ * Convert want to want_ext if necessary.
+ * For the high level interface this function might be called
+ * twice, once from the high level interface and once from the
+ * low level interface. Both, with different want_ext_default and
+ * want_default values. In order to suppress a failure for the
+ * second call, we check if the lower 32 bits of want_ext are
+ * already set to the value of want.
+ */
+ if (conn->want != se->conn_want &&
+ fuse_lower_32_bits(conn->want_ext) != conn->want) {
+ if (conn->want_ext != se->conn_want_ext) {
+ fuse_log(FUSE_LOG_ERR,
+ "%s: Both conn->want_ext and conn->want are set.\n"
+ "want=%x, want_ext=%lx, se->want=%lx se->want_ext=%lx\n",
+ __func__, conn->want, conn->want_ext,
+ se->conn_want, se->conn_want_ext);
+ return -EINVAL;
+ }
+
+ /* high bits from want_ext, low bits from want */
+ conn->want_ext = fuse_higher_32_bits(conn->want_ext) |
+ conn->want;
+ }
+
+ /* ensure there won't be a second conversion */
+ conn->want = fuse_lower_32_bits(conn->want_ext);
+
+ return 0;
+}
+
+bool fuse_set_feature_flag(struct fuse_conn_info *conn,
+ uint64_t flag)
+{
+ struct fuse_session *se = container_of(conn, struct fuse_session, conn);
+
+ if (conn->capable_ext & flag) {
+ conn->want_ext |= flag;
+ se->conn_want_ext |= flag;
+ conn->want |= flag;
+ se->conn_want |= flag;
+ return true;
+ }
+ return false;
+}
+
+void fuse_unset_feature_flag(struct fuse_conn_info *conn,
+ uint64_t flag)
+{
+ struct fuse_session *se = container_of(conn, struct fuse_session, conn);
+
+ conn->want_ext &= ~flag;
+ se->conn_want_ext &= ~flag;
+ conn->want &= ~flag;
+ se->conn_want &= ~flag;
+}
+
+bool fuse_get_feature_flag(struct fuse_conn_info *conn,
+ uint64_t flag)
+{
+ return conn->capable_ext & flag ? true : false;
+}
+
+
/* Prevent bogus data races (bogus since "init" is called before
* multi-threading becomes relevant */
static __attribute__((no_sanitize("thread")))
@@ -2154,12 +2225,8 @@ void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
se->got_init = 1;
if (se->op.init) {
- uint64_t want_ext_default = se->conn.want_ext;
- uint32_t want_default = fuse_lower_32_bits(se->conn.want_ext);
-
// Apply the first 32 bits of capable_ext to capable
se->conn.capable = fuse_lower_32_bits(se->conn.capable_ext);
- se->conn.want = want_default;
se->op.init(se->userdata, &se->conn);
@@ -2168,8 +2235,7 @@ void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
* se->conn.want_ext
* Userspace might still use conn.want - we need to convert it
*/
- convert_to_conn_want_ext(&se->conn, want_ext_default,
- want_default);
+ fuse_convert_to_conn_want_ext(&se->conn);
}
if (!want_flags_valid(se->conn.capable_ext, se->conn.want_ext)) {