2 * <fstab.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2005 Jonathan Pryor
20 #endif /* def HAVE_FSTAB_H */
22 #ifdef HAVE_SYS_VFSTAB_H
23 #include <sys/vfstab.h>
24 #endif /* def HAVE_SYS_VFSTAB_H */
28 struct Mono_Posix_Syscall__Fstab {
29 char *fs_spec; /* block device name */
30 char *fs_file; /* mount point */
31 char *fs_vfstype; /* filesystem type */
32 char *fs_mntops; /* mount options */
33 char *fs_type; /* rw/rq/ro/sw/xx option */
34 int fs_freq; /* dump frequency, in days */
35 int fs_passno; /* pass number on parallel dump */
42 typedef struct fstab mph_fstab;
46 offsetof (struct fstab, fs_spec),
47 offsetof (struct fstab, fs_file),
48 offsetof (struct fstab, fs_vfstype),
49 offsetof (struct fstab, fs_mntops),
50 offsetof (struct fstab, fs_type)
54 mph_fstab_offsets[] = {
55 offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
56 offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
57 offsetof (struct Mono_Posix_Syscall__Fstab, fs_vfstype),
58 offsetof (struct Mono_Posix_Syscall__Fstab, fs_mntops),
59 offsetof (struct Mono_Posix_Syscall__Fstab, fs_type)
63 * Copy the native `fstab' structure to it's managed representation.
65 * To minimize separate mallocs, all the strings are allocated within the same
66 * memory block (stored in _fs_buf_).
69 copy_fstab (struct Mono_Posix_Syscall__Fstab *to, struct fstab *from)
72 buf = _mph_copy_structure_strings (to, mph_fstab_offsets,
73 from, fstab_offsets, sizeof(fstab_offsets)/sizeof(fstab_offsets[0]));
75 to->fs_freq = from->fs_freq;
76 to->fs_passno = from->fs_passno;
86 #endif /* def HAVE_FSTAB_H */
88 #ifdef HAVE_SYS_VFSTAB_H
91 * Solaris doesn't provide <fstab.h> but has equivalent functionality in
92 * <sys/fstab.h> via getvfsent(3C) and company.
95 typedef struct vfstab mph_fstab;
99 offsetof (struct vfstab, vfs_special),
100 offsetof (struct vfstab, vfs_mountp),
101 offsetof (struct vfstab, vfs_fstype),
102 offsetof (struct vfstab, vfs_mntopts)
106 mph_fstab_offsets[] = {
107 offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
108 offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
109 offsetof (struct Mono_Posix_Syscall__Fstab, fs_vfstype),
110 offsetof (struct Mono_Posix_Syscall__Fstab, fs_mntops)
114 * Copy the native `vfstab' structure to it's managed representation.
116 * To minimize separate mallocs, all the strings are allocated within the same
117 * memory block (stored in _fs_buf_).
120 copy_fstab (struct Mono_Posix_Syscall__Fstab *to, struct vfstab *from)
123 buf = _mph_copy_structure_strings (to, mph_fstab_offsets,
124 from, vfstab_offsets, sizeof(vfstab_offsets)/sizeof(vfstab_offsets[0]));
139 * Implement Linux/BSD getfsent(3) in terms of Solaris getvfsent(3C)...
147 etc_fstab = fopen ("/etc/vfstab", "r");
148 if (etc_fstab != NULL)
163 static struct vfstab*
167 r = getvfsent (etc_fstab, &cur_vfstab_entry);
169 return &cur_vfstab_entry;
173 static struct vfstab*
174 getfsfile (const char *mount_point)
178 if (etc_fstab == 0) {
180 if (setfsent () != 1)
184 r = getvfsfile (etc_fstab, &cur_vfstab_entry, (char*) mount_point);
188 return &cur_vfstab_entry;
192 static struct vfstab*
193 getfsspec (const char *special_file)
197 if (etc_fstab == 0) {
199 if (setfsent () != 1)
203 r = getvfsspec (etc_fstab, &cur_vfstab_entry, (char*) special_file);
207 return &cur_vfstab_entry;
211 #endif /* def HAVE_SYS_VFSTAB_H */
213 #if defined (HAVE_FSTAB_H) || defined (HAVE_SYS_VFSTAB_H)
216 Mono_Posix_Syscall_endfsent (void)
222 Mono_Posix_Syscall_getfsent (struct Mono_Posix_Syscall__Fstab *fsbuf)
235 if (copy_fstab (fsbuf, fs) == -1) {
243 Mono_Posix_Syscall_getfsfile (const char *mount_point,
244 struct Mono_Posix_Syscall__Fstab *fsbuf)
253 fs = getfsfile (mount_point);
257 if (copy_fstab (fsbuf, fs) == -1) {
265 Mono_Posix_Syscall_getfsspec (const char *special_file,
266 struct Mono_Posix_Syscall__Fstab *fsbuf)
275 fs = getfsspec (special_file);
279 if (copy_fstab (fsbuf, fs) == -1) {
287 Mono_Posix_Syscall_setfsent (void)
292 #endif /* def HAVE_FSTAB_H || def HAVE_SYS_VFSTAB_H */