0

This would be the function I used

void put_partition_logical_block(int block_num)
{
    // 写入逻辑块前要加上引导块的大小
    fseek(fd, (block_num + 1) * LOGICAL_BLOCK_SIZE, SEEK_SET);
    fwrite(logical_block, LOGICAL_BLOCK_SIZE, 1, fd);
    fflush(fd);
}

void delete_hello(unsigned short id)
{
    struct d_inode inode;
    struct dir_entry dir;

    get_inode(id, &inode);

    for (int i = 0; i < 7; i++)
    {
        for (int j = 0; j < 64; j++)
        {
            get_partition_logical_block(inode.i_zone[i]);
            memcpy(&dir, &logical_block[j * sizeof(dir)], sizeof(dir));
            if (!strcmp(dir.name, "hello.c"))
            {
                memset(&logical_block[j * sizeof(dir)], 0, sizeof(dir));
                put_partition_logical_block(inode.i_zone[i]);
                return;
            }
        }
    }
}

I made sure that it wasn't a permission issue or another program tying up, and that get_partition_logical_block function was fine

0 Answers0