2 * <fstab.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2005 Jonathan Pryor
19 #if defined (HAVE_CHECKLIST_H)
20 #include <checklist.h>
21 #elif defined (HAVE_FSTAB_H)
23 #endif /* def HAVE_FSTAB_H */
25 #ifdef HAVE_SYS_VFSTAB_H
26 #include <sys/vfstab.h>
27 #endif /* def HAVE_SYS_VFSTAB_H */
31 #ifdef HAVE_CHECKLIST_H
33 typedef struct checklist mph_fstab;
37 offsetof (struct checklist, fs_spec),
38 offsetof (struct checklist, fs_dir),
39 offsetof (struct checklist, fs_type)
43 mph_fstab_offsets[] = {
44 offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
45 offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
46 offsetof (struct Mono_Posix_Syscall__Fstab, fs_type)
49 #elif defined (HAVE_FSTAB_H)
51 typedef struct fstab mph_fstab;
55 offsetof (struct fstab, fs_spec),
56 offsetof (struct fstab, fs_file),
57 offsetof (struct fstab, fs_vfstype),
58 offsetof (struct fstab, fs_mntops),
59 offsetof (struct fstab, fs_type)
63 mph_fstab_offsets[] = {
64 offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
65 offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
66 offsetof (struct Mono_Posix_Syscall__Fstab, fs_vfstype),
67 offsetof (struct Mono_Posix_Syscall__Fstab, fs_mntops),
68 offsetof (struct Mono_Posix_Syscall__Fstab, fs_type)
71 #endif /* def HAVE_FSTAB_H */
73 #if defined (HAVE_CHECKLIST_H) || defined (HAVE_FSTAB_H)
76 * Copy the native `fstab' structure to it's managed representation.
78 * To minimize separate mallocs, all the strings are allocated within the same
79 * memory block (stored in _fs_buf_).
82 copy_fstab (struct Mono_Posix_Syscall__Fstab *to, mph_fstab *from)
86 memset (to, 0, sizeof(*to));
88 buf = _mph_copy_structure_strings (to, mph_fstab_offsets,
89 from, fstab_offsets, sizeof(fstab_offsets)/sizeof(fstab_offsets[0]));
91 to->fs_freq = from->fs_freq;
92 to->fs_passno = from->fs_passno;
102 #endif /* def HAVE_CHECKLIST_H || def HAVE_FSTAB_H */
104 #ifdef HAVE_SYS_VFSTAB_H
107 * Solaris doesn't provide <fstab.h> but has equivalent functionality in
108 * <sys/fstab.h> via getvfsent(3C) and company.
111 typedef struct vfstab mph_fstab;
115 offsetof (struct vfstab, vfs_special),
116 offsetof (struct vfstab, vfs_mountp),
117 offsetof (struct vfstab, vfs_fstype),
118 offsetof (struct vfstab, vfs_mntopts)
122 mph_fstab_offsets[] = {
123 offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
124 offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
125 offsetof (struct Mono_Posix_Syscall__Fstab, fs_vfstype),
126 offsetof (struct Mono_Posix_Syscall__Fstab, fs_mntops)
130 * Copy the native `vfstab' structure to it's managed representation.
132 * To minimize separate mallocs, all the strings are allocated within the same
133 * memory block (stored in _fs_buf_).
136 copy_fstab (struct Mono_Posix_Syscall__Fstab *to, struct vfstab *from)
140 memset (to, 0, sizeof(*to));
142 buf = _mph_copy_structure_strings (to, mph_fstab_offsets,
143 from, vfstab_offsets, sizeof(vfstab_offsets)/sizeof(vfstab_offsets[0]));
158 * Implement Linux/BSD getfsent(3) in terms of Solaris getvfsent(3C)...
166 /* protect from bad users calling setfsent(), setfsent(), ... endfsent() */
167 if (etc_fstab != NULL)
169 etc_fstab = fopen ("/etc/vfstab", "r");
170 if (etc_fstab != NULL)
185 static struct vfstab*
189 r = getvfsent (etc_fstab, &cur_vfstab_entry);
191 return &cur_vfstab_entry;
195 static struct vfstab*
196 getfsfile (const char *mount_point)
200 if (etc_fstab == 0) {
202 if (setfsent () != 1)
206 r = getvfsfile (etc_fstab, &cur_vfstab_entry, (char*) mount_point);
210 return &cur_vfstab_entry;
214 static struct vfstab*
215 getfsspec (const char *special_file)
219 if (etc_fstab == 0) {
221 if (setfsent () != 1)
225 r = getvfsspec (etc_fstab, &cur_vfstab_entry, (char*) special_file);
229 return &cur_vfstab_entry;
233 #endif /* def HAVE_SYS_VFSTAB_H */
235 #if defined (HAVE_FSTAB_H) || defined (HAVE_CHECKPOINT_H) || defined (HAVE_SYS_VFSTAB_H)
238 Mono_Posix_Syscall_endfsent (void)
245 Mono_Posix_Syscall_getfsent (struct Mono_Posix_Syscall__Fstab *fsbuf)
258 if (copy_fstab (fsbuf, fs) == -1) {
266 Mono_Posix_Syscall_getfsfile (const char *mount_point,
267 struct Mono_Posix_Syscall__Fstab *fsbuf)
276 fs = getfsfile (mount_point);
280 if (copy_fstab (fsbuf, fs) == -1) {
288 Mono_Posix_Syscall_getfsspec (const char *special_file,
289 struct Mono_Posix_Syscall__Fstab *fsbuf)
298 fs = getfsspec (special_file);
302 if (copy_fstab (fsbuf, fs) == -1) {
310 Mono_Posix_Syscall_setfsent (void)
315 #endif /* def HAVE_FSTAB_H || def HAVE_CHECKPOINT_H || def HAVE_SYS_VFSTAB_H */