10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*5006Sek110237 * Common Development and Distribution License (the "License"). 6*5006Sek110237 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*5006Sek110237 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 290Sstevel@tonic-gate /* All Rights Reserved */ 300Sstevel@tonic-gate 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * Attach a STREAMS or door based file descriptor to an object in the file 340Sstevel@tonic-gate * system name space. 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate #pragma weak fattach = _fattach 370Sstevel@tonic-gate #include "synonyms.h" 380Sstevel@tonic-gate #include <sys/types.h> 390Sstevel@tonic-gate #include <errno.h> 400Sstevel@tonic-gate #include <stdio.h> 410Sstevel@tonic-gate #include <stropts.h> 420Sstevel@tonic-gate #include <sys/door.h> 430Sstevel@tonic-gate #include <sys/fs/namenode.h> 440Sstevel@tonic-gate #include <sys/mount.h> 450Sstevel@tonic-gate #include <unistd.h> 460Sstevel@tonic-gate #include <string.h> 470Sstevel@tonic-gate #include "libc.h" 480Sstevel@tonic-gate 490Sstevel@tonic-gate int 500Sstevel@tonic-gate fattach(int fildes, const char *path) 510Sstevel@tonic-gate { 520Sstevel@tonic-gate struct namefd namefdp; 530Sstevel@tonic-gate struct door_info dinfo; 540Sstevel@tonic-gate int s; 550Sstevel@tonic-gate char buf[MAXPATHLEN]; 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* Only STREAMS and doors allowed to be mounted */ 580Sstevel@tonic-gate if ((s = isastream(fildes)) == 1 || __door_info(fildes, &dinfo) == 0) { 590Sstevel@tonic-gate namefdp.fd = fildes; 600Sstevel@tonic-gate if (path == NULL || *path == '\0') { 610Sstevel@tonic-gate errno = ENOENT; 620Sstevel@tonic-gate return (-1); 630Sstevel@tonic-gate } else if (*path != '/') { 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * The mount point must be an absolute path. 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate if (getcwd(buf, sizeof (buf)) == NULL) { 680Sstevel@tonic-gate /* errno already set */ 690Sstevel@tonic-gate return (-1); 700Sstevel@tonic-gate } 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * The kernel will truncate the path if it would have 730Sstevel@tonic-gate * turned into something more than MAXPATHLEN bytes. 740Sstevel@tonic-gate * So we do the same here. 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate if (strlcat(buf, "/", sizeof (buf)) >= sizeof (buf) || 770Sstevel@tonic-gate strlcat(buf, path, sizeof (buf)) >= sizeof (buf)) { 780Sstevel@tonic-gate errno = ENAMETOOLONG; 790Sstevel@tonic-gate return (-1); 800Sstevel@tonic-gate } 810Sstevel@tonic-gate path = buf; 820Sstevel@tonic-gate } 830Sstevel@tonic-gate return (mount((char *)NULL, path, MS_DATA|MS_NOMNTTAB, 840Sstevel@tonic-gate (const char *)"namefs", (char *)&namefdp, 850Sstevel@tonic-gate sizeof (struct namefd), NULL, 0)); 860Sstevel@tonic-gate } else if (s == 0) { 870Sstevel@tonic-gate /* Not a STREAM */ 880Sstevel@tonic-gate errno = EINVAL; 890Sstevel@tonic-gate return (-1); 900Sstevel@tonic-gate } else { 910Sstevel@tonic-gate /* errno already set */ 920Sstevel@tonic-gate return (-1); 930Sstevel@tonic-gate } 940Sstevel@tonic-gate } 95