From: Yu Kuai yukuai3@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT
--------------------------------
cachefile is combined by: hulk-5.10: index cookie + data cookie linux-next: volume + cookie
1) for index cookie, cache dir is combined by csum + cache dir; 2) for volume from mainline, cache dir doens't contain csum; 3) for data cookie, cache file is combined by csum + cache file;
On the one hand, the way to generate csum is different from mainline, on the other hand, csum only exist for data cookie for mainline. There are no functional changes for now, and prepare to keep cachefile location the same as mainline.
Signed-off-by: Yu Kuai yukuai3@huawei.com Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/cachefiles/key.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/fs/cachefiles/key.c b/fs/cachefiles/key.c index c43808c82de0..1e2f840dabaa 100644 --- a/fs/cachefiles/key.c +++ b/fs/cachefiles/key.c @@ -30,6 +30,18 @@ static void cachefiles_cook_acc(char *key, unsigned int acc, int *len) *len += 2; }
+static int cachefiles_cook_csum(const u8 *raw, int keylen, char *key) +{ + unsigned char csum = 0; + int loop; + + for (loop = 0; loop < keylen; loop++) + csum += raw[loop]; + sprintf(key, "@%02x%c+", (unsigned int) csum, 0); + + return 5; +} + /* * turn the raw key into something cooked * - the raw key should include the length in the two bytes at the front @@ -40,7 +52,6 @@ static void cachefiles_cook_acc(char *key, unsigned int acc, int *len) */ char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type) { - unsigned char csum, ch; unsigned int acc; char *key; int loop, len, max, seg, mark, print; @@ -49,13 +60,9 @@ char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type)
BUG_ON(keylen < 2 || keylen > 514);
- csum = raw[0] + raw[1]; print = 1; - for (loop = 2; loop < keylen; loop++) { - ch = raw[loop]; - csum += ch; - print &= cachefiles_filecharmap[ch]; - } + for (loop = 2; loop < keylen; loop++) + print &= cachefiles_filecharmap[raw[loop]];
if (print) { /* if the path is usable ASCII, then we render it directly */ @@ -86,11 +93,7 @@ char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type) if (!key) return NULL;
- len = 0; - - /* build the cooked key */ - sprintf(key, "@%02x%c+", (unsigned) csum, 0); - len = 5; + len = cachefiles_cook_csum(raw, keylen, key); mark = len - 1;
if (print) {