📄 msdos_namei.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"
///////////////////////////////////////////////////////////////////////////////////////////////
struct m_inode * msdos_get_dir(const char * pathname)
{
struct m_inode * temp_inode;
struct buffer_head * temp_bh;
struct msdos_dir_entry * temp_de;
const char * thisname;
char c;
unsigned long temp_idev,temp_inr,temp_namelen;
int temp_i, temp_flag;
if (!current_root || !current_root->i_count || !current_pwd || !current_pwd->i_count)
return NULL;
if ((c = get_gs_byte(pathname)) == '\\') {
temp_inode = current_root;
pathname++;
for (temp_i = 0; temp_i <= current_root_pathlength; temp_i++)
current_path[temp_i] = current_root_path[temp_i];
current_pathlength = current_root_pathlength;
} else if (c) {
temp_inode = current_pwd;
for (temp_i = 0; temp_i <= current_pwd_pathlength; temp_i++)
current_path[temp_i] = current_pwd_path[temp_i];
current_pathlength = current_pwd_pathlength;
}
else
return NULL;
temp_inode->i_count++;
while (1) {
thisname = pathname;
if (!S_MSDOS_ISDIR(temp_inode->i_mode))
{
msdos_iput(temp_inode);
return NULL;
}
for(temp_namelen = 0 , current_namelen = 0 ; (c = get_gs_byte(pathname++)) && (c != '\\') ; temp_namelen++, current_namelen++)
{
if (current_namelen < MSDOS_NAME_LEN + 1)
current_name[current_namelen] = c;
current_path[current_pathlength + temp_namelen + 1] = c;
}
current_path[current_pathlength + temp_namelen + 1] = c;
if (!c)
return temp_inode;
if (!change_current_name())
{
msdos_iput(temp_inode);
return NULL;
}
if ((current_dir_type == 1) && (temp_inode == current_root))
continue;
if (!(temp_bh = msdos_find_entry(temp_inode,&temp_de)))
{
msdos_iput(temp_inode);
return 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);
msdos_iput(temp_inode);
if (S_MSDOS_ISLABEL(current_dir_entry.dir_mode))
return NULL;
temp_flag = 0;
switch (current_dir_type)
{
case 0:
current_path[current_pathlength + temp_namelen + 1] = current_pathlength;
current_pathlength = current_pathlength + temp_namelen + 1;
break;
case 1:
break;
case 2:
temp_flag = 1;
current_pathlength = current_path[current_pathlength];
break;
}
if (!(temp_inode = msdos_iget(¤t_dir_entry,temp_inr,temp_flag)))
return NULL;
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////////////////////
struct m_inode * msdos_dir_namei(const char * pathname, int * namelen, const char ** name){ struct m_inode * temp_dir;
const char * basename;
char c; if (!(temp_dir = msdos_get_dir(pathname))) return NULL; basename = pathname; while ((c = get_gs_byte(pathname++)) != 0) if (c == '\\')
basename = pathname;
*namelen = (int)(pathname - basename - 1); *name = basename; return temp_dir;}struct m_inode * msdos_namei(const char * pathname){ struct m_inode * temp_dir; struct buffer_head * temp_bh; struct msdos_dir_entry * temp_de; const char * basename;
unsigned long temp_idev,temp_inr,temp_namelen;
int temp_flag;
if (!(temp_dir = msdos_dir_namei(pathname,&temp_namelen,&basename))) return NULL; if (!temp_namelen) /* special case: '/usr/' etc */ return temp_dir;
if (!change_current_name())
{
msdos_iput(temp_dir);
return NULL;
}
if ((current_dir_type == 1) && (temp_dir == current_root))
return temp_dir;
if (!(temp_bh = msdos_find_entry(temp_dir,&temp_de)))
{
msdos_iput(temp_dir);
return 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);
msdos_iput(temp_dir);
if (S_MSDOS_ISLABEL(current_dir_entry.dir_mode))
return NULL;
temp_flag = 0;
switch (current_dir_type)
{
case 0:
current_path[current_pathlength + temp_namelen + 1] = current_pathlength;
current_pathlength = current_pathlength + temp_namelen + 1;
break;
case 1:
break;
case 2:
temp_flag = 1;
current_pathlength = current_path[current_pathlength];
break;
}
temp_dir = msdos_iget(¤t_dir_entry,temp_inr,temp_flag);
return temp_dir;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -