Back to index

avfs  1.0.1
Functions
redir2mount.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mount.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 6 of file redir2mount.c.

{
    int res;
    FILE *fp;
  
    if(argc != 3) {
        fprintf(stderr, "usage: %s from to\n", argv[0]);
        exit(1);
    }

    fp = fopen("/proc/fs/redir2/mount_pid", "w");
    if(fp == NULL) {
            perror("opening /proc/fs/redir2/mount_pid");
            exit(1);
    }
    fprintf(fp, "%u", getpid());
    fclose(fp);
    
    if (argv[1][0] == '-') {
        res = umount2(argv[2], 0);
        if (res == -1) {
            perror("umount failed");
            exit(1);
        }
    } else {
        res = mount(argv[1], argv[2], "none", MS_BIND, NULL);
        if(res == -1) {
            perror("mount failed");
            exit(1);
        }
    }
    return 0;
}