1 /* Copyright (C) 1995, 1996, 1997, 1998 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
23 #include <bits/libc-lock.h>
25 #define BUFFER_SIZE 0x1fc0
31 struct mntent fs_mntres
;
35 static struct fstab_state
*fstab_init (int opt_rewind
);
36 static struct mntent
*fstab_fetch (struct fstab_state
*state
);
37 static struct fstab
*fstab_convert (struct fstab_state
*state
);
39 static struct fstab_state fstab_state
;
45 return fstab_init (1) != NULL
;
52 struct fstab_state
*state
;
54 state
= fstab_init (0);
57 if (fstab_fetch (state
) == NULL
)
59 return fstab_convert (state
);
67 struct fstab_state
*state
;
70 state
= fstab_init (1);
73 while ((m
= fstab_fetch (state
)) != NULL
)
74 if (strcmp (m
->mnt_fsname
, name
) == 0)
75 return fstab_convert (state
);
84 struct fstab_state
*state
;
87 state
= fstab_init (1);
90 while ((m
= fstab_fetch (state
)) != NULL
)
91 if (strcmp (m
->mnt_dir
, name
) == 0)
92 return fstab_convert (state
);
100 struct fstab_state
*state
;
102 state
= &fstab_state
;
103 if (state
->fs_fp
!= NULL
)
105 (void) __endmntent (state
->fs_fp
);
111 static struct fstab_state
*
112 fstab_init (int opt_rewind
)
114 struct fstab_state
*state
;
118 state
= &fstab_state
;
120 buffer
= state
->fs_buffer
;
123 buffer
= (char *) malloc (BUFFER_SIZE
);
126 state
->fs_buffer
= buffer
;
137 fp
= __setmntent (_PATH_FSTAB
, "r");
147 static struct mntent
*
148 fstab_fetch (struct fstab_state
*state
)
150 return __getmntent_r (state
->fs_fp
, &state
->fs_mntres
,
151 state
->fs_buffer
, BUFFER_SIZE
);
155 static struct fstab
*
156 fstab_convert (struct fstab_state
*state
)
161 m
= &state
->fs_mntres
;
164 f
->fs_spec
= m
->mnt_fsname
;
165 f
->fs_file
= m
->mnt_dir
;
166 f
->fs_vfstype
= m
->mnt_type
;
167 f
->fs_mntops
= m
->mnt_opts
;
168 f
->fs_type
= (__hasmntopt (m
, FSTAB_RW
) ? FSTAB_RW
:
169 __hasmntopt (m
, FSTAB_RQ
) ? FSTAB_RQ
:
170 __hasmntopt (m
, FSTAB_RO
) ? FSTAB_RO
:
171 __hasmntopt (m
, FSTAB_SW
) ? FSTAB_SW
:
172 __hasmntopt (m
, FSTAB_XX
) ? FSTAB_XX
:
174 f
->fs_freq
= m
->mnt_freq
;
175 f
->fs_passno
= m
->mnt_passno
;
180 /* Make sure the memory is freed if the programs ends while in
181 memory-debugging mode and something actually was allocated. */
183 __attribute__ ((unused
))
188 buffer
= fstab_state
.fs_buffer
;
190 free ((void *) buffer
);
193 text_set_element (__libc_subfreeres
, fstab_free
);