FreeBSD/sys/cddl/compat/opensolaris/kern/opensolaris_zone.c
/*
 * Returns true if the named dataset is visible in the current zone.
 * The 'write' parameter is set to 1 if the dataset is also writable.
 */
Returns true if the named dataset is visible in the current zone.
The 'write' parameter is set to 1 if the dataset is also writable.
Returns true if the named dataset is visible in the current zone . The ' write ' parameter is set to 1 if the dataset is also writable .
int
zone_dataset_visible(const char *dataset, int *write)
{
	struct zone_dataset_head *head;
	zone_dataset_t *zd;
	struct prison *pr;
	size_t len;
	int ret = 0;
	if (dataset[0] == '\0')
		return (0);
	if (INGLOBALZONE(curthread)) {
		if (write != NULL)
			*write = 1;
		return (1);
	}
	pr = curthread->td_ucred->cr_prison;
	mtx_lock(&pr->pr_mtx);
	head = osd_jail_get(pr, zone_slot);
	if (head == NULL)
		goto end;
	LIST_FOREACH(zd, head, zd_next) {
		len = strlen(zd->zd_dataset);
		if (strlen(dataset) >= len &&
		    bcmp(dataset, zd->zd_dataset, len) == 0 &&
		    (dataset[len] == '\0' || dataset[len] == '/' ||
		    dataset[len] == '@')) {
			if (write)
				*write = 1;
			ret = 1;
			goto end;
		}
	}
	LIST_FOREACH(zd, head, zd_next) {
		len = strlen(dataset);
		if (dataset[len - 1] == '/')
			len--;	
		if (len < strlen(zd->zd_dataset) &&
		    bcmp(dataset, zd->zd_dataset, len) == 0 &&
		    zd->zd_dataset[len] == '/') {
			if (write)
				*write = 0;
			ret = 1;
			goto end;
		}
	}
end:
	mtx_unlock(&pr->pr_mtx);
	return (ret);
}
int zone_dataset_visible ( const char * dataset , int * write ) { struct zone_dataset_head * head ; zone_dataset_t * zd ; struct prison * pr ; size_t len ; int ret = 0 ; if ( dataset [ 0 ] == ' \0 ' ) return ( 0 ) ; if ( INGLOBALZONE ( curthread ) ) { if ( write != NULL ) * write = 1 ; return ( 1 ) ; } pr = curthread -> td_ucred -> cr_prison ; mtx_lock ( & pr -> pr_mtx ) ; head = osd_jail_get ( pr , zone_slot ) ; if ( head == NULL ) goto end ; LIST_FOREACH ( zd , head , zd_next ) { len = strlen ( zd -> zd_dataset ) ; if ( strlen ( dataset ) >= len && bcmp ( dataset , zd -> zd_dataset , len ) == 0 && ( dataset [ len ] == ' \0 ' || dataset [ len ] == ' ' || dataset [ len ] == ' ' ) ) { if ( write ) * write = 1 ; ret = 1 ; goto end ; } } LIST_FOREACH ( zd , head , zd_next ) { len = strlen ( dataset ) ; if ( dataset [ len - 1 ] == ' ' ) len -- ; if ( len < strlen ( zd -> zd_dataset ) && bcmp ( dataset , zd -> zd_dataset , len ) == 0 && zd -> zd_dataset [ len ] == ' ' ) { if ( write ) * write = 0 ; ret = 1 ; goto end ; } } end : mtx_unlock ( & pr -> pr_mtx ) ; return ( ret ) ; }
Returns true if the named dataset is visible in the current zone.
Returns true if the named dataset is visible in the current zone .
/*
	 * Walk the list once, looking for datasets which match exactly, or
	 * specify a dataset underneath an exported dataset.  If found, return
	 * true and note that it is writable.
	 */ /*
	 * Walk the list a second time, searching for datasets which are parents
	 * of exported datasets.  These should be visible, but read-only.
	 *
	 * Note that we also have to support forms such as 'pool/dataset/', with
	 * a trailing slash.
	 */ /* Ignore trailing slash */