mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 15:26:47 +00:00
增加touch到绝对路径的功能
This commit is contained in:
parent
8c8352e748
commit
d32aa2d99c
@ -90,7 +90,7 @@ struct vfs_dir_entry_t *vfs_path_walk(const char *path, uint64_t flags)
|
|||||||
return parent;
|
return parent;
|
||||||
|
|
||||||
struct vfs_dir_entry_t *dentry;
|
struct vfs_dir_entry_t *dentry;
|
||||||
kdebug("path before walk:%s", path);
|
// kdebug("path before walk:%s", path);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// 提取出下一级待搜索的目录名或文件名,并保存在dEntry_name中
|
// 提取出下一级待搜索的目录名或文件名,并保存在dEntry_name中
|
||||||
@ -107,13 +107,13 @@ struct vfs_dir_entry_t *vfs_path_walk(const char *path, uint64_t flags)
|
|||||||
|
|
||||||
memcpy(dentry->name, (void *)tmp_path, tmp_path_len);
|
memcpy(dentry->name, (void *)tmp_path, tmp_path_len);
|
||||||
dentry->name[tmp_path_len] = '\0';
|
dentry->name[tmp_path_len] = '\0';
|
||||||
kdebug("tmp_path_len=%d, dentry->name= %s", tmp_path_len, dentry->name);
|
// kdebug("tmp_path_len=%d, dentry->name= %s", tmp_path_len, dentry->name);
|
||||||
dentry->name_length = tmp_path_len;
|
dentry->name_length = tmp_path_len;
|
||||||
|
|
||||||
if (parent->dir_inode->inode_ops->lookup(parent->dir_inode, dentry) == NULL)
|
if (parent->dir_inode->inode_ops->lookup(parent->dir_inode, dentry) == NULL)
|
||||||
{
|
{
|
||||||
// 搜索失败
|
// 搜索失败
|
||||||
kerror("cannot find the file/dir : %s", dentry->name);
|
// kerror("cannot find the file/dir : %s", dentry->name);
|
||||||
kfree(dentry->name);
|
kfree(dentry->name);
|
||||||
kfree(dentry);
|
kfree(dentry);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -179,7 +179,7 @@ int vfs_fill_dentry(void *buf, ino_t d_ino, char *name, int namelen, unsigned ch
|
|||||||
uint64_t sys_mkdir(struct pt_regs *regs)
|
uint64_t sys_mkdir(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
const char *path = (const char *)regs->r8;
|
const char *path = (const char *)regs->r8;
|
||||||
kdebug("path = %s", path);
|
// kdebug("path = %s", path);
|
||||||
mode_t mode = (mode_t)regs->r9;
|
mode_t mode = (mode_t)regs->r9;
|
||||||
uint32_t pathlen;
|
uint32_t pathlen;
|
||||||
if (regs->cs & USER_CS)
|
if (regs->cs & USER_CS)
|
||||||
@ -215,7 +215,7 @@ uint64_t sys_mkdir(struct pt_regs *regs)
|
|||||||
else
|
else
|
||||||
strncpy(buf, path, last_slash);
|
strncpy(buf, path, last_slash);
|
||||||
buf[last_slash + 1] = '\0';
|
buf[last_slash + 1] = '\0';
|
||||||
kdebug("to walk: %s", buf);
|
// kdebug("to walk: %s", buf);
|
||||||
// 查找父目录
|
// 查找父目录
|
||||||
struct vfs_dir_entry_t *parent_dir = vfs_path_walk(buf, 0);
|
struct vfs_dir_entry_t *parent_dir = vfs_path_walk(buf, 0);
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ uint64_t sys_mkdir(struct pt_regs *regs)
|
|||||||
{
|
{
|
||||||
// 目录中已有对应的文件夹
|
// 目录中已有对应的文件夹
|
||||||
kwarn("Dir '%s' aleardy exists.", path);
|
kwarn("Dir '%s' aleardy exists.", path);
|
||||||
kdebug("name = %s", vfs_path_walk((const char *)path, 0)->name) return -EEXIST;
|
return -EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vfs_dir_entry_t *subdir_dentry = (struct vfs_dir_entry_t *)kmalloc(sizeof(struct vfs_dir_entry_t), 0);
|
struct vfs_dir_entry_t *subdir_dentry = (struct vfs_dir_entry_t *)kmalloc(sizeof(struct vfs_dir_entry_t), 0);
|
||||||
@ -251,12 +251,12 @@ uint64_t sys_mkdir(struct pt_regs *regs)
|
|||||||
}
|
}
|
||||||
++subdir_dentry->name_length;
|
++subdir_dentry->name_length;
|
||||||
|
|
||||||
kdebug("last_slash=%d", last_slash);
|
// kdebug("last_slash=%d", last_slash);
|
||||||
kdebug("name=%s", path + last_slash + 1);
|
// kdebug("name=%s", path + last_slash + 1);
|
||||||
subdir_dentry->parent = parent_dir;
|
subdir_dentry->parent = parent_dir;
|
||||||
kdebug("to mkdir, parent name=%s", parent_dir->name);
|
// kdebug("to mkdir, parent name=%s", parent_dir->name);
|
||||||
int retval = parent_dir->dir_inode->inode_ops->mkdir(parent_dir->dir_inode, subdir_dentry, 0);
|
int retval = parent_dir->dir_inode->inode_ops->mkdir(parent_dir->dir_inode, subdir_dentry, 0);
|
||||||
list_add(&parent_dir->subdirs_list, &subdir_dentry->child_node_list);
|
list_add(&parent_dir->subdirs_list, &subdir_dentry->child_node_list);
|
||||||
kdebug("retval = %d", retval);
|
// kdebug("retval = %d", retval);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -139,7 +139,7 @@ struct vfs_dir_entry_t *fat32_lookup(struct vfs_index_node_t *parent_inode, stru
|
|||||||
|
|
||||||
if (js >= dest_dentry->name_length) // 找到需要的目录项,返回
|
if (js >= dest_dentry->name_length) // 找到需要的目录项,返回
|
||||||
{
|
{
|
||||||
kdebug("found target long name.");
|
// kdebug("found target long name.");
|
||||||
|
|
||||||
goto find_lookup_success;
|
goto find_lookup_success;
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ struct vfs_dir_entry_t *fat32_lookup(struct vfs_index_node_t *parent_inode, stru
|
|||||||
js = 0;
|
js = 0;
|
||||||
for (int x = 0; x < 8; ++x)
|
for (int x = 0; x < 8; ++x)
|
||||||
{
|
{
|
||||||
kdebug("no long name, comparing short name");
|
// kdebug("no long name, comparing short name");
|
||||||
// kdebug("value = %#02x", tmp_dEntry->DIR_Name[x]);
|
// kdebug("value = %#02x", tmp_dEntry->DIR_Name[x]);
|
||||||
switch (tmp_dEntry->DIR_Name[x])
|
switch (tmp_dEntry->DIR_Name[x])
|
||||||
{
|
{
|
||||||
@ -627,38 +627,7 @@ long fat32_read(struct vfs_file_t *file_ptr, char *buf, int64_t count, long *pos
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 在磁盘中寻找一个空闲的簇
|
|
||||||
*
|
|
||||||
* @param fsbi fat32超级块信息结构体
|
|
||||||
* @return uint64_t 空闲簇号(找不到则返回0)
|
|
||||||
*/
|
|
||||||
// uint64_t fat32_find_available_cluster(fat32_sb_info_t *fsbi)
|
|
||||||
// {
|
|
||||||
// uint64_t sec_per_fat = fsbi->sec_per_FAT;
|
|
||||||
|
|
||||||
// // 申请1扇区的缓冲区
|
|
||||||
// uint32_t *buf = (uint32_t *)kmalloc(fsbi->bytes_per_sec, 0);
|
|
||||||
// int ent_per_sec = (fsbi->bytes_per_sec >> 2);
|
|
||||||
// for (int i = 0; i < sec_per_fat; ++i)
|
|
||||||
// {
|
|
||||||
// memset(buf, 0, fsbi->bytes_per_sec);
|
|
||||||
|
|
||||||
// ahci_operation.transfer(AHCI_CMD_READ_DMA_EXT, fsbi->FAT1_base_sector + i, 1, (uint64_t)buf, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
|
||||||
// // 依次检查簇是否空闲
|
|
||||||
// for (int j = 0; j < ent_per_sec; ++j)
|
|
||||||
// {
|
|
||||||
// // 找到空闲簇
|
|
||||||
// if ((buf[j] & 0x0fffffff) == 0)
|
|
||||||
// {
|
|
||||||
// kfree(buf);
|
|
||||||
// return i * ent_per_sec + j;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// kfree(buf);
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 向fat32文件系统写入数据
|
* @brief 向fat32文件系统写入数据
|
||||||
@ -677,8 +646,6 @@ long fat32_write(struct vfs_file_t *file_ptr, char *buf, int64_t count, long *po
|
|||||||
uint32_t cluster = finode->first_clus;
|
uint32_t cluster = finode->first_clus;
|
||||||
int64_t flags = 0;
|
int64_t flags = 0;
|
||||||
|
|
||||||
// kdebug("fsbi->bytes_per_clus=%d fsbi->sec_per_clus=%d finode->first_clus=%d *position=%d", fsbi->bytes_per_clus, fsbi->sec_per_clus, finode->first_clus, *position);
|
|
||||||
// kdebug("buf=%s", buf);
|
|
||||||
// clus offset in file
|
// clus offset in file
|
||||||
uint64_t clus_offset_in_file = (*position) / fsbi->bytes_per_clus;
|
uint64_t clus_offset_in_file = (*position) / fsbi->bytes_per_clus;
|
||||||
// bytes offset in clus
|
// bytes offset in clus
|
||||||
@ -686,10 +653,6 @@ long fat32_write(struct vfs_file_t *file_ptr, char *buf, int64_t count, long *po
|
|||||||
|
|
||||||
if (!cluster) // 起始簇号为0,说明是空文件
|
if (!cluster) // 起始簇号为0,说明是空文件
|
||||||
{
|
{
|
||||||
// // 找一个可用的簇
|
|
||||||
// cluster = fat32_find_available_cluster(fsbi);
|
|
||||||
// flags = 1;
|
|
||||||
|
|
||||||
// 分配空闲簇
|
// 分配空闲簇
|
||||||
if (fat32_alloc_clusters(file_ptr->dEntry->dir_inode, &cluster, 1) != 0)
|
if (fat32_alloc_clusters(file_ptr->dEntry->dir_inode, &cluster, 1) != 0)
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
@ -705,14 +668,7 @@ long fat32_write(struct vfs_file_t *file_ptr, char *buf, int64_t count, long *po
|
|||||||
if (!cluster)
|
if (!cluster)
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
|
||||||
// if (flags) // 空文件
|
|
||||||
// {
|
|
||||||
// // kdebug("empty file");
|
|
||||||
// finode->first_clus = cluster;
|
|
||||||
// // 写入目录项
|
|
||||||
// file_ptr->dEntry->dir_inode->sb->sb_ops->write_inode(file_ptr->dEntry->dir_inode);
|
|
||||||
// fat32_write_FAT_entry(fsbi, cluster, 0x0ffffff8); // 写入fat表项
|
|
||||||
// }
|
|
||||||
|
|
||||||
int64_t bytes_remain = count;
|
int64_t bytes_remain = count;
|
||||||
|
|
||||||
@ -793,7 +749,7 @@ long fat32_write(struct vfs_file_t *file_ptr, char *buf, int64_t count, long *po
|
|||||||
{
|
{
|
||||||
file_ptr->dEntry->dir_inode->file_size = *position;
|
file_ptr->dEntry->dir_inode->file_size = *position;
|
||||||
file_ptr->dEntry->dir_inode->sb->sb_ops->write_inode(file_ptr->dEntry->dir_inode);
|
file_ptr->dEntry->dir_inode->sb->sb_ops->write_inode(file_ptr->dEntry->dir_inode);
|
||||||
kdebug("new file size=%ld", *position);
|
// kdebug("new file size=%ld", *position);
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(tmp_buffer);
|
kfree(tmp_buffer);
|
||||||
@ -875,10 +831,9 @@ long fat32_create(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_t
|
|||||||
|
|
||||||
int64_t retval = 0;
|
int64_t retval = 0;
|
||||||
|
|
||||||
kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
|
||||||
// ======== 检验名称的合法性
|
// ======== 检验名称的合法性
|
||||||
retval = fat32_check_name_available(dest_dEntry->name, dest_dEntry->name_length, 0);
|
retval = fat32_check_name_available(dest_dEntry->name, dest_dEntry->name_length, 0);
|
||||||
kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
|
||||||
if (retval != 0)
|
if (retval != 0)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
@ -913,7 +868,7 @@ long fat32_create(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_t
|
|||||||
uint64_t tmp_parent_dentry_clus = 0;
|
uint64_t tmp_parent_dentry_clus = 0;
|
||||||
// 寻找空闲目录项
|
// 寻找空闲目录项
|
||||||
struct fat32_Directory_t *empty_fat32_dentry = fat32_find_empty_dentry(parent_inode, cnt_longname + 1, 0, &tmp_dentry_sector, &tmp_parent_dentry_clus, &tmp_dentry_clus_buf_addr);
|
struct fat32_Directory_t *empty_fat32_dentry = fat32_find_empty_dentry(parent_inode, cnt_longname + 1, 0, &tmp_dentry_sector, &tmp_parent_dentry_clus, &tmp_dentry_clus_buf_addr);
|
||||||
kdebug("found empty dentry, cnt_longname=%ld", cnt_longname);
|
// kdebug("found empty dentry, cnt_longname=%ld", cnt_longname);
|
||||||
|
|
||||||
finode->first_clus = 0;
|
finode->first_clus = 0;
|
||||||
finode->dEntry_location_clus = tmp_parent_dentry_clus;
|
finode->dEntry_location_clus = tmp_parent_dentry_clus;
|
||||||
@ -927,21 +882,21 @@ long fat32_create(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_t
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
kdebug("new dir clus=%ld", new_dir_clus);
|
// kdebug("new dir clus=%ld", new_dir_clus);
|
||||||
kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
// kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
||||||
// ====== 填写短目录项
|
// ====== 填写短目录项
|
||||||
fat32_fill_shortname(dest_dEntry, empty_fat32_dentry, new_dir_clus);
|
fat32_fill_shortname(dest_dEntry, empty_fat32_dentry, new_dir_clus);
|
||||||
kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
// kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
||||||
|
|
||||||
// 计算校验和
|
// 计算校验和
|
||||||
uint8_t short_dentry_ChkSum = fat32_ChkSum(empty_fat32_dentry->DIR_Name);
|
uint8_t short_dentry_ChkSum = fat32_ChkSum(empty_fat32_dentry->DIR_Name);
|
||||||
|
|
||||||
kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
// kdebug("dest_dEntry->name=%s",dest_dEntry->name);
|
||||||
// ======== 填写长目录项
|
// ======== 填写长目录项
|
||||||
fat32_fill_longname(dest_dEntry, (struct fat32_LongDirectory_t *)(empty_fat32_dentry - 1), short_dentry_ChkSum, cnt_longname);
|
fat32_fill_longname(dest_dEntry, (struct fat32_LongDirectory_t *)(empty_fat32_dentry - 1), short_dentry_ChkSum, cnt_longname);
|
||||||
|
|
||||||
// ====== 将目录项写回磁盘
|
// ====== 将目录项写回磁盘
|
||||||
kdebug("tmp_dentry_sector=%ld", tmp_dentry_sector);
|
// kdebug("tmp_dentry_sector=%ld", tmp_dentry_sector);
|
||||||
ahci_operation.transfer(AHCI_CMD_WRITE_DMA_EXT, tmp_dentry_sector, fsbi->sec_per_clus, tmp_dentry_clus_buf_addr, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
ahci_operation.transfer(AHCI_CMD_WRITE_DMA_EXT, tmp_dentry_sector, fsbi->sec_per_clus, tmp_dentry_clus_buf_addr, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
||||||
|
|
||||||
// 注意:parent字段需要在调用函数的地方进行设置
|
// 注意:parent字段需要在调用函数的地方进行设置
|
||||||
@ -992,7 +947,7 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
|||||||
uint64_t tmp_parent_dentry_clus = 0;
|
uint64_t tmp_parent_dentry_clus = 0;
|
||||||
// 寻找空闲目录项
|
// 寻找空闲目录项
|
||||||
struct fat32_Directory_t *empty_fat32_dentry = fat32_find_empty_dentry(parent_inode, cnt_longname + 1, 0, &tmp_dentry_sector, &tmp_parent_dentry_clus, &tmp_dentry_clus_buf_addr);
|
struct fat32_Directory_t *empty_fat32_dentry = fat32_find_empty_dentry(parent_inode, cnt_longname + 1, 0, &tmp_dentry_sector, &tmp_parent_dentry_clus, &tmp_dentry_clus_buf_addr);
|
||||||
kdebug("found empty dentry, cnt_longname=%ld", cnt_longname);
|
|
||||||
|
|
||||||
// ====== 初始化inode =======
|
// ====== 初始化inode =======
|
||||||
struct vfs_index_node_t *inode = (struct vfs_index_node_t *)kmalloc(sizeof(struct vfs_index_node_t), 0);
|
struct vfs_index_node_t *inode = (struct vfs_index_node_t *)kmalloc(sizeof(struct vfs_index_node_t), 0);
|
||||||
@ -1012,7 +967,7 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
|||||||
p->first_clus = 0;
|
p->first_clus = 0;
|
||||||
p->dEntry_location_clus = tmp_parent_dentry_clus;
|
p->dEntry_location_clus = tmp_parent_dentry_clus;
|
||||||
p->dEntry_location_clus_offset = empty_fat32_dentry - (struct fat32_Directory_t *)tmp_dentry_clus_buf_addr;
|
p->dEntry_location_clus_offset = empty_fat32_dentry - (struct fat32_Directory_t *)tmp_dentry_clus_buf_addr;
|
||||||
kdebug(" p->dEntry_location_clus_offset=%d", p->dEntry_location_clus_offset);
|
// kdebug(" p->dEntry_location_clus_offset=%d", p->dEntry_location_clus_offset);
|
||||||
// todo: 填写完全fat32_inode_info的信息
|
// todo: 填写完全fat32_inode_info的信息
|
||||||
|
|
||||||
// 初始化dentry信息
|
// 初始化dentry信息
|
||||||
@ -1029,7 +984,7 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
kdebug("new dir clus=%ld", new_dir_clus);
|
// kdebug("new dir clus=%ld", new_dir_clus);
|
||||||
|
|
||||||
// ====== 填写短目录项
|
// ====== 填写短目录项
|
||||||
fat32_fill_shortname(dEntry, empty_fat32_dentry, new_dir_clus);
|
fat32_fill_shortname(dEntry, empty_fat32_dentry, new_dir_clus);
|
||||||
@ -1041,11 +996,11 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
|||||||
fat32_fill_longname(dEntry, (struct fat32_LongDirectory_t *)(empty_fat32_dentry - 1), short_dentry_ChkSum, cnt_longname);
|
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);
|
// kdebug("tmp_dentry_sector=%ld", tmp_dentry_sector);
|
||||||
ahci_operation.transfer(AHCI_CMD_WRITE_DMA_EXT, tmp_dentry_sector, fsbi->sec_per_clus, tmp_dentry_clus_buf_addr, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
ahci_operation.transfer(AHCI_CMD_WRITE_DMA_EXT, tmp_dentry_sector, fsbi->sec_per_clus, tmp_dentry_clus_buf_addr, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
||||||
// ====== 初始化新的文件夹的目录项 =====
|
// ====== 初始化新的文件夹的目录项 =====
|
||||||
{
|
{
|
||||||
kdebug("to create dot and dot dot.");
|
// kdebug("to create dot and dot dot.");
|
||||||
void *buf = kmalloc(fsbi->bytes_per_clus, 0);
|
void *buf = kmalloc(fsbi->bytes_per_clus, 0);
|
||||||
struct fat32_Directory_t *new_dir_dentries = (struct fat32_Directory_t *)buf;
|
struct fat32_Directory_t *new_dir_dentries = (struct fat32_Directory_t *)buf;
|
||||||
memset((void *)new_dir_dentries, 0, fsbi->bytes_per_clus);
|
memset((void *)new_dir_dentries, 0, fsbi->bytes_per_clus);
|
||||||
@ -1074,7 +1029,7 @@ int64_t fat32_mkdir(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_
|
|||||||
// 写入磁盘
|
// 写入磁盘
|
||||||
|
|
||||||
uint64_t sector = fsbi->first_data_sector + (new_dir_clus - 2) * fsbi->sec_per_clus;
|
uint64_t sector = fsbi->first_data_sector + (new_dir_clus - 2) * fsbi->sec_per_clus;
|
||||||
kdebug("add dot and dot dot: sector=%ld", sector);
|
// kdebug("add dot and dot dot: sector=%ld", sector);
|
||||||
ahci_operation.transfer(AHCI_CMD_WRITE_DMA_EXT, sector, fsbi->sec_per_clus, (uint64_t)buf, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
ahci_operation.transfer(AHCI_CMD_WRITE_DMA_EXT, sector, fsbi->sec_per_clus, (uint64_t)buf, fsbi->ahci_ctrl_num, fsbi->ahci_port_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ int fat32_alloc_clusters(struct vfs_index_node_t *inode, uint32_t *clusters, int
|
|||||||
// 找到空闲簇
|
// 找到空闲簇
|
||||||
if ((buf[j] & 0x0fffffff) == 0)
|
if ((buf[j] & 0x0fffffff) == 0)
|
||||||
{
|
{
|
||||||
kdebug("clus[%d] = %d", clus_idx, i * ent_per_sec + j);
|
// kdebug("clus[%d] = %d", clus_idx, i * ent_per_sec + j);
|
||||||
clusters[clus_idx] = i * ent_per_sec + j;
|
clusters[clus_idx] = i * ent_per_sec + j;
|
||||||
++clus_idx;
|
++clus_idx;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ done:;
|
|||||||
// 写入fat表
|
// 写入fat表
|
||||||
for (int i = idx; i < num_clusters; ++i)
|
for (int i = idx; i < num_clusters; ++i)
|
||||||
{
|
{
|
||||||
kdebug("write cluster i=%d : cluster=%d, value= %d", i, cluster, clusters[i]);
|
// kdebug("write cluster i=%d : cluster=%d, value= %d", i, cluster, clusters[i]);
|
||||||
fat32_write_FAT_entry(fsbi, cluster, clusters[i]);
|
fat32_write_FAT_entry(fsbi, cluster, clusters[i]);
|
||||||
cluster = clusters[i];
|
cluster = clusters[i];
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ uint32_t fat32_write_FAT_entry(fat32_sb_info_t *fsbi, uint32_t cluster, uint32_t
|
|||||||
*/
|
*/
|
||||||
struct fat32_Directory_t *fat32_find_empty_dentry(struct vfs_index_node_t *parent_inode, uint32_t num, uint32_t mode, uint32_t *res_sector, uint64_t *res_cluster, uint64_t *res_data_buf_base)
|
struct fat32_Directory_t *fat32_find_empty_dentry(struct vfs_index_node_t *parent_inode, uint32_t num, uint32_t mode, uint32_t *res_sector, uint64_t *res_cluster, uint64_t *res_data_buf_base)
|
||||||
{
|
{
|
||||||
kdebug("find empty_dentry");
|
// kdebug("find empty_dentry");
|
||||||
struct fat32_inode_info_t *finode = (struct fat32_inode_info_t *)parent_inode->private_inode_info;
|
struct fat32_inode_info_t *finode = (struct fat32_inode_info_t *)parent_inode->private_inode_info;
|
||||||
fat32_sb_info_t *fsbi = (fat32_sb_info_t *)parent_inode->sb->private_sb_info;
|
fat32_sb_info_t *fsbi = (fat32_sb_info_t *)parent_inode->sb->private_sb_info;
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ uint64_t sys_open(struct pt_regs *regs)
|
|||||||
// printk_color(ORANGE, BLACK, "Found %s\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", path, ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
|
// printk_color(ORANGE, BLACK, "Found %s\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", path, ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
|
||||||
// else
|
// else
|
||||||
// printk_color(ORANGE, BLACK, "Can`t find file\n");
|
// printk_color(ORANGE, BLACK, "Can`t find file\n");
|
||||||
kdebug("flags=%#018lx", flags);
|
// kdebug("flags=%#018lx", flags);
|
||||||
if (dentry == NULL && flags & O_CREAT)
|
if (dentry == NULL && flags & O_CREAT)
|
||||||
{
|
{
|
||||||
// 先找到倒数第二级目录
|
// 先找到倒数第二级目录
|
||||||
@ -159,7 +159,7 @@ uint64_t sys_open(struct pt_regs *regs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct vfs_dir_entry_t *parent_dentry = NULL;
|
struct vfs_dir_entry_t *parent_dentry = NULL;
|
||||||
kdebug("tmp_index=%d", tmp_index);
|
// kdebug("tmp_index=%d", tmp_index);
|
||||||
if (tmp_index > 0)
|
if (tmp_index > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ uint64_t sys_open(struct pt_regs *regs)
|
|||||||
dentry->name = (char *)kmalloc(dentry->name_length, 0);
|
dentry->name = (char *)kmalloc(dentry->name_length, 0);
|
||||||
memset(dentry->name, 0, dentry->name_length);
|
memset(dentry->name, 0, dentry->name_length);
|
||||||
strncpy(dentry->name, path + tmp_index + 1, dentry->name_length);
|
strncpy(dentry->name, path + tmp_index + 1, dentry->name_length);
|
||||||
kdebug("to create new file:%s namelen=%d", dentry->name, dentry->name_length)
|
// kdebug("to create new file:%s namelen=%d", dentry->name, dentry->name_length)
|
||||||
dentry->parent = parent_dentry;
|
dentry->parent = parent_dentry;
|
||||||
uint64_t retval = parent_dentry->dir_inode->inode_ops->create(parent_dentry->dir_inode, dentry, 0);
|
uint64_t retval = parent_dentry->dir_inode->inode_ops->create(parent_dentry->dir_inode, dentry, 0);
|
||||||
if (retval != 0)
|
if (retval != 0)
|
||||||
@ -197,7 +197,7 @@ uint64_t sys_open(struct pt_regs *regs)
|
|||||||
list_init(&dentry->child_node_list);
|
list_init(&dentry->child_node_list);
|
||||||
list_init(&dentry->subdirs_list);
|
list_init(&dentry->subdirs_list);
|
||||||
list_add(&parent_dentry->subdirs_list, &dentry->child_node_list);
|
list_add(&parent_dentry->subdirs_list, &dentry->child_node_list);
|
||||||
kdebug("created.");
|
// kdebug("created.");
|
||||||
}
|
}
|
||||||
kfree(path);
|
kfree(path);
|
||||||
if (dentry == NULL)
|
if (dentry == NULL)
|
||||||
@ -466,12 +466,7 @@ uint64_t sys_brk(struct pt_regs *regs)
|
|||||||
else
|
else
|
||||||
offset = -(int64_t)(current_pcb->mm->brk_end - new_brk);
|
offset = -(int64_t)(current_pcb->mm->brk_end - new_brk);
|
||||||
|
|
||||||
/*
|
|
||||||
if (offset < 0)
|
|
||||||
{
|
|
||||||
kdebug("decrease brk, offset = %#010lx", (uint64_t)(-offset));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
new_brk = mm_do_brk(current_pcb->mm->brk_end, offset); // 扩展堆内存空间
|
new_brk = mm_do_brk(current_pcb->mm->brk_end, offset); // 扩展堆内存空间
|
||||||
|
|
||||||
@ -545,7 +540,7 @@ uint64_t sys_reboot(struct pt_regs *regs)
|
|||||||
uint64_t sys_chdir(struct pt_regs *regs)
|
uint64_t sys_chdir(struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
char *dest_path = (char *)regs->r8;
|
char *dest_path = (char *)regs->r8;
|
||||||
kdebug("dest_path=%s", dest_path);
|
// kdebug("dest_path=%s", dest_path);
|
||||||
// 检查目标路径是否为NULL
|
// 检查目标路径是否为NULL
|
||||||
if (dest_path == NULL)
|
if (dest_path == NULL)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
@ -579,14 +574,14 @@ uint64_t sys_chdir(struct pt_regs *regs)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
strncpy(path, dest_path, dest_path_len + 1);
|
strncpy(path, dest_path, dest_path_len + 1);
|
||||||
kdebug("chdir: path = %s", path);
|
// kdebug("chdir: path = %s", path);
|
||||||
struct vfs_dir_entry_t *dentry = vfs_path_walk(path, 0);
|
struct vfs_dir_entry_t *dentry = vfs_path_walk(path, 0);
|
||||||
|
|
||||||
kfree(path);
|
kfree(path);
|
||||||
|
|
||||||
if (dentry == NULL)
|
if (dentry == NULL)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
kdebug("dentry->name=%s, namelen=%d", dentry->name, dentry->name_length);
|
// kdebug("dentry->name=%s, namelen=%d", dentry->name, dentry->name_length);
|
||||||
// 目标不是目录
|
// 目标不是目录
|
||||||
if (dentry->dir_inode->attribute != VFS_ATTR_DIR)
|
if (dentry->dir_inode->attribute != VFS_ATTR_DIR)
|
||||||
return -ENOTDIR;
|
return -ENOTDIR;
|
||||||
|
@ -330,14 +330,26 @@ int shell_cmd_cat(int argc, char **argv)
|
|||||||
* @param argv
|
* @param argv
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
// todo:
|
|
||||||
int shell_cmd_touch(int argc, char **argv)
|
int shell_cmd_touch(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int path_len = 0;
|
int path_len = 0;
|
||||||
char *file_path = get_target_filepath(argv[1], &path_len);
|
char *file_path;
|
||||||
|
if (argv[1][0] == '/')
|
||||||
|
file_path = argv[1];
|
||||||
|
else
|
||||||
|
file_path = get_target_filepath(argv[1], &path_len);
|
||||||
|
|
||||||
// 打开文件
|
// 打开文件
|
||||||
int fd = open(file_path, O_CREAT);
|
int fd = open(file_path, O_CREAT);
|
||||||
|
switch (fd)
|
||||||
|
{
|
||||||
|
case -ENOENT:
|
||||||
|
put_string("Parent dir not exists.\n", COLOR_RED, COLOR_BLACK);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
if (argv != NULL)
|
if (argv != NULL)
|
||||||
free(argv);
|
free(argv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user