try to finish find

This commit is contained in:
2025-02-27 12:34:34 +08:00
parent 220553c3b8
commit 930df1c35b
4 changed files with 58 additions and 52 deletions

View File

@ -86,7 +86,7 @@ LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -Wall -Werror -O2 -fno-omit-frame-pointer -ggdb -gdwarf-2 CFLAGS = -Wall -Werror -Ofast -fno-omit-frame-pointer -ggdb -gdwarf-2
ifdef LAB ifdef LAB
LABUPPER = $(shell echo $(LAB) | tr a-z A-Z) LABUPPER = $(shell echo $(LAB) | tr a-z A-Z)
@ -191,6 +191,7 @@ UPROGS=\
$U/_sleep\ $U/_sleep\
$U/_pingpong\ $U/_pingpong\
$U/_primes\ $U/_primes\
$U/_find\
@ -227,10 +228,10 @@ $U/_uthread: $U/uthread.o $U/uthread_switch.o $(ULIB)
$(OBJDUMP) -S $U/_uthread > $U/uthread.asm $(OBJDUMP) -S $U/_uthread > $U/uthread.asm
ph: notxv6/ph.c ph: notxv6/ph.c
gcc -o ph -g -O2 $(XCFLAGS) notxv6/ph.c -pthread gcc -o ph -g -Ofast $(XCFLAGS) notxv6/ph.c -pthread
barrier: notxv6/barrier.c barrier: notxv6/barrier.c
gcc -o barrier -g -O2 $(XCFLAGS) notxv6/barrier.c -pthread gcc -o barrier -g -Ofast $(XCFLAGS) notxv6/barrier.c -pthread
endif endif
ifeq ($(LAB),pgtbl) ifeq ($(LAB),pgtbl)

View File

@ -1,6 +1,6 @@
// On-disk file system format. // On-disk file system format.
// Both the kernel and user programs use this header file. // Both the kernel and user programs use this header file.
#include "kernel/types.h"
#define ROOTINO 1 // root i-number #define ROOTINO 1 // root i-number
#define BSIZE 1024 // block size #define BSIZE 1024 // block size
@ -57,4 +57,3 @@ struct dirent {
ushort inum; ushort inum;
char name[DIRSIZ]; char name[DIRSIZ];
}; };

12
user/find.c Normal file
View File

@ -0,0 +1,12 @@
#include "kernel/fcntl.h"
#include "kernel/fs.h"
#include "kernel/stat.h"
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Usage: find path pattern\n");
}
exit(0);
}

View File

@ -1,12 +1,10 @@
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
#include "kernel/fs.h"
#include "kernel/fcntl.h" #include "kernel/fcntl.h"
#include "kernel/fs.h"
#include "kernel/stat.h"
#include "kernel/types.h"
#include "user/user.h"
char* char *fmtname(char *path) {
fmtname(char *path)
{
static char buf[DIRSIZ + 1]; static char buf[DIRSIZ + 1];
char *p; char *p;
@ -23,9 +21,7 @@ fmtname(char *path)
return buf; return buf;
} }
void void ls(char *path) {
ls(char *path)
{
char buf[512], *p; char buf[512], *p;
int fd; int fd;
struct dirent de; struct dirent de;
@ -72,9 +68,7 @@ ls(char *path)
close(fd); close(fd);
} }
int int main(int argc, char *argv[]) {
main(int argc, char *argv[])
{
int i; int i;
if (argc < 2) { if (argc < 2) {