3 * Copyright (C) 2002 Florin Malita <mali@go.ro>
5 * This file is part of LUFS, a free userspace filesystem implementation.
6 * See http://lufs.sourceforge.net/ for updates.
8 * LUFS is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * LUFS is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define TRACE(x...) fprintf(stdout, x)
36 #define TRACE(x...) do{}while(0);
39 #define ERROR(x...) fprintf(stderr, x)
43 char *short_opts = "hvu:g:f:d:c:o:Opq";
44 struct option long_opts[] = {
45 {"help", 0, NULL, 'h'},
46 {"uid", 1, NULL, 'u'},
47 {"gid", 1, NULL, 'g'},
48 {"fmask", 1, NULL, 'f'},
49 {"dmask", 1, NULL, 'd'},
50 {"channels",1, NULL, 'c'},
51 {"opts", 1, NULL, 'o'},
52 {"own_fs", 0, NULL, 'O'},
53 {"verbose", 0, NULL, 'v'},
54 {"password",0, NULL, 'p'},
55 {"quiet", 0, NULL, 'q'},
62 usage(FILE *fp, char *prgname){
63 fprintf(fp, "Usage: %s <fs_type>://[<user>[:<pass>]@]<host>[:<port>][/<remote_root>] <mountpoint> [options]\n", prgname);
64 fprintf(fp, " -c, --channels=NR_CHAN the number of transfer channels per filesystem\n");
65 fprintf(fp, " -d, --dmask=MASK minimum dir permissions\n");
66 fprintf(fp, " -f, --fmask=MASK minimum file permissions\n");
67 fprintf(fp, " -g, --gid=GID the gid to own the mounted filesystem\n");
68 fprintf(fp, " -h, --help display this help and exit\n");
69 fprintf(fp, " -o, --opts opt=val[,...] file system specific options\n");
70 fprintf(fp, " -O, --own_fs force fs ownership of the mounting user\n");
71 fprintf(fp, " -p, --password interactively prompt for password if not specified\n");
72 fprintf(fp, " -q --quiet disable all logging from daemon (close all fds)\n");
73 fprintf(fp, " -u, --uid=UID the uid to own the mounted filesystem\n");
74 fprintf(fp, " -v, --verbose print the mount command before executing\n");
78 main(int argc, char **argv){
79 int res, verbose = 0, own_fs = 0, ask_pass = 0, quiet = 0;
80 char *uid = NULL, *gid = NULL;
81 char *options = NULL, *chan = NULL;
82 char *fmask = NULL, *dmask = NULL;
83 char *url, *mpoint, *fs;
84 char *user = NULL, *pass = NULL, *root = NULL, *port = NULL;
88 res = getopt_long(argc, argv, short_opts, long_opts, NULL);
92 usage(stdout, argv[0]);
137 TRACE("wrong option\n");
138 usage(stderr, argv[0]);
146 if(optind > argc - 2){
147 usage(stderr, argv[0]);
151 url = argv[optind++];
152 mpoint = argv[optind++];
154 TRACE("url: %s\n", url);
155 TRACE("mountpoint: %s\n", mpoint);
157 if(!(i = strstr(url, "://"))){
158 ERROR("invalid URL (%s): protocol delimiter not found\n", url);
165 TRACE("fs: %s\n", fs);
167 i = strchr(url, '@');
168 j = strchr(url, '/');
170 if((i) && ((i < j) || (j == NULL))){
175 if((i = strchr(user, ':'))){
178 TRACE("pass: %s\n", pass);
180 TRACE("user: %s\n", user);
183 if((i = strchr(url, '/'))){
186 TRACE("root: %s\n", root);
189 if((i = strchr(url, ':'))){
192 TRACE("port: %s\n", port);
195 TRACE("host: %s\n", url);
197 if(!pass && ask_pass)
198 pass = getpass("password:");
201 if(snprintf(buf, MAX_LEN, "lufsd none %s -o fs=%s", mpoint, fs) >= MAX_LEN)
205 if(strlen(buf) + strlen(",host=") + strlen(url) >= MAX_LEN)
208 strcat(buf, ",host=");
213 if(strlen(buf) + strlen(",username=") + strlen(user) >= MAX_LEN)
216 strcat(buf, ",username=");
221 if(strlen(buf) + strlen(",password=") + strlen(pass) >= MAX_LEN)
224 strcat(buf, ",password=");
229 if(strlen(buf) + strlen(",port=") + strlen(port) >= MAX_LEN)
232 strcat(buf, ",port=");
237 if(strlen(buf) + strlen(",root=/") + strlen(root) >= MAX_LEN)
240 strcat(buf, ",root=/");
245 if(strlen(buf) + strlen(",uid=") + strlen(uid) >= MAX_LEN)
248 strcat(buf, ",uid=");
253 if(strlen(buf) + strlen(",gid=") + strlen(gid) >= MAX_LEN)
256 strcat(buf, ",gid=");
261 if(strlen(buf) + strlen(",fmask=") + strlen(fmask) >= MAX_LEN)
264 strcat(buf, ",fmask=");
269 if(strlen(buf) + strlen(",dmask=") + strlen(dmask) >= MAX_LEN)
272 strcat(buf, ",dmask=");
277 if(strlen(buf) + strlen(",channels=") + strlen(chan) >= MAX_LEN)
280 strcat(buf, ",channels=");
285 if(strlen(buf) + strlen(",") + strlen(options) >= MAX_LEN)
289 strcat(buf, options);
293 if(strlen(buf) + strlen(",own_fs") >= MAX_LEN)
296 strcat(buf, ",own_fs");
300 if(strlen(buf) + strlen(",quiet") >= MAX_LEN)
303 strcat(buf, ",quiet");
306 TRACE("cmd: %s\n", buf);
309 printf("executing command: %s\n", buf);
314 ERROR("options too long!\n");