inoptr nindex;
uint8_t j;
+ /* No parent? */
+ if (!pino) {
+ udata.u_error = ENXIO;
+ goto nogood;
+ }
+
/* First see if parent is writeable */
if (pino->c_flags & CRDONLY) {
udata.u_error = EROFS;
goto nogood;
}
- if(!(getperm(pino) & OTH_WR))
+ if (!(getperm(pino) & OTH_WR)) {
+ udata.u_error = EPERM;
goto nogood;
+ }
- if(!(nindex = i_open(pino->c_dev, 0)))
+ if (!(nindex = i_open(pino->c_dev, 0))) {
+ udata.u_error = ENFILE;
goto nogood;
+ }
/* This does not implement BSD style "sticky" groups */
nindex->c_node.i_uid = udata.u_euid;
nindex->c_node.i_mode = F_REG; /* For the time being */
nindex->c_node.i_nlink = 1;
nindex->c_node.i_size = 0;
- for(j=0; j <20; j++)
+ for (j = 0; j < 20; j++) {
nindex->c_node.i_addr[j] = 0;
+ }
wr_inode(nindex);
- if(!ch_link(pino, "", name, nindex)) {
+ if (!ch_link(pino, "", name, nindex)) {
i_deref(nindex);
+ /* ch_link sets udata.u_error */
goto nogood;
}
i_deref(pino);
/* The n_open failed */
if (udata.u_error == EFAULT)
goto cantopen;
+
/* New file */
if (!(flag & O_CREAT)) {
udata.u_error = ENOENT;
goto cantopen;
}
filename(name, fname);
+
/* newfile drops parent for us */
- if (parent && (ino = newfile(parent, fname))) {
- ino->c_node.i_mode =
- (F_REG | (mode & MODE_MASK & ~udata.u_mask));
- setftime(ino, A_TIME | M_TIME | C_TIME);
- wr_inode(ino);
- } else {
- udata.u_error = ENFILE; /* FIXME, should be set in newfile
- not bodged to a guessed code */
+ ino = newfile(parent, fname);
+ if (!ino) {
+ /* on error, newfile sets udata.u_error */
goto cantopen;
}
+
+ /* new inode, successfully created */
+ ino->c_node.i_mode =
+ (F_REG | (mode & MODE_MASK & ~udata.u_mask));
+ setftime(ino, A_TIME | M_TIME | C_TIME);
+ wr_inode(ino);
}
+
/* Book our slot in case we block opening a device */
of_tab[oftindex].o_inode = ino;