{
int rc;
const char *utab = NULL;
+ struct libmnt_table *u_tb;
if (mnt_has_regular_mtab(&filename, NULL)) {
return mnt_table_parse_file(tb, _PATH_PROC_MOUNTS);
}
+ if (mnt_table_get_nents(tb) == 0)
+ return 0; /* empty, ignore utab */
/*
* try to read user specific information from /run/mount/utabs
*/
utab = mnt_get_utab_path();
- if (utab) {
- struct libmnt_table *u_tb = mnt_new_table();
- if (u_tb) {
- u_tb->fmt = MNT_FMT_UTAB;
- mnt_table_set_parser_fltrcb(u_tb, tb->fltrcb, tb->fltrcb_data);
-
- if (mnt_table_parse_file(u_tb, utab) != 0) {
- mnt_free_table(u_tb);
- u_tb = NULL;
- }
- }
+ if (!utab || is_file_empty(utab))
+ return 0;
- if (u_tb) {
- struct libmnt_fs *u_fs;
- struct libmnt_iter itr;
+ u_tb = mnt_new_table();
+ if (!u_tb)
+ return -ENOMEM;
- mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
+ u_tb->fmt = MNT_FMT_UTAB;
+ mnt_table_set_parser_fltrcb(u_tb, tb->fltrcb, tb->fltrcb_data);
- /* merge user options into mountinfo from kernel */
- while(mnt_table_next_fs(u_tb, &itr, &u_fs) == 0)
- mnt_table_merge_user_fs(tb, u_fs);
+ if (mnt_table_parse_file(u_tb, utab) == 0) {
+ struct libmnt_fs *u_fs;
+ struct libmnt_iter itr;
- mnt_free_table(u_tb);
- }
+ mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
+
+ /* merge user options into mountinfo from kernel */
+ while(mnt_table_next_fs(u_tb, &itr, &u_fs) == 0)
+ mnt_table_merge_user_fs(tb, u_fs);
}
+
+ mnt_free_table(u_tb);
return 0;
}
return !strncmp(s, sx, off);
}
+/*
+ * Return 1 if the file does not accessible of empty
+ */
+int is_file_empty(const char *name)
+{
+ struct stat st;
+ assert(name);
+
+ return (stat(name, &st) != 0 || st.st_size == 0);
+}
+
int mnt_parse_offset(const char *str, size_t len, uintmax_t *res)
{
char *p;