├── .bochsrc.tmpl ├── .dir-locals.el ├── .gdbinit.tmpl ├── .gitignore ├── CODING ├── GNUmakefile ├── bochs_readme ├── boot ├── Makefrag ├── boot.S ├── main.c └── sign.pl ├── challenge1.txt ├── challenge2.txt ├── challenge3.txt ├── challenge4.txt ├── challenge5.txt ├── challenge6.txt ├── challenge7.txt ├── conf ├── env.mk └── lab.mk ├── fs ├── Makefrag ├── bc.c ├── fs.c ├── fs.h ├── fsformat.c ├── ide.c ├── index.html ├── lorem ├── motd ├── motd_guest ├── newmotd ├── robig ├── script ├── serv.c ├── test.c ├── testshell.key ├── testshell.sh └── vmx_host.c ├── grade-lab1 ├── grade-lab2 ├── grade-lab3 ├── grade-lab4 ├── grade-lab5 ├── grade-lab6 ├── grade-lab8 ├── gradelib.py ├── guest_boot ├── Makefrag ├── boot.S └── sign.pl ├── handin-prep ├── inc ├── COPYRIGHT ├── args.h ├── assert.h ├── elf.h ├── env.h ├── ept.h ├── error.h ├── fd.h ├── fs.h ├── kbdreg.h ├── lib.h ├── malloc.h ├── memlayout.h ├── mmu.h ├── ns.h ├── queue.h ├── stab.h ├── stdarg.h ├── stdio.h ├── string.h ├── syscall.h ├── trap.h ├── types.h ├── vmx.h └── x86.h ├── kern ├── COPYRIGHT ├── Makefrag ├── bootstrap.S ├── console.c ├── console.h ├── cpu.h ├── dwarf.h ├── dwarf_api.h ├── dwarf_define.h ├── dwarf_elf.h ├── dwarf_error.h ├── dwarf_lineno.h ├── e1000.c ├── e1000.h ├── elf_rw.c ├── entry.S ├── env.c ├── env.h ├── guest_kernel.ld ├── init.c ├── kclock.c ├── kclock.h ├── kdebug.c ├── kdebug.h ├── kernel.ld ├── lapic.c ├── libdwarf_frame.c ├── libdwarf_lineno.c ├── libdwarf_rw.c ├── macro.h ├── monitor.c ├── monitor.h ├── mpconfig.c ├── mpentry.S ├── multiboot.h ├── pci.c ├── pci.h ├── pcireg.h ├── picirq.c ├── picirq.h ├── pmap.c ├── pmap.h ├── printf.c ├── sched.c ├── sched.h ├── spinlock.c ├── spinlock.h ├── syscall.c ├── syscall.h ├── time.c ├── time.h ├── trap.c ├── trap.h └── trapentry.S ├── lib ├── Makefrag ├── args.c ├── console.c ├── entry.S ├── exit.c ├── fd.c ├── file.c ├── fork.c ├── fprintf.c ├── ipc.c ├── libmain.c ├── malloc.c ├── nsipc.c ├── pageref.c ├── panic.c ├── pfentry.S ├── pgfault.c ├── pipe.c ├── printf.c ├── printfmt.c ├── readline.c ├── sockets.c ├── spawn.c ├── string.c ├── syscall.c └── wait.c ├── mergedep.pl ├── net ├── Makefrag ├── input.c ├── lwip │ ├── FILES │ ├── Makefrag │ ├── api │ │ ├── api_lib.c │ │ ├── api_msg.c │ │ ├── err.c │ │ ├── netbuf.c │ │ ├── netdb.c │ │ ├── netifapi.c │ │ ├── sockets.c │ │ └── tcpip.c │ ├── core │ │ ├── dhcp.c │ │ ├── dns.c │ │ ├── init.c │ │ ├── ipv4 │ │ │ ├── autoip.c │ │ │ ├── icmp.c │ │ │ ├── igmp.c │ │ │ ├── inet.c │ │ │ ├── inet_chksum.c │ │ │ ├── ip.c │ │ │ ├── ip_addr.c │ │ │ └── ip_frag.c │ │ ├── ipv6 │ │ │ ├── README │ │ │ ├── icmp6.c │ │ │ ├── inet6.c │ │ │ ├── ip6.c │ │ │ └── ip6_addr.c │ │ ├── mem.c │ │ ├── memp.c │ │ ├── netif.c │ │ ├── pbuf.c │ │ ├── raw.c │ │ ├── snmp │ │ │ ├── asn1_dec.c │ │ │ ├── asn1_enc.c │ │ │ ├── mib2.c │ │ │ ├── mib_structs.c │ │ │ ├── msg_in.c │ │ │ └── msg_out.c │ │ ├── stats.c │ │ ├── sys.c │ │ ├── tcp.c │ │ ├── tcp_in.c │ │ ├── tcp_out.c │ │ └── udp.c │ ├── include │ │ ├── ipv4 │ │ │ └── lwip │ │ │ │ ├── autoip.h │ │ │ │ ├── icmp.h │ │ │ │ ├── igmp.h │ │ │ │ ├── inet.h │ │ │ │ ├── inet_chksum.h │ │ │ │ ├── ip.h │ │ │ │ ├── ip_addr.h │ │ │ │ └── ip_frag.h │ │ ├── ipv6 │ │ │ └── lwip │ │ │ │ ├── icmp.h │ │ │ │ ├── inet.h │ │ │ │ ├── ip.h │ │ │ │ └── ip_addr.h │ │ ├── lwip │ │ │ ├── api.h │ │ │ ├── api_msg.h │ │ │ ├── arch.h │ │ │ ├── debug.h │ │ │ ├── def.h │ │ │ ├── dhcp.h │ │ │ ├── dns.h │ │ │ ├── err.h │ │ │ ├── init.h │ │ │ ├── mem.h │ │ │ ├── memp.h │ │ │ ├── memp_std.h │ │ │ ├── netbuf.h │ │ │ ├── netdb.h │ │ │ ├── netif.h │ │ │ ├── netifapi.h │ │ │ ├── opt.h │ │ │ ├── pbuf.h │ │ │ ├── raw.h │ │ │ ├── sio.h │ │ │ ├── snmp.h │ │ │ ├── snmp_asn1.h │ │ │ ├── snmp_msg.h │ │ │ ├── snmp_structs.h │ │ │ ├── sockets.h │ │ │ ├── stats.h │ │ │ ├── sys.h │ │ │ ├── tcp.h │ │ │ ├── tcpip.h │ │ │ └── udp.h │ │ └── netif │ │ │ ├── etharp.h │ │ │ ├── loopif.h │ │ │ ├── ppp_oe.h │ │ │ └── slipif.h │ ├── jos │ │ ├── arch │ │ │ ├── cc.h │ │ │ ├── i386 │ │ │ │ └── setjmp.h │ │ │ ├── longjmp.S │ │ │ ├── perf.h │ │ │ ├── perror.c │ │ │ ├── perror.h │ │ │ ├── queue.h │ │ │ ├── setjmp.h │ │ │ ├── sys_arch.c │ │ │ ├── sys_arch.h │ │ │ ├── thread.c │ │ │ ├── thread.h │ │ │ └── threadq.h │ │ ├── jif │ │ │ ├── jif.c │ │ │ └── jif.h │ │ └── lwipopts.h │ └── netif │ │ ├── FILES │ │ ├── etharp.c │ │ ├── ethernetif.c │ │ ├── loopif.c │ │ ├── ppp │ │ ├── auth.c │ │ ├── auth.h │ │ ├── chap.c │ │ ├── chap.h │ │ ├── chpms.c │ │ ├── chpms.h │ │ ├── fsm.c │ │ ├── fsm.h │ │ ├── ipcp.c │ │ ├── ipcp.h │ │ ├── lcp.c │ │ ├── lcp.h │ │ ├── magic.c │ │ ├── magic.h │ │ ├── md5.c │ │ ├── md5.h │ │ ├── pap.c │ │ ├── pap.h │ │ ├── ppp.c │ │ ├── ppp.h │ │ ├── ppp_oe.c │ │ ├── pppdebug.h │ │ ├── randm.c │ │ ├── randm.h │ │ ├── vj.c │ │ ├── vj.h │ │ └── vjbsdhdr.h │ │ └── slipif.c ├── ns.h ├── output.c ├── serv.c ├── testinput.c ├── testoutput.c └── timer.c ├── slack.txt ├── user ├── Makefrag ├── badsegment.c ├── breakpoint.c ├── buggyhello.c ├── buggyhello2.c ├── cat.c ├── divzero.c ├── dumbfork.c ├── echo.c ├── echosrv.c ├── echotest.c ├── evilhello.c ├── fairness.c ├── faultalloc.c ├── faultallocbad.c ├── faultbadhandler.c ├── faultdie.c ├── faultevilhandler.c ├── faultnostack.c ├── faultread.c ├── faultreadkernel.c ├── faultregs.c ├── faultwrite.c ├── faultwritekernel.c ├── forktree.c ├── hello.c ├── httpd.c ├── icode.c ├── idle.c ├── init.c ├── initsh.c ├── ls.c ├── lsfd.c ├── num.c ├── pingpong.c ├── pingpongs.c ├── primes.c ├── primespipe.c ├── sendpage.c ├── sh.c ├── softint.c ├── spawnhello.c ├── spawninit.c ├── spin.c ├── stresssched.c ├── testbss.c ├── testfdsharing.c ├── testfile.c ├── testfilero.c ├── testkbd.c ├── testmalloc.c ├── testpipe.c ├── testpiperace.c ├── testpiperace2.c ├── testptelibrary.c ├── testpteshare.c ├── testshell.c ├── testtime.c ├── user.ld ├── vmm.c ├── vmmanager.c ├── writemotd.c └── yield.c └── vmm ├── .gitignore ├── Makefrag ├── ept.c ├── ept.h ├── jos_boot.S ├── vmexits.c ├── vmexits.h ├── vmx.c ├── vmx.h └── vmx_asm.h /.bochsrc.tmpl: -------------------------------------------------------------------------------- 1 | # configuration file generated by Bochs 2 | plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1 3 | config_interface: textconfig 4 | display_library: x 5 | memory: host=128, guest=128 6 | romimage: file="/usr/share/bochs/BIOS-bochs-latest" 7 | vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest" 8 | boot: floppy, disk 9 | floppy_bootsig_check: disabled=0 10 | # no floppya 11 | # no floppyb 12 | ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 13 | ata0-master: type=disk, path="path_to_kernel_img", mode=flat, cylinders=1, heads=1, spt=32, model="Generic 1234", biosdetect=auto, translation=auto 14 | ata0-slave: type=disk, path="path_to_disk_img", mode=flat, cylinders=1, heads=1, spt=32, model="Generic 1234", biosdetect=auto, translation=auto 15 | ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 16 | ata1-master: type=none 17 | ata1-slave: type=none 18 | ata2: enabled=0 19 | ata3: enabled=0 20 | pci: enabled=1, chipset=i440fx 21 | vga: extension=vbe, update_freq=5 22 | cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=0, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 23 | cpuid: level=6, stepping=3, model=3, family=6, vendor_string="AuthenticAMD", brand_string="AMD Athlon(tm) processor" 24 | cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0 25 | cpuid: aes=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=0, pcid=0, fsgsbase=0, smep=0 26 | cpuid: smap=0, mwait=1, vmx=2 27 | #, svm=0 28 | print_timestamps: enabled=0 29 | # no gdb stub 30 | port_e9_hack: enabled=0 31 | private_colormap: enabled=0 32 | clock: sync=none, time0=local, rtc_sync=0 33 | # no cmosimage 34 | # no loader 35 | log: bochs.log 36 | logprefix: %t%e%d 37 | debug: action=ignore 38 | info: action=report 39 | error: action=report 40 | panic: action=ask 41 | keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none 42 | mouse: type=ps2, enabled=0, toggle=ctrl+mbutton 43 | parport1: enabled=1, file=bochs.out 44 | parport2: enabled=0 45 | com1: enabled=1, mode=null, dev=none 46 | com2: enabled=0 47 | com3: enabled=0 48 | com4: enabled=0 49 | -------------------------------------------------------------------------------- /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((nil 2 | (indent-tabs-mode . t) 3 | (tab-width . 8)) 4 | (c-mode 5 | (c-file-style . "bsd") 6 | (c-basic-offset . 8)) 7 | (shell-mode 8 | (sh-basic-offset . 8) 9 | (sh-indentation . 8)) 10 | (python-mode 11 | (indent-tabs-mode . nil)) 12 | ) 13 | -------------------------------------------------------------------------------- /.gdbinit.tmpl: -------------------------------------------------------------------------------- 1 | set $lastcs = -1 2 | set $amd64 = -1 3 | 4 | define hook-stop 5 | # There doesn't seem to be a good way to detect if we're in 16- or 6 | # 32-bit mode, but we always run with CS == 8 in 32-bit mode. 7 | 8 | if $amd64 == -1 9 | if $cs == 8 || $cs == 27 10 | if $lastcs != 8 && $lastcs != 27 && $cs==8 11 | set architecture i386 12 | end 13 | x/i $pc 14 | else 15 | if $lastcs == -1 || $lastcs == 8 || $lastcs == 27 || $cs==0 16 | set architecture i8086 17 | end 18 | # Translate the segment:offset into a physical address 19 | printf "[%4x:%4x] ", $cs, $eip 20 | x/i $cs*16+$eip 21 | end 22 | set $lastcs = $cs 23 | end 24 | end 25 | 26 | #initially set architecture to x86_64 27 | echo + target remote localhost:1234\n 28 | target remote localhost:1234 29 | 30 | # If this fails, it's probably because your GDB doesn't support ELF. 31 | # Look at the tools page at 32 | # http://pdos.csail.mit.edu/6.828/2009/tools.html 33 | # for instructions on building GDB with ELF support. 34 | echo + symbol-file obj/kern/kernel\n 35 | symbol-file obj/kern/kernel 36 | 37 | break jumpto_longmode 38 | commands 39 | set $amd64 = 1 40 | tbreak *0x0 41 | commands 42 | set architecture i386:x86-64 43 | set $lastcs = $cs 44 | set $amd64 = 0 45 | continue 46 | end 47 | si 48 | end 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /obj 2 | /jos.in 3 | /jos.log 4 | /jos.out 5 | /jos.out.* 6 | /jos.cmd 7 | /.gdbinit 8 | /wget.log 9 | /qemu.pcap 10 | /qemu.pcap.* 11 | /qemu.out 12 | /qemu.log 13 | /gradelib.pyc 14 | /lab?-handin.tar.gz 15 | /lab?/ 16 | /sol?/ 17 | /conf/lab.mk 18 | *~ 19 | vivek.map 20 | -------------------------------------------------------------------------------- /CODING: -------------------------------------------------------------------------------- 1 | JOS CODING STANDARDS 2 | 3 | It's easier on everyone if all authors working on a shared 4 | code base are consistent in the way they write their programs. 5 | We have the following conventions in our code: 6 | 7 | * No space after the name of a function in a call 8 | For example, printf("hello") not printf ("hello"). 9 | 10 | * One space after keywords "if", "for", "while", "switch". 11 | For example, if (x) not if(x). 12 | 13 | * Space before braces. 14 | For example, if (x) { not if (x){. 15 | 16 | * Function names are all lower-case separated by underscores. 17 | 18 | * Beginning-of-line indentation via tabs, not spaces. 19 | 20 | * Preprocessor macros are always UPPERCASE. 21 | There are a few grandfathered exceptions: assert, panic, 22 | static_assert, offsetof. 23 | 24 | * Pointer types have spaces: (uint16_t *) not (uint16_t*). 25 | 26 | * Multi-word names are lower_case_with_underscores. 27 | 28 | * Comments in imported code are usually C /* ... */ comments. 29 | Comments in new code are C++ style //. 30 | 31 | * In a function definition, the function name starts a new line. 32 | Then you can grep -n '^foo' */*.c to find the definition of foo. 33 | 34 | * Functions that take no arguments are declared f(void) not f(). 35 | 36 | The included .dir-locals.el file will automatically set up the basic 37 | indentation style in Emacs. 38 | -------------------------------------------------------------------------------- /bochs_readme: -------------------------------------------------------------------------------- 1 | To successfully debug the lab8, we have to rebuild the bochs with gdb stubs support. We can download bochs source code from http://sourceforge.net/projects/bochs/files/bochs/2.6.7/ 2 | 3 | After downloading and decompressing the bochs-2.6.7.tar.gz, we have to do some configuration to enable needed features of bochs with the following command: 4 | 5 | ./configure --enable-x86-64 --enable-vmx=2 --enable-gdb-stub --enable-pci --enable-e1000 --enable-fpu --with-all-libs --prefix=/usr 6 | 7 | Then we can make the bochs. Errors in the make process are mainly caused by missing some supporting libraries in your system. Installing build-essentials, g++, libgtk2.0-dev, libxrandr-dev, and xorg-dev may help. 8 | 9 | When make finished, you can install following command to install the bochs: sudo make install 10 | -------------------------------------------------------------------------------- /boot/Makefrag: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile fragment for the JOS kernel. 3 | # This is NOT a complete makefile; 4 | # you must run GNU make in the top-level directory 5 | # where the GNUmakefile is located. 6 | # 7 | OBJDIRS += boot 8 | 9 | BOOT_OBJS := $(OBJDIR)/boot/boot.o $(OBJDIR)/boot/main.o 10 | 11 | $(OBJDIR)/boot/%.o: boot/%.c 12 | @echo + cc -Os $< 13 | @mkdir -p $(@D) 14 | $(V)$(CC) -nostdinc $(BOOT_CFLAGS) -Os -c -o $@ $< 15 | 16 | $(OBJDIR)/boot/%.o: boot/%.S 17 | @echo + as $< 18 | @mkdir -p $(@D) 19 | $(V)$(CC) -nostdinc $(BOOT_CFLAGS) -c -o $@ $< 20 | 21 | $(OBJDIR)/boot/boot: $(BOOT_OBJS) 22 | @echo + ld $(OBJDIR)/boot/boot 23 | $(V)$(LD) $(BOOT_LDFLAGS) -N -e start -Ttext 0x7c00 -o $@.out $^ 24 | $(V)$(OBJDUMP) -S $@.out >$@.asm 25 | $(V)$(OBJCOPY) -S -O binary -j .text $@.out $@ 26 | $(V)perl boot/sign.pl $(OBJDIR)/boot/boot 27 | 28 | 29 | -------------------------------------------------------------------------------- /boot/sign.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | open(BB, $ARGV[0]) || die "open $ARGV[0]: $!"; 4 | 5 | binmode BB; 6 | my $buf; 7 | read(BB, $buf, 1000); 8 | $n = length($buf); 9 | 10 | if($n > 510){ 11 | print STDERR "boot block too large: $n bytes (max 510)\n"; 12 | exit 1; 13 | } 14 | 15 | print STDERR "boot block is $n bytes (max 510)\n"; 16 | 17 | $buf .= "\0" x (510-$n); 18 | $buf .= "\x55\xAA"; 19 | 20 | open(BB, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; 21 | binmode BB; 22 | print BB $buf; 23 | close BB; 24 | -------------------------------------------------------------------------------- /challenge1.txt: -------------------------------------------------------------------------------- 1 | List challenge problems completed as part of the lab 1 handin, as well 2 | as the problem number. 3 | -------------------------------------------------------------------------------- /challenge2.txt: -------------------------------------------------------------------------------- 1 | List challenge problems completed as part of the lab 2 handin, as well 2 | as the problem number. If you worked any previous lab challenges and 3 | submitted them with this lab, list them here, along with the lab number. 4 | -------------------------------------------------------------------------------- /challenge3.txt: -------------------------------------------------------------------------------- 1 | List challenge problems completed as part of the lab 3 handin, as well 2 | as the problem number. If you worked any previous lab challenges and 3 | submitted them with this lab, list them here, along with the lab number. 4 | -------------------------------------------------------------------------------- /challenge4.txt: -------------------------------------------------------------------------------- 1 | List challenge problems completed as part of the lab 4 handin, as well 2 | as the problem number. If you worked any previous lab challenges and 3 | submitted them with this lab, list them here, along with the lab number. 4 | -------------------------------------------------------------------------------- /challenge5.txt: -------------------------------------------------------------------------------- 1 | List challenge problems completed as part of the lab 5 handin, as well 2 | as the problem number. If you worked any previous lab challenges and 3 | submitted them with this lab, list them here, along with the lab number. 4 | -------------------------------------------------------------------------------- /challenge6.txt: -------------------------------------------------------------------------------- 1 | List challenge problems completed as part of the lab 6 handin, as well 2 | as the problem number. If you worked any previous lab challenges and 3 | submitted them with this lab, list them here, along with the lab number. 4 | -------------------------------------------------------------------------------- /challenge7.txt: -------------------------------------------------------------------------------- 1 | List challenge problems completed as part of the lab 7 handin, as well 2 | as the problem number. If you worked any previous lab challenges and 3 | submitted them with this lab, list them here, along with the lab number. 4 | -------------------------------------------------------------------------------- /conf/env.mk: -------------------------------------------------------------------------------- 1 | # env.mk - configuration variables for the JOS lab 2 | 3 | # '$(V)' controls whether the lab makefiles print verbose commands (the 4 | # actual shell commands run by Make), as well as the "overview" commands 5 | # (such as '+ cc lib/readline.c'). 6 | # 7 | # For overview commands only, the line should read 'V = @'. 8 | # For overview and verbose commands, the line should read 'V ='. 9 | V = @ 10 | 11 | # If your system-standard GNU toolchain is ELF-compatible, then comment 12 | # out the following line to use those tools (as opposed to the i386-jos-elf 13 | # tools that the 6.828 make system looks for by default). 14 | # 15 | # GCCPREFIX='' 16 | 17 | # If the makefile cannot find your QEMU binary, uncomment the 18 | # following line and set it to the full path to QEMU. 19 | # 20 | # QEMU= 21 | -------------------------------------------------------------------------------- /conf/lab.mk: -------------------------------------------------------------------------------- 1 | LAB=8 2 | PACKAGEDATE=Wed Mar 14 19:12:24 EDT 2018 3 | -------------------------------------------------------------------------------- /fs/fs.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SECTSIZE 512 // bytes per disk sector 5 | #define BLKSECTS (BLKSIZE / SECTSIZE) // sectors per block 6 | 7 | /* Disk block n, when in memory, is mapped into the file system 8 | * server's address space at DISKMAP + (n*BLKSIZE). */ 9 | #define DISKMAP 0x10000000 10 | 11 | /* Maximum disk size we can handle (3GB) */ 12 | #define DISKSIZE 0xC0000000 13 | 14 | struct Super *super; // superblock 15 | uint32_t *bitmap; // bitmap blocks mapped in memory 16 | 17 | /* ide.c */ 18 | bool ide_probe_disk1(void); 19 | void ide_set_disk(int diskno); 20 | int ide_read(uint32_t secno, void *dst, size_t nsecs); 21 | int ide_write(uint32_t secno, const void *src, size_t nsecs); 22 | 23 | /* bc.c */ 24 | void* diskaddr(uint64_t blockno); 25 | bool va_is_mapped(void *va); 26 | bool va_is_dirty(void *va); 27 | void flush_block(void *addr); 28 | void bc_init(void); 29 | 30 | /* fs.c */ 31 | void fs_init(void); 32 | int file_get_block(struct File *f, uint32_t file_blockno, char **pblk); 33 | int file_create(const char *path, struct File **f); 34 | int file_open(const char *path, struct File **f); 35 | ssize_t file_read(struct File *f, void *buf, size_t count, off_t offset); 36 | int file_write(struct File *f, const void *buf, size_t count, off_t offset); 37 | int file_set_size(struct File *f, off_t newsize); 38 | void file_flush(struct File *f); 39 | int file_remove(const char *path); 40 | void fs_sync(void); 41 | int file_block_walk(struct File *f, uint32_t filebno, uint32_t **ppdiskbno, bool alloc); 42 | /* int map_block(uint32_t); */ 43 | bool block_is_free(uint32_t blockno); 44 | int alloc_block(void); 45 | 46 | /* test.c */ 47 | void fs_test(void); 48 | 49 | #ifdef VMM_GUEST 50 | /* vmx_host.c */ 51 | uint64_t get_host_fd(); 52 | int host_read(uint32_t secno, void *dst, size_t nsecs); 53 | int host_write(uint32_t secno, const void *src, size_t nsecs); 54 | void host_ipc_init(); 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /fs/ide.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Minimal PIO-based (non-interrupt-driven) IDE driver code. 3 | * For information about what all this IDE/ATA magic means, 4 | * see the materials available on the class references page. 5 | */ 6 | 7 | #include "fs.h" 8 | #include 9 | 10 | #define IDE_BSY 0x80 11 | #define IDE_DRDY 0x40 12 | #define IDE_DF 0x20 13 | #define IDE_ERR 0x01 14 | 15 | static int diskno = 1; 16 | 17 | static int 18 | ide_wait_ready(bool check_error) 19 | { 20 | int r; 21 | 22 | while (((r = inb(0x1F7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY) 23 | /* do nothing */; 24 | 25 | if (check_error && (r & (IDE_DF|IDE_ERR)) != 0) 26 | return -1; 27 | return 0; 28 | } 29 | 30 | bool 31 | ide_probe_disk1(void) 32 | { 33 | int r, x; 34 | 35 | // wait for Device 0 to be ready 36 | ide_wait_ready(0); 37 | 38 | // switch to Device 1 39 | outb(0x1F6, 0xE0 | (1<<4)); 40 | 41 | // check for Device 1 to be ready for a while 42 | for (x = 0; 43 | x < 1000 && ((r = inb(0x1F7)) & (IDE_BSY|IDE_DF|IDE_ERR)) != 0; 44 | x++) 45 | /* do nothing */; 46 | 47 | // switch back to Device 0 48 | outb(0x1F6, 0xE0 | (0<<4)); 49 | 50 | cprintf("Device 1 presence: %d\n", (x < 1000)); 51 | return (x < 1000); 52 | } 53 | 54 | void 55 | ide_set_disk(int d) 56 | { 57 | if (d != 0 && d != 1) 58 | panic("bad disk number"); 59 | diskno = d; 60 | } 61 | 62 | int 63 | ide_read(uint32_t secno, void *dst, size_t nsecs) 64 | { 65 | int r; 66 | 67 | assert(nsecs <= 256); 68 | 69 | ide_wait_ready(0); 70 | 71 | outb(0x1F2, nsecs); 72 | outb(0x1F3, secno & 0xFF); 73 | outb(0x1F4, (secno >> 8) & 0xFF); 74 | outb(0x1F5, (secno >> 16) & 0xFF); 75 | outb(0x1F6, 0xE0 | ((diskno&1)<<4) | ((secno>>24)&0x0F)); 76 | outb(0x1F7, 0x20); // CMD 0x20 means read sector 77 | 78 | for (; nsecs > 0; nsecs--, dst += SECTSIZE) { 79 | if ((r = ide_wait_ready(1)) < 0) 80 | return r; 81 | insw(0x1F0, dst, SECTSIZE/2); 82 | } 83 | 84 | return 0; 85 | } 86 | 87 | int 88 | ide_write(uint32_t secno, const void *src, size_t nsecs) 89 | { 90 | int r; 91 | 92 | assert(nsecs <= 256); 93 | 94 | ide_wait_ready(0); 95 | 96 | outb(0x1F2, nsecs); 97 | outb(0x1F3, secno & 0xFF); 98 | outb(0x1F4, (secno >> 8) & 0xFF); 99 | outb(0x1F5, (secno >> 16) & 0xFF); 100 | outb(0x1F6, 0xE0 | ((diskno&1)<<4) | ((secno>>24)&0x0F)); 101 | outb(0x1F7, 0x30); // CMD 0x30 means write sector 102 | 103 | for (; nsecs > 0; nsecs--, src += SECTSIZE) { 104 | if ((r = ide_wait_ready(1)) < 0) 105 | return r; 106 | outsw(0x1F0, src, SECTSIZE/2); 107 | } 108 | 109 | return 0; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /fs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | jhttpd on JOS 4 | 5 | 6 |
7 |

This file came from JOS.

8 | Cheesy web page! 9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /fs/lorem: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur 2 | adipisicing elit, sed do eiusmod tempor 3 | incididunt ut labore et dolore magna 4 | aliqua. Ut enim ad minim veniam, quis 5 | nostrud exercitation ullamco laboris 6 | nisi ut aliquip ex ea commodo consequat. 7 | Duis aute irure dolor in reprehenderit 8 | in voluptate velit esse cillum dolore eu 9 | fugiat nulla pariatur. Excepteur sint 10 | occaecat cupidatat non proident, sunt in 11 | culpa qui officia deserunt mollit anim 12 | id est laborum. 13 | -------------------------------------------------------------------------------- /fs/motd: -------------------------------------------------------------------------------- 1 | This is /motd, the message of the day. 2 | 3 | Welcome to the JOS kernel, now with a file system! 4 | 5 | -------------------------------------------------------------------------------- /fs/motd_guest: -------------------------------------------------------------------------------- 1 | 2 | This is /motd, the message of the day. 3 | 4 | Welcome to the JOS guest kernel. 5 | 6 | What is the tortoise standing on? 7 | You are very clever, young man, very clever, 8 | said the old lady. But it is turtles all the way 9 | down! 10 | 11 | -------------------------------------------------------------------------------- /fs/newmotd: -------------------------------------------------------------------------------- 1 | This is the NEW message of the day! 2 | 3 | -------------------------------------------------------------------------------- /fs/robig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oscarlab/hoss/69da6bc905ba0db77db6809985b34b28e347eb01/fs/robig -------------------------------------------------------------------------------- /fs/script: -------------------------------------------------------------------------------- 1 | echo This is from the script. 2 | cat lorem | num | cat 3 | echo These are my file descriptors. 4 | lsfd -1 5 | echo This is the end of the script. 6 | -------------------------------------------------------------------------------- /fs/test.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "fs.h" 6 | 7 | static char *msg = "This is the NEW message of the day!\n\n"; 8 | 9 | void 10 | fs_test(void) 11 | { 12 | struct File *f; 13 | int r; 14 | char *blk; 15 | uint32_t *bits; 16 | 17 | // back up bitmap 18 | if ((r = sys_page_alloc(0, (void*) PGSIZE, PTE_P|PTE_U|PTE_W)) < 0) 19 | panic("sys_page_alloc: %e", r); 20 | bits = (uint32_t*) PGSIZE; 21 | memmove(bits, bitmap, PGSIZE); 22 | // allocate block 23 | if ((r = alloc_block()) < 0) 24 | panic("alloc_block: %e", r); 25 | // check that block was free 26 | assert(bits[r/32] & (1 << (r%32))); 27 | // and is not free any more 28 | assert(!(bitmap[r/32] & (1 << (r%32)))); 29 | cprintf("alloc_block is good\n"); 30 | 31 | if ((r = file_open("/not-found", &f)) < 0 && r != -E_NOT_FOUND) 32 | panic("file_open /not-found: %e", r); 33 | else if (r == 0) 34 | panic("file_open /not-found succeeded!"); 35 | if ((r = file_open("/newmotd", &f)) < 0) 36 | panic("file_open /newmotd: %e", r); 37 | cprintf("file_open is good\n"); 38 | 39 | if ((r = file_get_block(f, 0, &blk)) < 0) 40 | panic("file_get_block: %e", r); 41 | if (strcmp(blk, msg) != 0) 42 | panic("file_get_block returned wrong data"); 43 | cprintf("file_get_block is good\n"); 44 | 45 | *(volatile char*)blk = *(volatile char*)blk; 46 | assert((uvpt[PGNUM(blk)] & PTE_D)); 47 | file_flush(f); 48 | assert(!(uvpt[PGNUM(blk)] & PTE_D)); 49 | cprintf("file_flush is good\n"); 50 | 51 | if ((r = file_set_size(f, 0)) < 0) 52 | panic("file_set_size: %e", r); 53 | assert(f->f_direct[0] == 0); 54 | assert(!(uvpt[PGNUM(f)] & PTE_D)); 55 | cprintf("file_truncate is good\n"); 56 | 57 | if ((r = file_set_size(f, strlen(msg))) < 0) 58 | panic("file_set_size 2: %e", r); 59 | assert(!(uvpt[PGNUM(f)] & PTE_D)); 60 | if ((r = file_get_block(f, 0, &blk)) < 0) 61 | panic("file_get_block 2: %e", r); 62 | strcpy(blk, msg); 63 | assert((uvpt[PGNUM(blk)] & PTE_D)); 64 | file_flush(f); 65 | assert(!(uvpt[PGNUM(blk)] & PTE_D)); 66 | assert(!(uvpt[PGNUM(f)] & PTE_D)); 67 | cprintf("file rewrite is good\n"); 68 | } 69 | -------------------------------------------------------------------------------- /fs/testshell.sh: -------------------------------------------------------------------------------- 1 | echo hello world | cat 2 | cat lorem 3 | cat lorem |num 4 | cat lorem |num |num |num |num |num 5 | lsfd -1 6 | cat script 7 | sh