mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 07:06:47 +00:00
🔧 将填充长短目录项的代码单独提取出来
This commit is contained in:
parent
440b3c917f
commit
fc3fbf7acc
@ -930,10 +930,13 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
||||
kdebug(" p->dEntry_location_clus_offset=%d", p->dEntry_location_clus_offset);
|
||||
// todo: 填写完全fat32_inode_info的信息
|
||||
|
||||
// ====== 为新的文件夹分配一个簇 =======
|
||||
// uint32_t new_dir_clus = fat32_find_available_cluster(fsbi);
|
||||
// kdebug("new_dir_clus=%d", new_dir_clus);
|
||||
// fat32_write_FAT_entry(fsbi, new_dir_clus, 0x0ffffff8);
|
||||
|
||||
// 初始化dentry信息
|
||||
list_init(&dEntry->child_node_list);
|
||||
list_init(&dEntry->subdirs_list);
|
||||
dEntry->dir_ops = &fat32_dEntry_ops;
|
||||
dEntry->dir_inode = inode;
|
||||
|
||||
|
||||
// ====== 为新的文件夹分配一个簇 =======
|
||||
uint32_t new_dir_clus;
|
||||
@ -946,75 +949,13 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
||||
kdebug("new dir clus=%ld", new_dir_clus);
|
||||
|
||||
// ====== 填写短目录项
|
||||
memset(empty_fat32_dentry, 0, sizeof(struct fat32_Directory_t));
|
||||
{
|
||||
int tmp_index = 0;
|
||||
// kdebug("dEntry->name_length=%d", dEntry->name_length);
|
||||
for (tmp_index = 0; tmp_index < min(8, dEntry->name_length); ++tmp_index)
|
||||
{
|
||||
if (dEntry->name[tmp_index] == '.')
|
||||
break;
|
||||
if (fat32_check_char_available_in_short_name(dEntry->name[tmp_index], tmp_index))
|
||||
empty_fat32_dentry->DIR_Name[tmp_index] = dEntry->name[tmp_index];
|
||||
else
|
||||
empty_fat32_dentry->DIR_Name[tmp_index] = 0x20;
|
||||
}
|
||||
|
||||
// 不满的部分使用0x20填充
|
||||
while (tmp_index < 11)
|
||||
{
|
||||
// kdebug("tmp index = %d", tmp_index);
|
||||
dEntry->name[tmp_index] = 0x20;
|
||||
++tmp_index;
|
||||
}
|
||||
}
|
||||
|
||||
empty_fat32_dentry->DIR_Attr = ATTR_DIRECTORY;
|
||||
empty_fat32_dentry->DIR_FileSize = fsbi->bytes_per_clus;
|
||||
empty_fat32_dentry->DIR_FstClusHI = (uint16_t)((new_dir_clus >> 16) & 0x0fff);
|
||||
empty_fat32_dentry->DIR_FstClusLO = (uint16_t)(new_dir_clus & 0xffff);
|
||||
fat32_fill_shortname(dEntry, empty_fat32_dentry, new_dir_clus);
|
||||
|
||||
// 计算校验和
|
||||
uint8_t short_dentry_ChkSum = fat32_ChkSum(empty_fat32_dentry->DIR_Name);
|
||||
// todo: 填写短目录项中的时间信息
|
||||
|
||||
// ======== 填写长目录项
|
||||
uint32_t current_name_index = 0;
|
||||
struct fat32_LongDirectory_t *Ldentry = (struct fat32_LongDirectory_t *)(empty_fat32_dentry);
|
||||
for (int i = 1; i <= cnt_longname; ++i)
|
||||
{
|
||||
--Ldentry;
|
||||
Ldentry->LDIR_Ord = i;
|
||||
|
||||
for (int j = 0; j < 5; ++j, ++current_name_index)
|
||||
{
|
||||
if (current_name_index < dEntry->name_length)
|
||||
Ldentry->LDIR_Name1[j] = dEntry->name[current_name_index];
|
||||
else
|
||||
Ldentry->LDIR_Name1[j] = 0xffff;
|
||||
}
|
||||
for (int j = 0; j < 6; ++j, ++current_name_index)
|
||||
{
|
||||
if (current_name_index < dEntry->name_length)
|
||||
Ldentry->LDIR_Name2[j] = dEntry->name[current_name_index];
|
||||
else
|
||||
Ldentry->LDIR_Name2[j] = 0xffff;
|
||||
}
|
||||
for (int j = 0; j < 2; ++j, ++current_name_index)
|
||||
{
|
||||
if (current_name_index < dEntry->name_length)
|
||||
Ldentry->LDIR_Name3[j] = dEntry->name[current_name_index];
|
||||
else
|
||||
Ldentry->LDIR_Name3[j] = 0xffff;
|
||||
}
|
||||
Ldentry->LDIR_Attr = ATTR_LONG_NAME;
|
||||
Ldentry->LDIR_FstClusLO = 0;
|
||||
Ldentry->LDIR_Type = 0;
|
||||
Ldentry->LDIR_Chksum = short_dentry_ChkSum;
|
||||
}
|
||||
|
||||
// 最后一个长目录项的ord要|=0x40
|
||||
Ldentry->LDIR_Ord |= 0x40;
|
||||
fat32_fill_longname(dEntry, (struct fat32_LongDirectory_t * )(empty_fat32_dentry-1), short_dentry_ChkSum, cnt_longname);
|
||||
|
||||
// ====== 将目录项写回磁盘
|
||||
kdebug("tmp_dentry_sector=%ld", tmp_dentry_sector);
|
||||
@ -1054,11 +995,7 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
||||
ahci_operation.transfer(AHCI_CMD_WRITE_DMA_EXT, sector, fsbi->sec_per_clus, (uint64_t)buf, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
||||
}
|
||||
|
||||
// 初始化dentry信息
|
||||
list_init(&dEntry->child_node_list);
|
||||
list_init(&dEntry->subdirs_list);
|
||||
dEntry->dir_ops = &fat32_dEntry_ops;
|
||||
dEntry->dir_inode = inode;
|
||||
|
||||
|
||||
// 注意:parent字段需要在调用函数的地方进行设置
|
||||
// 注意:需要将当前dentry加入父目录的subdirs_list
|
||||
|
@ -303,3 +303,95 @@ bool fat32_check_char_available_in_short_name(const char c, int index)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 填充短目录项的函数
|
||||
*
|
||||
* @param dEntry 目标dentry
|
||||
* @param target 目标dentry对应的短目录项
|
||||
* @param cluster 短目录项对应的文件/文件夹起始簇
|
||||
*/
|
||||
void fat32_fill_shortname(struct vfs_dir_entry_t *dEntry, struct fat32_Directory_t *target, uint32_t cluster)
|
||||
{
|
||||
memset(target, 0, sizeof(struct fat32_Directory_t));
|
||||
{
|
||||
int tmp_index = 0;
|
||||
// kdebug("dEntry->name_length=%d", dEntry->name_length);
|
||||
for (tmp_index = 0; tmp_index < min(8, dEntry->name_length); ++tmp_index)
|
||||
{
|
||||
if (dEntry->name[tmp_index] == '.')
|
||||
break;
|
||||
if (fat32_check_char_available_in_short_name(dEntry->name[tmp_index], tmp_index))
|
||||
target->DIR_Name[tmp_index] = dEntry->name[tmp_index];
|
||||
else
|
||||
target->DIR_Name[tmp_index] = 0x20;
|
||||
}
|
||||
|
||||
// 不满的部分使用0x20填充
|
||||
while (tmp_index < 11)
|
||||
{
|
||||
// kdebug("tmp index = %d", tmp_index);
|
||||
dEntry->name[tmp_index] = 0x20;
|
||||
++tmp_index;
|
||||
}
|
||||
}
|
||||
|
||||
struct vfs_index_node_t *inode = dEntry->dir_inode;
|
||||
target->DIR_Attr = 0;
|
||||
if (inode->attribute & VFS_ATTR_DIR)
|
||||
target->DIR_Attr |= ATTR_DIRECTORY;
|
||||
|
||||
target->DIR_FileSize = dEntry->dir_inode->file_size;
|
||||
target->DIR_FstClusHI = (uint16_t)((cluster >> 16) & 0x0fff);
|
||||
target->DIR_FstClusLO = (uint16_t)(cluster & 0xffff);
|
||||
|
||||
// todo: 填写短目录项中的时间信息
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 填充长目录项的函数
|
||||
*
|
||||
* @param dEntry 目标dentry
|
||||
* @param target 起始长目录项
|
||||
* @param checksum 短目录项的校验和
|
||||
* @param cnt_longname 总的长目录项的个数
|
||||
*/
|
||||
void fat32_fill_longname(struct vfs_dir_entry_t *dEntry, struct fat32_LongDirectory_t *target, uint8_t checksum, uint32_t cnt_longname)
|
||||
{
|
||||
uint32_t current_name_index = 0;
|
||||
struct fat32_LongDirectory_t *Ldentry = (struct fat32_LongDirectory_t *)(target+1);
|
||||
for (int i = 1; i <= cnt_longname; ++i)
|
||||
{
|
||||
--Ldentry;
|
||||
Ldentry->LDIR_Ord = i;
|
||||
|
||||
for (int j = 0; j < 5; ++j, ++current_name_index)
|
||||
{
|
||||
if (current_name_index < dEntry->name_length)
|
||||
Ldentry->LDIR_Name1[j] = dEntry->name[current_name_index];
|
||||
else
|
||||
Ldentry->LDIR_Name1[j] = 0xffff;
|
||||
}
|
||||
for (int j = 0; j < 6; ++j, ++current_name_index)
|
||||
{
|
||||
if (current_name_index < dEntry->name_length)
|
||||
Ldentry->LDIR_Name2[j] = dEntry->name[current_name_index];
|
||||
else
|
||||
Ldentry->LDIR_Name2[j] = 0xffff;
|
||||
}
|
||||
for (int j = 0; j < 2; ++j, ++current_name_index)
|
||||
{
|
||||
if (current_name_index < dEntry->name_length)
|
||||
Ldentry->LDIR_Name3[j] = dEntry->name[current_name_index];
|
||||
else
|
||||
Ldentry->LDIR_Name3[j] = 0xffff;
|
||||
}
|
||||
Ldentry->LDIR_Attr = ATTR_LONG_NAME;
|
||||
Ldentry->LDIR_FstClusLO = 0;
|
||||
Ldentry->LDIR_Type = 0;
|
||||
Ldentry->LDIR_Chksum = checksum;
|
||||
}
|
||||
|
||||
// 最后一个长目录项的ord要|=0x40
|
||||
Ldentry->LDIR_Ord |= 0x40;
|
||||
}
|
@ -74,3 +74,22 @@ int fat32_check_name_available(const char *name, int namelen, int8_t reserved);
|
||||
* @return false 不合法
|
||||
*/
|
||||
bool fat32_check_char_available_in_short_name(const char c, int index);
|
||||
|
||||
/**
|
||||
* @brief 填充短目录项的函数
|
||||
*
|
||||
* @param dEntry 目标dentry
|
||||
* @param target 目标dentry对应的短目录项
|
||||
* @param cluster 短目录项对应的文件/文件夹起始簇
|
||||
*/
|
||||
void fat32_fill_shortname(struct vfs_dir_entry_t *dEntry, struct fat32_Directory_t *target, uint32_t cluster);
|
||||
|
||||
/**
|
||||
* @brief 填充长目录项的函数
|
||||
*
|
||||
* @param dEntry 目标dentry
|
||||
* @param target 起始长目录项
|
||||
* @param checksum 短目录项的校验和
|
||||
* @param cnt_longname 总的长目录项的个数
|
||||
*/
|
||||
void fat32_fill_longname(struct vfs_dir_entry_t *dEntry, struct fat32_LongDirectory_t *target, uint8_t checksum, uint32_t cnt_longname);
|
Loading…
x
Reference in New Issue
Block a user