aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cachefiles/internal.h
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2021-11-17 15:48:06 +0000
committerDavid Howells <dhowells@redhat.com>2022-01-07 13:42:16 +0000
commit5d439467b802f5c6393b20d57662500dfb177c8f (patch)
treeed356351e8e25095ef79610b904314d5774b814a /fs/cachefiles/internal.h
parentcachefiles: Implement object lifecycle funcs (diff)
downloadlinux-dev-5d439467b802f5c6393b20d57662500dfb177c8f.tar.xz
linux-dev-5d439467b802f5c6393b20d57662500dfb177c8f.zip
cachefiles: Implement key to filename encoding
Implement a function to encode a binary cookie key as something that can be used as a filename. Four options are considered: (1) All printable chars with no '/' characters. Prepend a 'D' to indicate the encoding but otherwise use as-is. (2) Appears to be an array of __be32. Encode as 'S' plus a list of hex-encoded 32-bit ints separated by commas. If a number is 0, it is rendered as "" instead of "0". (3) Appears to be an array of __le32. Encoded as (2) but with a 'T' encoding prefix. (4) Encoded as base64 with an 'E' prefix plus a second char indicating how much padding is involved. A non-standard base64 encoding is used because '/' cannot be used in the encoded form. If (1) is not possible, whichever of (2), (3) or (4) produces the shortest string is selected (hex-encoding a number may be less dense than base64 encoding it). Note that the prefix characters have to be selected from the set [DEIJST@] lest cachefilesd remove the files because it recognise the name. Changes ======= ver #2: - Fix a short allocation that didn't allow for a string terminator[1] Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> cc: linux-cachefs@redhat.com Link: https://lore.kernel.org/r/bcefb8f2-576a-b3fc-cc29-89808ebfd7c1@linux.alibaba.com/ [1] Link: https://lore.kernel.org/r/163819640393.215744.15212364106412961104.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906940529.143852.17352132319136117053.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967149827.1823006.6088580775428487961.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021549223.640689.14762875188193982341.stgit@warthog.procyon.org.uk/ # v4
Diffstat (limited to 'fs/cachefiles/internal.h')
-rw-r--r--fs/cachefiles/internal.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
index 8763ee4a0df2..dbc37f5d4714 100644
--- a/fs/cachefiles/internal.h
+++ b/fs/cachefiles/internal.h
@@ -174,6 +174,11 @@ extern void cachefiles_put_object(struct cachefiles_object *object,
enum cachefiles_obj_ref_trace why);
/*
+ * key.c
+ */
+extern bool cachefiles_cook_key(struct cachefiles_object *object);
+
+/*
* main.c
*/
extern struct kmem_cache *cachefiles_object_jar;