4 Copyright (C) 2006-2009 Jonathan Zarate
10 #include <sys/mount.h>
12 #include <sys/statfs.h>
14 #define MNT_DETACH 0x00000002
20 xstart("mount-cifs", "-m");
25 killall("mount-cifs", SIGTERM
);
26 eval("mount-cifs", "-u");
29 int mount_cifs_main(int argc
, char *argv
[])
37 char *on
, *unc
, *user
, *pass
, *dom
, *exec
, *servern
, *sec
, *custom
;
42 if (strcmp(argv
[1], "-m") == 0) {
48 for (i
= 1; i
<= 2; ++i
) {
49 if (done
[i
]) continue;
53 sprintf(s
, "cifs%d", i
);
54 strlcpy(s
, nvram_safe_get(s
), sizeof(s
));
55 if ((vstrsep(s
, "<", &on
, &unc
, &user
, &pass
, &dom
, &exec
, &servern
, &sec
) != 8) || (*on
!= '1')) continue;
56 custom
= nvram_safe_get("cifs_opts");
61 notice_set("cifs", "Mounting...");
64 if (nvram_get_int("cifs_dbg") > 0) {
65 f_write_string("/proc/fs/cifs/cifsFYI", nvram_safe_get("cifs_dbg"), 0, 0);
69 j
= sprintf(opt
, "sep=<unc=%s", unc
);
70 if (*user
) j
+= sprintf(opt
+ j
, "<user=%s", user
);
71 if (*pass
) j
+= sprintf(opt
+ j
, "<pass=%s", pass
);
72 if (*dom
) j
+= sprintf(opt
+ j
, "<dom=%s", dom
);
73 if (*servern
) j
+= sprintf(opt
+ j
, "<servern=%s", servern
);
74 if (*sec
) j
+= sprintf(opt
+ j
, "<sec=%s", sec
);
75 if (*custom
) j
+= sprintf(opt
+ j
, "<%s", custom
);
77 sprintf(mpath
, "/cifs%d", i
);
79 if (mount("-", mpath
, "cifs", MS_NOATIME
|MS_NODIRATIME
, opt
) != 0) continue;
81 if (try > 12) try = 12; // 1 min
87 run_userfile(mpath
, ".autorun", mpath
, 3);
89 if ((done
[1]) && (done
[2])) {
90 notice_set("cifs", "");
95 if (try == 24) { // 2 min
96 sprintf(s
, "Error mounting CIFS #%s. Still trying... ", (done
[1] == done
[2]) ? "1 and #2" : ((done
[1] == 0) ? "1" : "2"));
97 notice_set("cifs", s
);
99 else if (try > 180) { // 15 mins
106 if (strcmp(argv
[1], "-u") == 0) {
107 for (i
= 1; i
<= 2; ++i
) {
108 sprintf(mpath
, "/cifs%d", i
);
109 if ((statfs(mpath
, &sf
) == 0) && (sf
.f_type
!= 0x73717368)) {
111 run_userfile(mpath
, ".autostop", mpath
, 5);
112 run_nvscript("script_autostop", mpath
, 5);
114 umount2(mpath
, MNT_DETACH
);
117 notice_set("cifs", "");
122 usage_exit(argv
[0], "-m|-u");