From aee209732a5296129b2955554c31d4eed2745bcc Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 28 Apr 2011 13:57:45 -0700 Subject: [PATCH] lfn: set hash and file name constants --- src/os/FileStore.cc | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 0c6952ab3d71c..ffbee365aec22 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -84,24 +84,25 @@ #include "common/ceph_crypto.h" -using ceph::crypto::SHA256; -// using ceph::crypto::SHA1; +using ceph::crypto::SHA1; /* * long file names will have the following format: * - * prefix_cookie_hash_index + * prefix_hash_index_cookie * * The prefix will just be the first X bytes of the original file name. - * The cookie is a constant string that hints whether this file name + * The cookie is a constant string that shows whether this file name * is hashed */ -#define FILENAME_MAX_LEN 4096 // the long file name size -#define FILENAME_SHORT_LEN 20 // the short file name size -#define FILENAME_COOKIE "long" // ceph long file name -#define FILENAME_HASH_LEN 3 -#define FILENAME_EXTRA 4 // underscores and digit +#define FILENAME_LFN_DIGEST_SIZE CEPH_CRYPTO_SHA1_DIGESTSIZE + +#define FILENAME_MAX_LEN 4096 // the long file name size +#define FILENAME_SHORT_LEN 255 // the short file name size +#define FILENAME_COOKIE "long" // ceph long file name +#define FILENAME_HASH_LEN FILENAME_LFN_DIGEST_SIZE +#define FILENAME_EXTRA 4 // underscores and digit #define FILENAME_PREFIX_LEN (FILENAME_SHORT_LEN - FILENAME_HASH_LEN - (sizeof(FILENAME_COOKIE) - 1) - FILENAME_EXTRA) @@ -176,19 +177,17 @@ static int hash_filename(const char *filename, char *hash, int buf_len) { if (buf_len < FILENAME_HASH_LEN + 1) return -EINVAL; -#if 0 - char buf[CEPH_CRYPTO_SHA256_DIGESTSIZE]; - char hex[CEPH_CRYPTO_SHA256_DIGESTSIZE * 2]; - SHA256 h; + + char buf[FILENAME_LFN_DIGEST_SIZE]; + char hex[FILENAME_LFN_DIGEST_SIZE * 2]; + + SHA1 h; h.Update((const byte *)filename, strlen(filename)); h.Final((byte *)buf); buf_to_hex((byte *)buf, (FILENAME_HASH_LEN + 1) / 2, hex); strncpy(hash, hex, FILENAME_HASH_LEN); hash[FILENAME_HASH_LEN] = '\0'; -#endif - memset(hash, 'z', FILENAME_HASH_LEN); - hash[FILENAME_HASH_LEN] = '\0'; return 0; } -- 2.39.5