/**
 * @brief 输出文件 
 * @param[in] absolute_path 文件的绝对路径
 * @param[in] all           是否输出全部文件,包括隐藏文件,以及.和..
 * @param[in] almost_all    是否“几乎全部”输出,包括隐藏文件,不包括.和..
 * @param[in] long_list     是否按长列表方式输出
 */
void output_files( const char * absolute_path, bool all, bool almost_all, bool long_list )  // ls
{
	struct ext2_group_desc group;
	struct ext2_inode inode;
	void * block = NULL;

	int inode_no = get_file_inode_no(absolute_path);
	if ( inode_no == -1 )
	{
		fprintf(stderr, "Current directory does not exist.\n");
		return;
	}
	read_group_descriptor(&group);
	read_inode(&group, &inode, inode_no);

	if (S_ISDIR(inode.i_mode))
	{
		struct ext2_dir_entry_2 * entry = NULL;
		unsigned int size = 0;
		if ((block = malloc(block_size)) == NULL)
		{
			fprintf(stderr, "Insufficient memory.\n");
			exit(EXIT_FAILURE);
		}

		lseek(fd_ext2, BLOCK_OFFSET(inode.i_block[0]), SEEK_SET);
		read(fd_ext2, block, block_size);                // read block from disk

		entry = (struct ext2_dir_entry_2 *) block;  // first entry in the directory
		// Notice that the list may be terminated with a NULL entry (entry->inode == NULL)
		while((size < inode.i_size) && entry->inode)
		{
			if ( entry->name[0] == '.' )
			{
				if ( all )
					output_entry(entry, long_list, entry->inode);
				else if ( almost_all )
				{
					if ( strcmp(entry->name, ".") && strcmp(entry->name, "..") )
						output_entry(entry, long_list, entry->inode);
				}
			}
			else
				output_entry(entry, long_list, entry->inode);
			entry = (struct ext2_dir_entry_2 *)((void *)entry + entry->rec_len);
			size += entry->rec_len;
		}
		puts("");

		free(block);
		block = entry = NULL;
	}
	else
		fprintf(stderr, "Current directory does not exist.\n");
}
Пример #2
0
void ok_cb (GtkWidget *w, void *v)
{  
   gboolean edit=TRUE;
   GtkWidget *widget;
   GtkType type;
   GSList *current = widgets;
   
   while (current) {
      edit=TRUE;
      widget = (GtkWidget *)current->data;
      current = current->next;
      
      type = GTK_OBJECT_TYPE(widget);
      if (type == gtk_entry_get_type())
	output_entry(widget);
      if (type == gtk_text_get_type())
	output_text(widget,&edit);
      if (type == gtk_combo_get_type())
	output_combo(widget);
      if (type == gtk_check_button_get_type())
	output_check_button(widget);
      if (type == gtk_option_menu_get_type())
	output_option_menu(widget);
      
      /* if there are more widgets with output values, separate them */
      if (current && edit) {
	putchar ('\v');
      }
   }
   quit(RETURN_OK);
}
Пример #3
0
static  void  output_alloc_list(
    FILE          *file,
    alloc_struct  *alloc_list )
{
    skip_entry  *ptr;

    ptr = alloc_list->header->forward[0];

    while( ptr != (skip_entry *) 0 )
    {
        output_entry( file, ptr );
        ptr = ptr->forward[0];
    }
}