1 /* Copyright (C) 1995-2017 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, see
16 <http://www.gnu.org/licenses/>. */
23 #include <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
);
64 getfsspec (const char *name
)
66 struct fstab_state
*state
;
69 state
= fstab_init (1);
72 while ((m
= fstab_fetch (state
)) != NULL
)
73 if (strcmp (m
->mnt_fsname
, name
) == 0)
74 return fstab_convert (state
);
80 getfsfile (const char *name
)
82 struct fstab_state
*state
;
85 state
= fstab_init (1);
88 while ((m
= fstab_fetch (state
)) != NULL
)
89 if (strcmp (m
->mnt_dir
, name
) == 0)
90 return fstab_convert (state
);
98 struct fstab_state
*state
;
100 state
= &fstab_state
;
101 if (state
->fs_fp
!= NULL
)
103 (void) __endmntent (state
->fs_fp
);
109 static struct fstab_state
*
110 fstab_init (int opt_rewind
)
112 struct fstab_state
*state
;
116 state
= &fstab_state
;
118 buffer
= state
->fs_buffer
;
121 buffer
= (char *) malloc (BUFFER_SIZE
);
124 state
->fs_buffer
= buffer
;
135 fp
= __setmntent (_PATH_FSTAB
, "r");
145 static struct mntent
*
146 fstab_fetch (struct fstab_state
*state
)
148 return __getmntent_r (state
->fs_fp
, &state
->fs_mntres
,
149 state
->fs_buffer
, BUFFER_SIZE
);
153 static struct fstab
*
154 fstab_convert (struct fstab_state
*state
)
159 m
= &state
->fs_mntres
;
162 f
->fs_spec
= m
->mnt_fsname
;
163 f
->fs_file
= m
->mnt_dir
;
164 f
->fs_vfstype
= m
->mnt_type
;
165 f
->fs_mntops
= m
->mnt_opts
;
166 f
->fs_type
= (__hasmntopt (m
, FSTAB_RW
) ? FSTAB_RW
:
167 __hasmntopt (m
, FSTAB_RQ
) ? FSTAB_RQ
:
168 __hasmntopt (m
, FSTAB_RO
) ? FSTAB_RO
:
169 __hasmntopt (m
, FSTAB_SW
) ? FSTAB_SW
:
170 __hasmntopt (m
, FSTAB_XX
) ? FSTAB_XX
:
172 f
->fs_freq
= m
->mnt_freq
;
173 f
->fs_passno
= m
->mnt_passno
;
178 /* Make sure the memory is freed if the programs ends while in
179 memory-debugging mode and something actually was allocated. */
180 libc_freeres_fn (fstab_free
)
184 buffer
= fstab_state
.fs_buffer
;
185 free ((void *) buffer
);