return retval;
}
+static size_t needroom3(void)
+{
+ /*
+ * Check for enough room. This is extremely approximate but should
+ * be enough space. Really need 2 times:
+ * (8byte fileid
+ * 8byte cookie
+ * 8byte name pointer
+ * 8byte next entry addres) = sizeof(am_entry3)
+ * 2byte name + 1byte terminator
+ * plus the size of the am_dirlist3 structure */
+ return ((2 * ((sizeof(am_entry3) + sizeof("..") + 1))) + sizeof(am_dirlist3));
+}
+
/* This one is called only if map is browsable */
static int
amfs_readdir3_browsable(am_node *mp, am_cookie3 cookie,
plog(XLOG_DEBUG, "amfs_readdir3_browsable gen=%lu, count=%d", gen, count);
if (gen == 0) {
+ size_t needed = needroom3();
/*
* In the default instance (which is used to start a search) we return
* "." and "..".
* fairly unbelievable) then tough.
*/
dlog("%s: default search", __func__);
- /*
- * Check for enough room. This is extremely approximate but should
- * be enough space. Really need 2 times:
- * (8byte fileid
- * 8byte cookie
- * 8byte name pointer
- * 8byte next entry addres) = sizeof(*ep)
- * 2byte name + 1byte terminator
- * plus the dirlist structure */
- if (count < ((2 * ((sizeof(*ep) + sizeof("..") + 1))) + sizeof(*dp)));
+
+ if (count < needed) {
+ dlog("%s: not enough room %u < %zu", __func__, count, needed);
return EINVAL;
+ }
/*
* compute # of entries to send in this chain.
/* when gen is 0, we start reading from the beginning of the directory */
if (gen == 0) {
+ size_t needed = needroom3();
/*
* In the default instance (which is used to start a search) we return
* "." and "..".
* fairly unbelievable) then tough.
*/
dlog("%s: default search", __func__);
- /*
- * Check for enough room. This is extremely approximate but should
- * be enough space. Really need 2 times:
- * (8byte fileid
- * 8byte cookie
- * 8byte name pointer
- * 8byte next entry addres) = sizeof(*ep)
- * 2byte name + 1byte terminator
- * plus the dirlist structure */
-#define NEEDROOM3 ((2 * ((sizeof(*ep) + sizeof("..") + 1))) + sizeof(*dp))
- if (count < NEEDROOM3) {
- dlog("%s: not enough room %u < %zu", __func__, count, NEEDROOM3);
+
+ if (count < needed) {
+ dlog("%s: not enough room %u < %zu", __func__, count, needed);
return EINVAL;
}