dirent_fill()

Finally, the helper routine dirent_fill() is used to stuff the values passed to it (namely, the inode, offset, and fname fields) into the directory entry also passed. As an added bonus, it returns a pointer to where the next directory entry should begin, taking into account alignment.

struct dirent *
dirent_fill (struct dirent *dp, int inode, int offset, 
             char *fname)
{
    dp -> d_ino = inode;
    dp -> d_offset = offset;
    strcpy (dp -> d_name, fname);
    dp -> d_namelen = strlen (dp -> d_name);
    dp -> d_reclen = ALIGN (sizeof (struct dirent) - 4
                   + dp -> d_namelen + 1);
    return ((struct dirent *) ((char *) dp + 
            dp -> d_reclen));
}