+ if (numdirpasses == 2) {
+ numdirpasses--;
+ u.u_offset = 0;
+ endsearch = u.u_ncache.nc_prevoffset;
+ goto searchloop;
+ }
+/* notfound: */
+ /*
+ * If creating, and at end of pathname and current
+ * directory has not been removed, then can consider
+ * allowing file to be created.
+ */
+ if (flag == CREATE && *cp == 0 && dp->i_nlink != 0) {
+ /*
+ * Access for write is interpreted as allowing
+ * creation of files in the directory.
+ */
+ if (access(dp, IWRITE))
+ goto bad;
+ /*
+ * Return an indication of where the new directory
+ * entry should be put. If we didn't find a slot,
+ * then set u.u_count to 0 indicating that the
+ * new slot belongs at the end of the directory.
+ * If we found a slot, then the new entry can be
+ * put in the range [u.u_offset..u.u_offset+u.u_count)
+ */
+ if (slotstatus == NONE) {
+ u.u_offset = roundup(dp->i_size, DIRBLKSIZ);
+ u.u_count = 0;
+ } else {
+ u.u_offset = slotoffset;
+ u.u_count = slotsize;
+ }
+ dp->i_flag |= IUPD|ICHG;
+ if (bp)
+ brelse(bp);
+ brelse(nbp);
+ /*
+ * We return with the directory locked, so that
+ * the parameters we set up above will still be
+ * valid if we actually decide to do a direnter().
+ * We return NULL to indicate that the entry doesn't
+ * currently exist, leaving a pointer to the (locked)
+ * directory inode in u.u_pdir.
+ */
+ u.u_pdir = dp;
+ return (NULL);
+ }
+ u.u_error = ENOENT;
+ goto bad;
+found:
+ /*
+ * Check that directory length properly reflects presence
+ * of this entry.
+ */
+ if (entryoffsetinblock + DIRSIZ(ep) > dp->i_size) {
+ dirbad(dp, "i_size too small");
+ dp->i_size = entryoffsetinblock + DIRSIZ(ep);
+ dp->i_flag |= IUPD|ICHG;
+ }
+
+ /*
+ * Found component in pathname.
+ * If final component of path name, save information
+ * in the cache as to where the entry was found.
+ */
+ if (*cp == '\0' && flag == LOOKUP) {
+ u.u_ncache.nc_prevoffset = u.u_offset;
+ u.u_ncache.nc_inumber = dp->i_number;
+ u.u_ncache.nc_dev = dp->i_dev;
+ u.u_ncache.nc_time = time.tv_sec;
+ }
+ /*
+ * Save directory entry in u.u_dent,
+ * and release directory buffer.
+ */
+ bcopy((caddr_t)ep, (caddr_t)&u.u_dent, (u_int)DIRSIZ(ep));
+ brelse(bp);