return mnt_match_options(fs->optstr, options);
}
-/* Unfortunately the classical Unix /etc/mtab and /etc/fstab
- do not handle directory names containing spaces.
- Here we mangle them, replacing a space by \040.
- What do other Unices do? */
-
-static unsigned char need_escaping[] = { ' ', '\t', '\n', '\\' };
-
-static char *mangle(const char *s)
-{
- char *ss, *sp;
- int n;
-
- n = strlen(s);
- ss = sp = malloc(4*n+1);
- if (!sp)
- return NULL;
- while(1) {
- for (n = 0; n < sizeof(need_escaping); n++) {
- if (*s == need_escaping[n]) {
- *sp++ = '\\';
- *sp++ = '0' + ((*s & 0300) >> 6);
- *sp++ = '0' + ((*s & 070) >> 3);
- *sp++ = '0' + (*s & 07);
- goto next;
- }
- }
- *sp++ = *s;
- if (*s == 0)
- break;
- next:
- s++;
- }
- return ss;
-}
-
-/**
- * mnt_fprintf_line:
- * @f: FILE
- * @fmt: printf-like format string (see MNT_TAB_PRINTFMT)
- * @source: (spec) device name or tag=value
- * @target: mountpoint
- * @fstype: filesystem type
- * @options: mount options
- * @freq: dump frequency in days
- * @passno: pass number on parallel fsck
- *
- * It's recommended to use this function rather than directly call fprintf() to
- * write an entry to mtab/fstab. All data in these files has to be properly
- * formatted (for example space within paths/tags has to be escaped, see
- * fstab(5) for more details).
- *
- * Returns: return value from fprintf().
- */
-int mnt_fprintf_line( FILE *f,
- const char *fmt,
- const char *source,
- const char *target,
- const char *fstype,
- const char *options,
- int freq,
- int passno)
-{
- char *m1 = NULL, *m2 = NULL, *m3 = NULL, *m4 = NULL;
- int rc = -1;
-
- if (!f || !fmt || !source || !target || !fstype || !options)
- return -1;
-
- m1 = mangle(source);
- m2 = mangle(target);
- m3 = mangle(fstype);
- m4 = mangle(options);
-
- if (!m1 || !m2 || !m3 || !m4)
- goto done;
-
- rc = fprintf(f, fmt, m1, m2, m3, m4, freq, passno);
-done:
- free(m1);
- free(m2);
- free(m3);
- free(m4);
-
- return rc;
-}
-
-/**
- * mnt_fs_fprintf:
- * @fs: fstab/mtab/mountinfo entry
- * @f: FILE
- * @fmt: printf-like format string (see MNT_TAB_PRINTFMT)
- *
- * Returns: return value from fprintf().
- */
-int mnt_fs_fprintf(mnt_fs *fs, FILE *f, const char *fmt)
-{
- assert(fs);
- assert(f);
- assert(fmt);
-
- if (!fs || !f)
- return -1;
-
- return mnt_fprintf_line(f, fmt,
- mnt_fs_get_source(fs),
- mnt_fs_get_target(fs),
- mnt_fs_get_fstype(fs),
- mnt_fs_get_optstr(fs),
- mnt_fs_get_freq(fs),
- mnt_fs_get_passno(fs));
-}
-
/**
* mnt_fs_print_debug
* @fs: fstab/mtab/mountinfo entry
extern int mnt_fs_match_source(mnt_fs *fs, const char *source, mnt_cache *cache);
extern int mnt_fs_match_fstype(mnt_fs *fs, const char *types);
extern int mnt_fs_match_options(mnt_fs *fs, const char *options);
-
-/* mtab/fstab line */
-#define MNT_TAB_PRINTFMT "%s %s %s %s %d %d\n"
-
-extern int mnt_fprintf_line(
- FILE *f,
- const char *fmt,
- const char *source,
- const char *target,
- const char *fstype,
- const char *options,
- int freq,
- int passno);
-
-extern int mnt_fs_fprintf(mnt_fs *ent, FILE *f, const char *fmt);
extern int mnt_fs_print_debug(mnt_fs *ent, FILE *file);
/* tab-parse.c */
int (*match_func)(mnt_fs *, void *), void *userdata,
mnt_fs **fs);
-extern int mnt_tab_fprintf(mnt_tab *tb, FILE *f, const char *fmt);
-extern int mnt_tab_update_file(mnt_tab *tb, const char *filename);
-
-
/*
* mount(8) userspace options masks (MNT_MAP_USERSPACE map)
*/
mnt_cache_find_tag;
mnt_cache_find_tag_value;
mnt_cache_read_tags;
- mnt_fprintf_line;
mnt_free_cache;
mnt_free_fs;
mnt_free_iter;
mnt_free_optls;
mnt_free_tab;
mnt_fs_append_optstr;
- mnt_fs_fprintf;
mnt_fs_get_devno;
mnt_fs_get_freq;
mnt_fs_get_fs_optstr;
mnt_tab_find_srcpath;
mnt_tab_find_tag;
mnt_tab_find_target;
- mnt_tab_fprintf;
mnt_tab_get_cache;
mnt_tab_get_name;
mnt_tab_get_nents;
return fs;
}
-
-/**
- * mnt_tab_fprintf:
- * @tb: tab pointer
- * @f: FILE
- * @fmt: per line printf-like format string (see MNT_TAB_PRINTFMT)
- *
- * Returns: 0 on success, -1 in case of error.
- */
-int mnt_tab_fprintf(mnt_tab *tb, FILE *f, const char *fmt)
-{
- mnt_iter itr;
- mnt_fs *fs;
-
- assert(f);
- assert(fmt);
- assert(tb);
-
- if (!f || !fmt || !tb)
- return -1;
-
- mnt_reset_iter(&itr, MNT_ITER_FORWARD);
- while(mnt_tab_next_fs(tb, &itr, &fs) == 0) {
- if (mnt_fs_fprintf(fs, f, fmt) == -1)
- return -1;
- }
-
- return 0;
-}
-
-/**
- * mnt_tab_update_file
- * @tb: tab pointer
- *
- * Writes tab to disk. Don't forget to lock the file (see mnt_lock()).
- *
- * Returns: 0 on success, -1 in case of error.
- */
-int mnt_tab_update_file(mnt_tab *tb, const char *filename)
-{
- FILE *f = NULL;
- char tmpname[PATH_MAX];
- struct stat st;
- int fd;
-
- assert(tb);
- if (!tb)
- goto error;
-
- if (snprintf(tmpname, sizeof(tmpname), "%s.tmp", filename)
- >= sizeof(tmpname))
- goto error;
-
- f = fopen(tmpname, "w");
- if (!f)
- goto error;
-
- if (mnt_tab_fprintf(tb, f, MNT_TAB_PRINTFMT) != 0)
- goto error;
-
- fd = fileno(f);
-
- if (fchmod(fd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0)
- goto error;
-
- /* Copy uid/gid from the present file before renaming. */
- if (stat(filename, &st) == 0) {
- if (fchown(fd, st.st_uid, st.st_gid) < 0)
- goto error;
- }
-
- fclose(f);
- f = NULL;
-
- if (rename(tmpname, filename) < 0)
- goto error;
-
- return 0;
-error:
- if (f)
- fclose(f);
- return -1;
-}
-
#ifdef TEST_PROGRAM
static int parser_errcb(mnt_tab *tb, const char *filename, int line, int flag)
* This function uses @uf to found corresponding record in @tb, then the record
* from @tb is updated (userspace specific mount options are added).
*
- * Note that @uf must contain userspace specific mount options only!
+ * Note that @uf must contain only userspace specific mount options instead of
+ * VFS options (note that FS options are ignored).
*
* Returns: modified filesystem (from @tb) or NULL.
*/