/* * Allocate an inode in the file system. * * we leave the actual allocation strategy to the (modified) * ext2_new_inode(), to make sure we get the policies right */ int ext2_valloc(struct vnode *pvp, int mode, struct ucred *cred, struct vnode **vpp) { struct inode *pip; struct ext2_sb_info *fs; struct inode *ip; ino_t ino; int i, error; *vpp = NULL; pip = VTOI(pvp); fs = pip->i_e2fs; if (fs->s_es->s_free_inodes_count == 0) goto noinodes; /* call the Linux routine - it returns the inode number only */ ino = ext2_new_inode(pip, mode); if (ino == 0) goto noinodes; error = VFS_VGET(pvp->v_mount, NULL, ino, vpp); if (error) { EXT2_VFREE(pvp, ino, mode); return (error); } ip = VTOI(*vpp); /* the question is whether using VGET was such good idea at all - Linux doesn't read the old inode in when it's allocating a new one. I will set at least i_size & i_blocks the zero. */ ip->i_mode = 0; ip->i_size = 0; ip->i_blocks = 0; ip->i_flags = 0; /* now we want to make sure that the block pointers are zeroed out */ for (i = 0; i < NDADDR; i++) ip->i_db[i] = 0; for (i = 0; i < NIADDR; i++) ip->i_ib[i] = 0; /* * Set up a new generation number for this inode. * XXX check if this makes sense in ext2 */ if (ip->i_gen == 0 || ++ip->i_gen == 0) ip->i_gen = krandom() / 2 + 1; /* kprintf("ext2_valloc: allocated inode %d\n", ino); */ return (0); noinodes: ext2_fserr(fs, cred->cr_uid, "out of inodes"); uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt); return (ENOSPC); }
/* * IP6 initialization: fill in IP6 protocol switch table. * All protocols not implemented in kernel go to raw IP6 protocol handler. */ void ip6_init(void) { struct protosw *pr; int i; struct timeval tv; pr = pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); if (pr == NULL) panic("ip6_init"); for (i = 0; i < IPPROTO_MAX; i++) ip6_protox[i] = pr - inet6sw; for (pr = inet6domain.dom_protosw; pr < inet6domain.dom_protoswNPROTOSW; pr++) if (pr->pr_domain->dom_family == PF_INET6 && pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) ip6_protox[pr->pr_protocol] = pr - inet6sw; inet6_pfil_hook.ph_type = PFIL_TYPE_AF; inet6_pfil_hook.ph_af = AF_INET6; if ((i = pfil_head_register(&inet6_pfil_hook)) != 0) { kprintf("%s: WARNING: unable to register pfil hook, " "error %d\n", __func__, i); } netisr_register(NETISR_IPV6, ip6_input, NULL); /* XXX cpufn */ scope6_init(); addrsel_policy_init(); nd6_init(); frag6_init(); /* * in many cases, random() here does NOT return random number * as initialization during bootstrap time occur in fixed order. */ microtime(&tv); ip6_flow_seq = krandom() ^ tv.tv_usec; microtime(&tv); ip6_desync_factor = (krandom() ^ tv.tv_usec) % MAX_TEMP_DESYNC_FACTOR; }
int trndlevel(KNable *knable) { int level = 0; int max; if (knable->level == SLHEIGHT - 1) max = SLHEIGHT - 1; else /* Dirty Hack. */ max = knable->level + 1; while (krandom() < SLPROB && level < max) level++; return level; }