├── .github ├── ISSUE_TEMPLATE.txt ├── PULL_REQUEST_TEMPLATE.txt └── workflows │ ├── build_cygwin.yml │ └── build_linux.yml ├── .gitignore ├── .gitmodules ├── AUTHORS ├── Android.bp ├── COPYING ├── ChangeLog ├── LICENSE ├── LICENSES ├── Apache-2.0 └── GPL-2.0 ├── METADATA ├── MODULE_LICENSE_GPL ├── Makefile ├── Makefile.am ├── OWNERS ├── README ├── README.md ├── VERSION ├── asprintf.h ├── autogen.sh ├── configure.ac ├── cygprefix.h ├── docs ├── INSTALL.md ├── PERFORMANCE.md └── compress-hints.example ├── dump ├── Makefile.am └── main.c ├── fsck ├── Makefile.am └── main.c ├── fuse ├── Makefile.am ├── macosx.h └── main.c ├── include ├── erofs │ ├── blobchunk.h │ ├── block_list.h │ ├── cache.h │ ├── compress.h │ ├── compress_hints.h │ ├── config.h │ ├── decompress.h │ ├── dedupe.h │ ├── defs.h │ ├── dir.h │ ├── err.h │ ├── exclude.h │ ├── flex-array.h │ ├── fragments.h │ ├── hashmap.h │ ├── hashtable.h │ ├── inode.h │ ├── internal.h │ ├── io.h │ ├── list.h │ ├── print.h │ ├── rebuild.h │ ├── tar.h │ ├── trace.h │ ├── xattr.h │ └── xxhash.h └── erofs_fs.h ├── lib ├── Makefile.am ├── blobchunk.c ├── block_list.c ├── cache.c ├── compress.c ├── compress_hints.c ├── compressor.c ├── compressor.h ├── compressor_deflate.c ├── compressor_libdeflate.c ├── compressor_liblzma.c ├── compressor_lz4.c ├── compressor_lz4hc.c ├── config.c ├── data.c ├── decompress.c ├── dedupe.c ├── dir.c ├── exclude.c ├── fragments.c ├── hashmap.c ├── inode.c ├── io.c ├── kite_deflate.c ├── liberofs_private.h ├── liberofs_uuid.h ├── namei.c ├── rb_tree.c ├── rb_tree.h ├── rebuild.c ├── rolling_hash.h ├── sha256.c ├── sha256.h ├── super.c ├── tar.c ├── uuid.c ├── uuid_unparse.c ├── xattr.c ├── xxhash.c └── zmap.c ├── libcutils ├── Android.bp ├── KernelLibcutilsTest.xml ├── MODULE_LICENSE_APACHE2 ├── Makefile ├── NOTICE ├── OWNERS ├── TEST_MAPPING ├── android_get_control_env.h ├── android_get_control_file.cpp ├── android_get_control_file_test.cpp ├── android_get_control_socket_test.cpp ├── android_reboot.cpp ├── arch-x86 │ └── cache.h ├── arch-x86_64 │ └── cache.h ├── ashmem-dev.cpp ├── ashmem-host.cpp ├── ashmem_test.cpp ├── canned_fs_config.cpp ├── config_utils.cpp ├── fs.cpp ├── fs_config.cpp ├── fs_config.h ├── fs_config_test.cpp ├── hashmap.cpp ├── include │ ├── cutils │ │ ├── android_get_control_file.h │ │ ├── android_reboot.h │ │ ├── ashmem.h │ │ ├── atomic.h │ │ ├── bitops.h │ │ ├── compiler.h │ │ ├── config_utils.h │ │ ├── fs.h │ │ ├── hashmap.h │ │ ├── iosched_policy.h │ │ ├── klog.h │ │ ├── list.h │ │ ├── log.h │ │ ├── memory.h │ │ ├── misc.h │ │ ├── multiuser.h │ │ ├── native_handle.h │ │ ├── partition_utils.h │ │ ├── properties.h │ │ ├── qtaguid.h │ │ ├── record_stream.h │ │ ├── sched_policy.h │ │ ├── sockets.h │ │ ├── str_parms.h │ │ ├── threads.h │ │ ├── trace.h │ │ └── uevent.h │ ├── private │ │ ├── android_filesystem_capability.h │ │ ├── android_filesystem_config.h │ │ ├── android_projectid_config.h │ │ ├── canned_fs_config.h │ │ └── fs_config.h │ └── utils │ │ ├── AndroidThreads.h │ │ ├── Atomic.h │ │ ├── BitSet.h │ │ ├── ByteOrder.h │ │ ├── CallStack.h │ │ ├── Compat.h │ │ ├── Condition.h │ │ ├── Debug.h │ │ ├── Endian.h │ │ ├── Errors.h │ │ ├── ErrorsMacros.h │ │ ├── FastStrcmp.h │ │ ├── FileMap.h │ │ ├── Flattenable.h │ │ ├── Functor.h │ │ ├── JenkinsHash.h │ │ ├── KeyedVector.h │ │ ├── LightRefBase.h │ │ ├── List.h │ │ ├── Log.h │ │ ├── Looper.h │ │ ├── LruCache.h │ │ ├── Mutex.h │ │ ├── NativeHandle.h │ │ ├── Printer.h │ │ ├── ProcessCallStack.h │ │ ├── RWLock.h │ │ ├── RefBase.h │ │ ├── Singleton.h │ │ ├── SortedVector.h │ │ ├── StopWatch.h │ │ ├── String16.h │ │ ├── String8.h │ │ ├── StrongPointer.h │ │ ├── SystemClock.h │ │ ├── Thread.h │ │ ├── ThreadDefs.h │ │ ├── Timers.h │ │ ├── Tokenizer.h │ │ ├── Trace.h │ │ ├── TypeHelpers.h │ │ ├── Unicode.h │ │ ├── Vector.h │ │ ├── VectorImpl.h │ │ ├── misc.h │ │ └── threads.h ├── include_outside_system │ └── cutils │ │ ├── bitops.h │ │ ├── fs.h │ │ └── misc.h ├── iosched_policy.cpp ├── klog.cpp ├── load_file.cpp ├── multiuser.cpp ├── multiuser_test.cpp ├── native_handle.cpp ├── native_handle_test.cpp ├── partition_utils.cpp ├── properties.cpp ├── properties_test.cpp ├── qtaguid.cpp ├── record_stream.cpp ├── sched_policy_test.cpp ├── socket_inaddr_any_server_unix.cpp ├── socket_inaddr_any_server_windows.cpp ├── socket_local_client_unix.cpp ├── socket_local_server_unix.cpp ├── socket_local_unix.h ├── socket_network_client_unix.cpp ├── socket_network_client_windows.cpp ├── sockets.cpp ├── sockets_test.cpp ├── sockets_unix.cpp ├── sockets_windows.cpp ├── str_parms.cpp ├── str_parms_test.cpp ├── strlcpy.c ├── threads.cpp ├── trace-container.cpp ├── trace-dev.cpp ├── trace-dev.inc ├── trace-dev_test.cpp ├── trace-host.cpp └── uevent.cpp ├── libext2_uuid ├── Android.bp ├── COPYING ├── Makefile ├── clear.c ├── compare.c ├── config.h ├── configure.in ├── copy.c ├── gen_uuid.c ├── gen_uuid_nt.c ├── isnull.c ├── pack.c ├── parse.c ├── tst_uuid.c ├── unpack.c ├── unparse.c ├── uuid.3.in ├── uuid.h ├── uuid.h.in ├── uuid.pc.in ├── uuidP.h ├── uuid_clear.3.in ├── uuid_compare.3.in ├── uuid_copy.3.in ├── uuid_generate.3.in ├── uuid_is_null.3.in ├── uuid_parse.3.in ├── uuid_time.3.in ├── uuid_time.c ├── uuid_types.h ├── uuid_types.h.in ├── uuid_unparse.3.in └── uuidd.h ├── libselinux ├── Android.mk ├── MODULE_LICENSE_PUBLIC_DOMAIN ├── Makefile ├── NOTICE ├── README.android ├── include │ ├── asprintf.h │ └── selinux │ │ ├── android.h │ │ ├── avc.h │ │ ├── context.h │ │ ├── label.h │ │ └── selinux.h ├── mman.c ├── mman.h ├── src │ ├── android.c │ ├── avc.c │ ├── avc_internal.c │ ├── avc_internal.h │ ├── avc_sidtab.c │ ├── avc_sidtab.h │ ├── booleans.c │ ├── callbacks.c │ ├── callbacks.h │ ├── canonicalize_context.c │ ├── checkAccess.c │ ├── check_context.c │ ├── compute_av.c │ ├── compute_create.c │ ├── context.c │ ├── context_internal.h │ ├── deny_unknown.c │ ├── disable.c │ ├── dso.h │ ├── enabled.c │ ├── fgetfilecon.c │ ├── freecon.c │ ├── fsetfilecon.c │ ├── get_initial_context.c │ ├── getenforce.c │ ├── getfilecon.c │ ├── getpeercon.c │ ├── init.c │ ├── label.c │ ├── label_android_property.c │ ├── label_file.c │ ├── label_file.h │ ├── label_internal.h │ ├── label_support.c │ ├── lgetfilecon.c │ ├── load_policy.c │ ├── lsetfilecon.c │ ├── mapping.c │ ├── mapping.h │ ├── policy.h │ ├── policyvers.c │ ├── procattr.c │ ├── selinux_internal.h │ ├── selinux_netlink.h │ ├── sestatus.c │ ├── setenforce.c │ ├── setfilecon.c │ └── stringrep.c └── utils │ └── sefcontext_compile.c ├── man ├── Makefile.am ├── dump.erofs.1 ├── erofsfuse.1 ├── fsck.erofs.1 └── mkfs.erofs.1 ├── mkfs ├── Makefile.am └── main.c ├── patch ├── libbase │ └── 0001-Patch-on-cygwin.patch └── logging │ ├── 0001-Patch-liblog-on-cygwin.patch │ ├── 0002-Patch-liblog-on-cygwin-add-Makefile.patch │ └── 0003-Fix-logger_write.cpp.patch ├── scripts ├── cyg-get-version-number ├── get-version-number └── patch-all └── winfsp ├── install.sh ├── uninstall.sh ├── x64 └── usr │ ├── bin │ └── cygfuse-2.8.dll │ ├── include │ └── fuse │ │ ├── fuse.h │ │ ├── fuse_common.h │ │ ├── fuse_opt.h │ │ └── winfsp_fuse.h │ └── lib │ ├── libfuse-2.8.dll.a │ ├── libfuse.dll.a │ └── pkgconfig │ └── fuse.pc └── x86 └── usr ├── bin └── cygfuse-2.8.dll ├── include └── fuse │ ├── fuse.h │ ├── fuse_common.h │ ├── fuse_opt.h │ └── winfsp_fuse.h └── lib ├── libfuse-2.8.dll.a ├── libfuse.dll.a └── pkgconfig └── fuse.pc /.github/ISSUE_TEMPLATE.txt: -------------------------------------------------------------------------------- 1 | Please **do not** send pull-requests or open new issues on Github. 2 | 3 | Besides, the current erofs-utils repo is: 4 | git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git 5 | 6 | Github is not _the place_ for EROFS development, and some mirrors 7 | are actually unofficial and not frequently monitored. 8 | 9 | * Send bug reports and/or feedback to: linux-erofs@lists.ozlabs.org 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.txt: -------------------------------------------------------------------------------- 1 | Please **do not** send pull-requests or open new issues on Github. 2 | 3 | Besides, the current erofs-utils repo is: 4 | git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git 5 | 6 | Github is not _the place_ for EROFS development, and some mirrors 7 | are actually unofficial and not frequently monitored. 8 | 9 | * Send bug reports and/or feedback to: linux-erofs@lists.ozlabs.org 10 | -------------------------------------------------------------------------------- /.github/workflows/build_linux.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow that is manually triggered 2 | 3 | name: build_linux 4 | 5 | on: 6 | workflow_dispatch: 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | 15 | - name: Setup Python2 16 | uses: actions/setup-python@v3.1.2 17 | with: 18 | python-version: "2.7" 19 | 20 | - name: Setup Python3 21 | uses: actions/setup-python@v3.1.2 22 | with: 23 | python-version: "3.8" 24 | 25 | - name: Setup environment 26 | run: | 27 | sudo apt-get update 28 | sudo apt-get install -y bc bison build-essential ccache curl flex g++-multilib gcc-multilib clang llvm git gnupg gperf autopoint libtool gettext perl m4 po4a libpcre++-dev imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev autoconf 29 | 30 | - name: Clone repo 31 | run: | 32 | git clone --recurse-submodules https://github.com/affggh/erofs-utils_cygwin.git erofs 33 | git clone https://github.com/sekaiacg/erofs-utils erofs/extract 34 | git clone https://github.com/xz-mirror/xz xz 35 | 36 | - name: Install xz 37 | run: | 38 | cd $GITHUB_WORKSPACE/xz 39 | ./autogen.sh 40 | ./configure 41 | make -j$(nproc --all) && sudo make install 42 | 43 | - name: Patch & Build 44 | run: | 45 | cd $GITHUB_WORKSPACE/erofs 46 | echo "EROFS_VERSION=$(sed -n '1p' VERSION | tr -d '\n')" >> $GITHUB_ENV 47 | ./scripts/patch-all 48 | make -j$(nproc --all) 49 | ls -al out/** 50 | 51 | - name: Compress out 52 | run: | 53 | cd $GITHUB_WORKSPACE/erofs 54 | 7za a -tZIP erofs-utils_linux_x86_64.zip bin/* 55 | - name: Upload output to GH-Release 56 | uses: ncipollo/release-action@v1.8.6 57 | with: 58 | artifacts: "${{ github.workspace }}/erofs/erofs-utils_linux_x86_64.zip" 59 | name: "erofs-utils-linux-x86_64-${{ env.EROFS_VERSION }}" 60 | tag: "erofs-utils-${{ env.EROFS_VERSION }}-${{ github.run_number }}" 61 | bodyFile: "${{ github.workspace}}/erofs/VERSION" 62 | token: ${{ secrets.GITHUB_TOKEN }} 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | *~ 3 | *.[ao] 4 | *.diff 5 | *.la 6 | *.lo 7 | *.mod.c 8 | *.orig 9 | *.rej 10 | *.so 11 | *.so.dbg 12 | *.tar.* 13 | 14 | # 15 | # Generated files 16 | # 17 | aclocal.m4 18 | autom4te.cache 19 | Makefile.in 20 | config/ 21 | m4/ 22 | configure 23 | configure.scan 24 | libtool 25 | stamp-h 26 | stamp-h1 27 | /mkfs/mkfs.erofs 28 | /fuse/erofsfuse 29 | /dump/dump.erofs 30 | /fsck/fsck.erofs 31 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libbase"] 2 | path = libbase 3 | url = https://android.googlesource.com/platform/system/libbase 4 | [submodule "logging"] 5 | path = logging 6 | url = https://chromium.googlesource.com/aosp/platform/system/logging 7 | [submodule "lz4"] 8 | path = lz4 9 | url = https://github.com/lz4/lz4 10 | [submodule "libpcre"] 11 | path = libpcre 12 | url = https://github.com/vmg/libpcre 13 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | EROFS USERSPACE UTILITIES 2 | M: Li Guifu 3 | M: Gao Xiang 4 | M: Huang Jianan 5 | R: Chao Yu 6 | R: Miao Xie 7 | R: Fang Wei 8 | S: Maintained 9 | L: linux-erofs@lists.ozlabs.org 10 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | erofs-utils uses two different license patterns: 2 | 3 | - most liberofs files in `lib` and `include` directories 4 | use GPL-2.0+ OR Apache-2.0 dual license; 5 | 6 | - all other files use GPL-2.0+ license, unless 7 | explicitly stated otherwise. 8 | 9 | Relevant licenses can be found in the LICENSES directory. 10 | 11 | This model is selected to emphasize that 12 | files in `lib` and `include` directory are designed to be included into 13 | 3rd-party applications, while all other files, are intended to be used 14 | "as is", as part of their intended scenarios, with no intention to 15 | support 3rd-party integration use cases. 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | COPYING -------------------------------------------------------------------------------- /METADATA: -------------------------------------------------------------------------------- 1 | # This project was upgraded with external_updater. 2 | # Usage: tools/external_updater/updater.sh update erofs-utils 3 | # For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md 4 | 5 | name: "erofs-utils" 6 | description: "EROFS Utilities" 7 | third_party { 8 | url { 9 | type: GIT 10 | value: "https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git" 11 | } 12 | version: "v1.5" 13 | license_type: RESTRICTED 14 | last_upgrade_date { 15 | year: 2023 16 | month: 1 17 | day: 18 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MODULE_LICENSE_GPL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/affggh/erofs-utils_cygwin/86e1a14214659270de4594137f4c3e1997c3ac75/MODULE_LICENSE_GPL -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0+ 2 | 3 | ACLOCAL_AMFLAGS = -I m4 4 | 5 | SUBDIRS = man lib mkfs dump fsck 6 | if ENABLE_FUSE 7 | SUBDIRS += fuse 8 | endif 9 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | dvander@google.com 2 | jaegeuk@google.com 3 | daehojeong@google.com 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # erofs-utils for cygwin 2 | ## Include 3 | **mkfs.erofs** 4 | **dump.erofs** 5 | **fsck.erofs** 6 | **extract.erofs** 7 | 8 | ## Thanks 9 | [erofs-utils](https://github.com/hsiangkao/erofs-utils) 10 | [extract.erofs](https://github.com/sekaiacg/erofs-utils) 11 | aosp project 12 | 13 | ## How to build 14 | ### Prepare 15 | #### ***prepare environment*** 16 | install in setup_x86_64.exe from [cygwin](https://cygwin.org) 17 | make gcc-core gcc-g++ github 18 | libiconv-devel zlib-devel 19 | clang llvm libpcre-devel 20 | liblzma-devel gettext 21 | gettext-devel libtool 22 | automake autoconf po4a patch 23 | #### ***install xz*** 24 | if you no need lzma compressor you can skip this step 25 | ```sh 26 | git clone https://github.com/xz-mirror/xz xz 27 | cd xz && ./autogen.sh 28 | ./configure 29 | make && make install 30 | ``` 31 | #### ***make*** 32 | ```sh 33 | git clone https://github.com/affggh/erofs-utils_cygwin erofs 34 | cd erofs 35 | # if you need extract.erofs 36 | # git clone https://github.com/sekaiacg/erofs-utils extract 37 | # then make 38 | make 39 | ``` 40 | the output will be saved in bin folder 41 | 42 | #### ***about fuse.erofs*** 43 | you must install [winfsp](https://github.com/winfsp/winfsp) on you windows. 44 | only support x86_64 45 | ```batch 46 | .\fuse.erofs -f .\vendor.img .\vendor 47 | ``` 48 | now you can see a folder in current dir called vendor. 49 | ## Archived 50 | please move to [here](https://github.com/sekaiacg/erofs-utils). 51 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.6 2 | 2023-03-12 3 | -------------------------------------------------------------------------------- /asprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef ASPRINTF_H 2 | #define ASPRINTF_H 3 | 4 | #if defined(__GNUC__) && ! defined(_GNU_SOURCE) 5 | #define _GNU_SOURCE /* needed for (v)asprintf, affects '#include ' */ 6 | #endif 7 | #include /* needed for vsnprintf */ 8 | #include /* needed for malloc, free */ 9 | #include /* needed for va_* */ 10 | 11 | /* 12 | * vscprintf: 13 | * MSVC implements this as _vscprintf, thus we just 'symlink' it here 14 | * GNU-C-compatible compilers do not implement this, thus we implement it here 15 | */ 16 | #ifdef _MSC_VER 17 | #define vscprintf _vscprintf 18 | #endif 19 | 20 | #ifdef __GNUC__ 21 | int vscprintf(const char *format, va_list ap) 22 | { 23 | va_list ap_copy; 24 | va_copy(ap_copy, ap); 25 | int retval = vsnprintf(NULL, 0, format, ap_copy); 26 | va_end(ap_copy); 27 | return retval; 28 | } 29 | #endif 30 | 31 | /* 32 | * asprintf, vasprintf: 33 | * MSVC does not implement these, thus we implement them here 34 | * GNU-C-compatible compilers implement these with the same names, thus we 35 | * don't have to do anything 36 | */ 37 | #ifdef _MSC_VER 38 | int vasprintf(char **strp, const char *format, va_list ap) 39 | { 40 | int len = vscprintf(format, ap); 41 | if (len == -1) 42 | return -1; 43 | char *str = (char*)malloc((size_t) len + 1); 44 | if (!str) 45 | return -1; 46 | int retval = vsnprintf(str, len + 1, format, ap); 47 | if (retval == -1) { 48 | free(str); 49 | return -1; 50 | } 51 | *strp = str; 52 | return retval; 53 | } 54 | 55 | int asprintf(char **strp, const char *format, ...) 56 | { 57 | va_list ap; 58 | va_start(ap, format); 59 | int retval = vasprintf(strp, format, ap); 60 | va_end(ap); 61 | return retval; 62 | } 63 | #endif 64 | 65 | #endif // ASPRINTF_H -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: GPL-2.0+ 3 | 4 | aclocal && \ 5 | autoheader && \ 6 | autoconf && \ 7 | case `uname` in Darwin*) glibtoolize --copy ;; \ 8 | *) libtoolize --copy ;; esac && \ 9 | automake -a -c 10 | -------------------------------------------------------------------------------- /cygprefix.h: -------------------------------------------------------------------------------- 1 | #ifndef __CYGPREFIX_H 2 | #define __CYGPREFIX_H 3 | 4 | // Prefix some issues 5 | #include 6 | 7 | // When i update cygwin, i meet these errors... func below from stdlib.h 8 | #ifndef __builtin_malloc 9 | #define __builtin_malloc malloc 10 | #endif 11 | 12 | #ifndef __builtin_free 13 | #define __builtin_free free 14 | #endif 15 | 16 | #ifdef __CYGWIN__ 17 | #define off64_t off_t // libext2 18 | #define typeof __typeof // libcutils 19 | 20 | // libsparse + -Wno-macro-redefined 21 | #define lseek64 lseek 22 | #define ftruncate64 ftruncate 23 | #endif // __CYGWIN__ 24 | #endif -------------------------------------------------------------------------------- /docs/INSTALL.md: -------------------------------------------------------------------------------- 1 | This document describes how to configure and build erofs-utils from 2 | source. 3 | 4 | See the [README](../README) file in the top level directory about 5 | the brief overview of erofs-utils. 6 | 7 | ## Dependencies & build 8 | 9 | LZ4 1.9.3+ for LZ4(HC) enabled [^1]. 10 | 11 | [XZ Utils 5.3.2alpha+](https://tukaani.org/xz/xz-5.3.2alpha.tar.gz) for 12 | LZMA enabled, [XZ Utils 5.4+](https://tukaani.org/xz/xz-5.4.1.tar.gz) 13 | highly recommended. 14 | 15 | libfuse 2.6+ for erofsfuse enabled. 16 | 17 | [^1]: It's not recommended to use LZ4 versions under 1.9.3 since 18 | unexpected crashes could make trouble to end users due to broken 19 | LZ4_compress_destSize() (fixed in v1.9.2), 20 | [LZ4_compress_HC_destSize()](https://github.com/lz4/lz4/commit/660d21272e4c8a0f49db5fc1e6853f08713dff82) or 21 | [LZ4_decompress_safe_partial()](https://github.com/lz4/lz4/issues/783). 22 | 23 | ## How to build with LZ4 24 | 25 | To build, the following commands can be used in order: 26 | 27 | ``` sh 28 | $ ./autogen.sh 29 | $ ./configure 30 | $ make 31 | ``` 32 | 33 | `mkfs.erofs`, `dump.erofs` and `fsck.erofs` binaries will be 34 | generated under the corresponding folders. 35 | 36 | ## How to build with liblzma 37 | 38 | In order to enable LZMA support, build with the following commands: 39 | 40 | ``` sh 41 | $ ./configure --enable-lzma 42 | $ make 43 | ``` 44 | 45 | Additionally, you could specify liblzma target paths with 46 | `--with-liblzma-incdir` and `--with-liblzma-libdir` manually. 47 | 48 | ## How to build erofsfuse 49 | 50 | It's disabled by default as an experimental feature for now due 51 | to the extra libfuse dependency, to enable and build it manually: 52 | 53 | ``` sh 54 | $ ./configure --enable-fuse 55 | $ make 56 | ``` 57 | 58 | `erofsfuse` binary will be generated under `fuse` folder. 59 | 60 | ## How to install erofs-utils manually 61 | 62 | Use the following command to install erofs-utils binaries: 63 | 64 | ``` sh 65 | # make install 66 | ``` 67 | 68 | By default, `make install` will install all the files in 69 | `/usr/local/bin`, `/usr/local/lib` etc. You can specify an 70 | installation prefix other than `/usr/local` using `--prefix`, 71 | for instance `--prefix=$HOME`. 72 | -------------------------------------------------------------------------------- /docs/compress-hints.example: -------------------------------------------------------------------------------- 1 | # https://github.com/debuerreotype/docker-debian-artifacts/blob/dist-amd64/bullseye/rootfs.tar.xz?raw=true 2 | # -zlzma:lz4hc,12:lzma,109 -C131072 --compress-hints=compress-hints.example image size: 66M 3 | # -zlz4hc,12 image size: 76M 4 | 4096 1 .*\.so.*$ 5 | 4096 1 bin/ 6 | 4096 1 sbin/ 7 | 131072 2 etc/ 8 | -------------------------------------------------------------------------------- /dump/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0+ 2 | # Makefile.am 3 | 4 | AUTOMAKE_OPTIONS = foreign 5 | bin_PROGRAMS = dump.erofs 6 | AM_CPPFLAGS = ${libuuid_CFLAGS} 7 | dump_erofs_SOURCES = main.c 8 | dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include 9 | dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ 10 | ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} 11 | -------------------------------------------------------------------------------- /fsck/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0+ 2 | # Makefile.am 3 | 4 | AUTOMAKE_OPTIONS = foreign 5 | bin_PROGRAMS = fsck.erofs 6 | AM_CPPFLAGS = ${libuuid_CFLAGS} 7 | fsck_erofs_SOURCES = main.c 8 | fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include 9 | fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ 10 | ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} 11 | 12 | if ENABLE_FUZZING 13 | noinst_PROGRAMS = fuzz_erofsfsck 14 | fuzz_erofsfsck_SOURCES = main.c 15 | fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING 16 | fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer 17 | fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ 18 | ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} 19 | endif 20 | -------------------------------------------------------------------------------- /fuse/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0+ 2 | 3 | AUTOMAKE_OPTIONS = foreign 4 | noinst_HEADERS = $(top_srcdir)/fuse/macosx.h 5 | bin_PROGRAMS = erofsfuse 6 | erofsfuse_SOURCES = main.c 7 | erofsfuse_CFLAGS = -Wall -I$(top_srcdir)/include 8 | erofsfuse_CFLAGS += -DFUSE_USE_VERSION=26 ${libfuse_CFLAGS} ${libselinux_CFLAGS} 9 | erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse_LIBS} ${liblz4_LIBS} \ 10 | ${libselinux_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} 11 | -------------------------------------------------------------------------------- /fuse/macosx.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ */ 2 | #ifdef __APPLE__ 3 | #undef LIST_HEAD 4 | #endif 5 | -------------------------------------------------------------------------------- /include/erofs/blobchunk.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * erofs-utils/lib/blobchunk.h 4 | * 5 | * Copyright (C) 2021, Alibaba Cloud 6 | */ 7 | #ifndef __EROFS_BLOBCHUNK_H 8 | #define __EROFS_BLOBCHUNK_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #include "erofs/internal.h" 16 | 17 | struct erofs_blobchunk *erofs_get_unhashed_chunk(unsigned int device_id, 18 | erofs_blk_t blkaddr, erofs_off_t sourceoffset); 19 | int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, erofs_off_t off); 20 | int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd); 21 | int tarerofs_write_chunkes(struct erofs_inode *inode, erofs_off_t data_offset); 22 | int erofs_mkfs_dump_blobs(struct erofs_sb_info *sbi); 23 | void erofs_blob_exit(void); 24 | int erofs_blob_init(const char *blobfile_path); 25 | int erofs_mkfs_init_devices(struct erofs_sb_info *sbi, unsigned int devices); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/erofs/block_list.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C), 2021, Coolpad Group Limited. 4 | * Created by Yue Hu 5 | */ 6 | #ifndef __EROFS_BLOCK_LIST_H 7 | #define __EROFS_BLOCK_LIST_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include "internal.h" 15 | 16 | int erofs_blocklist_open(char *filename, bool srcmap); 17 | void erofs_blocklist_close(void); 18 | 19 | void tarerofs_blocklist_write(erofs_blk_t blkaddr, erofs_blk_t nblocks, 20 | erofs_off_t srcoff); 21 | #ifdef WITH_ANDROID 22 | void erofs_droid_blocklist_write(struct erofs_inode *inode, 23 | erofs_blk_t blk_start, erofs_blk_t nblocks); 24 | void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode, 25 | erofs_blk_t blkaddr); 26 | void erofs_droid_blocklist_write_extent(struct erofs_inode *inode, 27 | erofs_blk_t blk_start, erofs_blk_t nblocks, 28 | bool first_extent, bool last_extent); 29 | #else 30 | static inline void erofs_droid_blocklist_write(struct erofs_inode *inode, 31 | erofs_blk_t blk_start, erofs_blk_t nblocks) {} 32 | static inline void 33 | erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode, 34 | erofs_blk_t blkaddr) {} 35 | static inline void 36 | erofs_droid_blocklist_write_extent(struct erofs_inode *inode, 37 | erofs_blk_t blk_start, erofs_blk_t nblocks, 38 | bool first_extent, bool last_extent) {} 39 | #endif 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/erofs/compress.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2019 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Gao Xiang 6 | */ 7 | #ifndef __EROFS_COMPRESS_H 8 | #define __EROFS_COMPRESS_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #include "internal.h" 16 | 17 | #define EROFS_CONFIG_COMPR_MAX_SZ (4000 * 1024) 18 | 19 | void z_erofs_drop_inline_pcluster(struct erofs_inode *inode); 20 | int erofs_write_compressed_file(struct erofs_inode *inode, int fd); 21 | 22 | int z_erofs_compress_init(struct erofs_sb_info *sbi, 23 | struct erofs_buffer_head *bh); 24 | int z_erofs_compress_exit(void); 25 | 26 | const char *z_erofs_list_supported_algorithms(int i, unsigned int *mask); 27 | const char *z_erofs_list_available_compressors(int *i); 28 | 29 | static inline bool erofs_is_packed_inode(struct erofs_inode *inode) 30 | { 31 | erofs_nid_t packed_nid = inode->sbi->packed_nid; 32 | 33 | if (inode->nid == EROFS_PACKED_NID_UNALLOCATED) { 34 | DBG_BUGON(packed_nid != EROFS_PACKED_NID_UNALLOCATED); 35 | return true; 36 | } 37 | return (packed_nid > 0 && inode->nid == packed_nid); 38 | } 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/erofs/compress_hints.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C), 2008-2021, OPPO Mobile Comm Corp., Ltd. 4 | * Created by Huang Jianan 5 | */ 6 | #ifndef __EROFS_COMPRESS_HINTS_H 7 | #define __EROFS_COMPRESS_HINTS_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include "erofs/internal.h" 15 | #include 16 | #include 17 | 18 | struct erofs_compress_hints { 19 | struct list_head list; 20 | 21 | regex_t reg; 22 | unsigned int physical_clusterblks; 23 | unsigned char algorithmtype; 24 | }; 25 | 26 | bool z_erofs_apply_compress_hints(struct erofs_inode *inode); 27 | void erofs_cleanup_compress_hints(void); 28 | int erofs_load_compress_hints(struct erofs_sb_info *sbi); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/erofs/decompress.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C), 2008-2020, OPPO Mobile Comm Corp., Ltd. 4 | * Created by Huang Jianan 5 | */ 6 | #ifndef __EROFS_DECOMPRESS_H 7 | #define __EROFS_DECOMPRESS_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include "internal.h" 15 | 16 | struct z_erofs_decompress_req { 17 | struct erofs_sb_info *sbi; 18 | char *in, *out; 19 | 20 | /* 21 | * initial decompressed bytes that need to be skipped 22 | * when finally copying to output buffer 23 | */ 24 | unsigned int decodedskip; 25 | unsigned int inputsize, decodedlength; 26 | 27 | /* cut point of interlaced uncompressed data */ 28 | unsigned int interlaced_offset; 29 | 30 | /* indicate the algorithm will be used for decompression */ 31 | unsigned int alg; 32 | bool partial_decoding; 33 | }; 34 | 35 | int z_erofs_decompress(struct z_erofs_decompress_req *rq); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/erofs/dedupe.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2022 Alibaba Cloud 4 | */ 5 | #ifndef __EROFS_DEDUPE_H 6 | #define __EROFS_DEDUPE_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #include "internal.h" 14 | 15 | struct z_erofs_inmem_extent { 16 | erofs_blk_t blkaddr; 17 | unsigned int compressedblks; 18 | unsigned int length; 19 | bool raw, partial; 20 | }; 21 | 22 | struct z_erofs_dedupe_ctx { 23 | u8 *start, *end; 24 | u8 *cur; 25 | struct z_erofs_inmem_extent e; 26 | }; 27 | 28 | int z_erofs_dedupe_match(struct z_erofs_dedupe_ctx *ctx); 29 | int z_erofs_dedupe_insert(struct z_erofs_inmem_extent *e, 30 | void *original_data); 31 | void z_erofs_dedupe_commit(bool drop); 32 | int z_erofs_dedupe_init(unsigned int wsiz); 33 | void z_erofs_dedupe_exit(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/erofs/err.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2018 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Li Guifu 6 | */ 7 | #ifndef __EROFS_ERR_H 8 | #define __EROFS_ERR_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #include 16 | 17 | #define MAX_ERRNO (4095) 18 | #define IS_ERR_VALUE(x) \ 19 | ((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO) 20 | 21 | static inline void *ERR_PTR(long error) 22 | { 23 | return (void *)error; 24 | } 25 | 26 | static inline int IS_ERR(const void *ptr) 27 | { 28 | return IS_ERR_VALUE((unsigned long)ptr); 29 | } 30 | 31 | static inline long PTR_ERR(const void *ptr) 32 | { 33 | return (long) ptr; 34 | } 35 | 36 | static inline void * ERR_CAST(const void *ptr) 37 | { 38 | /* cast away the const */ 39 | return (void *) ptr; 40 | } 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /include/erofs/exclude.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Created by Li Guifu 4 | */ 5 | #ifndef __EROFS_EXCLUDE_H 6 | #define __EROFS_EXCLUDE_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #include 14 | #include 15 | 16 | struct erofs_exclude_rule { 17 | struct list_head list; 18 | 19 | char *pattern; 20 | regex_t reg; 21 | }; 22 | 23 | void erofs_exclude_set_root(const char *rootdir); 24 | void erofs_cleanup_exclude_rules(void); 25 | 26 | int erofs_parse_exclude_path(const char *args, bool is_regex); 27 | struct erofs_exclude_rule *erofs_is_exclude_path(const char *dir, 28 | const char *name); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/erofs/fragments.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C), 2022, Coolpad Group Limited. 4 | */ 5 | #ifndef __EROFS_FRAGMENTS_H 6 | #define __EROFS_FRAGMENTS_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #include "erofs/internal.h" 14 | 15 | extern const char *erofs_frags_packedname; 16 | #define EROFS_PACKED_INODE erofs_frags_packedname 17 | 18 | FILE *erofs_packedfile_init(void); 19 | void erofs_packedfile_exit(void); 20 | struct erofs_inode *erofs_mkfs_build_packedfile(void); 21 | 22 | int z_erofs_fragments_dedupe(struct erofs_inode *inode, int fd, u32 *tofcrc); 23 | int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc); 24 | int z_erofs_pack_fragments(struct erofs_inode *inode, void *data, 25 | unsigned int len, u32 tofcrc); 26 | void z_erofs_fragments_commit(struct erofs_inode *inode); 27 | int z_erofs_fragments_init(void); 28 | void z_erofs_fragments_exit(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/erofs/inode.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2018-2019 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Li Guifu 6 | * with heavy changes by Gao Xiang 7 | */ 8 | #ifndef __EROFS_INODE_H 9 | #define __EROFS_INODE_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | #include "erofs/internal.h" 17 | 18 | static inline struct erofs_inode *erofs_igrab(struct erofs_inode *inode) 19 | { 20 | ++inode->i_count; 21 | return inode; 22 | } 23 | 24 | u32 erofs_new_encode_dev(dev_t dev); 25 | unsigned char erofs_mode_to_ftype(umode_t mode); 26 | unsigned char erofs_ftype_to_dtype(unsigned int filetype); 27 | void erofs_inode_manager_init(void); 28 | void erofs_insert_ihash(struct erofs_inode *inode, dev_t dev, ino_t ino); 29 | struct erofs_inode *erofs_iget(dev_t dev, ino_t ino); 30 | struct erofs_inode *erofs_iget_by_nid(erofs_nid_t nid); 31 | unsigned int erofs_iput(struct erofs_inode *inode); 32 | erofs_nid_t erofs_lookupnid(struct erofs_inode *inode); 33 | struct erofs_dentry *erofs_d_alloc(struct erofs_inode *parent, 34 | const char *name); 35 | int erofs_rebuild_dump_tree(struct erofs_inode *dir); 36 | int erofs_init_empty_dir(struct erofs_inode *dir); 37 | struct erofs_inode *erofs_new_inode(void); 38 | struct erofs_inode *erofs_mkfs_build_tree_from_path(const char *path); 39 | struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/erofs/io.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2018-2019 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Li Guifu 6 | */ 7 | #ifndef __EROFS_IO_H 8 | #define __EROFS_IO_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #ifndef _GNU_SOURCE 16 | #define _GNU_SOURCE 17 | #endif 18 | #include 19 | #include "internal.h" 20 | 21 | #ifndef O_BINARY 22 | #define O_BINARY 0 23 | #endif 24 | 25 | void blob_closeall(struct erofs_sb_info *sbi); 26 | int blob_open_ro(struct erofs_sb_info *sbi, const char *dev); 27 | int dev_open(struct erofs_sb_info *sbi, const char *devname); 28 | int dev_open_ro(struct erofs_sb_info *sbi, const char *dev); 29 | void dev_close(struct erofs_sb_info *sbi); 30 | int dev_write(struct erofs_sb_info *sbi, const void *buf, 31 | u64 offset, size_t len); 32 | int dev_read(struct erofs_sb_info *sbi, int device_id, 33 | void *buf, u64 offset, size_t len); 34 | int dev_fillzero(struct erofs_sb_info *sbi, u64 offset, 35 | size_t len, bool padding); 36 | int dev_fsync(struct erofs_sb_info *sbi); 37 | int dev_resize(struct erofs_sb_info *sbi, erofs_blk_t nblocks); 38 | 39 | ssize_t erofs_copy_file_range(int fd_in, erofs_off_t *off_in, 40 | int fd_out, erofs_off_t *off_out, 41 | size_t length); 42 | 43 | static inline int blk_write(struct erofs_sb_info *sbi, const void *buf, 44 | erofs_blk_t blkaddr, u32 nblocks) 45 | { 46 | return dev_write(sbi, buf, erofs_pos(sbi, blkaddr), 47 | erofs_pos(sbi, nblocks)); 48 | } 49 | 50 | static inline int blk_read(struct erofs_sb_info *sbi, int device_id, void *buf, 51 | erofs_blk_t start, u32 nblocks) 52 | { 53 | return dev_read(sbi, device_id, buf, erofs_pos(sbi, start), 54 | erofs_pos(sbi, nblocks)); 55 | } 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif // EROFS_IO_H_ 62 | -------------------------------------------------------------------------------- /include/erofs/print.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2018-2019 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Li Guifu 6 | */ 7 | #ifndef __EROFS_PRINT_H 8 | #define __EROFS_PRINT_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #include "config.h" 16 | #include 17 | 18 | enum { 19 | EROFS_MSG_MIN = 0, 20 | EROFS_ERR = 0, 21 | EROFS_WARN = 2, 22 | EROFS_INFO = 3, 23 | EROFS_DBG = 7, 24 | EROFS_MSG_MAX = 9 25 | }; 26 | 27 | #ifndef EROFS_MODNAME 28 | #define EROFS_MODNAME "erofs" 29 | #endif 30 | #define FUNC_LINE_FMT "%s() Line[%d] " 31 | 32 | #ifdef NDEBUG 33 | #ifndef pr_fmt 34 | #define pr_fmt(fmt) EROFS_MODNAME ": " fmt "\n" 35 | #endif 36 | #define PR_FMT_FUNC_LINE(fmt) pr_fmt(fmt) 37 | #else 38 | #ifndef pr_fmt 39 | #define pr_fmt(fmt) EROFS_MODNAME ": " FUNC_LINE_FMT fmt "\n" 40 | #endif 41 | #define PR_FMT_FUNC_LINE(fmt) pr_fmt(fmt), __func__, __LINE__ 42 | #endif 43 | 44 | void erofs_msg(int dbglv, const char *fmt, ...); 45 | 46 | #define erofs_dbg(fmt, ...) do { \ 47 | if (cfg.c_dbg_lvl >= EROFS_DBG) { \ 48 | erofs_msg(EROFS_DBG, \ 49 | " " PR_FMT_FUNC_LINE(fmt), \ 50 | ##__VA_ARGS__); \ 51 | } \ 52 | } while (0) 53 | 54 | #define erofs_info(fmt, ...) do { \ 55 | if (cfg.c_dbg_lvl >= EROFS_INFO) { \ 56 | erofs_msg(EROFS_INFO, \ 57 | " " PR_FMT_FUNC_LINE(fmt), \ 58 | ##__VA_ARGS__); \ 59 | fflush(stdout); \ 60 | } \ 61 | } while (0) 62 | 63 | #define erofs_warn(fmt, ...) do { \ 64 | if (cfg.c_dbg_lvl >= EROFS_WARN) { \ 65 | erofs_msg(EROFS_WARN, \ 66 | " " PR_FMT_FUNC_LINE(fmt), \ 67 | ##__VA_ARGS__); \ 68 | fflush(stdout); \ 69 | } \ 70 | } while (0) 71 | 72 | #define erofs_err(fmt, ...) do { \ 73 | if (cfg.c_dbg_lvl >= EROFS_ERR) { \ 74 | erofs_msg(EROFS_ERR, \ 75 | " " PR_FMT_FUNC_LINE(fmt), \ 76 | ##__VA_ARGS__); \ 77 | } \ 78 | } while (0) 79 | 80 | #define erofs_dump(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /include/erofs/rebuild.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | #ifndef __EROFS_REBUILD_H 3 | #define __EROFS_REBUILD_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | #include "internal.h" 11 | 12 | struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd, 13 | char *path, bool aufs, bool *whout, bool *opq); 14 | 15 | int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/erofs/tar.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | #ifndef __EROFS_TAR_H 3 | #define __EROFS_TAR_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | #include 11 | 12 | #include "internal.h" 13 | 14 | struct erofs_pax_header { 15 | struct stat st; 16 | struct list_head xattrs; 17 | bool use_mtime; 18 | bool use_size; 19 | bool use_uid; 20 | bool use_gid; 21 | char *path, *link; 22 | }; 23 | 24 | struct erofs_tarfile { 25 | struct erofs_pax_header global; 26 | char *mapfile; 27 | 28 | int fd; 29 | u64 offset; 30 | bool index_mode, aufs; 31 | }; 32 | 33 | int tarerofs_parse_tar(struct erofs_inode *root, struct erofs_tarfile *tar); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/erofs/trace.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2020 Gao Xiang 4 | */ 5 | #ifndef __EROFS_TRACE_H 6 | #define __EROFS_TRACE_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #define trace_erofs_map_blocks_flatmode_enter(inode, map, flags) ((void)0) 14 | #define trace_erofs_map_blocks_flatmode_exit(inode, map, flags, ret) ((void)0) 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/erofs/xattr.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Originally contributed by an anonymous person, 4 | * heavily changed by Li Guifu 5 | * and Gao Xiang 6 | */ 7 | #ifndef __EROFS_XATTR_H 8 | #define __EROFS_XATTR_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #include "internal.h" 16 | 17 | #ifndef ENOATTR 18 | #define ENOATTR ENODATA 19 | #endif 20 | 21 | static inline unsigned int inlinexattr_header_size(struct erofs_inode *vi) 22 | { 23 | return sizeof(struct erofs_xattr_ibody_header) + 24 | sizeof(u32) * vi->xattr_shared_count; 25 | } 26 | 27 | static inline erofs_blk_t xattrblock_addr(struct erofs_inode *vi, 28 | unsigned int xattr_id) 29 | { 30 | return vi->sbi->xattr_blkaddr + 31 | erofs_blknr(vi->sbi, xattr_id * sizeof(__u32)); 32 | } 33 | 34 | static inline unsigned int xattrblock_offset(struct erofs_inode *vi, 35 | unsigned int xattr_id) 36 | { 37 | return erofs_blkoff(vi->sbi, xattr_id * sizeof(__u32)); 38 | } 39 | 40 | #define EROFS_INODE_XATTR_ICOUNT(_size) ({\ 41 | u32 __size = le16_to_cpu(_size); \ 42 | ((__size) == 0) ? 0 : \ 43 | (_size - sizeof(struct erofs_xattr_ibody_header)) / \ 44 | sizeof(struct erofs_xattr_entry) + 1; }) 45 | 46 | int erofs_scan_file_xattrs(struct erofs_inode *inode); 47 | int erofs_prepare_xattr_ibody(struct erofs_inode *inode); 48 | char *erofs_export_xattr_ibody(struct erofs_inode *inode); 49 | int erofs_build_shared_xattrs_from_path(struct erofs_sb_info *sbi, const char *path); 50 | 51 | int erofs_xattr_insert_name_prefix(const char *prefix); 52 | void erofs_xattr_cleanup_name_prefixes(void); 53 | int erofs_xattr_write_name_prefixes(struct erofs_sb_info *sbi, FILE *f); 54 | void erofs_xattr_prefixes_cleanup(struct erofs_sb_info *sbi); 55 | int erofs_xattr_prefixes_init(struct erofs_sb_info *sbi); 56 | 57 | int erofs_setxattr(struct erofs_inode *inode, char *key, 58 | const void *value, size_t size); 59 | int erofs_set_opaque_xattr(struct erofs_inode *inode); 60 | void erofs_clear_opaque_xattr(struct erofs_inode *inode); 61 | int erofs_set_origin_xattr(struct erofs_inode *inode); 62 | int erofs_read_xattrs_from_disk(struct erofs_inode *inode); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/erofs/xxhash.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0+ */ 2 | #ifndef __EROFS_XXHASH_H 3 | #define __EROFS_XXHASH_H 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | #include 11 | 12 | /** 13 | * xxh32() - calculate the 32-bit hash of the input with a given seed. 14 | * 15 | * @input: The data to hash. 16 | * @length: The length of the data to hash. 17 | * @seed: The seed can be used to alter the result predictably. 18 | * 19 | * Return: The 32-bit hash of the data. 20 | */ 21 | uint32_t xxh32(const void *input, size_t length, uint32_t seed); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 2 | 3 | noinst_LTLIBRARIES = liberofs.la 4 | noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ 5 | $(top_srcdir)/include/erofs/blobchunk.h \ 6 | $(top_srcdir)/include/erofs/block_list.h \ 7 | $(top_srcdir)/include/erofs/cache.h \ 8 | $(top_srcdir)/include/erofs/compress.h \ 9 | $(top_srcdir)/include/erofs/config.h \ 10 | $(top_srcdir)/include/erofs/decompress.h \ 11 | $(top_srcdir)/include/erofs/defs.h \ 12 | $(top_srcdir)/include/erofs/err.h \ 13 | $(top_srcdir)/include/erofs/exclude.h \ 14 | $(top_srcdir)/include/erofs/flex-array.h \ 15 | $(top_srcdir)/include/erofs/hashmap.h \ 16 | $(top_srcdir)/include/erofs/hashtable.h \ 17 | $(top_srcdir)/include/erofs/inode.h \ 18 | $(top_srcdir)/include/erofs/internal.h \ 19 | $(top_srcdir)/include/erofs/io.h \ 20 | $(top_srcdir)/include/erofs/list.h \ 21 | $(top_srcdir)/include/erofs/print.h \ 22 | $(top_srcdir)/include/erofs/tar.h \ 23 | $(top_srcdir)/include/erofs/trace.h \ 24 | $(top_srcdir)/include/erofs/xattr.h \ 25 | $(top_srcdir)/include/erofs/compress_hints.h \ 26 | $(top_srcdir)/include/erofs/fragments.h \ 27 | $(top_srcdir)/include/erofs/xxhash.h \ 28 | $(top_srcdir)/include/erofs/rebuild.h \ 29 | $(top_srcdir)/lib/liberofs_private.h 30 | 31 | noinst_HEADERS += compressor.h 32 | liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ 33 | namei.c data.c compress.c compressor.c zmap.c decompress.c \ 34 | compress_hints.c hashmap.c sha256.c blobchunk.c dir.c \ 35 | fragments.c rb_tree.c dedupe.c uuid_unparse.c uuid.c tar.c \ 36 | block_list.c xxhash.c rebuild.c 37 | 38 | liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include 39 | if ENABLE_LZ4 40 | liberofs_la_CFLAGS += ${LZ4_CFLAGS} 41 | liberofs_la_SOURCES += compressor_lz4.c 42 | if ENABLE_LZ4HC 43 | liberofs_la_SOURCES += compressor_lz4hc.c 44 | endif 45 | endif 46 | if ENABLE_LIBLZMA 47 | liberofs_la_CFLAGS += ${liblzma_CFLAGS} 48 | liberofs_la_SOURCES += compressor_liblzma.c 49 | endif 50 | 51 | liberofs_la_SOURCES += kite_deflate.c compressor_deflate.c 52 | if ENABLE_LIBDEFLATE 53 | liberofs_la_SOURCES += compressor_libdeflate.c 54 | endif 55 | -------------------------------------------------------------------------------- /lib/compressor.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2018-2019 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Gao Xiang 6 | */ 7 | #ifndef __EROFS_LIB_COMPRESSOR_H 8 | #define __EROFS_LIB_COMPRESSOR_H 9 | 10 | #include "erofs/defs.h" 11 | 12 | struct erofs_compress; 13 | 14 | struct erofs_compressor { 15 | int default_level; 16 | int best_level; 17 | 18 | int (*init)(struct erofs_compress *c); 19 | int (*exit)(struct erofs_compress *c); 20 | int (*setlevel)(struct erofs_compress *c, int compression_level); 21 | 22 | int (*compress_destsize)(const struct erofs_compress *c, 23 | const void *src, unsigned int *srcsize, 24 | void *dst, unsigned int dstsize); 25 | }; 26 | 27 | struct erofs_algorithm; 28 | 29 | struct erofs_compress { 30 | struct erofs_sb_info *sbi; 31 | const struct erofs_algorithm *alg; 32 | 33 | unsigned int compress_threshold; 34 | unsigned int compression_level; 35 | 36 | /* *_destsize specific */ 37 | unsigned int destsize_alignsize; 38 | unsigned int destsize_redzone_begin; 39 | unsigned int destsize_redzone_end; 40 | 41 | void *private_data; 42 | }; 43 | 44 | /* list of compression algorithms */ 45 | extern const struct erofs_compressor erofs_compressor_lz4; 46 | extern const struct erofs_compressor erofs_compressor_lz4hc; 47 | extern const struct erofs_compressor erofs_compressor_lzma; 48 | extern const struct erofs_compressor erofs_compressor_deflate; 49 | extern const struct erofs_compressor erofs_compressor_libdeflate; 50 | 51 | int z_erofs_get_compress_algorithm_id(const struct erofs_compress *c); 52 | int erofs_compress_destsize(const struct erofs_compress *c, 53 | const void *src, unsigned int *srcsize, 54 | void *dst, unsigned int dstsize, bool inblocks); 55 | 56 | int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level); 57 | int erofs_compressor_init(struct erofs_sb_info *sbi, 58 | struct erofs_compress *c, char *alg_name); 59 | int erofs_compressor_exit(struct erofs_compress *c); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /lib/compressor_deflate.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 2 | /* 3 | * Copyright (C) 2023, Alibaba Cloud 4 | * Copyright (C) 2023, Gao Xiang 5 | */ 6 | #include "erofs/internal.h" 7 | #include "erofs/print.h" 8 | #include "erofs/config.h" 9 | #include "compressor.h" 10 | 11 | void *kite_deflate_init(int level, unsigned int dict_size); 12 | void kite_deflate_end(void *s); 13 | int kite_deflate_destsize(void *s, const u8 *in, u8 *out, 14 | unsigned int *srcsize, unsigned int target_dstsize); 15 | 16 | static int deflate_compress_destsize(const struct erofs_compress *c, 17 | const void *src, unsigned int *srcsize, 18 | void *dst, unsigned int dstsize) 19 | { 20 | int rc = kite_deflate_destsize(c->private_data, src, dst, 21 | srcsize, dstsize); 22 | 23 | if (rc <= 0) 24 | return -EFAULT; 25 | return rc; 26 | } 27 | 28 | static int compressor_deflate_exit(struct erofs_compress *c) 29 | { 30 | if (!c->private_data) 31 | return -EINVAL; 32 | 33 | kite_deflate_end(c->private_data); 34 | return 0; 35 | } 36 | 37 | static int compressor_deflate_init(struct erofs_compress *c) 38 | { 39 | c->private_data = NULL; 40 | 41 | erofs_warn("EXPERIMENTAL DEFLATE algorithm in use. Use at your own risk!"); 42 | erofs_warn("*Carefully* check filesystem data correctness to avoid corruption!"); 43 | erofs_warn("Please send a report to if something is wrong."); 44 | return 0; 45 | } 46 | 47 | static int erofs_compressor_deflate_setlevel(struct erofs_compress *c, 48 | int compression_level) 49 | { 50 | void *s; 51 | 52 | if (c->private_data) { 53 | kite_deflate_end(c->private_data); 54 | c->private_data = NULL; 55 | } 56 | 57 | if (compression_level < 0) 58 | compression_level = erofs_compressor_deflate.default_level; 59 | 60 | s = kite_deflate_init(compression_level, cfg.c_dict_size); 61 | if (IS_ERR(s)) 62 | return PTR_ERR(s); 63 | 64 | c->private_data = s; 65 | c->compression_level = compression_level; 66 | return 0; 67 | } 68 | 69 | const struct erofs_compressor erofs_compressor_deflate = { 70 | .default_level = 1, 71 | .best_level = 9, 72 | .init = compressor_deflate_init, 73 | .exit = compressor_deflate_exit, 74 | .setlevel = erofs_compressor_deflate_setlevel, 75 | .compress_destsize = deflate_compress_destsize, 76 | }; 77 | -------------------------------------------------------------------------------- /lib/compressor_lz4.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 2 | /* 3 | * Copyright (C) 2018-2019 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Gao Xiang 6 | */ 7 | #include 8 | #include "erofs/internal.h" 9 | #include "compressor.h" 10 | 11 | #ifndef LZ4_DISTANCE_MAX /* history window size */ 12 | #define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */ 13 | #endif 14 | 15 | static int lz4_compress_destsize(const struct erofs_compress *c, 16 | const void *src, unsigned int *srcsize, 17 | void *dst, unsigned int dstsize) 18 | { 19 | int srcSize = (int)*srcsize; 20 | int rc = LZ4_compress_destSize(src, dst, &srcSize, (int)dstsize); 21 | 22 | if (!rc) 23 | return -EFAULT; 24 | *srcsize = srcSize; 25 | return rc; 26 | } 27 | 28 | static int compressor_lz4_exit(struct erofs_compress *c) 29 | { 30 | return 0; 31 | } 32 | 33 | static int compressor_lz4_init(struct erofs_compress *c) 34 | { 35 | c->sbi->lz4_max_distance = LZ4_DISTANCE_MAX; 36 | return 0; 37 | } 38 | 39 | const struct erofs_compressor erofs_compressor_lz4 = { 40 | .default_level = 0, 41 | .best_level = 0, 42 | .init = compressor_lz4_init, 43 | .exit = compressor_lz4_exit, 44 | .compress_destsize = lz4_compress_destsize, 45 | }; 46 | -------------------------------------------------------------------------------- /lib/compressor_lz4hc.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 2 | /* 3 | * Copyright (C) 2018-2019 HUAWEI, Inc. 4 | * http://www.huawei.com/ 5 | * Created by Gao Xiang 6 | */ 7 | #define LZ4_HC_STATIC_LINKING_ONLY (1) 8 | #include 9 | #include "erofs/internal.h" 10 | #include "compressor.h" 11 | 12 | #ifndef LZ4_DISTANCE_MAX /* history window size */ 13 | #define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */ 14 | #endif 15 | 16 | static int lz4hc_compress_destsize(const struct erofs_compress *c, 17 | const void *src, unsigned int *srcsize, 18 | void *dst, unsigned int dstsize) 19 | { 20 | int srcSize = (int)*srcsize; 21 | int rc = LZ4_compress_HC_destSize(c->private_data, src, dst, 22 | &srcSize, (int)dstsize, 23 | c->compression_level); 24 | if (!rc) 25 | return -EFAULT; 26 | *srcsize = srcSize; 27 | return rc; 28 | } 29 | 30 | static int compressor_lz4hc_exit(struct erofs_compress *c) 31 | { 32 | if (!c->private_data) 33 | return -EINVAL; 34 | 35 | LZ4_freeStreamHC(c->private_data); 36 | return 0; 37 | } 38 | 39 | static int compressor_lz4hc_init(struct erofs_compress *c) 40 | { 41 | c->private_data = LZ4_createStreamHC(); 42 | if (!c->private_data) 43 | return -ENOMEM; 44 | 45 | c->sbi->lz4_max_distance = LZ4_DISTANCE_MAX; 46 | return 0; 47 | } 48 | 49 | static int compressor_lz4hc_setlevel(struct erofs_compress *c, 50 | int compression_level) 51 | { 52 | if (compression_level > LZ4HC_CLEVEL_MAX) 53 | return -EINVAL; 54 | 55 | c->compression_level = compression_level < 0 ? 56 | LZ4HC_CLEVEL_DEFAULT : compression_level; 57 | return 0; 58 | } 59 | 60 | const struct erofs_compressor erofs_compressor_lz4hc = { 61 | .default_level = LZ4HC_CLEVEL_DEFAULT, 62 | .best_level = LZ4HC_CLEVEL_MAX, 63 | .init = compressor_lz4hc_init, 64 | .exit = compressor_lz4hc_exit, 65 | .setlevel = compressor_lz4hc_setlevel, 66 | .compress_destsize = lz4hc_compress_destsize, 67 | }; 68 | -------------------------------------------------------------------------------- /lib/liberofs_private.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */ 2 | 3 | #ifdef HAVE_LIBSELINUX 4 | #include 5 | #include 6 | #endif 7 | 8 | #ifdef WITH_ANDROID 9 | #include 10 | #include 11 | #include 12 | #include 13 | #endif 14 | 15 | #ifndef HAVE_MEMRCHR 16 | static inline void *memrchr(const void *s, int c, size_t n) 17 | { 18 | const unsigned char *p = (const unsigned char *)s; 19 | 20 | for (p += n; n > 0; n--) 21 | if (*--p == c) 22 | return (void*)p; 23 | return NULL; 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/liberofs_uuid.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | #ifndef __EROFS_LIB_UUID_H 3 | #define __EROFS_LIB_UUID_H 4 | 5 | void erofs_uuid_generate(unsigned char *out); 6 | void erofs_uuid_unparse_lower(const unsigned char *buf, char *out); 7 | int erofs_uuid_parse(const char *in, unsigned char *uu); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lib/rolling_hash.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | /* 3 | * Copyright (C) 2022 Alibaba Cloud 4 | */ 5 | #ifndef __ROLLING_HASH_H__ 6 | #define __ROLLING_HASH_H__ 7 | 8 | #include 9 | 10 | #define PRIME_NUMBER 4294967295LL 11 | #define RADIX 256 12 | 13 | static inline long long erofs_rolling_hash_init(u8 *input, 14 | int len, bool backwards) 15 | { 16 | long long hash = 0; 17 | 18 | if (!backwards) { 19 | int i; 20 | 21 | for (i = 0; i < len; ++i) 22 | hash = (RADIX * hash + input[i]) % PRIME_NUMBER; 23 | } else { 24 | while (len) 25 | hash = (RADIX * hash + input[--len]) % PRIME_NUMBER; 26 | } 27 | return hash; 28 | } 29 | 30 | /* RM = R ^ (M-1) % Q */ 31 | /* 32 | * NOTE: value of "hash" could be negative so we cannot use unsiged types for "hash" 33 | * "long long" is used here and PRIME_NUMBER can be ULONG_MAX 34 | */ 35 | static inline long long erofs_rolling_hash_advance(long long old_hash, 36 | unsigned long long RM, 37 | u8 to_remove, u8 to_add) 38 | { 39 | long long hash = old_hash; 40 | long long to_remove_val = (to_remove * RM) % PRIME_NUMBER; 41 | 42 | hash = RADIX * (old_hash - to_remove_val) % PRIME_NUMBER; 43 | hash = (hash + to_add) % PRIME_NUMBER; 44 | 45 | /* We might get negative value of hash, converting it to positive */ 46 | if (hash < 0) 47 | hash += PRIME_NUMBER; 48 | return hash; 49 | } 50 | 51 | static inline long long erofs_rollinghash_calc_rm(int window_size) 52 | { 53 | int i; 54 | long long RM = 1; 55 | 56 | for (i = 0; i < window_size - 1; ++i) 57 | RM = (RM * RADIX) % PRIME_NUMBER; 58 | return RM; 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /lib/sha256.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 | #ifndef __EROFS_LIB_SHA256_H 3 | #define __EROFS_LIB_SHA256_H 4 | 5 | #include "erofs/defs.h" 6 | 7 | struct sha256_state { 8 | u64 length; 9 | u32 state[8], curlen; 10 | u8 buf[64]; 11 | }; 12 | 13 | void erofs_sha256_init(struct sha256_state *md); 14 | int erofs_sha256_process(struct sha256_state *md, 15 | const unsigned char *in, unsigned long inlen); 16 | int erofs_sha256_done(struct sha256_state *md, unsigned char *out); 17 | 18 | void erofs_sha256(const unsigned char *in, unsigned long in_size, 19 | unsigned char out[32]); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lib/uuid_unparse.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 2 | /* 3 | * Copyright (C) 2023 Norbert Lange 4 | */ 5 | 6 | #include 7 | 8 | #include "erofs/config.h" 9 | #include "liberofs_uuid.h" 10 | 11 | void erofs_uuid_unparse_lower(const unsigned char *buf, char *out) { 12 | sprintf(out, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", 13 | (buf[0] << 8) | buf[1], 14 | (buf[2] << 8) | buf[3], 15 | (buf[4] << 8) | buf[5], 16 | (buf[6] << 8) | buf[7], 17 | (buf[8] << 8) | buf[9], 18 | (buf[10] << 8) | buf[11], 19 | (buf[12] << 8) | buf[13], 20 | (buf[14] << 8) | buf[15]); 21 | } 22 | -------------------------------------------------------------------------------- /libcutils/KernelLibcutilsTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 34 | -------------------------------------------------------------------------------- /libcutils/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/affggh/erofs-utils_cygwin/86e1a14214659270de4594137f4c3e1997c3ac75/libcutils/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /libcutils/Makefile: -------------------------------------------------------------------------------- 1 | CXX = clang++ 2 | AR = ar rcs 3 | RM = rm -rf 4 | SHELL = bash 5 | 6 | override CXXFLAGS := $(CXXFLAGS) -std=c++17 7 | 8 | ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT) 9 | override CXXFLAGS := $(CXXFLAGS) -stdlib=libc++ -static 10 | endif 11 | 12 | libcutils_src = \ 13 | config_utils.cpp \ 14 | iosched_policy.cpp \ 15 | load_file.cpp \ 16 | native_handle.cpp \ 17 | properties.cpp \ 18 | record_stream.cpp \ 19 | strlcpy.c \ 20 | threads.cpp \ 21 | fs.cpp \ 22 | hashmap.cpp \ 23 | multiuser.cpp \ 24 | str_parms.cpp \ 25 | ashmem-host.cpp \ 26 | canned_fs_config.cpp \ 27 | fs_config.cpp \ 28 | trace-host.cpp 29 | 30 | ifeq ($(shell uname -s | cut -d "_" -f1), MINGW64) 31 | remove_src = fs.cpp multiuser.cpp ashmem-host.cpp 32 | libcutils_src := $(filter-out $(remove_src),$(libcutils_src)) 33 | endif 34 | 35 | libcutils_obj = $(patsubst %.cpp,obj/%.o,$(libcutils_src)) 36 | libcutils_cxxflags = $(CXXFLAGS) \ 37 | -Wall \ 38 | -Werror \ 39 | -Wextra \ 40 | -Wno-exit-time-destructors \ 41 | -include"../cygprefix.h" 42 | 43 | ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT) 44 | # Not a big issue 45 | libcutils_cxxflags += -D_Bool=bool 46 | endif 47 | 48 | .PHONY: all 49 | 50 | all: .lib/libcutils.a 51 | 52 | obj/%.o: %.cpp 53 | @mkdir -p `dirname $@` 54 | @echo -e "\t CPP\t $@" 55 | @$(CXX) $(libcutils_cxxflags) -I../libbase/include -I../logging/liblog/include -I./include -c $< -o $@ 56 | 57 | .lib/libcutils.a: $(libcutils_obj) 58 | @mkdir -p `dirname $@` 59 | @echo -e "\tAR \t$@" 60 | @$(AR) $@ $^ 61 | 62 | clean: 63 | $(RM) obj .lib 64 | -------------------------------------------------------------------------------- /libcutils/OWNERS: -------------------------------------------------------------------------------- 1 | include platform/system/core:/janitors/OWNERS 2 | -------------------------------------------------------------------------------- /libcutils/TEST_MAPPING: -------------------------------------------------------------------------------- 1 | { 2 | "presubmit": [ 3 | { 4 | "name": "libcutils_test" 5 | } 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /libcutils/android_get_control_env.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | __BEGIN_DECLS 22 | 23 | int __android_get_control_from_env(const char* prefix, const char* name) 24 | __attribute__((visibility("hidden"))); 25 | 26 | __END_DECLS 27 | -------------------------------------------------------------------------------- /libcutils/android_get_control_file_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | TEST(FilesTest, android_get_control_file) { 32 | TemporaryFile tf; 33 | ASSERT_GE(tf.fd, 0); 34 | 35 | std::string key(ANDROID_FILE_ENV_PREFIX); 36 | key += tf.path; 37 | 38 | std::for_each(key.begin(), key.end(), [] (char& c) { c = isalnum(c) ? c : '_'; }); 39 | 40 | EXPECT_EQ(unsetenv(key.c_str()), 0); 41 | EXPECT_EQ(android_get_control_file(tf.path), -1); 42 | 43 | EXPECT_EQ(setenv(key.c_str(), android::base::StringPrintf("%d", tf.fd).c_str(), true), 0); 44 | 45 | EXPECT_EQ(android_get_control_file(tf.path), tf.fd); 46 | close(tf.fd); 47 | EXPECT_EQ(android_get_control_file(tf.path), -1); 48 | EXPECT_EQ(unsetenv(key.c_str()), 0); 49 | EXPECT_EQ(android_get_control_file(tf.path), -1); 50 | } 51 | -------------------------------------------------------------------------------- /libcutils/android_reboot.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #define TAG "android_reboot" 25 | 26 | int android_reboot(unsigned cmd, int /*flags*/, const char* arg) { 27 | int ret; 28 | const char* restart_cmd = NULL; 29 | char* prop_value; 30 | 31 | switch (cmd) { 32 | case ANDROID_RB_RESTART: // deprecated 33 | case ANDROID_RB_RESTART2: 34 | restart_cmd = "reboot"; 35 | break; 36 | case ANDROID_RB_POWEROFF: 37 | restart_cmd = "shutdown"; 38 | break; 39 | case ANDROID_RB_THERMOFF: 40 | restart_cmd = "shutdown,thermal"; 41 | break; 42 | } 43 | if (!restart_cmd) return -1; 44 | if (arg && arg[0]) { 45 | ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg); 46 | } else { 47 | ret = asprintf(&prop_value, "%s", restart_cmd); 48 | } 49 | if (ret < 0) return -1; 50 | ret = property_set(ANDROID_RB_PROPERTY, prop_value); 51 | free(prop_value); 52 | return ret; 53 | } 54 | -------------------------------------------------------------------------------- /libcutils/arch-x86/cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #if defined(__slm__) 18 | /* Values are optimized for Silvermont */ 19 | #define SHARED_CACHE_SIZE (1024*1024) /* Silvermont L2 Cache */ 20 | #define DATA_CACHE_SIZE (24*1024) /* Silvermont L1 Data Cache */ 21 | #else 22 | /* Values are optimized for Atom */ 23 | #define SHARED_CACHE_SIZE (512*1024) /* Atom L2 Cache */ 24 | #define DATA_CACHE_SIZE (24*1024) /* Atom L1 Data Cache */ 25 | #endif 26 | 27 | #define SHARED_CACHE_SIZE_HALF (SHARED_CACHE_SIZE / 2) 28 | #define DATA_CACHE_SIZE_HALF (DATA_CACHE_SIZE / 2) 29 | -------------------------------------------------------------------------------- /libcutils/arch-x86_64/cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Values are optimized for Silvermont */ 18 | #define SHARED_CACHE_SIZE (1024*1024) /* Silvermont L2 Cache */ 19 | #define DATA_CACHE_SIZE (24*1024) /* Silvermont L1 Data Cache */ 20 | 21 | #define SHARED_CACHE_SIZE_HALF (SHARED_CACHE_SIZE / 2) 22 | #define DATA_CACHE_SIZE_HALF (DATA_CACHE_SIZE / 2) 23 | -------------------------------------------------------------------------------- /libcutils/fs_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | // Binary format for the runtime /etc/fs_config_(dirs|files) filesystem override files. 22 | struct fs_path_config_from_file { 23 | uint16_t len; 24 | uint16_t mode; 25 | uint16_t uid; 26 | uint16_t gid; 27 | uint64_t capabilities; 28 | char prefix[]; 29 | } __attribute__((__aligned__(sizeof(uint64_t)))); 30 | 31 | struct fs_path_config { 32 | unsigned mode; 33 | unsigned uid; 34 | unsigned gid; 35 | uint64_t capabilities; 36 | const char* prefix; 37 | }; 38 | -------------------------------------------------------------------------------- /libcutils/include/cutils/android_get_control_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_ANDROID_GET_CONTROL_FILE_H 18 | #define __CUTILS_ANDROID_GET_CONTROL_FILE_H 19 | 20 | #define ANDROID_FILE_ENV_PREFIX "ANDROID_FILE_" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* 27 | * android_get_control_file - simple helper function to get the file 28 | * descriptor of our init-managed file. `path' is the filename path as 29 | * given in init.rc. Returns -1 on error. 30 | */ 31 | int android_get_control_file(const char* path); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* __CUTILS_ANDROID_GET_CONTROL_FILE_H */ 38 | -------------------------------------------------------------------------------- /libcutils/include/cutils/android_reboot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | __BEGIN_DECLS 22 | 23 | /* Commands */ 24 | #define ANDROID_RB_RESTART 0xDEAD0001 /* deprecated. Use RESTART2. */ 25 | #define ANDROID_RB_POWEROFF 0xDEAD0002 26 | #define ANDROID_RB_RESTART2 0xDEAD0003 27 | #define ANDROID_RB_THERMOFF 0xDEAD0004 28 | 29 | /* Properties */ 30 | #define ANDROID_RB_PROPERTY "sys.powerctl" 31 | 32 | /* Android reboot reason stored in this property */ 33 | #define LAST_REBOOT_REASON_PROPERTY "persist.sys.boot.reason" 34 | #define LAST_REBOOT_REASON_FILE "/metadata/bootstat/" LAST_REBOOT_REASON_PROPERTY 35 | 36 | /* Reboot or shutdown the system. 37 | * This call uses ANDROID_RB_PROPERTY to request reboot to init process. 38 | * Due to that, process calling this should have proper selinux permission 39 | * to write to the property or the call will fail. 40 | */ 41 | int android_reboot(unsigned cmd, int flags, const char* arg); 42 | 43 | __END_DECLS 44 | -------------------------------------------------------------------------------- /libcutils/include/cutils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #if defined(__BIONIC__) 22 | #include 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | int ashmem_valid(int fd); 30 | int ashmem_create_region(const char *name, size_t size); 31 | int ashmem_set_prot_region(int fd, int prot); 32 | int ashmem_pin_region(int fd, size_t offset, size_t len); 33 | int ashmem_unpin_region(int fd, size_t offset, size_t len); 34 | int ashmem_get_size_region(int fd); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /libcutils/include/cutils/bitops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_BITOPS_H 18 | #define __CUTILS_BITOPS_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | __BEGIN_DECLS 26 | 27 | static inline int popcount(unsigned int x) { 28 | return __builtin_popcount(x); 29 | } 30 | 31 | static inline int popcountl(unsigned long x) { 32 | return __builtin_popcountl(x); 33 | } 34 | 35 | static inline int popcountll(unsigned long long x) { 36 | return __builtin_popcountll(x); 37 | } 38 | 39 | __END_DECLS 40 | 41 | #endif /* __CUTILS_BITOPS_H */ 42 | -------------------------------------------------------------------------------- /libcutils/include/cutils/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_COMPILER_H 18 | #define ANDROID_CUTILS_COMPILER_H 19 | 20 | /* 21 | * helps the compiler's optimizer predicting branches 22 | */ 23 | 24 | #ifdef __cplusplus 25 | # define CC_LIKELY( exp ) (__builtin_expect( !!(exp), true )) 26 | # define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), false )) 27 | #else 28 | # define CC_LIKELY( exp ) (__builtin_expect( !!(exp), 1 )) 29 | # define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 )) 30 | #endif 31 | 32 | /** 33 | * exports marked symbols 34 | * 35 | * if used on a C++ class declaration, this macro must be inserted 36 | * after the "class" keyword. For instance: 37 | * 38 | * template 39 | * class ANDROID_API Singleton { } 40 | */ 41 | 42 | #define ANDROID_API __attribute__((visibility("default"))) 43 | 44 | #endif // ANDROID_CUTILS_COMPILER_H 45 | -------------------------------------------------------------------------------- /libcutils/include/cutils/config_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_CONFIG_UTILS_H 18 | #define __CUTILS_CONFIG_UTILS_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct cnode cnode; 25 | 26 | 27 | struct cnode 28 | { 29 | cnode *next; 30 | cnode *first_child; 31 | cnode *last_child; 32 | const char *name; 33 | const char *value; 34 | }; 35 | 36 | /* parse a text string into a config node tree */ 37 | void config_load(cnode *root, char *data); 38 | 39 | /* parse a file into a config node tree */ 40 | void config_load_file(cnode *root, const char *fn); 41 | 42 | /* create a single config node */ 43 | cnode* config_node(const char *name, const char *value); 44 | 45 | /* locate a named child of a config node */ 46 | cnode* config_find(cnode *root, const char *name); 47 | 48 | /* look up a child by name and return the boolean value */ 49 | int config_bool(cnode *root, const char *name, int _default); 50 | 51 | /* look up a child by name and return the string value */ 52 | const char* config_str(cnode *root, const char *name, const char *_default); 53 | 54 | /* add a named child to a config node (or modify it if it already exists) */ 55 | void config_set(cnode *root, const char *name, const char *value); 56 | 57 | /* free a config node tree */ 58 | void config_free(cnode *root); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /libcutils/include/cutils/iosched_policy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_IOSCHED_POLICY_H 18 | #define __CUTILS_IOSCHED_POLICY_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef enum { 25 | IoSchedClass_NONE, 26 | IoSchedClass_RT, 27 | IoSchedClass_BE, 28 | IoSchedClass_IDLE, 29 | } IoSchedClass; 30 | 31 | extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio); 32 | extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* __CUTILS_IOSCHED_POLICY_H */ 39 | -------------------------------------------------------------------------------- /libcutils/include/cutils/klog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CUTILS_KLOG_H_ 18 | #define _CUTILS_KLOG_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | __BEGIN_DECLS 25 | 26 | void klog_set_level(int level); 27 | 28 | void klog_write(int level, const char *fmt, ...) 29 | __attribute__ ((format(printf, 2, 3))); 30 | void klog_writev(int level, const struct iovec* iov, int iov_count); 31 | 32 | __END_DECLS 33 | 34 | #define KLOG_ERROR_LEVEL 3 35 | #define KLOG_WARNING_LEVEL 4 36 | #define KLOG_NOTICE_LEVEL 5 37 | #define KLOG_INFO_LEVEL 6 38 | #define KLOG_DEBUG_LEVEL 7 39 | 40 | #define KLOG_ERROR(tag,x...) klog_write(KLOG_ERROR_LEVEL, "<3>" tag ": " x) 41 | #define KLOG_WARNING(tag,x...) klog_write(KLOG_WARNING_LEVEL, "<4>" tag ": " x) 42 | #define KLOG_NOTICE(tag,x...) klog_write(KLOG_NOTICE_LEVEL, "<5>" tag ": " x) 43 | #define KLOG_INFO(tag,x...) klog_write(KLOG_INFO_LEVEL, "<6>" tag ": " x) 44 | #define KLOG_DEBUG(tag,x...) klog_write(KLOG_DEBUG_LEVEL, "<7>" tag ": " x) 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libcutils/include/cutils/log.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libcutils/include/cutils/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #if defined(__GLIBC__) || defined(_WIN32) 27 | /* Declaration of strlcpy() for platforms that don't already have it. */ 28 | size_t strlcpy(char *dst, const char *src, size_t size); 29 | #endif 30 | 31 | #ifdef __cplusplus 32 | } // extern "C" 33 | #endif 34 | -------------------------------------------------------------------------------- /libcutils/include/cutils/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_MISC_H 18 | #define __CUTILS_MISC_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* Load an entire file into a malloc'd chunk of memory 25 | * that is length_of_file + 1 (null terminator). If 26 | * sz is non-zero, return the size of the file via sz. 27 | * Returns 0 on failure. 28 | */ 29 | extern void *load_file(const char *fn, unsigned *sz); 30 | 31 | /* This is the range of UIDs (and GIDs) that are reserved 32 | * for assigning to applications. 33 | */ 34 | #define FIRST_APPLICATION_UID 10000 35 | #define LAST_APPLICATION_UID 99999 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* __CUTILS_MISC_H */ 42 | -------------------------------------------------------------------------------- /libcutils/include/cutils/multiuser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_MULTIUSER_H 18 | #define __CUTILS_MULTIUSER_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef uid_t userid_t; 27 | typedef uid_t appid_t; 28 | 29 | extern userid_t multiuser_get_user_id(uid_t uid); 30 | extern appid_t multiuser_get_app_id(uid_t uid); 31 | 32 | extern uid_t multiuser_get_uid(userid_t user_id, appid_t app_id); 33 | extern uid_t multiuser_get_sdk_sandbox_uid(userid_t user_id, appid_t app_id); 34 | extern uid_t multiuser_convert_sdk_sandbox_to_app_uid(uid_t uid); 35 | 36 | extern gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id); 37 | extern gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id); 38 | extern gid_t multiuser_get_ext_cache_gid(userid_t user_id, appid_t app_id); 39 | extern gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id); 40 | 41 | /* TODO: switch callers over to multiuser_get_shared_gid() */ 42 | extern gid_t multiuser_get_shared_app_gid(uid_t uid); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* __CUTILS_MULTIUSER_H */ 49 | -------------------------------------------------------------------------------- /libcutils/include/cutils/partition_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_PARTITION_WIPED_H__ 18 | #define __CUTILS_PARTITION_WIPED_H__ 19 | 20 | #include 21 | 22 | __BEGIN_DECLS 23 | 24 | int partition_wiped(const char* source); 25 | 26 | __END_DECLS 27 | 28 | #endif /* __CUTILS_PARTITION_WIPED_H__ */ 29 | -------------------------------------------------------------------------------- /libcutils/include/cutils/qtaguid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_QTAGUID_H 18 | #define __CUTILS_QTAGUID_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* 27 | * Set tags (and owning UIDs) for network sockets. 28 | */ 29 | extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid); 30 | 31 | /* 32 | * Untag a network socket before closing. 33 | */ 34 | extern int qtaguid_untagSocket(int sockfd); 35 | 36 | /* 37 | * Enable/disable qtaguid functionnality at a lower level. 38 | * When pacified, the kernel will accept commands but do nothing. 39 | */ 40 | extern int qtaguid_setPacifier(int on); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* __CUTILS_QTAG_UID_H */ 47 | -------------------------------------------------------------------------------- /libcutils/include/cutils/record_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * A simple utility for reading fixed records out of a stream fd 19 | */ 20 | 21 | #ifndef _CUTILS_RECORD_STREAM_H 22 | #define _CUTILS_RECORD_STREAM_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include 29 | 30 | typedef struct RecordStream RecordStream; 31 | 32 | extern RecordStream *record_stream_new(int fd, size_t maxRecordLen); 33 | extern void record_stream_free(RecordStream *p_rs); 34 | 35 | extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord, 36 | size_t *p_outRecordLen); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | 43 | #endif /*_CUTILS_RECORD_STREAM_H*/ 44 | 45 | -------------------------------------------------------------------------------- /libcutils/include/cutils/sched_policy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_SCHED_POLICY_H 18 | #define __CUTILS_SCHED_POLICY_H 19 | 20 | /* 21 | * For backwards compatibility only 22 | * New users should include processgroup/sched_policy.h directly 23 | */ 24 | #include 25 | 26 | #endif /* __CUTILS_SCHED_POLICY_H */ 27 | -------------------------------------------------------------------------------- /libcutils/include/cutils/str_parms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_STR_PARMS_H 18 | #define __CUTILS_STR_PARMS_H 19 | 20 | #include 21 | #include 22 | 23 | __BEGIN_DECLS 24 | 25 | struct str_parms; 26 | 27 | struct str_parms *str_parms_create(void); 28 | struct str_parms *str_parms_create_str(const char *_string); 29 | void str_parms_destroy(struct str_parms *str_parms); 30 | 31 | void str_parms_del(struct str_parms *str_parms, const char *key); 32 | 33 | int str_parms_add_str(struct str_parms *str_parms, const char *key, 34 | const char *value); 35 | int str_parms_add_int(struct str_parms *str_parms, const char *key, int value); 36 | 37 | int str_parms_add_float(struct str_parms *str_parms, const char *key, 38 | float value); 39 | 40 | // Returns non-zero if the str_parms contains the specified key. 41 | int str_parms_has_key(struct str_parms *str_parms, const char *key); 42 | 43 | // Gets value associated with the specified key (if present), placing it in the buffer 44 | // pointed to by the out_val parameter. Returns the length of the returned string value. 45 | // If 'key' isn't in the parms, then return -ENOENT (-2) and leave 'out_val' untouched. 46 | int str_parms_get_str(struct str_parms *str_parms, const char *key, 47 | char *out_val, int len); 48 | int str_parms_get_int(struct str_parms *str_parms, const char *key, 49 | int *out_val); 50 | int str_parms_get_float(struct str_parms *str_parms, const char *key, 51 | float *out_val); 52 | 53 | char *str_parms_to_str(struct str_parms *str_parms); 54 | 55 | /* debug */ 56 | void str_parms_dump(struct str_parms *str_parms); 57 | 58 | __END_DECLS 59 | 60 | #endif /* __CUTILS_STR_PARMS_H */ 61 | -------------------------------------------------------------------------------- /libcutils/include/cutils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #if defined(_WIN32) 22 | #include 23 | #else 24 | #include 25 | #endif 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | // 32 | // Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows. 33 | // 34 | //#if !defined(__GLIBC__) || __GLIBC__ >= 2 && __GLIBC_MINOR__ < 32 35 | //extern pid_t gettid(); 36 | //#endif 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /libcutils/include/cutils/uevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_UEVENT_H 18 | #define __CUTILS_UEVENT_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int uevent_open_socket(int buf_sz, bool passcred); 28 | ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length); 29 | ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid); 30 | ssize_t uevent_kernel_recv(int socket, void *buffer, size_t length, bool require_group, uid_t *uid); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* __CUTILS_UEVENT_H */ 37 | -------------------------------------------------------------------------------- /libcutils/include/private/canned_fs_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | __BEGIN_DECLS 23 | 24 | int load_canned_fs_config(const char* fn); 25 | void canned_fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, 26 | unsigned* gid, unsigned* mode, uint64_t* capabilities); 27 | 28 | __END_DECLS 29 | -------------------------------------------------------------------------------- /libcutils/include/private/fs_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* This file is used to define the properties of the filesystem 18 | ** images generated by build tools (mkbootfs and mkyaffs2image) and 19 | ** by the device side of adb. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #if defined(__BIONIC__) 28 | #include 29 | #else // defined(__BIONIC__) 30 | #include 31 | #endif // defined(__BIONIC__) 32 | 33 | /* Rules for directories and files has moved to system/code/libcutils/fs_config.c */ 34 | 35 | __BEGIN_DECLS 36 | 37 | /* 38 | * Used in: 39 | * build/tools/fs_config/fs_config.c 40 | * build/tools/fs_get_stats/fs_get_stats.c 41 | * system/extras/ext4_utils/make_ext4fs_main.c 42 | * external/squashfs-tools/squashfs-tools/android.c 43 | * system/core/cpio/mkbootfs.c 44 | * system/core/adb/file_sync_service.cpp 45 | * system/extras/ext4_utils/canned_fs_config.c 46 | */ 47 | void fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid, 48 | unsigned* mode, uint64_t* capabilities); 49 | 50 | __END_DECLS 51 | -------------------------------------------------------------------------------- /libcutils/include/utils/Atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_ATOMIC_H 18 | #define ANDROID_UTILS_ATOMIC_H 19 | 20 | // DO NOT USE: Please instead use std::atomic 21 | 22 | #include 23 | 24 | #endif // ANDROID_UTILS_ATOMIC_H 25 | -------------------------------------------------------------------------------- /libcutils/include/utils/ByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | /* 20 | * If you're looking for a portable that's available on Android, 21 | * Linux, macOS, and Windows, see instead. 22 | * 23 | * Nothing in this file is useful because all supported Android ABIs are 24 | * little-endian and all our code that runs on the host assumes that the host is 25 | * also little-endian. What pretense at big-endian support exists is completely 26 | * untested and unlikely to actually work. 27 | */ 28 | 29 | #include 30 | #include 31 | #if defined(_WIN32) 32 | #include 33 | #else 34 | #include 35 | #endif 36 | 37 | /* TODO: move this cruft to frameworks/. */ 38 | 39 | #define dtohl(x) (x) 40 | #define dtohs(x) (x) 41 | #define htodl(x) (x) 42 | #define htods(x) (x) 43 | 44 | #define fromlel(x) (x) 45 | #define tolel(x) (x) 46 | -------------------------------------------------------------------------------- /libcutils/include/utils/Debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | // Note: new code should use static_assert directly. 20 | 21 | #define COMPILE_TIME_ASSERT static_assert 22 | #define COMPILE_TIME_ASSERT_FUNCTION_SCOPE static_assert 23 | -------------------------------------------------------------------------------- /libcutils/include/utils/Endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Android endian-ness defines. 19 | // 20 | #ifndef _LIBS_UTILS_ENDIAN_H 21 | #define _LIBS_UTILS_ENDIAN_H 22 | 23 | #if defined(__APPLE__) || defined(_WIN32) 24 | 25 | #define __BIG_ENDIAN 0x1000 26 | #define __LITTLE_ENDIAN 0x0001 27 | #define __BYTE_ORDER __LITTLE_ENDIAN 28 | 29 | #else 30 | 31 | #include 32 | 33 | #endif 34 | 35 | #endif /*_LIBS_UTILS_ENDIAN_H*/ 36 | -------------------------------------------------------------------------------- /libcutils/include/utils/Functor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_FUNCTOR_H 18 | #define ANDROID_FUNCTOR_H 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | // DO NOT USE: please use 25 | // - C++ lambda 26 | // - class with well-defined and specific functionality and semantics 27 | 28 | class Functor { 29 | public: 30 | Functor() {} 31 | virtual ~Functor() {} 32 | virtual status_t operator()(int /*what*/, void* /*data*/) { return OK; } 33 | }; 34 | 35 | } // namespace android 36 | 37 | #endif // ANDROID_FUNCTOR_H 38 | -------------------------------------------------------------------------------- /libcutils/include/utils/JenkinsHash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Implementation of Jenkins one-at-a-time hash function. These choices are 18 | * optimized for code size and portability, rather than raw speed. But speed 19 | * should still be quite good. 20 | **/ 21 | 22 | #ifndef ANDROID_JENKINS_HASH_H 23 | #define ANDROID_JENKINS_HASH_H 24 | 25 | #include 26 | 27 | namespace android { 28 | 29 | /* The Jenkins hash of a sequence of 32 bit words A, B, C is: 30 | * Whiten(Mix(Mix(Mix(0, A), B), C)) */ 31 | 32 | #ifdef __clang__ 33 | __attribute__((no_sanitize("integer"))) 34 | #endif 35 | inline uint32_t JenkinsHashMix(uint32_t hash, uint32_t data) { 36 | hash += data; 37 | hash += (hash << 10); 38 | hash ^= (hash >> 6); 39 | return hash; 40 | } 41 | 42 | hash_t JenkinsHashWhiten(uint32_t hash); 43 | 44 | /* Helpful utility functions for hashing data in 32 bit chunks */ 45 | uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t* bytes, size_t size); 46 | 47 | uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t* shorts, size_t size); 48 | 49 | } 50 | 51 | #endif // ANDROID_JENKINS_HASH_H 52 | -------------------------------------------------------------------------------- /libcutils/include/utils/Log.h: -------------------------------------------------------------------------------- 1 | // DO NOT INCLUDE ANYTHING NEW IN THIS FILE. 2 | 3 | // has replaced this file and all changes should go there instead. 4 | // This path remains strictly to include that header as there are thousands of 5 | // references to in the tree. 6 | 7 | #include 8 | -------------------------------------------------------------------------------- /libcutils/include/utils/NativeHandle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_NATIVE_HANDLE_H 18 | #define ANDROID_NATIVE_HANDLE_H 19 | 20 | #include 21 | #include 22 | 23 | typedef struct native_handle native_handle_t; 24 | 25 | namespace android { 26 | 27 | class NativeHandle : public LightRefBase { 28 | public: 29 | // Create a refcounted wrapper around a native_handle_t, and declare 30 | // whether the wrapper owns the handle (so that it should clean up the 31 | // handle upon destruction) or not. 32 | // If handle is NULL, no NativeHandle will be created. 33 | static sp create(native_handle_t* handle, bool ownsHandle); 34 | 35 | const native_handle_t* handle() const { 36 | return mHandle; 37 | } 38 | 39 | private: 40 | // for access to the destructor 41 | friend class LightRefBase; 42 | 43 | NativeHandle(native_handle_t* handle, bool ownsHandle); 44 | ~NativeHandle(); 45 | 46 | native_handle_t* mHandle; 47 | bool mOwnsHandle; 48 | 49 | // non-copyable 50 | NativeHandle(const NativeHandle&); 51 | NativeHandle& operator=(const NativeHandle&); 52 | }; 53 | 54 | } // namespace android 55 | 56 | #endif // ANDROID_NATIVE_HANDLE_H 57 | -------------------------------------------------------------------------------- /libcutils/include/utils/StopWatch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace android { 25 | 26 | class StopWatch { 27 | public: 28 | StopWatch(const char* name, int clock = SYSTEM_TIME_MONOTONIC); 29 | ~StopWatch(); 30 | 31 | const char* name() const; 32 | nsecs_t elapsedTime() const; 33 | 34 | void reset(); 35 | 36 | private: 37 | const char* mName; 38 | int mClock; 39 | 40 | nsecs_t mStartTime; 41 | }; 42 | 43 | } // namespace android 44 | -------------------------------------------------------------------------------- /libcutils/include/utils/SystemClock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_SYSTEMCLOCK_H 18 | #define ANDROID_UTILS_SYSTEMCLOCK_H 19 | 20 | #include 21 | #include 22 | 23 | // See https://developer.android.com/reference/android/os/SystemClock 24 | // to learn more about Android's timekeeping facilities. 25 | 26 | namespace android { 27 | 28 | // Returns milliseconds since boot, not counting time spent in deep sleep. 29 | int64_t uptimeMillis(); 30 | // Returns nanoseconds since boot, not counting time spent in deep sleep. 31 | int64_t uptimeNanos(); 32 | // Returns milliseconds since boot, including time spent in sleep. 33 | int64_t elapsedRealtime(); 34 | // Returns nanoseconds since boot, including time spent in sleep. 35 | int64_t elapsedRealtimeNano(); 36 | 37 | } // namespace android 38 | 39 | #endif // ANDROID_UTILS_SYSTEMCLOCK_H 40 | 41 | -------------------------------------------------------------------------------- /libcutils/include/utils/Trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_TRACE_H 18 | #define ANDROID_TRACE_H 19 | 20 | #if defined(_WIN32) 21 | 22 | #define ATRACE_NAME(...) 23 | #define ATRACE_CALL() 24 | 25 | #else // !_WIN32 26 | 27 | #include 28 | 29 | #include 30 | 31 | // See for more ATRACE_* macros. 32 | 33 | // ATRACE_NAME traces from its location until the end of its enclosing scope. 34 | #define _PASTE(x, y) x ## y 35 | #define PASTE(x, y) _PASTE(x,y) 36 | #define ATRACE_NAME(name) ::android::ScopedTrace PASTE(___tracer, __LINE__)(ATRACE_TAG, name) 37 | 38 | // ATRACE_CALL is an ATRACE_NAME that uses the current function name. 39 | #define ATRACE_CALL() ATRACE_NAME(__FUNCTION__) 40 | 41 | namespace android { 42 | 43 | class ScopedTrace { 44 | public: 45 | inline ScopedTrace(uint64_t tag, const char* name) : mTag(tag) { 46 | atrace_begin(mTag, name); 47 | } 48 | 49 | inline ~ScopedTrace() { 50 | atrace_end(mTag); 51 | } 52 | 53 | private: 54 | uint64_t mTag; 55 | }; 56 | 57 | } // namespace android 58 | 59 | #endif // _WIN32 60 | 61 | #endif // ANDROID_TRACE_H 62 | -------------------------------------------------------------------------------- /libcutils/include/utils/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Handy utility functions and portability code. 19 | // 20 | #ifndef _LIBS_UTILS_MISC_H 21 | #define _LIBS_UTILS_MISC_H 22 | 23 | #include 24 | 25 | /* get #of elements in a static array 26 | * DO NOT USE: please use std::vector/std::array instead 27 | */ 28 | #ifndef NELEM 29 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 30 | #endif 31 | 32 | namespace android { 33 | 34 | typedef void (*sysprop_change_callback)(void); 35 | void add_sysprop_change_callback(sysprop_change_callback cb, int priority); 36 | void report_sysprop_change(); 37 | 38 | } // namespace android 39 | 40 | #endif // _LIBS_UTILS_MISC_H 41 | -------------------------------------------------------------------------------- /libcutils/include/utils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREADS_H 18 | #define _LIBS_UTILS_THREADS_H 19 | 20 | /* 21 | * Please, DO NOT USE! 22 | * 23 | * This file is here only for legacy reasons. Instead, include directly 24 | * the headers you need below. 25 | * 26 | */ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #endif // _LIBS_UTILS_THREADS_H 39 | -------------------------------------------------------------------------------- /libcutils/include_outside_system/cutils/bitops.h: -------------------------------------------------------------------------------- 1 | unsupported reparse point -------------------------------------------------------------------------------- /libcutils/include_outside_system/cutils/fs.h: -------------------------------------------------------------------------------- 1 | unsupported reparse point -------------------------------------------------------------------------------- /libcutils/include_outside_system/cutils/misc.h: -------------------------------------------------------------------------------- 1 | unsupported reparse point -------------------------------------------------------------------------------- /libcutils/iosched_policy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright 2007, The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #if defined(__ANDROID__) 27 | #define IOPRIO_WHO_PROCESS (1) 28 | #define IOPRIO_CLASS_SHIFT (13) 29 | #include 30 | #define __android_unused 31 | #else 32 | #define __android_unused __attribute__((__unused__)) 33 | #endif 34 | 35 | int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) { 36 | #if defined(__ANDROID__) 37 | if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | (clazz << IOPRIO_CLASS_SHIFT))) { 38 | return -1; 39 | } 40 | #endif 41 | return 0; 42 | } 43 | 44 | int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) { 45 | #if defined(__ANDROID__) 46 | int rc; 47 | 48 | if ((rc = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid)) < 0) { 49 | return -1; 50 | } 51 | 52 | *clazz = static_cast(rc >> IOPRIO_CLASS_SHIFT); 53 | *ioprio = (rc & 0xff); 54 | #else 55 | *clazz = IoSchedClass_NONE; 56 | *ioprio = 0; 57 | #endif 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /libcutils/klog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | static int klog_level = KLOG_INFO_LEVEL; 32 | 33 | void klog_set_level(int level) { 34 | klog_level = level; 35 | } 36 | 37 | static int __open_klog(void) { 38 | static const char kmsg_device[] = "/dev/kmsg"; 39 | 40 | int ret = android_get_control_file(kmsg_device); 41 | if (ret >= 0) return ret; 42 | return TEMP_FAILURE_RETRY(open(kmsg_device, O_WRONLY | O_CLOEXEC)); 43 | } 44 | 45 | #define LOG_BUF_MAX 512 46 | 47 | void klog_writev(int level, const struct iovec* iov, int iov_count) { 48 | if (level > klog_level) return; 49 | 50 | static int klog_fd = __open_klog(); 51 | if (klog_fd == -1) return; 52 | TEMP_FAILURE_RETRY(writev(klog_fd, iov, iov_count)); 53 | } 54 | 55 | void klog_write(int level, const char* fmt, ...) { 56 | if (level > klog_level) return; 57 | 58 | char buf[LOG_BUF_MAX]; 59 | va_list ap; 60 | va_start(ap, fmt); 61 | vsnprintf(buf, sizeof(buf), fmt, ap); 62 | va_end(ap); 63 | 64 | buf[LOG_BUF_MAX - 1] = 0; 65 | 66 | struct iovec iov[1]; 67 | iov[0].iov_base = buf; 68 | iov[0].iov_len = strlen(buf); 69 | klog_writev(level, iov, 1); 70 | } 71 | -------------------------------------------------------------------------------- /libcutils/load_file.cpp: -------------------------------------------------------------------------------- 1 | /* libs/cutils/load_file.c 2 | ** 3 | ** Copyright 2006, The Android Open Source Project 4 | ** 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); 6 | ** you may not use this file except in compliance with the License. 7 | ** You may obtain a copy of the License at 8 | ** 9 | ** http://www.apache.org/licenses/LICENSE-2.0 10 | ** 11 | ** Unless required by applicable law or agreed to in writing, software 12 | ** distributed under the License is distributed on an "AS IS" BASIS, 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ** See the License for the specific language governing permissions and 15 | ** limitations under the License. 16 | */ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | void *load_file(const char *fn, unsigned *_sz) 25 | { 26 | char *data; 27 | int sz; 28 | int fd; 29 | 30 | data = 0; 31 | fd = open(fn, O_RDONLY); 32 | if(fd < 0) return 0; 33 | 34 | sz = lseek(fd, 0, SEEK_END); 35 | if(sz < 0) goto oops; 36 | 37 | if(lseek(fd, 0, SEEK_SET) != 0) goto oops; 38 | 39 | data = (char*) malloc(sz + 1); 40 | if(data == 0) goto oops; 41 | 42 | if(read(fd, data, sz) != sz) goto oops; 43 | close(fd); 44 | data[sz] = 0; 45 | 46 | if(_sz) *_sz = sz; 47 | return data; 48 | 49 | oops: 50 | close(fd); 51 | if(data != 0) free(data); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /libcutils/native_handle_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | 21 | TEST(native_handle, native_handle_delete) { 22 | ASSERT_EQ(0, native_handle_delete(nullptr)); 23 | } 24 | 25 | TEST(native_handle, native_handle_close) { 26 | ASSERT_EQ(0, native_handle_close(nullptr)); 27 | } 28 | -------------------------------------------------------------------------------- /libcutils/partition_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include /* for BLKGETSIZE */ 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | static int only_one_char(uint8_t *buf, int len, uint8_t c) 29 | { 30 | int i, ret; 31 | 32 | ret = 1; 33 | for (i=0; i 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #define LISTEN_BACKLOG 4 31 | 32 | /* open listen() port on any interface */ 33 | int socket_inaddr_any_server(int port, int type) 34 | { 35 | struct sockaddr_in6 addr; 36 | int s, n; 37 | 38 | memset(&addr, 0, sizeof(addr)); 39 | addr.sin6_family = AF_INET6; 40 | addr.sin6_port = htons(port); 41 | addr.sin6_addr = in6addr_any; 42 | 43 | s = socket(AF_INET6, type, 0); 44 | if (s < 0) return -1; 45 | 46 | n = 1; 47 | setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &n, sizeof(n)); 48 | 49 | if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { 50 | close(s); 51 | return -1; 52 | } 53 | 54 | if (type == SOCK_STREAM) { 55 | int ret; 56 | 57 | ret = listen(s, LISTEN_BACKLOG); 58 | 59 | if (ret < 0) { 60 | close(s); 61 | return -1; 62 | } 63 | } 64 | 65 | return s; 66 | } 67 | -------------------------------------------------------------------------------- /libcutils/socket_local_unix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __SOCKET_LOCAL_H 18 | #define __SOCKET_LOCAL_H 19 | 20 | #define FILESYSTEM_SOCKET_PREFIX "/tmp/" 21 | #define ANDROID_RESERVED_SOCKET_PREFIX "/dev/socket/" 22 | 23 | /* 24 | * Set up a given sockaddr_un, to have it refer to the given 25 | * name in the given namespace. The namespace must be one 26 | * of ANDROID_SOCKET_NAMESPACE_ABSTRACT, 27 | * ANDROID_SOCKET_NAMESPACE_RESERVED, or 28 | * ANDROID_SOCKET_NAMESPACE_FILESYSTEM. Upon success, 29 | * the pointed at sockaddr_un is filled in and the pointed at 30 | * socklen_t is set to indicate the final length. This function 31 | * will fail if the namespace is invalid (not one of the indicated 32 | * constants) or if the name is too long. 33 | * 34 | * @return 0 on success or -1 on failure 35 | */ 36 | int socket_make_sockaddr_un(const char *name, int namespaceId, 37 | struct sockaddr_un *p_addr, socklen_t *alen); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libcutils/sockets.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in 12 | * the documentation and/or other materials provided with the 13 | * distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | 29 | // This file contains socket implementation that can be shared between 30 | // platforms as long as the correct headers are included. 31 | 32 | #include 33 | 34 | int socket_get_local_port(cutils_socket_t sock) { 35 | sockaddr_storage addr; 36 | socklen_t addr_size = sizeof(addr); 37 | 38 | if (getsockname(sock, reinterpret_cast(&addr), &addr_size) == 0) { 39 | // sockaddr_in and sockaddr_in6 always overlap the port field. 40 | return ntohs(reinterpret_cast(&addr)->sin_port); 41 | } 42 | return -1; 43 | } 44 | -------------------------------------------------------------------------------- /libcutils/str_parms_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | static void test_str_parms_str(const char* str, const char* expected) { 21 | str_parms* str_parms = str_parms_create_str(str); 22 | str_parms_add_str(str_parms, "dude", "woah"); 23 | str_parms_add_str(str_parms, "dude", "woah"); 24 | str_parms_del(str_parms, "dude"); 25 | str_parms_dump(str_parms); 26 | char* out_str = str_parms_to_str(str_parms); 27 | str_parms_destroy(str_parms); 28 | ASSERT_STREQ(expected, out_str) << str; 29 | free(out_str); 30 | } 31 | 32 | TEST(str_parms, smoke) { 33 | test_str_parms_str("", ""); 34 | test_str_parms_str(";", ""); 35 | test_str_parms_str("=", ""); 36 | test_str_parms_str("=;", ""); 37 | test_str_parms_str("=bar", ""); 38 | test_str_parms_str("=bar;", ""); 39 | test_str_parms_str("foo=", "foo="); 40 | test_str_parms_str("foo=;", "foo="); 41 | test_str_parms_str("foo=bar", "foo=bar"); 42 | test_str_parms_str("foo=bar;", "foo=bar"); 43 | test_str_parms_str("foo=bar;baz", "foo=bar;baz="); 44 | test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); 45 | test_str_parms_str("foo=bar;baz=bat", "foo=bar;baz=bat"); 46 | test_str_parms_str("foo=bar;baz=bat;", "foo=bar;baz=bat"); 47 | test_str_parms_str("foo=bar1;baz=bat;foo=bar2", "foo=bar2;baz=bat"); 48 | } 49 | 50 | TEST(str_parms, put_ENOMEM) { 51 | // hashmapPut reports errors by setting errno to ENOMEM. 52 | // Test that we're not confused by running in an environment where this is already true. 53 | errno = ENOMEM; 54 | test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); 55 | ASSERT_EQ(ENOMEM, errno); 56 | test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); 57 | } 58 | -------------------------------------------------------------------------------- /libcutils/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998 Todd C. Miller 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | 19 | #if defined(__GLIBC__) || defined(_WIN32) 20 | 21 | #include 22 | 23 | #include 24 | 25 | /* Implementation of strlcpy() for platforms that don't already have it. */ 26 | 27 | /* 28 | * Copy src to string dst of size siz. At most siz-1 characters 29 | * will be copied. Always NUL terminates (unless siz == 0). 30 | * Returns strlen(src); if retval >= siz, truncation occurred. 31 | */ 32 | size_t 33 | strlcpy(char *dst, const char *src, size_t siz) 34 | { 35 | char *d = dst; 36 | const char *s = src; 37 | size_t n = siz; 38 | 39 | /* Copy as many bytes as will fit */ 40 | if (n != 0) { 41 | while (--n != 0) { 42 | if ((*d++ = *s++) == '\0') 43 | break; 44 | } 45 | } 46 | 47 | /* Not enough room in dst, add NUL and traverse rest of src */ 48 | if (n == 0) { 49 | if (siz != 0) 50 | *d = '\0'; /* NUL-terminate dst */ 51 | while (*s++) 52 | ; 53 | } 54 | 55 | return(s - src - 1); /* count does not include NUL */ 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /libcutils/threads.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (C) 2007, The Android Open Source Project 3 | ** 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); 5 | ** you may not use this file except in compliance with the License. 6 | ** You may obtain a copy of the License at 7 | ** 8 | ** http://www.apache.org/licenses/LICENSE-2.0 9 | ** 10 | ** Unless required by applicable law or agreed to in writing, software 11 | ** distributed under the License is distributed on an "AS IS" BASIS, 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | ** See the License for the specific language governing permissions and 14 | ** limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #if defined(__APPLE__) 20 | #include 21 | #elif defined(__linux__) 22 | #include 23 | #include 24 | #elif defined(_WIN32) || defined(__CYGWIN__) 25 | #include 26 | #endif 27 | 28 | #if defined(__BIONIC__) || defined(__GLIBC__) && __GLIBC_MINOR__ >= 32 29 | // No definition needed for Android because we'll just pick up bionic's copy. 30 | // No definition needed for Glibc >= 2.32 because it exposes its own copy. 31 | #else 32 | pid_t gettid() { 33 | #if defined(__APPLE__) 34 | uint64_t tid; 35 | pthread_threadid_np(NULL, &tid); 36 | return tid; 37 | #elif defined(__linux__) 38 | return syscall(__NR_gettid); 39 | #elif defined(_WIN32) || defined(__CYGWIN__) 40 | return GetCurrentThreadId(); 41 | #endif 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /libcutils/trace-host.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | atomic_bool atrace_is_ready = ATOMIC_VAR_INIT(true); 20 | int atrace_marker_fd = -1; 21 | uint64_t atrace_enabled_tags = 0; 22 | 23 | void atrace_set_debuggable(bool /*debuggable*/) {} 24 | void atrace_set_tracing_enabled(bool /*enabled*/) {} 25 | void atrace_update_tags() { } 26 | void atrace_setup() { } 27 | void atrace_begin_body(const char* /*name*/) {} 28 | void atrace_end_body() { } 29 | void atrace_async_begin_body(const char* /*name*/, int32_t /*cookie*/) {} 30 | void atrace_async_end_body(const char* /*name*/, int32_t /*cookie*/) {} 31 | void atrace_instant_body(const char* /*name*/) {} 32 | void atrace_instant_for_track_body(const char* /*trackName*/, 33 | const char* /*name*/) {} 34 | void atrace_int_body(const char* /*name*/, int32_t /*value*/) {} 35 | void atrace_int64_body(const char* /*name*/, int64_t /*value*/) {} 36 | void atrace_init() {} 37 | uint64_t atrace_get_enabled_tags() 38 | { 39 | return ATRACE_TAG_NOT_READY; 40 | } 41 | -------------------------------------------------------------------------------- /libext2_uuid/Android.bp: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Android Open Source Project 2 | 3 | package { 4 | default_applicable_licenses: ["external_e2fsprogs_lib_uuid_license"], 5 | } 6 | 7 | // Added automatically by a large-scale-change 8 | // See: http://go/android-license-faq 9 | license { 10 | name: "external_e2fsprogs_lib_uuid_license", 11 | visibility: [":__subpackages__"], 12 | license_kinds: [ 13 | "SPDX-license-identifier-BSD", 14 | ], 15 | license_text: [ 16 | "COPYING", 17 | ], 18 | } 19 | 20 | cc_library { 21 | name: "libext2_uuid", 22 | host_supported: true, 23 | ramdisk_available: true, 24 | vendor_ramdisk_available: true, 25 | recovery_available: true, 26 | vendor_available: true, 27 | product_available: true, 28 | unique_host_soname: true, 29 | defaults: ["e2fsprogs-defaults"], 30 | srcs: [ 31 | "clear.c", 32 | "compare.c", 33 | "copy.c", 34 | "gen_uuid.c", 35 | "isnull.c", 36 | "pack.c", 37 | "parse.c", 38 | "unpack.c", 39 | "unparse.c", 40 | "uuid_time.c", 41 | ], 42 | target: { 43 | windows: { 44 | enabled: true, 45 | }, 46 | }, 47 | header_libs: ["libext2-headers"], 48 | export_include_dirs: ["."], 49 | export_header_lib_headers: ["libext2-headers"], 50 | apex_available: [ 51 | "//apex_available:platform", 52 | "com.android.virt", 53 | ], 54 | } 55 | -------------------------------------------------------------------------------- /libext2_uuid/COPYING: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 1. Redistributions of source code must retain the above copyright 5 | notice, and the entire permission notice in its entirety, 6 | including the disclaimer of warranties. 7 | 2. Redistributions in binary form must reproduce the above copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote 11 | products derived from this software without specific prior 12 | written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 17 | WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 20 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 21 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 25 | DAMAGE. 26 | -------------------------------------------------------------------------------- /libext2_uuid/Makefile: -------------------------------------------------------------------------------- 1 | CC = clang 2 | AR = ar rcs 3 | RM = rm -rf 4 | SHELL = bash 5 | 6 | E2FS_DEF_DEFINES = \ 7 | -Wall \ 8 | -Werror \ 9 | -Wno-pointer-arith \ 10 | -Wno-sign-compare \ 11 | -Wno-type-limits \ 12 | -Wno-typedef-redefinition \ 13 | -Wno-unused-parameter 14 | 15 | ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT) 16 | # Not a big issue 17 | E2FS_DEF_DEFINES += -Wno-char-subscripts 18 | endif 19 | 20 | override CFLAGS := $(CFLAGS) $(E2FS_DEF_DEFINES) -I./ 21 | 22 | libext2_uuid_src = \ 23 | clear.c \ 24 | compare.c \ 25 | copy.c \ 26 | gen_uuid.c \ 27 | isnull.c \ 28 | pack.c \ 29 | parse.c \ 30 | unpack.c \ 31 | unparse.c \ 32 | uuid_time.c 33 | libext2_uuid_obj = $(patsubst %.c,obj/%.o,$(libext2_uuid_src)) 34 | 35 | .PHONY: all 36 | 37 | all: .lib/libext2_uuid.a 38 | 39 | obj/%.o: %.c 40 | @mkdir -p `dirname $@` 41 | @echo -e "\t CC\t $@" 42 | @$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ 43 | 44 | .lib/libext2_uuid.a: $(libext2_uuid_obj) 45 | @mkdir -p `dirname $@` 46 | @echo -e "\tAR \t$@" 47 | @$(AR) $@ $^ 48 | 49 | clean: 50 | $(RM) obj .lib 51 | -------------------------------------------------------------------------------- /libext2_uuid/clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | * clear.c -- Clear a UUID 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "config.h" 36 | #include "string.h" 37 | 38 | #include "uuidP.h" 39 | 40 | void uuid_clear(uuid_t uu) 41 | { 42 | memset(uu, 0, 16); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libext2_uuid/compare.c: -------------------------------------------------------------------------------- 1 | /* 2 | * compare.c --- compare whether or not two UUID's are the same 3 | * 4 | * Returns 0 if the two UUID's are different, and 1 if they are the same. 5 | * 6 | * Copyright (C) 1996, 1997 Theodore Ts'o. 7 | * 8 | * %Begin-Header% 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, and the entire permission notice in its entirety, 14 | * including the disclaimer of warranties. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. The name of the author may not be used to endorse or promote 19 | * products derived from this software without specific prior 20 | * written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 25 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 32 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 33 | * DAMAGE. 34 | * %End-Header% 35 | */ 36 | 37 | #include "config.h" 38 | #include "uuidP.h" 39 | #include 40 | 41 | #define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1); 42 | 43 | int uuid_compare(const uuid_t uu1, const uuid_t uu2) 44 | { 45 | struct uuid uuid1, uuid2; 46 | 47 | uuid_unpack(uu1, &uuid1); 48 | uuid_unpack(uu2, &uuid2); 49 | 50 | UUCMP(uuid1.time_low, uuid2.time_low); 51 | UUCMP(uuid1.time_mid, uuid2.time_mid); 52 | UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version); 53 | UUCMP(uuid1.clock_seq, uuid2.clock_seq); 54 | return memcmp(uuid1.node, uuid2.node, 6); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /libext2_uuid/config.h: -------------------------------------------------------------------------------- 1 | #ifndef __APPLE__ 2 | #define HAVE_MALLOC_H 1 3 | #endif 4 | 5 | #define ROOT_SYSCONFDIR "/etc" 6 | 7 | #define ENABLE_LIBSPARSE 1 8 | 9 | #define DISABLE_BACKTRACE 1 10 | #define HAVE_DIRENT_H 1 11 | #define HAVE_ERRNO_H 1 12 | #define HAVE_GETOPT_H 1 13 | #define HAVE_GETPWUID_R 1 14 | #define HAVE_INTPTR_T 1 15 | #define HAVE_INTTYPES_H 1 16 | #define HAVE_MMAP 1 17 | #define HAVE_SETJMP_H 1 18 | #define HAVE_SNPRINTF 1 19 | #define HAVE_STDLIB_H 1 20 | #define HAVE_STRCASECMP 1 21 | #define HAVE_STRDUP 1 22 | #define HAVE_STRINGS_H 1 23 | #define HAVE_STRNLEN 1 24 | #define HAVE_STRPTIME 1 25 | #define HAVE_SYSCONF 1 26 | #define HAVE_TYPE_SSIZE_T 1 27 | #define HAVE_UNISTD_H 1 28 | #define HAVE_UTIME_H 1 29 | 30 | #define HAVE_SYS_STAT_H 1 31 | #if !defined(__APPLE__) 32 | # define HAVE_SYS_SYSMACROS_H 1 33 | #endif 34 | #define HAVE_SYS_TIME_H 1 35 | #define HAVE_SYS_TYPES_H 1 36 | 37 | #if defined(_WIN32) 38 | # define HAVE_LINUX_TYPES_H 1 39 | #endif 40 | #if defined(__APPLE__) || defined(__linux__) || defined(__CYGWIN__) 41 | # define HAVE_FCNTL 1 42 | # define HAVE_FSYNC 1 43 | # define HAVE_GETPAGESIZE 1 44 | # define HAVE_NET_IF_H 1 45 | # define HAVE_NETINET_IN_H 1 46 | # define HAVE_PREAD 1 47 | # define HAVE_PWRITE 1 48 | # define HAVE_POSIX_MEMALIGN 1 49 | # define HAVE_SYS_IOCTL_H 1 50 | # define HAVE_SYS_MMAN_H 1 51 | # define HAVE_SYS_MOUNT_H 1 52 | # define HAVE_SYS_PARAM_H 1 53 | # define HAVE_SYS_RESOURCE_H 1 54 | # define HAVE_SYS_SELECT_H 1 55 | # define HAVE_SYS_WAIT_H 1 56 | #endif 57 | #ifdef __APPLE__ 58 | # define HAVE_GETMNTINFO 1 59 | #endif 60 | #if defined(__linux__) 61 | # define HAVE_EXT2_IOCTLS 1 62 | # define HAVE_FALLOCATE 1 63 | # define HAVE_LINUX_FD_H 1 64 | # define HAVE_LINUX_TYPES_H 1 65 | # define HAVE_LSEEK64 1 66 | # define HAVE_LSEEK64_PROTOTYPE 1 67 | # define HAVE_MNTENT_H 1 68 | # define HAVE_PREAD64 1 69 | # define HAVE_PWRITE64 1 70 | # define HAVE_SETMNTENT 1 71 | # define HAVE_SYS_PRCTL_H 1 72 | #endif 73 | -------------------------------------------------------------------------------- /libext2_uuid/configure.in: -------------------------------------------------------------------------------- 1 | dnl 2 | dnl Not used now, for the future when uuid is separated out into its 3 | dnl own package. 4 | dnl 5 | AC_INIT(gen_uuid.c) 6 | AC_PREREQ(2.12) 7 | 8 | AC_CHECK_HEADERS(stdlib.h unistd.h sys/sockio.h net/if.h netinet/in.h) 9 | AC_CHECK_FUNCS(srandom) 10 | AC_OUTPUT(Makefile) 11 | -------------------------------------------------------------------------------- /libext2_uuid/copy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * copy.c --- copy UUIDs 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "config.h" 36 | #include "uuidP.h" 37 | 38 | void uuid_copy(uuid_t dst, const uuid_t src) 39 | { 40 | unsigned char *cp1; 41 | const unsigned char *cp2; 42 | int i; 43 | 44 | for (i=0, cp1 = dst, cp2 = src; i < 16; i++) 45 | *cp1++ = *cp2++; 46 | } 47 | -------------------------------------------------------------------------------- /libext2_uuid/gen_uuid_nt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gen_uuid_nt.c -- Use NT api to generate uuid 3 | * 4 | * Written by Andrey Shedel (andreys@ns.cr.cyco.com) 5 | */ 6 | 7 | 8 | #include "config.h" 9 | #include "uuidP.h" 10 | 11 | #pragma warning(push,4) 12 | 13 | #pragma comment(lib, "ntdll.lib") 14 | 15 | // 16 | // Here is a nice example why it's not a good idea 17 | // to use native API in ordinary applications. 18 | // Number of parameters in function below was changed from 3 to 4 19 | // for NT5. 20 | // 21 | // 22 | // NTSYSAPI 23 | // NTSTATUS 24 | // NTAPI 25 | // NtAllocateUuids( 26 | // OUT PULONG p1, 27 | // OUT PULONG p2, 28 | // OUT PULONG p3, 29 | // OUT PUCHAR Seed // 6 bytes 30 | // ); 31 | // 32 | // 33 | 34 | unsigned long 35 | __stdcall 36 | NtAllocateUuids( 37 | void* p1, // 8 bytes 38 | void* p2, // 4 bytes 39 | void* p3 // 4 bytes 40 | ); 41 | 42 | typedef 43 | unsigned long 44 | (__stdcall* 45 | NtAllocateUuids_2000)( 46 | void* p1, // 8 bytes 47 | void* p2, // 4 bytes 48 | void* p3, // 4 bytes 49 | void* seed // 6 bytes 50 | ); 51 | 52 | 53 | 54 | // 55 | // Nice, but instead of including ntddk.h ot winnt.h 56 | // I should define it here because they MISSED __stdcall in those headers. 57 | // 58 | 59 | __declspec(dllimport) 60 | struct _TEB* 61 | __stdcall 62 | NtCurrentTeb(void); 63 | 64 | 65 | // 66 | // The only way to get version information from the system is to examine 67 | // one stored in PEB. But it's pretty dangerous because this value could 68 | // be altered in image header. 69 | // 70 | 71 | static 72 | int 73 | Nt5(void) 74 | { 75 | //return NtCuttentTeb()->Peb->OSMajorVersion >= 5; 76 | return (int)*(int*)((char*)(int)(*(int*)((char*)NtCurrentTeb() + 0x30)) + 0xA4) >= 5; 77 | } 78 | 79 | 80 | 81 | 82 | void uuid_generate(uuid_t out) 83 | { 84 | if(Nt5()) 85 | { 86 | unsigned char seed[6]; 87 | ((NtAllocateUuids_2000)NtAllocateUuids)(out, ((char*)out)+8, ((char*)out)+12, &seed[0] ); 88 | } 89 | else 90 | { 91 | NtAllocateUuids(out, ((char*)out)+8, ((char*)out)+12); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /libext2_uuid/isnull.c: -------------------------------------------------------------------------------- 1 | /* 2 | * isnull.c --- Check whether or not the UUID is null 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "config.h" 36 | #include "uuidP.h" 37 | 38 | /* Returns 1 if the uuid is the NULL uuid */ 39 | int uuid_is_null(const uuid_t uu) 40 | { 41 | const unsigned char *cp; 42 | int i; 43 | 44 | for (i=0, cp = uu; i < 16; i++) 45 | if (*cp++) 46 | return 0; 47 | return 1; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /libext2_uuid/pack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Internal routine for packing UUID's 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "config.h" 36 | #include 37 | #include "uuidP.h" 38 | 39 | void uuid_pack(const struct uuid *uu, uuid_t ptr) 40 | { 41 | uint32_t tmp; 42 | unsigned char *out = ptr; 43 | 44 | tmp = uu->time_low; 45 | out[3] = (unsigned char) tmp; 46 | tmp >>= 8; 47 | out[2] = (unsigned char) tmp; 48 | tmp >>= 8; 49 | out[1] = (unsigned char) tmp; 50 | tmp >>= 8; 51 | out[0] = (unsigned char) tmp; 52 | 53 | tmp = uu->time_mid; 54 | out[5] = (unsigned char) tmp; 55 | tmp >>= 8; 56 | out[4] = (unsigned char) tmp; 57 | 58 | tmp = uu->time_hi_and_version; 59 | out[7] = (unsigned char) tmp; 60 | tmp >>= 8; 61 | out[6] = (unsigned char) tmp; 62 | 63 | tmp = uu->clock_seq; 64 | out[9] = (unsigned char) tmp; 65 | tmp >>= 8; 66 | out[8] = (unsigned char) tmp; 67 | 68 | memcpy(out+10, uu->node, 6); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /libext2_uuid/unpack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Internal routine for unpacking UUID 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "config.h" 36 | #include 37 | #include "uuidP.h" 38 | 39 | void uuid_unpack(const uuid_t in, struct uuid *uu) 40 | { 41 | const uint8_t *ptr = in; 42 | uint32_t tmp; 43 | 44 | tmp = *ptr++; 45 | tmp = (tmp << 8) | *ptr++; 46 | tmp = (tmp << 8) | *ptr++; 47 | tmp = (tmp << 8) | *ptr++; 48 | uu->time_low = tmp; 49 | 50 | tmp = *ptr++; 51 | tmp = (tmp << 8) | *ptr++; 52 | uu->time_mid = tmp; 53 | 54 | tmp = *ptr++; 55 | tmp = (tmp << 8) | *ptr++; 56 | uu->time_hi_and_version = tmp; 57 | 58 | tmp = *ptr++; 59 | tmp = (tmp << 8) | *ptr++; 60 | uu->clock_seq = tmp; 61 | 62 | memcpy(uu->node, ptr, 6); 63 | } 64 | 65 | -------------------------------------------------------------------------------- /libext2_uuid/uuid.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: uuid 7 | Description: Universally unique id library 8 | Version: @E2FSPROGS_VERSION@ 9 | Requires: 10 | Cflags: -I${includedir}/uuid -I${includedir} 11 | Libs: -L${libdir} -luuid 12 | -------------------------------------------------------------------------------- /libext2_uuid/uuid_clear.3.in: -------------------------------------------------------------------------------- 1 | .\" Copyright 1999 Andreas Dilger (adilger@enel.ucalgary.ca) 2 | .\" 3 | .\" %Begin-Header% 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, and the entire permission notice in its entirety, 9 | .\" including the disclaimer of warranties. 10 | .\" 2. Redistributions in binary form must reproduce the above copyright 11 | .\" notice, this list of conditions and the following disclaimer in the 12 | .\" documentation and/or other materials provided with the distribution. 13 | .\" 3. The name of the author may not be used to endorse or promote 14 | .\" products derived from this software without specific prior 15 | .\" written permission. 16 | .\" 17 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | .\" WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 20 | .\" WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 21 | .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | .\" OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 | .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | .\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | .\" USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 28 | .\" DAMAGE. 29 | .\" %End-Header% 30 | .\" 31 | .\" Created Wed Mar 10 17:42:12 1999, Andreas Dilger 32 | .TH UUID_CLEAR 3 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@" 33 | .SH NAME 34 | uuid_clear \- reset value of UUID variable to the NULL value 35 | .SH SYNOPSIS 36 | .nf 37 | .B #include 38 | .sp 39 | .BI "void uuid_clear(uuid_t " uu ); 40 | .fi 41 | .SH DESCRIPTION 42 | The 43 | .B uuid_clear 44 | function sets the value of the supplied uuid variable 45 | .I uu 46 | to the NULL value. 47 | .SH AUTHOR 48 | Theodore Y. Ts'o 49 | .SH AVAILABILITY 50 | .UR http://e2fsprogs.sourceforge.net/ 51 | http://e2fsprogs.sourceforge.net/ 52 | .UE 53 | .SH "SEE ALSO" 54 | .BR uuid (3), 55 | .BR uuid_compare (3), 56 | .BR uuid_copy (3), 57 | .BR uuid_generate (3), 58 | .BR uuid_is_null (3), 59 | .BR uuid_parse (3), 60 | .BR uuid_unparse (3) 61 | -------------------------------------------------------------------------------- /libext2_uuid/uuid_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * If linux/types.h is already been included, assume it has defined 3 | * everything we need. (cross fingers) Other header files may have 4 | * also defined the types that we need. 5 | */ 6 | #if (!defined(_LINUX_TYPES_H) && !defined(_BLKID_TYPES_H) && \ 7 | !defined(_EXT2_TYPES_H) && !defined(_UUID_TYPES_H)) 8 | #define _UUID_TYPES_H 9 | 10 | typedef unsigned char __u8; 11 | typedef __signed__ char __s8; 12 | typedef unsigned short __u16; 13 | typedef __signed__ short __s16; 14 | typedef unsigned int __u32; 15 | typedef __signed__ int __s32; 16 | typedef unsigned long long __u64; 17 | typedef __signed__ long long __s64; 18 | #endif 19 | 20 | #include //uintptr_t 21 | 22 | /* endian checking stuff */ 23 | #ifndef EXT2_ENDIAN_H_ 24 | #define EXT2_ENDIAN_H_ 25 | 26 | #ifdef __CHECKER__ 27 | #ifndef __bitwise 28 | #define __bitwise __attribute__((bitwise)) 29 | #endif 30 | #define __force __attribute__((force)) 31 | #else 32 | #ifndef __bitwise 33 | #define __bitwise 34 | #endif 35 | #define __force 36 | #endif 37 | 38 | typedef __u16 __bitwise __le16; 39 | typedef __u32 __bitwise __le32; 40 | typedef __u64 __bitwise __le64; 41 | typedef __u16 __bitwise __be16; 42 | typedef __u32 __bitwise __be32; 43 | typedef __u64 __bitwise __be64; 44 | 45 | #endif /* EXT2_ENDIAN_H_ */ 46 | -------------------------------------------------------------------------------- /libext2_uuid/uuid_types.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * If linux/types.h is already been included, assume it has defined 3 | * everything we need. (cross fingers) Other header files may have 4 | * also defined the types that we need. 5 | */ 6 | #if (!defined(_STDINT_H) && !defined(_UUID_STDINT_H)) 7 | #define _UUID_STDINT_H 8 | 9 | typedef unsigned char uint8_t; 10 | typedef signed char int8_t; 11 | 12 | #if (@SIZEOF_INT@ == 8) 13 | typedef int int64_t; 14 | typedef unsigned int uint64_t; 15 | #elif (@SIZEOF_LONG@ == 8) 16 | typedef long int64_t; 17 | typedef unsigned long uint64_t; 18 | #elif (@SIZEOF_LONG_LONG@ == 8) 19 | #if defined(__GNUC__) 20 | typedef __signed__ long long int64_t; 21 | #else 22 | typedef signed long long int64_t; 23 | #endif 24 | typedef unsigned long long uint64_t; 25 | #endif 26 | 27 | #if (@SIZEOF_INT@ == 2) 28 | typedef int int16_t; 29 | typedef unsigned int uint16_t; 30 | #elif (@SIZEOF_SHORT@ == 2) 31 | typedef short int16_t; 32 | typedef unsigned short uint16_t; 33 | #else 34 | ?==error: undefined 16 bit type 35 | #endif 36 | 37 | #if (@SIZEOF_INT@ == 4) 38 | typedef int int32_t; 39 | typedef unsigned int uint32_t; 40 | #elif (@SIZEOF_LONG@ == 4) 41 | typedef long int32_t; 42 | typedef unsigned long uint32_t; 43 | #elif (@SIZEOF_SHORT@ == 4) 44 | typedef short int32_t; 45 | typedef unsigned short uint32_t; 46 | #else 47 | ?== error: undefined 32 bit type 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libext2_uuid/uuidd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Definitions used by the uuidd daemon 3 | * 4 | * Copyright (C) 2007 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #ifndef _UUID_UUIDD_H 36 | #define _UUID_UUIDD_H 37 | 38 | #define UUIDD_DIR "/var/lib/libuuid" 39 | #define UUIDD_SOCKET_PATH UUIDD_DIR "/request" 40 | #define UUIDD_PIDFILE_PATH UUIDD_DIR "/uuidd.pid" 41 | #define UUIDD_PATH "/usr/sbin/uuidd" 42 | 43 | #define UUIDD_OP_GETPID 0 44 | #define UUIDD_OP_GET_MAXOP 1 45 | #define UUIDD_OP_TIME_UUID 2 46 | #define UUIDD_OP_RANDOM_UUID 3 47 | #define UUIDD_OP_BULK_TIME_UUID 4 48 | #define UUIDD_OP_BULK_RANDOM_UUID 5 49 | #define UUIDD_MAX_OP UUIDD_OP_BULK_RANDOM_UUID 50 | 51 | extern void uuid__generate_time(uuid_t out, int *num); 52 | extern void uuid__generate_random(uuid_t out, int *num); 53 | 54 | #endif /* _UUID_UUID_H */ 55 | -------------------------------------------------------------------------------- /libselinux/MODULE_LICENSE_PUBLIC_DOMAIN: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/affggh/erofs-utils_cygwin/86e1a14214659270de4594137f4c3e1997c3ac75/libselinux/MODULE_LICENSE_PUBLIC_DOMAIN -------------------------------------------------------------------------------- /libselinux/Makefile: -------------------------------------------------------------------------------- 1 | override CC = clang 2 | override CXX = clang++ 3 | 4 | CFLAGS = -DAUDITD_LOG_TAG=1003 -Wno-pointer-bool-conversion 5 | 6 | SHELL = bash 7 | 8 | INCLUDES = -Iinclude 9 | 10 | LIBSELINUX_SRC = \ 11 | src/booleans.c \ 12 | src/canonicalize_context.c \ 13 | src/disable.c \ 14 | src/enabled.c \ 15 | src/fgetfilecon.c \ 16 | src/fsetfilecon.c \ 17 | src/getenforce.c \ 18 | src/getfilecon.c \ 19 | src/getpeercon.c \ 20 | src/lgetfilecon.c \ 21 | src/load_policy.c \ 22 | src/lsetfilecon.c \ 23 | src/policyvers.c \ 24 | src/procattr.c \ 25 | src/setenforce.c \ 26 | src/setfilecon.c \ 27 | src/context.c \ 28 | src/mapping.c \ 29 | src/stringrep.c \ 30 | src/compute_create.c \ 31 | src/compute_av.c \ 32 | src/avc.c \ 33 | src/avc_sidtab.c \ 34 | src/get_initial_context.c \ 35 | src/sestatus.c \ 36 | src/deny_unknown.c \ 37 | src/callbacks.c \ 38 | src/check_context.c \ 39 | src/freecon.c \ 40 | src/init.c \ 41 | src/label.c \ 42 | src/label_file.c \ 43 | src/label_android_property.c \ 44 | src/label_support.c 45 | 46 | ifeq ($(shell uname -s | cut -d"_" -f1), MINGW64) 47 | filterout = \ 48 | src/fgetfilecon.c \ 49 | src/fsetfilecon.c \ 50 | src/getfilecon.c \ 51 | src/getpeercon.c \ 52 | src/lgetfilecon.c \ 53 | src/lsetfilecon.c \ 54 | src/setfilecon.c \ 55 | src/init.c 56 | LIBSELINUX_SRC := $(filter-out $(filterout),$(LIBSELINUX_SRC)) mman.c 57 | endif 58 | LIBSELINUX_OBJ = $(patsubst %.c,obj/%.o,$(LIBSELINUX_SRC)) 59 | 60 | obj/%.o: %.c 61 | @mkdir -p `dirname $@` 62 | @echo -e "\033[94m\tCC\t$@\033[0m" 63 | @$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ 64 | 65 | .lib/libselinux.a: $(LIBSELINUX_OBJ) 66 | @mkdir -p `dirname $@` 67 | @echo -e "\033[94m\tAR\t$@\033[0m" 68 | @$(AR) rcs $@ $^ 69 | 70 | clean: 71 | ifeq ($(shell [[ -d "obj" ]];echo $$?), 0) 72 | @echo -e "\033[94m\tRM\tobj\033[0m" 73 | @rm -rf obj 74 | endif 75 | ifeq ($(shell [[ -d ".lib" ]];echo $$?), 0) 76 | @echo -e "\033[94m\tRM\t.lib\033[0m" 77 | @rm -rf .lib 78 | endif 79 | -------------------------------------------------------------------------------- /libselinux/NOTICE: -------------------------------------------------------------------------------- 1 | This library (libselinux) is public domain software, i.e. not copyrighted. 2 | 3 | Warranty Exclusion 4 | ------------------ 5 | You agree that this software is a 6 | non-commercially developed program that may contain "bugs" (as that 7 | term is used in the industry) and that it may not function as intended. 8 | The software is licensed "as is". NSA makes no, and hereby expressly 9 | disclaims all, warranties, express, implied, statutory, or otherwise 10 | with respect to the software, including noninfringement and the implied 11 | warranties of merchantability and fitness for a particular purpose. 12 | 13 | Limitation of Liability 14 | ----------------------- 15 | In no event will NSA be liable for any damages, including loss of data, 16 | lost profits, cost of cover, or other special, incidental, 17 | consequential, direct or indirect damages arising from the software or 18 | the use thereof, however caused and on any theory of liability. This 19 | limitation will apply even if NSA has been advised of the possibility 20 | of such damage. You acknowledge that this is a reasonable allocation of 21 | risk. 22 | -------------------------------------------------------------------------------- /libselinux/include/asprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef ASPRINTF_H 2 | #define ASPRINTF_H 3 | 4 | #if defined(__GNUC__) && ! defined(_GNU_SOURCE) 5 | #define _GNU_SOURCE /* needed for (v)asprintf, affects '#include ' */ 6 | #endif 7 | #include /* needed for vsnprintf */ 8 | #include /* needed for malloc, free */ 9 | #include /* needed for va_* */ 10 | 11 | /* 12 | * vscprintf: 13 | * MSVC implements this as _vscprintf, thus we just 'symlink' it here 14 | * GNU-C-compatible compilers do not implement this, thus we implement it here 15 | */ 16 | #ifdef _MSC_VER 17 | #define vscprintf _vscprintf 18 | #endif 19 | 20 | #ifdef __GNUC__ 21 | int vscprintf(const char *format, va_list ap) 22 | { 23 | va_list ap_copy; 24 | va_copy(ap_copy, ap); 25 | int retval = vsnprintf(NULL, 0, format, ap_copy); 26 | va_end(ap_copy); 27 | return retval; 28 | } 29 | #endif 30 | 31 | /* 32 | * asprintf, vasprintf: 33 | * MSVC does not implement these, thus we implement them here 34 | * GNU-C-compatible compilers implement these with the same names, thus we 35 | * don't have to do anything 36 | */ 37 | #ifdef _MSC_VER 38 | int vasprintf(char **strp, const char *format, va_list ap) 39 | { 40 | int len = vscprintf(format, ap); 41 | if (len == -1) 42 | return -1; 43 | char *str = (char*)malloc((size_t) len + 1); 44 | if (!str) 45 | return -1; 46 | int retval = vsnprintf(str, len + 1, format, ap); 47 | if (retval == -1) { 48 | free(str); 49 | return -1; 50 | } 51 | *strp = str; 52 | return retval; 53 | } 54 | 55 | int asprintf(char **strp, const char *format, ...) 56 | { 57 | va_list ap; 58 | va_start(ap, format); 59 | int retval = vasprintf(strp, format, ap); 60 | va_end(ap); 61 | return retval; 62 | } 63 | #endif 64 | 65 | #endif // ASPRINTF_H -------------------------------------------------------------------------------- /libselinux/include/selinux/android.h: -------------------------------------------------------------------------------- 1 | #ifndef _SELINUX_ANDROID_H_ 2 | #define _SELINUX_ANDROID_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | extern struct selabel_handle* selinux_android_file_context_handle(void); 15 | 16 | extern struct selabel_handle* selinux_android_prop_context_handle(void); 17 | 18 | extern struct selabel_handle* selinux_android_service_context_handle(void); 19 | 20 | extern void selinux_android_set_sehandle(const struct selabel_handle *hndl); 21 | 22 | extern int selinux_android_load_policy(void); 23 | 24 | extern int selinux_android_reload_policy(void); 25 | 26 | extern int selinux_android_setcon(const char *con); 27 | 28 | extern int selinux_android_setcontext(uid_t uid, 29 | bool isSystemServer, 30 | const char *seinfo, 31 | const char *name); 32 | 33 | extern int selinux_android_setfilecon(const char *pkgdir, 34 | const char *pkgname, 35 | const char *seinfo, 36 | uid_t uid); 37 | 38 | extern int selinux_log_callback(int type, const char *fmt, ...) 39 | __attribute__ ((format(printf, 2, 3))); 40 | 41 | #define SELINUX_ANDROID_RESTORECON_NOCHANGE 1 42 | #define SELINUX_ANDROID_RESTORECON_VERBOSE 2 43 | #define SELINUX_ANDROID_RESTORECON_RECURSE 4 44 | #define SELINUX_ANDROID_RESTORECON_FORCE 8 45 | #define SELINUX_ANDROID_RESTORECON_DATADATA 16 46 | extern int selinux_android_restorecon(const char *file, unsigned int flags); 47 | 48 | extern int selinux_android_restorecon_pkgdir(const char *pkgdir, 49 | const char *seinfo, 50 | uid_t uid, 51 | unsigned int flags); 52 | 53 | extern int selinux_android_seapp_context_reload(void); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | #endif 59 | -------------------------------------------------------------------------------- /libselinux/include/selinux/context.h: -------------------------------------------------------------------------------- 1 | #ifndef _SELINUX_CONTEXT_H_ 2 | #define _SELINUX_CONTEXT_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * Functions to deal with security contexts in user space. 10 | */ 11 | 12 | typedef struct { 13 | void *ptr; 14 | } context_s_t; 15 | 16 | typedef context_s_t *context_t; 17 | 18 | /* Return a new context initialized to a context string */ 19 | 20 | extern context_t context_new(const char *); 21 | 22 | /* 23 | * Return a pointer to the string value of the context_t 24 | * Valid until the next call to context_str or context_free 25 | * for the same context_t* 26 | */ 27 | 28 | extern char *context_str(context_t); 29 | 30 | /* Free the storage used by a context */ 31 | extern void context_free(context_t); 32 | 33 | /* Get a pointer to the string value of a context component */ 34 | 35 | extern const char *context_type_get(context_t); 36 | extern const char *context_range_get(context_t); 37 | extern const char *context_role_get(context_t); 38 | extern const char *context_user_get(context_t); 39 | 40 | /* Set a context component. Returns nonzero if unsuccessful */ 41 | 42 | extern int context_type_set(context_t, const char *); 43 | extern int context_range_set(context_t, const char *); 44 | extern int context_role_set(context_t, const char *); 45 | extern int context_user_set(context_t, const char *); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | #endif 51 | -------------------------------------------------------------------------------- /libselinux/mman.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sys/mman.h 3 | * mman-win32 4 | */ 5 | 6 | #ifndef _SYS_MMAN_H_ 7 | #define _SYS_MMAN_H_ 8 | 9 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 10 | #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 11 | #endif 12 | 13 | /* All the headers include this file. */ 14 | #ifndef _MSC_VER 15 | #include <_mingw.h> 16 | #endif 17 | 18 | #if defined(MMAN_LIBRARY_DLL) 19 | /* Windows shared libraries (DLL) must be declared export when building the lib and import when building the 20 | application which links against the library. */ 21 | #if defined(MMAN_LIBRARY) 22 | #define MMANSHARED_EXPORT __declspec(dllexport) 23 | #else 24 | #define MMANSHARED_EXPORT __declspec(dllimport) 25 | #endif /* MMAN_LIBRARY */ 26 | #else 27 | /* Static libraries do not require a __declspec attribute.*/ 28 | #define MMANSHARED_EXPORT 29 | #endif /* MMAN_LIBRARY_DLL */ 30 | 31 | /* Determine offset type */ 32 | #include 33 | #if defined(_WIN64) 34 | typedef int64_t OffsetType; 35 | #else 36 | typedef uint32_t OffsetType; 37 | #endif 38 | 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | #define PROT_NONE 0 46 | #define PROT_READ 1 47 | #define PROT_WRITE 2 48 | #define PROT_EXEC 4 49 | 50 | #define MAP_FILE 0 51 | #define MAP_SHARED 1 52 | #define MAP_PRIVATE 2 53 | #define MAP_TYPE 0xf 54 | #define MAP_FIXED 0x10 55 | #define MAP_ANONYMOUS 0x20 56 | #define MAP_ANON MAP_ANONYMOUS 57 | 58 | #define MAP_FAILED ((void *)-1) 59 | 60 | /* Flags for msync. */ 61 | #define MS_ASYNC 1 62 | #define MS_SYNC 2 63 | #define MS_INVALIDATE 4 64 | 65 | MMANSHARED_EXPORT void* mmap(void *addr, size_t len, int prot, int flags, int fildes, OffsetType off); 66 | MMANSHARED_EXPORT int munmap(void *addr, size_t len); 67 | MMANSHARED_EXPORT int _mprotect(void *addr, size_t len, int prot); 68 | MMANSHARED_EXPORT int msync(void *addr, size_t len, int flags); 69 | MMANSHARED_EXPORT int mlock(const void *addr, size_t len); 70 | MMANSHARED_EXPORT int munlock(const void *addr, size_t len); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* _SYS_MMAN_H_ */ 77 | -------------------------------------------------------------------------------- /libselinux/src/avc_sidtab.h: -------------------------------------------------------------------------------- 1 | /* 2 | * A security identifier table (sidtab) is a hash table 3 | * of security context structures indexed by SID value. 4 | */ 5 | #ifndef _SELINUX_AVC_SIDTAB_H_ 6 | #define _SELINUX_AVC_SIDTAB_H_ 7 | 8 | #include 9 | #include 10 | #include "dso.h" 11 | 12 | struct sidtab_node { 13 | struct security_id sid_s; 14 | struct sidtab_node *next; 15 | }; 16 | 17 | #define SIDTAB_HASH_BITS 7 18 | #define SIDTAB_HASH_BUCKETS (1 << SIDTAB_HASH_BITS) 19 | #define SIDTAB_HASH_MASK (SIDTAB_HASH_BUCKETS-1) 20 | #define SIDTAB_SIZE SIDTAB_HASH_BUCKETS 21 | 22 | struct sidtab { 23 | struct sidtab_node **htable; 24 | unsigned nel; 25 | }; 26 | 27 | int sidtab_init(struct sidtab *s) hidden; 28 | int sidtab_insert(struct sidtab *s, const char * ctx) hidden; 29 | 30 | int sidtab_context_to_sid(struct sidtab *s, 31 | const char * ctx, security_id_t * sid) hidden; 32 | 33 | void sidtab_sid_stats(struct sidtab *s, char *buf, int buflen) hidden; 34 | void sidtab_destroy(struct sidtab *s) hidden; 35 | 36 | #endif /* _SELINUX_AVC_SIDTAB_H_ */ 37 | -------------------------------------------------------------------------------- /libselinux/src/callbacks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file describes the callbacks passed to selinux_init() and available 3 | * for use from the library code. They all have default implementations. 4 | */ 5 | #ifndef _SELINUX_CALLBACKS_H_ 6 | #define _SELINUX_CALLBACKS_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "dso.h" 13 | 14 | /* callback pointers */ 15 | extern int __attribute__ ((format(printf, 2, 3))) 16 | (*selinux_log) (int type, const char *, ...) hidden; 17 | 18 | extern int 19 | (*selinux_audit) (void *, security_class_t, char *, size_t) hidden; 20 | 21 | extern int 22 | (*selinux_validate)(char **ctx) hidden; 23 | 24 | extern int 25 | (*selinux_netlink_setenforce) (int enforcing) hidden; 26 | 27 | extern int 28 | (*selinux_netlink_policyload) (int seqno) hidden; 29 | 30 | #endif /* _SELINUX_CALLBACKS_H_ */ 31 | -------------------------------------------------------------------------------- /libselinux/src/canonicalize_context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "selinux_internal.h" 9 | #include "policy.h" 10 | #include 11 | 12 | int security_canonicalize_context(const char * con, 13 | char ** canoncon) 14 | { 15 | char path[PATH_MAX]; 16 | char *buf; 17 | size_t size; 18 | int fd, ret; 19 | 20 | if (!selinux_mnt) { 21 | errno = ENOENT; 22 | return -1; 23 | } 24 | 25 | snprintf(path, sizeof path, "%s/context", selinux_mnt); 26 | fd = open(path, O_RDWR); 27 | if (fd < 0) 28 | return -1; 29 | 30 | size = selinux_page_size; 31 | buf = malloc(size); 32 | if (!buf) { 33 | ret = -1; 34 | goto out; 35 | } 36 | strncpy(buf, con, size); 37 | 38 | ret = write(fd, buf, strlen(buf) + 1); 39 | if (ret < 0) 40 | goto out2; 41 | 42 | memset(buf, 0, size); 43 | ret = read(fd, buf, size - 1); 44 | if (ret < 0 && errno == EINVAL) { 45 | /* Fall back to the original context for kernels 46 | that do not support the extended interface. */ 47 | strncpy(buf, con, size); 48 | } 49 | 50 | *canoncon = strdup(buf); 51 | if (!(*canoncon)) { 52 | ret = -1; 53 | goto out2; 54 | } 55 | ret = 0; 56 | out2: 57 | free(buf); 58 | out: 59 | close(fd); 60 | return ret; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /libselinux/src/checkAccess.c: -------------------------------------------------------------------------------- 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "selinux_internal.h" 7 | #include 8 | #include "avc_internal.h" 9 | 10 | static pthread_once_t once = PTHREAD_ONCE_INIT; 11 | static int selinux_enabled; 12 | 13 | static void avc_init_once(void) 14 | { 15 | selinux_enabled = is_selinux_enabled(); 16 | if (selinux_enabled == 1) 17 | avc_open(NULL, 0); 18 | } 19 | 20 | int selinux_check_access(const char * scon, const char * tcon, const char *class, const char *perm, void *aux) { 21 | int rc; 22 | security_id_t scon_id; 23 | security_id_t tcon_id; 24 | security_class_t sclass; 25 | access_vector_t av; 26 | 27 | __selinux_once(once, avc_init_once); 28 | 29 | if (selinux_enabled != 1) 30 | return 0; 31 | 32 | rc = avc_context_to_sid(scon, &scon_id); 33 | if (rc < 0) 34 | return rc; 35 | 36 | rc = avc_context_to_sid(tcon, &tcon_id); 37 | if (rc < 0) 38 | return rc; 39 | 40 | sclass = string_to_security_class(class); 41 | if (sclass == 0) { 42 | rc = errno; 43 | avc_log(SELINUX_ERROR, "Unknown class %s", class); 44 | if (security_deny_unknown() == 0) 45 | return 0; 46 | errno = rc; 47 | return -1; 48 | } 49 | 50 | av = string_to_av_perm(sclass, perm); 51 | if (av == 0) { 52 | rc = errno; 53 | avc_log(SELINUX_ERROR, "Unknown permission %s for class %s", perm, class); 54 | if (security_deny_unknown() == 0) 55 | return 0; 56 | errno = rc; 57 | return -1; 58 | } 59 | 60 | return avc_has_perm (scon_id, tcon_id, sclass, av, NULL, aux); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /libselinux/src/check_context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "selinux_internal.h" 9 | #include "policy.h" 10 | #include 11 | 12 | int security_check_context(const char * con) 13 | { 14 | char path[PATH_MAX]; 15 | int fd, ret; 16 | 17 | if (!selinux_mnt) { 18 | errno = ENOENT; 19 | return -1; 20 | } 21 | 22 | snprintf(path, sizeof path, "%s/context", selinux_mnt); 23 | fd = open(path, O_RDWR); 24 | if (fd < 0) 25 | return -1; 26 | 27 | ret = write(fd, con, strlen(con) + 1); 28 | close(fd); 29 | if (ret < 0) 30 | return -1; 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /libselinux/src/compute_av.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "selinux_internal.h" 10 | #include "policy.h" 11 | #include "mapping.h" 12 | 13 | int security_compute_av(const char * scon, 14 | const char * tcon, 15 | security_class_t tclass, 16 | access_vector_t requested, 17 | struct av_decision *avd) 18 | { 19 | char path[PATH_MAX]; 20 | char *buf; 21 | size_t len; 22 | int fd, ret; 23 | 24 | if (!selinux_mnt) { 25 | errno = ENOENT; 26 | return -1; 27 | } 28 | 29 | snprintf(path, sizeof path, "%s/access", selinux_mnt); 30 | fd = open(path, O_RDWR); 31 | if (fd < 0) 32 | return -1; 33 | 34 | len = selinux_page_size; 35 | buf = malloc(len); 36 | if (!buf) { 37 | ret = -1; 38 | goto out; 39 | } 40 | 41 | snprintf(buf, len, "%s %s %hu %x", scon, tcon, 42 | unmap_class(tclass), unmap_perm(tclass, requested)); 43 | 44 | ret = write(fd, buf, strlen(buf)); 45 | if (ret < 0) 46 | goto out2; 47 | 48 | memset(buf, 0, len); 49 | ret = read(fd, buf, len - 1); 50 | if (ret < 0) 51 | goto out2; 52 | 53 | ret = sscanf(buf, "%x %x %x %x %u %x", 54 | &avd->allowed, &avd->decided, 55 | &avd->auditallow, &avd->auditdeny, 56 | &avd->seqno, &avd->flags); 57 | if (ret < 5) { 58 | ret = -1; 59 | goto out2; 60 | } else if (ret < 6) 61 | avd->flags = 0; 62 | 63 | map_decision(tclass, avd); 64 | 65 | ret = 0; 66 | out2: 67 | free(buf); 68 | out: 69 | close(fd); 70 | return ret; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /libselinux/src/compute_create.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "selinux_internal.h" 10 | #include "policy.h" 11 | #include "mapping.h" 12 | 13 | int security_compute_create(const char * scon, 14 | const char * tcon, 15 | security_class_t tclass, 16 | char ** newcon) 17 | { 18 | char path[PATH_MAX]; 19 | char *buf; 20 | size_t size; 21 | int fd, ret; 22 | 23 | if (!selinux_mnt) { 24 | errno = ENOENT; 25 | return -1; 26 | } 27 | 28 | snprintf(path, sizeof path, "%s/create", selinux_mnt); 29 | fd = open(path, O_RDWR); 30 | if (fd < 0) 31 | return -1; 32 | 33 | size = selinux_page_size; 34 | buf = malloc(size); 35 | if (!buf) { 36 | ret = -1; 37 | goto out; 38 | } 39 | snprintf(buf, size, "%s %s %hu", scon, tcon, unmap_class(tclass)); 40 | 41 | ret = write(fd, buf, strlen(buf)); 42 | if (ret < 0) 43 | goto out2; 44 | 45 | memset(buf, 0, size); 46 | ret = read(fd, buf, size - 1); 47 | if (ret < 0) 48 | goto out2; 49 | 50 | *newcon = strdup(buf); 51 | if (!(*newcon)) { 52 | ret = -1; 53 | goto out2; 54 | } 55 | ret = 0; 56 | out2: 57 | free(buf); 58 | out: 59 | close(fd); 60 | return ret; 61 | } 62 | -------------------------------------------------------------------------------- /libselinux/src/context_internal.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dso.h" 3 | 4 | hidden_proto(context_new) 5 | hidden_proto(context_free) 6 | hidden_proto(context_str) 7 | hidden_proto(context_type_set) 8 | hidden_proto(context_type_get) 9 | hidden_proto(context_role_set) 10 | hidden_proto(context_role_get) 11 | hidden_proto(context_user_set) 12 | hidden_proto(context_user_get) 13 | hidden_proto(context_range_set) 14 | hidden_proto(context_range_get) 15 | -------------------------------------------------------------------------------- /libselinux/src/deny_unknown.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | #include 10 | #include 11 | 12 | int security_deny_unknown(void) 13 | { 14 | int fd, ret, deny_unknown = 0; 15 | char path[PATH_MAX]; 16 | char buf[20]; 17 | 18 | if (!selinux_mnt) { 19 | errno = ENOENT; 20 | return -1; 21 | } 22 | 23 | snprintf(path, sizeof(path), "%s/deny_unknown", selinux_mnt); 24 | fd = open(path, O_RDONLY); 25 | if (fd < 0) 26 | return -1; 27 | 28 | memset(buf, 0, sizeof(buf)); 29 | ret = read(fd, buf, sizeof(buf) - 1); 30 | close(fd); 31 | if (ret < 0) 32 | return -1; 33 | 34 | if (sscanf(buf, "%d", &deny_unknown) != 1) 35 | return -1; 36 | 37 | return deny_unknown; 38 | } 39 | 40 | hidden_def(security_deny_unknown); 41 | -------------------------------------------------------------------------------- /libselinux/src/disable.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | #include 10 | #include 11 | 12 | int security_disable(void) 13 | { 14 | int fd, ret; 15 | char path[PATH_MAX]; 16 | char buf[20]; 17 | 18 | if (!selinux_mnt) { 19 | errno = ENOENT; 20 | return -1; 21 | } 22 | 23 | snprintf(path, sizeof path, "%s/disable", selinux_mnt); 24 | fd = open(path, O_WRONLY); 25 | if (fd < 0) 26 | return -1; 27 | 28 | buf[0] = '1'; 29 | buf[1] = '\0'; 30 | ret = write(fd, buf, strlen(buf)); 31 | close(fd); 32 | if (ret < 0) 33 | return -1; 34 | 35 | return 0; 36 | } 37 | 38 | hidden_def(security_disable) 39 | -------------------------------------------------------------------------------- /libselinux/src/dso.h: -------------------------------------------------------------------------------- 1 | #ifndef _SELINUX_DSO_H 2 | #define _SELINUX_DSO_H 1 3 | 4 | #ifdef SHARED 5 | # define hidden __attribute__ ((visibility ("hidden"))) 6 | # define hidden_proto(fct) __hidden_proto (fct, fct##_internal) 7 | # define __hidden_proto(fct, internal) \ 8 | extern __typeof (fct) internal; \ 9 | extern __typeof (fct) fct __asm (#internal) hidden; 10 | # if defined(__alpha__) || defined(__mips__) 11 | # define hidden_def(fct) \ 12 | asm (".globl " #fct "\n" #fct " = " #fct "_internal"); 13 | # else 14 | # define hidden_def(fct) \ 15 | asm (".globl " #fct "\n.set " #fct ", " #fct "_internal"); 16 | #endif 17 | #else 18 | # define hidden 19 | # define hidden_proto(fct) 20 | # define hidden_def(fct) 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libselinux/src/enabled.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "selinux_internal.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "policy.h" 10 | 11 | int is_selinux_enabled(void) 12 | { 13 | /* init_selinuxmnt() gets called before this function. We 14 | * will assume that if a selinux file system is mounted, then 15 | * selinux is enabled. */ 16 | return (selinux_mnt ? 1 : 0); 17 | } 18 | 19 | hidden_def(is_selinux_enabled) 20 | 21 | /* 22 | * Function: is_selinux_mls_enabled() 23 | * Return: 1 on success 24 | * 0 on failure 25 | */ 26 | int is_selinux_mls_enabled(void) 27 | { 28 | char buf[20], path[PATH_MAX]; 29 | int fd, ret, enabled = 0; 30 | 31 | if (!selinux_mnt) 32 | return enabled; 33 | 34 | snprintf(path, sizeof path, "%s/mls", selinux_mnt); 35 | fd = open(path, O_RDONLY); 36 | if (fd < 0) 37 | return enabled; 38 | 39 | memset(buf, 0, sizeof buf); 40 | 41 | do { 42 | ret = read(fd, buf, sizeof buf - 1); 43 | } while (ret < 0 && errno == EINTR); 44 | close(fd); 45 | if (ret < 0) 46 | return enabled; 47 | 48 | if (!strcmp(buf, "1")) 49 | enabled = 1; 50 | 51 | return enabled; 52 | } 53 | 54 | hidden_def(is_selinux_mls_enabled) 55 | -------------------------------------------------------------------------------- /libselinux/src/fgetfilecon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | 10 | int fgetfilecon(int fd, char ** context) 11 | { 12 | char *buf; 13 | ssize_t size; 14 | ssize_t ret; 15 | 16 | size = INITCONTEXTLEN + 1; 17 | buf = malloc(size); 18 | if (!buf) 19 | return -1; 20 | memset(buf, 0, size); 21 | 22 | ret = fgetxattr(fd, XATTR_NAME_SELINUX, buf, size - 1); 23 | if (ret < 0 && errno == ERANGE) { 24 | char *newbuf; 25 | 26 | size = fgetxattr(fd, XATTR_NAME_SELINUX, NULL, 0); 27 | if (size < 0) 28 | goto out; 29 | 30 | size++; 31 | newbuf = realloc(buf, size); 32 | if (!newbuf) 33 | goto out; 34 | 35 | buf = newbuf; 36 | memset(buf, 0, size); 37 | ret = fgetxattr(fd, XATTR_NAME_SELINUX, buf, size - 1); 38 | } 39 | out: 40 | if (ret == 0) { 41 | /* Re-map empty attribute values to errors. */ 42 | errno = EOPNOTSUPP; 43 | ret = -1; 44 | } 45 | if (ret < 0) 46 | free(buf); 47 | else 48 | *context = buf; 49 | return ret; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /libselinux/src/freecon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "selinux_internal.h" 3 | #include 4 | #include 5 | 6 | void freecon(char * con) 7 | { 8 | free(con); 9 | } 10 | 11 | hidden_def(freecon) 12 | -------------------------------------------------------------------------------- /libselinux/src/fsetfilecon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | 10 | int fsetfilecon(int fd, const char *context) 11 | { 12 | return fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 13 | 0); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /libselinux/src/get_initial_context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "selinux_internal.h" 9 | #include "policy.h" 10 | #include 11 | 12 | #define SELINUX_INITCON_DIR "/initial_contexts/" 13 | 14 | int security_get_initial_context(const char * name, char ** con) 15 | { 16 | char path[PATH_MAX]; 17 | char *buf; 18 | size_t size; 19 | int fd, ret; 20 | 21 | if (!selinux_mnt) { 22 | errno = ENOENT; 23 | return -1; 24 | } 25 | 26 | snprintf(path, sizeof path, "%s%s%s", 27 | selinux_mnt, SELINUX_INITCON_DIR, name); 28 | fd = open(path, O_RDONLY); 29 | if (fd < 0) 30 | return -1; 31 | 32 | size = selinux_page_size; 33 | buf = malloc(size); 34 | if (!buf) { 35 | ret = -1; 36 | goto out; 37 | } 38 | memset(buf, 0, size); 39 | ret = read(fd, buf, size - 1); 40 | if (ret < 0) 41 | goto out2; 42 | 43 | *con = strdup(buf); 44 | if (!(*con)) { 45 | ret = -1; 46 | goto out2; 47 | } 48 | ret = 0; 49 | out2: 50 | free(buf); 51 | out: 52 | close(fd); 53 | return ret; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /libselinux/src/getenforce.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | #include 10 | #include 11 | 12 | int security_getenforce(void) 13 | { 14 | int fd, ret, enforce = 0; 15 | char path[PATH_MAX]; 16 | char buf[20]; 17 | 18 | if (!selinux_mnt) { 19 | errno = ENOENT; 20 | return -1; 21 | } 22 | 23 | snprintf(path, sizeof path, "%s/enforce", selinux_mnt); 24 | fd = open(path, O_RDONLY); 25 | if (fd < 0) 26 | return -1; 27 | 28 | memset(buf, 0, sizeof buf); 29 | ret = read(fd, buf, sizeof buf - 1); 30 | close(fd); 31 | if (ret < 0) 32 | return -1; 33 | 34 | if (sscanf(buf, "%d", &enforce) != 1) 35 | return -1; 36 | 37 | return enforce; 38 | } 39 | 40 | hidden_def(security_getenforce) 41 | -------------------------------------------------------------------------------- /libselinux/src/getfilecon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "selinux_internal.h" 5 | #include 6 | #include 7 | #include 8 | #include "policy.h" 9 | 10 | int getfilecon(const char *path, char ** context) 11 | { 12 | char *buf; 13 | ssize_t size; 14 | ssize_t ret; 15 | 16 | size = INITCONTEXTLEN + 1; 17 | buf = malloc(size); 18 | if (!buf) 19 | return -1; 20 | memset(buf, 0, size); 21 | 22 | ret = getxattr(path, XATTR_NAME_SELINUX, buf, size - 1); 23 | if (ret < 0 && errno == ERANGE) { 24 | char *newbuf; 25 | 26 | size = getxattr(path, XATTR_NAME_SELINUX, NULL, 0); 27 | if (size < 0) 28 | goto out; 29 | 30 | size++; 31 | newbuf = realloc(buf, size); 32 | if (!newbuf) 33 | goto out; 34 | 35 | buf = newbuf; 36 | memset(buf, 0, size); 37 | ret = getxattr(path, XATTR_NAME_SELINUX, buf, size - 1); 38 | } 39 | out: 40 | if (ret == 0) { 41 | /* Re-map empty attribute values to errors. */ 42 | errno = EOPNOTSUPP; 43 | ret = -1; 44 | } 45 | if (ret < 0) 46 | free(buf); 47 | else 48 | *context = buf; 49 | return ret; 50 | } 51 | -------------------------------------------------------------------------------- /libselinux/src/getpeercon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | 10 | #ifndef SO_PEERSEC 11 | #define SO_PEERSEC 31 12 | #endif 13 | 14 | int getpeercon(int fd, char ** context) 15 | { 16 | char *buf; 17 | socklen_t size; 18 | ssize_t ret; 19 | 20 | size = INITCONTEXTLEN + 1; 21 | buf = malloc(size); 22 | if (!buf) 23 | return -1; 24 | memset(buf, 0, size); 25 | 26 | ret = getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &size); 27 | if (ret < 0 && errno == ERANGE) { 28 | char *newbuf; 29 | 30 | newbuf = realloc(buf, size); 31 | if (!newbuf) 32 | goto out; 33 | 34 | buf = newbuf; 35 | memset(buf, 0, size); 36 | ret = getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &size); 37 | } 38 | out: 39 | if (ret < 0) 40 | free(buf); 41 | else 42 | *context = buf; 43 | return ret; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /libselinux/src/lgetfilecon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | 10 | int lgetfilecon(const char *path, char ** context) 11 | { 12 | char *buf; 13 | ssize_t size; 14 | ssize_t ret; 15 | 16 | size = INITCONTEXTLEN + 1; 17 | buf = malloc(size); 18 | if (!buf) 19 | return -1; 20 | memset(buf, 0, size); 21 | 22 | ret = lgetxattr(path, XATTR_NAME_SELINUX, buf, size - 1); 23 | if (ret < 0 && errno == ERANGE) { 24 | char *newbuf; 25 | 26 | size = lgetxattr(path, XATTR_NAME_SELINUX, NULL, 0); 27 | if (size < 0) 28 | goto out; 29 | 30 | size++; 31 | newbuf = realloc(buf, size); 32 | if (!newbuf) 33 | goto out; 34 | 35 | buf = newbuf; 36 | memset(buf, 0, size); 37 | ret = lgetxattr(path, XATTR_NAME_SELINUX, buf, size - 1); 38 | } 39 | out: 40 | if (ret == 0) { 41 | /* Re-map empty attribute values to errors. */ 42 | errno = EOPNOTSUPP; 43 | ret = -1; 44 | } 45 | if (ret < 0) 46 | free(buf); 47 | else 48 | *context = buf; 49 | return ret; 50 | } 51 | -------------------------------------------------------------------------------- /libselinux/src/load_policy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #ifndef __MINGW32__ 5 | #include 6 | #include 7 | #include 8 | #else 9 | #include "../mman.h" 10 | #endif 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "selinux_internal.h" 18 | #ifndef __MINGW32__ 19 | #include 20 | #endif 21 | #include "policy.h" 22 | #include 23 | #include "callbacks.h" 24 | 25 | int security_load_policy(void *data, size_t len) 26 | { 27 | char path[PATH_MAX]; 28 | int fd, ret; 29 | 30 | if (!selinux_mnt) { 31 | errno = ENOENT; 32 | return -1; 33 | } 34 | 35 | snprintf(path, sizeof path, "%s/load", selinux_mnt); 36 | fd = open(path, O_RDWR); 37 | if (fd < 0) 38 | return -1; 39 | 40 | ret = write(fd, data, len); 41 | close(fd); 42 | if (ret < 0) 43 | return -1; 44 | return 0; 45 | } 46 | 47 | hidden_def(security_load_policy) 48 | -------------------------------------------------------------------------------- /libselinux/src/lsetfilecon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | 10 | int lsetfilecon(const char *path, const char *context) 11 | { 12 | return lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 13 | 0); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /libselinux/src/mapping.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file describes the class and permission mappings used to 3 | * hide the kernel numbers from userspace by allowing userspace object 4 | * managers to specify a list of classes and permissions. 5 | */ 6 | #ifndef _SELINUX_MAPPING_H_ 7 | #define _SELINUX_MAPPING_H_ 8 | 9 | #include 10 | 11 | /* 12 | * Get real, kernel values from mapped values 13 | */ 14 | 15 | extern security_class_t 16 | unmap_class(security_class_t tclass); 17 | 18 | extern access_vector_t 19 | unmap_perm(security_class_t tclass, access_vector_t tperm); 20 | 21 | /* 22 | * Get mapped values from real, kernel values 23 | */ 24 | 25 | extern security_class_t 26 | map_class(security_class_t kclass); 27 | 28 | extern access_vector_t 29 | map_perm(security_class_t tclass, access_vector_t kperm); 30 | 31 | extern void 32 | map_decision(security_class_t tclass, struct av_decision *avd); 33 | 34 | /*mapping is not used for embedded build*/ 35 | #ifdef DISABLE_AVC 36 | #define unmap_perm(x,y) y 37 | #define unmap_class(x) x 38 | #define map_decision(x,y) 39 | #endif 40 | 41 | #endif /* _SELINUX_MAPPING_H_ */ 42 | -------------------------------------------------------------------------------- /libselinux/src/policy.h: -------------------------------------------------------------------------------- 1 | #ifndef _POLICY_H_ 2 | #define _POLICY_H_ 3 | 4 | /* Private definitions used internally by libselinux. */ 5 | 6 | /* xattr name for SELinux attributes. */ 7 | #define XATTR_NAME_SELINUX "security.selinux" 8 | 9 | /* Initial length guess for getting contexts. */ 10 | #define INITCONTEXTLEN 255 11 | 12 | /* selinuxfs magic number */ 13 | #define SELINUX_MAGIC 0xf97cff8c 14 | 15 | /* Preferred selinuxfs mount point directory paths. */ 16 | #define SELINUXMNT "/sys/fs/selinux" 17 | #define OLDSELINUXMNT "/selinux" 18 | 19 | /* selinuxfs filesystem type string. */ 20 | #define SELINUXFS "selinuxfs" 21 | 22 | /* selinuxfs mount point determined at runtime */ 23 | extern char *selinux_mnt; 24 | 25 | /* First version of policy supported in mainline Linux. */ 26 | #define DEFAULT_POLICY_VERSION 15 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libselinux/src/policyvers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include 9 | #include "policy.h" 10 | #include "dso.h" 11 | #include 12 | 13 | int security_policyvers(void) 14 | { 15 | int fd, ret; 16 | char path[PATH_MAX]; 17 | char buf[20]; 18 | unsigned vers = DEFAULT_POLICY_VERSION; 19 | 20 | if (!selinux_mnt) { 21 | errno = ENOENT; 22 | return -1; 23 | } 24 | 25 | snprintf(path, sizeof path, "%s/policyvers", selinux_mnt); 26 | fd = open(path, O_RDONLY); 27 | if (fd < 0) { 28 | if (errno == ENOENT) 29 | return vers; 30 | else 31 | return -1; 32 | } 33 | memset(buf, 0, sizeof buf); 34 | ret = read(fd, buf, sizeof buf - 1); 35 | close(fd); 36 | if (ret < 0) 37 | return -1; 38 | 39 | if (sscanf(buf, "%u", &vers) != 1) 40 | return -1; 41 | 42 | return vers; 43 | } 44 | 45 | hidden_def(security_policyvers) 46 | -------------------------------------------------------------------------------- /libselinux/src/selinux_netlink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Netlink event notifications for SELinux. 3 | * 4 | * Author: James Morris 5 | */ 6 | #ifndef _LINUX_SELINUX_NETLINK_H 7 | #define _LINUX_SELINUX_NETLINK_H 8 | 9 | /* Message types. */ 10 | #define SELNL_MSG_BASE 0x10 11 | enum { 12 | SELNL_MSG_SETENFORCE = SELNL_MSG_BASE, 13 | SELNL_MSG_POLICYLOAD, 14 | SELNL_MSG_MAX 15 | }; 16 | 17 | /* Multicast groups */ 18 | #define SELNL_GRP_NONE 0x00000000 19 | #define SELNL_GRP_AVC 0x00000001 /* AVC notifications */ 20 | #define SELNL_GRP_ALL 0xffffffff 21 | 22 | /* Message structures */ 23 | struct selnl_msg_setenforce { 24 | int32_t val; 25 | }; 26 | 27 | struct selnl_msg_policyload { 28 | uint32_t seqno; 29 | }; 30 | 31 | #endif /* _LINUX_SELINUX_NETLINK_H */ 32 | -------------------------------------------------------------------------------- /libselinux/src/setenforce.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | #include 10 | #include 11 | 12 | int security_setenforce(int value) 13 | { 14 | int fd, ret; 15 | char path[PATH_MAX]; 16 | char buf[20]; 17 | 18 | if (!selinux_mnt) { 19 | errno = ENOENT; 20 | return -1; 21 | } 22 | 23 | snprintf(path, sizeof path, "%s/enforce", selinux_mnt); 24 | fd = open(path, O_RDWR); 25 | if (fd < 0) 26 | return -1; 27 | 28 | snprintf(buf, sizeof buf, "%d", value); 29 | ret = write(fd, buf, strlen(buf)); 30 | close(fd); 31 | if (ret < 0) 32 | return -1; 33 | 34 | return 0; 35 | } 36 | 37 | hidden_def(security_setenforce) 38 | -------------------------------------------------------------------------------- /libselinux/src/setfilecon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "selinux_internal.h" 8 | #include "policy.h" 9 | 10 | int setfilecon(const char *path, const char *context) 11 | { 12 | return setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 13 | 0); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0+ 2 | 3 | dist_man_MANS = mkfs.erofs.1 dump.erofs.1 fsck.erofs.1 4 | 5 | EXTRA_DIST = erofsfuse.1 6 | if ENABLE_FUSE 7 | man_MANS = erofsfuse.1 8 | endif 9 | -------------------------------------------------------------------------------- /man/dump.erofs.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2021 Guo Xuenan 2 | .\" 3 | .TH DUMP.EROFS 1 4 | .SH NAME 5 | dump.erofs \- retrieve directory and file entries, show specific file 6 | or overall disk statistics information from an EROFS-formatted image. 7 | .SH SYNOPSIS 8 | \fBdump.erofs\fR [\fIOPTIONS\fR] \fIIMAGE\fR 9 | .SH DESCRIPTION 10 | .B dump.erofs 11 | is used to retrieve erofs metadata from \fIIMAGE\fP and demonstrate 12 | .br 13 | 1) overall disk statistics, 14 | .br 15 | 2) superblock information, 16 | .br 17 | 3) file information of the given inode NID, 18 | .br 19 | 4) file extent information of the given inode NID. 20 | .SH OPTIONS 21 | .TP 22 | .BI "\-\-device=" path 23 | Specify an extra device to be used together. 24 | You may give multiple 25 | .B --device 26 | options in the correct order. 27 | .TP 28 | .BI "\-\-ls" 29 | List directory contents. 30 | .I NID 31 | or 32 | .I path 33 | required. 34 | .TP 35 | .BI "\-\-nid=" NID 36 | Specify an inode NID in order to print its file information. 37 | .TP 38 | .BI "\-\-path=" path 39 | Specify an inode path in order to print its file information. 40 | .TP 41 | .BI \-e 42 | Show the file extent information. 43 | .I NID 44 | or 45 | .I path 46 | required. 47 | .TP 48 | .BI \-V 49 | Print the version number and exit. 50 | .TP 51 | .BI \-s 52 | Show superblock information. 53 | This is the default if no options are specified. 54 | .TP 55 | .BI \-S 56 | Show image statistics, including file type/size distribution, number of (un)compressed files, compression ratio, etc. 57 | .SH AUTHOR 58 | Initial code was written by Wang Qi , Guo Xuenan . 59 | .PP 60 | This manual page was written by Guo Xuenan 61 | .SH AVAILABILITY 62 | .B dump.erofs 63 | is part of erofs-utils package and is available from git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git. 64 | .SH SEE ALSO 65 | .BR mkfs.erofs(1), 66 | .BR fsck.erofs(1) 67 | -------------------------------------------------------------------------------- /man/erofsfuse.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2021 Gao Xiang 2 | .\" 3 | .TH EROFSFUSE 1 4 | .SH NAME 5 | erofsfuse \- FUSE file system client for erofs file system 6 | .SH SYNOPSIS 7 | \fBerofsfuse\fR [\fIOPTIONS\fR] \fIDEVICE\fR \fIMOUNTPOINT\fR 8 | .SH DESCRIPTION 9 | .B erofsfuse 10 | is a FUSE file system client that supports reading from devices or image files 11 | containing erofs file system. 12 | .SH OPTIONS 13 | .SS "general options:" 14 | .TP 15 | \fB\-o\fR opt,[opt...] 16 | mount options 17 | .TP 18 | \fB\-h\fR \fB\-\-help\fR 19 | display help and exit 20 | .SS "erofsfuse options:" 21 | .TP 22 | .BI "\-\-dbglevel=" # 23 | Specify the level of debugging messages. The default is 2, which shows basic 24 | warning messages. 25 | .TP 26 | .BI "\-\-device=" path 27 | Specify an extra device to be used together. 28 | You may give multiple `--device' options in the correct order. 29 | .TP 30 | .BI "\-\-offset=" # 31 | Specify `--offset' bytes to skip when reading image file. The default is 0. 32 | .SS "FUSE options:" 33 | .TP 34 | \fB-d -o\fR debug 35 | enable debug output (implies -f) 36 | .TP 37 | \fB-f\fR 38 | foreground operation 39 | .TP 40 | \fB-s\fR 41 | disable multi-threaded operation 42 | .P 43 | For other FUSE options please see 44 | .BR mount.fuse (8) 45 | or see the output of 46 | .I erofsfuse \-\-help 47 | .SH AVAILABILITY 48 | \fBerofsfuse\fR is part of erofs-utils package and is available from 49 | git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git. 50 | .SH SEE ALSO 51 | .BR mount.fuse (8) 52 | -------------------------------------------------------------------------------- /man/fsck.erofs.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2021 Daeho Jeong 2 | .\" 3 | .TH FSCK.EROFS 1 4 | .SH NAME 5 | fsck.erofs \- tool to check an EROFS filesystem's integrity 6 | .SH SYNOPSIS 7 | \fBfsck.erofs\fR [\fIOPTIONS\fR] \fIIMAGE\fR 8 | .SH DESCRIPTION 9 | fsck.erofs is used to scan an EROFS filesystem \fIIMAGE\fR and check the 10 | integrity of it. 11 | .SH OPTIONS 12 | .TP 13 | .B \-V 14 | Print the version number of fsck.erofs and exit. 15 | .TP 16 | .BI "\-d " # 17 | Specify the level of debugging messages. The default is 2, which shows basic 18 | warning messages. 19 | .TP 20 | .B \-p 21 | Print total compression ratio of all files including compressed and 22 | non-compressed files. 23 | .TP 24 | .BI "\-\-device=" path 25 | Specify an extra blob device to be used together. 26 | You may give multiple 27 | .B --device 28 | options in the correct order. 29 | .TP 30 | .B \-\-extract 31 | Check if all files are well encoded. This read all compressed files, 32 | and hence create more I/O load, 33 | so it might take too much time depending on the image. 34 | .TP 35 | .B \-\-help 36 | Display help string and exit. 37 | .SH AUTHOR 38 | This version of \fBfsck.erofs\fR is written by 39 | Daeho Jeong . 40 | .SH AVAILABILITY 41 | \fBfsck.erofs\fR is part of erofs-utils package and is available from 42 | git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git. 43 | .SH SEE ALSO 44 | .BR fsck (8). 45 | -------------------------------------------------------------------------------- /mkfs/Makefile.am: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0+ 2 | 3 | AUTOMAKE_OPTIONS = foreign 4 | bin_PROGRAMS = mkfs.erofs 5 | AM_CPPFLAGS = ${libselinux_CFLAGS} 6 | mkfs_erofs_SOURCES = main.c 7 | mkfs_erofs_CFLAGS = -Wall -I$(top_srcdir)/include 8 | mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \ 9 | ${libuuid_LIBS} ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} \ 10 | ${libdeflate_LIBS} 11 | -------------------------------------------------------------------------------- /patch/logging/0002-Patch-liblog-on-cygwin-add-Makefile.patch: -------------------------------------------------------------------------------- 1 | From 1562ad87784c5b5da5b7e7f6c0bbf5950343f1a4 Mon Sep 17 00:00:00 2001 2 | From: affggh <879632264@qq.com> 3 | Date: Wed, 12 Apr 2023 18:05:16 +0800 4 | Subject: [PATCH] Patch liblog on cygwin add Makefile 5 | 6 | --- 7 | Makefile | 44 ++++++++++++++++++++++++++++++++++++++++++++ 8 | 1 file changed, 44 insertions(+) 9 | create mode 100644 Makefile 10 | 11 | diff --git a/Makefile b/Makefile 12 | new file mode 100644 13 | index 00000000..b765e3a2 14 | --- /dev/null 15 | +++ b/Makefile 16 | @@ -0,0 +1,44 @@ 17 | +CC = clang 18 | +CXX = clang++ 19 | +AR = ar rcs 20 | +SHELL = bash 21 | +RM = rm -rf 22 | + 23 | +CXXFLAGS = -std=c++17 24 | + 25 | +ifeq ($(shell uname -s | cut -d "-" -f 1), CYGWIN_NT) 26 | +override CXXFLAGS := $(CXXFLAGS) -stdlib=libc++ -static -D_Bool=bool 27 | +endif 28 | + 29 | +INCLUDES = -include"../cygprefix.h" 30 | + 31 | +liblog_src = \ 32 | + liblog/log_event_list.cpp \ 33 | + liblog/log_event_write.cpp \ 34 | + liblog/logger_name.cpp \ 35 | + liblog/logger_read.cpp \ 36 | + liblog/logger_write.cpp \ 37 | + liblog/logprint.cpp \ 38 | + liblog/properties.cpp 39 | +liblog_obj = $(patsubst %.cpp,obj/%.o,$(liblog_src)) 40 | +liblog_cxxflags = $(CXXFLAGS) \ 41 | + -Wall \ 42 | + -Wextra \ 43 | + -Wexit-time-destructors \ 44 | + -DLIBLOG_LOG_TAG=1006 \ 45 | + -DSNET_EVENT_LOG_TAG=1397638484 46 | + 47 | +.PHONY: all 48 | + 49 | +all: .lib/liblog.a 50 | + 51 | +obj/%.o: %.cpp 52 | + @mkdir -p `dirname $@` 53 | + @echo -e "\t CPP\t $@" 54 | + @$(CXX) $(liblog_cxxflags) -I./liblog/include -I../libbase/include -I../libcutils/include $(INCLUDES) -c $< -o $@ 55 | + 56 | +.lib/liblog.a: $(liblog_obj) 57 | + @mkdir -p `dirname $@` 58 | + @echo -e "\tAR \t$@" 59 | + @$(AR) $@ $^ 60 | + 61 | +clean: 62 | + $(RM) obj .lib 63 | \ No newline at end of file 64 | -- 65 | 2.39.0 66 | 67 | -------------------------------------------------------------------------------- /patch/logging/0003-Fix-logger_write.cpp.patch: -------------------------------------------------------------------------------- 1 | From 7eb9b7fb0f7884935f3f93d6bc3562e813e886fe Mon Sep 17 00:00:00 2001 2 | From: affggh <879632264@qq.com> 3 | Date: Thu, 13 Apr 2023 13:54:53 +0800 4 | Subject: [PATCH] Fix logger_write.cpp 5 | 6 | --- 7 | liblog/logger_write.cpp | 6 ++++-- 8 | 1 file changed, 4 insertions(+), 2 deletions(-) 9 | 10 | diff --git a/liblog/logger_write.cpp b/liblog/logger_write.cpp 11 | index 08ab6e20..17e6d3ed 100644 12 | --- a/liblog/logger_write.cpp 13 | +++ b/liblog/logger_write.cpp 14 | @@ -48,7 +48,7 @@ 15 | #include 16 | #elif defined(__linux__) && !defined(__ANDROID__) 17 | #include 18 | -#elif defined(_WIN32) 19 | +#elif defined(_WIN32) || defined(__CYGWIN__) 20 | #include 21 | #endif 22 | 23 | @@ -110,6 +110,7 @@ void __android_log_close() { 24 | 25 | // BSD-based systems like Android/macOS have getprogname(). Others need us to provide one. 26 | #if !defined(__APPLE__) && !defined(__BIONIC__) 27 | +#ifndef __CYGWIN__ 28 | static const char* getprogname() { 29 | #ifdef _WIN32 30 | static bool first = true; 31 | @@ -132,6 +133,7 @@ static const char* getprogname() { 32 | return program_invocation_short_name; 33 | #endif 34 | } 35 | +#endif // __CYGWIN__ 36 | #endif 37 | 38 | // It's possible for logging to happen during static initialization before our globals are 39 | @@ -237,7 +239,7 @@ static uint64_t GetThreadId() { 40 | return tid; 41 | #elif defined(__linux__) 42 | return syscall(__NR_gettid); 43 | -#elif defined(_WIN32) 44 | +#elif defined(_WIN32) || defined(__CYGWIN__) 45 | return GetCurrentThreadId(); 46 | #endif 47 | } 48 | -- 49 | 2.39.0 50 | 51 | -------------------------------------------------------------------------------- /scripts/cyg-get-version-number: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: GPL-2.0 3 | 4 | cyg_version() { 5 | # just simple version + date + modifier 6 | modifier="affggh" 7 | os="$(uname -o)" 8 | local_date=$(date +%y%m%d) 9 | 10 | printf "%s%s-%s-%d" '-' "$modifier" "$os" "$local_date" 11 | } 12 | 13 | echo $(sed -n '1p' VERSION | tr -d '\n')$(cyg_version) -------------------------------------------------------------------------------- /scripts/get-version-number: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: GPL-2.0 3 | 4 | scm_version() 5 | { 6 | # Check for git and a git repo. 7 | if test -z "$(git rev-parse --show-cdup 2>/dev/null)" && 8 | head="$(git rev-parse --verify HEAD 2>/dev/null)"; then 9 | # If we are at a tagged commit, we ignore it. 10 | if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then 11 | # Add -g and 8 hex chars. 12 | printf '%s%s' -g "$(echo $head | cut -c1-8)" 13 | fi 14 | # Check for uncommitted changes. 15 | # This script must avoid any write attempt to the source tree, 16 | # which might be read-only. 17 | # You cannot use 'git describe --dirty' because it tries to 18 | # create .git/index.lock . 19 | # First, with git-status, but --no-optional-locks is only 20 | # supported in git >= 2.14, so fall back to git-diff-index if 21 | # it fails. Note that git-diff-index does not refresh the 22 | # index, so it may give misleading results. See 23 | # git-update-index(1), git-diff-index(1), and git-status(1). 24 | if { 25 | git --no-optional-locks status -uno --porcelain 2>/dev/null || 26 | git diff-index --name-only HEAD 27 | } | read dummy; then 28 | printf '%s' -dirty 29 | fi 30 | fi 31 | } 32 | 33 | echo $(sed -n '1p' VERSION | tr -d '\n')$(scm_version) 34 | -------------------------------------------------------------------------------- /scripts/patch-all: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | patch_all() { 4 | patch_dirs=$(ls patch/) 5 | current_dir=$(pwd) 6 | for i in $patch_dirs; do 7 | echo "- Patch working at dir $i..." 8 | cd "$i" 9 | 10 | patches=$(find "$current_dir/patch/$i" -name \*.patch | tr "\n" " ") 11 | for j in $patches; do 12 | echo "- Patching file $j..." 13 | # Reset Before patch 14 | git reset --hard HEAD 15 | patch -t -p1 -N -l -i "$j" 16 | done 17 | 18 | cd "$current_dir" 19 | done 20 | # add for extract.erofs 21 | if [ "$(uname -o)" = "Cygwin" ]; then 22 | if [ -d "extract" ]; then 23 | echo "- Detect cygwin environment, patch extract.erofs source" 24 | list_of_extract=$(find extract/extract -name \*.cpp | tr "\n" " ") 25 | for i in $list_of_extract; do 26 | # Remove unsupport attribute on clang-8 27 | sed -i "s/\[\[unlikely\]\]//g" "$i" 28 | sed -i "s/\[\[likely\]\]//g" "$i" 29 | done 30 | fi 31 | fi 32 | } 33 | 34 | patch_all -------------------------------------------------------------------------------- /winfsp/install.sh: -------------------------------------------------------------------------------- 1 | cd "$(dirname "$0")" 2 | case $(uname -m) in 3 | x86_64) 4 | tar -C/ -xaf x64/fuse-*.tar.xz 5 | tar -C/ -xaf x64/fuse3-*.tar.xz 6 | ;; 7 | i686) 8 | tar -C/ -xaf x86/fuse-*.tar.xz 9 | tar -C/ -xaf x86/fuse3-*.tar.xz 10 | ;; 11 | *) 12 | echo unsupported architecture 1>&2 13 | exit 1 14 | ;; 15 | esac 16 | echo FUSE for Cygwin installed. 17 | -------------------------------------------------------------------------------- /winfsp/uninstall.sh: -------------------------------------------------------------------------------- 1 | cd "$(dirname "$0")" 2 | case $(uname -m) in 3 | x86_64) 4 | tar -taf x64/fuse-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f 5 | tar -taf x64/fuse3-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f 6 | ;; 7 | i686) 8 | tar -taf x86/fuse-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f 9 | tar -taf x86/fuse3-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f 10 | ;; 11 | *) 12 | echo unsupported architecture 1>&2 13 | exit 1 14 | ;; 15 | esac 16 | echo FUSE for Cygwin uninstalled. 17 | -------------------------------------------------------------------------------- /winfsp/x64/usr/bin/cygfuse-2.8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/affggh/erofs-utils_cygwin/86e1a14214659270de4594137f4c3e1997c3ac75/winfsp/x64/usr/bin/cygfuse-2.8.dll -------------------------------------------------------------------------------- /winfsp/x64/usr/lib/libfuse-2.8.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/affggh/erofs-utils_cygwin/86e1a14214659270de4594137f4c3e1997c3ac75/winfsp/x64/usr/lib/libfuse-2.8.dll.a -------------------------------------------------------------------------------- /winfsp/x64/usr/lib/libfuse.dll.a: -------------------------------------------------------------------------------- 1 | libfuse-2.8.dll.a -------------------------------------------------------------------------------- /winfsp/x64/usr/lib/pkgconfig/fuse.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr 2 | incdir=${prefix}/include/fuse 3 | 4 | Name: fuse 5 | Description: WinFsp FUSE compatible API 6 | Version: 2.8 7 | URL: http://www.secfs.net/winfsp/ 8 | Libs: -lfuse-2.8 9 | Cflags: -I"${incdir}" -DCYGFUSE 10 | -------------------------------------------------------------------------------- /winfsp/x86/usr/bin/cygfuse-2.8.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/affggh/erofs-utils_cygwin/86e1a14214659270de4594137f4c3e1997c3ac75/winfsp/x86/usr/bin/cygfuse-2.8.dll -------------------------------------------------------------------------------- /winfsp/x86/usr/lib/libfuse-2.8.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/affggh/erofs-utils_cygwin/86e1a14214659270de4594137f4c3e1997c3ac75/winfsp/x86/usr/lib/libfuse-2.8.dll.a -------------------------------------------------------------------------------- /winfsp/x86/usr/lib/libfuse.dll.a: -------------------------------------------------------------------------------- 1 | libfuse-2.8.dll.a -------------------------------------------------------------------------------- /winfsp/x86/usr/lib/pkgconfig/fuse.pc: -------------------------------------------------------------------------------- 1 | prefix=/usr 2 | incdir=${prefix}/include/fuse 3 | 4 | Name: fuse 5 | Description: WinFsp FUSE compatible API 6 | Version: 2.8 7 | URL: http://www.secfs.net/winfsp/ 8 | Libs: -lfuse-2.8 9 | Cflags: -I"${incdir}" -DCYGFUSE 10 | --------------------------------------------------------------------------------