changeset 746:580b4da092b3

objstore: define PACKED_DIRENT_TGT_MIN_LEN This parallels the PACKED_DIRENT_TGT_MAX_LEN define. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sun, 29 Mar 2020 13:53:28 -0400
parents cc663a78252c
children dfc67b8051fe
files src/objstore/dir.h
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/objstore/dir.h	Sun Mar 29 13:32:31 2020 -0400
+++ b/src/objstore/dir.h	Sun Mar 29 13:53:28 2020 -0400
@@ -110,6 +110,13 @@
 /*
  * packed dirent tgt uses a CBOR array
  *
+ * Best (impossible) case, each will consist of:
+ *  - the array type byte (1 byte)
+ *  - the dirent type uint (1 bytes since types <= 23)
+ *  - target oid (graft uuid is 1+16)
+ *    - host uint (1 bytes)
+ *    - uniq uint (1 bytes)
+ *
  * Worst case, each will consist of:
  *  - the array type byte (1 byte)
  *  - the dirent type uint (1 bytes since types <= 23)
@@ -117,6 +124,7 @@
  *    - host uint (1+8 bytes)
  *    - uniq uint (1+8 bytes)
  */
+#define PACKED_DIRENT_TGT_MIN_LEN	(1 + 1 + 1 + 1)
 #define PACKED_DIRENT_TGT_MAX_LEN	(1 + 1 + (1 + 8) + (1 + 8))
 
 /* unpacked dirent tgt for easy processing */
@@ -143,9 +151,8 @@
 #define DIRBLOCK_USABLE_SPACE	(DIR_BLOCK_SIZE - sizeof(struct obj_dir_header))
 
 #define DIRBLOCK_MIN_NAME_SIZE	1 /* 1 byte min */
-#define DIRBLOCK_MIN_TGT_SIZE	3 /* 3 bytes min */
 #define DIRBLOCK_MIN_ENTRY_SIZE	\
-	(sizeof(struct ndirent_phys) + DIRBLOCK_MIN_TGT_SIZE + \
+	(sizeof(struct ndirent_phys) + PACKED_DIRENT_TGT_MIN_LEN + \
 	 DIRBLOCK_MIN_NAME_SIZE)
 
 /* max number of fixed sized entries in a block */
@@ -154,11 +161,11 @@
 /* max number of bytes used by names in a block */
 #define DIRBLOCK_MAX_NAME_SIZE \
 		(DIRBLOCK_USABLE_SPACE - sizeof(struct ndirent_phys) - \
-		 DIRBLOCK_MIN_TGT_SIZE)
+		 PACKED_DIRENT_TGT_MIN_LEN)
 /* max number of targets in a block */
 #define DIRBLOCK_MAX_TGT_COUNT \
 		((DIRBLOCK_USABLE_SPACE - sizeof(struct ndirent_phys) - \
-		  DIRBLOCK_MIN_NAME_SIZE) / DIRBLOCK_MIN_TGT_SIZE)
+		  DIRBLOCK_MIN_NAME_SIZE) / PACKED_DIRENT_TGT_MIN_LEN)
 
 struct dirblock {
 	size_t used_bytes; /* total bytes used in this block */