2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (C) 1989 by NeXT, Inc.
30 #include <mach/mach.h>
33 #include <rpc/types.h>
38 #include "_lu_types.h"
40 #include "lu_overrides.h"
42 static struct fstab global_fs
;
43 static int global_free
= 1;
44 static char *fs_data
= NULL
;
45 static unsigned fs_datalen
= 0;
46 static int fs_nentries
= 0;
47 static int fs_start
= 1;
48 static XDR fs_xdr
= { 0 };
53 if (global_free
== 1) return;
55 free(global_fs
.fs_spec
);
56 free(global_fs
.fs_file
);
57 free(global_fs
.fs_type
);
58 free(global_fs
.fs_vfstype
);
59 free(global_fs
.fs_mntops
);
65 convert_fs(_lu_fsent
*lu_fs
)
69 global_fs
.fs_spec
= strdup(lu_fs
->fs_spec
);
70 global_fs
.fs_file
= strdup(lu_fs
->fs_file
);
73 * Special case - if vfstype is unknown and spec is
74 * of the form foo:bar, then assume nfs.
76 if (lu_fs
->fs_vfstype
[0] == '\0')
78 if (strchr(lu_fs
->fs_spec
, ':') != NULL
)
80 global_fs
.fs_vfstype
= malloc(4);
81 strcpy(global_fs
.fs_vfstype
, "nfs");
83 else global_fs
.fs_vfstype
= strdup(lu_fs
->fs_vfstype
);
87 global_fs
.fs_vfstype
= strdup(lu_fs
->fs_vfstype
);
90 global_fs
.fs_mntops
= strdup(lu_fs
->fs_mntops
);
91 global_fs
.fs_type
= strdup(lu_fs
->fs_type
);
92 global_fs
.fs_freq
= lu_fs
->fs_freq
;
93 global_fs
.fs_passno
= lu_fs
->fs_passno
;
99 lu_getfsbyname(const char *name
)
102 char namebuf
[_LU_MAXLUSTRLEN
+ BYTES_PER_XDR_UNIT
];
106 static int proc
= -1;
107 unit lookup_buf
[MAX_INLINE_UNITS
];
111 if (_lookup_link(_lu_port
, "getfsbyname", &proc
) != KERN_SUCCESS
)
117 xdrmem_create(&outxdr
, namebuf
, sizeof(namebuf
), XDR_ENCODE
);
118 if (!xdr__lu_string(&outxdr
, &name
))
120 xdr_destroy(&outxdr
);
124 datalen
= MAX_INLINE_UNITS
;
125 if (_lookup_one(_lu_port
, proc
, (unit
*)namebuf
,
126 xdr_getpos(&outxdr
) / BYTES_PER_XDR_UNIT
, lookup_buf
, &datalen
)
129 xdr_destroy(&outxdr
);
133 xdr_destroy(&outxdr
);
135 datalen
*= BYTES_PER_XDR_UNIT
;
136 xdrmem_create(&inxdr
, lookup_buf
, datalen
,
139 if (!xdr__lu_fsent_ptr(&inxdr
, &lu_fs
) || (lu_fs
== NULL
))
148 xdr_free(xdr__lu_fsent_ptr
, &lu_fs
);
159 vm_deallocate(mach_task_self(), (vm_address_t
)fs_data
, fs_datalen
);
172 static struct fstab
*
175 static int proc
= -1;
184 if (_lookup_link(_lu_port
, "getfsent", &proc
) !=
192 if (_lookup_all(_lu_port
, proc
, NULL
, 0, &fs_data
, &fs_datalen
)
200 /* NOTDEF because OOL buffers are counted in bytes with untyped IPC */
201 fs_datalen
*= BYTES_PER_XDR_UNIT
;
203 xdrmem_create(&fs_xdr
, fs_data
,
204 fs_datalen
, XDR_DECODE
);
205 if (!xdr_int(&fs_xdr
, &fs_nentries
))
207 xdr_destroy(&fs_xdr
);
213 if (fs_nentries
== 0)
215 xdr_destroy(&fs_xdr
);
220 bzero(&lu_fs
, sizeof(lu_fs
));
221 if (!xdr__lu_fsent(&fs_xdr
, &lu_fs
))
223 xdr_destroy(&fs_xdr
);
230 xdr_free(xdr__lu_fsent
, &lu_fs
);
235 lu_getfsspec(const char *name
)
237 if (name
== NULL
) return (struct fstab
*)NULL
;
238 return lu_getfsbyname(name
);
242 lu_getfsfile(const char *name
)
246 if (name
== NULL
) return (struct fstab
*)NULL
;
249 for (fs
= lu_getfsent(); fs
!= NULL
; fs
= lu_getfsent())
250 if (!strcmp(fs
->fs_file
, name
)) return fs
;
253 return (struct fstab
*)NULL
;
257 getfsbyname(const char *name
)
259 if (_lu_running()) return (lu_getfsbyname(name
));
266 if (_lu_running()) return (lu_getfsent());
267 return (_old_getfsent());
273 if (_lu_running()) return (lu_setfsent());
274 return (_old_setfsent());
280 if (_lu_running()) lu_endfsent();
281 else _old_endfsent();
285 getfsspec(const char *name
)
287 if (_lu_running()) return (lu_getfsspec(name
));
288 return (_old_getfsspec(name
));
292 getfsfile(const char *name
)
294 if (_lu_running()) return (lu_getfsfile(name
));
295 return (_old_getfsfile(name
));