From ed59bf001ba9fdd82229afdfa99f8bcbdcc4d821 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Fri, 4 May 2012 13:38:00 +0400 Subject: [PATCH] Add mount.c file for mount helpers functions At moment only open_mnt_root is there, which is needed for inotify restore. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- Makefile | 1 + include/mount.h | 8 ++++++++ mount.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 include/mount.h create mode 100644 mount.c diff --git a/Makefile b/Makefile index 23002cfd7..16c11af5a 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,7 @@ OBJS += netfilter.o OBJS += shmem.o OBJS += eventfd.o OBJS += eventpoll.o +OBJS += mount.o DEPS := $(patsubst %.o,%.d,$(OBJS)) diff --git a/include/mount.h b/include/mount.h new file mode 100644 index 000000000..608c44846 --- /dev/null +++ b/include/mount.h @@ -0,0 +1,8 @@ +#ifndef MOUNT_H__ +#define MOUNT_H__ + +struct proc_mountinfo; + +extern int open_mnt_root(unsigned int s_dev, struct proc_mountinfo *mntinfo, int nr_mntinfo); + +#endif /* MOUNT_H__ */ diff --git a/mount.c b/mount.c new file mode 100644 index 000000000..3db7d3483 --- /dev/null +++ b/mount.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "types.h" +#include "util.h" +#include "mount.h" +#include "proc_parse.h" + +/* + * Returns path for mount device @s_dev + * + * FIXME this is not sufficient in general + * since mount points can be overmounted but + * works for now. + */ +int open_mnt_root(unsigned int s_dev, struct proc_mountinfo *mntinfo, int nr_mntinfo) +{ + static int last = 0; + int i; + +again: + for (i = last; i < nr_mntinfo; i++) { + if (s_dev == mntinfo[i].s_dev) { + last = i; + return open(mntinfo[i].mnt_root, O_RDONLY); + } + } + + if (last) { + last = 0; + goto again; + } + + return -ENOENT; +}