⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 g_nnfsrc.c

📁 Non-Networked File System在几个非网络的(或慢网络的)Unix 计算机上提供了一个兼容的文件系统。
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    NNFS: Non-Networked File System. *    Copyright (C) 1995-1998  Thierry EXCOFFIER (exco@ligim.univ-lyon1.fr) * *    This program is g_Free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the G_Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    This program is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the G_Free Software *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "g_nnfsrc.h"#include "g_help.h"#include "g_malloc.h"#include "g_debug.h"#include "g_secure.h"#include "g_unix.h"#include <stdio.h>#if HAVE_ERRNO_H#include <errno.h>#endif#if HAVE_TIME_H#include <time.h>#endif#include <stdlib.h>/* * DO NOT CHANGE ORDER or ADD/REMOVE in first table without changing order * in second part of the function. */#define S(N) t[i++].offset_in_g_config = (char*)&conf.N - (char*)&confg_Nnfsrc_Var *g_Nnfsrc_Var_Table(){  g_Config conf ;  int i ;  static g_Nnfsrc_Var t[] =  {    { "CASE"             , g_Var_String ,-1,      "Switch case in which current program go."},    { "COMMENT"          , g_Var_Big_String ,0,      "A comment for this host dependant configuration"},    /*    { "TMP"              , g_Var_String ,0,      "Name of a file used for copying on medium. It is useful if the copy command can not work with standard input or output.\nThe filename is generated by a shell script to avoid overwriting by another program."},    */    { "READ_MEDIUM"      , g_Var_String ,0,      "The command that read the file on the medium and output it on standard output.\nThe '%' is replaced by the file name. For example, 'exco.AAA', 'exco.AAB', ...", "program" },    { "WRITE_MEDIUM"     , g_Var_String ,0,      "The command that read its standard input and store it on the medium.\nThe '%' is replaced by the file name. For example, 'exco.AAA', 'exco.AAB', ...",    "program" },    { "COMPRESS_FILTER"  , g_Var_String ,1,    "The command compressing its standard input and writing the compressed result on its standard output",    "program"},    { "UNCOMPRESS_FILTER", g_Var_String ,1,    "The command uncompressing its standard input and writing the uncompressed result on its standard output",    "program"},    { "OUTPUT_FILTER"    , g_Var_Filter ,3,      "The filter used to avoid copy some files.\nFiles too big for the medium.\nFiles not useful. For example the '.o' if you synchronize hosts with uncompatible architecture.\nFiles dangerous to synchronize, for example the files used by a program while NNFS run. To be more precise, the mailbox summaries of 'Netscape' if you do not stop 'Netscape' while running NNFS."},    { "EJECT"            , g_Var_String ,0,      "The command ejecting the medium. If there is no such command, use the 'true' command to report 'no error'.",    "program"},    { "MEDIUM_SIZE"      , g_Var_Integer,1,      "The number of bytes you are sure you can store on the medium."},    { "HISTORY_DIR"      , g_Var_String ,2,      "Where to historize modified/deleted files. "      "Do 'man strftime' for more information. "      "The name is relative to $HOME/.nnfs/\n"      "  %Y : Year\n"      "  %m : Month\n"      "  %d : Month day\n"      "  %H : Hour\n"      "  %M : Minute\n"      "  %S : Second\n"      ,    "program"},    { "MEDIUM_NAME"      , g_Var_String ,2,      "Name of the file on the medium (if the medium is not a cartridge). This name is postfixed by AAA, AAB, AAC, ... for numbering. If you have the same username on all the hosts, the default value works. If it is not the case, set the name to a constant, for example 'nnfs'",    "program"},    { "HISTORIZE"        , g_Var_Boolean,1,      "Let you choose which file you want to historize: modified/deleted/conflicting.", NULL,      {	{"no",	 "deleted files and files with conflicting update"	},	{"yes",	 "deleted files and modified files (safest option)."	},	{""}      }    },    { "ASK_MEDIUM"       , g_Var_Boolean,2,      "By default, NNFS asks you to insert medium.\nIt is useful to not set this option if your medium is virtual (when you use FTP or 'remsh') or if you use an autochanger. A drawback is that in case of writing error, NNFS abort instead of asking a new medium.", NULL,      {	{"no",	 "NNFS will not ask you to insert medium.\nBeware, if there is an error, NNFS will abort."	},	{"yes",	 "NNFS asks you to insert medium"	},      {""}      }    },    { "CONFIRMATION"     , g_Var_Choice,1,      "Indicate to NNFS in which case a question "      "is asked to you before starting the updating of your files.", NULL,      {	{"never",	 "NNFS never asks confirmation before updating."	},	{"always",	 "NNFS always asks confirmation before updating."	},	{"yes",	 "NNFS asks confirmation in case of conflict or file to delete"	},	{""}      }    },    { "AUTO_START"     , g_Var_Choice,1,      "Indicate to NNFS X11 interface if synchronisation start "      "without user intervention.", NULL,      {	{"no",	 "NNFS asks confirmation before starting the update."	},	{"yes",	 "NNFS start immediatly update."	},	{""}      }    },    { "TMP_FILE"         , g_Var_Choice ,2,      "If there is an error when writing on the medium, NNFS abort the update. Except if this option is set to 'memory' in which case if there is an error, NNFS will attempt to rewrite the medium. Beware, if the medium size is 100Mb you will need 100Mb of swap...", NULL,      {	{"none",	 "NO TEMPORARY STORAGE.\nNNFS Abort in case of medium writing error"	},	{"memory",	 "MEMORY AS TEMPORARY STORAGE\nNNFS will retry in case of medium writing error.\nBeware, if your medium contains 100Mb\nyou will need 100Mb of swap..."	},	{""}      }    },    { "COPY_HARD_LINK"         , g_Var_Boolean ,2,      "If set to 'copy', the hard linked files on an host are copied as several files not hard linked on the other hosts. It is dangerous to use because if one of the not hard linked file is modified the hard link will be destroyed on the original host.\nIf set to 'not copy', the hard linked files are not copied at all, it is safest.", NULL,      {	{"no",	 "Hard linked files are not copied on other hosts"	},	{"yes",	 "Hard linked files are copied as\nnon hard linked files on the other hosts."	},	{""}      }    },    { "CROSS_MOUNT_POINT"         , g_Var_Boolean ,2,      "If mount point are crossed, all the files are synchronized even they are on several file systems", NULL,      {	{"no",	 "Do not cross mount point"	},	{"memory",	 "Cross mount point"	},	{""}      }    },    { NULL }  } ;  if ( t->offset_in_g_config )    return(t) ;  i = 0 ;  S(switchcase) ;  S(comment) ;  S(read_medium) ;  S(write_medium) ;  S(compress_filter) ;  S(uncompress_filter) ;  S(file_filter) ;  S(eject) ;  S(medium_size) ;  S(history_format) ;  S(medium_name) ;  S(historize) ;  S(ask_medium) ;  S(confirmation) ;  S(auto_start) ;  S(tmp_file) ;  S(copy_hard_link) ;  S(cross_mount_point) ;  return(t) ;}/* * */char *g_Read_Content(FILE *f){  int c ;  char tmp[G_LINE_CHUNK] ;  char *w ;  c = getc(f) ;  if ( c != '"' )    {      g_Printf("Not a \" after =, it is a `%c'\n", c) ;      exit(26) ;    }  w = tmp ;  for(;!feof(f);)    {      c = getc(f) ;      switch(c)	{	case '"':	  *w = '\0' ;	  return( g_Save_String(tmp) ) ;	case '\\':	  c = getc(f) ;	  if ( c!='"' && c!='`' )	    *w++ = '\\' ;	  *w++ = c ;	  break ;	default:	  *w++ = c ;	}    }  return(g_Save_String("String not terminated in nnfsrc")) ;}void g_Write_Content(FILE *f, const char *c){  putc('"', f) ;  while(*c)    {      switch(*c)	{	case '"':	  fputs("\\\"", f) ;	  break ;	case '`':	  fputs("\\`", f) ;	  break ;	default:	  putc(*c, f) ;	  break ;	}      c++ ;    }  putc('"', f) ;}/* * */char *g_Case_Name(const char *hostname){  FILE *h ;  char named[G_LINE_CHUNK] ;  /*    if ( hostname && hostname[0] && strchr(hostname,'.')==NULL )    {      strcpy(named, hostname) ;      h = g_popen("echo .`domainname 2>/dev/null`.`uname`","r");      fgets(named+strlen(named), sizeof(named), h) ;      g_pclose(h) ;      named[strlen(named)-1] = '\0' ;          }  else    {      h = g_popen("echo `hostname`.`domainname 2>/dev/null`.`uname`","r");      fgets(named, sizeof(named), h) ;      g_pclose(h) ;      named[strlen(named)-1] = '\0' ;    }  */  strcpy(named, hostname) ;  h = g_popen("echo .`uname`","r");  fgets(named+strlen(named), sizeof(named), h) ;  g_pclose(h) ;  named[strlen(named)-1] = '\0' ;        return( g_Save_String(named) ) ;}void g_Nnfsrc_Insert_Case(FILE *g, const char *hostname, const g_Nnfsrc_Var *vt){  time_t t ;  char *tmp ;  int i ;  /*   * New case to write   */  tmp = g_Case_Name(hostname) ;  time(&t) ;  fprintf(g, "\n\"%s\") # %s", tmp, ctime(&t)) ;  fprintf(g, "CASE=\"%s\"\n", tmp) ;  g_Free(tmp) ;    fprintf(g, "COMMENT=") ;  for(i=0;;i++)    if( strcmp(vt[i].name, "COMMENT") == 0 )      {	g_Write_Content(g, vt[i].content) ;	break ;      }  fprintf(g, "\nREAD_MEDIUM=") ;  for(i=0;;i++)    if( strcmp(vt[i].name, "READ_MEDIUM") == 0 )      {	g_Write_Content(g, vt[i].content) ;	break ;      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -