Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jun 2012 15:53:18 +0000
From:      gpf@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r238270 - soc2012/gpf/pefs_kmod/sys/fs/pefs
Message-ID:  <20120625155319.046A71065673@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gpf
Date: Mon Jun 25 15:53:17 2012
New Revision: 238270
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238270

Log:
  - adding sys/fs/pefs_checksum.c & .h
  

Added:
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h

Added: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c	Mon Jun 25 15:53:17 2012	(r238270)
@@ -0,0 +1,172 @@
+/*-
+ * Copyright (c) 2012 Efstratios Karatzas
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mount.h>
+#include <sys/namei.h>
+#include <sys/stat.h>
+#include <sys/vnode.h>
+#include <sys/dirent.h>
+#include <sys/endian.h>
+#include <sys/fnv_hash.h>
+
+#include <fs/pefs/pefs.h>
+#include <fs/pefs/pefs_checksum.h>
+
+static uint32_t
+pefs_checksum_hash1(struct pefs_checksum *pc, struct pefs_checksum_index_entry *pcie)
+{
+	uint32_t nbucket;
+
+	nbucket = pcie->pcie_file_id % pc->pcs_hash_table_size;
+	printf("hash1: goto bucket %d\n", nbucket);
+	return (nbucket);
+}
+
+static uint32_t
+pefs_checksum_hash2(struct pefs_checksum *pc, struct pefs_checksum_index_entry *pcie)
+{
+	uint32_t nbucket;
+
+	nbucket = fnv_64_buf(&(pcie->pcie_file_id), sizeof(pcie->pcie_file_id), FNV1_64_INIT)
+			% pc->pcs_hash_table_size;
+	printf("hash2: goto bucket %d\n", nbucket);
+
+	return (nbucket);
+}
+
+static void
+pefs_checksum_index_lookup(struct pefs_checksum_index_entry *pcie, struct vnode *vp)
+{
+	struct pefs_checksum_index_entry target_pcie;
+	struct pefs_mount *pm = VFS_TO_PEFS(vp->v_mount);
+	struct pefs_checksum *pcs = &(pm->pm_checksum);
+	struct pefs_node *pn = VP_TO_PN(vp);
+	char *start, *p;
+	uint32_t pos;
+
+	pos = pefs_checksum_hash1(pcs, pcie);
+	start = &(pcs->pcs_table1[pos * PEFS_HT_CELL_SIZE]);
+	p = start;
+
+	memcpy(&(target_pcie.pcie_nhashes), p, sizeof(target_pcie.pcie_nhashes));
+	target_pcie.pcie_nhashes = le32toh(target_pcie.pcie_nhashes);
+	if (target_pcie.pcie_nhashes != 0) {
+		p+=sizeof(target_pcie.pcie_nhashes);
+
+		memcpy(&(target_pcie.pcie_offset), p, sizeof(target_pcie.pcie_offset));
+		target_pcie.pcie_offset = le32toh(target_pcie.pcie_offset);
+		p+=sizeof(target_pcie.pcie_offset);
+
+		memcpy(&(target_pcie.pcie_file_id), p, sizeof(target_pcie.pcie_file_id));
+		target_pcie.pcie_file_id = le64toh(target_pcie.pcie_file_id);
+		printf("cell %d:\n", pos);
+		printf("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
+			target_pcie.pcie_nhashes, target_pcie.pcie_offset, target_pcie.pcie_file_id);
+
+		if (target_pcie.pcie_file_id == pcie->pcie_file_id) {
+			pn->pn_checksum_index_entry = start;
+			printf("checksum lookup: found1!\n");
+			return;
+		}
+	}
+
+	pos = pefs_checksum_hash2(pcs, pcie);
+	start = &(pcs->pcs_table2[pos * PEFS_HT_CELL_SIZE]);
+	p = start;
+
+	memcpy(&(target_pcie.pcie_nhashes), p, sizeof(target_pcie.pcie_nhashes));
+	target_pcie.pcie_nhashes = le32toh(target_pcie.pcie_nhashes);
+	if (target_pcie.pcie_nhashes != 0) {
+		p+=sizeof(target_pcie.pcie_nhashes);
+
+		memcpy(&(target_pcie.pcie_offset), p, sizeof(target_pcie.pcie_offset));
+		target_pcie.pcie_offset = le32toh(target_pcie.pcie_offset);
+		p+=sizeof(target_pcie.pcie_offset);
+
+		memcpy(&(target_pcie.pcie_file_id), p, sizeof(target_pcie.pcie_file_id));
+		target_pcie.pcie_file_id = le64toh(target_pcie.pcie_file_id);
+		printf("cell %d:\n", pos);
+		printf("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
+			target_pcie.pcie_nhashes, target_pcie.pcie_offset, target_pcie.pcie_file_id);
+
+		if (target_pcie.pcie_file_id == pcie->pcie_file_id) {
+			pn->pn_checksum_index_entry = start;
+			printf("checksum lookup: found2!\n");
+			return;
+		}
+	}
+
+	pn->pn_checksum_index_entry = NULL;
+	printf("checksum lookup: not found!\n");
+}
+
+void
+pefs_checksum_lookup(char *enc_name, size_t enc_name_len, struct componentname *cnp, struct vnode *vp)
+{
+	struct pefs_checksum_index_entry pcie;
+	char *buf;
+	size_t buf_len;
+	int error, r;
+
+	printf("gpf: checksum code @ lookup\n");
+	if (cnp->cn_nameiop != LOOKUP || (vp->v_type != VREG && vp->v_type != VLNK))
+		return;
+
+	/* XXXgpf: What if user wants integrity checking for .pefs.db or .conf? */
+	/* XXXgpf: [TODO] move this check to a mini function */
+	if (strncmp(enc_name, ".pefs.db", enc_name_len) == 0 ||
+		strncmp(enc_name, ".pefs.conf", enc_name_len) == 0 ||
+		strncmp(enc_name, ".pefs.checksum", enc_name_len) == 0)
+		return;
+
+	enc_name++;
+	enc_name_len--;
+	buf_len = MAXNAMLEN + 1;
+	buf = malloc(buf_len, M_TEMP, M_WAITOK);
+
+	r = pefs_name_pton(enc_name, enc_name_len, buf, buf_len);
+	if (r <= 0) {
+		/* XXXgpf: I sincerely doubt an error can occur here */
+		error = EINVAL;
+		printf("name_pton error: %d\n", error);
+	}
+	else {
+		memcpy(&(pcie.pcie_file_id), buf, sizeof(pcie.pcie_file_id));
+		pcie.pcie_file_id = be64toh(pcie.pcie_file_id);
+		printf("id to lookup: %llu\n", pcie.pcie_file_id);
+		pefs_checksum_index_lookup(&pcie, vp);
+	}
+
+	free(buf, M_TEMP);
+}

Added: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h	Mon Jun 25 15:53:17 2012	(r238270)
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2012 Efstratios Karatzas
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#define PEFS_FILE_CHECKSUM		".pefs.checksum"
+#define PEFS_CFH_SIZE 16	/* file header of .pefs.checksum file */
+#define PEFS_HT_CELL_SIZE 16 /* hash table cell(bucket) size */
+
+struct pefs_checksum_index_entry {
+	uint32_t pcie_nhashes;
+	uint32_t pcie_offset;
+	uint64_t pcie_file_id;
+};
+
+void	pefs_checksum_lookup(char *enc_name, size_t enc_name_len, struct componentname *cnp, struct vnode *vp);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120625155319.046A71065673>