Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Aug 2012 15:51:35 +0000
From:      gpf@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r240245 - in soc2012/gpf/pefs_kmod: sbin/pefs sys/fs/pefs
Message-ID:  <20120810155135.D6BDB1065674@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gpf
Date: Fri Aug 10 15:51:34 2012
New Revision: 240245
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240245

Log:
  rework how nameids are used by the codebase.
  

Modified:
  soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c
  soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_mac.c

Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c	Fri Aug 10 14:51:41 2012	(r240244)
+++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c	Fri Aug 10 15:51:34 2012	(r240245)
@@ -127,12 +127,17 @@
 	TAILQ_ENTRY(checksum) checksum_entries;
 };
 
+union file_id {
+	uint64_t fid_num;
+	uint8_t	fid_str[8];
+};
+
 /* XXXgpf: [TODO] turns offsets to uint64_t? */
 struct file_header {
 	/* on disk information */
 	uint32_t nhashes;	/* the number of hashes for the file */
 	uint32_t offset_to_checksums;	/* in file offset to start of checksums */
-	uint64_t file_id;	/* id is MAC tweak from filename (first 64 bits) */
+	union file_id fid;	/* id is MAC tweak from filename (first 64 bits) */
 
 	/* in memory information */
 	char path[MAXPATHLEN + 1];	/* fullpath for this file */
@@ -472,7 +477,7 @@
 
 	fhp->nhashes = 0;
 	fhp->offset_to_checksums = 0;
-	fhp->file_id = 0;
+	fhp->fid.fid_num = 0;
 	fhp->fd = -1;
 	fhp->pfd = -1;
 	fhp->found = 0;
@@ -545,7 +550,7 @@
 {
 	uint32_t nbucket;
 
-	nbucket = fhp->file_id % chtp->size;
+	nbucket = fhp->fid.fid_num % chtp->size;
 	dprintf(("hash1: goto bucket %d\n", nbucket));
 	return (nbucket);
 }
@@ -555,8 +560,8 @@
 {
 	uint32_t nbucket;
 
-	nbucket = fnv_64_buf(&(fhp->file_id), sizeof(fhp->file_id), FNV1_64_INIT) %
-			chtp->size;
+	nbucket = fnv_64_buf(&(fhp->fid.fid_num), sizeof(fhp->fid.fid_num),
+		FNV1_64_INIT) %	chtp->size;
 	dprintf(("hash2: goto bucket %d\n", nbucket));
 
 	return (nbucket);
@@ -572,7 +577,7 @@
 	pos1 = pefs_hash1(chtp, elem);
 	elem1 = chtp->buckets1[pos1].fhp;
 	if (elem1 != NULL) {
-		if (elem1->file_id == elem->file_id) {
+		if (elem1->fid.fid_num == elem->fid.fid_num) {
 			return (elem1);
 		}
 	}
@@ -580,7 +585,7 @@
 	pos2 = pefs_hash2(chtp, elem);
 	elem2 = chtp->buckets2[pos2].fhp;
 	if (elem2 != NULL) {
-		if (elem2->file_id == elem->file_id) {
+		if (elem2->fid.fid_num == elem->fid.fid_num) {
 			return (elem2);
 		}
 	}
@@ -648,7 +653,8 @@
 		fhp = chtp->buckets1[i].fhp;
 		dprintf(("\nbucket %d with element: %d\n", i, fhp == NULL ? 0 : 1));
 		if (fhp != NULL) {
-			dprintf(("\tid = %llu\tnhashes = %d\n", fhp->file_id, fhp->nhashes));
+			dprintf(("\tid = %llu\tnhashes = %d\n", fhp->fid.fid_num,
+				fhp->nhashes));
 			if (fhp->path[0] == '/')
 				dprintf(("\tpath = %s\n", fhp->path));
 			TAILQ_FOREACH(csp, &(fhp->checksums), checksum_entries) {
@@ -665,7 +671,8 @@
 		fhp = chtp->buckets2[i].fhp;
 		dprintf(("\nbucket %d with element: %d\n", i, fhp == NULL ? 0 : 1));
 		if (fhp != NULL) {
-			dprintf(("\tid = %llu\tnhashes = %d\n", fhp->file_id, fhp->nhashes));
+			dprintf(("\tid = %llu\tnhashes = %d\n", fhp->fid.fid_num,
+				fhp->nhashes));
 			if (fhp->path[0] == '/')
 				dprintf(("\tpath = %s\n", fhp->path));
 			TAILQ_FOREACH(csp, &(fhp->checksums), checksum_entries) {
@@ -715,8 +722,7 @@
 			error = PEFS_ERR_GENERIC;
 		}
 		else {
-			memcpy(&temp, buf, sizeof(temp));
-			fhp->file_id = be64toh(temp);
+			memcpy(fhp->fid.fid_str, buf, sizeof(temp));
 			error = 0;
 		}
 
@@ -730,10 +736,8 @@
 	/* feed parent directory to ioctl() */
 	error = ioctl(fhp->pfd, PEFS_GETNAMECSUM, &xncs);
 
-	if (error == 0) {
-		memcpy(&temp, xncs.pxnc_csum, sizeof(xncs.pxnc_csum));
-		fhp->file_id = be64toh(temp);
-	}
+	if (error == 0)
+		memcpy(fhp->fid.fid_str, xncs.pxnc_csum, sizeof(xncs.pxnc_csum));
 	else
 		pefs_warn("failed to fetch file id from kernel for filename: %s",
 			fhp->filename);
@@ -1267,7 +1271,6 @@
 pefs_write_file_header(int fdout, struct file_header *fhp,
 	uint32_t *buckets_offset)
 {
-	uint64_t file_id;
 	uint32_t nhashes, offset_to_checksums;
 	int bytes;
 
@@ -1288,13 +1291,13 @@
 	}
 	(*buckets_offset)+= sizeof(offset_to_checksums);
 
-	file_id = htole64(fhp->file_id);
-	bytes = pwrite(fdout, &file_id, sizeof(file_id), *buckets_offset);
-	if (bytes != sizeof(file_id)) {
+	bytes = pwrite(fdout, fhp->fid.fid_str, sizeof(fhp->fid.fid_str),
+		*buckets_offset);
+	if (bytes != sizeof(fhp->fid.fid_str)) {
 		warn("error writing to .pefs.checksum");
 		return (PEFS_ERR_IO);
 	}
-	(*buckets_offset)+= sizeof(file_id);
+	(*buckets_offset)+= sizeof(fhp->fid.fid_str);
 
 	return (0);
 }
@@ -1309,7 +1312,7 @@
 	/* Empty files aren't allowed so nhashes == 0 symbolizes an empty bucket */
 	if (fhp == NULL) {
 		emptyfh.nhashes = 0;
-		emptyfh.file_id = 0;
+		emptyfh.fid.fid_num = 0;
 		emptyfh.offset_to_checksums = 0;
 		fhp = &emptyfh;
 	}
@@ -1335,12 +1338,13 @@
 
 /*
  * All data member writes are done separately so as to avoid alignment problems.
- * Writes are always in little endian byte order.
+ * Writes are always in little endian byte order, except file_id which is
+ * always treated as big endian.
  *
- * First 512 bytes of .pefs.checksum are reserved for the file's digital 
+ * First 512 bytes of .pefs.checksum are reserved for the file's digital
  * signature.
- * 
- * After that, the next 16 bytes of .pefs.checksum are filled with 
+ *
+ * After that, the next 16 bytes of .pefs.checksum are filled with
  * .pefs.checksum's global file header. Right after this header lies the
  * 'index' part of our database.
  * This index is later kept in kernel memory.
@@ -1827,7 +1831,6 @@
 pefs_read_file_header(int fdin, struct file_header *fhp,
 	uint32_t *buckets_offset)
 {
-	uint64_t file_id;
 	uint32_t nhashes, offset_to_checksums;
 	int bytes;
 
@@ -1848,13 +1851,13 @@
 	fhp->offset_to_checksums = le32toh(offset_to_checksums);
 	(*buckets_offset)+= sizeof(offset_to_checksums);
 
-	bytes = pread(fdin, &file_id, sizeof(file_id), *buckets_offset);
-	if (bytes != sizeof(file_id)) {
+	bytes = pread(fdin, fhp->fid.fid_str, sizeof(fhp->fid.fid_str),
+		*buckets_offset);
+	if (bytes != sizeof(fhp->fid.fid_str)) {
 		warn("error reading from .pefs.checksum");
 		return (PEFS_ERR_IO);
 	}
-	fhp->file_id = le64toh(file_id);
-	(*buckets_offset)+= sizeof(file_id);
+	(*buckets_offset)+= sizeof(fhp->fid.fid_str);
 
 	//dprintf(("\nfile header offset = %d\n", *fh_offset));
 	//dprintf(("\n++priting file header info++\n"));
@@ -2005,7 +2008,8 @@
 	uint32_t i;
 	int error, cmp;
 
-	dprintf(("comparing hashes for file with fid: %llu\n", fhp->file_id));
+	dprintf(("comparing hashes for file with fid: %llu\n",
+		fhp->fid.fid_num));
 
 	error = 0;
 	if (fhp->nhashes != indexfhp->nhashes) {
@@ -2187,7 +2191,7 @@
 			if (fhp->found != 1) {
 				pefs_warn("file with file id %llu was not found in "
 					"filesystem but exists in %s",
-					fhp->file_id, PEFS_FILE_CHECKSUM);
+					fhp->fid.fid_num, PEFS_FILE_CHECKSUM);
 				error = PEFS_ERR_NOENT;
 			}
 	}
@@ -2198,7 +2202,7 @@
 			if (fhp->found != 1) {
 				pefs_warn("file with file id %llu was not found in "
 					"filesystem but exists in %s",
-					fhp->file_id, PEFS_FILE_CHECKSUM);
+					fhp->fid.fid_num, PEFS_FILE_CHECKSUM);
 				error = PEFS_ERR_NOENT;
 			}
 	}
@@ -2313,7 +2317,7 @@
 	if (error != 0)
 		goto out;
 
-	printf("id: %llu\n", fhp->file_id);
+	printf("id: %llu\n", fhp->fid.fid_num);
 
 out:
 	pefs_free_file_header(fhp);

Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c	Fri Aug 10 14:51:41 2012	(r240244)
+++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_ctl.c	Fri Aug 10 15:51:34 2012	(r240245)
@@ -1023,7 +1023,7 @@
  * path defines where .pefs.checksum should be created. By default,
  * .pefs.checksum is created under $PWD. path should be a directory,
  * outside of target pefs filesystem.
- * 
+ *
  * pkey_file is the file that contains the private key that will be used
  * by the DSA signing algorithm. Key should be in PEM format.
  *

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c	Fri Aug 10 14:51:41 2012	(r240244)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.c	Fri Aug 10 15:51:34 2012	(r240245)
@@ -77,7 +77,6 @@
 			//offset = le32toh(offset);
 			//p+=sizeof(offset);
 			//memcpy(&file_id, p, sizeof(file_id));
-			//file_id = le64toh(file_id);
 			//printf("cell %d:\n", i);
 			//printf("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
 				//nhashes, offset, file_id);
@@ -99,7 +98,6 @@
 			//offset = le32toh(offset);
 			//p+=sizeof(offset);
 			//memcpy(&file_id, p, sizeof(file_id));
-			//file_id = le64toh(file_id);
 			//printf("cell %d:\n", i);
 			//printf("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
 				//nhashes, offset, file_id);
@@ -147,7 +145,7 @@
 {
 	uint32_t nbucket;
 
-	nbucket = pcie->pcie_file_id % pc->pcs_hash_table_size;
+	nbucket = pcie->pcie_fid.pcfi_num % pc->pcs_hash_table_size;
 	dprintf(("hash1: goto bucket %d\n", nbucket));
 	return (nbucket);
 }
@@ -158,8 +156,9 @@
 {
 	uint32_t nbucket;
 
-	nbucket = fnv_64_buf(&(pcie->pcie_file_id), sizeof(pcie->pcie_file_id),
-		FNV1_64_INIT) % pc->pcs_hash_table_size;
+	nbucket = fnv_64_buf(&(pcie->pcie_fid.pcfi_num),
+		sizeof(pcie->pcie_fid.pcfi_num), FNV1_64_INIT) %
+		pc->pcs_hash_table_size;
 	dprintf(("hash2: goto bucket %d\n", nbucket));
 
 	return (nbucket);
@@ -180,8 +179,7 @@
 		pcie->pcie_offset = le32toh(pcie->pcie_offset);
 		p+=sizeof(pcie->pcie_offset);
 
-		memcpy(&(pcie->pcie_file_id), p, sizeof(pcie->pcie_file_id));
-		pcie->pcie_file_id = le64toh(pcie->pcie_file_id);
+		memcpy(pcie->pcie_fid.pcfi_str, p, sizeof(pcie->pcie_fid.pcfi_str));
 	}
 }
 
@@ -204,9 +202,9 @@
 		dprintf(("cell %d:\n", pos));
 		dprintf(("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
 			target_pcie.pcie_nhashes, target_pcie.pcie_offset,
-			target_pcie.pcie_file_id));
+			target_pcie.pcie_fid.pcfi_num));
 
-		if (target_pcie.pcie_file_id == pcie->pcie_file_id) {
+		if (target_pcie.pcie_fid.pcfi_num == pcie->pcie_fid.pcfi_num) {
 			pn->pn_checksum_index_entry = start;
 			dprintf(("checksum lookup: found1!\n"));
 			return (0);
@@ -221,9 +219,9 @@
 		dprintf(("cell %d:\n", pos));
 		dprintf(("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
 			target_pcie.pcie_nhashes, target_pcie.pcie_offset,
-			target_pcie.pcie_file_id));
+			target_pcie.pcie_fid.pcfi_num));
 
-		if (target_pcie.pcie_file_id == pcie->pcie_file_id) {
+		if (target_pcie.pcie_fid.pcfi_num == pcie->pcie_fid.pcfi_num) {
 			pn->pn_checksum_index_entry = start;
 			dprintf(("checksum lookup: found2!\n"));
 			return (0);
@@ -273,9 +271,8 @@
 		dprintf(("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);
-		dprintf(("id to lookup: %llu\n", pcie.pcie_file_id));
+		memcpy(pcie.pcie_fid.pcfi_str, buf, sizeof(pcie.pcie_fid.pcfi_str));
+		dprintf(("id to lookup: %llu\n", pcie.pcie_fid.pcfi_num));
 		error = pefs_checksum_index_lookup(&pcie, vp);
 		if (error != 0) {
 			free(buf, M_TEMP);
@@ -288,12 +285,13 @@
 	 */
 	error = VOP_GETATTR(vp, &va, cred);
 	if (error != 0) {
-		dprintf(("unable to retrieve attributes of %llu\n", pcie.pcie_file_id));
+		dprintf(("unable to retrieve attributes of %llu\n",
+			pcie.pcie_fid.pcfi_num));
 		pn->pn_flags|= PN_WRONG_CHECKSUM;
 	}
 	else {
 		if ((va.va_flags & SF_IMMUTABLE) == 0) {
-			dprintf(("schg not set for %llu\n", pcie.pcie_file_id));
+			dprintf(("schg not set for %llu\n", pcie.pcie_fid.pcfi_num));
 			pn->pn_flags|= PN_WRONG_CHECKSUM;
 		}
 	}
@@ -417,7 +415,7 @@
 
 	pefs_get_index_entry(pn->pn_checksum_index_entry, &pcie);
 
-	dprintf(("id: %llu\n", pcie.pcie_file_id));
+	dprintf(("id: %llu\n", pcie.pcie_fid.pcfi_num));
 
 	buf = (char *)pc->pc_base;
 	end = buf + pc->pc_size;

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h	Fri Aug 10 14:51:41 2012	(r240244)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_checksum.h	Fri Aug 10 15:51:34 2012	(r240245)
@@ -49,10 +49,15 @@
 #define dprintf(a)      (void)0
 #endif
 
+union pefs_checksum_file_id {
+	uint64_t pcfi_num;
+	uint8_t	pcfi_str[8];
+};
+
 struct pefs_checksum_index_entry {
 	uint32_t pcie_nhashes;
 	uint32_t pcie_offset;
-	uint64_t pcie_file_id;
+	union pefs_checksum_file_id pcie_fid;
 };
 
 static __inline int

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_mac.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_mac.c	Fri Aug 10 14:51:41 2012	(r240244)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_mac.c	Fri Aug 10 15:51:34 2012	(r240245)
@@ -166,10 +166,10 @@
  * mprotect(2).
  *
  * I did notice the existance of mac_vnode_check_mprotect(), but unfortunately
- * it's not used anywhere in the kernel for some reason(?)! If it ever comes 
+ * it's not used anywhere in the kernel for some reason(?)! If it ever comes
  * back into action, I believe it would be preferable to the following solution.
- * 
- * My alternative solution was to set the MAXPROT flag of the mapped area 
+ *
+ * My alternative solution was to set the MAXPROT flag of the mapped area
  * during mmap(). If we are mapping a file and we need schg protection, we
  * remove VM_PROT_EXECUTE from MAXPROT which in turn causes following attempts
  * to mprotect() with PROT_EXEC to fail.



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