2 * Copyright (c) 1999-2002 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>
36 #include "lu_overrides.h"
38 #define ENTRY_SIZE sizeof(struct fstab)
39 #define ENTRY_KEY _li_data_key_fstab
41 static pthread_mutex_t _fstab_lock
= PTHREAD_MUTEX_INITIALIZER
;
48 copy_fstab(struct fstab
*in
)
50 if (in
== NULL
) return NULL
;
52 return (struct fstab
*)LI_ils_create("sssss44", in
->fs_spec
, in
->fs_file
, in
->fs_vfstype
, in
->fs_mntops
, in
->fs_type
, in
->fs_freq
, in
->fs_passno
);
56 * Extract the next fstab entry from a kvarray.
59 extract_fstab(kvarray_t
*in
)
62 uint32_t d
, k
, kcount
;
64 if (in
== NULL
) return NULL
;
69 if (d
>= in
->count
) return NULL
;
71 memset(&tmp
, 0, ENTRY_SIZE
);
73 kcount
= in
->dict
[d
].kcount
;
75 for (k
= 0; k
< kcount
; k
++)
77 if (!strcmp(in
->dict
[d
].key
[k
], "fs_spec"))
79 if (tmp
.fs_spec
!= NULL
) continue;
80 if (in
->dict
[d
].vcount
[k
] == 0) continue;
82 tmp
.fs_spec
= (char *)in
->dict
[d
].val
[k
][0];
84 else if (!strcmp(in
->dict
[d
].key
[k
], "fs_file"))
86 if (tmp
.fs_file
!= NULL
) continue;
87 if (in
->dict
[d
].vcount
[k
] == 0) continue;
89 tmp
.fs_file
= (char *)in
->dict
[d
].val
[k
][0];
91 else if (!strcmp(in
->dict
[d
].key
[k
], "fs_vfstype"))
93 if (tmp
.fs_vfstype
!= NULL
) continue;
94 if (in
->dict
[d
].vcount
[k
] == 0) continue;
96 tmp
.fs_vfstype
= (char *)in
->dict
[d
].val
[k
][0];
98 else if (!strcmp(in
->dict
[d
].key
[k
], "fs_mntops"))
100 if (tmp
.fs_mntops
!= NULL
) continue;
101 if (in
->dict
[d
].vcount
[k
] == 0) continue;
103 tmp
.fs_mntops
= (char *)in
->dict
[d
].val
[k
][0];
105 else if (!strcmp(in
->dict
[d
].key
[k
], "fs_type"))
107 if (tmp
.fs_type
!= NULL
) continue;
108 if (in
->dict
[d
].vcount
[k
] == 0) continue;
110 tmp
.fs_type
= (char *)in
->dict
[d
].val
[k
][0];
112 else if (!strcmp(in
->dict
[d
].key
[k
], "fs_freq"))
114 if (in
->dict
[d
].vcount
[k
] == 0) continue;
115 tmp
.fs_freq
= atoi(in
->dict
[d
].val
[k
][0]);
117 else if (!strcmp(in
->dict
[d
].key
[k
], "fs_passno"))
119 if (in
->dict
[d
].vcount
[k
] == 0) continue;
120 tmp
.fs_passno
= atoi(in
->dict
[d
].val
[k
][0]);
124 if (tmp
.fs_spec
== NULL
) tmp
.fs_spec
= "";
125 if (tmp
.fs_file
== NULL
) tmp
.fs_file
= "";
126 if (tmp
.fs_vfstype
== NULL
) tmp
.fs_vfstype
= "";
127 if (tmp
.fs_mntops
== NULL
) tmp
.fs_mntops
= "";
128 if (tmp
.fs_type
== NULL
) tmp
.fs_type
= "";
130 return copy_fstab(&tmp
);
133 static struct fstab
*
134 ds_getfsspec(const char *name
)
136 static int proc
= -1;
138 return (struct fstab
*)LI_getone("getfsbyname", &proc
, extract_fstab
, "name", name
);
144 LI_data_free_kvarray(LI_data_find_key(ENTRY_KEY
));
154 static struct fstab
*
157 static int proc
= -1;
159 return (struct fstab
*)LI_getent("getfsent", &proc
, extract_fstab
, ENTRY_KEY
, ENTRY_SIZE
);
162 static struct fstab
*
163 ds_getfsfile(const char *name
)
167 if (name
== NULL
) return NULL
;
171 for (fs
= ds_getfsent(); fs
!= NULL
; fs
= ds_getfsent())
173 if (!strcmp(fs
->fs_file
, name
)) return fs
;
181 static struct fstab
*
182 getfs(const char *spec
, const char *file
, int source
)
184 struct fstab
*res
= NULL
;
185 struct li_thread_info
*tdata
;
187 tdata
= LI_data_create_key(ENTRY_KEY
, ENTRY_SIZE
);
188 if (tdata
== NULL
) return NULL
;
195 res
= ds_getfsspec(spec
);
198 res
= ds_getfsfile(file
);
208 pthread_mutex_lock(&_fstab_lock
);
213 res
= copy_fstab(_old_getfsspec(spec
));
216 res
= copy_fstab(_old_getfsfile(file
));
219 res
= copy_fstab(_old_getfsent());
224 pthread_mutex_unlock(&_fstab_lock
);
227 LI_data_recycle(tdata
, res
, ENTRY_SIZE
);
228 return (struct fstab
*)tdata
->li_entry
;
233 getfsbyname(const char *name
)
235 return getfs(name
, NULL
, FS_GET_SPEC
);
239 getfsspec(const char *name
)
241 return getfs(name
, NULL
, FS_GET_SPEC
);
245 getfsfile(const char *name
)
247 return getfs(NULL
, name
, FS_GET_FILE
);
253 return getfs(NULL
, NULL
, FS_GET_ENT
);
259 if (_ds_running()) return (ds_setfsent());
260 return (_old_setfsent());
266 if (_ds_running()) ds_endfsent();
267 else _old_endfsent();