akaros/tests/bind.c
<<
>>
Prefs
   1#define _LARGEFILE64_SOURCE /* needed to use lseek64 */
   2
   3#include <stdio.h>
   4#include <sys/types.h>
   5#include <sys/stat.h>
   6#include <fcntl.h>
   7#include <parlib/arch/arch.h>
   8#include <unistd.h>
   9#include <errno.h>
  10#include <dirent.h>
  11#include <stdlib.h>
  12#include <string.h>
  13#include <ros/syscall.h>
  14
  15static void usage_exit(void)
  16{
  17        fprintf(stderr, "usage: bind [-a|-b] [-c] [-v] src_path onto_path\n");
  18        exit(1);
  19}
  20
  21/* The naming for the args in bind is messy historically.  We do:
  22 *      bind src_path onto_path
  23 * plan9 says bind NEW OLD, where new is *src*, and old is *onto*.
  24 * Linux says mount --bind OLD NEW, where OLD is *src* and NEW is *onto*.
  25 *
  26 * Maybe we should go with WHAT WHERE... */
  27int main(int argc, char *argv[])
  28{
  29        int ret;
  30        int flag = 0;
  31        char *src_path, *onto_path;
  32        bool verbose = false;
  33
  34        /* crap arg handling for now. */
  35        argc--, argv++;
  36        while (argc > 2) {
  37                switch (argv[0][1]) {
  38                case 'b':
  39                        flag |= 1;
  40                        break;
  41                case 'a':
  42                        flag |= 2;
  43                        break;
  44                case 'c':
  45                        flag |= 4;
  46                        break;
  47                case 'v':
  48                        verbose = true;
  49                        break;
  50                default:
  51                        usage_exit();
  52                }
  53                /* extremely disgusting */
  54                if (argv[0][2]) {
  55                        fprintf(stderr, "sorry, only one argument per -\n");
  56                        usage_exit();
  57                }
  58                argc--, argv++;
  59        }
  60
  61        if (argc < 2)
  62                usage_exit();
  63        src_path = argv[0];
  64        onto_path = argv[1];
  65        if (verbose)
  66                printf("bind %s (onto) -> %s (src) flag %d\n", onto_path,
  67                       src_path, flag);
  68        ret = syscall(SYS_nbind, src_path, strlen(src_path), onto_path,
  69                      strlen(onto_path), flag);
  70        if (ret < 0)
  71                perror("Bind failed");
  72        return ret;
  73}
  74