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

📄 msdos_sys_dirstart.c

📁 阿基米德操作系统的源代码
💻 C
字号:

///////////////////////////////////////////////////////////////////////////////////////////////
#include "general.h"
#include "s_isdirreg.h"

#include "hd_info_struct.h"
#include "dir_entry.h"
#include "msdos_dir_entry.h"
#include "d_inode.h"
#include "m_inode.h"
#include "buffer_head.h"
#include "fat_cache.h"
#include "file.h"
#include "hd_request_struct.h"
#include "super_block.h"

#include "common_head.h"
///////////////////////////////////////////////////////////////////////////////////////////////
int msdos_sys_dirstart(const char * pathname,const char * basename,unsigned char * buf,unsigned long length)
{
	struct m_inode		* temp_dir, * temp_inode;
	struct buffer_head	* temp_bh;
	struct msdos_dir_entry	  * temp_de;
	char						c;
	unsigned long				temp_idev, temp_inr;
	int							ret_val = 0, temp_flag, temp_i;

	if (dir_file.f_count)
		return -1;
	if (!(temp_dir = msdos_namei(pathname)))
		return -1;
	if (!S_MSDOS_ISDIR(temp_dir->i_mode))
	{
		msdos_iput(temp_dir);
		return -1;
	}

	if (basename)
	{
		for (current_namelen = 0 ; (c = get_gs_byte(basename++)); current_namelen++)
		{
			if (current_namelen < MSDOS_NAME_LEN + 1)
				current_name[current_namelen] = c;
		}
		if (!buf || (length < MSDOS_NAME_LEN + 11) || !change_current_name())
		{
			msdos_iput(temp_dir);
			return -1;
		}
		if ((temp_bh = msdos_find_entry(temp_dir,&temp_de)) != NULL)
		{
			current_dir_entry	= *temp_de;
			temp_idev = 0;
			temp_inr  =  temp_bh->b_blocknr * BLOCK_SIZE + ((unsigned long)temp_de) - ((unsigned long)(temp_bh->b_data));
			srelse(temp_bh);

			if (S_MSDOS_ISLABEL(current_dir_entry.dir_mode))
			{
				msdos_iput(temp_dir);
				return -1;
			}
			temp_flag = 0;
			if (current_dir_type == 2)
				temp_flag = 1;
			if (!(temp_inode = msdos_iget(&current_dir_entry,temp_inr,temp_flag)))
			{
				msdos_iput(temp_dir);
				return -1;
			}

			if (S_MSDOS_ISDIR(temp_inode->i_mode))
			{
				msdos_iput(temp_dir);
				temp_dir = temp_inode;
			}
			else
			{
				for (temp_i = 0; temp_i < MSDOS_NAME_LEN; temp_i++)
					current_name[temp_i] = current_dir_entry.dir_name[temp_i];
				change_current_name0();

				put_gs_byte(1,buf++);
				for (temp_i = 0; temp_i < MSDOS_NAME_LEN + 1; temp_i++)
					put_gs_byte(current_name[temp_i],buf++);
				put_gs_byte(current_dir_entry.dir_mode,buf++);
				put_gs_long(current_dir_entry.dir_mtime,(long *)buf);
				buf = buf + 4;
				put_gs_long(current_dir_entry.dir_size,(long *)buf);
				buf = buf + 4;
				msdos_iput(temp_inode);
				ret_val = 1;
			}
		}
		else
		{
			put_gs_byte(0,buf++);
			ret_val = 1;
		}
	}
	dir_file.f_inode = temp_dir;
	dir_file.f_pos   = 0;
	dir_file.f_flag  = 0;
	dir_file.f_count = 1;

	return ret_val;
}

int msdos_sys_dirend(void)
{
	if (dir_file.f_count == 0)
		return -1;
	msdos_iput(dir_file.f_inode);
	dir_file.f_count = 0;

	return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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