fish.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  1. /* Virtual File System: FISH implementation for transfering files over
  2. shell connections.
  3. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
  4. 2007 Free Software Foundation, Inc.
  5. Written by: 1998 Pavel Machek
  6. Spaces fix: 2000 Michal Svec
  7. Derived from ftpfs.c.
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public License
  10. as published by the Free Software Foundation; either version 2 of
  11. the License, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU Library General Public License for more details.
  16. You should have received a copy of the GNU Library General Public
  17. License along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  19. /**
  20. * \file
  21. * \brief Source: Virtual File System: FISH implementation for transfering files over
  22. * shell connections
  23. * \author Pavel Machek
  24. * \author Michal Svec
  25. * \date 1998, 2000
  26. *
  27. * Derived from ftpfs.c
  28. * Read README.fish for protocol specification.
  29. *
  30. * Syntax of path is: \verbatim /#sh:user@host[:Cr]/path \endverbatim
  31. * where C means you want compressed connection,
  32. * and r means you want to use rsh
  33. *
  34. * Namespace: fish_vfs_ops exported.
  35. */
  36. /* Define this if your ssh can take -I option */
  37. #include <config.h>
  38. #include <errno.h>
  39. #include <fcntl.h>
  40. #include <pwd.h>
  41. #include <grp.h>
  42. #include <sys/time.h> /* gettimeofday() */
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include "lib/global.h"
  46. #include "lib/fs.h"
  47. #include "lib/tty/tty.h" /* enable/disable interrupt key */
  48. #include "lib/strescape.h"
  49. #include "lib/unixcompat.h"
  50. #include "src/wtools.h" /* message() */
  51. #include "src/main.h" /* print_vfs_message */
  52. #include "utilvfs.h"
  53. #include "xdirentry.h"
  54. #include "vfs.h"
  55. #include "vfs-impl.h"
  56. #include "gc.h" /* vfs_stamp_create */
  57. #include "netutil.h"
  58. #include "fish.h"
  59. int fish_directory_timeout = 900;
  60. #define DO_RESOLVE_SYMLINK 1
  61. #define DO_OPEN 2
  62. #define DO_FREE_RESOURCE 4
  63. #define FISH_FLAG_COMPRESSED 1
  64. #define FISH_FLAG_RSH 2
  65. #define OPT_FLUSH 1
  66. #define OPT_IGNORE_ERROR 2
  67. /*
  68. * Reply codes.
  69. */
  70. #define PRELIM 1 /* positive preliminary */
  71. #define COMPLETE 2 /* positive completion */
  72. #define CONTINUE 3 /* positive intermediate */
  73. #define TRANSIENT 4 /* transient negative completion */
  74. #define ERROR 5 /* permanent negative completion */
  75. /* command wait_flag: */
  76. #define NONE 0x00
  77. #define WAIT_REPLY 0x01
  78. #define WANT_STRING 0x02
  79. static char reply_str [80];
  80. static struct vfs_class vfs_fish_ops;
  81. static int
  82. fish_command (struct vfs_class *me, struct vfs_s_super *super,
  83. int wait_reply, const char *fmt, ...)
  84. __attribute__ ((format (__printf__, 4, 5)));
  85. static int fish_decode_reply (char *s, int was_garbage)
  86. {
  87. int code;
  88. if (!sscanf(s, "%d", &code)) {
  89. code = 500;
  90. return 5;
  91. }
  92. if (code<100) return was_garbage ? ERROR : (!code ? COMPLETE : PRELIM);
  93. return code / 100;
  94. }
  95. /* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
  96. static int fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
  97. {
  98. char answer[1024];
  99. int was_garbage = 0;
  100. for (;;) {
  101. if (!vfs_s_get_line(me, sock, answer, sizeof(answer), '\n')) {
  102. if (string_buf)
  103. *string_buf = 0;
  104. return 4;
  105. }
  106. if (strncmp(answer, "### ", 4)) {
  107. was_garbage = 1;
  108. if (string_buf)
  109. g_strlcpy(string_buf, answer, string_len);
  110. } else return fish_decode_reply(answer+4, was_garbage);
  111. }
  112. }
  113. #define SUP super->u.fish
  114. static int
  115. fish_command (struct vfs_class *me, struct vfs_s_super *super,
  116. int wait_reply, const char *fmt, ...)
  117. {
  118. va_list ap;
  119. char *str;
  120. int status;
  121. FILE *logfile = MEDATA->logfile;
  122. va_start (ap, fmt);
  123. str = g_strdup_vprintf (fmt, ap);
  124. va_end (ap);
  125. if (logfile) {
  126. fwrite (str, strlen (str), 1, logfile);
  127. fflush (logfile);
  128. }
  129. tty_enable_interrupt_key ();
  130. status = write (SUP.sockw, str, strlen (str));
  131. g_free (str);
  132. tty_disable_interrupt_key ();
  133. if (status < 0)
  134. return TRANSIENT;
  135. if (wait_reply)
  136. return fish_get_reply (me, SUP.sockr,
  137. (wait_reply & WANT_STRING) ? reply_str :
  138. NULL, sizeof (reply_str) - 1);
  139. return COMPLETE;
  140. }
  141. static void
  142. fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
  143. {
  144. if ((SUP.sockw != -1) || (SUP.sockr != -1)) {
  145. print_vfs_message (_("fish: Disconnecting from %s"),
  146. super->name ? super->name : "???");
  147. fish_command (me, super, NONE, "#BYE\nexit\n");
  148. close (SUP.sockw);
  149. close (SUP.sockr);
  150. SUP.sockw = SUP.sockr = -1;
  151. }
  152. g_free (SUP.host);
  153. g_free (SUP.user);
  154. g_free (SUP.cwdir);
  155. g_free (SUP.password);
  156. }
  157. static void
  158. fish_pipeopen(struct vfs_s_super *super, const char *path, const char *argv[])
  159. {
  160. int fileset1[2], fileset2[2];
  161. int res;
  162. if ((pipe(fileset1)<0) || (pipe(fileset2)<0))
  163. vfs_die("Cannot pipe(): %m.");
  164. if ((res = fork())) {
  165. if (res<0) vfs_die("Cannot fork(): %m.");
  166. /* We are the parent */
  167. close(fileset1[0]);
  168. SUP.sockw = fileset1[1];
  169. close(fileset2[1]);
  170. SUP.sockr = fileset2[0];
  171. } else {
  172. close(0);
  173. dup(fileset1[0]);
  174. close(fileset1[0]); close(fileset1[1]);
  175. close(1); close(2);
  176. dup(fileset2[1]);
  177. /* stderr to /dev/null */
  178. open ("/dev/null", O_WRONLY);
  179. close(fileset2[0]); close(fileset2[1]);
  180. execvp(path, const_cast(char **, argv));
  181. _exit(3);
  182. }
  183. }
  184. /* The returned directory should always contain a trailing slash */
  185. static char *fish_getcwd(struct vfs_class *me, struct vfs_s_super *super)
  186. {
  187. if (fish_command (me, super, WANT_STRING, "#PWD\npwd; echo '### 200'\n") == COMPLETE)
  188. return g_strconcat (reply_str, "/", (char *) NULL);
  189. ERRNOR (EIO, NULL);
  190. }
  191. static int
  192. fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
  193. {
  194. {
  195. char gbuf[10];
  196. const char *argv[10]; /* All of 10 is used now */
  197. const char *xsh = (SUP.flags == FISH_FLAG_RSH ? "rsh" : "ssh");
  198. int i = 0;
  199. argv[i++] = xsh;
  200. if (SUP.flags == FISH_FLAG_COMPRESSED)
  201. argv[i++] = "-C";
  202. if (SUP.flags > FISH_FLAG_RSH)
  203. {
  204. argv[i++] = "-p";
  205. g_snprintf (gbuf, sizeof (gbuf), "%d", SUP.flags);
  206. argv[i++] = gbuf;
  207. }
  208. /*
  209. * Add the user name to the ssh command line only if it was explicitly
  210. * set in vfs URL. rsh/ssh will get current user by default
  211. * plus we can set convenient overrides in ~/.ssh/config (explicit -l
  212. * option breaks it for some)
  213. */
  214. if (SUP.user) {
  215. argv[i++] = "-l";
  216. argv[i++] = SUP.user;
  217. }
  218. else
  219. {
  220. /* The rest of the code assumes it to be a valid username */
  221. SUP.user = vfs_get_local_username();
  222. }
  223. argv[i++] = SUP.host;
  224. argv[i++] = "echo FISH:; /bin/sh";
  225. argv[i++] = NULL;
  226. fish_pipeopen (super, xsh, argv);
  227. }
  228. {
  229. char answer[2048];
  230. print_vfs_message (_("fish: Waiting for initial line..."));
  231. if (!vfs_s_get_line (me, SUP.sockr, answer, sizeof (answer), ':'))
  232. ERRNOR (E_PROTO, -1);
  233. print_vfs_message ("%s", answer);
  234. if (strstr (answer, "assword")) {
  235. /* Currently, this does not work. ssh reads passwords from
  236. /dev/tty, not from stdin :-(. */
  237. message (D_ERROR, MSG_ERROR,
  238. _
  239. ("Sorry, we cannot do password authenticated connections for now."));
  240. ERRNOR (EPERM, -1);
  241. if (!SUP.password) {
  242. char *p, *op;
  243. p = g_strconcat (_(" fish: Password required for "),
  244. SUP.user, " ", (char *) NULL);
  245. op = vfs_get_password (p);
  246. g_free (p);
  247. if (op == NULL)
  248. ERRNOR (EPERM, -1);
  249. SUP.password = op;
  250. }
  251. print_vfs_message (_("fish: Sending password..."));
  252. write (SUP.sockw, SUP.password, strlen (SUP.password));
  253. write (SUP.sockw, "\n", 1);
  254. }
  255. }
  256. print_vfs_message (_("fish: Sending initial line..."));
  257. /*
  258. * Run `start_fish_server'. If it doesn't exist - no problem,
  259. * we'll talk directly to the shell.
  260. */
  261. if (fish_command
  262. (me, super, WAIT_REPLY,
  263. "#FISH\necho; start_fish_server 2>&1; echo '### 200'\n") !=
  264. COMPLETE)
  265. ERRNOR (E_PROTO, -1);
  266. print_vfs_message (_("fish: Handshaking version..."));
  267. if (fish_command
  268. (me, super, WAIT_REPLY,
  269. "#VER 0.0.0\necho '### 000'\n") != COMPLETE)
  270. ERRNOR (E_PROTO, -1);
  271. /* Set up remote locale to C, otherwise dates cannot be recognized */
  272. if (fish_command
  273. (me, super, WAIT_REPLY,
  274. "LANG=C; LC_ALL=C; LC_TIME=C\n"
  275. "export LANG; export LC_ALL; export LC_TIME\n" "echo '### 200'\n")
  276. != COMPLETE)
  277. ERRNOR (E_PROTO, -1);
  278. print_vfs_message (_("fish: Setting up current directory..."));
  279. SUP.cwdir = fish_getcwd (me, super);
  280. print_vfs_message (_("fish: Connected, home %s."), SUP.cwdir);
  281. #if 0
  282. super->name =
  283. g_strconcat ("/#sh:", SUP.user, "@", SUP.host, "/", (char *) NULL);
  284. #endif
  285. super->name = g_strdup (PATH_SEP_STR);
  286. super->root =
  287. vfs_s_new_inode (me, super,
  288. vfs_s_default_stat (me, S_IFDIR | 0755));
  289. return 0;
  290. }
  291. static int
  292. fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
  293. const char *archive_name, char *op)
  294. {
  295. char *host, *user, *password, *p;
  296. int flags;
  297. (void) archive_name;
  298. p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags,
  299. &password, 0, URL_NOSLASH | URL_USE_ANONYMOUS);
  300. g_free (p);
  301. SUP.host = host;
  302. SUP.user = user;
  303. SUP.flags = flags;
  304. if (!strncmp (op, "rsh:", 4))
  305. SUP.flags = FISH_FLAG_RSH;
  306. SUP.cwdir = NULL;
  307. if (password)
  308. SUP.password = password;
  309. return fish_open_archive_int (me, super);
  310. }
  311. static int
  312. fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
  313. const char *archive_name, char *op, void *cookie)
  314. {
  315. char *host, *user;
  316. int flags;
  317. int result;
  318. (void) me;
  319. (void) archive_name;
  320. (void) cookie;
  321. op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0,
  322. URL_NOSLASH | URL_USE_ANONYMOUS);
  323. g_free (op);
  324. if (user == NULL)
  325. user = vfs_get_local_username();
  326. result = ((strcmp (host, SUP.host) == 0)
  327. && (strcmp (user, SUP.user) == 0)
  328. && (flags == SUP.flags));
  329. g_free (host);
  330. g_free (user);
  331. return result;
  332. }
  333. static int
  334. fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
  335. {
  336. struct vfs_s_super *super = dir->super;
  337. char buffer[8192];
  338. struct vfs_s_entry *ent = NULL;
  339. FILE *logfile;
  340. char *quoted_path;
  341. int reply_code;
  342. gchar *shell_commands;
  343. #if 0
  344. /*
  345. * Simple FISH debug interface :]
  346. */
  347. if (!(MEDATA->logfile))
  348. {
  349. MEDATA->logfile = fopen("/tmp/mc-FISH.sh", "w");
  350. }
  351. #endif /* 0 */
  352. logfile = MEDATA->logfile;
  353. print_vfs_message(_("fish: Reading directory %s..."), remote_path);
  354. gettimeofday(&dir->timestamp, NULL);
  355. dir->timestamp.tv_sec += fish_directory_timeout;
  356. quoted_path = strutils_shell_escape (remote_path);
  357. shell_commands = g_strconcat(
  358. "#LIST /%s\n"
  359. "if `perl -v > /dev/null 2>&1` ; then\n"
  360. "perl -e '\n"
  361. "use strict;\n"
  362. "use POSIX;\n"
  363. "use Fcntl;\n"
  364. "use POSIX \":fcntl_h\"; #S_ISLNK was here until 5.6\n"
  365. "import Fcntl \":mode\" unless defined &S_ISLNK; #and is now here\n"
  366. "my $dirname = $ARGV[0];\n"
  367. "if (opendir ( DIR, $dirname )) {\n"
  368. "while( (my $filename = readdir(DIR))){\n"
  369. "my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat(\"$dirname/$filename\");\n"
  370. "my $mloctime= strftime(\"%%m-%%d-%%Y %%H:%%M\", localtime $mtime);\n"
  371. ,
  372. "my $strutils_shell_escape_regex= s/([;<>\\*\\|`&\\$!#\\(\\)\\[\\]\\{\\}:'\\''\"\\ \\\\])/\\\\$1/g;\n"
  373. "my $e_filename = $filename;\n"
  374. "$e_filename =~ $strutils_shell_escape_regex;\n"
  375. "if (S_ISLNK($mode) ) {\n"
  376. "my $linkname = readlink (\"$dirname/$filename\");\n"
  377. "$linkname =~ $strutils_shell_escape_regex;\n"
  378. "\n"
  379. "printf(\"R%%o %%o $uid.$gid\\n"
  380. "S$size\\n"
  381. "d$mloctime\\n"
  382. ":\\\"$e_filename\\\" -> \\\"$linkname\\\"\\n"
  383. "\\n\", S_IMODE($mode), S_IFMT($mode));\n"
  384. "} else {\n"
  385. "printf(\"R%%o %%o $uid.$gid\\n"
  386. "S$size\\n"
  387. "d$mloctime\\n"
  388. ":\\\"$e_filename\\\"\\n"
  389. "\\n\", S_IMODE($mode), S_IFMT($mode));\n"
  390. "}}\n"
  391. ,
  392. "printf(\"### 200\\n\");\n"
  393. "closedir(DIR);\n"
  394. "} else {\n"
  395. "printf(\"### 500\\n\");\n"
  396. "}\n"
  397. "exit 0\n"
  398. "' /%s ||\n" /* ARGV[0] - path to browse */
  399. " echo '### 500'\n" /* do not hang if perl is to eval it */
  400. "elif `ls -1 /%s >/dev/null 2>&1` ; then\n"
  401. "if `ls -Q /%s >/dev/null 2>&1`; then\n"
  402. "LSOPT=\"-Qlan\";\n"
  403. "ADD=0;\n"
  404. "else\n"
  405. "LSOPT=\"-lan\";\n"
  406. "ADD=1;\n"
  407. "fi\n"
  408. "ls $LSOPT /%s 2>/dev/null | grep '^[^cbt]' | (\n"
  409. "while read p l u g s m d y n n2 n3; do\n"
  410. "if test \"$m\" = \"0\" ; then \n"
  411. "s=$d; m=$y; d=$n y=$n2; n=$n3\n"
  412. "else\n"
  413. "n=$n\" \"$n2\" \"$n3\n"
  414. "fi\n"
  415. "if [ $ADD = 0 ]; then\n"
  416. "echo \"P$p $u.$g\nS$s\nd$m $d $y\n:$n\n\"\n"
  417. "elif `sed --version >/dev/null 2>&1` ; then\n"
  418. "file=`echo $n | sed -e 's#^\\(.*\\) -> \\(.*\\)#\\1\" -> \"\\2#'`\n"
  419. ,
  420. "echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$file\"\n\"\n"
  421. "else\n"
  422. "echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$n\"\n\"\n"
  423. "fi\n"
  424. "done )\n"
  425. "ls $LSOPT /%s 2>/dev/null | grep '^[cb]' | (\n"
  426. "while read p l u g a i m d y n n2 n3; do\n"
  427. "if test \"$a\" = \"0\" ; then \n"
  428. "a=$m; i=$d; m=$y; d=$n y=$n2; n=$n3\n"
  429. "else\n"
  430. "n=$n\" \"$n2\" \"$n3\n"
  431. "fi\n"
  432. "if [ $ADD = 0 ]; then\n"
  433. "echo \"P$p $u.$g\nE$a$i\nd$m $d $y\n:$n\n\"\n"
  434. "elif `sed --version >/dev/null 2>&1` ; then\n"
  435. "file=`echo $n | sed -e 's#^\\(.*\\) -> \\(.*\\)#\\1\" -> \"\\2#'`\n"
  436. "echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$file\"\n\"\n"
  437. "else\n"
  438. "echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$n\"\n\"\n"
  439. "fi\n"
  440. "done)\n"
  441. "echo '### 200'\n"
  442. "else\n"
  443. "echo '### 500'\n"
  444. "fi\n"
  445. , (char *) NULL
  446. );
  447. fish_command (me, super, NONE, shell_commands,
  448. quoted_path, quoted_path, quoted_path, quoted_path, quoted_path, quoted_path);
  449. g_free(shell_commands);
  450. g_free (quoted_path);
  451. ent = vfs_s_generate_entry(me, NULL, dir, 0);
  452. while (1) {
  453. int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr);
  454. if ((!res) || (res == EINTR)) {
  455. vfs_s_free_entry(me, ent);
  456. me->verrno = ECONNRESET;
  457. goto error;
  458. }
  459. if (logfile) {
  460. fputs (buffer, logfile);
  461. fputs ("\n", logfile);
  462. fflush (logfile);
  463. }
  464. if (!strncmp(buffer, "### ", 4))
  465. break;
  466. if ((!buffer[0])) {
  467. if (ent->name) {
  468. vfs_s_insert_entry(me, dir, ent);
  469. ent = vfs_s_generate_entry(me, NULL, dir, 0);
  470. }
  471. continue;
  472. }
  473. #define ST ent->ino->st
  474. switch(buffer[0]) {
  475. case ':': {
  476. char *temp;
  477. char *data_start = buffer+1;
  478. char *filename = data_start;
  479. char *linkname = data_start;
  480. char *filename_bound = filename + strlen(filename);
  481. char *linkname_bound = filename_bound;
  482. if (!strcmp(data_start, "\".\"") || !strcmp(data_start, "\"..\""))
  483. break; /* We'll do "." and ".." ourselves */
  484. if (S_ISLNK(ST.st_mode)) {
  485. /* we expect: "escaped-name" -> "escaped-name"
  486. // -> cannot occur in filenames,
  487. // because it will be escaped to -\> */
  488. if (*filename == '"')
  489. ++filename;
  490. linkname = strstr(filename, "\" -> \"");
  491. if (!linkname)
  492. {
  493. /* broken client, or smth goes wrong */
  494. linkname = filename_bound;
  495. if (filename_bound > filename
  496. && *(filename_bound - 1) == '"')
  497. --filename_bound; /* skip trailing " */
  498. }
  499. else
  500. {
  501. filename_bound = linkname;
  502. linkname += 6; /* strlen ("\" -> \"") */
  503. if (*(linkname_bound - 1) == '"')
  504. --linkname_bound; /* skip trailing " */
  505. }
  506. ent->name = str_dup_range(filename, filename_bound);
  507. temp = ent->name;
  508. ent->name = strutils_shell_unescape(ent->name);
  509. g_free(temp);
  510. ent->ino->linkname = str_dup_range(linkname, linkname_bound);
  511. temp = ent->ino->linkname;
  512. ent->ino->linkname = strutils_shell_unescape(ent->ino->linkname);
  513. g_free(temp);
  514. } else {
  515. /* we expect: "escaped-name" */
  516. if (filename_bound - filename > 2)
  517. {
  518. /*
  519. there is at least 2 "
  520. and we skip them
  521. */
  522. if (*filename == '"')
  523. ++filename;
  524. if (*(filename_bound - 1) == '"')
  525. --filename_bound;
  526. }
  527. ent->name = str_dup_range(filename, filename_bound);
  528. temp = ent->name;
  529. ent->name = strutils_shell_unescape(ent->name);
  530. g_free(temp);
  531. }
  532. break;
  533. }
  534. case 'S':
  535. #ifdef HAVE_ATOLL
  536. ST.st_size = (off_t) atoll (buffer+1);
  537. #else
  538. ST.st_size = (off_t) atof (buffer+1);
  539. #endif
  540. break;
  541. case 'P': {
  542. size_t skipped;
  543. vfs_parse_filemode (buffer + 1, &skipped, &ST.st_mode);
  544. break;
  545. }
  546. case 'R': {
  547. /*
  548. raw filemode:
  549. we expect: Roctal-filemode octal-filetype uid.gid
  550. */
  551. size_t skipped;
  552. vfs_parse_raw_filemode (buffer + 1, &skipped, &ST.st_mode);
  553. break;
  554. }
  555. case 'd': {
  556. vfs_split_text(buffer+1);
  557. if (!vfs_parse_filedate(0, &ST.st_ctime))
  558. break;
  559. ST.st_atime = ST.st_mtime = ST.st_ctime;
  560. }
  561. break;
  562. case 'D': {
  563. struct tm tim;
  564. if (sscanf(buffer+1, "%d %d %d %d %d %d", &tim.tm_year, &tim.tm_mon,
  565. &tim.tm_mday, &tim.tm_hour, &tim.tm_min, &tim.tm_sec) != 6)
  566. break;
  567. ST.st_atime = ST.st_mtime = ST.st_ctime = mktime(&tim);
  568. }
  569. break;
  570. case 'E': {
  571. int maj, min;
  572. if (sscanf(buffer+1, "%d,%d", &maj, &min) != 2)
  573. break;
  574. #ifdef HAVE_STRUCT_STAT_ST_RDEV
  575. ST.st_rdev = makedev (maj, min);
  576. #endif
  577. }
  578. }
  579. }
  580. vfs_s_free_entry (me, ent);
  581. reply_code = fish_decode_reply(buffer + 4, 0);
  582. if (reply_code == COMPLETE) {
  583. g_free (SUP.cwdir);
  584. SUP.cwdir = g_strdup (remote_path);
  585. print_vfs_message (_("%s: done."), me->name);
  586. return 0;
  587. } else if (reply_code == ERROR) {
  588. me->verrno = EACCES;
  589. } else {
  590. me->verrno = E_REMOTE;
  591. }
  592. error:
  593. print_vfs_message (_("%s: failure"), me->name);
  594. return -1;
  595. }
  596. static int
  597. fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
  598. {
  599. struct vfs_s_super *super = FH_SUPER;
  600. int n, total;
  601. char buffer[8192];
  602. struct stat s;
  603. int was_error = 0;
  604. int h;
  605. char *quoted_name;
  606. h = open (localname, O_RDONLY);
  607. if (h == -1)
  608. ERRNOR (EIO, -1);
  609. if (fstat(h, &s)<0) {
  610. close (h);
  611. ERRNOR (EIO, -1);
  612. }
  613. /* First, try this as stor:
  614. *
  615. * ( head -c number ) | ( cat > file; cat >/dev/null )
  616. *
  617. * If `head' is not present on the remote system, `dd' will be used.
  618. * Unfortunately, we cannot trust most non-GNU `head' implementations
  619. * even if `-c' options is supported. Therefore, we separate GNU head
  620. * (and other modern heads?) using `-q' and `-' . This causes another
  621. * implementations to fail (because of "incorrect options").
  622. *
  623. * Fallback is:
  624. *
  625. * rest=<number>
  626. * while [ $rest -gt 0 ]
  627. * do
  628. * cnt=`expr \( $rest + 255 \) / 256`
  629. * n=`dd bs=256 count=$cnt | tee -a <target_file> | wc -c`
  630. * rest=`expr $rest - $n`
  631. * done
  632. *
  633. * `dd' was not designed for full filling of input buffers,
  634. * and does not report exact number of bytes (not blocks).
  635. * Therefore a more complex shell script is needed.
  636. *
  637. * On some systems non-GNU head writes "Usage:" error report to stdout
  638. * instead of stderr. It makes impossible the use of "head || dd"
  639. * algorithm for file appending case, therefore just "dd" is used for it.
  640. */
  641. quoted_name = strutils_shell_escape(name);
  642. print_vfs_message(_("fish: store %s: sending command..."), quoted_name );
  643. /* FIXME: File size is limited to ULONG_MAX */
  644. if (!fh->u.fish.append)
  645. n = fish_command (me, super, WAIT_REPLY,
  646. "#STOR %lu /%s\n"
  647. "echo '### 001'\n"
  648. "file=/%s\n"
  649. "res=`exec 3>&1\n"
  650. "(\n"
  651. "head -c %lu -q - || echo DD >&3\n"
  652. ") 2>/dev/null | (\n"
  653. "cat > $file\n"
  654. "cat > /dev/null\n"
  655. ")`; [ \"$res\" = DD ] && {\n"
  656. "> \"$file\"\n"
  657. "rest=%lu\n"
  658. "while [ $rest -gt 0 ]\n"
  659. "do\n"
  660. " cnt=`expr \\( $rest + 255 \\) / 256`\n"
  661. " n=`dd bs=256 count=$cnt | tee -a \"$file\" | wc -c`\n"
  662. " rest=`expr $rest - $n`\n"
  663. "done\n"
  664. "}; echo '### 200'\n",
  665. (unsigned long) s.st_size, quoted_name,
  666. quoted_name, (unsigned long) s.st_size,
  667. (unsigned long) s.st_size);
  668. else
  669. n = fish_command (me, super, WAIT_REPLY,
  670. "#STOR %lu /%s\n"
  671. "echo '### 001'\n"
  672. "{\n"
  673. "file=/%s\n"
  674. "rest=%lu\n"
  675. "while [ $rest -gt 0 ]\n"
  676. "do\n"
  677. " cnt=`expr \\( $rest + 255 \\) / 256`\n"
  678. " n=`dd bs=256 count=$cnt | tee -a $file | wc -c`\n"
  679. " rest=`expr $rest - $n`\n"
  680. "done\n"
  681. "}; echo '### 200'\n",
  682. (unsigned long) s.st_size, quoted_name,
  683. quoted_name, (unsigned long) s.st_size);
  684. if (n != PRELIM) {
  685. close (h);
  686. ERRNOR(E_REMOTE, -1);
  687. }
  688. total = 0;
  689. while (1) {
  690. int t;
  691. while ((n = read(h, buffer, sizeof(buffer))) < 0) {
  692. if ((errno == EINTR) && tty_got_interrupt ())
  693. continue;
  694. print_vfs_message(_("fish: Local read failed, sending zeros") );
  695. close(h);
  696. h = open( "/dev/zero", O_RDONLY );
  697. }
  698. if (n == 0)
  699. break;
  700. if ((t = write (SUP.sockw, buffer, n)) != n) {
  701. if (t == -1) {
  702. me->verrno = errno;
  703. } else {
  704. me->verrno = EIO;
  705. }
  706. goto error_return;
  707. }
  708. tty_disable_interrupt_key ();
  709. total += n;
  710. print_vfs_message(_("fish: storing %s %d (%lu)"),
  711. was_error ? _("zeros") : _("file"), total,
  712. (unsigned long) s.st_size);
  713. }
  714. close(h);
  715. g_free(quoted_name);
  716. if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error)
  717. ERRNOR (E_REMOTE, -1);
  718. return 0;
  719. error_return:
  720. close(h);
  721. fish_get_reply(me, SUP.sockr, NULL, 0);
  722. g_free(quoted_name);
  723. return -1;
  724. }
  725. static int
  726. fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
  727. {
  728. char *name;
  729. char *quoted_name;
  730. if (offset)
  731. ERRNOR (E_NOTSUPP, 0);
  732. name = vfs_s_fullpath (me, fh->ino);
  733. if (!name)
  734. return 0;
  735. quoted_name = strutils_shell_escape(name);
  736. fh->u.fish.append = 0;
  737. /*
  738. * Check whether the remote file is readable by using `dd' to copy
  739. * a single byte from the remote file to /dev/null. If `dd' completes
  740. * with exit status of 0 use `cat' to send the file contents to the
  741. * standard output (i.e. over the network).
  742. */
  743. offset = fish_command (me, FH_SUPER, WANT_STRING,
  744. "#RETR /%s\n"
  745. "if dd if=/%s of=/dev/null bs=1 count=1 2>/dev/null ;\n"
  746. "then\n"
  747. "ls -ln /%s 2>/dev/null | (\n"
  748. "read p l u g s r\n"
  749. "echo $s\n"
  750. ")\n"
  751. "echo '### 100'\n"
  752. "cat /%s\n"
  753. "echo '### 200'\n"
  754. "else\n"
  755. "echo '### 500'\n"
  756. "fi\n",
  757. quoted_name, quoted_name, quoted_name, quoted_name );
  758. g_free (quoted_name);
  759. if (offset != PRELIM) ERRNOR (E_REMOTE, 0);
  760. fh->linear = LS_LINEAR_OPEN;
  761. fh->u.fish.got = 0;
  762. errno = 0;
  763. #if SIZEOF_OFF_T == SIZEOF_LONG
  764. fh->u.fish.total = strtol (reply_str, NULL, 10);
  765. #else
  766. fh->u.fish.total = strtoll (reply_str, NULL, 10);
  767. #endif
  768. if (errno != 0)
  769. ERRNOR (E_REMOTE, 0);
  770. return 1;
  771. }
  772. static void
  773. fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
  774. {
  775. struct vfs_s_super *super = FH_SUPER;
  776. char buffer[8192];
  777. int n;
  778. print_vfs_message( _("Aborting transfer...") );
  779. do {
  780. n = MIN(8192, fh->u.fish.total - fh->u.fish.got);
  781. if (n) {
  782. if ((n = read(SUP.sockr, buffer, n)) < 0)
  783. return;
  784. fh->u.fish.got += n;
  785. }
  786. } while (n);
  787. if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)
  788. print_vfs_message( _("Error reported after abort.") );
  789. else
  790. print_vfs_message( _("Aborted transfer would be successful.") );
  791. }
  792. static int
  793. fish_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, int len)
  794. {
  795. struct vfs_s_super *super = FH_SUPER;
  796. int n = 0;
  797. len = MIN( fh->u.fish.total - fh->u.fish.got, len );
  798. tty_disable_interrupt_key ();
  799. while (len && ((n = read (SUP.sockr, buf, len))<0)) {
  800. if ((errno == EINTR) && !tty_got_interrupt ())
  801. continue;
  802. break;
  803. }
  804. tty_enable_interrupt_key();
  805. if (n>0) fh->u.fish.got += n;
  806. if (n<0) fish_linear_abort(me, fh);
  807. if ((!n) && ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)))
  808. ERRNOR (E_REMOTE, -1);
  809. ERRNOR (errno, n);
  810. }
  811. static void
  812. fish_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
  813. {
  814. if (fh->u.fish.total != fh->u.fish.got)
  815. fish_linear_abort(me, fh);
  816. }
  817. static int
  818. fish_ctl (void *fh, int ctlop, void *arg)
  819. {
  820. (void) arg;
  821. (void) fh;
  822. (void) ctlop;
  823. return 0;
  824. #if 0
  825. switch (ctlop) {
  826. case VFS_CTL_IS_NOTREADY:
  827. {
  828. int v;
  829. if (!FH->linear)
  830. vfs_die ("You may not do this");
  831. if (FH->linear == LS_LINEAR_CLOSED || FH->linear == LS_LINEAR_PREOPEN)
  832. return 0;
  833. v = vfs_s_select_on_two (FH_SUPER->u.fish.sockr, 0);
  834. if (((v < 0) && (errno == EINTR)) || v == 0)
  835. return 1;
  836. return 0;
  837. }
  838. default:
  839. return 0;
  840. }
  841. #endif
  842. }
  843. static int
  844. fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *cmd, int flags)
  845. {
  846. int r;
  847. r = fish_command (me, super, WAIT_REPLY, "%s", cmd);
  848. vfs_stamp_create (&vfs_fish_ops, super);
  849. if (r != COMPLETE) ERRNOR (E_REMOTE, -1);
  850. if (flags & OPT_FLUSH)
  851. vfs_s_invalidate(me, super);
  852. return 0;
  853. }
  854. #define PREFIX \
  855. char buf[BUF_LARGE]; \
  856. const char *crpath; \
  857. char *rpath, *mpath = g_strdup (path); \
  858. struct vfs_s_super *super; \
  859. if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \
  860. g_free (mpath); \
  861. return -1; \
  862. } \
  863. rpath = strutils_shell_escape(crpath); \
  864. g_free (mpath);
  865. #define POSTFIX(flags) \
  866. g_free (rpath); \
  867. return fish_send_command(me, super, buf, flags);
  868. static int
  869. fish_chmod (struct vfs_class *me, const char *path, int mode)
  870. {
  871. PREFIX
  872. g_snprintf(buf, sizeof(buf), "#CHMOD %4.4o /%s\n"
  873. "if chmod %4.4o /%s 2>/dev/null; then\n"
  874. "echo '### 000'\n"
  875. "else\n"
  876. "echo '### 500'\n"
  877. "fi\n",
  878. mode & 07777, rpath,
  879. mode & 07777, rpath);
  880. POSTFIX(OPT_FLUSH);
  881. }
  882. #define FISH_OP(name, string) \
  883. static int fish_##name (struct vfs_class *me, const char *path1, const char *path2) \
  884. { \
  885. char buf[BUF_LARGE]; \
  886. const char *crpath1, *crpath2; \
  887. char *rpath1, *rpath2, *mpath1, *mpath2; \
  888. struct vfs_s_super *super1, *super2; \
  889. if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) { \
  890. g_free (mpath1); \
  891. return -1; \
  892. } \
  893. if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) { \
  894. g_free (mpath1); \
  895. g_free (mpath2); \
  896. return -1; \
  897. } \
  898. rpath1 = strutils_shell_escape (crpath1); \
  899. g_free (mpath1); \
  900. rpath2 = strutils_shell_escape (crpath2); \
  901. g_free (mpath2); \
  902. g_snprintf(buf, sizeof(buf), string "\n", rpath1, rpath2, rpath1, rpath2); \
  903. g_free (rpath1); \
  904. g_free (rpath2); \
  905. return fish_send_command(me, super2, buf, OPT_FLUSH); \
  906. }
  907. FISH_OP(rename, "#RENAME /%s /%s\n"
  908. "if mv /%s /%s 2>/dev/null; then\n"
  909. "echo '### 000'\n"
  910. "else\n"
  911. "echo '### 500'\n"
  912. "fi\n")
  913. FISH_OP(link, "#LINK /%s /%s\n"
  914. "if ln /%s /%s 2>/dev/null; then\n"
  915. "echo '### 000'\n"
  916. "else\n"
  917. "echo '### 500'\n"
  918. "fi\n")
  919. static int fish_symlink (struct vfs_class *me, const char *setto, const char *path)
  920. {
  921. char *qsetto;
  922. PREFIX
  923. qsetto = strutils_shell_escape (setto);
  924. g_snprintf(buf, sizeof(buf),
  925. "#SYMLINK %s /%s\n"
  926. "if ln -s %s /%s 2>/dev/null; then\n"
  927. "echo '### 000'\n"
  928. "else\n"
  929. "echo '### 500'\n"
  930. "fi\n",
  931. qsetto, rpath, qsetto, rpath);
  932. g_free (qsetto);
  933. POSTFIX(OPT_FLUSH);
  934. }
  935. static int
  936. fish_chown (struct vfs_class *me, const char *path, int owner, int group)
  937. {
  938. char *sowner, *sgroup;
  939. struct passwd *pw;
  940. struct group *gr;
  941. if ((pw = getpwuid (owner)) == NULL)
  942. return 0;
  943. if ((gr = getgrgid (group)) == NULL)
  944. return 0;
  945. sowner = pw->pw_name;
  946. sgroup = gr->gr_name;
  947. {
  948. PREFIX
  949. g_snprintf (buf, sizeof(buf),
  950. "#CHOWN %s:%s /%s\n"
  951. "if chown %s:%s /%s 2>/dev/null; then\n"
  952. "echo '### 000'\n"
  953. "else\n"
  954. "echo '### 500'\n"
  955. "fi\n",
  956. sowner, sgroup, rpath,
  957. sowner, sgroup, rpath);
  958. fish_send_command (me, super, buf, OPT_FLUSH);
  959. /* FIXME: what should we report if chgrp succeeds but chown fails? */
  960. /* fish_send_command(me, super, buf, OPT_FLUSH); */
  961. POSTFIX (OPT_FLUSH)
  962. }
  963. }
  964. static int fish_unlink (struct vfs_class *me, const char *path)
  965. {
  966. PREFIX
  967. g_snprintf(buf, sizeof(buf),
  968. "#DELE /%s\n"
  969. "if rm -f /%s 2>/dev/null; then\n"
  970. "echo '### 000'\n"
  971. "else\n"
  972. "echo '### 500'\n"
  973. "fi\n",
  974. rpath, rpath);
  975. POSTFIX(OPT_FLUSH);
  976. }
  977. static int fish_exists (struct vfs_class *me, const char *path)
  978. {
  979. PREFIX
  980. g_snprintf(buf, sizeof(buf),
  981. "#ISEXISTS /%s\n"
  982. "ls -l /%s >/dev/null 2>/dev/null\n"
  983. "echo '### '$?\n",
  984. rpath, rpath);
  985. g_free (rpath);
  986. if ( fish_send_command(me, super, buf, OPT_FLUSH) == 0 )
  987. return 1;
  988. return 0;
  989. }
  990. static int fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
  991. {
  992. int ret_code;
  993. PREFIX
  994. (void) mode;
  995. g_snprintf(buf, sizeof(buf),
  996. "#MKD /%s\n"
  997. "if mkdir /%s 2>/dev/null; then\n"
  998. "echo '### 000'\n"
  999. "else\n"
  1000. "echo '### 500'\n"
  1001. "fi\n",
  1002. rpath, rpath);
  1003. g_free (rpath);
  1004. ret_code = fish_send_command(me, super, buf, OPT_FLUSH);
  1005. if ( ret_code != 0 )
  1006. return ret_code;
  1007. if ( ! fish_exists (me, path) ){
  1008. ERRNOR (EACCES, -1);
  1009. }
  1010. return 0;
  1011. }
  1012. static int fish_rmdir (struct vfs_class *me, const char *path)
  1013. {
  1014. PREFIX
  1015. g_snprintf(buf, sizeof(buf),
  1016. "#RMD /%s\n"
  1017. "if rmdir /%s 2>/dev/null; then\n"
  1018. "echo '### 000'\n"
  1019. "else\n"
  1020. "echo '### 500'\n"
  1021. "fi\n",
  1022. rpath, rpath);
  1023. POSTFIX(OPT_FLUSH);
  1024. }
  1025. static int
  1026. fish_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags,
  1027. int mode)
  1028. {
  1029. (void) mode;
  1030. fh->u.fish.append = 0;
  1031. /* File will be written only, so no need to retrieve it */
  1032. if (((flags & O_WRONLY) == O_WRONLY) && !(flags & (O_RDONLY | O_RDWR))) {
  1033. fh->u.fish.append = flags & O_APPEND;
  1034. if (!fh->ino->localname) {
  1035. int tmp_handle =
  1036. vfs_mkstemps (&fh->ino->localname, me->name,
  1037. fh->ino->ent->name);
  1038. if (tmp_handle == -1)
  1039. return -1;
  1040. close (tmp_handle);
  1041. }
  1042. return 0;
  1043. }
  1044. if (!fh->ino->localname)
  1045. if (vfs_s_retrieve_file (me, fh->ino) == -1)
  1046. return -1;
  1047. if (!fh->ino->localname)
  1048. vfs_die ("retrieve_file failed to fill in localname");
  1049. return 0;
  1050. }
  1051. static void
  1052. fish_fill_names (struct vfs_class *me, fill_names_f func)
  1053. {
  1054. struct vfs_s_super *super = MEDATA->supers;
  1055. char *name;
  1056. char gbuf[10];
  1057. while (super)
  1058. {
  1059. const char *flags = "";
  1060. switch (SUP.flags)
  1061. {
  1062. case FISH_FLAG_RSH:
  1063. flags = ":r";
  1064. break;
  1065. case FISH_FLAG_COMPRESSED:
  1066. flags = ":C";
  1067. break;
  1068. default:
  1069. if (SUP.flags > FISH_FLAG_RSH)
  1070. {
  1071. break;
  1072. g_snprintf (gbuf, sizeof (gbuf), ":%d", SUP.flags);
  1073. flags = gbuf;
  1074. }
  1075. break;
  1076. }
  1077. name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, flags,
  1078. "/", SUP.cwdir, (char *) NULL);
  1079. (*func)(name);
  1080. g_free (name);
  1081. super = super->next;
  1082. }
  1083. }
  1084. static void *
  1085. fish_open (struct vfs_class *me, const char *file, int flags, int mode)
  1086. {
  1087. /*
  1088. sorry, i've places hack here
  1089. cause fish don't able to open files with O_EXCL flag
  1090. */
  1091. flags &= ~O_EXCL;
  1092. return vfs_s_open (me, file, flags, mode);
  1093. }
  1094. void
  1095. init_fish (void)
  1096. {
  1097. static struct vfs_s_subclass fish_subclass;
  1098. tcp_init();
  1099. fish_subclass.flags = VFS_S_REMOTE;
  1100. fish_subclass.archive_same = fish_archive_same;
  1101. fish_subclass.open_archive = fish_open_archive;
  1102. fish_subclass.free_archive = fish_free_archive;
  1103. fish_subclass.fh_open = fish_fh_open;
  1104. fish_subclass.dir_load = fish_dir_load;
  1105. fish_subclass.file_store = fish_file_store;
  1106. fish_subclass.linear_start = fish_linear_start;
  1107. fish_subclass.linear_read = fish_linear_read;
  1108. fish_subclass.linear_close = fish_linear_close;
  1109. vfs_s_init_class (&vfs_fish_ops, &fish_subclass);
  1110. vfs_fish_ops.name = "fish";
  1111. vfs_fish_ops.prefix = "sh:";
  1112. vfs_fish_ops.fill_names = fish_fill_names;
  1113. vfs_fish_ops.chmod = fish_chmod;
  1114. vfs_fish_ops.chown = fish_chown;
  1115. vfs_fish_ops.open = fish_open;
  1116. vfs_fish_ops.symlink = fish_symlink;
  1117. vfs_fish_ops.link = fish_link;
  1118. vfs_fish_ops.unlink = fish_unlink;
  1119. vfs_fish_ops.rename = fish_rename;
  1120. vfs_fish_ops.mkdir = fish_mkdir;
  1121. vfs_fish_ops.rmdir = fish_rmdir;
  1122. vfs_fish_ops.ctl = fish_ctl;
  1123. vfs_register_class (&vfs_fish_ops);
  1124. }