Back to index

avfs  1.0.1
redir2mount.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include <sys/mount.h>
00005 
00006 int main(int argc, char *argv[])
00007 {
00008     int res;
00009     FILE *fp;
00010   
00011     if(argc != 3) {
00012         fprintf(stderr, "usage: %s from to\n", argv[0]);
00013         exit(1);
00014     }
00015 
00016     fp = fopen("/proc/fs/redir2/mount_pid", "w");
00017     if(fp == NULL) {
00018             perror("opening /proc/fs/redir2/mount_pid");
00019             exit(1);
00020     }
00021     fprintf(fp, "%u", getpid());
00022     fclose(fp);
00023     
00024     if (argv[1][0] == '-') {
00025         res = umount2(argv[2], 0);
00026         if (res == -1) {
00027             perror("umount failed");
00028             exit(1);
00029         }
00030     } else {
00031         res = mount(argv[1], argv[2], "none", MS_BIND, NULL);
00032         if(res == -1) {
00033             perror("mount failed");
00034             exit(1);
00035         }
00036     }
00037     return 0;
00038 }