FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c
/*
 * Link zp into dzp.  Can only fail if zp has been unlinked.
 */
Link zp into dzp.  Can only fail if zp has been unlinked.
Link zp into dzp . Can only fail if zp has been unlinked .
int
zfs_link_create(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
    int flag)
{
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
	vnode_t *vp = ZTOV(zp);
	uint64_t value;
	int zp_is_dir = (vp->v_type == VDIR);
	sa_bulk_attr_t bulk[5];
	uint64_t mtime[2], ctime[2];
	int count = 0;
	int error;
	ASSERT_VOP_ELOCKED(ZTOV(dzp), __func__);
	ASSERT_VOP_ELOCKED(ZTOV(zp), __func__);
#if 0
	if (zp_is_dir) {
		error = 0;
		if (dzp->z_links >= LINK_MAX)
			error = SET_ERROR(EMLINK);
		return (error);
	}
#endif
	if (!(flag & ZRENAMING)) {
		if (zp->z_unlinked) {	
			ASSERT(!(flag & (ZNEW | ZEXISTS)));
			return (SET_ERROR(ENOENT));
		}
#if 0
		if (zp->z_links >= LINK_MAX) {
			return (SET_ERROR(EMLINK));
		}
#endif
		zp->z_links++;
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL,
		    &zp->z_links, sizeof (zp->z_links));
	} else {
		ASSERT(zp->z_unlinked == 0);
	}
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL,
	    &dzp->z_id, sizeof (dzp->z_id));
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
	    &zp->z_pflags, sizeof (zp->z_pflags));
	if (!(flag & ZNEW)) {
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
		    ctime, sizeof (ctime));
		zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime,
		    ctime, B_TRUE);
	}
	error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
	ASSERT0(error);
	dzp->z_size++;
	dzp->z_links += zp_is_dir;
	count = 0;
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
	    &dzp->z_size, sizeof (dzp->z_size));
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL,
	    &dzp->z_links, sizeof (dzp->z_links));
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
	    mtime, sizeof (mtime));
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
	    ctime, sizeof (ctime));
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
	    &dzp->z_pflags, sizeof (dzp->z_pflags));
	zfs_tstamp_update_setup(dzp, CONTENT_MODIFIED, mtime, ctime, B_TRUE);
	error = sa_bulk_update(dzp->z_sa_hdl, bulk, count, tx);
	ASSERT0(error);
	value = zfs_dirent(zp, zp->z_mode);
	error = zap_add(zp->z_zfsvfs->z_os, dzp->z_id, name,
	    8, 1, &value, tx);
	VERIFY0(error);
	return (0);
}
int zfs_link_create ( znode_t * dzp , const char * name , znode_t * zp , dmu_tx_t * tx , int flag ) { zfsvfs_t * zfsvfs = zp -> z_zfsvfs ; vnode_t * vp = ZTOV ( zp ) ; uint64_t value ; int zp_is_dir = ( vp -> v_type == VDIR ) ; sa_bulk_attr_t bulk [ 5 ] ; uint64_t mtime [ 2 ] , ctime [ 2 ] ; int count = 0 ; int error ; ASSERT_VOP_ELOCKED ( ZTOV ( dzp ) , __func__ ) ; ASSERT_VOP_ELOCKED ( ZTOV ( zp ) , __func__ ) ; #if 0 if ( zp_is_dir ) { error = 0 ; if ( dzp -> z_links >= LINK_MAX ) error = SET_ERROR ( EMLINK ) ; return ( error ) ; } #endif if ( ! ( flag & ZRENAMING ) ) { if ( zp -> z_unlinked ) { ASSERT ( ! ( flag & ( ZNEW | ZEXISTS ) ) ) ; return ( SET_ERROR ( ENOENT ) ) ; } #if 0 if ( zp -> z_links >= LINK_MAX ) { return ( SET_ERROR ( EMLINK ) ) ; } #endif zp -> z_links ++ ; SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_LINKS ( zfsvfs ) , NULL , & zp -> z_links , sizeof ( zp -> z_links ) ) ; } else { ASSERT ( zp -> z_unlinked == 0 ) ; } SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_PARENT ( zfsvfs ) , NULL , & dzp -> z_id , sizeof ( dzp -> z_id ) ) ; SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_FLAGS ( zfsvfs ) , NULL , & zp -> z_pflags , sizeof ( zp -> z_pflags ) ) ; if ( ! ( flag & ZNEW ) ) { SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_CTIME ( zfsvfs ) , NULL , ctime , sizeof ( ctime ) ) ; zfs_tstamp_update_setup ( zp , STATE_CHANGED , mtime , ctime , B_TRUE ) ; } error = sa_bulk_update ( zp -> z_sa_hdl , bulk , count , tx ) ; ASSERT0 ( error ) ; dzp -> z_size ++ ; dzp -> z_links += zp_is_dir ; count = 0 ; SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_SIZE ( zfsvfs ) , NULL , & dzp -> z_size , sizeof ( dzp -> z_size ) ) ; SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_LINKS ( zfsvfs ) , NULL , & dzp -> z_links , sizeof ( dzp -> z_links ) ) ; SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_MTIME ( zfsvfs ) , NULL , mtime , sizeof ( mtime ) ) ; SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_CTIME ( zfsvfs ) , NULL , ctime , sizeof ( ctime ) ) ; SA_ADD_BULK_ATTR ( bulk , count , SA_ZPL_FLAGS ( zfsvfs ) , NULL , & dzp -> z_pflags , sizeof ( dzp -> z_pflags ) ) ; zfs_tstamp_update_setup ( dzp , CONTENT_MODIFIED , mtime , ctime , B_TRUE ) ; error = sa_bulk_update ( dzp -> z_sa_hdl , bulk , count , tx ) ; ASSERT0 ( error ) ; value = zfs_dirent ( zp , zp -> z_mode ) ; error = zap_add ( zp -> z_zfsvfs -> z_os , dzp -> z_id , name , 8 , 1 , & value , tx ) ; VERIFY0 ( error ) ; return ( 0 ) ; }
Link zp into dzp.
Link zp into dzp .
/* no new links to unlinked zp */