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