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 <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Cyrill Gorcunov 2012-05-04 13:38:00 +04:00 committed by Pavel Emelyanov
parent 9ea069d2c9
commit ed59bf001b
3 changed files with 51 additions and 0 deletions

View file

@ -53,6 +53,7 @@ OBJS += netfilter.o
OBJS += shmem.o
OBJS += eventfd.o
OBJS += eventpoll.o
OBJS += mount.o
DEPS := $(patsubst %.o,%.d,$(OBJS))

8
include/mount.h Normal file
View file

@ -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__ */

42
mount.c Normal file
View file

@ -0,0 +1,42 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <string.h>
#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;
}