1 /* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2008
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include <bits/libc-lock.h>
27 #define BUFFER_SIZE 0x1fc0
33 struct mntent fs_mntres
;
37 static struct fstab_state
*fstab_init (int opt_rewind
);
38 static struct mntent
*fstab_fetch (struct fstab_state
*state
);
39 static struct fstab
*fstab_convert (struct fstab_state
*state
);
41 static struct fstab_state fstab_state
;
47 return fstab_init (1) != NULL
;
54 struct fstab_state
*state
;
56 state
= fstab_init (0);
59 if (fstab_fetch (state
) == NULL
)
61 return fstab_convert (state
);
69 struct fstab_state
*state
;
72 state
= fstab_init (1);
75 while ((m
= fstab_fetch (state
)) != NULL
)
76 if (strcmp (m
->mnt_fsname
, name
) == 0)
77 return fstab_convert (state
);
86 struct fstab_state
*state
;
89 state
= fstab_init (1);
92 while ((m
= fstab_fetch (state
)) != NULL
)
93 if (strcmp (m
->mnt_dir
, name
) == 0)
94 return fstab_convert (state
);
102 struct fstab_state
*state
;
104 state
= &fstab_state
;
105 if (state
->fs_fp
!= NULL
)
107 (void) __endmntent (state
->fs_fp
);
113 static struct fstab_state
*
114 fstab_init (int opt_rewind
)
116 struct fstab_state
*state
;
120 state
= &fstab_state
;
122 buffer
= state
->fs_buffer
;
125 buffer
= (char *) malloc (BUFFER_SIZE
);
128 state
->fs_buffer
= buffer
;
139 fp
= __setmntent (_PATH_FSTAB
, "r");
149 static struct mntent
*
150 fstab_fetch (struct fstab_state
*state
)
152 return __getmntent_r (state
->fs_fp
, &state
->fs_mntres
,
153 state
->fs_buffer
, BUFFER_SIZE
);
157 static struct fstab
*
158 fstab_convert (struct fstab_state
*state
)
163 m
= &state
->fs_mntres
;
166 f
->fs_spec
= m
->mnt_fsname
;
167 f
->fs_file
= m
->mnt_dir
;
168 f
->fs_vfstype
= m
->mnt_type
;
169 f
->fs_mntops
= m
->mnt_opts
;
170 f
->fs_type
= (__hasmntopt (m
, FSTAB_RW
) ? FSTAB_RW
:
171 __hasmntopt (m
, FSTAB_RQ
) ? FSTAB_RQ
:
172 __hasmntopt (m
, FSTAB_RO
) ? FSTAB_RO
:
173 __hasmntopt (m
, FSTAB_SW
) ? FSTAB_SW
:
174 __hasmntopt (m
, FSTAB_XX
) ? FSTAB_XX
:
176 f
->fs_freq
= m
->mnt_freq
;
177 f
->fs_passno
= m
->mnt_passno
;
182 /* Make sure the memory is freed if the programs ends while in
183 memory-debugging mode and something actually was allocated. */
184 libc_freeres_fn (fstab_free
)
188 buffer
= fstab_state
.fs_buffer
;
189 free ((void *) buffer
);