extfs.c 37 KB

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