--- archive/podfuk.c.pavel.2.9 Tue Oct 26 09:59:00 1999 +++ podfuk.c Wed Oct 27 03:25:23 1999 @@ -48,9 +48,8 @@ # DEBUG turns on diagnostic printing # USE_MONITOR makes calls to an X progress bar -#CFLAGS = -DDEBUG -DUSE_MONITOR -Wall -#CFLAGS = -DDEBUG -DUSE_MONITOR -Wall -CFLAGS = -DDEBUG -Wall +CFLAGS = -DDEBUG -DUSE_MONITOR -DCOREL_DEF -Wall +#CFLAGS = -DDEBUG -Wall -DNODAEMON MIDNIGHT=/home/patb/projects/mc-4.5.40 @@ -66,7 +65,7 @@ gcc podfuk.c `glib-config --libs --cflags` -I$(MIDNIGHT) -I$(KERNEL) -g $(VFS)/libvfs.so -o podfuk $(CFLAGS) podfuk-static: podfuk.c - gcc podfuk.c `glib-config --libs --cflags` -DNODAEMON -I$(MIDNIGHT) -I$(KERNEL) -g $(VFS)/tcputil.so $(VFS)/fish.so $(VFS)/ftpfs.so $(VFS)/mcfs.so $(VFS)/utilvfs.so $(VFS)/local.so $(VFS)/vfs.so $(VFS)/tar.so $(VFS)/sfs.so $(VFS)/names.so $(VFS)/container.so $(VFS)/extfs.so $(VFS)/util-alone.so $(VFS)/util.sor $(VFS)/utilunix.sor $(VFS)/direntry.so -o podfuk-static + gcc podfuk.c `glib-config --libs --cflags` -I$(MIDNIGHT) -I$(KERNEL) -g $(VFS)/tcputil.so $(VFS)/fish.so $(VFS)/ftpfs.so $(VFS)/mcfs.so $(VFS)/utilvfs.so $(VFS)/local.so $(VFS)/vfs.so $(VFS)/tar.so $(VFS)/sfs.so $(VFS)/names.so $(VFS)/container.so $(VFS)/extfs.so $(VFS)/util-alone.so $(VFS)/util.sor $(VFS)/utilunix.sor $(VFS)/direntry.so -o podfuk-static /dev/cfs0: mknod /dev/cfs0 c 67 5 @@ -161,6 +160,12 @@ # define FLUSH_TIME 300 #endif +#if COREL_DEF +# define MOUNT_POINT_STRING "/mnt/.mcvfs" +#else +# define MOUNT_POINT_STRING "/overlay" +#endif + /* There is nothing magic about these constants. I just selected them * so that kernel does not complain too loudly. */ #define MY_VOL 0x01234567 @@ -171,7 +176,8 @@ /* missing from vfs.h */ vfs * vfs_rosplit (char *path); extern int ftpfs_use_passive_connections; - int ftpfs_login_timeout = 10; +extern int ftpfs_retry_seconds; + /* our handle to the pipe */ int cfs; @@ -194,7 +200,6 @@ /* a linked list of the above objects */ GList *pList; -int bListLocked = 0; int count = 0; @@ -215,15 +220,19 @@ exit(0); } -void alarm_handler(int signo) +void flush_VFids(void) { GList *pWalk, *pPrev; struct coda_purgefid_out cmd; + return; + /* this code is temporarily disabled. Because: if a process is + * using a mounted directory, and we issue a CODA_PURGEFID, + * the coda filesystem will NOT purge that VFid (the usage count !=0) + * Then, later, coda will call up to use, using that VFid, which we + * don't have anymore. Boom! + */ - /* should this be wrapped in a semaphore? YES */ - if (bListLocked) return; - DEBUG_PRINT( "cleaning the local VFid cache\n" ); /* note: we are deleting elements, so we have to walk carefully */ /* walk backward so that we purge children, then parents */ @@ -259,7 +268,7 @@ if ( !strcmp( var, "logfile" ) && val[0] ) { ftpfs_set_debug( val ); printf("logfile set to %s\n",val); } if ( !strcmp( var, "ftpfs_login_timeout") ) - ftpfs_login_timeout = atoi(val); + ftpfs_retry_seconds = atoi(val); } /* load and parse an ini file: handles sections, comments and params */ @@ -297,8 +306,9 @@ void progress_func( char* m) { if (!monitor_handle) return; - /* You should better do text parsing in monitor */ - write(monitor_handle,m,strlen(m)); + /* Send the progress string to the monitor. + * Add an extra zero to delimit the string. */ + write(monitor_handle,m,strlen(m)+1); } #endif // USE_MONITOR @@ -547,7 +557,7 @@ int legal_name(char *name) { - if (!strncmp (name, "/overlay", 8) + if (!strncmp (name, MOUNT_POINT_STRING, strlen(MOUNT_POINT_STRING)) || (strchr(name, '#') && !vfs_rosplit(name))) return 0; return 1; @@ -557,6 +567,7 @@ main(int argc, char** argv) { char buf[2048]; + time_t time_last_msg = time(NULL); if (argc>1) { printf("%s: a virtual file system extention to Linux\n",argv[0]); @@ -583,14 +594,20 @@ DEBUG_PRINT( "Opened cfs0\n" ); #ifdef USE_MONITOR vfs_set_callback( CALL_INFO, progress_func ); - monitor_handle = open("/var/tmp/podfuk.pipe", O_WRONLY | O_NONBLOCK); + monitor_handle = open("/var/tmp/podfuk.pipe", O_RDWR | O_NONBLOCK); + if (monitor_handle==-1) { + DEBUG_PRINT( "failed to open pipe to monitor\n" ); + monitor_handle = 0; + } #endif load_profile( "/etc/podfukrc", set_global_var ); mc_vfs_init(); - signal(SIGTERM, signal_handler); + + signal(SIGTERM, signal_handler); /* graceful shutdown */ signal(SIGINT, signal_handler); + signal(SIGPIPE, SIG_IGN); /* pipe faults are benign */ + vfs_flags |= FL_ALWAYS_MAGIC; - #ifdef FL_NO_LOCALHASH vfs_flags |= FL_NO_LOCALHASH; /* Avoid local deadlock when someone accesses /#ahoj#utar */ #else @@ -613,7 +630,6 @@ struct timeval tv; int retval; - bListLocked = 0; /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&rfds); FD_SET(cfs, &rfds); @@ -623,12 +639,20 @@ tv.tv_usec = 0; retval = select(cfs+1, &rfds, NULL, NULL, &tv); + /* onError */ if (retval == -1) { - if (errno == EINTR) - continue; printf( "select failed: %m\n" ); exit(1); } + /* onTimeout */ + if (retval == 0) { + if (time(NULL)-time_last_msg > FLUSH_TIME) { + flush_VFids(); + time_last_msg = (time_t) 0x7fffffff; /* only flush once */ + } + continue; + } + vfs_timeout_handler(); /* Don't rely on the value of tv now! */ @@ -636,8 +660,6 @@ if (msg == -1) continue; - bListLocked = 1; - DEBUG_PRINT( "got %3.3d byte command: opcode = %2.2ld ", msg, req->ih.opcode ); // printf( " (un=%d,pid=%d,pgid=%d) ", req.ih.unique, req.ih.pid, req.ih.pgid ); // printf( " (uid=%d,euid=%d,suid=%d,fsuid=%d) ",req.ih.cred.cr_uid,req.ih.cred.cr_euid,req.ih.cred.cr_suid,req.ih.cred.cr_fsuid ); @@ -736,10 +758,8 @@ if (!memcmp(name,"/#ftp:",6)) pName = strchr( name+1,'/' ); if (!pName) pName = name; - sprintf(monitor_buf,"PROG 0!NAME %s",pName); - /* blow away the ! */ - monitor_buf[6]=0; - write(monitor_handle, monitor_buf, strlen(monitor_buf+7)+7); + sprintf(monitor_buf,"NAME %s",pName); + write(monitor_handle, monitor_buf, strlen(monitor_buf+1)); } #endif name = get_local_copy(req->coda_open.VFid,req->coda_open.flags); @@ -840,6 +860,8 @@ setegid (0); vfs_gid = 0; seteuid (0); vfs_uid = 0; + + time_last_msg = time(NULL); } /* while */ }