The helper routine dirent_size() simply calculates the number of bytes required for the struct dirent, given the alignment constraints:

dirent_size (char *fname)
  return (ALIGN (sizeof (struct dirent) - 4 + strlen (fname) + 1));

We subtract four bytes because the dirent structure includes space for the first four characters of the name, and we add one for the null character at the end of the name. We could also calculate the size like this:

ALIGN (offsetof (struct dirent, d_name) + strlen (fname) + 1)

Again, this routine is slight overkill for our simple resource manager, because we know how big each directory entry is going to be—all filenames are exactly one byte in length. However, it's a useful utility routine.