int nandfs_node_create(struct nandfsmount *nmp, struct nandfs_node **node, uint16_t mode) { struct nandfs_alloc_request req; struct nandfs_device *nandfsdev; struct nandfs_mdt *mdt; struct nandfs_node *ifile; struct nandfs_inode *inode; struct vnode *vp; uint32_t entry; int error = 0; nandfsdev = nmp->nm_nandfsdev; mdt = &nandfsdev->nd_ifile_mdt; ifile = nmp->nm_ifile_node; vp = NTOV(ifile); VOP_LOCK(vp, LK_EXCLUSIVE); /* Allocate new inode in ifile */ req.entrynum = nandfsdev->nd_last_ino + 1; error = nandfs_find_free_entry(mdt, ifile, &req); if (error) { VOP_UNLOCK(vp, 0); return (error); } error = nandfs_get_entry_block(mdt, ifile, &req, &entry, 1); if (error) { VOP_UNLOCK(vp, 0); return (error); } /* Inode initialization */ inode = ((struct nandfs_inode *) req.bp_entry->b_data) + entry; nandfs_inode_init(inode, mode); error = nandfs_alloc_entry(mdt, &req); if (error) { VOP_UNLOCK(vp, 0); return (error); } VOP_UNLOCK(vp, 0); nandfsdev->nd_last_ino = req.entrynum; error = nandfs_get_node(nmp, req.entrynum, node); DPRINTF(IFILE, ("%s: node: %p ino: %#jx\n", __func__, node, (uintmax_t)((*node)->nn_ino))); return (error); }
int nandfs_vblock_alloc(struct nandfs_device *nandfsdev, nandfs_daddr_t *vblock) { struct nandfs_node *dat; struct nandfs_mdt *mdt; struct nandfs_alloc_request req; struct nandfs_dat_entry *dat_entry; uint64_t start; uint32_t entry; int locked, error; dat = nandfsdev->nd_dat_node; mdt = &nandfsdev->nd_dat_mdt; start = nandfsdev->nd_last_cno + 1; locked = NANDFS_VOP_ISLOCKED(NTOV(dat)); if (!locked) VOP_LOCK(NTOV(dat), LK_EXCLUSIVE); req.entrynum = 0; /* Alloc vblock number */ error = nandfs_find_free_entry(mdt, dat, &req); if (error) { nandfs_error("%s: cannot find free vblk entry\n", __func__); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); } /* Read/create buffer */ error = nandfs_get_entry_block(mdt, dat, &req, &entry, 1); if (error) { nandfs_error("%s: cannot get free vblk entry\n", __func__); nandfs_abort_entry(&req); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); } /* Fill out vblock data */ dat_entry = (struct nandfs_dat_entry *) req.bp_entry->b_data; dat_entry[entry].de_start = start; dat_entry[entry].de_end = UINTMAX_MAX; dat_entry[entry].de_blocknr = 0; /* Commit allocation */ error = nandfs_alloc_entry(mdt, &req); if (error) { nandfs_error("%s: cannot get free vblk entry\n", __func__); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); } /* Return allocated vblock */ *vblock = req.entrynum; DPRINTF(DAT, ("%s: allocated vblock %#jx\n", __func__, (uintmax_t)*vblock)); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); }