kernel/fs/vfs.c
/*
 * TODO: Need to allocate vnode but not set INODE nr, then send message to server.
 * Otherwise could fail to allocate after sending.
 */
Need to allocate vnode but not set INODE nr, then send message to server.
Otherwise could fail to allocate after sending.
Need to allocate vnode but not set INODE nr then send message to server . Otherwise could fail to allocate after sending .
int vfs_mknod(struct VNode *dir, char *name, struct stat *stat,
                            struct VNode **result) {
  int status;
  struct SuperBlock *sb;
  struct fsreq req;
  struct fsreply reply;
  struct Msg msg;
  struct IOV iov[3];
  struct VNode *vnode = NULL;
  memset(&req, 0, sizeof req);
  sb = dir->superblock;
  LockSuperBlock(sb);
  req.cmd = CMD_MKNOD;
  req.args.mknod.dir_inode_nr = dir->inode_nr;
  req.args.mknod.name_sz = StrLen(name) + 1;
  req.args.mknod.uid = stat->st_uid;
  req.args.mknod.gid = stat->st_gid;
  req.args.mknod.mode = stat->st_mode;
  Info ("vfs_mknod, mode = %o", stat->st_mode);
  iov[0].addr = &req;
  iov[0].size = sizeof req;
  iov[1].addr = name;
  iov[1].size = req.args.mkdir.name_sz;
  iov[2].addr = &reply;
  iov[2].size = sizeof reply;
  msg.iov_cnt = 3;
  msg.iov = iov;
  status = KSendMsg(&sb->msgport, dir, &msg);
  if (status < 0) {
    goto exit;
  }
  vnode = VNodeNew(sb, reply.args.lookup.inode_nr);
  if (vnode == NULL) {
    status = -ENOMEM;
    goto exit;
  }
  vnode->nlink = 1;      
  vnode->reference_cnt = 1;
  vnode->size = reply.args.mknod.size;      
  vnode->uid = reply.args.mknod.uid;  
  vnode->gid = reply.args.mknod.gid;
  vnode->mode = reply.args.mknod.mode;
  vnode->flags = V_VALID;
  *result = vnode;
  status = reply.args.mknod.status;
  UnlockSuperBlock(sb);
  Info ("vfs_mknod success, mode = %o", vnode->mode);
  return status;
exit:
  UnlockSuperBlock(sb);
  Info ("vfs_mknod fail");
  return status;
}
int vfs_mknod ( struct VNode * dir , char * name , struct stat * stat , struct VNode * * result ) { int status ; struct SuperBlock * sb ; struct fsreq req ; struct fsreply reply ; struct Msg msg ; struct IOV iov [ 3 ] ; struct VNode * vnode = NULL ; memset ( & req , 0 , sizeof req ) ; sb = dir -> superblock ; LockSuperBlock ( sb ) ; req . cmd = CMD_MKNOD ; req . args . mknod . dir_inode_nr = dir -> inode_nr ; req . args . mknod . name_sz = StrLen ( name ) + 1 ; req . args . mknod . uid = stat -> st_uid ; req . args . mknod . gid = stat -> st_gid ; req . args . mknod . mode = stat -> st_mode ; Info ( " " , stat -> st_mode ) ; iov [ 0 ] . addr = & req ; iov [ 0 ] . size = sizeof req ; iov [ 1 ] . addr = name ; iov [ 1 ] . size = req . args . mkdir . name_sz ; iov [ 2 ] . addr = & reply ; iov [ 2 ] . size = sizeof reply ; msg . iov_cnt = 3 ; msg . iov = iov ; status = KSendMsg ( & sb -> msgport , dir , & msg ) ; if ( status < 0 ) { goto exit ; } vnode = VNodeNew ( sb , reply . args . lookup . inode_nr ) ; if ( vnode == NULL ) { status = - ENOMEM ; goto exit ; } vnode -> nlink = 1 ; vnode -> reference_cnt = 1 ; vnode -> size = reply . args . mknod . size ; vnode -> uid = reply . args . mknod . uid ; vnode -> gid = reply . args . mknod . gid ; vnode -> mode = reply . args . mknod . mode ; vnode -> flags = V_VALID ; * result = vnode ; status = reply . args . mknod . status ; UnlockSuperBlock ( sb ) ; Info ( " " , vnode -> mode ) ; return status ; exit : UnlockSuperBlock ( sb ) ; Info ( " " ) ; return status ; }
TODO: Need to allocate vnode but not set INODE nr, then send message to server.
TODO : Need to allocate vnode but not set INODE nr then send message to server .
//  req.args.mknod.size = 0; // TODO: Copy stat fields to req