Compare commits

..

130 Commits

Author SHA1 Message Date
a52dc89f9f diagdummy srpr2 wait for device lock 2025-11-24 22:29:59 +01:00
cc2b96f37a qemu_pci_serial device locking/sync 2025-11-24 22:29:32 +01:00
80a29d8ff6 Handle continous jobs via new subsystem - CJob 2025-11-24 21:53:51 +01:00
4f55d765b4 ulib Fix volatile 2025-11-24 17:14:45 +01:00
ec732d4627 Make SpinLock IRQ_CTX irq_flags volatile 2025-11-24 17:14:28 +01:00
3f3795df3c Fix stack alignment 2025-11-24 17:04:33 +01:00
2faad79559 diagdummy Add srpr2 subcommand for contiguous printing to serial (and testing access races) 2025-11-24 01:00:53 +01:00
9b25dcd691 pci ata Print info about falling back to ISA 2025-11-23 23:00:51 +01:00
33b3a641fb qemu_pci_serial driver 2025-11-23 22:56:45 +01:00
d3a91b6438 Move PCI ATA driver to pci/ata 2025-11-23 21:49:49 +01:00
fa152cac4d PCI driver rewrite 2025-11-23 21:37:12 +01:00
e105b2fe35 ulib Remove sync 2025-11-23 19:51:48 +01:00
7f78f20b17 diadummy Testing serial device 2025-11-22 12:22:35 +01:00
b4d6315dea Add FAT32 support 2025-11-19 15:54:17 +01:00
a05e73e69a legal Add fat_io_lib license 2025-11-19 15:51:02 +01:00
0cc78a7247 Port fat_io_lib, mount atasd0mp1 as sys: 2025-11-19 15:50:00 +01:00
5d77974586 Don't clean up backing storedev on mountpoint cleanup 2025-11-19 01:20:18 +01:00
ae6f5d9df0 Fix int8_t cast in sys_ipc_mbusconsume() 2025-11-19 00:13:17 +01:00
ecfe1a7eae Detect ATA driver via PCI 2025-11-18 23:28:45 +01:00
88f9d0e3d4 Spinlock fix small race window 2025-11-18 23:28:11 +01:00
28c95303e9 Fix PIC, add small delays when initializing 2025-11-18 23:27:49 +01:00
638214a0e2 rename ps2kb_intr() to ps2kbdev_keycode() 2025-11-18 21:59:49 +01:00
4fb5448dd9 Change order of sending EOI to PIC, works with -enable-kvm now 2025-11-18 16:56:28 +01:00
2a0dddead3 Fix interrupts not working with -enable-kvm 2025-11-18 14:20:46 +01:00
edcdaa5c60 List PCI devices 2025-11-17 04:43:41 +01:00
77b5a4a153 Modularize interrupt handlers, split up scheduler and PIT interrupt handlers 2025-11-17 01:08:23 +01:00
f2b7c5da57 Avoid deadlock in proc_killself() 2025-11-17 00:52:25 +01:00
58a47edc79 Shorter ata driver and partition dev names 2025-11-16 00:08:31 +01:00
0a43ba36cd Reduce binary sizes for the kernel and userspace apps 2025-11-15 23:56:16 +01:00
e66fe4030d tb Implement "#" comments 2025-11-15 22:25:41 +01:00
55b58bbe22 tb Fix runtime being initialized on every interp_runstring() exec, which causes memory leaks 2025-11-15 22:20:45 +01:00
bc53f9746e Fix mbus skipping other consumers in ipc_mbusconsume() 2025-11-15 01:46:46 +01:00
d7059ac4e3 Fix term_getsizes(), return proper char count 2025-11-15 01:46:17 +01:00
af27592957 tb Print colorful shell prompt and logged cmds, print terminal W/H 2025-11-15 00:58:40 +01:00
7da422fdb6 ulib Add term_getsizes() syscall 2025-11-15 00:58:09 +01:00
871c9cf439 Remove fbdev, add term_getsizes() syscall to get terminal width+height 2025-11-15 00:57:53 +01:00
cf4a6b23c7 init Move to term_XXX() interface 2025-11-15 00:39:27 +01:00
71fa87d7a4 ulib term_write() syscall 2025-11-15 00:39:04 +01:00
ecee481b33 Reimplement the terminal user access via separate syscalls 2025-11-15 00:38:54 +01:00
3726cc49da New font 2025-11-15 00:26:55 +01:00
ef7a45e7cf Remove ps2kbdev dev functions in favour of MBus 2025-11-11 23:50:24 +01:00
a530304e18 tb Use ps2kb MBus to handle C-S 2025-11-11 23:49:51 +01:00
f8863d19bd tb Use MBus for keyboard handling 2025-11-11 23:45:10 +01:00
f9d3fde4ad ulib Add MBus syscalls 2025-11-11 23:44:55 +01:00
c2364fbd48 Add MBus syscalls 2025-11-11 23:44:43 +01:00
4fe907a733 Clean up PS/2 keyboard driver, new IPC mechanism MBus (message bus) 2025-11-11 23:10:38 +01:00
07fc8a5562 Remove sched_ticks, move proc_reaper() out to proc_tick() function 2025-11-11 22:07:58 +01:00
5bd6ca0fa7 Remove extconf and KPRINTF_COLORS 2025-11-11 21:31:17 +01:00
7256fcd818 Prefix backtrace() with intr_ 2025-11-11 21:28:54 +01:00
51e89c8603 Remove atomic.h 2025-11-11 21:27:47 +01:00
566b35f4d5 Big code refactor, get rid of HAL entirely 2025-11-11 21:26:27 +01:00
7015bc9576 Decouple I/O from HAL 2025-11-11 19:59:01 +01:00
344952fb5f Move string functions/utils from HAL to std/string 2025-11-11 19:54:09 +01:00
f5dae4984d Rename base.img.6pack to base.img.6pk 2025-11-11 01:49:49 +01:00
8fc99a5fb1 init Remove useless ref to ps2kbdev device 2025-11-11 01:23:44 +01:00
91ecc2dc6a Break when IpcPipe is full 2025-11-11 00:51:29 +01:00
1f793f287f Clean up kernel/proc, remove devs_spinlock, remove PROC_DIE() macro 2025-11-11 00:32:09 +01:00
44893aeeb0 tb Fix minor leak in 'do' builtin function (ufree args1) 2025-11-10 20:44:54 +01:00
26e5d92947 Use hal_memcpy to propagate new proc interrupt frame 2025-11-10 20:25:55 +01:00
d81d1133dd diagdummy Test concurrent openfs 2025-11-10 20:23:28 +01:00
7e3b162591 Protect busy VfsObjs during opening and deleting 2025-11-10 20:23:03 +01:00
a349154545 ulib Fix uninitialized variables 2025-11-10 18:49:08 +01:00
1f93e8db13 Reduce proc stack size to 1M 2025-11-10 18:48:47 +01:00
81015d600b ulib Non-partitioned umalloc implementation 2025-11-10 18:36:27 +01:00
5c02d4d44a Fix distingishing kernel/user mode cpu exceptions 2025-11-10 18:35:46 +01:00
efaddb970a Remove useless path fiels in VfsObj 2025-11-10 18:19:17 +01:00
f4dbe830db Use FAT16/20iMB for boot partition 2025-11-10 14:16:58 +01:00
6da93cd854 fs Fix bug, check if fs_read() returned < 0 2025-11-09 23:06:18 +01:00
4084336705 ulib Add umallocbig() and ufreebig() for non-fragmented allocations 2025-11-09 22:21:19 +01:00
02d60129b1 Compress base.img using FastLZ library 2025-11-09 21:38:27 +01:00
e4a5c07b3d Change proc state under held spinlock 2025-11-08 21:40:15 +01:00
e0162e9e0b Add dev_delhandle() syscall to delete a device handle from process resources 2025-11-08 16:24:04 +01:00
2fa77d073f Only allow absolute paths 2025-11-06 21:58:24 +01:00
f3fcc92991 README.md add screenshots 2025-11-04 00:53:16 +01:00
0ed10b019a static Add screenshots 2025-11-04 00:51:24 +01:00
da72450d2a add README.md 2025-11-04 00:42:54 +01:00
771bbd1e9a fs lsmount subcommand for listing VFS mountpoint info 2025-11-04 00:25:57 +01:00
95e5d17018 ulib Add vfsavailmounts() and vfsmountstat() 2025-11-04 00:25:24 +01:00
88ac5cf877 New syscalls vfsavailmounts() and vfsmountstat() to get info about current VFS mountpoints 2025-11-04 00:24:58 +01:00
9612e7961e No networking for now 2025-11-02 18:31:51 +01:00
0f93aa2a81 Implement schedsleep() syscall to sleep a process for a given time 2025-11-02 16:46:37 +01:00
179c4b98e2 Only one fb-terminal-based putchar_() 2025-11-02 14:16:10 +01:00
e52b33671b Fix very subtle spinlock race condition due to atomics misuse 2025-11-02 02:17:03 +01:00
9ccc6751e3 Use CS register to detect kernel code vs. user code in case of an exception 2025-11-02 00:46:31 +01:00
d947192475 Make socket port binding a separate step with ipc_netsockbindport() syscall 2025-10-29 22:33:41 +01:00
4417141216 Implement ipc_netsockdelete() syscall and automatic dangling socket cleanup 2025-10-29 21:21:35 +01:00
7db6a8e130 Add fsh_t type for filesystem handles 2025-10-29 15:39:46 +01:00
815c2239fe Porting PicoTCP WIP 2025-10-29 14:29:06 +01:00
6722f42e68 fix tiny leak 2025-10-26 17:38:39 +01:00
2b3b135160 fix unused stuff warnings 2025-10-25 23:26:32 +02:00
f389f58daf fs Add unmount subcommand 2025-10-25 23:21:30 +02:00
08c1171d50 format uhome partition for disk.hdd 2025-10-25 23:07:11 +02:00
43482d5444 dev Device names are getting quite long heh 2025-10-20 00:02:08 +02:00
e8d8e5e9f9 Expose raw reads/writes to store devs via dev interface 2025-10-20 00:00:53 +02:00
ff33afbb2a fs Clean up dummy mount point post-formatting 2025-10-19 23:03:13 +02:00
1e0eca3076 fs Disk formatting subcommand 2025-10-19 23:01:02 +02:00
a96ea5edb6 tb Command-like scripts 2025-10-19 23:00:46 +02:00
01da863b8b Handle disk partitioning 2025-10-19 22:29:19 +02:00
68e0e8848d Clean up kernel/storedev/atasd.c, remove ata_probe1() 2025-10-19 15:48:51 +02:00
c3621a33dc Support up to 4 ATA drives (primary and secondary bus) 2025-10-19 15:46:56 +02:00
4452f1b196 Change naming scheme for atasd and ramsd 2025-10-18 22:16:01 +02:00
0e0bff4888 Use implicitly passed _caller_pid in syscalls 2025-10-18 12:20:43 +02:00
a5fe64b253 Pass implicit PID into syscalls 2025-10-18 12:10:59 +02:00
d1d777ec75 Enable cmd logging 2025-10-18 10:48:52 +02:00
a46da0a7ae tb Enable/disable command logging dynamically + setlogcmds builtin 2025-10-18 10:48:31 +02:00
d136c001df tb Handle line continuation and left trim lines before tokenizing 2025-10-18 10:36:34 +02:00
9212ff0e97 ulib String tokenization with line continuation 2025-10-18 10:36:08 +02:00
76faf0581d ulib setjmp() and longjmp() 2025-10-18 10:01:57 +02:00
e1a850a8f8 Don't regenerate system.img on every build 2025-10-18 09:10:11 +02:00
8a1d42896c Decrease user process stack size to 4MiB 2025-10-17 00:04:10 +02:00
55f5fbefe4 tb Add & syntax to run commands without blocking/waiting 2025-10-16 15:55:39 +02:00
e7421f73bb pctl List process uptime 2025-10-16 15:46:27 +02:00
43ab1674e8 ulib More time conversion utils 2025-10-16 15:46:06 +02:00
1a2962de80 Track process uptime 2025-10-16 15:45:36 +02:00
5158305fa6 Fix parenthesis in time_isleap() 2025-10-16 15:23:50 +02:00
553b893a9c time Utility for working with time/dates 2025-10-16 14:15:55 +02:00
7445689010 ulib Time utilities, expose time() syscall 2025-10-16 14:15:27 +02:00
702f0ddf87 Add time() syscall 2025-10-16 14:15:05 +02:00
48231931bd Improve ipcpipe locking 2025-10-15 23:26:14 +02:00
eefff6e492 Get RTC date 2025-10-15 23:08:23 +02:00
846ddd54f3 Automate aliasing baseimg apps 2025-10-15 21:26:48 +02:00
317667cfb8 Add eachfile and mkaliasbn builtins 2025-10-15 21:26:30 +02:00
7936eb92f6 fs Implement del command 2025-10-15 20:11:07 +02:00
e917e81e78 Expose fs_delete() via ulib 2025-10-15 20:10:56 +02:00
ac6ebce112 Add fs_delete() syscall 2025-10-15 20:10:26 +02:00
371d777a7c vfs_delete() implement deleting files 2025-10-15 20:10:00 +02:00
a81d4e0c3b qemu-x86_64.sh run with system.img drive 2025-10-15 19:57:18 +02:00
fd8c6f6441 Create system disk image 2025-10-14 21:50:25 +02:00
1f7f81016e Remove SYS_IOCTL from sysdefs/syscall.h 2025-10-14 21:35:35 +02:00
fa6c194163 Break devctl() up into smaller syscalls 2025-10-14 21:35:10 +02:00
282 changed files with 16000 additions and 2071 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
/iso_root /iso_root
*.iso *.iso
*.img *.img
*.hdd
*.6pk

19
FastLZ/.editorconfig Normal file
View File

@ -0,0 +1,19 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
[*.{c,h}]
indent_size = 2
indent_style = space
[Makefile]
indent_style = tab
[Makefile.win]
indent_style = tab

View File

@ -0,0 +1,32 @@
name: amd64_linux_clang
on: [push, pull_request]
jobs:
amd64_linux_clang:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: clang
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt install -y make clang
- run: clang --version
- run: cd tests && make roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,32 @@
name: amd64_linux_gcc
on: [push, pull_request]
jobs:
amd64_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt install -y make gcc
- run: gcc --version
- run: cd tests && make roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,32 @@
name: amd64_linux_tcc
on: [push, pull_request]
jobs:
amd64_linux_tcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: tcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt install -y make tcc
- run: tcc -v
- run: cd tests && make roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,29 @@
name: amd64_macos_clang
on: [push, pull_request]
jobs:
amd64_macos_clang:
runs-on: macos-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: cc --version
- run: cd tests && make roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,32 @@
name: amd64_macos_gcc
on: [push, pull_request]
jobs:
amd64_macos_gcc:
runs-on: macos-12
timeout-minutes: 10
env:
CC: gcc-9
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: brew install gcc@9
- run: gcc-9 --version
- run: cd tests && make roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,34 @@
name: amd64_windows_clang
on: [push, pull_request]
jobs:
amd64_windows_clang:
runs-on: windows-2019
timeout-minutes: 10
env:
CC: clang
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- uses: msys2/setup-msys2@v2
with:
install: make mingw-w64-x86_64-clang
- run: clang --version
- run: cd tests && make roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,34 @@
name: amd64_windows_gcc
on: [push, pull_request]
jobs:
amd64_windows_gcc:
runs-on: windows-2019
timeout-minutes: 10
env:
CC: gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- uses: msys2/setup-msys2@v2
with:
install: gcc make
- run: gcc --version
- run: cd tests && make roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,35 @@
name: amd64_windows_tcc
on: [push, pull_request]
jobs:
amd64_windows_tcc:
runs-on: windows-2019
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- name: Install tcc
run: |
echo "5a3979bd5044b795547a4948a5625a12 tcc.zip" > checksum.md5
dos2unix checksum.md5
curl -L -o tcc.zip https://archive.org/download/tinyccompiler/tcc-0.9.27-win32-bin.zip
md5sum -c checksum.md5 && unzip -q tcc.zip
- run: tcc\x86_64-win32-tcc.exe -v
- run: cd tests && make roundtrip CC=..\tcc\x86_64-win32-tcc.exe
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make CC=..\tcc\x86_64-win32-tcc.exe
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,30 @@
name: amd64_windows_vs2019
on: [push, pull_request]
jobs:
amd64_windows_vs2019:
runs-on: windows-2019
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- uses: ilammy/msvc-dev-cmd@v1
- run: cl
- run: cd tests && mingw32-make -f Makefile.win roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make -f Makefile.win
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: arm64_linux_gcc
on: [push, pull_request]
jobs:
arm64_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/aarch64-linux-musl-cross.tgz
tar xzf aarch64-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-aarch64 ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-aarch64 ./6pack -v
qemu-aarch64 ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-aarch64 ./6unpack -v
qemu-aarch64 ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: armhf_linux_gcc
on: [push, pull_request]
jobs:
armhf_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/armel-linux-musleabihf-cross/bin/armel-linux-musleabihf-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O https://musl.cc/armel-linux-musleabihf-cross.tgz
tar xzf armel-linux-musleabihf-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/armel-linux-musleabihf-cross/bin/armel-linux-musleabihf-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-arm ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-arm ./6pack -v
qemu-arm ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-arm ./6unpack -v
qemu-arm ./6unpack archive.6pk

29
FastLZ/.github/workflows/asan.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Address Sanitizer
on: [push, pull_request]
jobs:
asan:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt install -y make gcc
- run: gcc --version
- run: cd tests && make roundtrip
name: Perform round-trip tests
env:
CFLAGS: "-g -fno-omit-frame-pointer -fsanitize=address"
- run: cd tests && make roundtrip
name: Perform round-trip tests with FASTLZ_USE_MEMMOVE=0
env:
CFLAGS: "-g -fno-omit-frame-pointer -fsanitize=address -DFASTLZ_USE_MEMMOVE=0"

19
FastLZ/.github/workflows/codestyle.yml vendored Normal file
View File

@ -0,0 +1,19 @@
name: Code style
on: [push, pull_request]
jobs:
codestyle:
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- run: sudo apt install -y clang-format-6.0
name: Install clang-format
- run: clang-format-6.0 --version
- run: bash tools/format-code.sh
name: Run code formatter
- run: git diff
- run: git diff --quiet HEAD
name: Check if the styling guide is followed

View File

@ -0,0 +1,52 @@
name: i586_dos_gcc_cross
on: [push, pull_request]
jobs:
i586_dos_gcc_cross:
runs-on: ubuntu-20.04
timeout-minutes: 15
env:
CC: /opt/djgpp/bin/i586-pc-msdosdjgpp-gcc
LDFLAGS: -static
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- name: Prepare cross-compiler
run: |
curl -OL https://github.com/andrewwutw/build-djgpp/releases/download/v3.3/djgpp-linux64-gcc1210.tar.bz2
tar xf djgpp-linux64-gcc1210.tar.bz2 -C /opt
- name: Verify compiler version
run: /opt/djgpp/bin/i586-pc-msdosdjgpp-gcc --version
- name: Install DOSEMU2
run: |
sudo add-apt-repository -y ppa:dosemu2/ppa
sudo apt update -y
sudo apt install -y dosemu2
- run: dosemu --version
- name: Perform round-trip tests
run: |
cd tests
ln -s ../compression-corpus/ corpus
make test_roundtrip TEST_ROUNDTRIP=testrr
file ./testrr.exe
dosemu -dumb -K . -t -E "testrr corpus/"
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
ln -s ../compression-corpus/enwik/enwik8.txt enwik8.txt
make
file ./6pack.exe
dosemu -K . -t -E "6pack.exe -v"
dosemu -K . -t -E "6pack.exe enwik8.txt archive.6pk"
mv enwik8.txt enwik8.txt.orig
dosemu -K . -t -E "6unpack.exe -v"
dosemu -K . -t -E "6unpack.exe archive.6pk"
ls -l enwik8*

View File

@ -0,0 +1,36 @@
name: i686_linux_clang
on: [push, pull_request]
jobs:
i686_linux_clang:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: clang
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y make clang gcc-multilib qemu-user
- run: clang --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS="-static -m32"
file ./test_roundtrip
qemu-i386 ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS="-static -m32"
qemu-i386 ./6pack -v
qemu-i386 ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-i386 ./6unpack -v
qemu-i386 ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: i686_linux_gcc
on: [push, pull_request]
jobs:
i686_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/i686-linux-musl-cross/bin/i686-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O https://musl.cc/i686-linux-musl-cross.tgz
tar xzf i686-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/i686-linux-musl-cross/bin/i686-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-i386 ./test_roundtrip
- name: 'Build and run examples: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-i386 ./6pack -v
qemu-i386 ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-i386 ./6unpack -v
qemu-i386 ./6unpack archive.6pk

View File

@ -0,0 +1,35 @@
name: i686_windows_tcc
on: [push, pull_request]
jobs:
i686_windows_tcc:
runs-on: windows-2019
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- name: Install tcc
run: |
echo "D73CF66CEC8C761DE38C7A3D16C9EB0D tcc.zip" > checksum.md5
dos2unix checksum.md5
curl -L -o tcc.zip https://archive.org/download/tinyccompiler/tcc-0.9.27-win64-bin.zip
md5sum -c checksum.md5 && unzip -q tcc.zip
- run: tcc\i386-win32-tcc.exe -v
- run: cd tests && make roundtrip CC=..\tcc\i386-win32-tcc.exe
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make CC=..\tcc\i386-win32-tcc.exe
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,32 @@
name: i686_windows_vs2019
on: [push, pull_request]
jobs:
i686_windows_vs2019:
runs-on: windows-2019
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86
- run: cl
- run: cd tests && mingw32-make -f Makefile.win roundtrip
name: Perform round-trip tests
- name: 'Build examples: 6pack and 6unpack'
run: cd examples && make -f Makefile.win
- name: 'Run examples: 6pack and 6unpack'
run: |
cd examples
./6pack -v
./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
./6unpack -v
./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: mips64_linux_gcc
on: [push, pull_request]
jobs:
mips64_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/mips64-linux-musl-cross/bin/mips64-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/mips64-linux-musl-cross.tgz
tar xzf mips64-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/mips64-linux-musl-cross/bin/mips64-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-mips64 ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-mips64 ./6pack -v
qemu-mips64 ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-mips64 ./6unpack -v
qemu-mips64 ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: mips64el_linux_gcc
on: [push, pull_request]
jobs:
mips64el_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/mips64el-linux-musl-cross/bin/mips64el-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/mips64el-linux-musl-cross.tgz
tar xzf mips64el-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/mips64el-linux-musl-cross/bin/mips64el-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-mips64el ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-mips64el ./6pack -v
qemu-mips64el ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-mips64el ./6unpack -v
qemu-mips64el ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: mips_linux_gcc
on: [push, pull_request]
jobs:
mips_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/mips-linux-musl-cross/bin/mips-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/mips-linux-musl-cross.tgz
tar xzf mips-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/mips-linux-musl-cross/bin/mips-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-mips ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-mips ./6pack -v
qemu-mips ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-mips ./6unpack -v
qemu-mips ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: mipsel_linux_gcc
on: [push, pull_request]
jobs:
mipsel_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/mipsel-linux-musl-cross/bin/mipsel-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/mipsel-linux-musl-cross.tgz
tar xzf mipsel-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/mipsel-linux-musl-cross/bin/mipsel-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-mipsel ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-mipsel ./6pack -v
qemu-mipsel ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-mipsel ./6unpack -v
qemu-mipsel ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: powerpc_linux_gcc
on: [push, pull_request]
jobs:
powerpc_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/powerpc-linux-musl-cross/bin/powerpc-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/powerpc-linux-musl-cross.tgz
tar xzf powerpc-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/powerpc-linux-musl-cross/bin/powerpc-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-ppc ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-ppc ./6pack -v
qemu-ppc ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-ppc ./6unpack -v
qemu-ppc ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: ppc64_linux_gcc
on: [push, pull_request]
jobs:
ppc64_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/powerpc64-linux-musl-cross/bin/powerpc64-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/powerpc64-linux-musl-cross.tgz
tar xzf powerpc64-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/powerpc64-linux-musl-cross/bin/powerpc64-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-ppc64 ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-ppc64 ./6pack -v
qemu-ppc64 ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-ppc64 ./6unpack -v
qemu-ppc64 ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: ppc64le_linux_gcc
on: [push, pull_request]
jobs:
ppc64le_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/powerpc64le-linux-musl-cross/bin/powerpc64le-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/powerpc64le-linux-musl-cross.tgz
tar xzf powerpc64le-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/powerpc64le-linux-musl-cross/bin/powerpc64le-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-ppc64le ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-ppc64le ./6pack -v
qemu-ppc64le ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-ppc64le ./6unpack -v
qemu-ppc64le ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: riscv64_linux_gcc
on: [push, pull_request]
jobs:
riscv64_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/riscv64-linux-musl-cross/bin/riscv64-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/riscv64-linux-musl-cross.tgz
tar xzf riscv64-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/riscv64-linux-musl-cross/bin/riscv64-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-riscv64 ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-riscv64 ./6pack -v
qemu-riscv64 ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-riscv64 ./6unpack -v
qemu-riscv64 ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: riscv_linux_gcc
on: [push, pull_request]
jobs:
riscv_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/riscv32-linux-musl-cross/bin/riscv32-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/riscv32-linux-musl-cross.tgz
tar xzf riscv32-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/riscv32-linux-musl-cross/bin/riscv32-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-riscv32 ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-riscv32 ./6pack -v
qemu-riscv32 ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-riscv32 ./6unpack -v
qemu-riscv32 ./6unpack archive.6pk

View File

@ -0,0 +1,41 @@
name: s390x_linux_gcc
on: [push, pull_request]
jobs:
s390x_linux_gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
CC: /opt/s390x-linux-musl-cross/bin/s390x-linux-musl-gcc
steps:
- uses: actions/checkout@v3
- name: Retrieve test compression corpus
run: |
git clone https://github.com/ariya/compression-corpus.git
cd compression-corpus
cd enwik
unzip enwik8.zip
- run: sudo apt-get -y -qq update
- run: sudo apt install -y qemu-user
- name: Prepare cross-compiler
run: |
curl -O http://musl.cc/s390x-linux-musl-cross.tgz
tar xzf s390x-linux-musl-cross.tgz -C /opt
- name: Verify compiler version
run: /opt/s390x-linux-musl-cross/bin/s390x-linux-musl-gcc --version
- name: Perform round-trip tests
run: |
cd tests
make test_roundtrip CFLAGS=-static
file ./test_roundtrip
qemu-s390x ./test_roundtrip
- name: 'Build and run example: 6pack and 6unpack'
run: |
cd examples
make CFLAGS=-static
qemu-s390x ./6pack -v
qemu-s390x ./6pack ../compression-corpus/enwik/enwik8.txt archive.6pk
qemu-s390x ./6unpack -v
qemu-s390x ./6unpack archive.6pk

1
FastLZ/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.o

3
FastLZ/.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "compression-corpus"]
path = compression-corpus
url = https://github.com/ariya/compression-corpus.git

8
FastLZ/ChangeLog Normal file
View File

@ -0,0 +1,8 @@
2020-02-02: Version 0.5.0
Minor speed improvement on the decompressor.
Prevent memory violation when decompressing corrupted input.
2020-01-10: Version 0.4.0
Only code & infrastructure clean-up, no new functionality.

21
FastLZ/LICENSE.MIT Normal file
View File

@ -0,0 +1,21 @@
FastLZ - Byte-aligned LZ77 compression library
Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

207
FastLZ/README.md Normal file
View File

@ -0,0 +1,207 @@
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Code style](https://github.com/ariya/fastlz/workflows/Code%20style/badge.svg)](https://github.com/ariya/fastlz/actions)
[![Address Sanitizer](https://github.com/ariya/fastlz/workflows/Address%20Sanitizer/badge.svg)](https://github.com/ariya/fastlz/actions)
## Overview
FastLZ (MIT license) is an ANSI C/C90 implementation of [Lempel-Ziv 77 algorithm](https://en.wikipedia.org/wiki/LZ77_and_LZ78#LZ77) (LZ77) of lossless data compression. It is suitable to compress series of text/paragraphs, sequences of raw pixel data, or any other blocks of data with lots of repetition. It is not intended to be used on images, videos, and other formats of data typically already in an optimal compressed form.
The focus for FastLZ is a very fast compression and decompression, doing that at the cost of the compression ratio. As an illustration, the comparison with zlib when compressing [enwik8](http://www.mattmahoney.net/dc/textdata.html) (also in [more details](https://github.com/inikep/lzbench)):
||Ratio|Compression|Decompression
|--|--|--|--|
|FastLZ |54.2%|159 MB/s|305 MB/s|
|zlib -1|42.3%|50 MB/s|184 MB/s|
|zlib -9|36.5%|11 MB/s|185 MB/s|
FastLZ is used by many software products, from a number of games (such as [Death Stranding](https://en.wikipedia.org/wiki/Death_Stranding)) to various open-source projects ([Godot Engine](https://godotengine.org/), [Facebook HHVM](https://hhvm.com/), [Apache Traffic Server](https://trafficserver.apache.org/), [Calligra Office](https://www.calligra.org/), [OSv](http://osv.io/), [Netty](https://netty.io/), etc). It even serves as the basis for other compression projects like [BLOSC](https://blosc.org/).
For other implementations of byte-aligned LZ77, take a look at [LZ4](https://lz4.github.io/lz4/), [Snappy](http://google.github.io/snappy/), [Density](https://github.com/centaurean/density), [LZO](http://www.oberhumer.com/opensource/lzo/), [LZF](http://oldhome.schmorp.de/marc/liblzf.html), [LZJB](https://en.wikipedia.org/wiki/LZJB), [LZRW](http://www.ross.net/compression/lzrw1.html), etc.
## Usage
FastLZ can be used directly in any C/C++ applications. For other programming languages/environments, use the corresponding binding:
* [Rust](https://crates.io/crates/fastlz), available on Crates: `cargo install fastlz`
* [Python](https://pypi.org/project/fastlz/), available on PyPi: `pip install fastlz`
* [JavaScript](https://www.npmjs.com/package/fastlz), available on npm: `npm install fastlz`
* [Ruby](https://rubygems.org/gems/fastlz), available on Rubygems: `gem install fastlz`
* Lua via [github.com/oneoo/lua-fastlz](https://github.com/oneoo/lua-fastlz)
FastLZ consists of only two files: `fastlz.h` and `fastlz.c`. Just add these files to your project in order to use FastLZ. For the detailed information on the API to perform compression and decompression, see `fastlz.h`.
For [Vcpkg](https://github.com/microsoft/vcpkg) users, FastLZ is [already available](https://github.com/microsoft/vcpkg): `vcpkg install fastlz`.
A simple file compressor called `6pack` is included as an example on how to use FastLZ. The corresponding decompressor is `6unpack`.
FastLZ supports any standard-conforming ANSI C/C90 compiler, including the popular ones such as [GCC](https://gcc.gnu.org/), [Clang](https://clang.llvm.org/), [Visual Studio](https://visualstudio.microsoft.com/vs/features/cplusplus/), and even [Tiny CC](https://bellard.org/tcc/). FastLZ works well on a number of architectures (32-bit and 64-bit, big endian and little endian), from Intel/AMD, PowerPC, System z, ARM, MIPS, and RISC-V.
The continuous integration system runs an extensive set of compression-decompression round trips on the following systems:
For more details, check the corresponding [GitHub Actions build logs](https://github.com/ariya/FastLZ/actions).
| | | | |
|----------------------|--------------------------------------------------------------------------------------------------------:|--------------------------------------------------------------------------------------------------:|--------------------------------------------------------------------------------------------:|
| **amd64** | **Linux** | **Windows** | **macOS** |
| GCC | ![amd64_linux_gcc](https://github.com/ariya/FastLZ/workflows/amd64_linux_gcc/badge.svg) | ![amd64_windows_gcc](https://github.com/ariya/FastLZ/workflows/amd64_windows_gcc/badge.svg) | ![amd64_macos_gcc](https://github.com/ariya/FastLZ/workflows/amd64_macos_gcc/badge.svg) |
| Clang | ![amd64_linux_clang](https://github.com/ariya/FastLZ/workflows/amd64_linux_clang/badge.svg) | ![amd64_windows_clang](https://github.com/ariya/FastLZ/workflows/amd64_windows_clang/badge.svg) | ![amd64_macos_clang](https://github.com/ariya/FastLZ/workflows/amd64_macos_clang/badge.svg) |
| TinyCC | ![amd64_linux_tcc](https://github.com/ariya/FastLZ/workflows/amd64_linux_tcc/badge.svg) | ![amd64_windows_tcc](https://github.com/ariya/FastLZ/workflows/amd64_windows_tcc/badge.svg) | |
| VS 2019 | | ![amd64_windows_vs2019](https://github.com/ariya/FastLZ/workflows/amd64_windows_vs2019/badge.svg) | |
| **i686** | **Linux** | **Windows** | **macOS** |
| GCC | ![i686_linux_gcc](https://github.com/ariya/FastLZ/workflows/i686_linux_gcc/badge.svg) | | |
| Clang | ![i686_linux_clang](https://github.com/ariya/FastLZ/workflows/i686_linux_clang/badge.svg) | | |
| TinyCC | | ![i686_windows_tcc](https://github.com/ariya/FastLZ/workflows/i686_windows_tcc/badge.svg) | |
| VS 2019 | | ![i686_windows_vs2019](https://github.com/ariya/FastLZ/workflows/i686_windows_vs2019/badge.svg) | |
| **i586** | **Linux** | **DOS** | |
| GCC | | ![i586_dos_gcc_cross](https://github.com/ariya/FastLZ/workflows/i586_dos_gcc_cross/badge.svg) | |
| | **Linux** | | |
| **powerpc** | | | |
| GCC | ![powerpc_linux_gcc](https://github.com/ariya/FastLZ/workflows/powerpc_linux_gcc/badge.svg) | | |
| **ppc64(le)** | | | |
| GCC | ![ppc64_linux_gcc](https://github.com/ariya/FastLZ/workflows/ppc64_linux_gcc/badge.svg) | | |
| GCC | ![ppc64le_linux_gcc](https://github.com/ariya/FastLZ/workflows/ppc64le_linux_gcc/badge.svg) | | |
| **s390x** | | | |
| GCC | ![s390x_linux_gcc](https://github.com/ariya/FastLZ/workflows/s390x_linux_gcc/badge.svg) | | |
| **armhf** | | | |
| GCC | ![armhf_linux_gcc](https://github.com/ariya/FastLZ/workflows/armhf_linux_gcc/badge.svg) | | |
| **arm64** | | | |
| GCC | ![arm64_linux_gcc](https://github.com/ariya/FastLZ/workflows/arm64_linux_gcc/badge.svg) | | |
| **mips(el)** | | | |
| GCC | ![mipsel_linux_gcc](https://github.com/ariya/FastLZ/workflows/mipsel_linux_gcc/badge.svg) | | |
| GCC | ![mips_linux_gcc](https://github.com/ariya/FastLZ/workflows/mips_linux_gcc/badge.svg) | | |
| **mips64(el)** | | | |
| GCC | ![mips64el_linux_gcc](https://github.com/ariya/FastLZ/workflows/mips64el_linux_gcc/badge.svg) | | |
| GCC | ![mips64_linux_gcc](https://github.com/ariya/FastLZ/workflows/mips64_linux_gcc/badge.svg) | | |
| **riscv** | | | |
| GCC | ![riscv_linux_gcc](https://github.com/ariya/FastLZ/workflows/riscv_linux_gcc/badge.svg) | | |
| **riscv64** | | | |
| GCC | ![riscv64_linux_gcc](https://github.com/ariya/FastLZ/workflows/riscv64_linux_gcc/badge.svg) | | |
## Block Format
Let us assume that FastLZ compresses an array of bytes, called the _uncompressed block_, into another array of bytes, called the _compressed block_. To understand what will be stored in the compressed block, it is illustrative to demonstrate how FastLZ will _decompress_ the block to retrieve the original uncompressed block.
The first 3-bit of the block, i.e. the 3 most-significant bits of the first byte, is the **block tag**. Currently the block tag determines the compression level used to produce the compressed block.
|Block tag|Compression level|
|---------|-----------------|
| 0 | Level 1 |
| 1 | Level 2 |
The content of the block will vary depending on the compression level.
### Block Format for Level 1
FastLZ Level 1 implements LZ77 compression algorithm with 8 KB sliding window and up to 264 bytes of match length.
The compressed block consists of one or more **instructions**.
Each instruction starts with a 1-byte opcode, 2-byte opcode, or 3-byte opcode.
| Instruction type | Opcode[0] | Opcode[1] | Opcode[2]
|-----------|------------------|--------------------|--|
| Literal run | `000`, L&#x2084;-L&#x2080; | -|- |
| Short match | M&#x2082;-M&#x2080;, R&#x2081;&#x2082;-R&#x2088; | R&#x2087;-R&#x2080; | - |
| Long match | `111`, R&#x2081;&#x2082;-R&#x2088; | M&#x2087;-M&#x2080; | R&#x2087;-R&#x2080; |
Note that the _very first_ instruction in a compressed block is always a literal run.
#### Literal run instruction
For the literal run instruction, there is one or more bytes following the code. This is called the literal run.
The 5 least-significant bits of `opcode[0]`, _L_, determines the **number of literals** following the opcode. The value of 0 indicates a 1-byte literal run, 1 indicates a 2-byte literal run, and so on. The minimum literal run is 1 and the maximum literal run is 32.
The decompressor copies (_L + 1_) bytes of literal run, starting from the first one right after opcode.
_Example_: If the compressed block is a 4-byte array of `[0x02, 0x41, 0x42, 0x43]`, then the opcode is `0x02` and that means a literal run of 3 bytes. The decompressor will then copy the subsequent 3 bytes, `[0x41, 0x42, 0x43]`, to the output buffer. The output buffer now represents the (original) uncompressed block, `[0x41, 0x42, 0x43]`.
#### Short match instruction
The 3 most-significant bits of `opcode[0]`, _M_, determines the **match length**. The value of 1 indicates a 3-byte match, 2 indicates a 4-byte match and so on. The minimum match length is 3 and the maximum match length is 8.
The 5 least-significant bits of `opcode[0]` combined with the 8 bits of the `opcode[1]`, _R_, determines the **reference offset**. Since the offset is encoded in 13 bits, the minimum is 0 and the maximum is 8191.
The following C code retrieves the match length and reference offset:
```c
M = opcode[0] >> 5;
R = 256 * (opcode[0] << 5) + opcode[1];
```
The decompressor copies _(M+2)_ bytes, starting from the location offsetted by _R_ in the output buffer. Note that _R_ is a *back reference*, i.e. the value of 0 corresponds the last byte in the output buffer, 1 is the second to last byte, and so forth.
_Example 1_: If the compressed block is a 7-byte array of `[0x03, 0x41, 0x42, 0x43, 0x44, 0x20, 0x02]`, then there are two instructions in the there. The first instruction is the literal run of 4 bytes (due to _L = 3_). Thus, the decompressor copies 4 bytes to the output buffer, resulting in `[0x41, 0x42, 0x43, 0x44]`. The second instruction is the short match of 3 bytes (from _M = 1_, i.e `0x20 >> 5`) and the offset of 2. Therefore, the compressor goes back 2 bytes from the last position, copies 3 bytes (`[0x42, 0x43, 0x44]`), and appends them to the output buffer. The output buffer now represents the complete uncompressed data, `[0x41, 0x42, 0x43, 0x44, 0x42, 0x43, 0x44]`.
_Example 2_: If the compressed block is a 4-byte array of `[0x00, 0x61, 0x40, 0x00]`, then there are two instructions in there. The first instruction is the literal run of just 1 byte (_L = 0_). Thus, the decompressor copies the byte (`0x61`) to the output buffer. The output buffer now becomes `[0x61]`. The second instruction is the short match of 4 bytes (from _M = 2_, i.e. `0x40 >> 5`) and the offset of 0. Therefore, the decompressor copies 4 bytes starting using the back reference of 0 (i.e. the position of `0x61`). The output buffer now represents the complete uncompressed data, `[0x61, 0x61, 0x61, 0x61, 0x61]`.
#### Long match instruction
The value of `opcode[1]`, _M_, determines the **match length**. The value of 0 indicates a 9-byte match, 1 indicates a 10-byte match and so on. The minimum match length is 9 and the maximum match length is 264.
The 5 least-significant bits of `opcode[0]` combined with the 8 bits of `opcode[2]`, _R_, determines the **reference offset**. Since the offset is encoded in 13 bits, the minimum is 0 and the maximum is 8191.
The following C code retrieves the match length and reference offset:
```c
M = opcode[1];
R = 256 * (opcode[0] << 5) + opcode[2];
```
The decompressor copies _(M+9)_ bytes, starting from the location offsetted by _R_ in the output buffer. Note that _R_ is a *back reference*, i.e. the value of 0 corresponds to the last byte in the output buffer, 1 is for the second to last byte, and so forth.
_Example_: If the compressed block is a 4-byte array of `[0x01, 0x44, 0x45, 0xE0, 0x01, 0x01]`, then there are two instructions in there. The first instruction is the literal run with the length of 2 (due to _L = 1_). Thus, the decompressor copies the 2-byte literal run (`[0x44, 0x45]`) to the output buffer. The second instruction is the long match with the match length of 10 (from _M = 1_) and the offset of 1. Therefore, the decompressor copies 10 bytes starting using the back reference of 1 (i.e. the position of `0x44`). The output buffer now represents the complete uncompressed data, `[0x44, 0x45, 0x44, 0x45, 0x44, 0x45, 0x44, 0x45, 0x44, 0x45, 0x44, 0x45]`.
#### Decompressor Reference Implementation
The following 40-line C function implements a fully-functional decompressor for the above block format. Note that it is intended to be educational, e.g. no bound check is implemented, and therefore it is absolutely **unsafe** for production.
```c
void fastlz_level1_decompress(const uint8_t* input, int length, uint8_t* output) {
int src = 0;
int dest = 0;
while (src < length) {
int type = input[src] >> 5;
if (type == 0) {
/* literal run */
int run = 1 + input[src];
src = src + 1;
while (run > 0) {
output[dest] = input[src];
src = src + 1;
dest = dest + 1;
run = run - 1;
}
} else if (type < 7) {
/* short match */
int ofs = 256 * (input[src] & 31) + input[src + 1];
int len = 2 + (input[src] >> 5);
src = src + 2;
int ref = dest - ofs - 1;
while (len > 0) {
output[dest] = output[ref];
ref = ref + 1;
dest = dest + 1;
len = len - 1;
}
} else {
/* long match */
int ofs = 256 * (input[src] & 31) + input[src + 2];
int len = 9 + input[src + 1];
src = src + 3;
int ref = dest - ofs - 1;
while (len > 0) {
output[dest] = output[ref];
ref = ref + 1;
dest = dest + 1;
len = len - 1;
}
}
}
}
```
### Block Format for Level 2
(To be written)

1
FastLZ/_config.yml Normal file
View File

@ -0,0 +1 @@
theme: jekyll-theme-tactile

2
FastLZ/examples/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
6pack
6unpack

586
FastLZ/examples/6pack.c Normal file
View File

@ -0,0 +1,586 @@
/*
6PACK - file compressor using FastLZ (lightning-fast compression library)
Copyright (C) 2007-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIXPACK_VERSION_MAJOR 0
#define SIXPACK_VERSION_MINOR 1
#define SIXPACK_VERSION_REVISION 0
#define SIXPACK_VERSION_STRING "snapshot 20070615"
#include "fastlz.h"
#undef PATH_SEPARATOR
#if defined(MSDOS) || defined(__MSDOS__) || defined(MSDOS)
#define PATH_SEPARATOR '\\'
#endif
#if defined(WIN32) || defined(__NT__) || defined(_WIN32) || defined(__WIN32__)
#define PATH_SEPARATOR '\\'
#endif
#ifndef PATH_SEPARATOR
#define PATH_SEPARATOR '/'
#endif
#undef SIXPACK_BENCHMARK_WIN32
#if defined(WIN32) || defined(__NT__) || defined(_WIN32) || defined(__WIN32__)
#if defined(_MSC_VER) || defined(__GNUC__)
#define SIXPACK_BENCHMARK_WIN32
#include <windows.h>
#endif
#endif
/* magic identifier for 6pack file */
static unsigned char sixpack_magic[8] = {137, '6', 'P', 'K', 13, 10, 26, 10};
#define BLOCK_SIZE (2 * 64 * 1024)
/* prototypes */
static unsigned long update_adler32(unsigned long checksum, const void* buf, int len);
void usage(void);
int detect_magic(FILE* f);
void write_magic(FILE* f);
void write_chunk_header(FILE* f, int id, int options, unsigned long size, unsigned long checksum, unsigned long extra);
unsigned long block_compress(const unsigned char* input, unsigned long length, unsigned char* output);
int pack_file_compressed(const char* input_file, int method, int level, FILE* f);
int pack_file(int compress_level, const char* input_file, const char* output_file);
/* for Adler-32 checksum algorithm, see RFC 1950 Section 8.2 */
#define ADLER32_BASE 65521
static unsigned long update_adler32(unsigned long checksum, const void* buf, int len) {
const unsigned char* ptr = (const unsigned char*)buf;
unsigned long s1 = checksum & 0xffff;
unsigned long s2 = (checksum >> 16) & 0xffff;
while (len > 0) {
unsigned k = len < 5552 ? len : 5552;
len -= k;
while (k >= 8) {
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
k -= 8;
}
while (k-- > 0) {
s1 += *ptr++;
s2 += s1;
}
s1 = s1 % ADLER32_BASE;
s2 = s2 % ADLER32_BASE;
}
return (s2 << 16) + s1;
}
void usage(void) {
printf("6pack: high-speed file compression tool\n");
printf("Copyright (C) Ariya Hidayat\n");
printf("\n");
printf("Usage: 6pack [options] input-file output-file\n");
printf("\n");
printf("Options:\n");
printf(" -1 compress faster\n");
printf(" -2 compress better\n");
printf(" -v show program version\n");
#ifdef SIXPACK_BENCHMARK_WIN32
printf(" -mem check in-memory compression speed\n");
#endif
printf("\n");
}
/* return non-zero if magic sequence is detected */
/* warning: reset the read pointer to the beginning of the file */
int detect_magic(FILE* f) {
unsigned char buffer[8];
size_t bytes_read;
int c;
fseek(f, SEEK_SET, 0);
bytes_read = fread(buffer, 1, 8, f);
fseek(f, SEEK_SET, 0);
if (bytes_read < 8) return 0;
for (c = 0; c < 8; c++)
if (buffer[c] != sixpack_magic[c]) return 0;
return -1;
}
void write_magic(FILE* f) { fwrite(sixpack_magic, 8, 1, f); }
void write_chunk_header(FILE* f, int id, int options, unsigned long size, unsigned long checksum, unsigned long extra) {
unsigned char buffer[16];
buffer[0] = id & 255;
buffer[1] = id >> 8;
buffer[2] = options & 255;
buffer[3] = options >> 8;
buffer[4] = size & 255;
buffer[5] = (size >> 8) & 255;
buffer[6] = (size >> 16) & 255;
buffer[7] = (size >> 24) & 255;
buffer[8] = checksum & 255;
buffer[9] = (checksum >> 8) & 255;
buffer[10] = (checksum >> 16) & 255;
buffer[11] = (checksum >> 24) & 255;
buffer[12] = extra & 255;
buffer[13] = (extra >> 8) & 255;
buffer[14] = (extra >> 16) & 255;
buffer[15] = (extra >> 24) & 255;
fwrite(buffer, 16, 1, f);
}
int pack_file_compressed(const char* input_file, int method, int level, FILE* f) {
FILE* in;
unsigned long fsize;
unsigned long checksum;
const char* shown_name;
unsigned char buffer[BLOCK_SIZE];
unsigned char result[BLOCK_SIZE * 2]; /* FIXME twice is too large */
unsigned char progress[20];
int c;
unsigned long percent;
unsigned long total_read;
unsigned long total_compressed;
int chunk_size;
/* sanity check */
in = fopen(input_file, "rb");
if (!in) {
printf("Error: could not open %s\n", input_file);
return -1;
}
/* find size of the file */
fseek(in, 0, SEEK_END);
fsize = ftell(in);
fseek(in, 0, SEEK_SET);
/* already a 6pack archive? */
if (detect_magic(in)) {
printf("Error: file %s is already a 6pack archive!\n", input_file);
fclose(in);
return -1;
}
/* truncate directory prefix, e.g. "foo/bar/FILE.txt" becomes "FILE.txt" */
shown_name = input_file + strlen(input_file) - 1;
while (shown_name > input_file)
if (*(shown_name - 1) == PATH_SEPARATOR)
break;
else
shown_name--;
/* chunk for File Entry */
buffer[0] = fsize & 255;
buffer[1] = (fsize >> 8) & 255;
buffer[2] = (fsize >> 16) & 255;
buffer[3] = (fsize >> 24) & 255;
#if 0
buffer[4] = (fsize >> 32) & 255;
buffer[5] = (fsize >> 40) & 255;
buffer[6] = (fsize >> 48) & 255;
buffer[7] = (fsize >> 56) & 255;
#else
/* because fsize is only 32-bit */
buffer[4] = 0;
buffer[5] = 0;
buffer[6] = 0;
buffer[7] = 0;
#endif
buffer[8] = (strlen(shown_name) + 1) & 255;
buffer[9] = (strlen(shown_name) + 1) >> 8;
checksum = 1L;
checksum = update_adler32(checksum, buffer, 10);
checksum = update_adler32(checksum, shown_name, strlen(shown_name) + 1);
write_chunk_header(f, 1, 0, 10 + strlen(shown_name) + 1, checksum, 0);
fwrite(buffer, 10, 1, f);
fwrite(shown_name, strlen(shown_name) + 1, 1, f);
total_compressed = 16 + 10 + strlen(shown_name) + 1;
/* for progress status */
memset(progress, ' ', 20);
if (strlen(shown_name) < 16)
for (c = 0; c < (int)strlen(shown_name); c++) progress[c] = shown_name[c];
else {
for (c = 0; c < 13; c++) progress[c] = shown_name[c];
progress[13] = '.';
progress[14] = '.';
progress[15] = ' ';
}
progress[16] = '[';
progress[17] = 0;
printf("%s", progress);
for (c = 0; c < 50; c++) printf(".");
printf("]\r");
printf("%s", progress);
/* read file and place in archive */
total_read = 0;
percent = 0;
for (;;) {
int compress_method = method;
int last_percent = (int)percent;
size_t bytes_read = fread(buffer, 1, BLOCK_SIZE, in);
if (bytes_read == 0) break;
total_read += bytes_read;
/* for progress */
if (fsize < (1 << 24))
percent = total_read * 100 / fsize;
else
percent = total_read / 256 * 100 / (fsize >> 8);
percent >>= 1;
while (last_percent < (int)percent) {
printf("#");
last_percent++;
}
/* too small, don't bother to compress */
if (bytes_read < 32) compress_method = 0;
/* write to output */
switch (compress_method) {
/* FastLZ */
case 1:
chunk_size = fastlz_compress_level(level, buffer, bytes_read, result);
checksum = update_adler32(1L, result, chunk_size);
write_chunk_header(f, 17, 1, chunk_size, checksum, bytes_read);
fwrite(result, 1, chunk_size, f);
total_compressed += 16;
total_compressed += chunk_size;
break;
/* uncompressed, also fallback method */
case 0:
default:
checksum = 1L;
checksum = update_adler32(checksum, buffer, bytes_read);
write_chunk_header(f, 17, 0, bytes_read, checksum, bytes_read);
fwrite(buffer, 1, bytes_read, f);
total_compressed += 16;
total_compressed += bytes_read;
break;
}
}
fclose(in);
if (total_read != fsize) {
printf("\n");
printf("Error: reading %s failed!\n", input_file);
return -1;
} else {
printf("] ");
if (total_compressed < fsize) {
if (fsize < (1 << 20))
percent = total_compressed * 1000 / fsize;
else
percent = total_compressed / 256 * 1000 / (fsize >> 8);
percent = 1000 - percent;
printf("%2d.%d%% saved", (int)percent / 10, (int)percent % 10);
}
printf("\n");
}
return 0;
}
int pack_file(int compress_level, const char* input_file, const char* output_file) {
FILE* f;
int result;
f = fopen(output_file, "rb");
if (f) {
fclose(f);
printf("Error: file %s already exists. Aborted.\n\n", output_file);
return -1;
}
f = fopen(output_file, "wb");
if (!f) {
printf("Error: could not create %s. Aborted.\n\n", output_file);
return -1;
}
write_magic(f);
result = pack_file_compressed(input_file, 1, compress_level, f);
fclose(f);
return result;
}
#ifdef SIXPACK_BENCHMARK_WIN32
int benchmark_speed(int compress_level, const char* input_file);
int benchmark_speed(int compress_level, const char* input_file) {
FILE* in;
unsigned long fsize;
unsigned long maxout;
const char* shown_name;
unsigned char* buffer;
unsigned char* result;
size_t bytes_read;
/* sanity check */
in = fopen(input_file, "rb");
if (!in) {
printf("Error: could not open %s\n", input_file);
return -1;
}
/* find size of the file */
fseek(in, 0, SEEK_END);
fsize = ftell(in);
fseek(in, 0, SEEK_SET);
/* already a 6pack archive? */
if (detect_magic(in)) {
printf("Error: no benchmark for 6pack archive!\n");
fclose(in);
return -1;
}
/* truncate directory prefix, e.g. "foo/bar/FILE.txt" becomes "FILE.txt" */
shown_name = input_file + strlen(input_file) - 1;
while (shown_name > input_file)
if (*(shown_name - 1) == PATH_SEPARATOR)
break;
else
shown_name--;
maxout = 1.05 * fsize;
maxout = (maxout < 66) ? 66 : maxout;
buffer = (unsigned char*)malloc(fsize);
result = (unsigned char*)malloc(maxout);
if (!buffer || !result) {
printf("Error: not enough memory!\n");
free(buffer);
free(result);
fclose(in);
return -1;
}
printf("Reading source file....\n");
bytes_read = fread(buffer, 1, fsize, in);
if (bytes_read != fsize) {
printf("Error reading file %s!\n", shown_name);
printf("Read %d bytes, expecting %d bytes\n", bytes_read, fsize);
free(buffer);
free(result);
fclose(in);
return -1;
}
/* shamelessly copied from QuickLZ 1.20 test program */
{
unsigned int j, y;
size_t i, u = 0;
double mbs, fastest;
unsigned long compressed_size;
printf("Setting HIGH_PRIORITY_CLASS...\n");
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
printf("Benchmarking FastLZ Level %d, please wait...\n", compress_level);
i = bytes_read;
fastest = 0.0;
for (j = 0; j < 3; j++) {
y = 0;
mbs = GetTickCount();
while (GetTickCount() == mbs)
;
mbs = GetTickCount();
while (GetTickCount() - mbs < 3000) /* 1% accuracy with 18.2 timer */
{
u = fastlz_compress_level(compress_level, buffer, bytes_read, result);
y++;
}
mbs = ((double)i * (double)y) / ((double)(GetTickCount() - mbs) / 1000.) / 1000000.;
/*printf(" %.1f Mbyte/s ", mbs);*/
if (fastest < mbs) fastest = mbs;
}
printf("\nCompressed %d bytes into %d bytes (%.1f%%) at %.1f Mbyte/s.\n", (unsigned int)i, (unsigned int)u,
(double)u / (double)i * 100., fastest);
#if 1
fastest = 0.0;
compressed_size = u;
for (j = 0; j < 3; j++) {
y = 0;
mbs = GetTickCount();
while (GetTickCount() == mbs)
;
mbs = GetTickCount();
while (GetTickCount() - mbs < 3000) /* 1% accuracy with 18.2 timer */
{
u = fastlz_decompress(result, compressed_size, buffer, bytes_read);
y++;
}
mbs = ((double)i * (double)y) / ((double)(GetTickCount() - mbs) / 1000.) / 1000000.;
/*printf(" %.1f Mbyte/s ", mbs);*/
if (fastest < mbs) fastest = mbs;
}
printf("\nDecompressed at %.1f Mbyte/s.\n\n(1 MB = 1000000 byte)\n", fastest);
#endif
}
fclose(in);
return 0;
}
#endif /* SIXPACK_BENCHMARK_WIN32 */
int main(int argc, char** argv) {
int i;
int compress_level;
int benchmark;
char* input_file;
char* output_file;
/* show help with no argument at all*/
if (argc == 1) {
usage();
return 0;
}
/* default compression level, not the fastest */
compress_level = 2;
/* do benchmark only when explicitly specified */
benchmark = 0;
/* no file is specified */
input_file = 0;
output_file = 0;
for (i = 1; i <= argc; i++) {
char* argument = argv[i];
if (!argument) continue;
/* display help on usage */
if (!strcmp(argument, "-h") || !strcmp(argument, "--help")) {
usage();
return 0;
}
/* check for version information */
if (!strcmp(argument, "-v") || !strcmp(argument, "--version")) {
printf("6pack: high-speed file compression tool\n");
printf("Version %s (using FastLZ %s)\n", SIXPACK_VERSION_STRING, FASTLZ_VERSION_STRING);
printf("Copyright (C) Ariya Hidayat\n");
printf("\n");
return 0;
}
/* test compression speed? */
if (!strcmp(argument, "-mem")) {
benchmark = 1;
continue;
}
/* compression level */
if (!strcmp(argument, "-1") || !strcmp(argument, "--fastest")) {
compress_level = 1;
continue;
}
if (!strcmp(argument, "-2")) {
compress_level = 2;
continue;
}
/* unknown option */
if (argument[0] == '-') {
printf("Error: unknown option %s\n\n", argument);
printf("To get help on usage:\n");
printf(" 6pack --help\n\n");
return -1;
}
/* first specified file is input */
if (!input_file) {
input_file = argument;
continue;
}
/* next specified file is output */
if (!output_file) {
output_file = argument;
continue;
}
/* files are already specified */
printf("Error: unknown option %s\n\n", argument);
printf("To get help on usage:\n");
printf(" 6pack --help\n\n");
return -1;
}
if (!input_file) {
printf("Error: input file is not specified.\n\n");
printf("To get help on usage:\n");
printf(" 6pack --help\n\n");
return -1;
}
if (!output_file && !benchmark) {
printf("Error: output file is not specified.\n\n");
printf("To get help on usage:\n");
printf(" 6pack --help\n\n");
return -1;
}
#ifdef SIXPACK_BENCHMARK_WIN32
if (benchmark)
return benchmark_speed(compress_level, input_file);
else
#endif
return pack_file(compress_level, input_file, output_file);
/* unreachable */
return 0;
}

425
FastLZ/examples/6unpack.c Normal file
View File

@ -0,0 +1,425 @@
/*
6PACK - file compressor using FastLZ (lightning-fast compression library)
Copyright (C) 2007-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIXPACK_VERSION_MAJOR 0
#define SIXPACK_VERSION_MINOR 1
#define SIXPACK_VERSION_REVISION 0
#define SIXPACK_VERSION_STRING "0.1.0"
#include "fastlz.h"
/* magic identifier for 6pack file */
static unsigned char sixpack_magic[8] = {137, '6', 'P', 'K', 13, 10, 26, 10};
#define BLOCK_SIZE 65536
/* prototypes */
static unsigned long update_adler32(unsigned long checksum, const void* buf, int len);
void usage(void);
int detect_magic(FILE* f);
static unsigned long readU16(const unsigned char* ptr);
static unsigned long readU32(const unsigned char* ptr);
void read_chunk_header(FILE* f, int* id, int* options, unsigned long* size, unsigned long* checksum,
unsigned long* extra);
int unpack_file(const char* archive_file);
/* for Adler-32 checksum algorithm, see RFC 1950 Section 8.2 */
#define ADLER32_BASE 65521
static unsigned long update_adler32(unsigned long checksum, const void* buf, int len) {
const unsigned char* ptr = (const unsigned char*)buf;
unsigned long s1 = checksum & 0xffff;
unsigned long s2 = (checksum >> 16) & 0xffff;
while (len > 0) {
unsigned k = len < 5552 ? len : 5552;
len -= k;
while (k >= 8) {
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
s1 += *ptr++;
s2 += s1;
k -= 8;
}
while (k-- > 0) {
s1 += *ptr++;
s2 += s1;
}
s1 = s1 % ADLER32_BASE;
s2 = s2 % ADLER32_BASE;
}
return (s2 << 16) + s1;
}
void usage(void) {
printf("6unpack: uncompress 6pack archive\n");
printf("Copyright (C) Ariya Hidayat\n");
printf("\n");
printf("Usage: 6unpack archive-file\n");
printf("\n");
}
/* return non-zero if magic sequence is detected */
/* warning: reset the read pointer to the beginning of the file */
int detect_magic(FILE* f) {
unsigned char buffer[8];
size_t bytes_read;
int c;
fseek(f, SEEK_SET, 0);
bytes_read = fread(buffer, 1, 8, f);
fseek(f, SEEK_SET, 0);
if (bytes_read < 8) return 0;
for (c = 0; c < 8; c++)
if (buffer[c] != sixpack_magic[c]) return 0;
return -1;
}
static unsigned long readU16(const unsigned char* ptr) { return ptr[0] + (ptr[1] << 8); }
static unsigned long readU32(const unsigned char* ptr) {
return ptr[0] + (ptr[1] << 8) + (ptr[2] << 16) + (ptr[3] << 24);
}
void read_chunk_header(FILE* f, int* id, int* options, unsigned long* size, unsigned long* checksum,
unsigned long* extra) {
unsigned char buffer[16];
fread(buffer, 1, 16, f);
*id = readU16(buffer) & 0xffff;
*options = readU16(buffer + 2) & 0xffff;
*size = readU32(buffer + 4) & 0xffffffff;
*checksum = readU32(buffer + 8) & 0xffffffff;
*extra = readU32(buffer + 12) & 0xffffffff;
}
int unpack_file(const char* input_file) {
FILE* in;
unsigned long fsize;
int c;
unsigned long percent;
unsigned char progress[20];
int chunk_id;
int chunk_options;
unsigned long chunk_size;
unsigned long chunk_checksum;
unsigned long chunk_extra;
unsigned char buffer[BLOCK_SIZE];
unsigned long checksum;
unsigned long decompressed_size;
unsigned long total_extracted;
int name_length;
char* output_file;
FILE* f;
unsigned char* compressed_buffer;
unsigned char* decompressed_buffer;
unsigned long compressed_bufsize;
unsigned long decompressed_bufsize;
/* sanity check */
in = fopen(input_file, "rb");
if (!in) {
printf("Error: could not open %s\n", input_file);
return -1;
}
/* find size of the file */
fseek(in, 0, SEEK_END);
fsize = ftell(in);
fseek(in, 0, SEEK_SET);
/* not a 6pack archive? */
if (!detect_magic(in)) {
fclose(in);
printf("Error: file %s is not a 6pack archive!\n", input_file);
return -1;
}
printf("Archive: %s", input_file);
/* position of first chunk */
fseek(in, 8, SEEK_SET);
/* initialize */
output_file = 0;
f = 0;
total_extracted = 0;
decompressed_size = 0;
percent = 0;
compressed_buffer = 0;
decompressed_buffer = 0;
compressed_bufsize = 0;
decompressed_bufsize = 0;
/* main loop */
for (;;) {
/* end of file? */
size_t pos = ftell(in);
if (pos >= fsize) break;
read_chunk_header(in, &chunk_id, &chunk_options, &chunk_size, &chunk_checksum, &chunk_extra);
if ((chunk_id == 1) && (chunk_size > 10) && (chunk_size < BLOCK_SIZE)) {
/* close current file, if any */
printf("\n");
free(output_file);
output_file = 0;
if (f) fclose(f);
/* file entry */
fread(buffer, 1, chunk_size, in);
checksum = update_adler32(1L, buffer, chunk_size);
if (checksum != chunk_checksum) {
free(output_file);
output_file = 0;
fclose(in);
printf("\nError: checksum mismatch!\n");
printf("Got %08lX Expecting %08lX\n", checksum, chunk_checksum);
return -1;
}
decompressed_size = readU32(buffer);
total_extracted = 0;
percent = 0;
/* get file to extract */
name_length = (int)readU16(buffer + 8);
if (name_length > (int)chunk_size - 10) name_length = chunk_size - 10;
output_file = (char*)malloc(name_length + 1);
memset(output_file, 0, name_length + 1);
for (c = 0; c < name_length; c++) output_file[c] = buffer[10 + c];
/* check if already exists */
f = fopen(output_file, "rb");
if (f) {
fclose(f);
printf("File %s already exists. Skipped.\n", output_file);
free(output_file);
output_file = 0;
f = 0;
} else {
/* create the file */
f = fopen(output_file, "wb");
if (!f) {
printf("Can't create file %s. Skipped.\n", output_file);
free(output_file);
output_file = 0;
f = 0;
} else {
/* for progress status */
printf("\n");
memset(progress, ' ', 20);
if (strlen(output_file) < 16)
for (c = 0; c < (int)strlen(output_file); c++) progress[c] = output_file[c];
else {
for (c = 0; c < 13; c++) progress[c] = output_file[c];
progress[13] = '.';
progress[14] = '.';
progress[15] = ' ';
}
progress[16] = '[';
progress[17] = 0;
printf("%s", progress);
for (c = 0; c < 50; c++) printf(".");
printf("]\r");
printf("%s", progress);
}
}
}
if ((chunk_id == 17) && f && output_file && decompressed_size) {
unsigned long remaining;
/* uncompressed */
switch (chunk_options) {
/* stored, simply copy to output */
case 0:
/* read one block at at time, write and update checksum */
total_extracted += chunk_size;
remaining = chunk_size;
checksum = 1L;
for (;;) {
unsigned long r = (BLOCK_SIZE < remaining) ? BLOCK_SIZE : remaining;
size_t bytes_read = fread(buffer, 1, r, in);
if (bytes_read == 0) break;
fwrite(buffer, 1, bytes_read, f);
checksum = update_adler32(checksum, buffer, bytes_read);
remaining -= bytes_read;
}
/* verify everything is written correctly */
if (checksum != chunk_checksum) {
fclose(f);
f = 0;
free(output_file);
output_file = 0;
printf("\nError: checksum mismatch. Aborted.\n");
printf("Got %08lX Expecting %08lX\n", checksum, chunk_checksum);
}
break;
/* compressed using FastLZ */
case 1:
/* enlarge input buffer if necessary */
if (chunk_size > compressed_bufsize) {
compressed_bufsize = chunk_size;
free(compressed_buffer);
compressed_buffer = (unsigned char*)malloc(compressed_bufsize);
}
/* enlarge output buffer if necessary */
if (chunk_extra > decompressed_bufsize) {
decompressed_bufsize = chunk_extra;
free(decompressed_buffer);
decompressed_buffer = (unsigned char*)malloc(decompressed_bufsize);
}
/* read and check checksum */
fread(compressed_buffer, 1, chunk_size, in);
checksum = update_adler32(1L, compressed_buffer, chunk_size);
total_extracted += chunk_extra;
/* verify that the chunk data is correct */
if (checksum != chunk_checksum) {
fclose(f);
f = 0;
free(output_file);
output_file = 0;
printf("\nError: checksum mismatch. Skipped.\n");
printf("Got %08lX Expecting %08lX\n", checksum, chunk_checksum);
} else {
/* decompress and verify */
remaining = fastlz_decompress(compressed_buffer, chunk_size, decompressed_buffer, chunk_extra);
if (remaining != chunk_extra) {
fclose(f);
f = 0;
free(output_file);
output_file = 0;
printf("\nError: decompression failed. Skipped.\n");
} else
fwrite(decompressed_buffer, 1, chunk_extra, f);
}
break;
default:
printf("\nError: unknown compression method (%d)\n", chunk_options);
fclose(f);
f = 0;
free(output_file);
output_file = 0;
break;
}
/* for progress, if everything is fine */
if (f) {
int last_percent = (int)percent;
if (decompressed_size < (1 << 24))
percent = total_extracted * 100 / decompressed_size;
else
percent = total_extracted / 256 * 100 / (decompressed_size >> 8);
percent >>= 1;
while (last_percent < (int)percent) {
printf("#");
last_percent++;
}
}
}
/* position of next chunk */
fseek(in, pos + 16 + chunk_size, SEEK_SET);
}
printf("\n\n");
/* free allocated stuff */
free(compressed_buffer);
free(decompressed_buffer);
free(output_file);
/* close working files */
if (f) fclose(f);
fclose(in);
/* so far so good */
return 0;
}
int main(int argc, char** argv) {
int i;
const char* archive_file;
/* show help with no argument at all*/
if (argc == 1) {
usage();
return 0;
}
/* check for help on usage */
for (i = 1; i <= argc; i++)
if (argv[i])
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
usage();
return 0;
}
/* check for version information */
for (i = 1; i <= argc; i++)
if (argv[i])
if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
printf("6unpack: high-speed file compression tool\n");
printf("Version %s (using FastLZ %s)\n", SIXPACK_VERSION_STRING, FASTLZ_VERSION_STRING);
printf("Copyright (C) Ariya Hidayat\n");
printf("\n");
return 0;
}
/* needs at least two arguments */
if (argc <= 1) {
usage();
return 0;
}
archive_file = argv[1];
return unpack_file(archive_file);
}

12
FastLZ/examples/Makefile Normal file
View File

@ -0,0 +1,12 @@
CFLAGS?=-Wall -std=c90
all: 6pack 6unpack
6pack: 6pack.c ../fastlz.c
$(CC) -o 6pack $(CFLAGS) -I.. 6pack.c ../fastlz.c
6unpack: 6unpack.c ../fastlz.c
$(CC) -o 6unpack $(CFLAGS) -I.. 6unpack.c ../fastlz.c
clean :
$(RM) 6pack 6unpack *.o

14
FastLZ/examples/Makefile.win Executable file
View File

@ -0,0 +1,14 @@
CC=cl.exe
CFLAGS=/Wall
RM=del
all: 6pack 6unpack
6pack: 6pack.c ../fastlz.c
$(CC) -o 6pack $(CFLAGS) -I.. 6pack.c ../fastlz.c
6unpack: 6unpack.c ../fastlz.c
$(CC) -o 6unpack $(CFLAGS) -I.. 6unpack.c ../fastlz.c
clean :
$(RM) 6pack.exe 6unpack.exe *.obj

508
FastLZ/fastlz.c Normal file
View File

@ -0,0 +1,508 @@
/*
FastLZ - Byte-aligned LZ77 compression library
Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "fastlz.h"
#include <stdint.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
/*
* Give hints to the compiler for branch prediction optimization.
*/
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 2))
#define FASTLZ_LIKELY(c) (__builtin_expect(!!(c), 1))
#define FASTLZ_UNLIKELY(c) (__builtin_expect(!!(c), 0))
#else
#define FASTLZ_LIKELY(c) (c)
#define FASTLZ_UNLIKELY(c) (c)
#endif
/*
* Specialize custom 64-bit implementation for speed improvements.
*/
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__)
#define FLZ_ARCH64
#endif
/*
* Workaround for DJGPP to find uint8_t, uint16_t, etc.
*/
#if defined(__MSDOS__) && defined(__GNUC__)
#include <stdint-gcc.h>
#endif
#if defined(FASTLZ_USE_MEMMOVE) && (FASTLZ_USE_MEMMOVE == 0)
static void fastlz_memmove(uint8_t* dest, const uint8_t* src, uint32_t count) {
do {
*dest++ = *src++;
} while (--count);
}
static void fastlz_memcpy(uint8_t* dest, const uint8_t* src, uint32_t count) {
return fastlz_memmove(dest, src, count);
}
#else
#include <string.h>
static void fastlz_memmove(uint8_t* dest, const uint8_t* src, uint32_t count) {
if ((count > 4) && (dest >= src + count)) {
memmove(dest, src, count);
} else {
switch (count) {
default:
do {
*dest++ = *src++;
} while (--count);
break;
case 3:
*dest++ = *src++;
case 2:
*dest++ = *src++;
case 1:
*dest++ = *src++;
case 0:
break;
}
}
}
static void fastlz_memcpy(uint8_t* dest, const uint8_t* src, uint32_t count) { memcpy(dest, src, count); }
#endif
#if defined(FLZ_ARCH64)
static uint32_t flz_readu32(const void* ptr) { return *(const uint32_t*)ptr; }
static uint32_t flz_cmp(const uint8_t* p, const uint8_t* q, const uint8_t* r) {
const uint8_t* start = p;
if (flz_readu32(p) == flz_readu32(q)) {
p += 4;
q += 4;
}
while (q < r)
if (*p++ != *q++) break;
return p - start;
}
#endif /* FLZ_ARCH64 */
#if !defined(FLZ_ARCH64)
static uint32_t flz_readu32(const void* ptr) {
const uint8_t* p = (const uint8_t*)ptr;
return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
}
static uint32_t flz_cmp(const uint8_t* p, const uint8_t* q, const uint8_t* r) {
const uint8_t* start = p;
while (q < r)
if (*p++ != *q++) break;
return p - start;
}
#endif /* !FLZ_ARCH64 */
#define MAX_COPY 32
#define MAX_LEN 264 /* 256 + 8 */
#define MAX_L1_DISTANCE 8192
#define MAX_L2_DISTANCE 8191
#define MAX_FARDISTANCE (65535 + MAX_L2_DISTANCE - 1)
#define HASH_LOG 13
#define HASH_SIZE (1 << HASH_LOG)
#define HASH_MASK (HASH_SIZE - 1)
static uint16_t flz_hash(uint32_t v) {
uint32_t h = (v * 2654435769LL) >> (32 - HASH_LOG);
return h & HASH_MASK;
}
/* special case of memcpy: at most MAX_COPY bytes */
static void flz_smallcopy(uint8_t* dest, const uint8_t* src, uint32_t count) {
#if defined(FLZ_ARCH64)
if (count >= 4) {
const uint32_t* p = (const uint32_t*)src;
uint32_t* q = (uint32_t*)dest;
while (count > 4) {
*q++ = *p++;
count -= 4;
dest += 4;
src += 4;
}
}
#endif
fastlz_memcpy(dest, src, count);
}
/* special case of memcpy: exactly MAX_COPY bytes */
static void flz_maxcopy(void* dest, const void* src) {
#if defined(FLZ_ARCH64)
const uint32_t* p = (const uint32_t*)src;
uint32_t* q = (uint32_t*)dest;
*q++ = *p++;
*q++ = *p++;
*q++ = *p++;
*q++ = *p++;
*q++ = *p++;
*q++ = *p++;
*q++ = *p++;
*q++ = *p++;
#else
fastlz_memcpy(dest, src, MAX_COPY);
#endif
}
static uint8_t* flz_literals(uint32_t runs, const uint8_t* src, uint8_t* dest) {
while (runs >= MAX_COPY) {
*dest++ = MAX_COPY - 1;
flz_maxcopy(dest, src);
src += MAX_COPY;
dest += MAX_COPY;
runs -= MAX_COPY;
}
if (runs > 0) {
*dest++ = runs - 1;
flz_smallcopy(dest, src, runs);
dest += runs;
}
return dest;
}
static uint8_t* flz1_match(uint32_t len, uint32_t distance, uint8_t* op) {
--distance;
if (FASTLZ_UNLIKELY(len > MAX_LEN - 2))
while (len > MAX_LEN - 2) {
*op++ = (7 << 5) + (distance >> 8);
*op++ = MAX_LEN - 2 - 7 - 2;
*op++ = (distance & 255);
len -= MAX_LEN - 2;
}
if (len < 7) {
*op++ = (len << 5) + (distance >> 8);
*op++ = (distance & 255);
} else {
*op++ = (7 << 5) + (distance >> 8);
*op++ = len - 7;
*op++ = (distance & 255);
}
return op;
}
#define FASTLZ_BOUND_CHECK(cond) \
if (FASTLZ_UNLIKELY(!(cond))) return 0;
static int fastlz1_compress(const void* input, int length, void* output) {
const uint8_t* ip = (const uint8_t*)input;
const uint8_t* ip_start = ip;
const uint8_t* ip_bound = ip + length - 4; /* because readU32 */
const uint8_t* ip_limit = ip + length - 12 - 1;
uint8_t* op = (uint8_t*)output;
uint32_t htab[HASH_SIZE];
uint32_t seq, hash;
/* initializes hash table */
for (hash = 0; hash < HASH_SIZE; ++hash) htab[hash] = 0;
/* we start with literal copy */
const uint8_t* anchor = ip;
ip += 2;
/* main loop */
while (FASTLZ_LIKELY(ip < ip_limit)) {
const uint8_t* ref;
uint32_t distance, cmp;
/* find potential match */
do {
seq = flz_readu32(ip) & 0xffffff;
hash = flz_hash(seq);
ref = ip_start + htab[hash];
htab[hash] = ip - ip_start;
distance = ip - ref;
cmp = FASTLZ_LIKELY(distance < MAX_L1_DISTANCE) ? flz_readu32(ref) & 0xffffff : 0x1000000;
if (FASTLZ_UNLIKELY(ip >= ip_limit)) break;
++ip;
} while (seq != cmp);
if (FASTLZ_UNLIKELY(ip >= ip_limit)) break;
--ip;
if (FASTLZ_LIKELY(ip > anchor)) {
op = flz_literals(ip - anchor, anchor, op);
}
uint32_t len = flz_cmp(ref + 3, ip + 3, ip_bound);
op = flz1_match(len, distance, op);
/* update the hash at match boundary */
ip += len;
seq = flz_readu32(ip);
hash = flz_hash(seq & 0xffffff);
htab[hash] = ip++ - ip_start;
seq >>= 8;
hash = flz_hash(seq);
htab[hash] = ip++ - ip_start;
anchor = ip;
}
uint32_t copy = (uint8_t*)input + length - anchor;
op = flz_literals(copy, anchor, op);
return op - (uint8_t*)output;
}
static int fastlz1_decompress(const void* input, int length, void* output, int maxout) {
const uint8_t* ip = (const uint8_t*)input;
const uint8_t* ip_limit = ip + length;
const uint8_t* ip_bound = ip_limit - 2;
uint8_t* op = (uint8_t*)output;
uint8_t* op_limit = op + maxout;
uint32_t ctrl = (*ip++) & 31;
while (1) {
if (ctrl >= 32) {
uint32_t len = (ctrl >> 5) - 1;
uint32_t ofs = (ctrl & 31) << 8;
const uint8_t* ref = op - ofs - 1;
if (len == 7 - 1) {
FASTLZ_BOUND_CHECK(ip <= ip_bound);
len += *ip++;
}
ref -= *ip++;
len += 3;
FASTLZ_BOUND_CHECK(op + len <= op_limit);
FASTLZ_BOUND_CHECK(ref >= (uint8_t*)output);
fastlz_memmove(op, ref, len);
op += len;
} else {
ctrl++;
FASTLZ_BOUND_CHECK(op + ctrl <= op_limit);
FASTLZ_BOUND_CHECK(ip + ctrl <= ip_limit);
fastlz_memcpy(op, ip, ctrl);
ip += ctrl;
op += ctrl;
}
if (FASTLZ_UNLIKELY(ip > ip_bound)) break;
ctrl = *ip++;
}
return op - (uint8_t*)output;
}
static uint8_t* flz2_match(uint32_t len, uint32_t distance, uint8_t* op) {
--distance;
if (distance < MAX_L2_DISTANCE) {
if (len < 7) {
*op++ = (len << 5) + (distance >> 8);
*op++ = (distance & 255);
} else {
*op++ = (7 << 5) + (distance >> 8);
for (len -= 7; len >= 255; len -= 255) *op++ = 255;
*op++ = len;
*op++ = (distance & 255);
}
} else {
/* far away, but not yet in the another galaxy... */
if (len < 7) {
distance -= MAX_L2_DISTANCE;
*op++ = (len << 5) + 31;
*op++ = 255;
*op++ = distance >> 8;
*op++ = distance & 255;
} else {
distance -= MAX_L2_DISTANCE;
*op++ = (7 << 5) + 31;
for (len -= 7; len >= 255; len -= 255) *op++ = 255;
*op++ = len;
*op++ = 255;
*op++ = distance >> 8;
*op++ = distance & 255;
}
}
return op;
}
static int fastlz2_compress(const void* input, int length, void* output) {
const uint8_t* ip = (const uint8_t*)input;
const uint8_t* ip_start = ip;
const uint8_t* ip_bound = ip + length - 4; /* because readU32 */
const uint8_t* ip_limit = ip + length - 12 - 1;
uint8_t* op = (uint8_t*)output;
uint32_t htab[HASH_SIZE];
uint32_t seq, hash;
/* initializes hash table */
for (hash = 0; hash < HASH_SIZE; ++hash) htab[hash] = 0;
/* we start with literal copy */
const uint8_t* anchor = ip;
ip += 2;
/* main loop */
while (FASTLZ_LIKELY(ip < ip_limit)) {
const uint8_t* ref;
uint32_t distance, cmp;
/* find potential match */
do {
seq = flz_readu32(ip) & 0xffffff;
hash = flz_hash(seq);
ref = ip_start + htab[hash];
htab[hash] = ip - ip_start;
distance = ip - ref;
cmp = FASTLZ_LIKELY(distance < MAX_FARDISTANCE) ? flz_readu32(ref) & 0xffffff : 0x1000000;
if (FASTLZ_UNLIKELY(ip >= ip_limit)) break;
++ip;
} while (seq != cmp);
if (FASTLZ_UNLIKELY(ip >= ip_limit)) break;
--ip;
/* far, needs at least 5-byte match */
if (distance >= MAX_L2_DISTANCE) {
if (ref[3] != ip[3] || ref[4] != ip[4]) {
++ip;
continue;
}
}
if (FASTLZ_LIKELY(ip > anchor)) {
op = flz_literals(ip - anchor, anchor, op);
}
uint32_t len = flz_cmp(ref + 3, ip + 3, ip_bound);
op = flz2_match(len, distance, op);
/* update the hash at match boundary */
ip += len;
seq = flz_readu32(ip);
hash = flz_hash(seq & 0xffffff);
htab[hash] = ip++ - ip_start;
seq >>= 8;
hash = flz_hash(seq);
htab[hash] = ip++ - ip_start;
anchor = ip;
}
uint32_t copy = (uint8_t*)input + length - anchor;
op = flz_literals(copy, anchor, op);
/* marker for fastlz2 */
*(uint8_t*)output |= (1 << 5);
return op - (uint8_t*)output;
}
static int fastlz2_decompress(const void* input, int length, void* output, int maxout) {
const uint8_t* ip = (const uint8_t*)input;
const uint8_t* ip_limit = ip + length;
const uint8_t* ip_bound = ip_limit - 2;
uint8_t* op = (uint8_t*)output;
uint8_t* op_limit = op + maxout;
uint32_t ctrl = (*ip++) & 31;
while (1) {
if (ctrl >= 32) {
uint32_t len = (ctrl >> 5) - 1;
uint32_t ofs = (ctrl & 31) << 8;
const uint8_t* ref = op - ofs - 1;
uint8_t code;
if (len == 7 - 1) do {
FASTLZ_BOUND_CHECK(ip <= ip_bound);
code = *ip++;
len += code;
} while (code == 255);
code = *ip++;
ref -= code;
len += 3;
/* match from 16-bit distance */
if (FASTLZ_UNLIKELY(code == 255))
if (FASTLZ_LIKELY(ofs == (31 << 8))) {
FASTLZ_BOUND_CHECK(ip < ip_bound);
ofs = (*ip++) << 8;
ofs += *ip++;
ref = op - ofs - MAX_L2_DISTANCE - 1;
}
FASTLZ_BOUND_CHECK(op + len <= op_limit);
FASTLZ_BOUND_CHECK(ref >= (uint8_t*)output);
fastlz_memmove(op, ref, len);
op += len;
} else {
ctrl++;
FASTLZ_BOUND_CHECK(op + ctrl <= op_limit);
FASTLZ_BOUND_CHECK(ip + ctrl <= ip_limit);
fastlz_memcpy(op, ip, ctrl);
ip += ctrl;
op += ctrl;
}
if (FASTLZ_UNLIKELY(ip >= ip_limit)) break;
ctrl = *ip++;
}
return op - (uint8_t*)output;
}
int fastlz_compress(const void* input, int length, void* output) {
/* for short block, choose fastlz1 */
if (length < 65536) return fastlz1_compress(input, length, output);
/* else... */
return fastlz2_compress(input, length, output);
}
int fastlz_decompress(const void* input, int length, void* output, int maxout) {
/* magic identifier for compression level */
int level = ((*(const uint8_t*)input) >> 5) + 1;
if (level == 1) return fastlz1_decompress(input, length, output, maxout);
if (level == 2) return fastlz2_decompress(input, length, output, maxout);
/* unknown level, trigger error */
return 0;
}
int fastlz_compress_level(int level, const void* input, int length, void* output) {
if (level == 1) return fastlz1_compress(input, length, output);
if (level == 2) return fastlz2_compress(input, length, output);
return 0;
}
#pragma GCC diagnostic pop

97
FastLZ/fastlz.h Normal file
View File

@ -0,0 +1,97 @@
/*
FastLZ - Byte-aligned LZ77 compression library
Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef FASTLZ_H
#define FASTLZ_H
#define FASTLZ_VERSION 0x000500
#define FASTLZ_VERSION_MAJOR 0
#define FASTLZ_VERSION_MINOR 5
#define FASTLZ_VERSION_REVISION 0
#define FASTLZ_VERSION_STRING "0.5.0"
#if defined(__cplusplus)
extern "C" {
#endif
/**
Compress a block of data in the input buffer and returns the size of
compressed block. The size of input buffer is specified by length. The
minimum input buffer size is 16.
The output buffer must be at least 5% larger than the input buffer
and can not be smaller than 66 bytes.
If the input is not compressible, the return value might be larger than
length (input buffer size).
The input buffer and the output buffer can not overlap.
Compression level can be specified in parameter level. At the moment,
only level 1 and level 2 are supported.
Level 1 is the fastest compression and generally useful for short data.
Level 2 is slightly slower but it gives better compression ratio.
Note that the compressed data, regardless of the level, can always be
decompressed using the function fastlz_decompress below.
*/
int fastlz_compress_level(int level, const void* input, int length, void* output);
/**
Decompress a block of compressed data and returns the size of the
decompressed block. If error occurs, e.g. the compressed data is
corrupted or the output buffer is not large enough, then 0 (zero)
will be returned instead.
The input buffer and the output buffer can not overlap.
Decompression is memory safe and guaranteed not to write the output buffer
more than what is specified in maxout.
Note that the decompression will always work, regardless of the
compression level specified in fastlz_compress_level above (when
producing the compressed block).
*/
int fastlz_decompress(const void* input, int length, void* output, int maxout);
/**
DEPRECATED.
This is similar to fastlz_compress_level above, but with the level
automatically chosen.
This function is deprecated and it will be completely removed in some future
version.
*/
int fastlz_compress(const void* input, int length, void* output);
#if defined(__cplusplus)
}
#endif
#endif /* FASTLZ_H */

13
FastLZ/tests/Makefile Normal file
View File

@ -0,0 +1,13 @@
CFLAGS?=-Wall -std=c90
TEST_ROUNDTRIP?=./test_roundtrip
all: roundtrip
roundtrip: test_roundtrip
$(TEST_ROUNDTRIP)
test_roundtrip: test_roundtrip.c ../fastlz.c refimpl.c
$(CC) -o $(TEST_ROUNDTRIP) $(CFLAGS) -I.. test_roundtrip.c ../fastlz.c refimpl.c
clean :
$(RM) $(TEST_ROUNDTRIP) *.o

14
FastLZ/tests/Makefile.win Executable file
View File

@ -0,0 +1,14 @@
CC=cl.exe
CFLAGS=/Wall /Za
RM=del
TEST_ROUNDTRIP=test_roundtrip.exe
all: roundtrip
roundtrip: test_roundtrip.c ../fastlz.c refimpl.c
$(CC) -o $(TEST_ROUNDTRIP) $(CFLAGS) -I.. test_roundtrip.c ../fastlz.c refimpl.c
$(TEST_ROUNDTRIP)
clean :
$(RM) $(TEST_ROUNDTRIP) *.obj

103
FastLZ/tests/refimpl.c Normal file
View File

@ -0,0 +1,103 @@
#include <stdint.h>
/*
* Workaround for DJGPP to find uint8_t, uint16_t, etc.
*/
#if defined(__MSDOS__) && defined(__GNUC__)
#include <stdint-gcc.h>
#endif
void REF_Level1_decompress(const uint8_t* input, int length, uint8_t* output) {
int src = 0;
int dest = 0;
while (src < length) {
int type = input[src] >> 5;
if (type == 0) {
/* literal run */
int run = 1 + input[src];
src = src + 1;
while (run > 0) {
output[dest] = input[src];
src = src + 1;
dest = dest + 1;
run = run - 1;
}
} else if (type < 7) {
/* short match */
int ofs = 256 * (input[src] & 31) + input[src + 1];
int len = 2 + (input[src] >> 5);
src = src + 2;
int ref = dest - ofs - 1;
while (len > 0) {
output[dest] = output[ref];
ref = ref + 1;
dest = dest + 1;
len = len - 1;
}
} else {
/* long match */
int ofs = 256 * (input[src] & 31) + input[src + 2];
int len = 9 + input[src + 1];
src = src + 3;
int ref = dest - ofs - 1;
while (len > 0) {
output[dest] = output[ref];
ref = ref + 1;
dest = dest + 1;
len = len - 1;
}
}
}
}
void REF_Level2_decompress(const uint8_t* input, int length, uint8_t* output) {
int src = 0;
int dest = 0;
while (src < length) {
int type = input[src] >> 5;
if (type == 0) {
/* literal run */
int run = 1 + input[src];
src = src + 1;
while (run > 0) {
output[dest] = input[src];
src = src + 1;
dest = dest + 1;
run = run - 1;
}
} else {
int next = 2;
int len = 2 + (input[src] >> 5);
if (len == 9) {
/* long match */
next = next + 1;
len = len + input[src + 1];
if (len == 9 + 255) {
/* Gamma code for match length */
int nn = input[src + 1];
while (nn == 255) {
nn = input[src + next - 1];
next = next + 1;
len += nn;
}
}
}
int ofs = 256 * (input[src] & 31) + input[src + next - 1];
if (ofs == 8191) {
/* match from 16-bit distance */
ofs += 256 * input[src + next] + input[src + next + 1];
next = next + 2;
}
src = src + next;
int ref = dest - ofs - 1;
while (len > 0) {
output[dest] = output[ref];
ref = ref + 1;
dest = dest + 1;
len = len - 1;
}
}
}
}

View File

@ -0,0 +1,451 @@
/*
FastLZ - Byte-aligned LZ77 compression library
Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fastlz.h"
/*
* Workaround for DJGPP to find uint8_t, uint16_t, etc.
*/
#if defined(__MSDOS__) && defined(__GNUC__)
#include <stdint-gcc.h>
#endif
#define LOG
#undef LOG
int compare(const char* name, const uint8_t* a, const uint8_t* b, int size) {
int bad = 0;
int i;
for (i = 0; i < size; ++i) {
if (a[i] != b[i]) {
bad = 1;
printf("Error on %s!\n", name);
printf("Different at index %d: expecting %02x,actual %02x\n", i, a[i], b[i]);
break;
}
}
return bad;
}
#if !defined(__MSDOS__)
#define MAX_FILE_SIZE (100 * 1024 * 1024)
#else
#define MAX_FILE_SIZE (32 * 1024 * 1024)
#endif
/* prototype, implemented in refimpl.c */
void REF_Level1_decompress(const uint8_t* input, int length, uint8_t* output);
void REF_Level2_decompress(const uint8_t* input, int length, uint8_t* output);
/*
Same as test_roundtrip_level1 EXCEPT that the decompression is carried out
using the highly-simplified, unoptimized vanilla reference decompressor.
*/
void test_ref_decompressor_level1(const char* name, const char* file_name) {
#ifdef LOG
printf("Processing %s...\n", name);
#endif
FILE* f = fopen(file_name, "rb");
if (!f) {
printf("Error: can not open %s!\n", file_name);
exit(1);
}
fseek(f, 0L, SEEK_END);
long file_size = ftell(f);
rewind(f);
#ifdef LOG
printf("Size is %ld bytes.\n", file_size);
#endif
if (file_size > MAX_FILE_SIZE) {
fclose(f);
printf("%25s %10ld [skipped, file too big]\n", name, file_size);
return;
}
uint8_t* file_buffer = malloc(file_size);
long read = fread(file_buffer, 1, file_size, f);
fclose(f);
if (read != file_size) {
free(file_buffer);
printf("Error: only read %ld bytes!\n", read);
exit(1);
}
#ifdef LOG
printf("Compressing. Please wait...\n");
#endif
uint8_t* compressed_buffer = malloc(1.05 * file_size);
int compressed_size = fastlz_compress_level(1, file_buffer, file_size, compressed_buffer);
double ratio = (100.0 * compressed_size) / file_size;
#ifdef LOG
printf("Compressing was completed: %ld -> %ld (%.2f%%)\n", file_size, compressed_size, ratio);
#endif
#ifdef LOG
printf("Decompressing. Please wait...\n");
#endif
uint8_t* uncompressed_buffer = malloc(file_size);
if (uncompressed_buffer == NULL) {
printf("%25s %10ld -> %10d (%.2f%%) skipped, can't decompress\n", name, file_size, compressed_size, ratio);
return;
}
memset(uncompressed_buffer, '-', file_size);
REF_Level1_decompress(compressed_buffer, compressed_size, uncompressed_buffer);
#ifdef LOG
printf("Comparing. Please wait...\n");
#endif
int result = compare(file_name, file_buffer, uncompressed_buffer, file_size);
if (result == 1) {
free(uncompressed_buffer);
exit(1);
}
free(file_buffer);
free(compressed_buffer);
free(uncompressed_buffer);
#ifdef LOG
printf("OK.\n");
#else
printf("%25s %10ld -> %10d (%.2f%%)\n", name, file_size, compressed_size, ratio);
#endif
}
/*
Same as test_roundtrip_level2 EXCEPT that the decompression is carried out
using the highly-simplified, unoptimized vanilla reference decompressor.
*/
void test_ref_decompressor_level2(const char* name, const char* file_name) {
#ifdef LOG
printf("Processing %s...\n", name);
#endif
FILE* f = fopen(file_name, "rb");
if (!f) {
printf("Error: can not open %s!\n", file_name);
exit(1);
}
fseek(f, 0L, SEEK_END);
long file_size = ftell(f);
rewind(f);
#ifdef LOG
printf("Size is %ld bytes.\n", file_size);
#endif
if (file_size > MAX_FILE_SIZE) {
fclose(f);
printf("%25s %10ld [skipped, file too big]\n", name, file_size);
return;
}
uint8_t* file_buffer = malloc(file_size);
long read = fread(file_buffer, 1, file_size, f);
fclose(f);
if (read != file_size) {
free(file_buffer);
printf("Error: only read %ld bytes!\n", read);
exit(1);
}
#ifdef LOG
printf("Compressing. Please wait...\n");
#endif
uint8_t* compressed_buffer = malloc(1.05 * file_size);
int compressed_size = fastlz_compress_level(2, file_buffer, file_size, compressed_buffer);
double ratio = (100.0 * compressed_size) / file_size;
#ifdef LOG
printf("Compressing was completed: %ld -> %ld (%.2f%%)\n", file_size, compressed_size, ratio);
#endif
#ifdef LOG
printf("Decompressing. Please wait...\n");
#endif
uint8_t* uncompressed_buffer = malloc(file_size);
if (uncompressed_buffer == NULL) {
printf("%25s %10ld -> %10d (%.2f%%) skipped, can't decompress\n", name, file_size, compressed_size, ratio);
return;
}
memset(uncompressed_buffer, '-', file_size);
/* intentionally mask out the block tag */
compressed_buffer[0] = compressed_buffer[0] & 31;
REF_Level2_decompress(compressed_buffer, compressed_size, uncompressed_buffer);
#ifdef LOG
printf("Comparing. Please wait...\n");
#endif
int result = compare(file_name, file_buffer, uncompressed_buffer, file_size);
if (result == 1) {
free(uncompressed_buffer);
exit(1);
}
free(file_buffer);
free(compressed_buffer);
free(uncompressed_buffer);
#ifdef LOG
printf("OK.\n");
#else
printf("%25s %10ld -> %10d (%.2f%%)\n", name, file_size, compressed_size, ratio);
#endif
}
/*
Read the content of the file.
Compress it first using the Level 1 compressor.
Decompress the output with Level 1 decompressor.
Compare the result with the original file content.
*/
void test_roundtrip_level1(const char* name, const char* file_name) {
#ifdef LOG
printf("Processing %s...\n", name);
#endif
FILE* f = fopen(file_name, "rb");
if (!f) {
printf("Error: can not open %s!\n", file_name);
exit(1);
}
fseek(f, 0L, SEEK_END);
long file_size = ftell(f);
rewind(f);
#ifdef LOG
printf("Size is %ld bytes.\n", file_size);
#endif
if (file_size > MAX_FILE_SIZE) {
fclose(f);
printf("%25s %10ld [skipped, file too big]\n", name, file_size);
return;
}
uint8_t* file_buffer = malloc(file_size);
long read = fread(file_buffer, 1, file_size, f);
fclose(f);
if (read != file_size) {
free(file_buffer);
printf("Error: only read %ld bytes!\n", read);
exit(1);
}
#ifdef LOG
printf("Compressing. Please wait...\n");
#endif
uint8_t* compressed_buffer = malloc(1.05 * file_size);
int compressed_size = fastlz_compress_level(1, file_buffer, file_size, compressed_buffer);
double ratio = (100.0 * compressed_size) / file_size;
#ifdef LOG
printf("Compressing was completed: %ld -> %ld (%.2f%%)\n", file_size, compressed_size, ratio);
#endif
#ifdef LOG
printf("Decompressing. Please wait...\n");
#endif
uint8_t* uncompressed_buffer = malloc(file_size);
if (uncompressed_buffer == NULL) {
printf("%25s %10ld -> %10d (%.2f%%) skipped, can't decompress\n", name, file_size, compressed_size, ratio);
return;
}
memset(uncompressed_buffer, '-', file_size);
fastlz_decompress(compressed_buffer, compressed_size, uncompressed_buffer, file_size);
#ifdef LOG
printf("Comparing. Please wait...\n");
#endif
int result = compare(file_name, file_buffer, uncompressed_buffer, file_size);
if (result == 1) {
free(uncompressed_buffer);
exit(1);
}
free(file_buffer);
free(compressed_buffer);
free(uncompressed_buffer);
#ifdef LOG
printf("OK.\n");
#else
printf("%25s %10ld -> %10d (%.2f%%)\n", name, file_size, compressed_size, ratio);
#endif
}
/*
Read the content of the file.
Compress it first using the Level 2 compressor.
Decompress the output with Level 2 decompressor.
Compare the result with the original file content.
*/
void test_roundtrip_level2(const char* name, const char* file_name) {
#ifdef LOG
printf("Processing %s...\n", name);
#endif
FILE* f = fopen(file_name, "rb");
if (!f) {
printf("Error: can not open %s!\n", file_name);
exit(1);
}
fseek(f, 0L, SEEK_END);
long file_size = ftell(f);
rewind(f);
#ifdef LOG
printf("Size is %ld bytes.\n", file_size);
#endif
if (file_size > MAX_FILE_SIZE) {
fclose(f);
printf("%25s %10ld [skipped, file too big]\n", name, file_size);
return;
}
uint8_t* file_buffer = malloc(file_size);
long read = fread(file_buffer, 1, file_size, f);
fclose(f);
if (read != file_size) {
free(file_buffer);
printf("Error: only read %ld bytes!\n", read);
exit(1);
}
#ifdef LOG
printf("Compressing. Please wait...\n");
#endif
uint8_t* compressed_buffer = malloc(1.05 * file_size);
int compressed_size = fastlz_compress_level(2, file_buffer, file_size, compressed_buffer);
double ratio = (100.0 * compressed_size) / file_size;
#ifdef LOG
printf("Compressing was completed: %ld -> %ld (%.2f%%)\n", file_size, compressed_size, ratio);
#endif
#ifdef LOG
printf("Decompressing. Please wait...\n");
#endif
uint8_t* uncompressed_buffer = malloc(file_size);
if (uncompressed_buffer == NULL) {
free(file_buffer);
free(compressed_buffer);
printf("%25s %10ld -> %10d (%.2f%%) skipped, can't decompress OOM\n", name, file_size, compressed_size, ratio);
exit(1);
return;
}
memset(uncompressed_buffer, '-', file_size);
fastlz_decompress(compressed_buffer, compressed_size, uncompressed_buffer, file_size);
#ifdef LOG
printf("Comparing. Please wait...\n");
#endif
int result = compare(file_name, file_buffer, uncompressed_buffer, file_size);
if (result == 1) {
free(uncompressed_buffer);
exit(1);
}
free(file_buffer);
free(compressed_buffer);
free(uncompressed_buffer);
#ifdef LOG
printf("OK.\n");
#else
printf("%25s %10ld -> %10d (%.2f%%)\n", name, file_size, compressed_size, ratio);
#endif
}
int main(int argc, char** argv) {
const char* default_prefix = "../compression-corpus/";
const char* names[] = {"canterbury/alice29.txt",
"canterbury/asyoulik.txt",
"canterbury/cp.html",
"canterbury/fields.c",
"canterbury/grammar.lsp",
"canterbury/kennedy.xls",
"canterbury/lcet10.txt",
"canterbury/plrabn12.txt",
"canterbury/ptt5",
"canterbury/sum",
"canterbury/xargs.1",
"silesia/dickens",
"silesia/mozilla",
"silesia/mr",
"silesia/nci",
"silesia/ooffice",
"silesia/osdb",
"silesia/reymont",
"silesia/samba",
"silesia/sao",
"silesia/webster",
"silesia/x-ray",
"silesia/xml",
"enwik/enwik8.txt"};
const char* prefix = (argc == 2) ? argv[1] : default_prefix;
const int count = sizeof(names) / sizeof(names[0]);
int i;
printf("Test reference decompressor for Level 1\n\n");
for (i = 0; i < count; ++i) {
const char* name = names[i];
char* filename = malloc(strlen(prefix) + strlen(name) + 1);
strcpy(filename, prefix);
strcat(filename, name);
test_ref_decompressor_level1(name, filename);
free(filename);
}
printf("\n");
printf("Test reference decompressor for Level 2\n\n");
for (i = 0; i < count; ++i) {
const char* name = names[i];
char* filename = malloc(strlen(prefix) + strlen(name) + 1);
strcpy(filename, prefix);
strcat(filename, name);
test_ref_decompressor_level2(name, filename);
free(filename);
}
printf("\n");
printf("Test round-trip for Level 1\n\n");
for (i = 0; i < count; ++i) {
const char* name = names[i];
char* filename = malloc(strlen(prefix) + strlen(name) + 1);
strcpy(filename, prefix);
strcat(filename, name);
test_roundtrip_level1(name, filename);
free(filename);
}
printf("\n");
printf("Test round-trip for Level 2\n\n");
for (i = 0; i < count; ++i) {
const char* name = names[i];
char* filename = malloc(strlen(prefix) + strlen(name) + 1);
strcpy(filename, prefix);
strcat(filename, name);
test_roundtrip_level2(name, filename);
free(filename);
}
printf("\n");
return 0;
}

4
FastLZ/tools/format-code.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
cwd=$(pwd)
clang-format-6.0 -i --style='{BasedOnStyle: "google", ColumnLimit: 120}' $cwd/*.h $cwd/*.c $cwd/tests/*.c $cwd/examples/*.c

View File

@ -1,4 +1,4 @@
.PHONY: clean prepare cleanall iso base kernel user test .PHONY: clean prepare cleanall iso hdd base kernel user test
ARCH ?= x86_64 ARCH ?= x86_64
@ -29,6 +29,11 @@ prepare:
$(PWD)/scripts/build-gcc.sh; \ $(PWD)/scripts/build-gcc.sh; \
cd ..; \ cd ..; \
fi fi
if [ ! -e FastLZ/examples/6pack ] || [ ! -e FastLZ/examples/6unpack ]; then \
cd FastLZ/examples; \
make; \
cd ..; \
fi
cleanall: cleanall:
make clean make clean
@ -38,10 +43,13 @@ clean:
make -C kernel ARCH=$(ARCH) ROOT=$(PWD) clean make -C kernel ARCH=$(ARCH) ROOT=$(PWD) clean
make -C user ARCH=$(ARCH) ROOT=$(PWD) clean make -C user ARCH=$(ARCH) ROOT=$(PWD) clean
make -C ulib ARCH=$(ARCH) ROOT=$(PWD) clean make -C ulib ARCH=$(ARCH) ROOT=$(PWD) clean
rm -f mop2.iso base.img rm -f mop2.iso base.img disk.hdd base.img.lz77
base: base:
./scripts/mkbaseimg.sh ./scripts/mkbaseimg.sh
iso: iso:
./scripts/mkiso.sh ./scripts/mkiso.sh
hdd:
./scripts/mkhdd.sh

213
README.md Normal file
View File

@ -0,0 +1,213 @@
# MOP2 - My OS project (2)
It's no. 2, because version no. 1 failed...
## Building
### Prepare stuff
```bash
make prepare
```
WARNING: This will take a while, since we're building an entire GCC toolchain + BinUtils.
### For development
```bash
./scripts/devel.sh
```
Will generate an `mop2.iso` image and a `disk.hdd`. You can run both live-iso and drive-installed
versions via `qemu-system-x86_64`.
## Running
There are two variants for the live-iso and drive-installed systems:
- `./run/qemu-x86_64-hdd.sh`
- `./run/qemu-x86_64-iso.sh`
## Blog posts
Sometimes I post updated on my blog regarding the project: [https://www.kamkow1lair.pl/]
## Screenshots
![Screenshot 1](https://git.kamkow1lair.pl/kamkow1/my-os-project2/raw/branch/master/static/MOP2-1.png)
![Screenshot 2](https://git.kamkow1lair.pl/kamkow1/my-os-project2/raw/branch/master/static/MOP2-2.png)
![Screenshot 3](https://git.kamkow1lair.pl/kamkow1/my-os-project2/raw/branch/master/static/MOP2-3.png)
## Legal
See `legal/` for the licenses of projects that where used as refrences. The directory also contains
licenses for used libraries.
LICENSE FOR MOP2:
```text
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
```

1
base/scripts/fmtdisk.tb Normal file
View File

@ -0,0 +1 @@
$fs fmt -dev $0 -fs $1

View File

@ -1,4 +1,5 @@
print 'this is an init script!\n' print 'this is an init script!\n'
setlogcmds yes
$tb -m runfile -f base:/scripts/mount.tb $tb -m runfile -f base:/scripts/mount.tb
$pctl ls $pctl ls
$tb -m interactive $tb -m interactive

View File

@ -1,2 +1,7 @@
print 'Mounting filesystems...\n' print 'Mounting filesystems...\n'
$fs mount -mp system -fs LittleFS -dev atasd-mst -fmt no setlogcmds yes
# MOUNTPOINT FILESYSTEM DEVICE NAME DO FORMATTING
$fs mount -mp uhome -fs LittleFS -dev atasd0mp2 -fmt no
$fs mount -mp sys -fs FAT16 -dev atasd0mp1 -fmt no

View File

@ -1,5 +1,3 @@
mkalias pctl base:/bin/pctl # Create an $alias out of basenames of each entry in base:/bin
mkalias tb base:/bin/tb eachfile !.gitkeep base:/bin \
mkalias fs base:/bin/fs mkaliasbn &EF-ELEM
mkalias dev base:/bin/dev
mkalias rc base:/bin/rc

115
kernel/FastLZ/6unpack_mem.c Normal file
View File

@ -0,0 +1,115 @@
#include <stdint.h>
#include <stddef.h>
#include "FastLZ/fastlz.h"
#include "std/string.h"
#define SIXPACK_OK 0
#define SIXPACK_ERR_MAGIC -1
#define SIXPACK_ERR_CHECKSUM -2
#define SIXPACK_ERR_DECOMPRESS -3
#define SIXPACK_ERR_BAD_FORMAT -4
#define SIXPACK_ERR_NO_SPACE -5
#define ADLER32_BASE 65521
#define BLOCK_SIZE 65536
static const uint8_t sixpack_magic[8] = {137, '6', 'P', 'K', 13, 10, 26, 10};
static uint32_t update_adler32(uint32_t checksum, const void *buf, int len) {
const uint8_t *ptr = (const uint8_t*)buf;
uint32_t s1 = checksum & 0xffff;
uint32_t s2 = (checksum >> 16) & 0xffff;
while (len > 0) {
unsigned k = len < 5552 ? len : 5552;
len -= k;
while (k--) {
s1 += *ptr++;
if (s1 >= ADLER32_BASE) s1 -= ADLER32_BASE;
s2 += s1;
if (s2 >= ADLER32_BASE) s2 -= ADLER32_BASE;
}
}
return (s2 << 16) + s1;
}
static uint32_t readU16(const uint8_t *p) {
return (uint32_t)p[0] | ((uint32_t)p[1] << 8);
}
static uint32_t readU32(const uint8_t *p) {
return (uint32_t)p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
}
static void read_chunk_header(const uint8_t *p, int *id, int *opts,
uint32_t *size, uint32_t *checksum, uint32_t *extra) {
*id = (int)readU16(p);
*opts = (int)readU16(p + 2);
*size = readU32(p + 4);
*checksum = readU32(p + 8);
*extra = readU32(p + 12);
}
int sixpack_decompress_mem(const uint8_t *input, size_t in_size,
uint8_t *output, size_t out_cap)
{
if (!input || in_size < 8)
return SIXPACK_ERR_BAD_FORMAT;
/* Check magic */
for (int i = 0; i < 8; i++)
if (input[i] != sixpack_magic[i])
return SIXPACK_ERR_MAGIC;
size_t pos = 8; /* skip magic */
size_t written = 0;
while (pos + 16 <= in_size) {
int chunk_id, opts;
uint32_t size, checksum, extra;
read_chunk_header(input + pos, &chunk_id, &opts, &size, &checksum, &extra);
pos += 16;
if (pos + size > in_size)
return SIXPACK_ERR_BAD_FORMAT;
const uint8_t *chunk_data = input + pos;
pos += size;
/* File header chunk */
if (chunk_id == 1) {
uint32_t decomp_size = readU32(chunk_data);
(void)decomp_size; /* not strictly needed here */
continue;
}
/* Data chunk */
if (chunk_id == 17) {
uint32_t cksum = update_adler32(1L, chunk_data, size);
if (cksum != checksum)
return SIXPACK_ERR_CHECKSUM;
if (opts == 0) {
/* Stored (uncompressed) */
if (written + size > out_cap)
return SIXPACK_ERR_NO_SPACE;
memcpy(output + written, chunk_data, size);
written += size;
} else if (opts == 1) {
/* FastLZ compressed */
if (written + extra > out_cap)
return SIXPACK_ERR_NO_SPACE;
int dec = fastlz_decompress(chunk_data, size, output + written, extra);
if (dec != (int)extra)
return SIXPACK_ERR_DECOMPRESS;
written += extra;
} else {
return SIXPACK_ERR_BAD_FORMAT;
}
}
}
return (int)written;
}

View File

@ -0,0 +1,7 @@
#ifndef SIXUNPACK_MEM_H_
#define SIXUNPACK_MEM_H_
int sixpack_decompress_mem(const uint8_t *input, size_t in_size,
uint8_t *output, size_t out_cap);
#endif // SIXUNPACK_MEM_H_

1
kernel/FastLZ/fastlz.c Symbolic link
View File

@ -0,0 +1 @@
../../FastLZ/fastlz.c

1
kernel/FastLZ/fastlz.h Symbolic link
View File

@ -0,0 +1 @@
../../FastLZ/fastlz.h

View File

@ -4,7 +4,8 @@ include $(ROOT)/mk/grabsrc.mk
PUTCHAR_ ?= fb PUTCHAR_ ?= fb
CFLAGS := -ffreestanding -Wall -Wextra -g -fcommon -nostdinc CFLAGS := -ffreestanding -Wall -Wextra -fcommon -nostdinc \
-fdata-sections -ffunction-sections
CFLAGS += -I. \ CFLAGS += -I. \
-I$(ROOT)/limine \ -I$(ROOT)/limine \
@ -12,23 +13,22 @@ CFLAGS += -I. \
-I./std \ -I./std \
-I./flanterm/src \ -I./flanterm/src \
-I$(ROOT)/share \ -I$(ROOT)/share \
-I./picotcp/include \
-I./picotcp/modules \
-I./port_picotcp \
-DPRINTF_INCLUDE_CONFIG_H=1 \ -DPRINTF_INCLUDE_CONFIG_H=1 \
-DLFS_NO_ASSERT \ -DLFS_NO_ASSERT \
-DLFS_NO_DEBUG \ -DLFS_NO_DEBUG \
-DLFS_NO_WARN \ -DLFS_NO_WARN \
-DLFS_NO_ERROR \ -DLFS_NO_ERROR \
-DUACPI_BAREBONES_MODE -DFASTLZ_USE_MEMMOVE=0 \
-DFATFS_MAX_OPEN_FILES=128 \
ifeq ($(PUTCHAR_),fb) -D"FAT_PRINTF(a)"
CFLAGS += -DPUTCHAR_=PUTCHAR_FB
else
CFLAGS += -DPUTCHAR_=PUTCHAR_SERIAL
endif
include arch/$(ARCH)/$(ARCH).mk include arch/$(ARCH)/$(ARCH).mk
include extconf/extra.mk
LDFLAGS += -nostdlib -static -T arch/$(ARCH)/link.ld $(shell $(CC) -print-libgcc-file-name) LDFLAGS += -nostdlib -static -T arch/$(ARCH)/link.ld $(shell $(CC) -print-libgcc-file-name) \
--gc-sections --strip-all
SRCFILES := SRCFILES :=
@ -47,10 +47,10 @@ SRCFILES += $(call GRABSRC, \
fs/kvfs \ fs/kvfs \
fs/littlefs \ fs/littlefs \
fs/portlfs \ fs/portlfs \
fs/fatfs \
fs/portfatfs \
baseimg \ baseimg \
proc \ proc \
hal \
hal/$(ARCH) \
std \ std \
flanterm/src \ flanterm/src \
flanterm/src/flanterm_backends \ flanterm/src/flanterm_backends \
@ -58,8 +58,20 @@ SRCFILES += $(call GRABSRC, \
path \ path \
rbuf \ rbuf \
ipc/pipe \ ipc/pipe \
ipc/mbus \
dev \ dev \
randcrypto \ randcrypto \
time \
diskpart \
FastLZ \
io \
intr \
cpu \
vmm \
pci \
pci/ata \
pci/qemu_pci_serial \
cjob \
) )
CFILES := $(call GET_CFILES, $(SRCFILES)) CFILES := $(call GET_CFILES, $(SRCFILES))

View File

@ -9,7 +9,7 @@
//Regular text //Regular text
#define BLK "\e[0;30m" #define BLK "\e[0;30m"
#define RED "\e[0;31m" #define RED1 "\e[0;31m"
#define GRN "\e[0;32m" #define GRN "\e[0;32m"
#define YEL "\e[0;33m" #define YEL "\e[0;33m"
#define BLU "\e[0;34m" #define BLU "\e[0;34m"
@ -78,7 +78,7 @@
#define BHWHT "\e[1;97m" #define BHWHT "\e[1;97m"
//Reset //Reset
#define reset "\e[0m" #define RESET "\e[0m"
#define CRESET "\e[0m" #define CRESET "\e[0m"
#define COLOR_RESET "\e[0m" #define COLOR_RESET "\e[0m"

View File

@ -1,15 +0,0 @@
#ifndef ASSERT_H_
#define ASSERT_H_
#include "kprintf.h"
#include "hal/hal.h"
#define ASSERT(mod, cond, fmt, ...) \
do { \
if (!(cond)) { \
ERR(mod, fmt, ##__VA_ARGS__); \
hal_hang(); \
} \
} while(0)
#endif // ASSERT_H_

View File

@ -1,6 +0,0 @@
#ifndef ATOMIC_H_
#define ATOMIC_H_
#define ATOMIC(X) _Atomic(X)
#endif // ATOMIC_H_

View File

@ -1,37 +1,46 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <limine.h> #include <limine.h>
#include "baseimg.h" #include "baseimg/baseimg.h"
#include "bootinfo/bootinfo.h" #include "bootinfo/bootinfo.h"
#include "kprintf.h"
#include "util/util.h" #include "util/util.h"
#include "hal/hal.h" #include "dlmalloc/malloc.h"
#include "FastLZ/fastlz.h"
#include "FastLZ/6unpack_mem.h"
#include "std/string.h"
#include "cpu/hang.h"
#include "kprintf.h"
struct limine_file *baseimg = NULL; #define BASEIMG_DECOMPRESSED (1024*1024*4)
size_t BASEIMG_DECOMP_SIZE;
uint8_t *BASEIMG_DECOMP_ADDR;
uint64_t baseimg_getaddr(void) { uint64_t baseimg_getaddr(void) {
return (uint64_t)baseimg->address; return (uint64_t)BASEIMG_DECOMP_ADDR;
} }
uint64_t baseimg_getsize(void) { uint64_t baseimg_getsize(void) {
return baseimg->size; return (uint64_t)BASEIMG_DECOMP_SIZE;
} }
void baseimg_init(void) { void baseimg_init(void) {
struct limine_file *baseimg = NULL;
LOG("baseimg", "looking for base image...\n"); LOG("baseimg", "looking for base image...\n");
for (size_t i = 0; i < BOOT_INFO.modules->module_count; i++) { for (size_t i = 0; i < BOOT_INFO.modules->module_count; i++) {
struct limine_file *module = BOOT_INFO.modules->modules[i]; struct limine_file *module = BOOT_INFO.modules->modules[i];
if (hal_strcmp(util_get_filename(module->path), "base.img") == 0) { if (strcmp(util_get_filename(module->path), "base.img.6pk") == 0) {
baseimg = module; baseimg = module;
break; break;
} }
} }
if (baseimg == NULL) { if (baseimg == NULL) {
ERR("baseimg", "base.img not found\n"); ERR("baseimg", "base.img.6pk not found\n");
hal_hang(); cpu_hang();
} else { } else {
LOG("baseimg", "base.img found\n"); LOG("baseimg", "base.img.6pk found\n");
LOG("baseimg", "addr = %p, size = %lu\n", baseimg->address, baseimg->size); LOG("baseimg", "addr = %p, size = %lu\n", baseimg->address, baseimg->size);
for (size_t i = 0; i < 30; i++) { for (size_t i = 0; i < 30; i++) {
kprintf("%02X ", ((uint8_t *)(baseimg->address))[i]); kprintf("%02X ", ((uint8_t *)(baseimg->address))[i]);
@ -40,4 +49,14 @@ void baseimg_init(void) {
} }
} }
} }
BASEIMG_DECOMP_ADDR = dlmalloc(BASEIMG_DECOMPRESSED);
int res = sixpack_decompress_mem(baseimg->address, baseimg->size,
BASEIMG_DECOMP_ADDR, BASEIMG_DECOMPRESSED);
if (res < 0) {
ERR("baseimg", "could not uncompress base.img.6pk\n");
cpu_hang();
}
BASEIMG_DECOMP_SIZE = res;
kprintf("%p %zu\n", BASEIMG_DECOMP_ADDR, BASEIMG_DECOMP_SIZE);
} }

View File

@ -1,7 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include "bitmap.h" #include "bitmap/bitmap.h"
#include "util/util.h" #include "util/util.h"
#include "kprintf.h" #include "kprintf.h"

View File

@ -4,8 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include "vmm/vmm.h"
#include "hal/hal.h"
typedef struct { typedef struct {
uint8_t *map; uint8_t *map;
@ -17,7 +16,7 @@ typedef struct {
} BitMap; } BitMap;
#define BITMAP_BLOCKS_PER_BYTE 8 #define BITMAP_BLOCKS_PER_BYTE 8
#define BITMAP_BLOCK_SIZE HAL_PAGE_SIZE #define BITMAP_BLOCK_SIZE VMM_PAGE_SIZE
#define BITMAP_INVALID_BLOCK ((size_t)-1) #define BITMAP_INVALID_BLOCK ((size_t)-1)
void *bitmap_toptr(BitMap *bm, size_t block); void *bitmap_toptr(BitMap *bm, size_t block);

View File

@ -1,8 +1,8 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <limine.h> #include <limine.h>
#include "bootinfo.h" #include "bootinfo/bootinfo.h"
#include "hal/hal.h" #include "cpu/hang.h"
BootInfo BOOT_INFO; BootInfo BOOT_INFO;
@ -26,7 +26,7 @@ DEFINE_REQ(module, MODULE);
void bootinfo_init(void) { void bootinfo_init(void) {
if (framebuffer_req.response == NULL || framebuffer_req.response->framebuffer_count < 1) { if (framebuffer_req.response == NULL || framebuffer_req.response->framebuffer_count < 1) {
hal_hang(); cpu_hang();
} }
BOOT_INFO.fb = framebuffer_req.response->framebuffers[0]; BOOT_INFO.fb = framebuffer_req.response->framebuffers[0];
@ -35,7 +35,7 @@ void bootinfo_init(void) {
struct limine_paging_mode_response *pagingres = paging_req.response; struct limine_paging_mode_response *pagingres = paging_req.response;
if (pagingres->mode != LIMINE_PAGING_MODE_X86_64_4LVL) { if (pagingres->mode != LIMINE_PAGING_MODE_X86_64_4LVL) {
hal_hang(); cpu_hang();
} }
struct limine_hhdm_response *hhdmres = hhdm_req.response; struct limine_hhdm_response *hhdmres = hhdm_req.response;
@ -68,7 +68,7 @@ void bootinfo_init(void) {
} }
} }
if (BOOT_INFO.smp_bspindex == (uint64_t)-1) { if (BOOT_INFO.smp_bspindex == (uint64_t)-1) {
hal_hang(); cpu_hang();
} }
struct limine_rsdp_response *rsdpres = rsdp_req.response; struct limine_rsdp_response *rsdpres = rsdp_req.response;

36
kernel/cjob/cjob.c Normal file
View File

@ -0,0 +1,36 @@
#include <stdint.h>
#include <stddef.h>
#include "spinlock/spinlock.h"
#include "cjob/cjob.h"
#include "dlmalloc/malloc.h"
#include "util/util.h"
CJobs CJOBS;
static uint64_t cjobids = 0;
void cjob_init(void) {
spinlock_init(&CJOBS.spinlock);
CJOBS.cjobs = NULL;
}
int32_t cjob_register(CJobFn fn, void *arg) {
CJob *cjob = dlmalloc(sizeof(*cjob));
cjob->fn = fn;
cjob->arg = arg;
int32_t id = cjob->id = cjobids++;
spinlock_acquire(&CJOBS.spinlock);
LL_APPEND(CJOBS.cjobs, cjob);
spinlock_release(&CJOBS.spinlock);
return id;
}
void cjob_runjobs(void) {
CJob *cjob, *cjobtmp;
spinlock_acquire(&CJOBS.spinlock);
LL_FOREACH_SAFE(CJOBS.cjobs, cjob, cjobtmp) {
cjob->fn(cjob->arg);
}
spinlock_release(&CJOBS.spinlock);
}

29
kernel/cjob/cjob.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef CJOB_CJOB_H_
#define CJOB_CJOB_H_
#include <stdint.h>
#include <stddef.h>
#include "spinlock/spinlock.h"
typedef void (*CJobFn)(void *arg);
typedef struct CJob {
struct CJob *next;
CJobFn fn;
void *arg;
int32_t id;
} CJob;
typedef struct {
SpinLock spinlock;
CJob *cjobs;
} CJobs;
extern CJobs CJOBS;
void cjob_init(void);
int32_t cjob_register(CJobFn fn, void *arg);
void cjob_runjobs(void);
#endif // CJOB_CJOB_H_

View File

@ -1,8 +1,8 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "compiler/attr.h" #include "compiler/attr.h"
#include "hal/hal.h" #include "cpu/gdt.h"
#include "gdt.h" #include "std/string.h"
#define GDT_PRESENT 0x80 #define GDT_PRESENT 0x80
#define GDT_TSS 0x89 #define GDT_TSS 0x89
@ -43,7 +43,7 @@ void gdt_setentry(GdtEntry *ent, uint32_t base, uint32_t limit, uint8_t acc, uin
} }
void gdt_init(void) { void gdt_init(void) {
hal_memset(&tss, 0, sizeof(tss)); memset(&tss, 0, sizeof(tss));
tss.iopb_off = sizeof(tss); tss.iopb_off = sizeof(tss);
tss.rsp0 = (uint64_t)(kernelstack + sizeof(kernelstack)); tss.rsp0 = (uint64_t)(kernelstack + sizeof(kernelstack));

View File

@ -1,5 +1,8 @@
#ifndef HAL_GDT_H_ #ifndef CPU_GDT_H_
#define HAL_GDT_H_ #define CPU_GDT_H_
#include <stdint.h>
#include "compiler/attr.h"
#define KCODE 0x08 #define KCODE 0x08
#define KDATA 0x10 #define KDATA 0x10
@ -23,4 +26,4 @@ ALIGNED(16) extern Tss tss;
void gdt_init(void); void gdt_init(void);
#endif // HAL_GDT_H_ #endif // CPU_GDT_H_

10
kernel/cpu/hang.c Normal file
View File

@ -0,0 +1,10 @@
#include "cpu/hang.h"
#include "intr/intr.h"
void cpu_hang(void) {
intr_disable();
for(;;) {
asm("hlt");
}
}

6
kernel/cpu/hang.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CPU_HANG_H_
#define CPU_HANG_H_
void cpu_hang(void);
#endif // CPU_HANG_H_

View File

@ -1,22 +1,16 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "spinlock/spinlock.h" #include "spinlock/spinlock.h"
#include "dev.h" #include "std/string.h"
#include "dev/dev.h"
#include "dev/ps2kbdev.h"
#include "hshtb.h" #include "hshtb.h"
#include "hal/hal.h"
#include "termdev.h"
#include "ps2kbdev.h"
#include "serialdev.h"
#include "fbdev.h"
DevTable DEVTABLE; DevTable DEVTABLE;
void dev_init(void) { void dev_init(void) {
hal_memset(&DEVTABLE, 0, sizeof(DEVTABLE)); memset(&DEVTABLE, 0, sizeof(DEVTABLE));
spinlock_init(&DEVTABLE.spinlock); spinlock_init(&DEVTABLE.spinlock);
termdev_init();
ps2kbdev_init(); ps2kbdev_init();
serialdev_init();
fbdev_init();
} }

View File

@ -8,7 +8,7 @@
struct Dev; struct Dev;
typedef int32_t (*DevFn)(struct Dev *dev, uint8_t *buffer, size_t len, void *extra); typedef int32_t (*DevFn)(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid);
typedef struct Dev { typedef struct Dev {
int _hshtbstate; int _hshtbstate;

View File

@ -1,30 +0,0 @@
#include <stdint.h>
#include <stddef.h>
#include "fbdev.h"
#include "dev.h"
#include "sysdefs/devctl.h"
#include "hshtb.h"
#include "spinlock/spinlock.h"
#include "util/util.h"
#include "hal/hal.h"
#include "bootinfo/bootinfo.h"
#include "errors.h"
int32_t fbdev_getinfo(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void)extra;
FbDevGetInfo info = {
.w = BOOT_INFO.fb->width,
.h = BOOT_INFO.fb->height,
.margin = 20,
.fontw = 8,
.fonth = 16,
};
hal_memcpy(buffer, &info, sizeof(info));
return E_OK;
}
void fbdev_init(void) {
Dev *fbdev;
HSHTB_ALLOC(DEVTABLE.devs, ident, "fbdev", fbdev);
fbdev->fns[DEV_FBDEV_GETINFO] = &fbdev_getinfo;
}

View File

@ -1,6 +0,0 @@
#ifndef DEV_FBDEV_H_
#define DEV_FBDEV_H_
void fbdev_init(void);
#endif // DEV_FBDEV_H_

View File

@ -1,15 +1,17 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "kprintf.h" #include "dev/ps2kbdev.h"
#include "hal/hal.h" #include "dev/dev.h"
#include "ps2kbdev.h"
#include "dev.h"
#include "errors.h"
#include "dlmalloc/malloc.h" #include "dlmalloc/malloc.h"
#include "util/util.h" #include "util/util.h"
#include "hshtb.h" #include "sysdefs/dev.h"
#include "sysdefs/devctl.h"
#include "proc/proc.h" #include "proc/proc.h"
#include "io/io.h"
#include "ipc/mbus/mbus.h"
#include "intr/intr.h"
#include "errors.h"
#include "hshtb.h"
#include "kprintf.h"
#define KB_CTL_STATUS 0x64 #define KB_CTL_STATUS 0x64
#define KB_DATA_IN_BUF 0x01 #define KB_DATA_IN_BUF 0x01
@ -115,7 +117,7 @@ static uint8_t ctlmap[256] =
[0xc7] KB_HOME, [0xc7] KB_HOME,
}; };
int32_t ps2kb_intr(void) { int32_t ps2kbdev_keycode(void) {
static uint8_t shift; static uint8_t shift;
static uint8_t *charcode[4] = { normalmap, shiftmap, ctlmap, ctlmap }; static uint8_t *charcode[4] = { normalmap, shiftmap, ctlmap, ctlmap };
uint32_t st, data, c; uint32_t st, data, c;
@ -152,110 +154,23 @@ int32_t ps2kb_intr(void) {
return c; return c;
} }
typedef struct Ps2kbEvConsumer { IpcMBus *PS2KB_MBUS;
struct Ps2kbEvConsumer *next;
Proc *proc;
RBuf rbuf;
} Ps2kbEvConsumer;
struct { void ps2kbdev_intr(IntrStackFrame *frame) {
SpinLock spinlock; (void)frame;
Ps2kbEvConsumer *list;
} PS2KB_CONSUMERS = {0};
int32_t ps2kbdev_readch(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) { int32_t c = ps2kbdev_keycode();
(void)dev; (void)len; (void)extra;
uint64_t pid = (uint64_t)buffer;
Proc *consproc = NULL;
spinlock_acquire(&PROCS.spinlock);
Proc *proc, *proctmp;
LL_FOREACH_SAFE(PROCS.procs, proc, proctmp) {
if (proc->pid == pid) {
consproc = proc;
}
}
spinlock_release(&PROCS.spinlock);
if (consproc == NULL) {
return E_INVALIDOPER;
}
uint8_t b;
int32_t r = -1;
spinlock_acquire(&PS2KB_CONSUMERS.spinlock);
Ps2kbEvConsumer *cons, *constmp;
LL_FOREACH_SAFE(PS2KB_CONSUMERS.list, cons, constmp) {
if (cons->proc == consproc) {
r = rbuf_pop(&cons->rbuf, &b);
break;
}
}
spinlock_release(&PS2KB_CONSUMERS.spinlock);
if (r == 0) {
return b;
} else {
return E_NOTYET;
}
}
#define CONSUMER_RBUF_MAX 0x400
int32_t ps2kbdev_attchcons(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)len; (void)extra;
uint64_t pid = (uint64_t)buffer;
spinlock_acquire(&PROCS.spinlock);
Proc *proc, *proctmp;
LL_FOREACH_SAFE(PROCS.procs, proc, proctmp) {
if (proc->pid == pid) {
Ps2kbEvConsumer *cons = dlmalloc(sizeof(*cons));
cons->proc = proc;
uint8_t *buf = dlmalloc(CONSUMER_RBUF_MAX);
rbuf_init(&cons->rbuf, buf, CONSUMER_RBUF_MAX);
spinlock_acquire(&PS2KB_CONSUMERS.spinlock);
LL_APPEND(PS2KB_CONSUMERS.list, cons);
spinlock_release(&PS2KB_CONSUMERS.spinlock);
break;
}
}
spinlock_release(&PROCS.spinlock);
return E_OK;
}
void ps2kbdev_intr(void) {
int32_t c = ps2kb_intr();
if (c >= 0) { if (c >= 0) {
uint8_t b = c; uint8_t b = c;
spinlock_acquire(&PS2KB_CONSUMERS.spinlock); ipc_mbuspublish("ps2kb", &b);
Ps2kbEvConsumer *cons, *constmp;
LL_FOREACH_SAFE(PS2KB_CONSUMERS.list, cons, constmp) {
bool found = false;
spinlock_acquire(&PROCS.spinlock);
Proc *proc, *proctmp;
LL_FOREACH_SAFE(PROCS.procs, proc, proctmp) {
if (proc == cons->proc) {
found = true;
}
}
if (!found) {
LL_REMOVE(PS2KB_CONSUMERS.list, cons);
}
spinlock_release(&PROCS.spinlock);
rbuf_push(&cons->rbuf, b);
}
spinlock_release(&PS2KB_CONSUMERS.spinlock);
} }
} }
void ps2kbdev_init(void) { void ps2kbdev_init(void) {
intr_attchhandler(&ps2kbdev_intr, INTR_IRQBASE+1);
Dev *ps2kbdev; Dev *ps2kbdev;
HSHTB_ALLOC(DEVTABLE.devs, ident, "ps2kbdev", ps2kbdev); HSHTB_ALLOC(DEVTABLE.devs, ident, "ps2kbdev", ps2kbdev);
spinlock_init(&ps2kbdev->spinlock); spinlock_init(&ps2kbdev->spinlock);
spinlock_init(&PS2KB_CONSUMERS.spinlock); PS2KB_MBUS = ipc_mbusmake("ps2kb", 1, 0x100);
ps2kbdev->fns[DEV_PS2KBDEV_READCH] = &ps2kbdev_readch;
ps2kbdev->fns[DEV_PS2KBDEV_ATTCHCONS] = &ps2kbdev_attchcons; intr_attchhandler(&ps2kbdev_intr, INTR_IRQBASE+1);
} }

View File

@ -1,81 +0,0 @@
#include <stdint.h>
#include <stddef.h>
#include "dev.h"
#include "serialdev.h"
#include "errors.h"
#include "util/util.h"
#include "hshtb.h"
#include "sysdefs/devctl.h"
#include "kprintf.h"
#include "hal/hal.h"
// https://wiki.osdev.org/Serial_Ports
#define PORT 0x3f8
void serial_init(void) {
io_out8(PORT+1, 0x00);
io_out8(PORT+3, 0x80);
io_out8(PORT+0, 0x03);
io_out8(PORT+1, 0x00);
io_out8(PORT+3, 0x03);
io_out8(PORT+2, 0xC7);
io_out8(PORT+4, 0x0B);
io_out8(PORT+4, 0x1E);
io_out8(PORT+0, 0xAE);
if (io_in8(PORT+0) != 0xAE) {
ERR("serial", "serial is faulty!\n");
return;
}
io_out8(PORT+4, 0x0F);
}
int serial_recvready(void) {
return io_in8(PORT+5) & 1;
}
uint8_t serial_recvb(void) {
return io_in8(PORT);
}
int serial_sendready(void) {
return io_in8(PORT+5) & 0x20;
}
void serial_sendb(uint8_t b) {
io_out8(PORT, b);
}
int32_t serialdev_sendb(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)len; (void)extra;
serial_sendb(buffer[0]);
return E_OK;
}
int32_t serialdev_sendready(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void) extra;
return serial_sendready();
}
int32_t serialdev_recvb(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void)extra;
return serial_recvb();
}
int32_t serialdev_recvready(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void)extra;
return serial_recvready();
}
void serialdev_init(void) {
Dev *serialdev = NULL;
HSHTB_ALLOC(DEVTABLE.devs, ident, "serialdev", serialdev);
serialdev->fns[DEV_SERIALDEV_SENDB] = &serialdev_sendb;
serialdev->fns[DEV_SERIALDEV_SENDREADY] = &serialdev_sendready;
serialdev->fns[DEV_SERIALDEV_RECVB] = &serialdev_recvb;
serialdev->fns[DEV_SERIALDEV_RECVREADY] = &serialdev_recvready;
spinlock_init(&serialdev->spinlock);
serial_init();
}

View File

@ -1,6 +0,0 @@
#ifndef DEV_SERIALDEV_H_
#define DEV_SERIALDEV_H_
void serialdev_init(void);
#endif // DEV_SERIALDEV_H_

View File

@ -1,23 +0,0 @@
#include <stdint.h>
#include <stddef.h>
#include "kprintf.h"
#include "hal/hal.h"
#include "termdev.h"
#include "dev.h"
#include "errors.h"
#include "util/util.h"
#include "hshtb.h"
#include "sysdefs/devctl.h"
int32_t termdev_putch(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)extra;
kprintf("%.*s", (int)len, (char *)buffer);
return E_OK;
}
void termdev_init(void) {
Dev *termdev = NULL;
HSHTB_ALLOC(DEVTABLE.devs, ident, "termdev", termdev);
termdev->fns[DEV_TERMDEV_PUTCH] = &termdev_putch;
spinlock_init(&termdev->spinlock);
}

View File

@ -1,10 +0,0 @@
#ifndef DEV_TERMDEV_H_
#define DEV_TERMDEV_H_
#include <stdint.h>
#include <stddef.h>
#include "dev.h"
void termdev_init(void);
#endif // DEV_TERMDEV_H_

View File

@ -0,0 +1,15 @@
#include <stdint.h>
#include <stddef.h>
#include "storedev/storedev.h"
#include "diskpart/mbr.h"
#include "util/util.h"
#include "kprintf.h"
void diskpart_init(void) {
LOG("diskpart", "probing for disks with partitions\n");
StoreDev *sd, *sdtmp;
LL_FOREACH_SAFE(STOREDEV_LIST.head, sd, sdtmp) {
diskpart_mbr_probe(sd);
}
}

View File

@ -0,0 +1,6 @@
#ifndef DISKPART_DISKPART_H_
#define DISKPART_DISKPART_H_
void diskpart_init(void);
#endif // DISKPART_DISKPART_H_

77
kernel/diskpart/mbr.c Normal file
View File

@ -0,0 +1,77 @@
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include "storedev/storedev.h"
#include "diskpart/mbr.h"
#include "diskpart/diskpart.h"
#include "compiler/attr.h"
#include "util/util.h"
#include "dev/dev.h"
#include "std/string.h"
#include "errors.h"
#include "kprintf.h"
typedef struct {
uint8_t driveattrs;
uint8_t chs_start_addr[3];
uint8_t parttype;
uint8_t chs_last_sect_addr[3];
uint32_t startlba;
uint32_t sectorcount;
} PACKED PTE;
typedef struct {
uint8_t bootcode[440];
uint8_t signature[4];
uint8_t resv[2];
PTE pte1;
PTE pte2;
PTE pte3;
PTE pte4;
uint8_t validsign[2];
} PACKED MBR;
void diskpart_mbr_expose_partitions(StoreDev *sd, MBR *mbr) {
PTE *parts[4] = { &mbr->pte1, &mbr->pte2, &mbr->pte3, &mbr->pte4 };
for (size_t i = 0; i < 4; i++) {
char *name = NULL;
spinlock_acquire(&DEVTABLE.spinlock);
for (size_t i = 0; i < LEN(DEVTABLE.devs); i++) {
Dev *dev = &DEVTABLE.devs[i];
if (dev->extra == sd) {
name = (char *)dev->ident;
}
}
spinlock_release(&DEVTABLE.spinlock);
PartSdInitExtra extra = {
.parent = sd,
.sectorcount = parts[i]->sectorcount,
.startsector = parts[i]->startlba,
};
char name1[100];
ksprintf(name1, "%sp%zu", name, i+1);
kprintf("%s\n", name1);
storedev_create(STOREDEV_PARTSD, name1, &extra);
}
}
bool diskpart_mbr_probe(StoreDev *sd) {
LOG("diskpart", "probing for MBR\n");
MBR mbr;
memset(&mbr, 0, sizeof(mbr));
sd->read(sd, (uint8_t *const)&mbr, 0, 0, sizeof(mbr));
if (!(mbr.validsign[0] == 0x55 && mbr.validsign[1] == 0xAA)) {
return false;
}
LOG("diskpart", "got valid MBR on %s\n", storedev_strings[sd->sdtype]);
diskpart_mbr_expose_partitions(sd, &mbr);
return true;
}

9
kernel/diskpart/mbr.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef DISKPART_MBR_H_
#define DISKPART_MBR_H_
#include <stdbool.h>
#include "storedev/storedev.h"
bool diskpart_mbr_probe(StoreDev *sd);
#endif // DISKPART_MBR_H_

View File

@ -1,14 +1,16 @@
// Config // Config
#include <stddef.h> #include <stddef.h>
#include "hal/hal.h"
#include "spinlock/spinlock.h" #include "spinlock/spinlock.h"
#include "kprintf.h"
#include "bitmap/bitmap.h" #include "bitmap/bitmap.h"
#include "util/util.h" #include "util/util.h"
#include "pmm/pmm.h" #include "pmm/pmm.h"
#include "malloc.h" #include "dlmalloc/malloc.h"
#include "bootinfo/bootinfo.h" #include "bootinfo/bootinfo.h"
#include "std/string.h"
#include "vmm/vmm.h"
#include "cpu/hang.h"
#include "kprintf.h"
#define USE_DL_PREFIX 1 #define USE_DL_PREFIX 1
#define LACKS_SYS_TYPES_H 1 #define LACKS_SYS_TYPES_H 1
@ -26,7 +28,7 @@
#define ABORT \ #define ABORT \
do { \ do { \
ERR("dlmalloc", "Aborting..."); \ ERR("dlmalloc", "Aborting..."); \
hal_hang(); \ cpu_hang(); \
} while(0) } while(0)
#define MALLOC_FAILURE_ACTION #define MALLOC_FAILURE_ACTION
#define HAVE_MORECORE 1 #define HAVE_MORECORE 1
@ -67,7 +69,7 @@ void *sbrk(long inc) {
uint64_t blocks = _DIV_ROUNDUP(inc, BITMAP_BLOCK_SIZE); uint64_t blocks = _DIV_ROUNDUP(inc, BITMAP_BLOCK_SIZE);
uint8_t *virt = VIRT(pmm_alloc(blocks)); uint8_t *virt = VIRT(pmm_alloc(blocks));
hal_memset(virt, 0, blocks * BITMAP_BLOCK_SIZE); memset(virt, 0, blocks * BITMAP_BLOCK_SIZE);
_last = (void *)(virt + inc); _last = (void *)(virt + inc);
return virt; return virt;
} }

View File

@ -1 +0,0 @@
CFLAGS += -DKPRINTF_COLORS

View File

@ -1,345 +0,0 @@
unsigned char FM_T_437_F16[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0x81, 0xa5, 0xa5, 0x81, 0x81,
0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x7e, 0xff, 0xff,
0xdb, 0xdb, 0xff, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00,
0x00, 0x22, 0x22, 0x77, 0x7f, 0x7f, 0x7f, 0x7f, 0x3e, 0x3e, 0x1c, 0x1c,
0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x1c, 0x3e, 0x3e, 0x7f, 0x7f,
0x3e, 0x3e, 0x1c, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x1c,
0x1c, 0x08, 0x6b, 0x7f, 0x7f, 0x6b, 0x08, 0x1c, 0x3e, 0x00, 0x00, 0x00,
0x00, 0x08, 0x08, 0x1c, 0x3e, 0x7f, 0x7f, 0x7f, 0x7f, 0x2a, 0x08, 0x1c,
0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x7e, 0x7e, 0x7e,
0x7e, 0x7e, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xc3,
0xc3, 0x81, 0x81, 0x81, 0x81, 0x81, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff,
0x00, 0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24,
0x18, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xdb, 0xdb, 0xbd, 0xbd, 0xbd,
0xbd, 0xbd, 0xdb, 0xdb, 0xe7, 0xff, 0xff, 0xff, 0x00, 0x0f, 0x03, 0x05,
0x05, 0x08, 0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, 0x00, 0x00,
0x00, 0x1c, 0x22, 0x41, 0x41, 0x41, 0x41, 0x22, 0x1c, 0x08, 0x08, 0x3e,
0x08, 0x08, 0x00, 0x00, 0x00, 0x08, 0x0c, 0x0a, 0x0a, 0x09, 0x09, 0x09,
0x08, 0x08, 0x38, 0x78, 0x78, 0x30, 0x00, 0x00, 0x00, 0x3f, 0x21, 0x3f,
0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x23, 0x67, 0xe7, 0xe2, 0x40, 0x00,
0x00, 0x49, 0x49, 0x2a, 0x36, 0x14, 0x22, 0xe3, 0x22, 0x14, 0x36, 0x2a,
0x49, 0x49, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e,
0x7c, 0x78, 0x70, 0x60, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06,
0x0e, 0x1e, 0x3e, 0x7e, 0x3e, 0x1e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00,
0x00, 0x08, 0x1c, 0x2a, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x2a,
0x1c, 0x08, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22, 0x22, 0x00, 0x00, 0x22, 0x22, 0x00, 0x00, 0x00, 0x3f, 0x49, 0x49,
0x49, 0x49, 0x39, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x40, 0x20, 0x58, 0x44, 0x22, 0x1a, 0x04, 0x02,
0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x2a,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x2a, 0x1c, 0x08, 0x3e, 0x00, 0x00,
0x00, 0x08, 0x1c, 0x2a, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x2a, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0x02, 0x7f, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x7f, 0x20, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40,
0x40, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x24, 0x42, 0xff, 0x42, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x1c, 0x1c, 0x3e, 0x3e, 0x7f, 0x7f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x3e, 0x3e,
0x1c, 0x1c, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x08, 0x08, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24,
0x7e, 0x24, 0x24, 0x24, 0x24, 0x24, 0x7e, 0x24, 0x24, 0x24, 0x00, 0x00,
0x00, 0x08, 0x1e, 0x2b, 0x28, 0x28, 0x28, 0x1c, 0x0a, 0x0a, 0x0a, 0x6a,
0x3c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x32, 0x52, 0x54, 0x64, 0x08, 0x08,
0x10, 0x10, 0x26, 0x2a, 0x4a, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44,
0x44, 0x44, 0x28, 0x18, 0x24, 0x45, 0x42, 0x42, 0x42, 0x3d, 0x00, 0x00,
0x00, 0x00, 0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x08, 0x08, 0x04, 0x00, 0x00, 0x00, 0x20, 0x10, 0x10,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x00, 0x00,
0x00, 0x00, 0x08, 0x49, 0x2a, 0x1c, 0x1c, 0x7f, 0x1c, 0x1c, 0x2a, 0x49,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x3e,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02,
0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x80, 0x80, 0x00, 0x00,
0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24,
0x24, 0x18, 0x00, 0x00, 0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42,
0x42, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x40, 0x40, 0x7e, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x02, 0x02, 0x02, 0x1c, 0x02, 0x02, 0x02, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x0c, 0x14, 0x14, 0x24, 0x24,
0x44, 0x44, 0x44, 0x7e, 0x04, 0x04, 0x00, 0x00, 0x00, 0x7e, 0x40, 0x40,
0x40, 0x40, 0x7c, 0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x40, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x7e, 0x42, 0x42, 0x42, 0x04, 0x04, 0x04,
0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42,
0x42, 0x42, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x10, 0x20, 0x00, 0x00,
0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x04,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00,
0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20,
0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x02, 0x04, 0x08, 0x08, 0x08, 0x00, 0x00,
0x08, 0x08, 0x00, 0x00, 0x00, 0x1e, 0x22, 0x41, 0x49, 0x55, 0x55, 0x55,
0x55, 0x55, 0x57, 0x4b, 0x20, 0x1f, 0x00, 0x00, 0x00, 0x18, 0x24, 0x42,
0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x7c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x3c, 0x22, 0x22, 0x22, 0x22,
0x22, 0x7c, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x42, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x42, 0x22, 0x1c, 0x00, 0x00, 0x00, 0x78, 0x24, 0x22,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x24, 0x78, 0x00, 0x00,
0x00, 0x7e, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x40,
0x40, 0x7e, 0x00, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7c,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x42,
0x40, 0x40, 0x40, 0x40, 0x4e, 0x42, 0x42, 0x42, 0x22, 0x1c, 0x00, 0x00,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x00, 0x00, 0x00, 0x1c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x00, 0x00, 0x0e, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00,
0x00, 0x42, 0x42, 0x44, 0x44, 0x48, 0x50, 0x50, 0x68, 0x48, 0x44, 0x44,
0x42, 0x42, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x41, 0x63, 0x63,
0x55, 0x55, 0x49, 0x49, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, 0x00,
0x00, 0x42, 0x42, 0x62, 0x62, 0x52, 0x52, 0x4a, 0x4a, 0x46, 0x46, 0x42,
0x42, 0x42, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x78, 0x44, 0x42,
0x42, 0x42, 0x44, 0x78, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x52, 0x4a, 0x44,
0x44, 0x3a, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7c,
0x48, 0x48, 0x44, 0x44, 0x42, 0x42, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42,
0x40, 0x40, 0x40, 0x3c, 0x02, 0x02, 0x02, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x41, 0x41, 0x41,
0x41, 0x41, 0x41, 0x41, 0x22, 0x22, 0x22, 0x14, 0x1c, 0x08, 0x00, 0x00,
0x00, 0x41, 0x41, 0x41, 0x41, 0x49, 0x49, 0x49, 0x49, 0x55, 0x55, 0x55,
0x22, 0x22, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x36, 0x14, 0x08, 0x08,
0x08, 0x14, 0x36, 0x22, 0x41, 0x41, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22,
0x22, 0x14, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x00, 0x7e, 0x02, 0x02, 0x04, 0x04, 0x08, 0x18, 0x10, 0x20, 0x20, 0x40,
0x40, 0x7e, 0x00, 0x00, 0x00, 0x1c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80,
0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
0x00, 0x1c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x1c, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00,
0x00, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x04,
0x3c, 0x44, 0x44, 0x44, 0x48, 0x36, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40,
0x40, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x3a, 0x46, 0x42,
0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x7e, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x0c, 0x12, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x46, 0x42,
0x42, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x02, 0x3c, 0x00, 0x40, 0x40, 0x40,
0x40, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x08, 0x08, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x1c, 0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x0c, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x24, 0x18, 0x00, 0x40, 0x40, 0x40,
0x40, 0x42, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00,
0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0x6d, 0x49,
0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x62, 0x42,
0x42, 0x42, 0x42, 0x42, 0x62, 0x5c, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3a, 0x46, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x32, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x40,
0x40, 0x3c, 0x02, 0x02, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10,
0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x12, 0x0c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x46, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x41,
0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x66, 0x24, 0x18, 0x24, 0x66,
0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7e, 0x02, 0x04, 0x04, 0x18, 0x20, 0x20, 0x40, 0x7e, 0x00, 0x00,
0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x08, 0x08, 0x08, 0x08,
0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x10,
0x10, 0x10, 0x10, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00, 0x00,
0x00, 0x32, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x28,
0x44, 0x82, 0x82, 0x82, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x42,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x42, 0x22, 0x1c, 0x08, 0x38,
0x00, 0x42, 0x42, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x46, 0x3a, 0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x00, 0x3c, 0x42, 0x42,
0x42, 0x7e, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x10, 0x28, 0x44,
0x00, 0x38, 0x44, 0x04, 0x3c, 0x44, 0x44, 0x44, 0x48, 0x36, 0x00, 0x00,
0x00, 0x44, 0x44, 0x00, 0x00, 0x38, 0x44, 0x04, 0x3c, 0x44, 0x44, 0x44,
0x48, 0x36, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x00, 0x38, 0x44, 0x04,
0x3c, 0x44, 0x44, 0x44, 0x48, 0x36, 0x00, 0x00, 0x00, 0x18, 0x24, 0x18,
0x00, 0x38, 0x44, 0x04, 0x3c, 0x44, 0x44, 0x44, 0x48, 0x36, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40,
0x42, 0x3c, 0x08, 0x38, 0x00, 0x18, 0x24, 0x42, 0x00, 0x3c, 0x42, 0x42,
0x42, 0x7e, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x42, 0x42, 0x00,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x7e, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x20, 0x10, 0x08, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x7e, 0x40, 0x40,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x42, 0x42, 0x00, 0x00, 0x18, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22,
0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x00,
0x00, 0x20, 0x10, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x1c, 0x00, 0x00, 0x00, 0x42, 0x42, 0x18, 0x24, 0x42, 0x42, 0x42,
0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00, 0x00, 0x18, 0x24, 0x18,
0x24, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x04, 0x08, 0x7e, 0x40, 0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x40,
0x40, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x49, 0x09,
0x39, 0x4f, 0x48, 0x48, 0x49, 0x36, 0x00, 0x00, 0x00, 0x1f, 0x28, 0x48,
0x48, 0x48, 0x48, 0x7f, 0x48, 0x48, 0x48, 0x48, 0x48, 0x4f, 0x00, 0x00,
0x00, 0x18, 0x24, 0x42, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x42, 0x42, 0x00, 0x00, 0x3c, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08,
0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x18, 0x24, 0x42, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x46, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x00, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x00, 0x00, 0x00, 0x42, 0x42, 0x00,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x02, 0x3c,
0x42, 0x42, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x42, 0x42, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x08, 0x3e, 0x49, 0x48, 0x48, 0x48, 0x48, 0x49, 0x3e, 0x08, 0x08, 0x00,
0x00, 0x0c, 0x12, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x08, 0x38, 0x49,
0x49, 0x36, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x7f, 0x08,
0x08, 0x7f, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x78, 0x44, 0x42,
0x42, 0x44, 0x78, 0x40, 0x44, 0x5f, 0x44, 0x44, 0x45, 0x42, 0x00, 0x00,
0x00, 0x06, 0x09, 0x09, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x48,
0x48, 0x30, 0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x00, 0x38, 0x44, 0x04,
0x3c, 0x44, 0x44, 0x44, 0x48, 0x36, 0x00, 0x00, 0x00, 0x04, 0x08, 0x10,
0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x00,
0x00, 0x04, 0x08, 0x10, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x00, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x00, 0x00, 0x00, 0x32, 0x4c, 0x00,
0x00, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x32, 0x4c, 0x00, 0x42, 0x62, 0x62, 0x52, 0x52, 0x4a, 0x4a, 0x46, 0x46,
0x42, 0x42, 0x00, 0x00, 0x00, 0x38, 0x48, 0x48, 0x34, 0x00, 0x7c, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48, 0x48,
0x30, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x20, 0x40, 0x42, 0x42,
0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e,
0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x30, 0x10, 0x10, 0x11, 0x3a, 0x04, 0x08, 0x16, 0x29, 0x42,
0x04, 0x08, 0x0f, 0x00, 0x00, 0x10, 0x30, 0x10, 0x10, 0x11, 0x3a, 0x04,
0x08, 0x12, 0x26, 0x4a, 0x1f, 0x02, 0x02, 0x00, 0x00, 0x00, 0x08, 0x08,
0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x24, 0x48, 0x24, 0x12, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x24, 0x12,
0x24, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x44, 0x11, 0x44,
0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44,
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
0x55, 0xaa, 0x55, 0xaa, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb,
0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xf8, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xf8, 0x08,
0xf8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0xe4, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x08,
0xf8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0xe4, 0x04, 0xe4, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x04,
0xe4, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0xe4, 0x04, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xf8, 0x08,
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0xff, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0f, 0x08, 0x0f, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x27, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x27, 0x20, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x27, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0xe7, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0x00, 0xe7, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x27, 0x20, 0x27, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0xe7, 0x00, 0xe7, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0x00, 0xff, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x0f, 0x08, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x0f, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3f, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0xff, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xff, 0x08, 0xff, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x32, 0x4a, 0x4a, 0x44, 0x44, 0x44, 0x44, 0x4a, 0x32, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x44, 0x48, 0x44, 0x42, 0x42,
0x42, 0x4c, 0x40, 0x40, 0x00, 0x7e, 0x42, 0x42, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00,
0x00, 0x7f, 0x40, 0x40, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x40,
0x40, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x48, 0x44,
0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5d, 0x40, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x4e, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x00, 0x00, 0x00, 0x7f, 0x08, 0x08, 0x1c, 0x22, 0x41, 0x41,
0x41, 0x22, 0x1c, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x00, 0x18, 0x24, 0x24,
0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x24, 0x24, 0x18, 0x00, 0x00,
0x00, 0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24,
0x24, 0x66, 0x00, 0x00, 0x00, 0x0e, 0x11, 0x08, 0x04, 0x1c, 0x22, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x02, 0x04, 0x3c, 0x4a, 0x4a, 0x52, 0x52, 0x3c, 0x20,
0x40, 0x40, 0x00, 0x00, 0x00, 0x0e, 0x10, 0x20, 0x20, 0x40, 0x40, 0x7c,
0x40, 0x40, 0x20, 0x20, 0x10, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x3e,
0x08, 0x08, 0x08, 0x08, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x10, 0x08, 0x04, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x7e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x04,
0x00, 0x7e, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x48, 0x48, 0x48, 0x30, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x4c, 0x00,
0x32, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x48, 0x48,
0x48, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x28, 0x68, 0x28, 0x18, 0x18, 0x08, 0x00, 0x00,
0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x04, 0x18, 0x20, 0x3c, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
unsigned int FM_T_437_F16_len = 4096;

345
kernel/font.h Normal file
View File

@ -0,0 +1,345 @@
unsigned char FLORI_F16[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xc3, 0x81, 0xe7, 0x81, 0xe7,
0xbd, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xff,
0xff, 0x99, 0xff, 0xbd, 0x99, 0xc3, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x36, 0x7f, 0x7f, 0x7f, 0x7f, 0x3e, 0x1c, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x3e, 0x7f, 0x3e,
0x1c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c,
0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, 0xbd,
0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x07,
0x0d, 0x19, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x81, 0x99, 0xbd, 0xff, 0x99, 0x99, 0x99, 0x99, 0x81, 0x81,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x30,
0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63,
0x7f, 0x63, 0x63, 0x63, 0x67, 0xe7, 0xe6, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xf0, 0xd8, 0xcc, 0xc6, 0xc3, 0xc6,
0xcc, 0xd8, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0f, 0x1b,
0x33, 0x63, 0xc3, 0x63, 0x33, 0x1b, 0x0f, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x3c, 0x7e, 0xff, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
0x00, 0x00, 0x33, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xdb,
0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x63, 0x30, 0x7c, 0x66, 0x33, 0x1f, 0x06, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e,
0xff, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x3c, 0x7e, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x0c, 0x0e, 0xff, 0x0e, 0x0c, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x30, 0x70, 0xff, 0x70, 0x30, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3, 0xc3, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc3, 0xc3, 0x66, 0x66,
0x3c, 0x3c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0x7f, 0x36, 0x36, 0x36, 0x7f, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x08, 0x3e, 0x6b, 0x68, 0x68, 0x3e, 0x0b, 0x0b, 0x6b, 0x3e,
0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xdb, 0x76, 0x0c, 0x18,
0x30, 0x6e, 0xdb, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
0x36, 0x3c, 0x18, 0x3b, 0x6e, 0x66, 0x6e, 0x3b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30,
0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18,
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x6b, 0x3e, 0x7f, 0x3e, 0x6b, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0xff,
0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x63, 0x63, 0x67, 0x6f, 0x7b, 0x73, 0x63, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x0c, 0x0c, 0x0c,
0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63,
0x43, 0x03, 0x0e, 0x38, 0x60, 0x60, 0x61, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x63, 0x43, 0x03, 0x1e, 0x03, 0x03, 0x03, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x33, 0x63, 0x63,
0x7f, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x61,
0x60, 0x60, 0x7e, 0x03, 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1e, 0x30, 0x60, 0x60, 0x7e, 0x63, 0x63, 0x63, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x43, 0x03, 0x03, 0x06, 0x0c,
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63,
0x63, 0x63, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x3f, 0x03, 0x03, 0x06, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x63, 0x63, 0x03, 0x0e, 0x18, 0x18, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x6f, 0x6b, 0x6b,
0x6b, 0x6e, 0x60, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33,
0x63, 0x63, 0x63, 0xff, 0x63, 0x63, 0x63, 0xe3, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x63, 0xe3, 0x63, 0x7e, 0x63, 0x63, 0x63, 0x63, 0xfe,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x63, 0x60, 0x60, 0x60,
0x60, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63,
0xe3, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0x61, 0xe0, 0x60, 0x7c, 0x60, 0x60, 0x60, 0x61, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x61, 0xe0, 0x60, 0x7c, 0x60,
0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33,
0x63, 0x60, 0x60, 0x6f, 0x63, 0x63, 0x63, 0x3f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x63, 0xe3, 0x63, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0xe3,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0e,
0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x63, 0xe3, 0x66, 0x6c, 0x78, 0x7c, 0x66, 0x63, 0x63, 0xe3,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x70, 0xe0, 0x60, 0x60, 0x60,
0x60, 0x60, 0x61, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xe7,
0xff, 0xdb, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x63, 0xf3, 0x7b, 0x6f, 0x67, 0x63, 0x63, 0x63, 0x63, 0xe3,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63,
0xe3, 0x63, 0x63, 0x7e, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1e, 0x33, 0x63, 0x63, 0x63, 0x63, 0x63, 0x7b, 0x6f, 0x3e,
0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0xe3, 0x63, 0x63, 0x7e,
0x6c, 0x66, 0x63, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33,
0x63, 0x60, 0x78, 0x1e, 0x03, 0x63, 0x63, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xd9, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0xe3, 0x63, 0x63, 0x63, 0x63,
0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0xe3,
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0xe3, 0x63, 0x3e, 0x1c, 0x3e,
0x63, 0x63, 0x63, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xc3,
0xc3, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0x63, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x61, 0x7f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30,
0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x03, 0x3f,
0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xe0,
0x60, 0x6e, 0x73, 0x63, 0x63, 0x63, 0x63, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x60, 0x60, 0x60, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x03, 0x3f, 0x63, 0x63,
0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3e, 0x63, 0x63, 0x6e, 0x78, 0x73, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1e, 0x33, 0x30, 0x30, 0x7c, 0x30, 0x30, 0x30, 0x30, 0x30,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x63, 0x63,
0x63, 0x67, 0x3b, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x60, 0xe0,
0x60, 0x6e, 0x73, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x38, 0x18, 0x18, 0x18, 0x1b, 0x0e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x06, 0x0e, 0x06,
0x06, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x60, 0xe0,
0x60, 0x66, 0x66, 0x7c, 0x78, 0x6c, 0x66, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x0e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdb, 0xdb,
0xdb, 0xdb, 0xdb, 0xdb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x6e, 0xf3, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xf3, 0x63,
0x63, 0x63, 0x63, 0x7e, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0x63, 0x63, 0x63, 0x63, 0x67, 0x3b, 0x03, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xf3, 0x63, 0x60, 0x60, 0x60, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x60,
0x3e, 0x03, 0x63, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18,
0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0xe3, 0x63, 0x63, 0x63, 0x67, 0x3b,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0xe3, 0x63,
0x63, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc3, 0xc3, 0xc3, 0xdb, 0xdb, 0xff, 0x66, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x36, 0x1c, 0x1c, 0x1c, 0x36, 0x63,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0xe3, 0x63,
0x63, 0x67, 0x3b, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3f, 0x66, 0x0c, 0x18, 0x30, 0x61, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18,
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18,
0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3b, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36,
0x63, 0x63, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33,
0x63, 0x60, 0x60, 0x60, 0x60, 0x63, 0x63, 0x3e, 0x03, 0x0e, 0x00, 0x00,
0x00, 0x00, 0x63, 0x63, 0x00, 0x63, 0xe3, 0x63, 0x63, 0x63, 0x67, 0x3b,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x3e, 0x63, 0x63,
0x7f, 0x60, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1e, 0x33,
0x00, 0x3e, 0x03, 0x3f, 0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x33, 0x33, 0x00, 0x3e, 0x03, 0x3f, 0x63, 0x63, 0x67, 0x3b,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0x06, 0x00, 0x3e, 0x03, 0x3f,
0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x1c,
0x00, 0x3e, 0x03, 0x3f, 0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63, 0x60, 0x60, 0x60, 0x63, 0x3e,
0x03, 0x0e, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x00, 0x3e, 0x63, 0x63,
0x7f, 0x60, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33,
0x00, 0x3e, 0x63, 0x63, 0x7f, 0x60, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x0c, 0x06, 0x00, 0x3e, 0x63, 0x63, 0x7f, 0x60, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x00, 0x18, 0x18, 0x18,
0x18, 0x18, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36,
0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x30, 0x18, 0x0c, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x0e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x1e, 0x33, 0x63, 0x63, 0xff,
0x63, 0x63, 0x63, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x33, 0x1e,
0x33, 0x63, 0x63, 0xff, 0x63, 0x63, 0x63, 0xe3, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x30, 0x3f, 0x61, 0xe0, 0x7c, 0x60, 0x60, 0x60, 0x61, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x1b, 0x1b,
0xfb, 0xdf, 0xd8, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x36,
0x66, 0x66, 0x66, 0xff, 0x66, 0x66, 0x66, 0xe7, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x1c, 0x36, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x00, 0x3e, 0x63, 0x63,
0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c,
0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x1c, 0x36, 0x00, 0x63, 0xe3, 0x63, 0x63, 0x63, 0x67, 0x3b,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x00, 0x63, 0xe3, 0x63,
0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63,
0x00, 0x63, 0xe3, 0x63, 0x63, 0x63, 0x3f, 0x03, 0x63, 0x3e, 0x00, 0x00,
0x00, 0x63, 0x63, 0x00, 0x1e, 0x33, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x63, 0x00, 0x63, 0xe3, 0x63, 0x63,
0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x7e, 0xc3, 0xc0, 0xc0, 0xc3, 0x7e, 0x18, 0x18, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x36, 0x30, 0x30, 0x78, 0x30, 0x30, 0x30, 0x73, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x3c, 0x18, 0xff, 0x18,
0xff, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x66,
0x66, 0x7c, 0x62, 0x66, 0x6f, 0x66, 0x66, 0x77, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0e, 0x1b, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0xd8,
0x70, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x00, 0x3e, 0x03, 0x3f,
0x63, 0x63, 0x67, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30,
0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x18, 0x30, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x63, 0xe3, 0x63,
0x63, 0x63, 0x63, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x6e,
0x00, 0x6e, 0xf3, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3b, 0x6e, 0x00, 0x63, 0xf3, 0x7b, 0x6f, 0x67, 0x63, 0x63, 0xe3,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x6c, 0x6c, 0x3c, 0x00, 0x7e, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c,
0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x3c, 0x60, 0x63, 0x63, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x60,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0xe1, 0x63, 0x66, 0x6c, 0x18, 0x36, 0x6b, 0xdb, 0x86, 0x0c,
0x1f, 0x00, 0x00, 0x00, 0x00, 0x60, 0xe1, 0x63, 0x66, 0x6c, 0x18, 0x33,
0x67, 0xcb, 0x9b, 0x1f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18,
0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x36, 0x6c, 0x36, 0x1b, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x36, 0x1b,
0x36, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x41, 0x63, 0x36,
0x14, 0x41, 0x63, 0x36, 0x14, 0x41, 0x63, 0x36, 0x14, 0x41, 0x63, 0x36,
0xdb, 0x00, 0xdb, 0x00, 0xdb, 0x00, 0xdb, 0x00, 0xdb, 0x00, 0xdb, 0x00,
0xdb, 0x00, 0xdb, 0x00, 0x00, 0x1c, 0x63, 0x14, 0x63, 0x1c, 0x00, 0x00,
0x00, 0x1c, 0x63, 0x14, 0x63, 0x1c, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x38, 0xf0, 0x00, 0xf0,
0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0e, 0xe6,
0x76, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x76, 0xe6, 0x0e, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf0, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x1c, 0x0f, 0x00, 0x0f, 0x1c, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x33, 0x38, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x38, 0x33, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36,
0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xe3,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x38, 0xf0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3b, 0x6e, 0x6c, 0x6c, 0x6e, 0x3b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x6e, 0x63, 0x63, 0x63, 0x6e,
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63, 0x63, 0x60, 0x60, 0x60,
0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xc3, 0x60, 0x30, 0x18, 0x18, 0x30, 0x60, 0xc3, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x6c,
0x6c, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x3e, 0x70, 0x70, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x6e, 0x0c, 0x0c, 0x0c, 0x0c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x7e, 0xe7, 0xc3, 0xc3,
0xe7, 0x7e, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c,
0x66, 0xc3, 0xff, 0xc3, 0xc3, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x66, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x66, 0x66, 0xe7,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x18, 0x0c, 0x3e, 0x66,
0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x7e, 0xdb, 0xdb, 0xf3, 0x7e, 0x60,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x38, 0x60, 0x60, 0x7e, 0x60,
0x60, 0x60, 0x38, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x63,
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18,
0x18, 0x18, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18,
0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0xff, 0x00, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x6e, 0x00, 0x3b,
0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c,
0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c,
0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x1c, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x78, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xd8, 0x18, 0x70, 0xc0, 0xf8, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
unsigned int FLORI_F16_len = 4096;

674
kernel/fs/fatfs/LICENSE Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

167
kernel/fs/fatfs/README.md Normal file
View File

@ -0,0 +1,167 @@
### FAT16/32 File System Library
Github: [http://github.com/ultraembedded/fat_io_lib](https://github.com/ultraembedded/fat_io_lib)
#### Intro
Designed for low memory embedded systems back in 2003, this project is a multi-purpose platform independent C code implementation of a FAT16 & FAT32 driver with read & write support.
The library provides stdio like interface functions such as fopen(), fgetc(), fputc(), fread(), fwrite() etc, allowing existing applications to be ported easily using a familiar API.
The project is aimed at applications which require file system support such as MP3 players, data loggers, etc and has a low memory footprint with customizable build options to enable it to run on platforms such as the Atmel AVR, ARM & PIC microcontrollers.
The source code is available for free under GPL license, or alternatively, with a commercial compatible license for a small donation.
This library has been used in many open source projects including;
* Aleph - Open source sound computer.
* IV:MP - Grand Theft Auto: IV multiplayer game mod.
* hxcfloppyemu - HxC Floppy Drive Emulator.
#### Features
* Standard file I/O API (fopen(), fread(), fwrite(), etc)
* FAT16/FAT32 support (read + write)
* Long filename support (optional)
* Format function (optional)
* Directory listing (optional)
* Buffering & caching for higher performance (optional)
#### API
The following file IO API is provided:
* fopen
* fclose
* fread
* fwrite
* fputc
* fputs
* fgetc
* fflush
* fgetpos
* fseek
* ftell
* feof
* remove
Just add sector read & write functions for the media/platform you are using for a complete file system!
#### Testing
Each release of the project is tested using self verifying test benches to ensure validity and to protect against regressions (not currently released).
#### Commercial
If you would like to use this code in a commercial project with a closed source compatible license, please contact me.
#### Configuration
See the following defines in src/fat_opts.h:
```
FATFS_IS_LITTLE_ENDIAN [1/0]
Which endian is your system? Set to 1 for little endian, 0 for big endian.
FATFS_MAX_LONG_FILENAME [260]
By default, 260 characters (max LFN length). Increase this to support greater path depths.
FATFS_MAX_OPEN_FILES
The more files you wish to have concurrently open, the greater this number should be.
This increases the number of FL_FILE file structures in the library, each of these is around 1K in size (assuming 512 byte sectors).
FAT_BUFFER_SECTORS
Minimum is 1, more increases performance.
This defines how many FAT sectors can be buffered per FAT_BUFFER entry.
FAT_BUFFERS
Minimum is 1, more increases performance.
This defines how many FAT buffer entries are available.
Memory usage is FAT_BUFFERS * FAT_BUFFER_SECTORS * FAT_SECTOR_SIZE
FATFS_INC_WRITE_SUPPORT
Support file write functionality.
FAT_SECTOR_SIZE
Sector size used by buffers. Most likely to be 512 bytes (standard for ATA/IDE).
FAT_PRINTF
A define that allows the File IO library to print to console/stdout.
Provide your own printf function if printf not available.
FAT_CLUSTER_CACHE_ENTRIES
Size of cluster chain cache (can be undefined if not required).
Mem used = FAT_CLUSTER_CACHE_ENTRIES * 4 * 2
Improves access speed considerably.
FATFS_INC_LFN_SUPPORT [1/0]
Enable/Disable support for long filenames.
FATFS_DIR_LIST_SUPPORT [1/0]
Include support for directory listing.
FATFS_INC_TIME_DATE_SUPPORT [1/0]
Use time/date functions provided by time.h to update creation & modification timestamps.
FATFS_INC_FORMAT_SUPPORT
Include support for formatting disks (FAT16 only).
FAT_PRINTF_NOINC_STDIO
Disable use of printf & inclusion of stdio.h
```
#### Interfacing to storage media
```
-----------------------------------------------------------------
int media_read(uint32 sector, uint8 *buffer, uint32 sector_count)
-----------------------------------------------------------------
Params:
Sector: 32-bit sector number
Buffer: Target buffer to read n sectors of data into.
Sector_count: Number of sectors to read
Return:
int, 1 = success, 0 = failure.
Description:
Application/target specific disk/media read function.
Sector number (sectors are usually 512 byte pages) to read.
-----------------------------------------------------------------
int media_write(uint32 sector, uint8 *buffer, uint32 sector_count)
-----------------------------------------------------------------
Params:
Sector: 32-bit sector number
Buffer: Target buffer to write n sectors of data from.
Sector_count: Number of sectors to write.
Return:
int, 1 = success, 0 = failure.
Description:
Application/target specific disk/media write function.
Sector number (sectors are usually 512 byte pages) to write to.
-----------------------------------------------------------------
Use the following API to attach the media IO functions to the File IO library;
fl_attach_media(media_read, media_write);
```
#### History
* v2.6.11 - Fix compilation with GCC on 64-bit machines
* v2.6.10 - Added support for FAT32 format.
* v2.6.9 - Added support for time & date handling.
* v2.6.8 - Fixed error with FSINFO sector write.
* v2.6.7 - Added fgets(). Fixed C warnings, removed dependency on some string.h functions.
* v2.6.6 - Massive read + write performance improvements.
* v2.6.5 - Bug fixes for big endian systems.
* v2.6.4 - Further bug fixes and performance improvements for write operations.
* v2.6.3 - Performance improvements, FAT16 formatting support. Various bug fixes
* v2.6 - Basic support for FAT16 added
* v2.5 - Code cleaned up. Many bugs fixed. Thread safety functions added.
* v2.x - Write support added as well as better stdio like API.
* v1.0 - Rewrite of all code to enable multiple files to be opened and provides a better file API.
* v0.1b - fopen(), fgetc(), fopenDIR() using new software stack for IDE drives and FAT32 access.
* v0.1a - First release; fopen(), fgetc() unbuffered reads.... (27/12/03)

View File

@ -0,0 +1,905 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// FAT16/32 File IO Library
// V2.6
// Ultra-Embedded.com
// Copyright 2003 - 2012
//
// Email: admin@ultra-embedded.com
//
// License: GPL
// If you would like a version with a more permissive license for use in
// closed source commercial applications please contact me for details.
//-----------------------------------------------------------------------------
//
// This file is part of FAT File IO Library.
//
// FAT File IO Library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// FAT File IO Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FAT File IO Library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include <string.h>
#include "fat_defs.h"
#include "fat_access.h"
#include "fat_table.h"
#include "fat_write.h"
#include "fat_string.h"
#include "fat_misc.h"
#include "fat_context.h"
//-----------------------------------------------------------------------------
// fatfs_init: Load FAT Parameters
//-----------------------------------------------------------------------------
int fatfs_init(struct fat_ctx *ctx, struct fatfs *fs)
{
uint8 num_of_fats;
uint16 reserved_sectors;
uint32 FATSz;
uint32 root_dir_sectors;
uint32 total_sectors;
uint32 data_sectors;
uint32 count_of_clusters;
uint8 valid_partition = 0;
fs->currentsector.address = FAT32_INVALID_CLUSTER;
fs->currentsector.dirty = 0;
fs->next_free_cluster = 0; // Invalid
fatfs_fat_init(fs);
// Make sure we have a read function (write function is optional)
if (!fs->disk_io.read_media)
return FAT_INIT_MEDIA_ACCESS_ERROR;
// MBR: Sector 0 on the disk
// NOTE: Some removeable media does not have this.
// Load MBR (LBA 0) into the 512 byte buffer
if (!fs->disk_io.read_media(ctx, 0, fs->currentsector.sector, 1))
return FAT_INIT_MEDIA_ACCESS_ERROR;
// Make Sure 0x55 and 0xAA are at end of sector
// (this should be the case regardless of the MBR or boot sector)
if (fs->currentsector.sector[SIGNATURE_POSITION] != 0x55 || fs->currentsector.sector[SIGNATURE_POSITION+1] != 0xAA)
return FAT_INIT_INVALID_SIGNATURE;
// Now check again using the access function to prove endian conversion function
if (GET_16BIT_WORD(fs->currentsector.sector, SIGNATURE_POSITION) != SIGNATURE_VALUE)
return FAT_INIT_ENDIAN_ERROR;
// Verify packed structures
if (sizeof(struct fat_dir_entry) != FAT_DIR_ENTRY_SIZE)
return FAT_INIT_STRUCT_PACKING;
// Check the partition type code
switch(fs->currentsector.sector[PARTITION1_TYPECODE_LOCATION])
{
case 0x0B:
case 0x06:
case 0x0C:
case 0x0E:
case 0x0F:
case 0x05:
valid_partition = 1;
break;
case 0x00:
valid_partition = 0;
break;
default:
if (fs->currentsector.sector[PARTITION1_TYPECODE_LOCATION] <= 0x06)
valid_partition = 1;
break;
}
// Read LBA Begin for the file system
if (valid_partition)
fs->lba_begin = GET_32BIT_WORD(fs->currentsector.sector, PARTITION1_LBA_BEGIN_LOCATION);
// Else possibly MBR less disk
else
fs->lba_begin = 0;
// Load Volume 1 table into sector buffer
// (We may already have this in the buffer if MBR less drive!)
if (!fs->disk_io.read_media(ctx, fs->lba_begin, fs->currentsector.sector, 1))
return FAT_INIT_MEDIA_ACCESS_ERROR;
// Make sure there are 512 bytes per cluster
if (GET_16BIT_WORD(fs->currentsector.sector, 0x0B) != FAT_SECTOR_SIZE)
return FAT_INIT_INVALID_SECTOR_SIZE;
// Load Parameters of FAT partition
fs->sectors_per_cluster = fs->currentsector.sector[BPB_SECPERCLUS];
reserved_sectors = GET_16BIT_WORD(fs->currentsector.sector, BPB_RSVDSECCNT);
num_of_fats = fs->currentsector.sector[BPB_NUMFATS];
fs->root_entry_count = GET_16BIT_WORD(fs->currentsector.sector, BPB_ROOTENTCNT);
if(GET_16BIT_WORD(fs->currentsector.sector, BPB_FATSZ16) != 0)
fs->fat_sectors = GET_16BIT_WORD(fs->currentsector.sector, BPB_FATSZ16);
else
fs->fat_sectors = GET_32BIT_WORD(fs->currentsector.sector, BPB_FAT32_FATSZ32);
// For FAT32 (which this may be)
fs->rootdir_first_cluster = GET_32BIT_WORD(fs->currentsector.sector, BPB_FAT32_ROOTCLUS);
fs->fs_info_sector = GET_16BIT_WORD(fs->currentsector.sector, BPB_FAT32_FSINFO);
// For FAT16 (which this may be), rootdir_first_cluster is actuall rootdir_first_sector
fs->rootdir_first_sector = reserved_sectors + (num_of_fats * fs->fat_sectors);
fs->rootdir_sectors = ((fs->root_entry_count * 32) + (FAT_SECTOR_SIZE - 1)) / FAT_SECTOR_SIZE;
// First FAT LBA address
fs->fat_begin_lba = fs->lba_begin + reserved_sectors;
// The address of the first data cluster on this volume
fs->cluster_begin_lba = fs->fat_begin_lba + (num_of_fats * fs->fat_sectors);
if (GET_16BIT_WORD(fs->currentsector.sector, 0x1FE) != 0xAA55) // This signature should be AA55
return FAT_INIT_INVALID_SIGNATURE;
// Calculate the root dir sectors
root_dir_sectors = ((GET_16BIT_WORD(fs->currentsector.sector, BPB_ROOTENTCNT) * 32) + (GET_16BIT_WORD(fs->currentsector.sector, BPB_BYTSPERSEC) - 1)) / GET_16BIT_WORD(fs->currentsector.sector, BPB_BYTSPERSEC);
if(GET_16BIT_WORD(fs->currentsector.sector, BPB_FATSZ16) != 0)
FATSz = GET_16BIT_WORD(fs->currentsector.sector, BPB_FATSZ16);
else
FATSz = GET_32BIT_WORD(fs->currentsector.sector, BPB_FAT32_FATSZ32);
if(GET_16BIT_WORD(fs->currentsector.sector, BPB_TOTSEC16) != 0)
total_sectors = GET_16BIT_WORD(fs->currentsector.sector, BPB_TOTSEC16);
else
total_sectors = GET_32BIT_WORD(fs->currentsector.sector, BPB_TOTSEC32);
data_sectors = total_sectors - (GET_16BIT_WORD(fs->currentsector.sector, BPB_RSVDSECCNT) + (fs->currentsector.sector[BPB_NUMFATS] * FATSz) + root_dir_sectors);
// Find out which version of FAT this is...
if (fs->sectors_per_cluster != 0)
{
count_of_clusters = data_sectors / fs->sectors_per_cluster;
if(count_of_clusters < 4085)
// Volume is FAT12
return FAT_INIT_WRONG_FILESYS_TYPE;
else if(count_of_clusters < 65525)
{
// Clear this FAT32 specific param
fs->rootdir_first_cluster = 0;
// Volume is FAT16
fs->fat_type = FAT_TYPE_16;
return FAT_INIT_OK;
}
else
{
// Volume is FAT32
fs->fat_type = FAT_TYPE_32;
return FAT_INIT_OK;
}
}
else
return FAT_INIT_WRONG_FILESYS_TYPE;
}
//-----------------------------------------------------------------------------
// fatfs_lba_of_cluster: This function converts a cluster number into a sector /
// LBA number.
//-----------------------------------------------------------------------------
uint32 fatfs_lba_of_cluster(struct fatfs *fs, uint32 Cluster_Number)
{
if (fs->fat_type == FAT_TYPE_16)
return (fs->cluster_begin_lba + (fs->root_entry_count * 32 / FAT_SECTOR_SIZE) + ((Cluster_Number-2) * fs->sectors_per_cluster));
else
return ((fs->cluster_begin_lba + ((Cluster_Number-2)*fs->sectors_per_cluster)));
}
//-----------------------------------------------------------------------------
// fatfs_sector_read:
//-----------------------------------------------------------------------------
int fatfs_sector_read(struct fat_ctx *ctx, struct fatfs *fs, uint32 lba, uint8 *target, uint32 count)
{
return fs->disk_io.read_media(ctx, lba, target, count);
}
//-----------------------------------------------------------------------------
// fatfs_sector_write:
//-----------------------------------------------------------------------------
int fatfs_sector_write(struct fat_ctx *ctx, struct fatfs *fs, uint32 lba, uint8 *target, uint32 count)
{
return fs->disk_io.write_media(ctx, lba, target, count);
}
//-----------------------------------------------------------------------------
// fatfs_sector_reader: From the provided startcluster and sector offset
// Returns True if success, returns False if not (including if read out of range)
//-----------------------------------------------------------------------------
int fatfs_sector_reader(struct fat_ctx *ctx, struct fatfs *fs, uint32 start_cluster, uint32 offset, uint8 *target)
{
uint32 sector_to_read = 0;
uint32 cluster_to_read = 0;
uint32 cluster_chain = 0;
uint32 i;
uint32 lba;
// FAT16 Root directory
if (fs->fat_type == FAT_TYPE_16 && start_cluster == 0)
{
if (offset < fs->rootdir_sectors)
lba = fs->lba_begin + fs->rootdir_first_sector + offset;
else
return 0;
}
// FAT16/32 Other
else
{
// Set start of cluster chain to initial value
cluster_chain = start_cluster;
// Find parameters
cluster_to_read = offset / fs->sectors_per_cluster;
sector_to_read = offset - (cluster_to_read*fs->sectors_per_cluster);
// Follow chain to find cluster to read
for (i=0; i<cluster_to_read; i++)
cluster_chain = fatfs_find_next_cluster(ctx, fs, cluster_chain);
// If end of cluster chain then return false
if (cluster_chain == FAT32_LAST_CLUSTER)
return 0;
// Calculate sector address
lba = fatfs_lba_of_cluster(fs, cluster_chain)+sector_to_read;
}
// User provided target array
if (target)
return fs->disk_io.read_media(ctx, lba, target, 1);
// Else read sector if not already loaded
else if (lba != fs->currentsector.address)
{
fs->currentsector.address = lba;
return fs->disk_io.read_media(ctx, fs->currentsector.address, fs->currentsector.sector, 1);
}
else
return 1;
}
//-----------------------------------------------------------------------------
// fatfs_read_sector: Read from the provided cluster and sector offset
// Returns True if success, returns False if not
//-----------------------------------------------------------------------------
int fatfs_read_sector(struct fat_ctx *ctx, struct fatfs *fs, uint32 cluster, uint32 sector, uint8 *target)
{
// FAT16 Root directory
if (fs->fat_type == FAT_TYPE_16 && cluster == 0)
{
uint32 lba;
// In FAT16, there are a limited amount of sectors in root dir!
if (sector < fs->rootdir_sectors)
lba = fs->lba_begin + fs->rootdir_first_sector + sector;
else
return 0;
// User target buffer passed in
if (target)
{
// Read from disk
return fs->disk_io.read_media(ctx, lba, target, 1);
}
else
{
// Calculate read address
fs->currentsector.address = lba;
// Read from disk
return fs->disk_io.read_media(ctx, fs->currentsector.address, fs->currentsector.sector, 1);
}
}
// FAT16/32 Other
else
{
// User target buffer passed in
if (target)
{
// Calculate read address
uint32 lba = fatfs_lba_of_cluster(fs, cluster) + sector;
// Read from disk
return fs->disk_io.read_media(ctx, lba, target, 1);
}
else
{
// Calculate write address
fs->currentsector.address = fatfs_lba_of_cluster(fs, cluster)+sector;
// Read from disk
return fs->disk_io.read_media(ctx, fs->currentsector.address, fs->currentsector.sector, 1);
}
}
}
//-----------------------------------------------------------------------------
// fatfs_write_sector: Write to the provided cluster and sector offset
// Returns True if success, returns False if not
//-----------------------------------------------------------------------------
#if FATFS_INC_WRITE_SUPPORT
int fatfs_write_sector(struct fat_ctx *ctx, struct fatfs *fs, uint32 cluster, uint32 sector, uint8 *target)
{
// No write access?
if (!fs->disk_io.write_media)
return 0;
// FAT16 Root directory
if (fs->fat_type == FAT_TYPE_16 && cluster == 0)
{
uint32 lba;
// In FAT16 we cannot extend the root dir!
if (sector < fs->rootdir_sectors)
lba = fs->lba_begin + fs->rootdir_first_sector + sector;
else
return 0;
// User target buffer passed in
if (target)
{
// Write to disk
return fs->disk_io.write_media(ctx, lba, target, 1);
}
else
{
// Calculate write address
fs->currentsector.address = lba;
// Write to disk
return fs->disk_io.write_media(ctx, fs->currentsector.address, fs->currentsector.sector, 1);
}
}
// FAT16/32 Other
else
{
// User target buffer passed in
if (target)
{
// Calculate write address
uint32 lba = fatfs_lba_of_cluster(fs, cluster) + sector;
// Write to disk
return fs->disk_io.write_media(ctx, lba, target, 1);
}
else
{
// Calculate write address
fs->currentsector.address = fatfs_lba_of_cluster(fs, cluster)+sector;
// Write to disk
return fs->disk_io.write_media(ctx, fs->currentsector.address, fs->currentsector.sector, 1);
}
}
}
#endif
//-----------------------------------------------------------------------------
// fatfs_show_details: Show the details about the filesystem
//-----------------------------------------------------------------------------
void fatfs_show_details(struct fatfs *fs)
{
FAT_PRINTF(("FAT details:\r\n"));
FAT_PRINTF((" Type =%s", (fs->fat_type == FAT_TYPE_32) ? "FAT32": "FAT16"));
FAT_PRINTF((" Root Dir First Cluster = %x\r\n", fs->rootdir_first_cluster));
FAT_PRINTF((" FAT Begin LBA = 0x%x\r\n",fs->fat_begin_lba));
FAT_PRINTF((" Cluster Begin LBA = 0x%x\r\n",fs->cluster_begin_lba));
FAT_PRINTF((" Sectors Per Cluster = %d\r\n", fs->sectors_per_cluster));
}
//-----------------------------------------------------------------------------
// fatfs_get_root_cluster: Get the root dir cluster
//-----------------------------------------------------------------------------
uint32 fatfs_get_root_cluster(struct fatfs *fs)
{
// NOTE: On FAT16 this will be 0 which has a special meaning...
return fs->rootdir_first_cluster;
}
//-------------------------------------------------------------
// fatfs_get_file_entry: Find the file entry for a filename
//-------------------------------------------------------------
uint32 fatfs_get_file_entry(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *name_to_find, struct fat_dir_entry *sfEntry)
{
uint8 item=0;
uint16 recordoffset = 0;
uint8 i=0;
int x=0;
char *long_filename = NULL;
char short_filename[13];
struct lfn_cache lfn;
int dotRequired = 0;
struct fat_dir_entry *directoryEntry;
fatfs_lfn_cache_init(&lfn, 1);
// Main cluster following loop
while (1)
{
// Read sector
if (fatfs_sector_reader(ctx, fs, Cluster, x++, 0)) // If sector read was successfull
{
// Analyse Sector
for (item = 0; item < FAT_DIR_ENTRIES_PER_SECTOR; item++)
{
// Create the multiplier for sector access
recordoffset = FAT_DIR_ENTRY_SIZE * item;
// Overlay directory entry over buffer
directoryEntry = (struct fat_dir_entry*)(fs->currentsector.sector+recordoffset);
#if FATFS_INC_LFN_SUPPORT
// Long File Name Text Found
if (fatfs_entry_lfn_text(directoryEntry) )
fatfs_lfn_cache_entry(&lfn, fs->currentsector.sector+recordoffset);
// If Invalid record found delete any long file name information collated
else if (fatfs_entry_lfn_invalid(directoryEntry) )
fatfs_lfn_cache_init(&lfn, 0);
// Normal SFN Entry and Long text exists
else if (fatfs_entry_lfn_exists(&lfn, directoryEntry) )
{
long_filename = fatfs_lfn_cache_get(&lfn);
// Compare names to see if they match
if (fatfs_compare_names(long_filename, name_to_find))
{
memcpy(sfEntry,directoryEntry,sizeof(struct fat_dir_entry));
return 1;
}
fatfs_lfn_cache_init(&lfn, 0);
}
else
#endif
// Normal Entry, only 8.3 Text
if (fatfs_entry_sfn_only(directoryEntry) )
{
memset(short_filename, 0, sizeof(short_filename));
// Copy name to string
for (i=0; i<8; i++)
short_filename[i] = directoryEntry->Name[i];
// Extension
dotRequired = 0;
for (i=8; i<11; i++)
{
short_filename[i+1] = directoryEntry->Name[i];
if (directoryEntry->Name[i] != ' ')
dotRequired = 1;
}
// Dot only required if extension present
if (dotRequired)
{
// If not . or .. entry
if (short_filename[0]!='.')
short_filename[8] = '.';
else
short_filename[8] = ' ';
}
else
short_filename[8] = ' ';
// Compare names to see if they match
if (fatfs_compare_names(short_filename, name_to_find))
{
memcpy(sfEntry,directoryEntry,sizeof(struct fat_dir_entry));
return 1;
}
fatfs_lfn_cache_init(&lfn, 0);
}
} // End of if
}
else
break;
} // End of while loop
return 0;
}
//-------------------------------------------------------------
// fatfs_sfn_exists: Check if a short filename exists.
// NOTE: shortname is XXXXXXXXYYY not XXXXXXXX.YYY
//-------------------------------------------------------------
#if FATFS_INC_WRITE_SUPPORT
int fatfs_sfn_exists(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *shortname)
{
uint8 item=0;
uint16 recordoffset = 0;
int x=0;
struct fat_dir_entry *directoryEntry;
// Main cluster following loop
while (1)
{
// Read sector
if (fatfs_sector_reader(ctx, fs, Cluster, x++, 0)) // If sector read was successfull
{
// Analyse Sector
for (item = 0; item < FAT_DIR_ENTRIES_PER_SECTOR; item++)
{
// Create the multiplier for sector access
recordoffset = FAT_DIR_ENTRY_SIZE * item;
// Overlay directory entry over buffer
directoryEntry = (struct fat_dir_entry*)(fs->currentsector.sector+recordoffset);
#if FATFS_INC_LFN_SUPPORT
// Long File Name Text Found
if (fatfs_entry_lfn_text(directoryEntry) )
;
// If Invalid record found delete any long file name information collated
else if (fatfs_entry_lfn_invalid(directoryEntry) )
;
else
#endif
// Normal Entry, only 8.3 Text
if (fatfs_entry_sfn_only(directoryEntry) )
{
if (strncmp((const char*)directoryEntry->Name, shortname, 11)==0)
return 1;
}
} // End of if
}
else
break;
} // End of while loop
return 0;
}
#endif
//-------------------------------------------------------------
// fatfs_update_timestamps: Update date/time details
//-------------------------------------------------------------
#if FATFS_INC_TIME_DATE_SUPPORT
int fatfs_update_timestamps(struct fat_dir_entry *directoryEntry, int create, int modify, int access)
{
time_t time_now;
struct tm * time_info;
uint16 fat_time;
uint16 fat_date;
// Get system time
time(&time_now);
// Convert to local time
time_info = localtime(&time_now);
// Convert time to FAT format
fat_time = fatfs_convert_to_fat_time(time_info->tm_hour, time_info->tm_min, time_info->tm_sec);
// Convert date to FAT format
fat_date = fatfs_convert_to_fat_date(time_info->tm_mday, time_info->tm_mon + 1, time_info->tm_year + 1900);
// Update requested fields
if (create)
{
directoryEntry->CrtTime[1] = fat_time >> 8;
directoryEntry->CrtTime[0] = fat_time >> 0;
directoryEntry->CrtDate[1] = fat_date >> 8;
directoryEntry->CrtDate[0] = fat_date >> 0;
}
if (modify)
{
directoryEntry->WrtTime[1] = fat_time >> 8;
directoryEntry->WrtTime[0] = fat_time >> 0;
directoryEntry->WrtDate[1] = fat_date >> 8;
directoryEntry->WrtDate[0] = fat_date >> 0;
}
if (access)
{
directoryEntry->LstAccDate[1] = fat_time >> 8;
directoryEntry->LstAccDate[0] = fat_time >> 0;
directoryEntry->LstAccDate[1] = fat_date >> 8;
directoryEntry->LstAccDate[0] = fat_date >> 0;
}
return 1;
}
#endif
//-------------------------------------------------------------
// fatfs_update_file_length: Find a SFN entry and update it
// NOTE: shortname is XXXXXXXXYYY not XXXXXXXX.YYY
//-------------------------------------------------------------
#if FATFS_INC_WRITE_SUPPORT
int fatfs_update_file_length(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *shortname, uint32 fileLength)
{
uint8 item=0;
uint16 recordoffset = 0;
int x=0;
struct fat_dir_entry *directoryEntry;
// No write access?
if (!fs->disk_io.write_media)
return 0;
// Main cluster following loop
while (1)
{
// Read sector
if (fatfs_sector_reader(ctx, fs, Cluster, x++, 0)) // If sector read was successfull
{
// Analyse Sector
for (item = 0; item < FAT_DIR_ENTRIES_PER_SECTOR; item++)
{
// Create the multiplier for sector access
recordoffset = FAT_DIR_ENTRY_SIZE * item;
// Overlay directory entry over buffer
directoryEntry = (struct fat_dir_entry*)(fs->currentsector.sector+recordoffset);
#if FATFS_INC_LFN_SUPPORT
// Long File Name Text Found
if (fatfs_entry_lfn_text(directoryEntry) )
;
// If Invalid record found delete any long file name information collated
else if (fatfs_entry_lfn_invalid(directoryEntry) )
;
// Normal Entry, only 8.3 Text
else
#endif
if (fatfs_entry_sfn_only(directoryEntry) )
{
if (strncmp((const char*)directoryEntry->Name, shortname, 11)==0)
{
directoryEntry->FileSize = FAT_HTONL(fileLength);
#if FATFS_INC_TIME_DATE_SUPPORT
// Update access / modify time & date
fatfs_update_timestamps(directoryEntry, 0, 1, 1);
#endif
// Update sfn entry
memcpy((uint8*)(fs->currentsector.sector+recordoffset), (uint8*)directoryEntry, sizeof(struct fat_dir_entry));
// Write sector back
return fs->disk_io.write_media(ctx, fs->currentsector.address, fs->currentsector.sector, 1);
}
}
} // End of if
}
else
break;
} // End of while loop
return 0;
}
#endif
//-------------------------------------------------------------
// fatfs_mark_file_deleted: Find a SFN entry and mark if as deleted
// NOTE: shortname is XXXXXXXXYYY not XXXXXXXX.YYY
//-------------------------------------------------------------
#if FATFS_INC_WRITE_SUPPORT
int fatfs_mark_file_deleted(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *shortname)
{
uint8 item=0;
uint16 recordoffset = 0;
int x=0;
struct fat_dir_entry *directoryEntry;
// No write access?
if (!fs->disk_io.write_media)
return 0;
// Main cluster following loop
while (1)
{
// Read sector
if (fatfs_sector_reader(ctx, fs, Cluster, x++, 0)) // If sector read was successfull
{
// Analyse Sector
for (item = 0; item < FAT_DIR_ENTRIES_PER_SECTOR; item++)
{
// Create the multiplier for sector access
recordoffset = FAT_DIR_ENTRY_SIZE * item;
// Overlay directory entry over buffer
directoryEntry = (struct fat_dir_entry*)(fs->currentsector.sector+recordoffset);
#if FATFS_INC_LFN_SUPPORT
// Long File Name Text Found
if (fatfs_entry_lfn_text(directoryEntry) )
;
// If Invalid record found delete any long file name information collated
else if (fatfs_entry_lfn_invalid(directoryEntry) )
;
// Normal Entry, only 8.3 Text
else
#endif
if (fatfs_entry_sfn_only(directoryEntry) )
{
if (strncmp((const char *)directoryEntry->Name, shortname, 11)==0)
{
// Mark as deleted
directoryEntry->Name[0] = FILE_HEADER_DELETED;
#if FATFS_INC_TIME_DATE_SUPPORT
// Update access / modify time & date
fatfs_update_timestamps(directoryEntry, 0, 1, 1);
#endif
// Update sfn entry
memcpy((uint8*)(fs->currentsector.sector+recordoffset), (uint8*)directoryEntry, sizeof(struct fat_dir_entry));
// Write sector back
return fs->disk_io.write_media(ctx, fs->currentsector.address, fs->currentsector.sector, 1);
}
}
} // End of if
}
else
break;
} // End of while loop
return 0;
}
#endif
//-----------------------------------------------------------------------------
// fatfs_list_directory_start: Initialise a directory listing procedure
//-----------------------------------------------------------------------------
#if FATFS_DIR_LIST_SUPPORT
void fatfs_list_directory_start(struct fatfs *fs, struct fs_dir_list_status *dirls, uint32 StartCluster)
{
dirls->cluster = StartCluster;
dirls->sector = 0;
dirls->offset = 0;
}
#endif
//-----------------------------------------------------------------------------
// fatfs_list_directory_next: Get the next entry in the directory.
// Returns: 1 = found, 0 = end of listing
//-----------------------------------------------------------------------------
#if FATFS_DIR_LIST_SUPPORT
int fatfs_list_directory_next(struct fat_ctx *ctx, struct fatfs *fs, struct fs_dir_list_status *dirls, struct fs_dir_ent *entry)
{
uint8 i,item;
uint16 recordoffset;
struct fat_dir_entry *directoryEntry;
char *long_filename = NULL;
char short_filename[13];
struct lfn_cache lfn;
int dotRequired = 0;
int result = 0;
// Initialise LFN cache first
fatfs_lfn_cache_init(&lfn, 0);
while (1)
{
// If data read OK
if (fatfs_sector_reader(ctx, fs, dirls->cluster, dirls->sector, 0))
{
// Maximum of 16 directory entries
for (item = dirls->offset; item < FAT_DIR_ENTRIES_PER_SECTOR; item++)
{
// Increase directory offset
recordoffset = FAT_DIR_ENTRY_SIZE * item;
// Overlay directory entry over buffer
directoryEntry = (struct fat_dir_entry*)(fs->currentsector.sector+recordoffset);
#if FATFS_INC_LFN_SUPPORT
// Long File Name Text Found
if ( fatfs_entry_lfn_text(directoryEntry) )
fatfs_lfn_cache_entry(&lfn, fs->currentsector.sector+recordoffset);
// If Invalid record found delete any long file name information collated
else if ( fatfs_entry_lfn_invalid(directoryEntry) )
fatfs_lfn_cache_init(&lfn, 0);
// Normal SFN Entry and Long text exists
else if (fatfs_entry_lfn_exists(&lfn, directoryEntry) )
{
// Get text
long_filename = fatfs_lfn_cache_get(&lfn);
strncpy(entry->filename, long_filename, FATFS_MAX_LONG_FILENAME-1);
if (fatfs_entry_is_dir(directoryEntry))
entry->is_dir = 1;
else
entry->is_dir = 0;
#if FATFS_INC_TIME_DATE_SUPPORT
// Get time / dates
entry->create_time = ((uint16)directoryEntry->CrtTime[1] << 8) | directoryEntry->CrtTime[0];
entry->create_date = ((uint16)directoryEntry->CrtDate[1] << 8) | directoryEntry->CrtDate[0];
entry->access_date = ((uint16)directoryEntry->LstAccDate[1] << 8) | directoryEntry->LstAccDate[0];
entry->write_time = ((uint16)directoryEntry->WrtTime[1] << 8) | directoryEntry->WrtTime[0];
entry->write_date = ((uint16)directoryEntry->WrtDate[1] << 8) | directoryEntry->WrtDate[0];
#endif
entry->size = FAT_HTONL(directoryEntry->FileSize);
entry->cluster = (FAT_HTONS(directoryEntry->FstClusHI)<<16) | FAT_HTONS(directoryEntry->FstClusLO);
// Next starting position
dirls->offset = item + 1;
result = 1;
return 1;
}
// Normal Entry, only 8.3 Text
else
#endif
if ( fatfs_entry_sfn_only(directoryEntry) )
{
fatfs_lfn_cache_init(&lfn, 0);
memset(short_filename, 0, sizeof(short_filename));
// Copy name to string
for (i=0; i<8; i++)
short_filename[i] = directoryEntry->Name[i];
// Extension
dotRequired = 0;
for (i=8; i<11; i++)
{
short_filename[i+1] = directoryEntry->Name[i];
if (directoryEntry->Name[i] != ' ')
dotRequired = 1;
}
// Dot only required if extension present
if (dotRequired)
{
// If not . or .. entry
if (short_filename[0]!='.')
short_filename[8] = '.';
else
short_filename[8] = ' ';
}
else
short_filename[8] = ' ';
fatfs_get_sfn_display_name(entry->filename, short_filename);
if (fatfs_entry_is_dir(directoryEntry))
entry->is_dir = 1;
else
entry->is_dir = 0;
#if FATFS_INC_TIME_DATE_SUPPORT
// Get time / dates
entry->create_time = ((uint16)directoryEntry->CrtTime[1] << 8) | directoryEntry->CrtTime[0];
entry->create_date = ((uint16)directoryEntry->CrtDate[1] << 8) | directoryEntry->CrtDate[0];
entry->access_date = ((uint16)directoryEntry->LstAccDate[1] << 8) | directoryEntry->LstAccDate[0];
entry->write_time = ((uint16)directoryEntry->WrtTime[1] << 8) | directoryEntry->WrtTime[0];
entry->write_date = ((uint16)directoryEntry->WrtDate[1] << 8) | directoryEntry->WrtDate[0];
#endif
entry->size = FAT_HTONL(directoryEntry->FileSize);
entry->cluster = (FAT_HTONS(directoryEntry->FstClusHI)<<16) | FAT_HTONS(directoryEntry->FstClusLO);
// Next starting position
dirls->offset = item + 1;
result = 1;
return 1;
}
}// end of for
// If reached end of the dir move onto next sector
dirls->sector++;
dirls->offset = 0;
}
else
break;
}
return result;
}
#endif

View File

@ -0,0 +1,135 @@
#ifndef __FAT_ACCESS_H__
#define __FAT_ACCESS_H__
#include "fat_defs.h"
#include "fat_opts.h"
struct fat_ctx;
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#define FAT_INIT_OK 0
#define FAT_INIT_MEDIA_ACCESS_ERROR (-1)
#define FAT_INIT_INVALID_SECTOR_SIZE (-2)
#define FAT_INIT_INVALID_SIGNATURE (-3)
#define FAT_INIT_ENDIAN_ERROR (-4)
#define FAT_INIT_WRONG_FILESYS_TYPE (-5)
#define FAT_INIT_WRONG_PARTITION_TYPE (-6)
#define FAT_INIT_STRUCT_PACKING (-7)
#define FAT_DIR_ENTRIES_PER_SECTOR (FAT_SECTOR_SIZE / FAT_DIR_ENTRY_SIZE)
//-----------------------------------------------------------------------------
// Function Pointers
//-----------------------------------------------------------------------------
typedef int (*fn_diskio_read) (struct fat_ctx *ctx, uint32 sector, uint8 *buffer, uint32 sector_count);
typedef int (*fn_diskio_write)(struct fat_ctx *ctx, uint32 sector, uint8 *buffer, uint32 sector_count);
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct disk_if
{
// User supplied function pointers for disk IO
fn_diskio_read read_media;
fn_diskio_write write_media;
};
// Forward declaration
struct fat_buffer;
struct fat_buffer
{
uint8 sector[FAT_SECTOR_SIZE * FAT_BUFFER_SECTORS];
uint32 address;
int dirty;
uint8 * ptr;
// Next in chain of sector buffers
struct fat_buffer *next;
};
typedef enum eFatType
{
FAT_TYPE_16,
FAT_TYPE_32
} tFatType;
struct fatfs
{
// Filesystem globals
uint8 sectors_per_cluster;
uint32 cluster_begin_lba;
uint32 rootdir_first_cluster;
uint32 rootdir_first_sector;
uint32 rootdir_sectors;
uint32 fat_begin_lba;
uint16 fs_info_sector;
uint32 lba_begin;
uint32 fat_sectors;
uint32 next_free_cluster;
uint16 root_entry_count;
uint16 reserved_sectors;
uint8 num_of_fats;
tFatType fat_type;
// Disk/Media API
struct disk_if disk_io;
// [Optional] Thread Safety
void (*fl_lock)(void);
void (*fl_unlock)(void);
// Working buffer
struct fat_buffer currentsector;
// FAT Buffer
struct fat_buffer *fat_buffer_head;
struct fat_buffer fat_buffers[FAT_BUFFERS];
};
struct fs_dir_list_status
{
uint32 sector;
uint32 cluster;
uint8 offset;
};
struct fs_dir_ent
{
char filename[FATFS_MAX_LONG_FILENAME];
uint8 is_dir;
uint32 cluster;
uint32 size;
#if FATFS_INC_TIME_DATE_SUPPORT
uint16 access_date;
uint16 write_time;
uint16 write_date;
uint16 create_date;
uint16 create_time;
#endif
};
//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
int fatfs_init(struct fat_ctx *ctx, struct fatfs *fs);
uint32 fatfs_lba_of_cluster(struct fatfs *fs, uint32 Cluster_Number);
int fatfs_sector_reader(struct fat_ctx *ctx, struct fatfs *fs, uint32 Startcluster, uint32 offset, uint8 *target);
int fatfs_sector_read(struct fat_ctx *ctx, struct fatfs *fs, uint32 lba, uint8 *target, uint32 count);
int fatfs_sector_write(struct fat_ctx *ctx, struct fatfs *fs, uint32 lba, uint8 *target, uint32 count);
int fatfs_read_sector(struct fat_ctx *ctx, struct fatfs *fs, uint32 cluster, uint32 sector, uint8 *target);
int fatfs_write_sector(struct fat_ctx *ctx, struct fatfs *fs, uint32 cluster, uint32 sector, uint8 *target);
void fatfs_show_details(struct fatfs *fs);
uint32 fatfs_get_root_cluster(struct fatfs *fs);
uint32 fatfs_get_file_entry(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *nametofind, struct fat_dir_entry *sfEntry);
int fatfs_sfn_exists(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *shortname);
int fatfs_update_file_length(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *shortname, uint32 fileLength);
int fatfs_mark_file_deleted(struct fat_ctx *ctx, struct fatfs *fs, uint32 Cluster, char *shortname);
void fatfs_list_directory_start(struct fatfs *fs, struct fs_dir_list_status *dirls, uint32 StartCluster);
int fatfs_list_directory_next(struct fat_ctx *ctx, struct fatfs *fs, struct fs_dir_list_status *dirls, struct fs_dir_ent *entry);
int fatfs_update_timestamps(struct fat_dir_entry *directoryEntry, int create, int modify, int access);
#endif

View File

@ -0,0 +1,91 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// FAT16/32 File IO Library
// V2.6
// Ultra-Embedded.com
// Copyright 2003 - 2012
//
// Email: admin@ultra-embedded.com
//
// License: GPL
// If you would like a version with a more permissive license for use in
// closed source commercial applications please contact me for details.
//-----------------------------------------------------------------------------
//
// This file is part of FAT File IO Library.
//
// FAT File IO Library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// FAT File IO Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FAT File IO Library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#include <string.h>
#include "fat_cache.h"
// Per file cluster chain caching used to improve performance.
// This does not have to be enabled for architectures with low
// memory space.
//-----------------------------------------------------------------------------
// fatfs_cache_init:
//-----------------------------------------------------------------------------
int fatfs_cache_init(struct fatfs *fs, FL_FILE *file)
{
#ifdef FAT_CLUSTER_CACHE_ENTRIES
int i;
for (i=0;i<FAT_CLUSTER_CACHE_ENTRIES;i++)
{
file->cluster_cache_idx[i] = 0xFFFFFFFF; // Not used
file->cluster_cache_data[i] = 0;
}
#endif
return 1;
}
//-----------------------------------------------------------------------------
// fatfs_cache_get_next_cluster:
//-----------------------------------------------------------------------------
int fatfs_cache_get_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 *pNextCluster)
{
#ifdef FAT_CLUSTER_CACHE_ENTRIES
uint32 slot = clusterIdx % FAT_CLUSTER_CACHE_ENTRIES;
if (file->cluster_cache_idx[slot] == clusterIdx)
{
*pNextCluster = file->cluster_cache_data[slot];
return 1;
}
#endif
return 0;
}
//-----------------------------------------------------------------------------
// fatfs_cache_set_next_cluster:
//-----------------------------------------------------------------------------
int fatfs_cache_set_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 nextCluster)
{
#ifdef FAT_CLUSTER_CACHE_ENTRIES
uint32 slot = clusterIdx % FAT_CLUSTER_CACHE_ENTRIES;
if (file->cluster_cache_idx[slot] == clusterIdx)
file->cluster_cache_data[slot] = nextCluster;
else
{
file->cluster_cache_idx[slot] = clusterIdx;
file->cluster_cache_data[slot] = nextCluster;
}
#endif
return 1;
}

View File

@ -0,0 +1,13 @@
#ifndef __FAT_CACHE_H__
#define __FAT_CACHE_H__
#include "fat_filelib.h"
//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
int fatfs_cache_init(struct fatfs *fs, FL_FILE *file);
int fatfs_cache_get_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 *pNextCluster);
int fatfs_cache_set_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 nextCluster);
#endif

View File

@ -0,0 +1,17 @@
#ifndef FAT_CONTEXT_H_
#define FAT_CONTEXT_H_
#include "fat_defs.h"
#include "fat_filelib.h"
struct fat_ctx {
FL_FILE _files[FATFS_MAX_OPEN_FILES];
int _filelib_init;
int _filelib_valid;
struct fatfs _fs;
struct fat_list _open_file_list;
struct fat_list _free_file_list;
void *extra;
};
#endif // FAT_CONTEXT_H_

128
kernel/fs/fatfs/fat_defs.h Normal file
View File

@ -0,0 +1,128 @@
#ifndef __FAT_DEFS_H__
#define __FAT_DEFS_H__
#include "fat_opts.h"
#include "fat_types.h"
//-----------------------------------------------------------------------------
// FAT32 Offsets
// Name Offset
//-----------------------------------------------------------------------------
// Boot Sector
#define BS_JMPBOOT 0 // Length = 3
#define BS_OEMNAME 3 // Length = 8
#define BPB_BYTSPERSEC 11 // Length = 2
#define BPB_SECPERCLUS 13 // Length = 1
#define BPB_RSVDSECCNT 14 // Length = 2
#define BPB_NUMFATS 16 // Length = 1
#define BPB_ROOTENTCNT 17 // Length = 2
#define BPB_TOTSEC16 19 // Length = 2
#define BPB_MEDIA 21 // Length = 1
#define BPB_FATSZ16 22 // Length = 2
#define BPB_SECPERTRK 24 // Length = 2
#define BPB_NUMHEADS 26 // Length = 2
#define BPB_HIDDSEC 28 // Length = 4
#define BPB_TOTSEC32 32 // Length = 4
// FAT 12/16
#define BS_FAT_DRVNUM 36 // Length = 1
#define BS_FAT_BOOTSIG 38 // Length = 1
#define BS_FAT_VOLID 39 // Length = 4
#define BS_FAT_VOLLAB 43 // Length = 11
#define BS_FAT_FILSYSTYPE 54 // Length = 8
// FAT 32
#define BPB_FAT32_FATSZ32 36 // Length = 4
#define BPB_FAT32_EXTFLAGS 40 // Length = 2
#define BPB_FAT32_FSVER 42 // Length = 2
#define BPB_FAT32_ROOTCLUS 44 // Length = 4
#define BPB_FAT32_FSINFO 48 // Length = 2
#define BPB_FAT32_BKBOOTSEC 50 // Length = 2
#define BS_FAT32_DRVNUM 64 // Length = 1
#define BS_FAT32_BOOTSIG 66 // Length = 1
#define BS_FAT32_VOLID 67 // Length = 4
#define BS_FAT32_VOLLAB 71 // Length = 11
#define BS_FAT32_FILSYSTYPE 82 // Length = 8
//-----------------------------------------------------------------------------
// FAT Types
//-----------------------------------------------------------------------------
#define FAT_TYPE_FAT12 1
#define FAT_TYPE_FAT16 2
#define FAT_TYPE_FAT32 3
//-----------------------------------------------------------------------------
// FAT32 Specific Statics
//-----------------------------------------------------------------------------
#define SIGNATURE_POSITION 510
#define SIGNATURE_VALUE 0xAA55
#define PARTITION1_TYPECODE_LOCATION 450
#define FAT32_TYPECODE1 0x0B
#define FAT32_TYPECODE2 0x0C
#define PARTITION1_LBA_BEGIN_LOCATION 454
#define PARTITION1_SIZE_LOCATION 458
#define FAT_DIR_ENTRY_SIZE 32
#define FAT_SFN_SIZE_FULL 11
#define FAT_SFN_SIZE_PARTIAL 8
//-----------------------------------------------------------------------------
// FAT32 File Attributes and Types
//-----------------------------------------------------------------------------
#define FILE_ATTR_READ_ONLY 0x01
#define FILE_ATTR_HIDDEN 0x02
#define FILE_ATTR_SYSTEM 0x04
#define FILE_ATTR_SYSHID 0x06
#define FILE_ATTR_VOLUME_ID 0x08
#define FILE_ATTR_DIRECTORY 0x10
#define FILE_ATTR_ARCHIVE 0x20
#define FILE_ATTR_LFN_TEXT 0x0F
#define FILE_HEADER_BLANK 0x00
#define FILE_HEADER_DELETED 0xE5
#define FILE_TYPE_DIR 0x10
#define FILE_TYPE_FILE 0x20
//-----------------------------------------------------------------------------
// Time / Date details
//-----------------------------------------------------------------------------
#define FAT_TIME_HOURS_SHIFT 11
#define FAT_TIME_HOURS_MASK 0x1F
#define FAT_TIME_MINUTES_SHIFT 5
#define FAT_TIME_MINUTES_MASK 0x3F
#define FAT_TIME_SECONDS_SHIFT 0
#define FAT_TIME_SECONDS_MASK 0x1F
#define FAT_TIME_SECONDS_SCALE 2
#define FAT_DATE_YEAR_SHIFT 9
#define FAT_DATE_YEAR_MASK 0x7F
#define FAT_DATE_MONTH_SHIFT 5
#define FAT_DATE_MONTH_MASK 0xF
#define FAT_DATE_DAY_SHIFT 0
#define FAT_DATE_DAY_MASK 0x1F
#define FAT_DATE_YEAR_OFFSET 1980
//-----------------------------------------------------------------------------
// Other Defines
//-----------------------------------------------------------------------------
#define FAT32_LAST_CLUSTER 0xFFFFFFFF
#define FAT32_INVALID_CLUSTER 0xFFFFFFFF
STRUCT_PACK_BEGIN
struct fat_dir_entry STRUCT_PACK
{
uint8 Name[11];
uint8 Attr;
uint8 NTRes;
uint8 CrtTimeTenth;
uint8 CrtTime[2];
uint8 CrtDate[2];
uint8 LstAccDate[2];
uint16 FstClusHI;
uint8 WrtTime[2];
uint8 WrtDate[2];
uint16 FstClusLO;
uint32 FileSize;
} STRUCT_PACKED;
STRUCT_PACK_END
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,148 @@
#ifndef __FAT_FILELIB_H__
#define __FAT_FILELIB_H__
#include "fat_opts.h"
#include "fat_access.h"
#include "fat_list.h"
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef EOF
#define EOF (-1)
#endif
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct sFL_FILE;
struct fat_ctx;
struct cluster_lookup
{
uint32 ClusterIdx;
uint32 CurrentCluster;
};
typedef struct sFL_FILE
{
uint32 parentcluster;
uint32 startcluster;
uint32 bytenum;
uint32 filelength;
int filelength_changed;
char path[FATFS_MAX_LONG_FILENAME];
char filename[FATFS_MAX_LONG_FILENAME];
uint8 shortfilename[11];
#ifdef FAT_CLUSTER_CACHE_ENTRIES
uint32 cluster_cache_idx[FAT_CLUSTER_CACHE_ENTRIES];
uint32 cluster_cache_data[FAT_CLUSTER_CACHE_ENTRIES];
#endif
// Cluster Lookup
struct cluster_lookup last_fat_lookup;
// Read/Write sector buffer
uint8 file_data_sector[FAT_SECTOR_SIZE];
uint32 file_data_address;
int file_data_dirty;
// File fopen flags
uint8 flags;
#define FILE_READ (1 << 0)
#define FILE_WRITE (1 << 1)
#define FILE_APPEND (1 << 2)
#define FILE_BINARY (1 << 3)
#define FILE_ERASE (1 << 4)
#define FILE_CREATE (1 << 5)
struct fat_node list_node;
} FL_FILE;
//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
// External
void fl_init(struct fat_ctx *ctx);
void fl_attach_locks(struct fat_ctx *ctx, void (*lock)(void), void (*unlock)(void));
int fl_attach_media(struct fat_ctx *ctx, fn_diskio_read rd, fn_diskio_write wr);
void fl_shutdown(struct fat_ctx *ctx);
// Standard API
void* fl_fopen(struct fat_ctx *ctx, const char *path, const char *modifiers);
void fl_fclose(struct fat_ctx *ctx, void *file);
int fl_fflush(struct fat_ctx *ctx, void *file);
int fl_fgetc(struct fat_ctx *ctx, void *file);
char * fl_fgets(struct fat_ctx *ctx, char *s, int n, void *f);
int fl_fputc(struct fat_ctx *ctx, int c, void *file);
int fl_fputs(struct fat_ctx *ctx, const char * str, void *file);
int fl_fwrite(struct fat_ctx *ctx, const void * data, int size, int count, void *file );
int fl_fread(struct fat_ctx *ctx, void * data, int size, int count, void *file );
int fl_fseek(struct fat_ctx *ctx, void *file , long offset , int origin );
int fl_fgetpos(struct fat_ctx *ctx, void *file , uint32 * position);
long fl_ftell(struct fat_ctx *ctx, void *f);
int fl_feof(struct fat_ctx *ctx, void *f);
int fl_remove(struct fat_ctx *ctx, const char * filename);
// Equivelant dirent.h
typedef struct fs_dir_list_status FL_DIR;
typedef struct fs_dir_ent fl_dirent;
FL_DIR* fl_opendir(struct fat_ctx *ctx, const char* path, FL_DIR *dir);
int fl_readdir(struct fat_ctx *ctx, FL_DIR *dirls, fl_dirent *entry);
int fl_closedir(struct fat_ctx *ctx, FL_DIR* dir);
// Extensions
void fl_listdirectory(struct fat_ctx *ctx, const char *path);
int fl_createdirectory(struct fat_ctx *ctx, const char *path);
int fl_is_dir(struct fat_ctx *ctx, const char *path);
int fl_format(struct fat_ctx *ctx, uint32 volume_sectors, const char *name);
// Test hooks
#ifdef FATFS_INC_TEST_HOOKS
struct fatfs* fl_get_fs(struct fat_ctx *ctx);
#endif
//-----------------------------------------------------------------------------
// Stdio file I/O names
//-----------------------------------------------------------------------------
#ifdef USE_FILELIB_STDIO_COMPAT_NAMES
#define FILE FL_FILE
#define fopen(a,b) fl_fopen(a, b)
#define fclose(a) fl_fclose(a)
#define fflush(a) fl_fflush(a)
#define fgetc(a) fl_fgetc(a)
#define fgets(a,b,c) fl_fgets(a, b, c)
#define fputc(a,b) fl_fputc(a, b)
#define fputs(a,b) fl_fputs(a, b)
#define fwrite(a,b,c,d) fl_fwrite(a, b, c, d)
#define fread(a,b,c,d) fl_fread(a, b, c, d)
#define fseek(a,b,c) fl_fseek(a, b, c)
#define fgetpos(a,b) fl_fgetpos(a, b)
#define ftell(a) fl_ftell(a)
#define feof(a) fl_feof(a)
#define remove(a) fl_remove(a)
#define mkdir(a) fl_createdirectory(a)
#define rmdir(a) 0
#endif
#endif

Some files were not shown because too many files have changed in this diff Show More