usr/src/uts/common/os/modctl.c
changeset 6065 b05c5c670963
parent 5331 3047ad28a67b
child 6855 18f1316f1bed
equal deleted inserted replaced
6064:45d29804ab93 6065:b05c5c670963
    18  *
    18  *
    19  * CDDL HEADER END
    19  * CDDL HEADER END
    20  */
    20  */
    21 
    21 
    22 /*
    22 /*
    23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
    23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
    24  * Use is subject to license terms.
    24  * Use is subject to license terms.
    25  */
    25  */
    26 
    26 
    27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
    27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
    28 
    28 
  2044 	dir = kmem_zalloc(udirlen + 1, KM_SLEEP);
  2044 	dir = kmem_zalloc(udirlen + 1, KM_SLEEP);
  2045 	if ((ret = copyinstr(udir, dir, udirlen, NULL)) != 0)
  2045 	if ((ret = copyinstr(udir, dir, udirlen, NULL)) != 0)
  2046 		goto err;
  2046 		goto err;
  2047 
  2047 
  2048 	if ((ret = sdev_modctl_readdir(dir, &dirlist,
  2048 	if ((ret = sdev_modctl_readdir(dir, &dirlist,
  2049 	    &npaths, &npaths_alloc)) != 0) {
  2049 	    &npaths, &npaths_alloc, 0)) != 0) {
  2050 		ASSERT(dirlist == NULL);
  2050 		ASSERT(dirlist == NULL);
  2051 		goto err;
  2051 		goto err;
  2052 	}
  2052 	}
  2053 
  2053 
  2054 	lens = 0;
  2054 	lens = 0;
  2091 		kmem_free(paths, lens);
  2091 		kmem_free(paths, lens);
  2092 	kmem_free(dir, udirlen + 1);
  2092 	kmem_free(dir, udirlen + 1);
  2093 	return (ret);
  2093 	return (ret);
  2094 }
  2094 }
  2095 
  2095 
       
  2096 static int
       
  2097 modctl_devemptydir(const char *udir, int udirlen, int *uempty)
       
  2098 {
       
  2099 	char	*dir;
       
  2100 	int	ret;
       
  2101 	char	**dirlist = NULL;
       
  2102 	int	npaths;
       
  2103 	int	npaths_alloc;
       
  2104 	int	empty;
       
  2105 
       
  2106 	/*
       
  2107 	 * copyin the /dev path including terminating null
       
  2108 	 */
       
  2109 	udirlen++;
       
  2110 	if (udirlen <= 1 || udirlen > MAXPATHLEN)
       
  2111 		return (EINVAL);
       
  2112 	dir = kmem_zalloc(udirlen + 1, KM_SLEEP);
       
  2113 	if ((ret = copyinstr(udir, dir, udirlen, NULL)) != 0)
       
  2114 		goto err;
       
  2115 
       
  2116 	if ((ret = sdev_modctl_readdir(dir, &dirlist,
       
  2117 	    &npaths, &npaths_alloc, 1)) != 0) {
       
  2118 		goto err;
       
  2119 	}
       
  2120 
       
  2121 	empty = npaths ? 0 : 1;
       
  2122 	if (copyout(&empty, uempty, sizeof (empty)))
       
  2123 		ret = EFAULT;
       
  2124 
       
  2125 err:
       
  2126 	if (dirlist)
       
  2127 		sdev_modctl_readdir_free(dirlist, npaths, npaths_alloc);
       
  2128 	kmem_free(dir, udirlen + 1);
       
  2129 	return (ret);
       
  2130 }
       
  2131 
  2096 int
  2132 int
  2097 modctl_moddevname(int subcmd, uintptr_t a1, uintptr_t a2)
  2133 modctl_moddevname(int subcmd, uintptr_t a1, uintptr_t a2)
  2098 {
  2134 {
  2099 	int error = 0;
  2135 	int error = 0;
  2100 
  2136 
  2343 		break;
  2379 		break;
  2344 
  2380 
  2345 	case MODDEVREADDIR:	/* non-reconfiguring /dev readdir */
  2381 	case MODDEVREADDIR:	/* non-reconfiguring /dev readdir */
  2346 		error = modctl_devreaddir((const char *)a1, (size_t)a2,
  2382 		error = modctl_devreaddir((const char *)a1, (size_t)a2,
  2347 		    (char *)a3, (int64_t *)a4);
  2383 		    (char *)a3, (int64_t *)a4);
       
  2384 		break;
       
  2385 
       
  2386 	case MODDEVEMPTYDIR:	/* non-reconfiguring /dev emptydir */
       
  2387 		error = modctl_devemptydir((const char *)a1, (size_t)a2,
       
  2388 		    (int *)a3);
  2348 		break;
  2389 		break;
  2349 
  2390 
  2350 	case MODDEVNAME:
  2391 	case MODDEVNAME:
  2351 		error = modctl_moddevname((int)a1, a2, a3);
  2392 		error = modctl_moddevname((int)a1, a2, a3);
  2352 		break;
  2393 		break;