From c6de550e45a4efff58fc7c1b220a3ec834c31822 Mon Sep 17 00:00:00 2001 From: TXuian <1163589503@qq.com> Date: Thu, 16 May 2024 10:34:39 +0800 Subject: [PATCH] Fix UserFS, support more blocks. --- .../drivers/imx6q-sabrelite/enet/Makefile | 2 +- .../drivers/imx6q-sabrelite/enet/enet_drv.c | 2 - .../services/fs/fs_server/include/block_io.h | 3 +- .../services/fs/fs_server/include/fs.h | 1 + .../XiZi_AIoT/services/tools/mkfs/mkfs.c | 48 ++++++++++--------- .../XiZi_AIoT/services/tools/mkfs/mkfs.h | 5 +- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile index 6741c8fb1..40096c142 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile @@ -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 \ # -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 \ -I$(KERNEL_ROOT)/services/boards/$(BOARD) \ diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/enet_drv.c b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/enet_drv.c index c1f0de0d6..efb58e98f 100755 --- a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/enet_drv.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/enet_drv.c @@ -555,8 +555,6 @@ void imx_enet_start(imx_enet_priv_t* dev, unsigned char* enaddr) dev->tx_busy = 0; 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; - 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); } diff --git a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h index cf6867c94..8fd07762b 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h +++ b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/block_io.h @@ -18,12 +18,13 @@ // Block size #define BLOCK_SIZE 512 +#define NR_BIT_BLOCKS 2 // bits size #define BITS 8 // 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 #define INODE_SIZE (BLOCK_SIZE / sizeof(struct Inode)) diff --git a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/fs.h b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/fs.h index 776cfbbea..17a536ece 100644 --- a/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/fs.h +++ b/Ubiquitous/XiZi_AIoT/services/fs/fs_server/include/fs.h @@ -77,6 +77,7 @@ struct SuperBlock { uint32_t size; // Number of total blocks of file system image uint32_t nblocks; // Number of data blocks uint32_t ninodes; // Number of inodes. + uint32_t nbitblocks; }; // Inode structure diff --git a/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c index f7ee5203e..027d9dd5c 100755 --- a/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c +++ b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.c @@ -52,7 +52,7 @@ Modification: int fsfd; struct SuperBlock sb; -char zeroes[512]; +char zeroes[BLOCK_SIZE]; uint freeblock; uint usedblocks; uint bitblocks; @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) int i, cc, fd; uint rootino, inum, off; struct DirEntry de; - char buf[512]; + char buf[BLOCK_SIZE]; struct Inode din; int size, nblocks; @@ -104,8 +104,8 @@ int main(int argc, char* argv[]) exit(1); } - assert((512 % sizeof(struct Inode)) == 0); - assert((512 % sizeof(struct DirEntry)) == 0); + assert((BLOCK_SIZE % sizeof(struct Inode)) == 0); + assert((BLOCK_SIZE % sizeof(struct DirEntry)) == 0); fsfd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0666); if (fsfd < 0) { @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) } size = nr_blocks_total; - bitblocks = size / (512 * 8) + 1; + bitblocks = NR_BIT_BLOCKS; usedblocks = 2 + (nr_inodes / INODE_SIZE + 1) + bitblocks; nblocks = nr_blocks_total - usedblocks; freeblock = usedblocks; @@ -122,6 +122,7 @@ int main(int argc, char* argv[]) sb.size = xint(size); sb.nblocks = xint(nblocks); 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, 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) { - if (lseek(fsfd, sec * 512L, 0) != sec * 512L) { + if (lseek(fsfd, sec * BLOCK_SIZE, 0) != sec * BLOCK_SIZE) { perror("lseek"); exit(1); } - if (write(fsfd, buf, 512) != 512) { + if (write(fsfd, buf, BLOCK_SIZE) != BLOCK_SIZE) { perror("write"); exit(1); } @@ -209,7 +210,7 @@ uint i2b(uint inum) void winode(uint inum, struct Inode* ip) { - char buf[512]; + char buf[BLOCK_SIZE]; uint bn; struct Inode* dip; @@ -222,7 +223,7 @@ void winode(uint inum, struct Inode* ip) void rinode(uint inum, struct Inode* ip) { - char buf[512]; + char buf[BLOCK_SIZE]; uint bn; struct Inode* dip; @@ -234,11 +235,11 @@ void rinode(uint inum, struct Inode* ip) 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"); exit(1); } - if (read(fsfd, buf, 512) != 512) { + if (read(fsfd, buf, BLOCK_SIZE) != BLOCK_SIZE) { perror("read"); exit(1); } @@ -259,17 +260,18 @@ uint ialloc(ushort type) void balloc(int used) { - uchar buf[512]; + uchar buf[BLOCK_SIZE]; int i; - printf("balloc: first %d blocks have been allocated\n", used); - assert(used < 512 * 8); - bzero(buf, 512); - for (i = 0; i < used; i++) { - buf[i / 8] = buf[i / 8] | (0x1 << (i % 8)); + bzero(buf, BLOCK_SIZE); + for (int bmsec = 0; bmsec < bitblocks; bmsec++) { + for (i = 0; i < ((used > NR_BIT_PER_BYTE * BLOCK_SIZE) ? NR_BIT_PER_BYTE * BLOCK_SIZE : used); i++) { + 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)) @@ -279,7 +281,7 @@ void iappend(uint inum, void* xp, int n) char* p = (char*)xp; uint fbn, off, n1; struct Inode din; - char buf[512]; + char buf[BLOCK_SIZE]; uint indirect[NR_INDIRECT_BLOCKS * MAX_INDIRECT_BLOCKS]; uint x; @@ -287,7 +289,7 @@ void iappend(uint inum, void* xp, int n) off = xint(din.size); while (n > 0) { - fbn = off / 512; + fbn = off / BLOCK_SIZE; assert(fbn < MAX_FILE_SIZE); assert(usedblocks < nr_blocks_total); if (fbn < NR_DIRECT_BLOCKS) { @@ -315,9 +317,9 @@ void iappend(uint inum, void* xp, int n) x = xint(indirect[idx]); } } - n1 = min(n, (fbn + 1) * 512 - off); + n1 = min(n, (fbn + 1) * BLOCK_SIZE - off); rsect(x, buf); - bcopy(p, buf + off - (fbn * 512), n1); + bcopy(p, buf + off - (fbn * BLOCK_SIZE), n1); wsect(x, buf); n -= n1; off += n1; diff --git a/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.h b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.h index 8682e5ac8..b7d299bb9 100755 --- a/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.h +++ b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/mkfs.h @@ -48,7 +48,9 @@ Modification: #define ROOT_INUM 1 // root inode number #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_DIRECT_BLOCKS 4 @@ -69,6 +71,7 @@ struct SuperBlock { uint size; // Size of file system image (blocks) uint nblocks; // Number of data blocks uint ninodes; // Number of inodes. + uint nbitblocks; }; // Inode structure