extfs.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. /* Virtual File System: External file system.
  2. Copyright (C) 1995 The Free Software Foundation
  3. Written by: 1995 Jakub Jelinek
  4. Rewritten by: 1998 Pavel Machek
  5. Additional changes by: 1999 Andrew T. Veliath
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public License
  8. as published by the Free Software Foundation; either version 2 of
  9. the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  17. /* Namespace: init_extfs */
  18. #include <config.h>
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <unistd.h>
  26. #include <signal.h>
  27. #ifdef HAVE_SYS_WAIT_H
  28. #include <sys/wait.h>
  29. #endif
  30. #include <errno.h>
  31. #include "../src/global.h"
  32. #include "../src/tty.h" /* enable/disable interrupt key */
  33. #include "../src/wtools.h" /* message() */
  34. #include "../src/main.h" /* print_vfs_message */
  35. #include "utilvfs.h"
  36. #include "../src/execute.h" /* For shell_execute */
  37. #include "vfs.h"
  38. #include "vfs-impl.h"
  39. #include "gc.h" /* vfs_rmstamp */
  40. #undef ERRNOR
  41. #define ERRNOR(x,y) do { my_errno = x; return y; } while(0)
  42. struct inode {
  43. nlink_t nlink;
  44. struct entry *first_in_subdir; /* only used if this is a directory */
  45. struct entry *last_in_subdir;
  46. ino_t inode; /* This is inode # */
  47. dev_t dev; /* This is an internal identification of the extfs archive */
  48. struct archive *archive; /* And this is an archive structure */
  49. dev_t rdev;
  50. mode_t mode;
  51. uid_t uid;
  52. gid_t gid;
  53. off_t size;
  54. time_t mtime;
  55. char *linkname;
  56. time_t atime;
  57. time_t ctime;
  58. char *local_filename;
  59. };
  60. struct entry {
  61. struct entry *next_in_dir;
  62. struct entry *dir;
  63. char *name;
  64. struct inode *inode;
  65. };
  66. struct pseudofile {
  67. struct archive *archive;
  68. unsigned int has_changed:1;
  69. int local_handle;
  70. struct entry *entry;
  71. };
  72. struct archive {
  73. int fstype;
  74. char *name;
  75. char *local_name;
  76. struct stat local_stat;
  77. dev_t rdev;
  78. int fd_usage;
  79. ino_t inode_counter;
  80. struct entry *root_entry;
  81. struct archive *next;
  82. };
  83. static struct entry *extfs_find_entry (struct entry *dir, char *name,
  84. int make_dirs, int make_file);
  85. static int extfs_which (struct vfs_class *me, const char *path);
  86. static void extfs_remove_entry (struct entry *e);
  87. static void extfs_free (vfsid id);
  88. static struct vfs_class vfs_extfs_ops;
  89. static struct archive *first_archive = NULL;
  90. static int my_errno = 0;
  91. #define MAXEXTFS 32
  92. static char *extfs_prefixes [MAXEXTFS];
  93. static char extfs_need_archive [MAXEXTFS];
  94. static int extfs_no = 0;
  95. static void
  96. extfs_fill_names (struct vfs_class *me, fill_names_f func)
  97. {
  98. struct archive *a = first_archive;
  99. char *name;
  100. (void) me;
  101. while (a) {
  102. name =
  103. g_strconcat (a->name ? a->name : "", "#",
  104. extfs_prefixes[a->fstype], (char *) NULL);
  105. (*func) (name);
  106. g_free (name);
  107. a = a->next;
  108. }
  109. }
  110. static void extfs_make_dots (struct entry *ent)
  111. {
  112. struct entry *entry = g_new (struct entry, 1);
  113. struct entry *parentry = ent->dir;
  114. struct inode *inode = ent->inode, *parent;
  115. parent = (parentry != NULL) ? parentry->inode : NULL;
  116. entry->name = g_strdup (".");
  117. entry->inode = inode;
  118. entry->dir = ent;
  119. inode->local_filename = NULL;
  120. inode->first_in_subdir = entry;
  121. inode->nlink++;
  122. entry->next_in_dir = g_new (struct entry, 1);
  123. entry = entry->next_in_dir;
  124. entry->name = g_strdup ("..");
  125. inode->last_in_subdir = entry;
  126. entry->next_in_dir = NULL;
  127. if (parent != NULL) {
  128. entry->inode = parent;
  129. entry->dir = parentry;
  130. parent->nlink++;
  131. } else {
  132. entry->inode = inode;
  133. entry->dir = ent;
  134. inode->nlink++;
  135. }
  136. }
  137. static struct entry *extfs_generate_entry (struct archive *archive,
  138. const char *name, struct entry *parentry, mode_t mode)
  139. {
  140. mode_t myumask;
  141. struct inode *inode, *parent;
  142. struct entry *entry;
  143. parent = (parentry != NULL) ? parentry->inode : NULL;
  144. entry = g_new (struct entry, 1);
  145. entry->name = g_strdup (name);
  146. entry->next_in_dir = NULL;
  147. entry->dir = parentry;
  148. if (parent != NULL) {
  149. parent->last_in_subdir->next_in_dir = entry;
  150. parent->last_in_subdir = entry;
  151. }
  152. inode = g_new (struct inode, 1);
  153. entry->inode = inode;
  154. inode->local_filename = NULL;
  155. inode->linkname = NULL;
  156. inode->last_in_subdir = NULL;
  157. inode->inode = (archive->inode_counter)++;
  158. inode->dev = archive->rdev;
  159. inode->archive = archive;
  160. myumask = umask (022);
  161. umask (myumask);
  162. inode->mode = mode & ~myumask;
  163. mode = inode->mode;
  164. inode->rdev = 0;
  165. inode->uid = getuid ();
  166. inode->gid = getgid ();
  167. inode->size = 0;
  168. inode->mtime = time (NULL);
  169. inode->atime = inode->mtime;
  170. inode->ctime = inode->mtime;
  171. inode->nlink = 1;
  172. if (S_ISDIR (mode))
  173. extfs_make_dots (entry);
  174. return entry;
  175. }
  176. static void extfs_free_entries (struct entry *entry)
  177. {
  178. (void) entry;
  179. return;
  180. }
  181. static void extfs_free_archive (struct archive *archive)
  182. {
  183. extfs_free_entries (archive->root_entry);
  184. if (archive->local_name != NULL) {
  185. struct stat my;
  186. mc_stat (archive->local_name, &my);
  187. mc_ungetlocalcopy (archive->name, archive->local_name,
  188. archive->local_stat.st_mtime != my.st_mtime);
  189. g_free(archive->local_name);
  190. }
  191. g_free (archive->name);
  192. g_free (archive);
  193. }
  194. static FILE *
  195. extfs_open_archive (int fstype, const char *name, struct archive **pparc)
  196. {
  197. static dev_t archive_counter = 0;
  198. FILE *result;
  199. mode_t mode;
  200. char *cmd;
  201. char *mc_extfsdir;
  202. struct stat mystat;
  203. struct archive *current_archive;
  204. struct entry *root_entry;
  205. char *local_name = NULL, *tmp = 0;
  206. int uses_archive = extfs_need_archive[fstype];
  207. if (uses_archive) {
  208. if (mc_stat (name, &mystat) == -1)
  209. return NULL;
  210. if (!vfs_file_is_local (name)) {
  211. local_name = mc_getlocalcopy (name);
  212. if (local_name == NULL)
  213. return NULL;
  214. }
  215. tmp = name_quote (name, 0);
  216. }
  217. mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
  218. cmd =
  219. g_strconcat (mc_extfsdir, extfs_prefixes[fstype], " list ",
  220. local_name ? local_name : tmp, (char *) NULL);
  221. g_free (tmp);
  222. g_free (mc_extfsdir);
  223. open_error_pipe ();
  224. result = popen (cmd, "r");
  225. g_free (cmd);
  226. if (result == NULL) {
  227. close_error_pipe (1, NULL);
  228. if (local_name) {
  229. mc_ungetlocalcopy (name, local_name, 0);
  230. g_free(local_name);
  231. }
  232. return NULL;
  233. }
  234. #ifdef ___QNXNTO__
  235. setvbuf (result, NULL, _IONBF, 0);
  236. #endif
  237. current_archive = g_new (struct archive, 1);
  238. current_archive->fstype = fstype;
  239. current_archive->name = name ? g_strdup (name) : NULL;
  240. current_archive->local_name = local_name;
  241. if (local_name != NULL)
  242. mc_stat (local_name, &current_archive->local_stat);
  243. current_archive->inode_counter = 0;
  244. current_archive->fd_usage = 0;
  245. current_archive->rdev = archive_counter++;
  246. current_archive->next = first_archive;
  247. first_archive = current_archive;
  248. mode = mystat.st_mode & 07777;
  249. if (mode & 0400)
  250. mode |= 0100;
  251. if (mode & 0040)
  252. mode |= 0010;
  253. if (mode & 0004)
  254. mode |= 0001;
  255. mode |= S_IFDIR;
  256. root_entry = extfs_generate_entry (current_archive, "/", NULL, mode);
  257. root_entry->inode->uid = mystat.st_uid;
  258. root_entry->inode->gid = mystat.st_gid;
  259. root_entry->inode->atime = mystat.st_atime;
  260. root_entry->inode->ctime = mystat.st_ctime;
  261. root_entry->inode->mtime = mystat.st_mtime;
  262. current_archive->root_entry = root_entry;
  263. *pparc = current_archive;
  264. return result;
  265. }
  266. /*
  267. * Main loop for reading an archive.
  268. * Return 0 on success, -1 on error.
  269. */
  270. static int
  271. extfs_read_archive (int fstype, const char *name, struct archive **pparc)
  272. {
  273. FILE *extfsd;
  274. char *buffer;
  275. struct archive *current_archive;
  276. char *current_file_name, *current_link_name;
  277. if ((extfsd =
  278. extfs_open_archive (fstype, name, &current_archive)) == NULL) {
  279. message (1, MSG_ERROR, _("Cannot open %s archive\n%s"),
  280. extfs_prefixes[fstype], name);
  281. return -1;
  282. }
  283. buffer = g_malloc (4096);
  284. while (fgets (buffer, 4096, extfsd) != NULL) {
  285. struct stat hstat;
  286. current_link_name = NULL;
  287. if (vfs_parse_ls_lga
  288. (buffer, &hstat, &current_file_name, &current_link_name)) {
  289. struct entry *entry, *pent;
  290. struct inode *inode;
  291. char *p, *q, *cfn = current_file_name;
  292. if (*cfn) {
  293. if (*cfn == '/')
  294. cfn++;
  295. p = strchr (cfn, 0);
  296. if (p != cfn && *(p - 1) == '/')
  297. *(p - 1) = 0;
  298. p = strrchr (cfn, '/');
  299. if (p == NULL) {
  300. p = cfn;
  301. q = strchr (cfn, 0);
  302. } else {
  303. *(p++) = 0;
  304. q = cfn;
  305. }
  306. if (S_ISDIR (hstat.st_mode)
  307. && (!strcmp (p, ".") || !strcmp (p, "..")))
  308. goto read_extfs_continue;
  309. pent =
  310. extfs_find_entry (current_archive->root_entry, q, 1,
  311. 0);
  312. if (pent == NULL) {
  313. /* FIXME: Should clean everything one day */
  314. g_free (buffer);
  315. pclose (extfsd);
  316. close_error_pipe (1, _("Inconsistent extfs archive"));
  317. return -1;
  318. }
  319. entry = g_new (struct entry, 1);
  320. entry->name = g_strdup (p);
  321. entry->next_in_dir = NULL;
  322. entry->dir = pent;
  323. if (pent->inode->last_in_subdir) {
  324. pent->inode->last_in_subdir->next_in_dir = entry;
  325. pent->inode->last_in_subdir = entry;
  326. }
  327. if (!S_ISLNK (hstat.st_mode) && current_link_name != NULL) {
  328. pent =
  329. extfs_find_entry (current_archive->root_entry,
  330. current_link_name, 0, 0);
  331. if (pent == NULL) {
  332. /* FIXME: Should clean everything one day */
  333. g_free (buffer);
  334. pclose (extfsd);
  335. close_error_pipe (1,
  336. _("Inconsistent extfs archive"));
  337. return -1;
  338. } else {
  339. entry->inode = pent->inode;
  340. pent->inode->nlink++;
  341. }
  342. } else {
  343. inode = g_new (struct inode, 1);
  344. entry->inode = inode;
  345. inode->local_filename = NULL;
  346. inode->inode = (current_archive->inode_counter)++;
  347. inode->nlink = 1;
  348. inode->dev = current_archive->rdev;
  349. inode->archive = current_archive;
  350. inode->mode = hstat.st_mode;
  351. #ifdef HAVE_STRUCT_STAT_ST_RDEV
  352. inode->rdev = hstat.st_rdev;
  353. #else
  354. inode->rdev = 0;
  355. #endif
  356. inode->uid = hstat.st_uid;
  357. inode->gid = hstat.st_gid;
  358. inode->size = hstat.st_size;
  359. inode->mtime = hstat.st_mtime;
  360. inode->atime = hstat.st_atime;
  361. inode->ctime = hstat.st_ctime;
  362. inode->first_in_subdir = NULL;
  363. inode->last_in_subdir = NULL;
  364. if (current_link_name != NULL
  365. && S_ISLNK (hstat.st_mode)) {
  366. inode->linkname = current_link_name;
  367. current_link_name = NULL;
  368. } else {
  369. if (S_ISLNK (hstat.st_mode))
  370. inode->mode &= ~S_IFLNK; /* You *DON'T* want to do this always */
  371. inode->linkname = NULL;
  372. }
  373. if (S_ISDIR (hstat.st_mode))
  374. extfs_make_dots (entry);
  375. }
  376. }
  377. read_extfs_continue:
  378. g_free (current_file_name);
  379. g_free (current_link_name);
  380. }
  381. }
  382. g_free (buffer);
  383. /* Check if extfs 'list' returned 0 */
  384. if (pclose (extfsd) != 0) {
  385. extfs_free (current_archive);
  386. close_error_pipe (1, _("Inconsistent extfs archive"));
  387. return -1;
  388. }
  389. close_error_pipe (1, NULL);
  390. *pparc = current_archive;
  391. return 0;
  392. }
  393. /*
  394. * Dissect the path and create corresponding superblock. Note that inname
  395. * can be changed and the result may point inside the original string.
  396. */
  397. static char *
  398. extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **archive,
  399. int do_not_open)
  400. {
  401. char *local, *op;
  402. const char *archive_name;
  403. int result = -1;
  404. struct archive *parc;
  405. int fstype;
  406. archive_name = inname;
  407. vfs_split (inname, &local, &op);
  408. fstype = extfs_which (me, op);
  409. if (fstype == -1)
  410. return NULL;
  411. if (!local)
  412. local = inname + strlen (inname);
  413. /*
  414. * All filesystems should have some local archive, at least
  415. * it can be '/'.
  416. */
  417. for (parc = first_archive; parc != NULL; parc = parc->next)
  418. if (parc->name) {
  419. if (!strcmp (parc->name, archive_name)) {
  420. vfs_stamp (&vfs_extfs_ops, (vfsid) parc);
  421. goto return_success;
  422. }
  423. }
  424. result =
  425. do_not_open ? -1 : extfs_read_archive (fstype, archive_name,
  426. &parc);
  427. if (result == -1)
  428. ERRNOR (EIO, NULL);
  429. return_success:
  430. *archive = parc;
  431. return local;
  432. }
  433. /*
  434. * Dissect the path and create corresponding superblock.
  435. * The result should be freed.
  436. */
  437. static char *
  438. extfs_get_path (struct vfs_class *me, const char *inname, struct archive **archive,
  439. int do_not_open)
  440. {
  441. char *buf = g_strdup (inname);
  442. char *res = extfs_get_path_mangle (me, buf, archive, do_not_open);
  443. char *res2 = NULL;
  444. if (res)
  445. res2 = g_strdup (res);
  446. g_free (buf);
  447. return res2;
  448. }
  449. /* Return allocated path (without leading slash) inside the archive */
  450. static char *extfs_get_path_from_entry (struct entry *entry)
  451. {
  452. struct list {
  453. struct list *next;
  454. char *name;
  455. } *head, *p;
  456. char *localpath;
  457. size_t len;
  458. for (len = 0, head = 0; entry->dir; entry = entry->dir) {
  459. p = g_new (struct list, 1);
  460. p->next = head;
  461. p->name = entry->name;
  462. head = p;
  463. len += strlen (entry->name) + 1;
  464. }
  465. if (len == 0)
  466. return g_strdup ("");
  467. localpath = g_malloc (len);
  468. *localpath = '\0';
  469. while (head) {
  470. strcat (localpath, head->name);
  471. if (head->next)
  472. strcat (localpath, "/");
  473. p = head;
  474. head = head->next;
  475. g_free (p);
  476. }
  477. return (localpath);
  478. }
  479. struct loop_protect {
  480. struct entry *entry;
  481. struct loop_protect *next;
  482. };
  483. static int errloop;
  484. static int notadir;
  485. static struct entry *
  486. extfs_find_entry_int (struct entry *dir, char *name,
  487. struct loop_protect *list, int make_dirs, int make_file);
  488. static struct entry *
  489. extfs_resolve_symlinks_int (struct entry *entry,
  490. struct loop_protect *list)
  491. {
  492. struct entry *pent;
  493. struct loop_protect *looping;
  494. if (!S_ISLNK (entry->inode->mode))
  495. return entry;
  496. for (looping = list; looping != NULL; looping = looping->next)
  497. if (entry == looping->entry) { /* Here we protect us against symlink looping */
  498. errloop = 1;
  499. return NULL;
  500. }
  501. looping = g_new (struct loop_protect, 1);
  502. looping->entry = entry;
  503. looping->next = list;
  504. pent = extfs_find_entry_int (entry->dir, entry->inode->linkname, looping, 0, 0);
  505. g_free (looping);
  506. if (pent == NULL)
  507. my_errno = ENOENT;
  508. return pent;
  509. }
  510. static struct entry *extfs_resolve_symlinks (struct entry *entry)
  511. {
  512. struct entry *res;
  513. errloop = 0;
  514. notadir = 0;
  515. res = extfs_resolve_symlinks_int (entry, NULL);
  516. if (res == NULL) {
  517. if (errloop)
  518. my_errno = ELOOP;
  519. else if (notadir)
  520. my_errno = ENOTDIR;
  521. }
  522. return res;
  523. }
  524. static const char *
  525. extfs_get_archive_name (struct archive *archive)
  526. {
  527. const char *archive_name;
  528. if (archive->local_name)
  529. archive_name = archive->local_name;
  530. else
  531. archive_name = archive->name;
  532. if (!archive_name || !*archive_name)
  533. return "no_archive_name";
  534. else
  535. return archive_name;
  536. }
  537. /* Don't pass localname as NULL */
  538. static int
  539. extfs_cmd (const char *extfs_cmd, struct archive *archive,
  540. struct entry *entry, const char *localname)
  541. {
  542. char *file;
  543. char *quoted_file;
  544. char *quoted_localname;
  545. char *archive_name;
  546. char *mc_extfsdir;
  547. char *cmd;
  548. int retval;
  549. file = extfs_get_path_from_entry (entry);
  550. quoted_file = name_quote (file, 0);
  551. g_free (file);
  552. archive_name = name_quote (extfs_get_archive_name (archive), 0);
  553. quoted_localname = name_quote (localname, 0);
  554. mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
  555. cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
  556. extfs_cmd, archive_name, " ", quoted_file, " ",
  557. quoted_localname, (char *) NULL);
  558. g_free (quoted_file);
  559. g_free (quoted_localname);
  560. g_free (mc_extfsdir);
  561. g_free (archive_name);
  562. open_error_pipe ();
  563. retval = my_system (EXECUTE_AS_SHELL, shell, cmd);
  564. g_free (cmd);
  565. close_error_pipe (1, NULL);
  566. return retval;
  567. }
  568. static void
  569. extfs_run (struct vfs_class *me, const char *file)
  570. {
  571. struct archive *archive = NULL;
  572. char *p, *q, *archive_name, *mc_extfsdir;
  573. char *cmd;
  574. if ((p = extfs_get_path (me, file, &archive, 0)) == NULL)
  575. return;
  576. q = name_quote (p, 0);
  577. g_free (p);
  578. archive_name = name_quote (extfs_get_archive_name (archive), 0);
  579. mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
  580. cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
  581. " run ", archive_name, " ", q, (char *) NULL);
  582. g_free (mc_extfsdir);
  583. g_free (archive_name);
  584. g_free (q);
  585. shell_execute (cmd, 0);
  586. g_free (cmd);
  587. }
  588. static void *
  589. extfs_open (struct vfs_class *me, const char *file, int flags, int mode)
  590. {
  591. struct pseudofile *extfs_info;
  592. struct archive *archive = NULL;
  593. char *q;
  594. struct entry *entry;
  595. int local_handle;
  596. int created = 0;
  597. if ((q = extfs_get_path (me, file, &archive, 0)) == NULL)
  598. return NULL;
  599. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  600. if (entry == NULL && (flags & O_CREAT)) {
  601. /* Create new entry */
  602. entry = extfs_find_entry (archive->root_entry, q, 0, 1);
  603. created = (entry != NULL);
  604. }
  605. g_free (q);
  606. if (entry == NULL)
  607. return NULL;
  608. if ((entry = extfs_resolve_symlinks (entry)) == NULL)
  609. return NULL;
  610. if (S_ISDIR (entry->inode->mode))
  611. ERRNOR (EISDIR, NULL);
  612. if (entry->inode->local_filename == NULL) {
  613. char *local_filename;
  614. local_handle = vfs_mkstemps (&local_filename, "extfs", entry->name);
  615. if (local_handle == -1)
  616. return NULL;
  617. close (local_handle);
  618. if (!created && !(flags & O_TRUNC)
  619. && extfs_cmd (" copyout ", archive, entry, local_filename)) {
  620. unlink (local_filename);
  621. free (local_filename);
  622. my_errno = EIO;
  623. return NULL;
  624. }
  625. entry->inode->local_filename = local_filename;
  626. }
  627. local_handle =
  628. open (entry->inode->local_filename, NO_LINEAR (flags), mode);
  629. if (local_handle == -1)
  630. ERRNOR (EIO, NULL);
  631. extfs_info = g_new (struct pseudofile, 1);
  632. extfs_info->archive = archive;
  633. extfs_info->entry = entry;
  634. extfs_info->has_changed = created;
  635. extfs_info->local_handle = local_handle;
  636. /* i.e. we had no open files and now we have one */
  637. vfs_rmstamp (&vfs_extfs_ops, (vfsid) archive);
  638. archive->fd_usage++;
  639. return extfs_info;
  640. }
  641. static int extfs_read (void *data, char *buffer, int count)
  642. {
  643. struct pseudofile *file = (struct pseudofile *)data;
  644. return read (file->local_handle, buffer, count);
  645. }
  646. static int
  647. extfs_close (void *data)
  648. {
  649. struct pseudofile *file;
  650. int errno_code = 0;
  651. file = (struct pseudofile *) data;
  652. close (file->local_handle);
  653. /* Commit the file if it has changed */
  654. if (file->has_changed) {
  655. if (extfs_cmd
  656. (" copyin ", file->archive, file->entry,
  657. file->entry->inode->local_filename))
  658. errno_code = EIO;
  659. {
  660. struct stat file_status;
  661. if (stat (file->entry->inode->local_filename, &file_status) !=
  662. 0)
  663. errno_code = EIO;
  664. else
  665. file->entry->inode->size = file_status.st_size;
  666. }
  667. file->entry->inode->mtime = time (NULL);
  668. }
  669. file->archive->fd_usage--;
  670. if (!file->archive->fd_usage)
  671. vfs_stamp_create (&vfs_extfs_ops, file->archive);
  672. g_free (data);
  673. if (errno_code)
  674. ERRNOR (EIO, -1);
  675. return 0;
  676. }
  677. #define RECORDSIZE 512
  678. static struct entry*
  679. extfs_find_entry_int (struct entry *dir, char *name,
  680. struct loop_protect *list, int make_dirs, int make_file)
  681. {
  682. struct entry *pent, *pdir;
  683. char *p, *q, *name_end;
  684. char c;
  685. if (*name == '/') { /* Handle absolute paths */
  686. name++;
  687. dir = dir->inode->archive->root_entry;
  688. }
  689. pent = dir;
  690. p = name;
  691. name_end = name + strlen (name);
  692. q = strchr (p, '/');
  693. c = '/';
  694. if (!q)
  695. q = strchr (p, 0);
  696. for (; pent != NULL && c && *p; ){
  697. c = *q;
  698. *q = 0;
  699. if (strcmp (p, ".")){
  700. if (!strcmp (p, ".."))
  701. pent = pent->dir;
  702. else {
  703. if ((pent = extfs_resolve_symlinks_int (pent, list))==NULL){
  704. *q = c;
  705. return NULL;
  706. }
  707. if (!S_ISDIR (pent->inode->mode)){
  708. *q = c;
  709. notadir = 1;
  710. return NULL;
  711. }
  712. pdir = pent;
  713. for (pent = pent->inode->first_in_subdir; pent; pent = pent->next_in_dir)
  714. /* Hack: I keep the original semanthic unless
  715. q+1 would break in the strchr */
  716. if (!strcmp (pent->name, p)){
  717. if (q + 1 > name_end){
  718. *q = c;
  719. notadir = !S_ISDIR (pent->inode->mode);
  720. return pent;
  721. }
  722. break;
  723. }
  724. /* When we load archive, we create automagically
  725. * non-existant directories
  726. */
  727. if (pent == NULL && make_dirs) {
  728. pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFDIR | 0777);
  729. }
  730. if (pent == NULL && make_file) {
  731. pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFREG | 0666);
  732. }
  733. }
  734. }
  735. /* Next iteration */
  736. *q = c;
  737. p = q + 1;
  738. q = strchr (p, '/');
  739. if (!q)
  740. q = strchr (p, 0);
  741. }
  742. if (pent == NULL)
  743. my_errno = ENOENT;
  744. return pent;
  745. }
  746. static struct entry *extfs_find_entry (struct entry *dir, char *name, int make_dirs, int make_file)
  747. {
  748. struct entry *res;
  749. errloop = 0;
  750. notadir = 0;
  751. res = extfs_find_entry_int (dir, name, NULL, make_dirs, make_file);
  752. if (res == NULL) {
  753. if (errloop)
  754. my_errno = ELOOP;
  755. else if (notadir)
  756. my_errno = ENOTDIR;
  757. }
  758. return res;
  759. }
  760. static int extfs_errno (struct vfs_class *me)
  761. {
  762. (void) me;
  763. return my_errno;
  764. }
  765. static void * extfs_opendir (struct vfs_class *me, const char *dirname)
  766. {
  767. struct archive *archive = NULL;
  768. char *q;
  769. struct entry *entry;
  770. struct entry **info;
  771. if ((q = extfs_get_path (me, dirname, &archive, 0)) == NULL)
  772. return NULL;
  773. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  774. g_free (q);
  775. if (entry == NULL)
  776. return NULL;
  777. if ((entry = extfs_resolve_symlinks (entry)) == NULL)
  778. return NULL;
  779. if (!S_ISDIR (entry->inode->mode)) ERRNOR (ENOTDIR, NULL);
  780. info = g_new (struct entry *, 2);
  781. info[0] = entry->inode->first_in_subdir;
  782. info[1] = entry->inode->first_in_subdir;
  783. return info;
  784. }
  785. static void * extfs_readdir(void *data)
  786. {
  787. static union vfs_dirent dir;
  788. struct entry **info = (struct entry **) data;
  789. if (!*info)
  790. return NULL;
  791. g_strlcpy(dir.dent.d_name, (*info)->name, MC_MAXPATHLEN);
  792. compute_namelen(&dir.dent);
  793. *info = (*info)->next_in_dir;
  794. return (void *) &dir;
  795. }
  796. static int extfs_closedir (void *data)
  797. {
  798. g_free (data);
  799. return 0;
  800. }
  801. static void extfs_stat_move (struct stat *buf, const struct inode *inode)
  802. {
  803. buf->st_dev = inode->dev;
  804. buf->st_ino = inode->inode;
  805. buf->st_mode = inode->mode;
  806. buf->st_nlink = inode->nlink;
  807. buf->st_uid = inode->uid;
  808. buf->st_gid = inode->gid;
  809. #ifdef HAVE_STRUCT_STAT_ST_RDEV
  810. buf->st_rdev = inode->rdev;
  811. #endif
  812. buf->st_size = inode->size;
  813. #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
  814. buf->st_blksize = RECORDSIZE;
  815. #endif
  816. #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
  817. buf->st_blocks = (inode->size + RECORDSIZE - 1) / RECORDSIZE;
  818. #endif
  819. buf->st_atime = inode->atime;
  820. buf->st_mtime = inode->mtime;
  821. buf->st_ctime = inode->ctime;
  822. }
  823. static int
  824. extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf,
  825. int resolve)
  826. {
  827. struct archive *archive;
  828. char *q;
  829. struct entry *entry;
  830. char *path2 = g_strdup (path);
  831. int result = -1;
  832. if ((q = extfs_get_path_mangle (me, path2, &archive, 0)) == NULL)
  833. goto cleanup;
  834. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  835. if (entry == NULL)
  836. goto cleanup;
  837. if (resolve && (entry = extfs_resolve_symlinks (entry)) == NULL)
  838. goto cleanup;
  839. extfs_stat_move (buf, entry->inode);
  840. result = 0;
  841. cleanup:
  842. g_free (path2);
  843. return result;
  844. }
  845. static int extfs_stat (struct vfs_class *me, const char *path, struct stat *buf)
  846. {
  847. return extfs_internal_stat (me, path, buf, 1);
  848. }
  849. static int extfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
  850. {
  851. return extfs_internal_stat (me, path, buf, 0);
  852. }
  853. static int extfs_fstat (void *data, struct stat *buf)
  854. {
  855. struct pseudofile *file = (struct pseudofile *)data;
  856. extfs_stat_move (buf, file->entry->inode);
  857. return 0;
  858. }
  859. static int
  860. extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
  861. {
  862. struct archive *archive;
  863. char *q;
  864. size_t len;
  865. struct entry *entry;
  866. char *mpath = g_strdup (path);
  867. int result = -1;
  868. if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
  869. goto cleanup;
  870. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  871. if (entry == NULL)
  872. goto cleanup;
  873. if (!S_ISLNK (entry->inode->mode)) {
  874. me->verrno = EINVAL;
  875. goto cleanup;
  876. }
  877. len = strlen (entry->inode->linkname);
  878. if (size < len)
  879. len = size;
  880. /* readlink() does not append a NUL character to buf */
  881. memcpy (buf, entry->inode->linkname, result = len);
  882. cleanup:
  883. g_free (mpath);
  884. return result;
  885. }
  886. static int extfs_chmod (struct vfs_class *me, const char *path, int mode)
  887. {
  888. (void) me;
  889. (void) path;
  890. (void) mode;
  891. return 0;
  892. }
  893. static int extfs_write (void *data, const char *buf, int nbyte)
  894. {
  895. struct pseudofile *file = (struct pseudofile *)data;
  896. file->has_changed = 1;
  897. return write (file->local_handle, buf, nbyte);
  898. }
  899. static int extfs_unlink (struct vfs_class *me, const char *file)
  900. {
  901. struct archive *archive;
  902. char *q, *mpath = g_strdup (file);
  903. struct entry *entry;
  904. int result = -1;
  905. if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
  906. goto cleanup;
  907. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  908. if (entry == NULL)
  909. goto cleanup;
  910. if ((entry = extfs_resolve_symlinks (entry)) == NULL)
  911. goto cleanup;
  912. if (S_ISDIR (entry->inode->mode)) {
  913. me->verrno = EISDIR;
  914. goto cleanup;
  915. }
  916. if (extfs_cmd (" rm ", archive, entry, "")){
  917. my_errno = EIO;
  918. goto cleanup;
  919. }
  920. extfs_remove_entry (entry);
  921. result = 0;
  922. cleanup:
  923. g_free (mpath);
  924. return result;
  925. }
  926. static int extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
  927. {
  928. struct archive *archive;
  929. char *q, *mpath = g_strdup(path);
  930. struct entry *entry;
  931. int result = -1;
  932. (void) mode;
  933. if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
  934. goto cleanup;
  935. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  936. if (entry != NULL) {
  937. me->verrno = EEXIST;
  938. goto cleanup;
  939. }
  940. entry = extfs_find_entry (archive->root_entry, q, 1, 0);
  941. if (entry == NULL)
  942. goto cleanup;
  943. if ((entry = extfs_resolve_symlinks (entry)) == NULL)
  944. goto cleanup;
  945. if (!S_ISDIR (entry->inode->mode)) {
  946. me->verrno = ENOTDIR;
  947. goto cleanup;
  948. }
  949. if (extfs_cmd (" mkdir ", archive, entry, "")){
  950. my_errno = EIO;
  951. extfs_remove_entry (entry);
  952. goto cleanup;
  953. }
  954. result = 0;
  955. cleanup:
  956. g_free (mpath);
  957. return result;
  958. }
  959. static int extfs_rmdir (struct vfs_class *me, const char *path)
  960. {
  961. struct archive *archive;
  962. char *q, *mpath = g_strdup(path);
  963. struct entry *entry;
  964. int result = -1;
  965. if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
  966. goto cleanup;
  967. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  968. if (entry == NULL)
  969. goto cleanup;
  970. if ((entry = extfs_resolve_symlinks (entry)) == NULL)
  971. goto cleanup;
  972. if (!S_ISDIR (entry->inode->mode)) {
  973. me->verrno = ENOTDIR;
  974. goto cleanup;
  975. }
  976. if (extfs_cmd (" rmdir ", archive, entry, "")){
  977. my_errno = EIO;
  978. goto cleanup;
  979. }
  980. extfs_remove_entry (entry);
  981. result = 0;
  982. cleanup:
  983. g_free (mpath);
  984. return result;
  985. }
  986. static int
  987. extfs_chdir (struct vfs_class *me, const char *path)
  988. {
  989. struct archive *archive = NULL;
  990. char *q;
  991. struct entry *entry;
  992. my_errno = ENOTDIR;
  993. if ((q = extfs_get_path (me, path, &archive, 0)) == NULL)
  994. return -1;
  995. entry = extfs_find_entry (archive->root_entry, q, 0, 0);
  996. g_free (q);
  997. if (!entry)
  998. return -1;
  999. entry = extfs_resolve_symlinks (entry);
  1000. if ((!entry) || (!S_ISDIR (entry->inode->mode)))
  1001. return -1;
  1002. my_errno = 0;
  1003. return 0;
  1004. }
  1005. static int extfs_lseek (void *data, off_t offset, int whence)
  1006. {
  1007. struct pseudofile *file = (struct pseudofile *) data;
  1008. return lseek (file->local_handle, offset, whence);
  1009. }
  1010. static vfsid
  1011. extfs_getid (struct vfs_class *me, const char *path)
  1012. {
  1013. struct archive *archive = NULL;
  1014. char *p;
  1015. if (!(p = extfs_get_path (me, path, &archive, 1)))
  1016. return NULL;
  1017. g_free (p);
  1018. return (vfsid) archive;
  1019. }
  1020. static int extfs_nothingisopen (vfsid id)
  1021. {
  1022. if (((struct archive *)id)->fd_usage <= 0)
  1023. return 1;
  1024. return 0;
  1025. }
  1026. static void extfs_remove_entry (struct entry *e)
  1027. {
  1028. int i = --(e->inode->nlink);
  1029. struct entry *pe, *ent, *prev;
  1030. if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) {
  1031. struct entry *f = e->inode->first_in_subdir;
  1032. e->inode->first_in_subdir = NULL;
  1033. extfs_remove_entry (f);
  1034. }
  1035. pe = e->dir;
  1036. if (e == pe->inode->first_in_subdir)
  1037. pe->inode->first_in_subdir = e->next_in_dir;
  1038. prev = NULL;
  1039. for (ent = pe->inode->first_in_subdir; ent && ent->next_in_dir;
  1040. ent = ent->next_in_dir)
  1041. if (e == ent->next_in_dir) {
  1042. prev = ent;
  1043. break;
  1044. }
  1045. if (prev)
  1046. prev->next_in_dir = e->next_in_dir;
  1047. if (e == pe->inode->last_in_subdir)
  1048. pe->inode->last_in_subdir = prev;
  1049. if (i <= 0) {
  1050. if (e->inode->local_filename != NULL) {
  1051. unlink (e->inode->local_filename);
  1052. free (e->inode->local_filename);
  1053. }
  1054. g_free (e->inode->linkname);
  1055. g_free (e->inode);
  1056. }
  1057. g_free (e->name);
  1058. g_free (e);
  1059. }
  1060. static void extfs_free_entry (struct entry *e)
  1061. {
  1062. int i = --(e->inode->nlink);
  1063. if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) {
  1064. struct entry *f = e->inode->first_in_subdir;
  1065. e->inode->first_in_subdir = NULL;
  1066. extfs_free_entry (f);
  1067. }
  1068. if (i <= 0) {
  1069. if (e->inode->local_filename != NULL) {
  1070. unlink (e->inode->local_filename);
  1071. free (e->inode->local_filename);
  1072. }
  1073. g_free (e->inode->linkname);
  1074. g_free (e->inode);
  1075. }
  1076. if (e->next_in_dir != NULL)
  1077. extfs_free_entry (e->next_in_dir);
  1078. g_free (e->name);
  1079. g_free (e);
  1080. }
  1081. static void extfs_free (vfsid id)
  1082. {
  1083. struct archive *parc;
  1084. struct archive *archive = (struct archive *)id;
  1085. extfs_free_entry (archive->root_entry);
  1086. if (archive == first_archive) {
  1087. first_archive = archive->next;
  1088. } else {
  1089. for (parc = first_archive; parc != NULL; parc = parc->next)
  1090. if (parc->next == archive)
  1091. break;
  1092. if (parc != NULL)
  1093. parc->next = archive->next;
  1094. }
  1095. extfs_free_archive (archive);
  1096. }
  1097. static char *
  1098. extfs_getlocalcopy (struct vfs_class *me, const char *path)
  1099. {
  1100. struct pseudofile *fp =
  1101. (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
  1102. char *p;
  1103. if (fp == NULL)
  1104. return NULL;
  1105. if (fp->entry->inode->local_filename == NULL) {
  1106. extfs_close ((void *) fp);
  1107. return NULL;
  1108. }
  1109. p = g_strdup (fp->entry->inode->local_filename);
  1110. fp->archive->fd_usage++;
  1111. extfs_close ((void *) fp);
  1112. return p;
  1113. }
  1114. static int
  1115. extfs_ungetlocalcopy (struct vfs_class *me, const char *path,
  1116. const char *local, int has_changed)
  1117. {
  1118. struct pseudofile *fp =
  1119. (struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
  1120. if (fp == NULL)
  1121. return 0;
  1122. if (!strcmp (fp->entry->inode->local_filename, local)) {
  1123. fp->archive->fd_usage--;
  1124. fp->has_changed |= has_changed;
  1125. extfs_close ((void *) fp);
  1126. return 0;
  1127. } else {
  1128. /* Should not happen */
  1129. extfs_close ((void *) fp);
  1130. return 0;
  1131. }
  1132. }
  1133. static int extfs_init (struct vfs_class *me)
  1134. {
  1135. FILE *cfg;
  1136. char *mc_extfsini;
  1137. char key[256];
  1138. (void) me;
  1139. mc_extfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini");
  1140. cfg = fopen (mc_extfsini, "r");
  1141. /* We may not use vfs_die() message or message or similar,
  1142. * UI is not initialized at this time and message would not
  1143. * appear on screen. */
  1144. if (!cfg) {
  1145. fprintf (stderr, _("Warning: file %s not found\n"), mc_extfsini);
  1146. g_free (mc_extfsini);
  1147. return 0;
  1148. }
  1149. extfs_no = 0;
  1150. while (extfs_no < MAXEXTFS && fgets (key, sizeof (key), cfg)) {
  1151. char *c;
  1152. /* Handle those with a trailing ':', those flag that the
  1153. * file system does not require an archive to work
  1154. */
  1155. if (*key == '[') {
  1156. fprintf(stderr, "Warning: You need to update your %s file.\n",
  1157. mc_extfsini);
  1158. fclose(cfg);
  1159. g_free (mc_extfsini);
  1160. return 0;
  1161. }
  1162. if (*key == '#' || *key == '\n')
  1163. continue;
  1164. if ((c = strchr (key, '\n'))){
  1165. *c-- = 0;
  1166. } else { /* Last line without newline or strlen (key) > 255 */
  1167. c = &key [strlen (key) - 1];
  1168. }
  1169. extfs_need_archive [extfs_no] = !(*c == ':');
  1170. if (*c == ':')
  1171. *c = 0;
  1172. if (!(*key))
  1173. continue;
  1174. extfs_prefixes [extfs_no++] = g_strdup (key);
  1175. }
  1176. fclose(cfg);
  1177. g_free (mc_extfsini);
  1178. return 1;
  1179. }
  1180. static int extfs_which (struct vfs_class *me, const char *path)
  1181. {
  1182. int i;
  1183. (void) me;
  1184. for (i = 0; i < extfs_no; i++)
  1185. if (!strcmp (path, extfs_prefixes [i]))
  1186. return i;
  1187. return -1;
  1188. }
  1189. static void extfs_done (struct vfs_class *me)
  1190. {
  1191. int i;
  1192. (void) me;
  1193. for (i = 0; i < extfs_no; i++ )
  1194. g_free (extfs_prefixes [i]);
  1195. extfs_no = 0;
  1196. }
  1197. static int
  1198. extfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
  1199. {
  1200. (void) arg;
  1201. if (ctlop == VFS_SETCTL_RUN) {
  1202. extfs_run (me, path);
  1203. return 1;
  1204. }
  1205. return 0;
  1206. }
  1207. void
  1208. init_extfs (void)
  1209. {
  1210. vfs_extfs_ops.name = "extfs";
  1211. vfs_extfs_ops.init = extfs_init;
  1212. vfs_extfs_ops.done = extfs_done;
  1213. vfs_extfs_ops.fill_names = extfs_fill_names;
  1214. vfs_extfs_ops.which = extfs_which;
  1215. vfs_extfs_ops.open = extfs_open;
  1216. vfs_extfs_ops.close = extfs_close;
  1217. vfs_extfs_ops.read = extfs_read;
  1218. vfs_extfs_ops.write = extfs_write;
  1219. vfs_extfs_ops.opendir = extfs_opendir;
  1220. vfs_extfs_ops.readdir = extfs_readdir;
  1221. vfs_extfs_ops.closedir = extfs_closedir;
  1222. vfs_extfs_ops.stat = extfs_stat;
  1223. vfs_extfs_ops.lstat = extfs_lstat;
  1224. vfs_extfs_ops.fstat = extfs_fstat;
  1225. vfs_extfs_ops.chmod = extfs_chmod;
  1226. vfs_extfs_ops.readlink = extfs_readlink;
  1227. vfs_extfs_ops.unlink = extfs_unlink;
  1228. vfs_extfs_ops.chdir = extfs_chdir;
  1229. vfs_extfs_ops.ferrno = extfs_errno;
  1230. vfs_extfs_ops.lseek = extfs_lseek;
  1231. vfs_extfs_ops.getid = extfs_getid;
  1232. vfs_extfs_ops.nothingisopen = extfs_nothingisopen;
  1233. vfs_extfs_ops.free = extfs_free;
  1234. vfs_extfs_ops.getlocalcopy = extfs_getlocalcopy;
  1235. vfs_extfs_ops.ungetlocalcopy = extfs_ungetlocalcopy;
  1236. vfs_extfs_ops.mkdir = extfs_mkdir;
  1237. vfs_extfs_ops.rmdir = extfs_rmdir;
  1238. vfs_extfs_ops.setctl = extfs_setctl;
  1239. vfs_register_class (&vfs_extfs_ops);
  1240. }