coverity appeasement
[minix.git] / servers / pfs / open.c
blob72ab0b5df348cdcdc5a051439089a1f877f256a3
1 #include "fs.h"
2 #include <sys/stat.h>
3 #include "buf.h"
4 #include "inode.h"
5 #include <minix/vfsif.h>
8 /*===========================================================================*
9 * fs_newnode *
10 *===========================================================================*/
11 int fs_newnode(message *fs_m_in, message *fs_m_out)
13 register int r = OK;
14 mode_t bits;
15 struct inode *rip;
16 dev_t dev;
18 caller_uid = (uid_t) fs_m_in->REQ_UID;
19 caller_gid = (gid_t) fs_m_in->REQ_GID;
20 bits = (mode_t) fs_m_in->REQ_MODE;
21 dev = (dev_t) fs_m_in->REQ_DEV;
23 /* Try to allocate the inode */
24 if( (rip = alloc_inode(dev, bits) ) == NULL) return(err_code);
26 switch (bits & S_IFMT) {
27 case S_IFBLK:
28 case S_IFCHR:
29 rip->i_rdev = dev; /* Major/minor dev numbers */
30 break;
31 case S_IFIFO:
32 if ((get_block(dev, rip->i_num)) == NULL)
33 r = EIO;
34 break;
35 default:
36 r = EIO; /* Unsupported file type */
39 if (r != OK) {
40 free_inode(rip);
41 } else {
42 /* Fill in the fields of the response message */
43 fs_m_out->RES_INODE_NR = rip->i_num;
44 fs_m_out->RES_MODE = rip->i_mode;
45 fs_m_out->RES_FILE_SIZE_LO = rip->i_size;
46 fs_m_out->RES_UID = rip->i_uid;
47 fs_m_out->RES_GID = rip->i_gid;
48 fs_m_out->RES_DEV = dev;
51 return(r);