4 Copyright (C) 2006-2009 Jonathan Zarate
10 #include <sys/mount.h>
16 xstart("mount-cifs", "-m");
21 killall("mount-cifs", SIGTERM
);
22 eval("mount-cifs", "-u");
25 int mount_cifs_main(int argc
, char *argv
[])
33 char *on
, *unc
, *user
, *pass
, *dom
, *exec
;
39 if (strcmp(argv
[1], "-m") == 0) {
45 for (i
= 1; i
<= 2; ++i
) {
46 if (done
[i
]) continue;
50 sprintf(s
, "cifs%d", i
);
51 strlcpy(s
, nvram_safe_get(s
), sizeof(s
));
52 if ((vstrsep(s
, "<", &on
, &unc
, &user
, &pass
, &dom
, &exec
) != 6) || (*on
!= '1')) continue;
57 notice_set("cifs", "Mounting...");
62 j
= sprintf(opt
, "sep=<unc=%s", unc
);
63 if (*user
) j
+= sprintf(opt
+ j
, "<user=%s", user
);
64 if (*pass
) j
+= sprintf(opt
+ j
, "<pass=%s", pass
);
65 if (*dom
) j
+= sprintf(opt
+ j
, "<dom=%s", dom
);
67 sprintf(mpath
, "/cifs%d", i
);
69 if (mount("-", mpath
, "cifs", MS_NOATIME
|MS_NODIRATIME
, opt
) != 0) continue;
71 if (try > 12) try = 12; // 1 min
77 _eval(exargv
, NULL
, 0, &pid
);
80 if ((done
[1]) && (done
[2])) {
81 notice_set("cifs", "");
86 if (try == 24) { // 2 min
87 sprintf(s
, "Error mounting CIFS #%s. Still trying... ", (done
[1] == done
[2]) ? "1 and #2" : ((done
[1] == 0) ? "1" : "2"));
88 notice_set("cifs", s
);
90 else if (try > 180) { // 15 mins
97 if (strcmp(argv
[1], "-u") == 0) {
98 for (i
= 1; i
<= 2; ++i
) {
99 sprintf(mpath
, "/cifs%d", i
);
103 notice_set("cifs", "");
108 usage_exit(argv
[0], "-m|-u");