2 * <fstab.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2005 Jonathan Pryor
18 #if defined (HAVE_CHECKLIST_H)
19 #include <checklist.h>
20 #elif defined (HAVE_FSTAB_H)
22 #endif /* def HAVE_FSTAB_H */
24 #ifdef HAVE_SYS_VFSTAB_H
25 #include <sys/vfstab.h>
26 #endif /* def HAVE_SYS_VFSTAB_H */
30 struct Mono_Posix_Syscall__Fstab
{
31 char *fs_spec
; /* block device name */
32 char *fs_file
; /* mount point */
33 char *fs_vfstype
; /* filesystem type */
34 char *fs_mntops
; /* mount options */
35 char *fs_type
; /* rw/rq/ro/sw/xx option */
36 int fs_freq
; /* dump frequency, in days */
37 int fs_passno
; /* pass number on parallel dump */
42 #ifdef HAVE_CHECKLIST_H
44 typedef struct checklist mph_fstab
;
48 offsetof (struct checklist
, fs_spec
),
49 offsetof (struct checklist
, fs_dir
),
50 offsetof (struct checklist
, 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_type
)
60 #elif defined (HAVE_FSTAB_H)
62 typedef struct fstab mph_fstab
;
66 offsetof (struct fstab
, fs_spec
),
67 offsetof (struct fstab
, fs_file
),
68 offsetof (struct fstab
, fs_vfstype
),
69 offsetof (struct fstab
, fs_mntops
),
70 offsetof (struct fstab
, fs_type
)
74 mph_fstab_offsets
[] = {
75 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_spec
),
76 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_file
),
77 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_vfstype
),
78 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_mntops
),
79 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_type
)
82 #endif /* def HAVE_FSTAB_H */
84 #if defined (HAVE_CHECKLIST_H) || defined (HAVE_FSTAB_H)
87 * Copy the native `fstab' structure to it's managed representation.
89 * To minimize separate mallocs, all the strings are allocated within the same
90 * memory block (stored in _fs_buf_).
93 copy_fstab (struct Mono_Posix_Syscall__Fstab
*to
, mph_fstab
*from
)
97 memset (to
, 0, sizeof(*to
));
99 buf
= _mph_copy_structure_strings (to
, mph_fstab_offsets
,
100 from
, fstab_offsets
, sizeof(fstab_offsets
)/sizeof(fstab_offsets
[0]));
102 to
->fs_freq
= from
->fs_freq
;
103 to
->fs_passno
= from
->fs_passno
;
113 #endif /* def HAVE_CHECKLIST_H || def HAVE_FSTAB_H */
115 #ifdef HAVE_SYS_VFSTAB_H
118 * Solaris doesn't provide <fstab.h> but has equivalent functionality in
119 * <sys/fstab.h> via getvfsent(3C) and company.
122 typedef struct vfstab mph_fstab
;
126 offsetof (struct vfstab
, vfs_special
),
127 offsetof (struct vfstab
, vfs_mountp
),
128 offsetof (struct vfstab
, vfs_fstype
),
129 offsetof (struct vfstab
, vfs_mntopts
)
133 mph_fstab_offsets
[] = {
134 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_spec
),
135 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_file
),
136 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_vfstype
),
137 offsetof (struct Mono_Posix_Syscall__Fstab
, fs_mntops
)
141 * Copy the native `vfstab' structure to it's managed representation.
143 * To minimize separate mallocs, all the strings are allocated within the same
144 * memory block (stored in _fs_buf_).
147 copy_fstab (struct Mono_Posix_Syscall__Fstab
*to
, struct vfstab
*from
)
151 memset (to
, 0, sizeof(*to
));
153 buf
= _mph_copy_structure_strings (to
, mph_fstab_offsets
,
154 from
, vfstab_offsets
, sizeof(vfstab_offsets
)/sizeof(vfstab_offsets
[0]));
169 * Implement Linux/BSD getfsent(3) in terms of Solaris getvfsent(3C)...
177 etc_fstab
= fopen ("/etc/vfstab", "r");
178 if (etc_fstab
!= NULL
)
193 static struct vfstab
*
197 r
= getvfsent (etc_fstab
, &cur_vfstab_entry
);
199 return &cur_vfstab_entry
;
203 static struct vfstab
*
204 getfsfile (const char *mount_point
)
208 if (etc_fstab
== 0) {
210 if (setfsent () != 1)
214 r
= getvfsfile (etc_fstab
, &cur_vfstab_entry
, (char*) mount_point
);
218 return &cur_vfstab_entry
;
222 static struct vfstab
*
223 getfsspec (const char *special_file
)
227 if (etc_fstab
== 0) {
229 if (setfsent () != 1)
233 r
= getvfsspec (etc_fstab
, &cur_vfstab_entry
, (char*) special_file
);
237 return &cur_vfstab_entry
;
241 #endif /* def HAVE_SYS_VFSTAB_H */
243 #if defined (HAVE_FSTAB_H) || defined (HAVE_CHECKPOINT_H) || defined (HAVE_SYS_VFSTAB_H)
246 Mono_Posix_Syscall_endfsent (void)
252 Mono_Posix_Syscall_getfsent (struct Mono_Posix_Syscall__Fstab
*fsbuf
)
265 if (copy_fstab (fsbuf
, fs
) == -1) {
273 Mono_Posix_Syscall_getfsfile (const char *mount_point
,
274 struct Mono_Posix_Syscall__Fstab
*fsbuf
)
283 fs
= getfsfile (mount_point
);
287 if (copy_fstab (fsbuf
, fs
) == -1) {
295 Mono_Posix_Syscall_getfsspec (const char *special_file
,
296 struct Mono_Posix_Syscall__Fstab
*fsbuf
)
305 fs
= getfsspec (special_file
);
309 if (copy_fstab (fsbuf
, fs
) == -1) {
317 Mono_Posix_Syscall_setfsent (void)
322 #endif /* def HAVE_FSTAB_H || def HAVE_CHECKPOINT_H || def HAVE_SYS_VFSTAB_H */