1 /* Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include <bits/libc-lock.h>
26 #define BUFFER_SIZE 0x1fc0
32 struct mntent fs_mntres
;
36 static struct fstab_state
*fstab_init (int opt_rewind
);
37 static struct mntent
*fstab_fetch (struct fstab_state
*state
);
38 static struct fstab
*fstab_convert (struct fstab_state
*state
);
40 static struct fstab_state fstab_state
;
46 return fstab_init (1) != NULL
;
53 struct fstab_state
*state
;
55 state
= fstab_init (0);
58 if (fstab_fetch (state
) == NULL
)
60 return fstab_convert (state
);
68 struct fstab_state
*state
;
71 state
= fstab_init (1);
74 while ((m
= fstab_fetch (state
)) != NULL
)
75 if (strcmp (m
->mnt_fsname
, name
) == 0)
76 return fstab_convert (state
);
85 struct fstab_state
*state
;
88 state
= fstab_init (1);
91 while ((m
= fstab_fetch (state
)) != NULL
)
92 if (strcmp (m
->mnt_dir
, name
) == 0)
93 return fstab_convert (state
);
101 struct fstab_state
*state
;
103 state
= &fstab_state
;
104 if (state
->fs_fp
!= NULL
)
106 (void) __endmntent (state
->fs_fp
);
112 static struct fstab_state
*
113 fstab_init (int opt_rewind
)
115 struct fstab_state
*state
;
119 state
= &fstab_state
;
121 buffer
= state
->fs_buffer
;
124 buffer
= (char *) malloc (BUFFER_SIZE
);
127 state
->fs_buffer
= buffer
;
138 fp
= __setmntent (_PATH_FSTAB
, "r");
148 static struct mntent
*
149 fstab_fetch (struct fstab_state
*state
)
151 return __getmntent_r (state
->fs_fp
, &state
->fs_mntres
,
152 state
->fs_buffer
, BUFFER_SIZE
);
156 static struct fstab
*
157 fstab_convert (struct fstab_state
*state
)
162 m
= &state
->fs_mntres
;
165 f
->fs_spec
= m
->mnt_fsname
;
166 f
->fs_file
= m
->mnt_dir
;
167 f
->fs_vfstype
= m
->mnt_type
;
168 f
->fs_mntops
= m
->mnt_opts
;
169 f
->fs_type
= (__hasmntopt (m
, FSTAB_RW
) ? FSTAB_RW
:
170 __hasmntopt (m
, FSTAB_RQ
) ? FSTAB_RQ
:
171 __hasmntopt (m
, FSTAB_RO
) ? FSTAB_RO
:
172 __hasmntopt (m
, FSTAB_SW
) ? FSTAB_SW
:
173 __hasmntopt (m
, FSTAB_XX
) ? FSTAB_XX
:
175 f
->fs_freq
= m
->mnt_freq
;
176 f
->fs_passno
= m
->mnt_passno
;
181 /* Make sure the memory is freed if the programs ends while in
182 memory-debugging mode and something actually was allocated. */
184 __attribute__ ((unused
))
189 buffer
= fstab_state
.fs_buffer
;
191 free ((void *) buffer
);
194 text_set_element (__libc_subfreeres
, fstab_free
);