fix a FAT32 bug

This commit is contained in:
Lu Sitong 2021-03-04 11:12:38 +08:00
parent d2d2aa7916
commit 7172563512
4 changed files with 25 additions and 17 deletions

View File

@ -127,7 +127,7 @@ QEMUOPTS = -machine virt -bios $(RUSTSBI) -kernel $T/kernel -m 128M -smp $(CPUS)
QEMUOPTS += -drive file=fs.img,if=none,format=raw,id=x0 QEMUOPTS += -drive file=fs.img,if=none,format=raw,id=x0
QEMUOPTS += -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 QEMUOPTS += -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
run: build run: build fs.img
ifeq ($(platform), k210) ifeq ($(platform), k210)
@$(OBJCOPY) $T/kernel --strip-all -O binary $(image) @$(OBJCOPY) $T/kernel --strip-all -O binary $(image)
@$(OBJCOPY) $(RUSTSBI) --strip-all -O binary $(k210) @$(OBJCOPY) $(RUSTSBI) --strip-all -O binary $(k210)
@ -136,10 +136,12 @@ ifeq ($(platform), k210)
@sudo chmod 777 $(k210-serialport) @sudo chmod 777 $(k210-serialport)
@python3 ./tools/kflash.py -p $(k210-serialport) -b 1500000 -t $(k210) @python3 ./tools/kflash.py -p $(k210-serialport) -b 1500000 -t $(k210)
else else
@./fs.sh
@$(QEMU) $(QEMUOPTS) @$(QEMU) $(QEMUOPTS)
endif endif
fs.img: $(UPROGS)
@./fs.sh
$U/initcode: $U/initcode.S $U/initcode: $U/initcode.S
$(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/initcode.S -o $U/initcode.o $(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/initcode.S -o $U/initcode.o
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/initcode.out $U/initcode.o $(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/initcode.out $U/initcode.o

28
fs.sh
View File

@ -1,18 +1,20 @@
dd if=/dev/zero of=fs.img bs=512k count=2048 if [ ! -f "fs.img" ]; then
mkfs.vfat -F 32 fs.img dd if=/dev/zero of=fs.img bs=512k count=2048
mkfs.vfat -F 32 fs.img
fi
sudo mount fs.img /mnt sudo mount fs.img /mnt
sudo mkdir /mnt/xv6sh sudo mkdir /mnt/bin
sudo cp ./xv6-user/_init /mnt/init sudo cp ./xv6-user/_init /mnt/init
sudo cp ./xv6-user/_sh /mnt/sh sudo cp ./xv6-user/_sh /mnt/sh
sudo cp ./xv6-user/_cat /mnt/xv6sh/cat sudo cp ./xv6-user/_cat /mnt/bin/cat
sudo cp ./xv6-user/_echo /mnt/xv6sh/echo sudo cp ./xv6-user/_echo /mnt/bin/echo
sudo cp ./xv6-user/_grep /mnt/xv6sh/grep sudo cp ./xv6-user/_grep /mnt/bin/grep
sudo cp ./xv6-user/_ls /mnt/xv6sh/ls sudo cp ./xv6-user/_ls /mnt/bin/ls
sudo cp ./xv6-user/_kill /mnt/xv6sh/kill sudo cp ./xv6-user/_kill /mnt/bin/kill
sudo cp ./xv6-user/_mkdir /mnt/xv6sh/mkdir sudo cp ./xv6-user/_mkdir /mnt/bin/mkdir
sudo cp ./xv6-user/_xargs /mnt/xv6sh/xargs sudo cp ./xv6-user/_xargs /mnt/bin/xargs
sudo cp ./xv6-user/_rm /mnt/xv6sh/rm sudo cp ./xv6-user/_rm /mnt/bin/rm
sudo cp ./xv6-user/_sleep /mnt/xv6sh/sleep sudo cp ./xv6-user/_sleep /mnt/bin/sleep
sudo cp ./xv6-user/_find /mnt/xv6sh/find sudo cp ./xv6-user/_find /mnt/bin/find
sudo umount /mnt sudo umount /mnt

View File

@ -450,7 +450,7 @@ struct dirent *edup(struct dirent *entry)
return entry; return entry;
} }
// Only update filesize in this case. // Only update filesize and first cluster in this case.
void eupdate(struct dirent *entry) void eupdate(struct dirent *entry)
{ {
if (!entry->dirty) { return; } if (!entry->dirty) { return; }
@ -459,6 +459,10 @@ void eupdate(struct dirent *entry)
rw_clus(entry->parent->cur_clus, 0, 0, (uint64) &entcnt, off, 1); rw_clus(entry->parent->cur_clus, 0, 0, (uint64) &entcnt, off, 1);
entcnt &= ~LAST_LONG_ENTRY; entcnt &= ~LAST_LONG_ENTRY;
off = reloc_clus(entry->parent, entry->off + (entcnt << 5), 0); off = reloc_clus(entry->parent, entry->off + (entcnt << 5), 0);
uint16 clus_high = (uint16)(entry->first_clus >> 16);
uint16 clus_low = (uint16)(entry->first_clus & 0xff);
rw_clus(entry->parent->cur_clus, 1, 0, (uint64) &clus_high, off + 20, sizeof(uint16));
rw_clus(entry->parent->cur_clus, 1, 0, (uint64) &clus_low, off + 26, sizeof(uint16));
rw_clus(entry->parent->cur_clus, 1, 0, (uint64) &entry->file_size, off + 28, sizeof(entry->file_size)); rw_clus(entry->parent->cur_clus, 1, 0, (uint64) &entry->file_size, off + 28, sizeof(entry->file_size));
entry->dirty = 0; entry->dirty = 0;
} }

View File

@ -217,7 +217,7 @@ main(void)
// Add an embedded env var(for basic commands in shell) // Add an embedded env var(for basic commands in shell)
strcpy(envs[nenv].name, "SHELL"); strcpy(envs[nenv].name, "SHELL");
strcpy(envs[nenv].value, "/xv6sh"); strcpy(envs[nenv].value, "/bin");
nenv++; nenv++;
getcwd(mycwd); getcwd(mycwd);