1 #ifndef GO32 2 #include <stdio.h> 3 #include <unistd.h> 4 #include <stdlib.h> 5 #include <sys/mount.h> 6 #include <sys/types.h> 7 #include <sys/stat.h> 8 #include <fcntl.h> 9 #ifndef GLIBC2 10 #include <linux/fs.h> 11 #endif 12 #include <string.h> 13 #include "version.h" 14 #include "mount.h" 15 16 17 /* Various declartaions of where to find files. */ 18 #ifndef PROC_FILESYSTEMS 19 #define PROC_FILESYSTEMS "/proc/filesystems" 20 #endif 21 #ifndef ETC_FSTAB 22 #define ETC_FSTAB "/etc/fstab" 23 #endif 24 #ifndef PROC_MOUNTS 25 #define PROC_MOUNTS "/proc/mounts" 26 #endif 27 28 /* The mount(2) man page was lying to me. */ 29 30 #if defined(MS_SYNCHRONOUS) && !defined(MS_SYNC) 31 #define MS_SYNC MS_SYNCHRONOUS 32 #endif 33 34 35 extern char *optarg; 36 extern int optind, opterr, optopt; 37 38 int mount_main (int argc, char **argv) { 39 char *option_fstype=NULL; 40 char *fs_source=NULL; 41 char *fs_dest=NULL; 42 char buf[255]; 43 char option_fake=0; 44 char option_verbose=0; 45 char option_fork=0; 46 char option_mountall=0; 47 char ch; 48 int option_options=0; 49 int fd; 50 int i; 51 52 /* Parse our arguments, using getopt(3) ... */ 53 54 while ( (ch=getopt(argc,argv,"VafFrvwt:o:")) != -1 ) { 55 switch (ch) { 56 case 'a': 57 option_mountall=1; 58 /* TODO: Make mountall work. */ 59 break; 60 case 'f': 61 option_fake=1; 62 break; 63 case 'F': 64 /* TODO: Make fork work, requires -a first.*/ 65 option_fork=1; 66 break; 67 case 'r': 68 option_options|=MS_RDONLY; 69 break; 70 case 'v': 71 /* TODO: Make verbose work. */ 72 option_verbose=1; 73 break; 74 case 'w': 75 option_options&=(~((int) MS_RDONLY)); 76 break; 77 case 't': 78 option_fstype=optarg; 79 break; 80 case 'o': 81 option_options=mount_parse_options(option_options,optarg); 82 break; 83 case 'V': 84 write(STDOUT_FILENO, "mount: mooselinux-" MOOSE_VERSION "\n", 18+sizeof(MOOSE_VERSION)); 85 return(0); 86 default: 87 break; 88 } 89 } 90 91 /* If there are no arguments (exluding options), then just display mounts */ 92 93 if ((argc-optind)==0) { 94 if ((fd=open(PROC_MOUNTS, O_RDONLY))==-1) return(-1); 95 while (1) { 96 if ((i=read(fd,&buf,sizeof(buf)))==0) break; 97 write(STDOUT_FILENO,&buf,i); 98 } 99 close(fd); 100 return(0); 101 } 102 103 /* TODO: Add fstab support ! */ 104 105 /* If there were 2 arguments, mount special arg1 to directory arg2 */ 106 107 if ((argc-optind)==2) { 108 fs_source=argv[optind]; 109 fs_dest=argv[optind+1]; 110 } 111 112 /* unless Fake is enabled, then just do nothing. */ 113 114 if (!option_fake) { 115 if (mount(fs_source,fs_dest,option_fstype,MS_MGC_VAL|option_options,NULL)<0) { 116 perror("mount"); 117 return(-1); 118 } 119 } 120 121 return(0); 122 } 123 124 /* Parse the mount options */ 125 126 int mount_parse_options(int initop, char *value) { 127 char *buf; 128 129 buf=strtok(value,","); 130 131 while (1) { 132 if (!strcmp(buf,"atime")) initop&=(~((int) MS_NOATIME)); 133 if (!strcmp(buf,"noatime")) initop|= MS_NOATIME; 134 if (!strcmp(buf,"async")) initop&=(~((int) MS_SYNC)); 135 if (!strcmp(buf,"sync")) initop|= MS_SYNC; 136 if (!strcmp(buf,"dev")) initop&=(~((int) MS_NODEV)); 137 if (!strcmp(buf,"nodev")) initop|= MS_NODEV; 138 if (!strcmp(buf,"exec")) initop&=(~((int) MS_NOEXEC)); 139 if (!strcmp(buf,"noexec")) initop|= MS_NOEXEC; 140 if (!strcmp(buf,"suid")) initop&=(~((int) MS_NOSUID)); 141 if (!strcmp(buf,"nosuid")) initop|= MS_NOSUID; 142 if (!strcmp(buf,"remount")) initop|= MS_REMOUNT; 143 if (!strcmp(buf,"rw")) initop&=(~((int) MS_RDONLY)); 144 if (!strcmp(buf,"ro")) initop|= MS_RDONLY; 145 if (!strcmp(buf,"user")) initop|=(MS_NODEV | MS_NOSUID | MS_NOEXEC); 146 if (!strcmp(buf,"defaults")) initop=0; 147 if ((buf=strtok(NULL,","))==NULL) break; 148 } 149 150 return(initop); 151 } 152 #else 153 int mount_main(int argc, char **argv) { 154 return(0); 155 } 156 #endif |