Fix UserFS, support more blocks.
This commit is contained in:
parent
52387d47a7
commit
c6de550e45
|
@ -18,7 +18,7 @@ cflags = -std=c11 -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -g \
|
||||||
# cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic \
|
# cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic \
|
||||||
# -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
# -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
||||||
|
|
||||||
c_useropts = -O2
|
c_useropts = -O0
|
||||||
|
|
||||||
INC_DIR = -I$(KERNEL_ROOT)/services/app \
|
INC_DIR = -I$(KERNEL_ROOT)/services/app \
|
||||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||||
|
|
|
@ -555,8 +555,6 @@ void imx_enet_start(imx_enet_priv_t* dev, unsigned char* enaddr)
|
||||||
dev->tx_busy = 0;
|
dev->tx_busy = 0;
|
||||||
dev->enet_reg->ECR.U |= ENET_ETHER_EN | ENET_ETHER_SPEED_1000M | ENET_ETHER_LITTLE_ENDIAN;
|
dev->enet_reg->ECR.U |= ENET_ETHER_EN | ENET_ETHER_SPEED_1000M | ENET_ETHER_LITTLE_ENDIAN;
|
||||||
dev->enet_reg->RDAR.U |= ENET_RX_TX_ACTIVE;
|
dev->enet_reg->RDAR.U |= ENET_RX_TX_ACTIVE;
|
||||||
HW_ENET_RDAR_WR(ENET_RX_TX_ACTIVE);
|
|
||||||
printf("addr1: %x, addr2: %x\n", &dev->enet_reg->RDAR.U, HW_ENET_RDAR_ADDR);
|
|
||||||
printf("EIR: %08x, ECR: %08x, TDAR.U: %08x, RDAR.U: %08x (%08x)\n", dev->enet_reg->EIR.U, dev->enet_reg->ECR.U, dev->enet_reg->TDAR.U, dev->enet_reg->RDAR.U, ENET_RX_TX_ACTIVE);
|
printf("EIR: %08x, ECR: %08x, TDAR.U: %08x, RDAR.U: %08x (%08x)\n", dev->enet_reg->EIR.U, dev->enet_reg->ECR.U, dev->enet_reg->TDAR.U, dev->enet_reg->RDAR.U, ENET_RX_TX_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
|
|
||||||
// Block size
|
// Block size
|
||||||
#define BLOCK_SIZE 512
|
#define BLOCK_SIZE 512
|
||||||
|
#define NR_BIT_BLOCKS 2
|
||||||
|
|
||||||
// bits size
|
// bits size
|
||||||
#define BITS 8
|
#define BITS 8
|
||||||
|
|
||||||
// Bitmap size of one block
|
// Bitmap size of one block
|
||||||
#define BITMAP_SIZE (BLOCK_SIZE * BITS)
|
#define BITMAP_SIZE (BLOCK_SIZE * BITS * NR_BIT_BLOCKS)
|
||||||
|
|
||||||
// Inode size of one block
|
// Inode size of one block
|
||||||
#define INODE_SIZE (BLOCK_SIZE / sizeof(struct Inode))
|
#define INODE_SIZE (BLOCK_SIZE / sizeof(struct Inode))
|
||||||
|
|
|
@ -77,6 +77,7 @@ struct SuperBlock {
|
||||||
uint32_t size; // Number of total blocks of file system image
|
uint32_t size; // Number of total blocks of file system image
|
||||||
uint32_t nblocks; // Number of data blocks
|
uint32_t nblocks; // Number of data blocks
|
||||||
uint32_t ninodes; // Number of inodes.
|
uint32_t ninodes; // Number of inodes.
|
||||||
|
uint32_t nbitblocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Inode structure
|
// Inode structure
|
||||||
|
|
|
@ -52,7 +52,7 @@ Modification:
|
||||||
|
|
||||||
int fsfd;
|
int fsfd;
|
||||||
struct SuperBlock sb;
|
struct SuperBlock sb;
|
||||||
char zeroes[512];
|
char zeroes[BLOCK_SIZE];
|
||||||
uint freeblock;
|
uint freeblock;
|
||||||
uint usedblocks;
|
uint usedblocks;
|
||||||
uint bitblocks;
|
uint bitblocks;
|
||||||
|
@ -93,7 +93,7 @@ int main(int argc, char* argv[])
|
||||||
int i, cc, fd;
|
int i, cc, fd;
|
||||||
uint rootino, inum, off;
|
uint rootino, inum, off;
|
||||||
struct DirEntry de;
|
struct DirEntry de;
|
||||||
char buf[512];
|
char buf[BLOCK_SIZE];
|
||||||
struct Inode din;
|
struct Inode din;
|
||||||
int size, nblocks;
|
int size, nblocks;
|
||||||
|
|
||||||
|
@ -104,8 +104,8 @@ int main(int argc, char* argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert((512 % sizeof(struct Inode)) == 0);
|
assert((BLOCK_SIZE % sizeof(struct Inode)) == 0);
|
||||||
assert((512 % sizeof(struct DirEntry)) == 0);
|
assert((BLOCK_SIZE % sizeof(struct DirEntry)) == 0);
|
||||||
|
|
||||||
fsfd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666);
|
fsfd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||||
if (fsfd < 0) {
|
if (fsfd < 0) {
|
||||||
|
@ -114,7 +114,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
size = nr_blocks_total;
|
size = nr_blocks_total;
|
||||||
bitblocks = size / (512 * 8) + 1;
|
bitblocks = NR_BIT_BLOCKS;
|
||||||
usedblocks = 2 + (nr_inodes / INODE_SIZE + 1) + bitblocks;
|
usedblocks = 2 + (nr_inodes / INODE_SIZE + 1) + bitblocks;
|
||||||
nblocks = nr_blocks_total - usedblocks;
|
nblocks = nr_blocks_total - usedblocks;
|
||||||
freeblock = usedblocks;
|
freeblock = usedblocks;
|
||||||
|
@ -122,6 +122,7 @@ int main(int argc, char* argv[])
|
||||||
sb.size = xint(size);
|
sb.size = xint(size);
|
||||||
sb.nblocks = xint(nblocks);
|
sb.nblocks = xint(nblocks);
|
||||||
sb.ninodes = xint(nr_inodes);
|
sb.ninodes = xint(nr_inodes);
|
||||||
|
sb.nbitblocks = xint(NR_BIT_BLOCKS);
|
||||||
|
|
||||||
printf("block 0 is unused, block 1 is for super block, used %d (bit %d ninode %zu) free %u total %d\n", usedblocks,
|
printf("block 0 is unused, block 1 is for super block, used %d (bit %d ninode %zu) free %u total %d\n", usedblocks,
|
||||||
bitblocks, nr_inodes / INODE_SIZE + 1, size - usedblocks, nblocks + usedblocks);
|
bitblocks, nr_inodes / INODE_SIZE + 1, size - usedblocks, nblocks + usedblocks);
|
||||||
|
@ -192,11 +193,11 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
void wsect(uint sec, void* buf)
|
void wsect(uint sec, void* buf)
|
||||||
{
|
{
|
||||||
if (lseek(fsfd, sec * 512L, 0) != sec * 512L) {
|
if (lseek(fsfd, sec * BLOCK_SIZE, 0) != sec * BLOCK_SIZE) {
|
||||||
perror("lseek");
|
perror("lseek");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (write(fsfd, buf, 512) != 512) {
|
if (write(fsfd, buf, BLOCK_SIZE) != BLOCK_SIZE) {
|
||||||
perror("write");
|
perror("write");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +210,7 @@ uint i2b(uint inum)
|
||||||
|
|
||||||
void winode(uint inum, struct Inode* ip)
|
void winode(uint inum, struct Inode* ip)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[BLOCK_SIZE];
|
||||||
uint bn;
|
uint bn;
|
||||||
struct Inode* dip;
|
struct Inode* dip;
|
||||||
|
|
||||||
|
@ -222,7 +223,7 @@ void winode(uint inum, struct Inode* ip)
|
||||||
|
|
||||||
void rinode(uint inum, struct Inode* ip)
|
void rinode(uint inum, struct Inode* ip)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[BLOCK_SIZE];
|
||||||
uint bn;
|
uint bn;
|
||||||
struct Inode* dip;
|
struct Inode* dip;
|
||||||
|
|
||||||
|
@ -234,11 +235,11 @@ void rinode(uint inum, struct Inode* ip)
|
||||||
|
|
||||||
void rsect(uint sec, void* buf)
|
void rsect(uint sec, void* buf)
|
||||||
{
|
{
|
||||||
if (lseek(fsfd, sec * 512L, 0) != sec * 512L) {
|
if (lseek(fsfd, sec * BLOCK_SIZE, 0) != sec * BLOCK_SIZE) {
|
||||||
perror("lseek");
|
perror("lseek");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (read(fsfd, buf, 512) != 512) {
|
if (read(fsfd, buf, BLOCK_SIZE) != BLOCK_SIZE) {
|
||||||
perror("read");
|
perror("read");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -259,17 +260,18 @@ uint ialloc(ushort type)
|
||||||
|
|
||||||
void balloc(int used)
|
void balloc(int used)
|
||||||
{
|
{
|
||||||
uchar buf[512];
|
uchar buf[BLOCK_SIZE];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("balloc: first %d blocks have been allocated\n", used);
|
printf("balloc: first %d blocks have been allocated\n", used);
|
||||||
assert(used < 512 * 8);
|
bzero(buf, BLOCK_SIZE);
|
||||||
bzero(buf, 512);
|
for (int bmsec = 0; bmsec < bitblocks; bmsec++) {
|
||||||
for (i = 0; i < used; i++) {
|
for (i = 0; i < ((used > NR_BIT_PER_BYTE * BLOCK_SIZE) ? NR_BIT_PER_BYTE * BLOCK_SIZE : used); i++) {
|
||||||
buf[i / 8] = buf[i / 8] | (0x1 << (i % 8));
|
buf[i / NR_BIT_PER_BYTE] = buf[i / NR_BIT_PER_BYTE] | (0x1 << (i % NR_BIT_PER_BYTE));
|
||||||
|
}
|
||||||
|
printf("balloc: write bitmap block at sector %zu\n", nr_inodes / INODE_SIZE + 3 + bmsec);
|
||||||
|
wsect(nr_inodes / INODE_SIZE + 3 + bmsec, buf);
|
||||||
|
used -= NR_BIT_PER_BYTE * BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
printf("balloc: write bitmap block at sector %zu\n", nr_inodes / INODE_SIZE + 3);
|
|
||||||
wsect(nr_inodes / INODE_SIZE + 3, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
@ -279,7 +281,7 @@ void iappend(uint inum, void* xp, int n)
|
||||||
char* p = (char*)xp;
|
char* p = (char*)xp;
|
||||||
uint fbn, off, n1;
|
uint fbn, off, n1;
|
||||||
struct Inode din;
|
struct Inode din;
|
||||||
char buf[512];
|
char buf[BLOCK_SIZE];
|
||||||
uint indirect[NR_INDIRECT_BLOCKS * MAX_INDIRECT_BLOCKS];
|
uint indirect[NR_INDIRECT_BLOCKS * MAX_INDIRECT_BLOCKS];
|
||||||
uint x;
|
uint x;
|
||||||
|
|
||||||
|
@ -287,7 +289,7 @@ void iappend(uint inum, void* xp, int n)
|
||||||
|
|
||||||
off = xint(din.size);
|
off = xint(din.size);
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
fbn = off / 512;
|
fbn = off / BLOCK_SIZE;
|
||||||
assert(fbn < MAX_FILE_SIZE);
|
assert(fbn < MAX_FILE_SIZE);
|
||||||
assert(usedblocks < nr_blocks_total);
|
assert(usedblocks < nr_blocks_total);
|
||||||
if (fbn < NR_DIRECT_BLOCKS) {
|
if (fbn < NR_DIRECT_BLOCKS) {
|
||||||
|
@ -315,9 +317,9 @@ void iappend(uint inum, void* xp, int n)
|
||||||
x = xint(indirect[idx]);
|
x = xint(indirect[idx]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n1 = min(n, (fbn + 1) * 512 - off);
|
n1 = min(n, (fbn + 1) * BLOCK_SIZE - off);
|
||||||
rsect(x, buf);
|
rsect(x, buf);
|
||||||
bcopy(p, buf + off - (fbn * 512), n1);
|
bcopy(p, buf + off - (fbn * BLOCK_SIZE), n1);
|
||||||
wsect(x, buf);
|
wsect(x, buf);
|
||||||
n -= n1;
|
n -= n1;
|
||||||
off += n1;
|
off += n1;
|
||||||
|
|
|
@ -48,7 +48,9 @@ Modification:
|
||||||
|
|
||||||
#define ROOT_INUM 1 // root inode number
|
#define ROOT_INUM 1 // root inode number
|
||||||
#define BLOCK_SIZE 512 // block size
|
#define BLOCK_SIZE 512 // block size
|
||||||
#define nr_blocks_total 8192 // total number of blocks (including used blocks and free blocks)
|
#define NR_BIT_PER_BYTE 8
|
||||||
|
#define NR_BIT_BLOCKS 2
|
||||||
|
#define nr_blocks_total (BLOCK_SIZE * NR_BIT_PER_BYTE * NR_BIT_BLOCKS) // total number of blocks (including used blocks and free blocks)
|
||||||
#define nr_inodes 200 // total number of inodes
|
#define nr_inodes 200 // total number of inodes
|
||||||
|
|
||||||
#define NR_DIRECT_BLOCKS 4
|
#define NR_DIRECT_BLOCKS 4
|
||||||
|
@ -69,6 +71,7 @@ struct SuperBlock {
|
||||||
uint size; // Size of file system image (blocks)
|
uint size; // Size of file system image (blocks)
|
||||||
uint nblocks; // Number of data blocks
|
uint nblocks; // Number of data blocks
|
||||||
uint ninodes; // Number of inodes.
|
uint ninodes; // Number of inodes.
|
||||||
|
uint nbitblocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Inode structure
|
// Inode structure
|
||||||
|
|
Loading…
Reference in New Issue