+
+/*
+ * Make a new file.
+ */
+struct inode *
+maknode(mode)
+ int mode;
+{
+ register struct inode *ip;
+ ino_t ipref;
+
+ if ((mode & IFMT) == IFDIR)
+ ipref = dirpref(u.u_pdir->i_fs);
+ else
+ ipref = u.u_pdir->i_number;
+ ip = ialloc(u.u_pdir, ipref, mode);
+ if (ip == NULL) {
+ iput(u.u_pdir);
+ return(NULL);
+ }
+#ifdef QUOTA
+ if (ip->i_dquot != NODQUOT)
+ panic("maknode: dquot");
+#endif
+ ip->i_flag |= IACC|IUPD|ICHG;
+ if ((mode & IFMT) == 0)
+ mode |= IFREG;
+ ip->i_mode = mode & ~u.u_cmask;
+ ip->i_nlink = 1;
+ ip->i_uid = u.u_uid;
+ ip->i_gid = u.u_pdir->i_gid;
+#ifdef QUOTA
+ ip->i_dquot = inoquota(ip);
+#endif
+
+ /*
+ * Make sure inode goes to disk before directory entry.
+ */
+ iupdat(ip, &time, &time, 1);
+ direnter(ip);
+ if (u.u_error) {
+ /*
+ * write error occurred trying to update directory
+ * so must deallocate the inode
+ */
+ ip->i_nlink = 0;
+ ip->i_flag |= ICHG;
+ iput(ip);
+ return(NULL);
+ }
+ return(ip);
+}