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

📄 tree.c

📁 刻录光盘的程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    if( strcmp(d_entry->d_name, "..") == 0 	&& this_dir->dir_flags & DIR_HAS_DOTDOT )      {	continue;      }#if 0    if (verbose > 1)  fprintf(stderr, "%s\n",whole_path);#endif    /*     * This actually adds the entry to the directory in question.     */    insert_file_entry(this_dir, whole_path, d_entry->d_name);  }  closedir(current_dir);    return 1;}/*  * Function:		insert_file_entry * * Purpose:		Insert one entry into our directory node. * * Note: * This function inserts a single entry into the directory.  It * is assumed that all filtering and decision making regarding what * we want to include has already been made, so the purpose of this * is to insert one entry (file, link, dir, etc), into this directory. * Note that if the entry is a dir (or if we are following links, * and the thing it points to is a dir), then we will scan those * trees before we return. */intFDECL3(insert_file_entry,struct directory *, this_dir,       char *, whole_path,       char *, short_name){  struct stat			  statbuf, lstatbuf;  struct directory_entry	* s_entry, *s_entry1;  int				  lstatus;  int				  status;  int				  deep_flag;  int				  no_scandir = 0;  status = stat_filter(whole_path, &statbuf);  lstatus = lstat_filter(whole_path, &lstatbuf);  if( (status == -1) && (lstatus == -1) )    {      /*       * This means that the file doesn't exist, or isn't accessible.       * Sometimes this is because of NFS permissions problems.       */#ifdef	USE_LIBSCHILY      errmsg("Non-existant or inaccessible: %s\n",whole_path);#else      fprintf(stderr, "Non-existant or inaccessible: %s\n",whole_path);#endif      return 0;    }    if(this_dir == root && strcmp(short_name, ".") == 0)    root_statbuf = statbuf;  /* Save this for later on */    /* We do this to make sure that the root entries are consistent */  if(this_dir == root && strcmp(short_name, "..") == 0)     {      statbuf = root_statbuf;      lstatbuf = root_statbuf;    }  if(S_ISLNK(lstatbuf.st_mode))    {            /* Here we decide how to handle the symbolic links.  Here	 we handle the general case - if we are not following	 links or there is an error, then we must change	 something.  If RR is in use, it is easy, we let RR	 describe the file.  If not, then we punt the file. */            if((status || !follow_links))	{	  if(use_RockRidge)	    {	      status = 0;	      statbuf.st_size = 0;	      STAT_INODE(statbuf) = UNCACHED_INODE;	      statbuf.st_dev = (dev_t) UNCACHED_DEVICE;	      statbuf.st_mode = (statbuf.st_mode & ~S_IFMT) | S_IFREG;	    } else {	      if(follow_links) 		{#ifdef	USE_LIBSCHILY/* XXX errno may be wrong! */		  errmsg("Unable to stat file %s - ignoring and continuing.\n",			  whole_path);#else		  fprintf(stderr,			  "Unable to stat file %s - ignoring and continuing.\n",			  whole_path);#endif		}	      else		{#ifdef	USE_LIBSCHILY		  errmsgno(EX_BAD,			  "Symlink %s ignored - continuing.\n",			  whole_path);#else		  fprintf(stderr,			  "Symlink %s ignored - continuing.\n",			  whole_path);#endif		  return 0;  /* Non Rock Ridge discs - ignore all symlinks */		}	    }	}            /* Here we handle a different kind of case.  Here we have	 a symlink, but we want to follow symlinks.  If we run	 across a directory loop, then we need to pretend that	 we are not following symlinks for this file.  If this	 is the first time we have seen this, then make this	 seem as if there was no symlink there in the first	 place */            if( follow_links	  && S_ISDIR(statbuf.st_mode) ) 	{	  if(   strcmp(short_name, ".")		&& strcmp(short_name, "..") )	    {	      if(find_directory_hash(statbuf.st_dev, STAT_INODE(statbuf)))		{		  if(!use_RockRidge) 		    {		      fprintf(stderr, "Already cached directory seen (%s)\n", 			      whole_path);		      return 0;		    }		  lstatbuf = statbuf;		  no_scandir = 1;		}	      else 		{		  lstatbuf = statbuf;		  add_directory_hash(statbuf.st_dev, STAT_INODE(statbuf));		}	    }	}            /*       * For non-directories, we just copy the stat information over       * so we correctly include this file.       */      if( follow_links	  && !S_ISDIR(statbuf.st_mode) ) 	{	  lstatbuf = statbuf;	}    }    /*   * Add directories to the cache so that we don't waste space even   * if we are supposed to be following symlinks.   */  if( follow_links      && strcmp(short_name, ".")      && strcmp(short_name, "..")      && S_ISDIR(statbuf.st_mode) )     {      add_directory_hash(statbuf.st_dev, STAT_INODE(statbuf));    }#ifdef VMS  if(!S_ISDIR(lstatbuf.st_mode) && (statbuf.st_fab_rfm != FAB$C_FIX && 				    statbuf.st_fab_rfm != FAB$C_STMLF)) {    fprintf(stderr,"Warning - file %s has an unsupported VMS record"	    " format (%d)\n",	    whole_path, statbuf.st_fab_rfm);  }#endif    if(S_ISREG(lstatbuf.st_mode) && (status = access(whole_path, R_OK)))    {#ifdef	USE_LIBSCHILY      errmsg("File %s is not readable - ignoring\n", 	      whole_path);#else      fprintf(stderr, "File %s is not readable (errno = %d) - ignoring\n", 	      whole_path, errno);#endif      return 0;    }    /* Add this so that we can detect directory loops with hard links.     If we are set up to follow symlinks, then we skip this checking. */  if(   !follow_links 	&& S_ISDIR(lstatbuf.st_mode) 	&& strcmp(short_name, ".") 	&& strcmp(short_name, "..") )     {      if(find_directory_hash(statbuf.st_dev, STAT_INODE(statbuf))) {#ifdef	USE_LIBSCHILY/*	comerrno(EX_BAD, "Directory loop - fatal goof (%s %lx %lu).\n",*/	comerrno(EX_BAD, "Warning: Directory loop (%s dev: %lx ino: %lu).\n",		whole_path, (unsigned long) statbuf.st_dev,		(unsigned long) STAT_INODE(statbuf));#else/*	fprintf(stderr,"Directory loop - fatal goof (%s %lx %lu).\n",*/	fprintf(stderr, "Warning: Directory loop (%s dev: %lx ino: %lu).\n",		whole_path, (unsigned long) statbuf.st_dev,		(unsigned long) STAT_INODE(statbuf));	exit(1);#endif      }      add_directory_hash(statbuf.st_dev, STAT_INODE(statbuf));    }    if (!S_ISCHR(lstatbuf.st_mode) && !S_ISBLK(lstatbuf.st_mode) &&      !S_ISFIFO(lstatbuf.st_mode) && !S_ISSOCK(lstatbuf.st_mode)      && !S_ISLNK(lstatbuf.st_mode) && !S_ISREG(lstatbuf.st_mode) &&      !S_ISDIR(lstatbuf.st_mode)) {    fprintf(stderr,"Unknown file type (%s) %s - ignoring and continuing.\n",	    filetype((int)lstatbuf.st_mode), whole_path);    return 0;  }    /* Who knows what trash this is - ignore and continue */    if(status)     {#ifdef	USE_LIBSCHILY      errmsg("Unable to stat file %s - ignoring and continuing.\n",	      whole_path);#else      fprintf(stderr,	      "Unable to stat file %s - ignoring and continuing.\n",	      whole_path);#endif      return 0;     }    /*   * Check to see if we have already seen this directory node.   * If so, then we don't create a new entry for it, but we do want   * to recurse beneath it and add any new files we do find.   */  if (S_ISDIR(statbuf.st_mode))     {      int dflag;            for( s_entry = this_dir->contents; s_entry; s_entry = s_entry->next)	{	  if( strcmp(s_entry->name, short_name) == 0 )	    {	      break;	    }	}      if ( s_entry != NULL 	   && strcmp(short_name,".") 	   && strcmp(short_name,"..")) 	{	  struct directory * child;	  	  if ( (s_entry->de_flags & RELOCATED_DIRECTORY) != 0)	    {	      for( s_entry = reloc_dir->contents; s_entry; s_entry = s_entry->next)		{		  if( strcmp(s_entry->name, short_name) == 0 )		    {		      break;		    }		}	      child = find_or_create_directory(reloc_dir, whole_path, 					       s_entry, 1);	    }	  else	    {	      child = find_or_create_directory(this_dir, whole_path, 					       s_entry, 1);	      /* If unable to scan directory, mark this as a non-directory */	    }	  if (no_scandir) dflag = 1; else	  dflag = scan_directory_tree(child, whole_path, s_entry);	  if(!dflag)	    {	      lstatbuf.st_mode = (lstatbuf.st_mode & ~S_IFMT) | S_IFREG;	    }	  return 0;	}    }    s_entry = (struct directory_entry *)     e_malloc(sizeof (struct directory_entry));  s_entry->next = this_dir->contents;  memset(s_entry->isorec.extent, 0, 8);  this_dir->contents = s_entry;  deep_flag = 0;  s_entry->table = NULL;    s_entry->name = strdup(short_name);  s_entry->whole_name = strdup (whole_path);  s_entry->de_flags = 0;  /*   * If the current directory is hidden, then hide all it's members   * otherwise check if this entry needs to be hidden as well */  if (this_dir->dir_flags & INHIBIT_ISO9660_ENTRY) {    s_entry->de_flags |= INHIBIT_ISO9660_ENTRY;  }  else if (strcmp(short_name,".") != 0 && strcmp(short_name,"..") != 0) {    if (i_matches(short_name) || i_matches(whole_path)) {      if (verbose > 1) {	fprintf(stderr, "Hidden from ISO9660 tree: %s\n", whole_path);      }      s_entry->de_flags |= INHIBIT_ISO9660_ENTRY;    }  }  if (this_dir != reloc_dir && this_dir->dir_flags & INHIBIT_JOLIET_ENTRY) {    s_entry->de_flags |= INHIBIT_JOLIET_ENTRY;  }  else if (strcmp(short_name,".") != 0 && strcmp(short_name,"..") != 0) {    if (j_matches(short_name) || j_matches(whole_path)) {      if (verbose > 1) {	fprintf(stderr, "Hidden from Joliet tree: %s\n", whole_path);      }      s_entry->de_flags |= INHIBIT_JOLIET_ENTRY;    }  }  s_entry->filedir = this_dir;  s_entry->isorec.flags[0] = 0;  s_entry->isorec.ext_attr_length[0] = 0;  iso9660_date(s_entry->isorec.date, statbuf.st_mtime);  s_entry->isorec.file_unit_size[0] = 0;  s_entry->isorec.interleave[0] = 0;  if( strcmp(short_name,  ".") == 0)    {      this_dir->dir_flags |= DIR_HAS_DOT;    }   if( strcmp(short_name,  "..") == 0)    {      this_dir->dir_flags |= DIR_HAS_DOTDOT;    }   if(   this_dir->parent      && this_dir->parent == reloc_dir      && strcmp(short_name,  "..") == 0)    {      s_entry->inode = UNCACHED_INODE;      s_entry->dev = (dev_t) UNCACHED_DEVICE;      deep_flag  = NEED_PL;    }   else    {      s_entry->inode = STAT_INODE(statbuf);      s_entry->dev = statbuf.st_dev;    }  set_723(s_entry->isorec.volume_sequence_number, volume_sequence_number);  iso9660_file_length(short_name, s_entry, S_ISDIR(statbuf.st_mode));  s_entry->rr_attr_size = 0;  s_entry->total_rr_attr_size = 0;  s_entry->rr_attributes = NULL;    /* Directories are assigned sizes later on */  if (!S_ISDIR(statbuf.st_mode))     {      if (S_ISCHR(lstatbuf.st_mode) || S_ISBLK(lstatbuf.st_mode) || 	  S_ISFIFO(lstatbuf.st_mode) || S_ISSOCK(lstatbuf.st_mode)	  || S_ISLNK(lstatbuf.st_mode))	{	  s_entry->size = 0; 	  statbuf.st_size = 0; 	}      else	{	  s_entry->size = statbuf.st_size; 	}      set_733((char *) s_entry->isorec.size, statbuf.st_size);     }   else    {      s_entry->isorec.flags[0] = 2;    }    if (strcmp(short_name,".") != 0 && strcmp(short_name,"..") != 0 &&      S_ISDIR(statbuf.st_mode) && this_dir->depth >  RR_relocation_depth)    {      struct directory * child;      if(!reloc_dir) generate_reloc_directory();            /*       * Replicate the entry for this directory.  The old one will stay where it       * is, and it will be neutered so that it no longer looks like a directory.       * The new one will look like a directory, and it will be put in the reloc_dir.       */      s_entry1 = (struct directory_entry *) 	e_malloc(sizeof (struct directory_entry));      memcpy(s_entry1, s_entry,  sizeof(struct directory_entry));      s_entry1->table = NULL;      s_entry1->name = strdup(this_dir->contents->name);      s_entry1->whole_name = strdup(this_dir->contents->whole_name);      s_entry1->next = reloc_dir->contents;      reloc_dir->contents = s_entry1;      s_entry1->priority  =  32768;      s_entry1->parent_rec = this_dir->contents;      set_723(s_entry1->isorec.volume_sequence_number, volume_sequence_number);            deep_flag = NEED_RE;            if(use_RockRidge) 	{	  generate_rock_ridge_attributes(whole_path,					 short_name, s_entry1,					 &statbuf, &lstatbuf, deep_flag);	}            deep_flag = 0;            /* We need to set this temporarily so that the parent to this	 is correctly determined. */      s_entry1->filedir = reloc_dir;      child = find_or_create_directory(reloc_dir, whole_path, 				       s_entry1, 0);      if (!no_scandir)	      scan_directory_tree(child, whole_path, s_entry1);      s_entry1->filedir = this_dir;            statbuf.st_size = 0;      statbuf.st_mode &= 0777;      set_733((char *) s_entry->isorec.size, 0);      s_entry->size = 0;      s_entry->isorec.flags[0] = 0;      s_entry->inode = UNCACHED_INODE;      s_entry->de_flags |= RELOCATED_DIRECTORY;      deep_flag = NEED_CL;    }    if(generate_tables      && strcmp(s_entry->name, ".") != 0     && strcmp(s_entry->name, "..") != 0)     {      char  buffer[2048];      int nchar;      switch(lstatbuf.st_mode & S_IFMT)	{	case S_IFDIR:	  sprintf(buffer,"D\t%s\n",		  s_entry->name);	  break;/* extra for WIN32 - if it doesn't have the major/minor defined, then   S_IFBLK and S_IFCHR type files are unlikely to exist anyway ...   code similar to that in rock.c */#if 0/* * Use the device handling code from <device.h> */#ifndef major#define major(dev) (sizeof(dev_t) <= 2 ? ((dev) >> 8) : \	(sizeof(dev_t) <= 4 ? (((dev) >> 8) >> 8) : \	(((dev) >> 16) >> 16)))#define minor(dev) (sizeof(dev_t) <= 2 ? (dev) & 0xff : \	(sizeof(dev_t) <= 4 ? (dev) & 0xffff : \	(dev) & 0xffffffff))#endif#endif#ifdef S_IFBLK	case S_IFBLK:	  sprintf(buffer,"B\t%s\t%lu %lu\n",		  s_entry->name,		  (unsigned long) major(statbuf.st_rdev),		  (unsigned long) minor(statbuf.st_rdev));	  break;#endif#ifdef S_IFIFO	case S_IFIFO:	  sprintf(buffer,"P\t%s\n",		  s_entry->name);	  break;#endif#ifdef S_IFCHR	case S_IFCHR:	  sprintf(buffer,"C\t%s\t%lu %lu\n",		  s_entry->name,		  (unsigned long) major(statbuf.st_rdev),		  (unsigned long) minor(statbuf.st_rdev));	  break;#endif#ifdef S_IFLNK	case S_IFLNK:#ifdef	HAVE_READLINK	  nchar = readlink(whole_path, 			   (char *)symlink_buff, 			   sizeof(symlink_buff));#else	  nchar = -1;#endif	  symlink_buff[nchar < 0 ? 0 : nchar] = 0;	  sprintf(buffer,"L\t%s\t%s\n",		  s_entry->name, symlink_buff);	  break;#endif#ifdef S_IFSOCK	case S_IFSOCK:	  sprintf(buffer,"S\t%s\n",		  s_entry->name);	  break;#endif	case S_IFREG:	default:	  sprintf(buffer,"F\t%s\n",		  s_entry->name);	  break;	};      s_entry->table = strdup(buffer);

⌨️ 快捷键说明

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