ext2: remove ext2_dir struct and funcs
This commit is contained in:
parent
746c907a43
commit
017758ea41
4 changed files with 12 additions and 39 deletions
38
fs/ext2.c
38
fs/ext2.c
|
|
@ -1,4 +1,7 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
#include "kernel/lock.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "string.h"
|
||||||
#include <kernel/slab.h>
|
#include <kernel/slab.h>
|
||||||
|
|
||||||
#include <fs/ext2.h>
|
#include <fs/ext2.h>
|
||||||
|
|
@ -7,7 +10,7 @@ static int ext2_read_super(struct block_device *bdev, struct ext2_superblock *sb
|
||||||
{
|
{
|
||||||
char *buf = kmalloc(1024, ALLOC_DMA);
|
char *buf = kmalloc(1024, ALLOC_DMA);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -1;
|
return -ENOMEM;
|
||||||
|
|
||||||
#ifdef KDEBUG
|
#ifdef KDEBUG
|
||||||
kprintf(LOG_DEBUG "Reading superblock from device %s, start_lba: %X\n", bdev->name, bdev->lba_start);
|
kprintf(LOG_DEBUG "Reading superblock from device %s, start_lba: %X\n", bdev->name, bdev->lba_start);
|
||||||
|
|
@ -22,7 +25,7 @@ static int ext2_read_super(struct block_device *bdev, struct ext2_superblock *sb
|
||||||
struct ext2_superblock *sb = (struct ext2_superblock *)buf;
|
struct ext2_superblock *sb = (struct ext2_superblock *)buf;
|
||||||
if (sb->magic != EXT2_SUPER_MAGIC) {
|
if (sb->magic != EXT2_SUPER_MAGIC) {
|
||||||
kfree(buf);
|
kfree(buf);
|
||||||
return -1;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(sb_struct, buf, sizeof(*sb_struct));
|
memcpy(sb_struct, buf, sizeof(*sb_struct));
|
||||||
|
|
@ -62,7 +65,7 @@ int ext2_read_inode(struct ext2fs *fs, struct ext2_inode *out, uint32_t inode)
|
||||||
|
|
||||||
struct ext2_group_desc *gd = kmalloc(fs->block_size, ALLOC_DMA);
|
struct ext2_group_desc *gd = kmalloc(fs->block_size, ALLOC_DMA);
|
||||||
if (!gd)
|
if (!gd)
|
||||||
return -1;
|
return -ENOMEM;
|
||||||
|
|
||||||
int ret = ext2_read_block(fs, gd, fs->sb.first_data_block + 1 + group);
|
int ret = ext2_read_block(fs, gd, fs->sb.first_data_block + 1 + group);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
@ -75,7 +78,7 @@ int ext2_read_inode(struct ext2fs *fs, struct ext2_inode *out, uint32_t inode)
|
||||||
|
|
||||||
struct ext2_inode *in = kmalloc(fs->block_size, ALLOC_DMA);
|
struct ext2_inode *in = kmalloc(fs->block_size, ALLOC_DMA);
|
||||||
if (!in)
|
if (!in)
|
||||||
return -1;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = ext2_read_block(fs, in, inode_table + block);
|
ret = ext2_read_block(fs, in, inode_table + block);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
@ -99,7 +102,7 @@ int ext2_write_inode(struct ext2fs *fs, struct ext2_inode *in, uint32_t inode)
|
||||||
|
|
||||||
struct ext2_group_desc *gd = kmalloc(fs->block_size, ALLOC_DMA);
|
struct ext2_group_desc *gd = kmalloc(fs->block_size, ALLOC_DMA);
|
||||||
if (!gd)
|
if (!gd)
|
||||||
return -1;
|
return -ENOMEM;
|
||||||
|
|
||||||
int ret = ext2_read_block(fs, gd, fs->sb.first_data_block + 1 + group);
|
int ret = ext2_read_block(fs, gd, fs->sb.first_data_block + 1 + group);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
@ -112,7 +115,7 @@ int ext2_write_inode(struct ext2fs *fs, struct ext2_inode *in, uint32_t inode)
|
||||||
|
|
||||||
struct ext2_inode *out = kmalloc(fs->block_size, ALLOC_DMA);
|
struct ext2_inode *out = kmalloc(fs->block_size, ALLOC_DMA);
|
||||||
if (!out)
|
if (!out)
|
||||||
return -1;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = ext2_read_block(fs, out, inode_table + block);
|
ret = ext2_read_block(fs, out, inode_table + block);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
@ -127,29 +130,6 @@ int ext2_write_inode(struct ext2fs *fs, struct ext2_inode *in, uint32_t inode)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ext2_read_dir(struct ext2fs *fs, struct ext2_inode *in, struct ext2_dir *out, uint32_t index)
|
|
||||||
{
|
|
||||||
uint32_t block = index / (fs->block_size / sizeof(struct ext2_dir));
|
|
||||||
uint32_t offset = index % (fs->block_size / sizeof(struct ext2_dir));
|
|
||||||
|
|
||||||
uint32_t block_num = in->block[block];
|
|
||||||
|
|
||||||
struct ext2_dir *buf = kmalloc(fs->block_size, ALLOC_DMA);
|
|
||||||
if (!buf)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
int ret = ext2_read_block(fs, buf, block_num);
|
|
||||||
if (ret < 0) {
|
|
||||||
kfree(buf);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(out, (void *)((uint64_t)buf + offset), sizeof(*out));
|
|
||||||
kfree(buf);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ext2fs *ext2_init_fs(struct block_device *bdev)
|
struct ext2fs *ext2_init_fs(struct block_device *bdev)
|
||||||
{
|
{
|
||||||
struct ext2fs *ret = kmalloc(sizeof(*ret), ALLOC_KERN);
|
struct ext2fs *ret = kmalloc(sizeof(*ret), ALLOC_KERN);
|
||||||
|
|
|
||||||
2
fs/gpt.c
2
fs/gpt.c
|
|
@ -58,7 +58,7 @@ void block_gpt_init(struct block_device *dev)
|
||||||
if (entry->lba_first == 0)
|
if (entry->lba_first == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (entry->lba_first > dev->block_count)
|
if (entry->lba_first >= dev->block_count)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Name and register the partition */
|
/* Name and register the partition */
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
#ifndef _ERRNO_H_
|
#ifndef _ERRNO_H_
|
||||||
#define _ERRNO_H_
|
#define _ERRNO_H_
|
||||||
|
|
||||||
|
#define ENOMEM 1
|
||||||
#define ENOENT 2
|
#define ENOENT 2
|
||||||
|
#define EINVAL 3
|
||||||
|
|
||||||
#endif /* _ERRNO_H_ */
|
#endif /* _ERRNO_H_ */
|
||||||
|
|
|
||||||
|
|
@ -121,15 +121,6 @@ struct ext2_dir_entry {
|
||||||
char name[];
|
char name[];
|
||||||
} PACKED;
|
} PACKED;
|
||||||
|
|
||||||
struct ext2_dir {
|
|
||||||
struct ext2_dir_entry *entry;
|
|
||||||
uint32_t inode;
|
|
||||||
char *name;
|
|
||||||
size_t name_len;
|
|
||||||
|
|
||||||
struct ext2_dir *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ext2fs {
|
struct ext2fs {
|
||||||
struct ext2_superblock sb;
|
struct ext2_superblock sb;
|
||||||
struct block_device *bdev;
|
struct block_device *bdev;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue