home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / ifs-5.1 / ifsprogs / smount.c < prev    next >
C/C++ Source or Header  |  1995-10-10  |  3KB  |  143 lines

  1. /* smount.c  -  very simplistic mount command */
  2.  
  3. /*
  4.  * Usage: smount [ -t type ] [ -o option,option,... ] device directory
  5.  *       smount -t ifs [ -o option,option,... ] directory,... directory
  6.  *        smount -u device
  7.  *        smount -u directory
  8.  */
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13.  
  14. #include <linux/unistd.h>
  15. #include <linux/config.h>
  16. #include <linux/fs.h>
  17. #ifdef CONFIG_IFS_FS
  18. #include <linux/ifs_fs.h>
  19. #endif
  20. #include <linux/mm.h>
  21.  
  22.  
  23. #ifndef MS_MGC_VAL
  24. #define MS_MGC_VAL 0xC0ED0000
  25. #endif
  26.  
  27.  
  28. static struct mount_opt {
  29.     char *name;
  30.     int value;
  31. } mount_opt[] = {
  32.     { "ro",     MS_RDONLY },
  33.     { "rw",     0 },
  34.     { "nosuid", MS_NOSUID },
  35.     { "nodev",  MS_NODEV },
  36.     { "noexec", MS_NOEXEC },
  37. #ifdef MS_REMOUNT
  38.     { "remount",MS_REMOUNT },
  39. #endif
  40.     { NULL,     0 }
  41. };
  42.  
  43.  
  44. _syscall5(int,mount,char *,dev,char *,dir,char *,type,unsigned long,flags,
  45.   void *,data)
  46. _syscall1(int,umount,char *,name)
  47.  
  48.  
  49. static void usage(char *name)
  50. {
  51.     fprintf(stderr,"usage: %s [-t type] [-o option,option,...] device dir\n",
  52.       name);
  53. #ifdef CONFIG_IFS_FS
  54.     fprintf(stderr,"%7s%s -t ifs [-o option,option,...] dir,dir,... dir\n","",
  55.       name);
  56. #endif
  57.     fprintf(stderr,"%7s%s -u device\n","",name);
  58.     fprintf(stderr,"%7s%s -u dir\n","",name);
  59.     exit(1);
  60. }
  61.  
  62.  
  63. int main(int argc,char **argv)
  64. {
  65.     char *type,*options,*name,*this;
  66.     char opt[PAGE_SIZE];
  67.     int do_umount,flags;
  68.     struct mount_opt *walk;
  69.  
  70.     type = options = NULL;
  71.     do_umount = 0;
  72.     if (!--argc) usage(*argv);
  73.     name = *argv++;
  74.     while (argc && argv[0][0] == '-') {
  75.     if (argv[0][2]) usage(name);
  76.     switch (argv[0][1]) {
  77.         case 'o':
  78.         if (argc < 2) usage(name);
  79.         options = *++argv;
  80.         argc--;
  81.         break;
  82.         case 't':
  83.         if (argc < 2) usage(name);
  84.         type = *++argv;
  85.         argc--;
  86.         break;
  87.         case 'u':
  88.         do_umount = 1;
  89.         break;
  90.         default:
  91.         usage(name);
  92.     }
  93.     argv++;
  94.     argc--;
  95.     }
  96.     if (do_umount) {
  97.     if (type || options || argc != 1) usage(name);
  98.     if (umount(argv[0]) < 0) {
  99.         perror("smount");
  100.         return 1;
  101.     }
  102.     return 0;
  103.     }
  104.     if (argc != 2) usage(name);
  105.     flags = 0;
  106.     *opt = 0;
  107.     for (this = strtok(options,","); this; this = strtok(NULL,",")) {
  108.     for (walk = mount_opt; walk->name; walk++)
  109.         if (!strcmp(walk->name,this)) break;
  110.     if (walk->name) flags |= walk->value;
  111.     else strcat(strcat(opt,this),",");
  112.     }
  113.     if (this = strrchr(opt,',')) *this = 0;
  114. #ifdef CONFIG_IFS_FS
  115.     if (!strcmp(type,"ifs")) {
  116.     struct ifs_mpar *mpar;
  117.     int flags;
  118.     char *next;
  119.  
  120.     flags = 0;
  121.     if (*opt)
  122.         if (!strcmp(opt,"cache")) flags = IFS_FF_CACHE;
  123.         else {
  124.         fprintf(stderr,"Unrecognized by IFS: %s\n",opt);
  125.         return 1;
  126.         }
  127.     mpar = (struct ifs_mpar *) opt;
  128.     mpar->magic = IFS_MOUNT_MAGIC;
  129.     mpar->flags = flags;
  130.     mpar->layers = 0;
  131.     for (this = argv[0]; this; this = next) {
  132.         if (next = strchr(this,',')) *next++ = 0;
  133.         mpar->names[mpar->layers++] = this;
  134.     }
  135.     }
  136. #endif
  137.     if (mount(argv[0],argv[1],type,MS_MGC_VAL | flags,opt) < 0) {
  138.     perror("smount");
  139.     return 1;
  140.     }
  141.     return 0;
  142. }
  143.