1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27/* 28 * Portions Copyright 2007-2011 Apple Inc. 29 */ 30 31/* 32 * Definitions and declarations shared between the autofs kext and 33 * user-mode code. 34 */ 35 36#ifndef __AUTOFS_H__ 37#define __AUTOFS_H__ 38 39#include <stdint.h> 40 41#include <sys/dirent.h> 42#include <sys/mount.h> 43#include <sys/ioccom.h> 44 45#ifdef __cplusplus 46extern "C" { 47#endif 48 49#include "autofs_types.h" 50 51#define MNTTYPE_AUTOFS "autofs" 52 53#define AUTOFS_ARGSVERSION 2 /* change when autofs_args changes */ 54 55/* 56 * Mount types. 57 */ 58#define MOUNT_TYPE_MAP 0 /* top-level map mount */ 59#define MOUNT_TYPE_TRIGGERED_MAP 1 /* map mount on a trigger */ 60#define MOUNT_TYPE_SUBTRIGGER 2 /* subtrigger */ 61 62/* 63 * autofs mount args, as seen by userland code. 64 * This structure is different in ILP32 and LP64. 65 */ 66struct autofs_args { 67 uint32_t version; /* args structure version number */ 68 char *path; /* autofs mountpoint */ 69 char *opts; /* default mount options */ 70 char *map; /* name of map */ 71 char *subdir; /* subdir within map */ 72 char *key; /* used in direct mounts */ 73 uint32_t mntflags; /* Boolean default mount options */ 74 int32_t direct; /* 1 = direct mount */ 75 int32_t mount_type; /* mount type - see above */ 76 int32_t node_type; /* node_type value for root node */ 77}; 78 79#ifdef KERNEL 80/* 81 * ILP32 version of autofs_args, for use in the kernel when fetching args 82 * from userland in a 32-bit process. 83 * WARNING - keep in sync with autofs_args 84 */ 85struct autofs_args_32 { 86 uint32_t version; /* args structure version number */ 87 uint32_t path; /* autofs mountpoint */ 88 uint32_t opts; /* default mount options */ 89 uint32_t map; /* name of map */ 90 uint32_t subdir; /* subdir within map */ 91 uint32_t key; /* used in direct mounts */ 92 uint32_t mntflags; /* Boolean default mount options */ 93 int32_t direct; /* 1 = direct mount */ 94 int32_t mount_type; /* mount type - see above */ 95 int32_t node_type; /* node_type value for root node */ 96}; 97 98/* 99 * LP64 version of autofs_args, for use in the kernel when fetching args 100 * from userland in a 64-bit process. 101 * WARNING - keep in sync with autofs_args 102 */ 103struct autofs_args_64 { 104 uint32_t version; /* args structure version number */ 105 user_addr_t path __attribute((aligned(8))); /* autofs mountpoint */ 106 user_addr_t opts __attribute((aligned(8))); /* default mount options */ 107 user_addr_t map __attribute((aligned(8))); /* name of map */ 108 user_addr_t subdir __attribute((aligned(8)));/* subdir within map */ 109 user_addr_t key __attribute((aligned(8))); /* used in direct mounts */ 110 uint32_t mntflags; /* Boolean default mount options */ 111 int32_t direct; /* 1 = direct mount */ 112 int32_t mount_type; /* mount type - see above */ 113 int32_t node_type; /* node_type value for root node */ 114}; 115#endif 116 117/* 118 * Autofs-specific mount options. 119 */ 120#define MNTOPT_RESTRICT "restrict" 121#define AUTOFS_MNT_RESTRICT 0x00000001 122#define AUTOFS_MNT_NOBROWSE 0x00000002 /* autofs's notion of "nobrowse", not OS X's */ 123#define MNTOPT_HIDEFROMFINDER "hidefromfinder" 124#define AUTOFS_MNT_HIDEFROMFINDER 0x00000004 125 126#ifdef __APPLE_API_PRIVATE 127/* arg is int */ 128#define AUTOFS_CTL_DEBUG 0x0001 /* toggle debug. */ 129#endif /* __APPLE_API_PRIVATE */ 130 131/* 132 * autofs update args, as seen by userland code. 133 * This structure is different in ILP32 and LP64. 134 */ 135struct autofs_update_args { 136 fsid_t fsid; 137 char *opts; /* default mount options */ 138 char *map; /* name of map */ 139 uint32_t mntflags; /* Boolean default mount options */ 140 int32_t direct; /* 1 = direct mount */ 141 int32_t node_type; /* node_type value for root node */ 142}; 143 144#ifdef KERNEL 145/* 146 * ILP32 version of autofs_update_args, for use in the kernel when fetching args 147 * from userland in a 32-bit process. 148 * WARNING - keep in sync with autofs_update_args 149 */ 150struct autofs_update_args_32 { 151 fsid_t fsid; 152 uint32_t opts; /* default mount options */ 153 uint32_t map; /* name of map */ 154 uint32_t mntflags; /* Boolean default mount options */ 155 int32_t direct; /* 1 = direct mount */ 156 int32_t node_type; /* node_type value for root node */ 157}; 158 159/* 160 * LP64 version of autofs_update_args, for use in the kernel when fetching args 161 * from userland in a 64-bit process. 162 * WARNING - keep in sync with autofs_update_args 163 */ 164struct autofs_update_args_64 { 165 fsid_t fsid; 166 user_addr_t opts __attribute((aligned(8))); /* default mount options */ 167 user_addr_t map __attribute((aligned(8))); /* name of map */ 168 uint32_t mntflags; /* Boolean default mount options */ 169 int32_t direct; /* 1 = direct mount */ 170 int32_t node_type; /* node_type value for root node */ 171}; 172#endif 173 174/* 175 * Autofs ioctls. 176 */ 177#define AUTOFS_SET_MOUNT_TO _IOW('a', 0, int) 178#ifdef KERNEL 179#define AUTOFS_UPDATE_OPTIONS_32 _IOW('a', 1, struct autofs_update_args_32) 180#define AUTOFS_UPDATE_OPTIONS_64 _IOW('a', 1, struct autofs_update_args_64) 181#else 182#define AUTOFS_UPDATE_OPTIONS _IOW('a', 1, struct autofs_update_args) 183#endif 184#define AUTOFS_NOTIFYCHANGE _IO('a', 2) 185#define AUTOFS_WAITFORFLUSH _IO('a', 3) 186#define AUTOFS_UNMOUNT _IOW('a', 4, fsid_t) 187#define AUTOFS_UNMOUNT_TRIGGERED _IO('a', 5) 188 189/* 190 * Autofs fsctls. 191 */ 192#define AUTOFS_MARK_HOMEDIRMOUNT _IO('a', 666) 193 194/* 195 * Node type flags 196 */ 197#define NT_SYMLINK 0x00000001 /* node should be a symlink to / */ 198#define NT_TRIGGER 0x00000002 /* node is a trigger */ 199#define NT_FORCEMOUNT 0x00000004 /* wildcard lookup - must do mount to check for existence */ 200 201/* 202 * Action Status 203 * Automountd replies to autofs indicating whether the operation is done, 204 * or further action needs to be taken by autofs. 205 */ 206enum autofs_stat { 207 AUTOFS_ACTION=0, /* list of actions included */ 208 AUTOFS_DONE=1 /* no further action required by kernel */ 209}; 210 211struct mounta { 212 char *dir; 213 char *opts; 214 char *path; 215 char *map; 216 char *subdir; 217 char *trig_mntpnt; 218 int flags; 219 int mntflags; 220 uint32_t isdirect; 221 uint32_t needs_subtrigger; 222 char *key; 223}; 224 225typedef struct action_list { 226 struct mounta mounta; 227 struct action_list *next; 228} action_list; 229 230/* 231 * Flags returned by autofs_mount() and autofs_mount_url(). 232 */ 233#define MOUNT_RETF_DONTUNMOUNT 0x00000001 /* don't auto-unmount or preemptively unmount this */ 234#define MOUNT_RETF_DONTPREUNMOUNT 0x00000002 /* don't preemptively unmount this */ 235 236#ifndef KERNEL 237/* 238 * XXX - "struct dirent" is different depending on whether 239 * __DARWIN_64_BIT_INO_T is defined or not. We define it, 240 * so we can get the long f_mntonname field, but the autofs 241 * file system expects us to return the form of the structure 242 * you get when __DARWIN_64_BIT_INO_T isn't defined. 243 * 244 * For now, we solve this by defining "struct dirent_nonext" 245 * to be the old directory entry. 246 */ 247struct dirent_nonext { 248 __uint32_t d_ino; /* file number of entry */ 249 __uint16_t d_reclen; /* length of this record */ 250 __uint8_t d_type; /* file type, see below */ 251 __uint8_t d_namlen; /* length of string in d_name */ 252 char d_name[__DARWIN_MAXNAMLEN + 1]; /* name must be no longer than this */ 253}; 254#else 255/* In the kernel, "struct direct" is always the non-extended directory entry. */ 256#define dirent_nonext dirent 257#endif 258 259/* 260 * Macros for readdir. 261 */ 262#define DIRENT_NAMELEN(reclen) \ 263 ((reclen) - (offsetof(struct dirent_nonext, d_name[0]))) 264#define DIRENT_RECLEN(namlen) \ 265 (((u_int)sizeof (struct dirent_nonext) - (MAXNAMLEN+1)) + (((namlen)+1 + 3) &~ 3)) 266#define RECLEN(dp) DIRENT_RECLEN((dp)->d_namlen) 267#define nextdp(dp) ((struct dirent_nonext *)((char *)(dp) + RECLEN(dp))) 268 269/* 270 * Autofs device; opened by automountd, which needs to avoid triggering 271 * mounts and to bypass locks on in-progress mounts, so it can do mounts, 272 * to let autofs know what its PID is. 273 * This name is relative to /dev. 274 */ 275#define AUTOFS_DEVICE "autofs" 276 277/* 278 * Autofs nowait device; opened by processes that want to trigger mounts 279 * but don't want to wait for the mount to finish (for which read 280 * "launchd"), to let autofs know what their PIDs are. 281 * This name is relative to /dev. 282 */ 283#define AUTOFS_NOWAIT_DEVICE "autofs_nowait" 284 285/* 286 * Autofs notrigger device; opened by processes that don't want to trigger 287 * mounts, to let autofs know what their PIDs are. 288 * This name is relative to /dev. 289 */ 290#define AUTOFS_NOTRIGGER_DEVICE "autofs_notrigger" 291 292/* 293 * Autofs homedirmounter device; opened by processes that want to mount 294 * home directories on an autofs trigger. 295 * This name is relative to /dev. 296 */ 297#define AUTOFS_HOMEDIRMOUNTER_DEVICE "autofs_homedirmounter" 298 299/* 300 * Autofs control device; opened by the automount command to perform 301 * various operations. This name is relative to /dev. 302 */ 303#define AUTOFS_CONTROL_DEVICE "autofs_control" 304 305#ifdef KERNEL 306/* 307 * Entry in a table of mount options; mirrors userland struct mntopt. 308 */ 309struct mntopt { 310 const char *m_option; /* option name */ 311 int m_inverse; /* if a negative option, eg "dev" */ 312 int m_flag; /* bit to set, eg. MNT_RDONLY */ 313 int m_altloc; /* 1 => set bit in altflags */ 314}; 315 316/* 317 * Definitions for options that appear in RESTRICTED_MNTOPTS; mirrors 318 * userland definitions. 319 */ 320#define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 } 321#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 } 322#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 } 323#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 } 324#endif 325 326/* 327 * List of mntoptions which are inherited when the "restrict" option 328 * is present. The RESTRICT option must be first! 329 * This define is shared between the kernel and the automount daemon. 330 */ 331#define RESTRICTED_MNTOPTS \ 332 { MNTOPT_RESTRICT, 0, AUTOFS_MNT_RESTRICT, 1 }, /* restricted autofs mount */ \ 333 MOPT_NODEV, \ 334 MOPT_NOEXEC, \ 335 MOPT_NOSUID, \ 336 MOPT_RDONLY, \ 337 { NULL, 0, 0, 0 } /* list terminator */ 338 339#ifdef __cplusplus 340} 341#endif 342 343#endif /* __AUTOFS_H__ */ 344