scoutfs: add file with simple name functions

Directory entries and extended attributes similarly hash and compare
strings so we'll give them some shared functions for doing so.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2016-07-04 10:49:41 -07:00
parent a64ca8018a
commit cedeacacb8
4 changed files with 48 additions and 9 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ CFLAGS_scoutfs_trace.o = -I$(src) # define_trace.h double include
scoutfs-y += first.o
scoutfs-y += block.o btree.o buddy.o counters.o crc.o dir.o filerw.o \
inode.o ioctl.o msg.o scoutfs_trace.o super.o trace.o trans.o \
treap.o
inode.o ioctl.o msg.o name.o scoutfs_trace.o super.o trace.o \
trans.o treap.o
scoutfs-y += last.o
+3 -7
View File
@@ -23,6 +23,7 @@
#include "super.h"
#include "btree.h"
#include "trans.h"
#include "name.h"
/*
* Directory entries are stored in entries with offsets calculated from
@@ -84,11 +85,6 @@ static unsigned int dentry_type(unsigned int type)
return DT_UNKNOWN;
}
static int names_equal(const char *name_a, int len_a, const char *name_b,
int len_b)
{
return (len_a == len_b) && !memcmp(name_a, name_b, len_a);
}
/*
* XXX This crc nonsense is a quick hack. We'll want something a
@@ -209,8 +205,8 @@ static struct dentry *scoutfs_lookup(struct inode *dir, struct dentry *dentry,
dent = curs.val;
name_len = item_name_len(&curs);
if (names_equal(dentry->d_name.name, dentry->d_name.len,
dent->name, name_len)) {
if (scoutfs_names_equal(dentry->d_name.name, dentry->d_name.len,
dent->name, name_len)) {
ino = le64_to_cpu(dent->ino);
di->hash = scoutfs_key_offset(curs.key);
break;
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 Versity Software, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License v2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include <linux/kernel.h>
#include <linux/crc32c.h>
#include <linux/string.h>
#include "name.h"
/*
* XXX This crc nonsense is a quick hack. We'll want something a
* lot stronger like siphash.
*/
u64 scoutfs_name_hash(const char *name, unsigned int len)
{
unsigned int half = (len + 1) / 2;
return crc32c(~0, name, half) |
((u64)crc32c(~0, name + len - half, half) << 32);
}
int scoutfs_names_equal(const char *name_a, int len_a,
const char *name_b, int len_b)
{
return (len_a == len_b) && !memcmp(name_a, name_b, len_a);
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef _SCOUTFS_NAME_H_
#define _SCOUTFS_NAME_H_
u64 scoutfs_name_hash(const char *data, unsigned int len);
int scoutfs_names_equal(const char *name_a, int len_a,
const char *name_b, int len_b);
#endif