├── kmod-sys ├── wrapper.h ├── .gitignore ├── src │ └── lib.rs ├── Cargo.toml ├── build.rs └── fallback.h ├── .gitignore ├── .travis.yml ├── .github └── workflows │ └── rust.yml ├── Cargo.toml ├── examples ├── modprobe.rs ├── lsmod.rs ├── insmod.rs └── rmmod.rs ├── src ├── errors.rs ├── lib.rs ├── modules.rs └── ctx.rs ├── LICENSE-MIT ├── README.md └── LICENSE-APACHE /kmod-sys/wrapper.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | Cargo.lock 5 | -------------------------------------------------------------------------------- /kmod-sys/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | Cargo.lock 5 | -------------------------------------------------------------------------------- /kmod-sys/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_upper_case_globals)] 2 | #![allow(non_camel_case_types)] 3 | #![allow(non_snake_case)] 4 | 5 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | before_install: 3 | - sudo apt-get -qq update 4 | - sudo apt-get install -y libkmod-dev 5 | script: 6 | - cargo build --verbose --all 7 | - cargo test --verbose --all 8 | -------------------------------------------------------------------------------- /kmod-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "kmod-sys" 3 | version = "0.2.0" 4 | description = "Bindings to libkmod to manage linux kernel modules" 5 | authors = ["kpcyrd "] 6 | links = "kmod" 7 | license = "MIT/Apache-2.0" 8 | repository = "https://github.com/kpcyrd/kmod-rs" 9 | categories = ["external-ffi-bindings"] 10 | edition = "2021" 11 | 12 | [dependencies] 13 | 14 | [build-dependencies] 15 | bindgen = "0.63" 16 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Install dependencies 20 | run: sudo apt-get install libkmod-dev 21 | - name: Build 22 | run: cargo build --verbose 23 | - name: Run tests 24 | run: cargo test --verbose 25 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "kmod" 3 | version = "0.5.0" 4 | description = "Bindings to libkmod to manage linux kernel modules" 5 | authors = ["kpcyrd "] 6 | license = "MIT/Apache-2.0" 7 | repository = "https://github.com/kpcyrd/kmod-rs" 8 | categories = ["api-bindings"] 9 | readme = "README.md" 10 | edition = "2021" 11 | 12 | [workspace] 13 | 14 | [dependencies] 15 | log = "0.4" 16 | errno = "0.2" 17 | kmod-sys = { version = "0.2.0", path = "kmod-sys" } 18 | thiserror = "1.0.37" 19 | 20 | [dev-dependencies] 21 | anyhow = "1.0.66" 22 | env_logger = "0.10" 23 | -------------------------------------------------------------------------------- /examples/modprobe.rs: -------------------------------------------------------------------------------- 1 | use kmod::errors::*; 2 | use std::env; 3 | 4 | fn main() -> anyhow::Result<()> { 5 | env_logger::init(); 6 | 7 | let ctx = kmod::Context::new()?; 8 | 9 | let mut args: Vec = env::args().skip(1).collect(); 10 | if args.is_empty() { 11 | anyhow::bail!("Missing argument"); 12 | } 13 | let name = args.remove(0); 14 | let module = ctx.module_new_from_name(&name)?; 15 | 16 | info!("got module: {:?}", module.name()); 17 | module.insert_module(0, &args.iter().map(|x| x.as_str()).collect::>())?; 18 | 19 | Ok(()) 20 | } 21 | -------------------------------------------------------------------------------- /examples/lsmod.rs: -------------------------------------------------------------------------------- 1 | fn main() -> anyhow::Result<()> { 2 | env_logger::init(); 3 | 4 | let ctx = kmod::Context::new()?; 5 | 6 | for module in ctx.modules_loaded()? { 7 | let name = module.name().to_string_lossy(); 8 | let refcount = module.refcount(); 9 | let size = module.size(); 10 | 11 | let holders: Vec<_> = module 12 | .holders() 13 | .map(|x| x.name().to_string_lossy().into_owned()) 14 | .collect(); 15 | 16 | println!("{:<19} {:8} {} {:?}", name, size, refcount, holders); 17 | } 18 | 19 | Ok(()) 20 | } 21 | -------------------------------------------------------------------------------- /examples/insmod.rs: -------------------------------------------------------------------------------- 1 | use kmod::errors::*; 2 | use std::env; 3 | 4 | fn main() -> anyhow::Result<()> { 5 | env_logger::init(); 6 | 7 | let ctx = kmod::Context::new()?; 8 | 9 | let mut args: Vec = env::args().skip(1).collect(); 10 | if args.is_empty() { 11 | anyhow::bail!("missing argument"); 12 | } 13 | let filename = args.remove(0); 14 | 15 | let module = ctx.module_new_from_path(&filename)?; 16 | 17 | info!("got module: {:?}", module.name()); 18 | module.insert_module(0, &args.iter().map(|x| x.as_str()).collect::>())?; 19 | 20 | Ok(()) 21 | } 22 | -------------------------------------------------------------------------------- /examples/rmmod.rs: -------------------------------------------------------------------------------- 1 | use anyhow::Context; 2 | use kmod::errors::*; 3 | use std::env; 4 | use std::fs; 5 | 6 | fn main() -> anyhow::Result<()> { 7 | env_logger::init(); 8 | 9 | let ctx = kmod::Context::new().context("kmod ctx failed")?; 10 | let filename = env::args().nth(1).context("missing argument")?; 11 | 12 | let module = if fs::metadata(&filename).is_ok() { 13 | // it's a file 14 | ctx.module_new_from_path(&filename)? 15 | } else { 16 | // it's probably a name 17 | ctx.module_new_from_name(&filename)? 18 | }; 19 | 20 | info!("got module: {:?}", module.name()); 21 | module.remove_module(0)?; 22 | 23 | Ok(()) 24 | } 25 | -------------------------------------------------------------------------------- /src/errors.rs: -------------------------------------------------------------------------------- 1 | pub use log::{debug, error, info, trace, warn}; 2 | use thiserror::Error; 3 | 4 | #[derive(Error, Debug)] 5 | pub enum Error { 6 | #[error("Could not setup kmod context")] 7 | NewCtx, 8 | #[error("Could not insert kernel module: {0}")] 9 | InsertModule(errno::Errno), 10 | #[error("Could not insert kernel module")] 11 | InsertModuleUnknown, 12 | #[error("Could not remove kernel module: {0}")] 13 | RemoveModule(errno::Errno), 14 | #[error("Could not find kernel module by name")] 15 | ModuleFromName, 16 | #[error("Could not find kernel module by lookup")] 17 | ModuleFromLookup, 18 | #[error("Could not load kernel module from path: {0}")] 19 | ModuleFromPath(errno::Errno), 20 | #[error("Could not access list of loaded modules")] 21 | LoadedModules, 22 | #[error("Input contains null bytes and can't be passed to the kernel")] 23 | Null(#[from] std::ffi::NulError), 24 | } 25 | 26 | pub type Result = std::result::Result; 27 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kmod-rs [![Build Status][travis-img]][travis] [![crates.io][crates-img]][crates] [![docs.rs][docs-img]][docs] 2 | 3 | [travis-img]: https://travis-ci.org/kpcyrd/kmod-rs.svg?branch=master 4 | [travis]: https://travis-ci.org/kpcyrd/kmod-rs 5 | [crates-img]: https://img.shields.io/crates/v/kmod.svg 6 | [crates]: https://crates.io/crates/kmod 7 | [docs-img]: https://docs.rs/kmod/badge.svg 8 | [docs]: https://docs.rs/kmod 9 | 10 | Bindings to libkmod to manage linux kernel modules. 11 | 12 | ``` 13 | # Cargo.toml 14 | [dependencies] 15 | kmod = "0.4" 16 | ``` 17 | 18 | To get started, see the [docs] and the examples/ folder. 19 | ```rust 20 | extern crate kmod; 21 | extern crate env_logger; 22 | 23 | fn main() { 24 | env_logger::init(); 25 | 26 | let ctx = kmod::Context::new().expect("kmod ctx failed"); 27 | 28 | for module in ctx.modules_loaded().unwrap() { 29 | let name = module.name(); 30 | let refcount = module.refcount(); 31 | let size = module.size(); 32 | 33 | let holders: Vec<_> = module.holders() 34 | .map(|x| x.name().to_owned()) 35 | .collect(); 36 | 37 | println!("{:<19} {:8} {} {:?}", name, size, refcount, holders); 38 | } 39 | } 40 | ``` 41 | 42 | ## License 43 | 44 | MIT/Apache-2.0 45 | -------------------------------------------------------------------------------- /kmod-sys/build.rs: -------------------------------------------------------------------------------- 1 | extern crate bindgen; 2 | 3 | use std::env; 4 | use std::path::PathBuf; 5 | 6 | fn genbindings(path: &str) -> Result { 7 | // The bindgen::Builder is the main entry point 8 | // to bindgen, and lets you build up options for 9 | // the resulting bindings. 10 | bindgen::Builder::default() 11 | // The input header we would like to generate 12 | // bindings for. 13 | .header(path) 14 | // Finish the builder and generate the bindings. 15 | .generate() 16 | } 17 | 18 | fn try_genbindings() -> Option { 19 | for header in &["wrapper.h", "fallback.h"] { 20 | if let Ok(bindings) = genbindings(header) { 21 | return Some(bindings); 22 | } 23 | } 24 | 25 | None 26 | } 27 | 28 | fn main() { 29 | // Tell cargo to tell rustc to link the system kmod 30 | // shared library. 31 | println!("cargo:rustc-link-lib=kmod"); 32 | 33 | let bindings = try_genbindings() 34 | // Unwrap the Result and panic on failure. 35 | .expect("Unable to generate bindings"); 36 | 37 | // Write the bindings to the $OUT_DIR/bindings.rs file. 38 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 39 | bindings 40 | .write_to_file(out_path.join("bindings.rs")) 41 | .expect("Couldn't write bindings!"); 42 | } 43 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Bindings to libkmod to manage linux kernel modules. 2 | //! 3 | //! # Example 4 | //! ``` 5 | //! fn main() -> anyhow::Result<()> { 6 | //! // create a new kmod context 7 | //! let ctx = kmod::Context::new()?; 8 | //! 9 | //! // get a kmod_list of all loaded modules 10 | //! for module in ctx.modules_loaded()? { 11 | //! let name = module.name().to_string_lossy(); 12 | //! let refcount = module.refcount(); 13 | //! let size = module.size(); 14 | //! 15 | //! let holders: Vec<_> = module.holders() 16 | //! .map(|x| x.name().to_string_lossy().into_owned()) 17 | //! .collect(); 18 | //! 19 | //! println!("{:<19} {:8} {} {:?}", name, size, refcount, holders); 20 | //! } 21 | //! Ok(()) 22 | //! } 23 | //! ``` 24 | 25 | pub mod ctx; 26 | pub mod errors; 27 | pub mod modules; 28 | 29 | pub use ctx::*; 30 | pub use errno::Errno; 31 | pub use errors::*; 32 | pub use modules::*; 33 | 34 | #[cfg(test)] 35 | mod tests { 36 | use super::*; 37 | 38 | #[test] 39 | fn lsmod() { 40 | let ctx = Context::new().unwrap(); 41 | 42 | for module in ctx.modules_loaded().unwrap() { 43 | let name = module.name().to_string_lossy(); 44 | let refcount = module.refcount(); 45 | let size = module.size(); 46 | 47 | let holders: Vec<_> = module 48 | .holders() 49 | .map(|x| x.name().to_string_lossy().into_owned()) 50 | .collect(); 51 | 52 | println!("{:<19} {:8} {} {:?}", name, size, refcount, holders); 53 | } 54 | } 55 | 56 | #[test] 57 | fn bad_name() { 58 | let ctx = Context::new().unwrap(); 59 | let m = ctx 60 | .module_new_from_name("/lib/modules/5.1.12-300.fc30.x86_64/kernel/fs/cifs/cifs.ko.xz") 61 | .unwrap(); 62 | println!("name: {:?}", m.name()); 63 | println!("path: {:?}", m.path()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/modules.rs: -------------------------------------------------------------------------------- 1 | use crate::errors::*; 2 | use kmod_sys::{self, kmod_list, kmod_module}; 3 | use std::ffi::{CStr, CString, OsStr}; 4 | use std::fmt; 5 | use std::os::unix::ffi::OsStrExt; 6 | 7 | /// Wrapper around a kmod_module 8 | pub struct Module { 9 | inner: *mut kmod_module, 10 | } 11 | 12 | impl Drop for Module { 13 | fn drop(&mut self) { 14 | trace!("dropping kmod_module: {:?}", self.inner); 15 | let _ = unsafe { kmod_sys::kmod_module_unref(self.inner) }; 16 | } 17 | } 18 | 19 | impl Module { 20 | #[inline] 21 | pub(crate) fn new(module: *mut kmod_module) -> Module { 22 | trace!("creating kmod_module: {:?}", module); 23 | Module { inner: module } 24 | } 25 | 26 | /// Get the name of the module 27 | #[inline] 28 | pub fn name(&self) -> &OsStr { 29 | unsafe { 30 | kmod_sys::kmod_module_get_name(self.inner) 31 | .as_ref() 32 | .map(|ptr| CStr::from_ptr(ptr)) 33 | } 34 | .map(CStr::to_bytes) 35 | .map(OsStr::from_bytes) 36 | .unwrap() // Don't account for NULL as libkmod states that name is always available 37 | } 38 | 39 | /// Get the size of the module 40 | #[inline] 41 | pub fn size(&self) -> i64 { 42 | unsafe { kmod_sys::kmod_module_get_size(self.inner) } 43 | } 44 | 45 | /// Get the number of references to this module 46 | #[inline] 47 | pub fn refcount(&self) -> i32 { 48 | unsafe { kmod_sys::kmod_module_get_refcnt(self.inner) } 49 | } 50 | 51 | /// Iterate over the modules depending on this module 52 | #[inline] 53 | pub fn holders(&self) -> ModuleIterator { 54 | let holders = unsafe { kmod_sys::kmod_module_get_holders(self.inner) }; 55 | ModuleIterator::new(holders) 56 | } 57 | 58 | /// Get this modules dependencies 59 | #[inline] 60 | pub fn dependencies(&self) -> ModuleIterator { 61 | let dependencies = unsafe { kmod_sys::kmod_module_get_dependencies(self.inner) }; 62 | ModuleIterator::new(dependencies) 63 | } 64 | 65 | /// Get module path 66 | #[inline] 67 | pub fn path(&self) -> Option<&OsStr> { 68 | unsafe { 69 | kmod_sys::kmod_module_get_path(self.inner) 70 | .as_ref() 71 | .map(|ptr| CStr::from_ptr(ptr)) 72 | } 73 | .map(CStr::to_bytes) 74 | .map(OsStr::from_bytes) 75 | } 76 | 77 | /// Get module options 78 | #[inline] 79 | pub fn options(&self) -> Option<&OsStr> { 80 | unsafe { 81 | kmod_sys::kmod_module_get_options(self.inner) 82 | .as_ref() 83 | .map(|ptr| CStr::from_ptr(ptr)) 84 | .map(CStr::to_bytes) 85 | .map(OsStr::from_bytes) 86 | } 87 | } 88 | 89 | /// Insert the module into the kernel 90 | #[inline] 91 | pub fn insert_module(&self, flags: u32, opts: &[&str]) -> Result<()> { 92 | let opts = opts.join(" "); 93 | 94 | let opts = CString::new(opts)?; 95 | 96 | let ret = unsafe { kmod_sys::kmod_module_insert_module(self.inner, flags, opts.as_ptr()) }; 97 | if ret < 0 { 98 | if errno::errno() == errno::Errno(0) { 99 | Err(Error::InsertModuleUnknown) 100 | } else { 101 | Err(Error::InsertModule(errno::errno())) 102 | } 103 | } else { 104 | Ok(()) 105 | } 106 | } 107 | 108 | /// Remove the module from the kernel 109 | #[inline] 110 | pub fn remove_module(&self, flags: u32) -> Result<()> { 111 | let ret = unsafe { kmod_sys::kmod_module_remove_module(self.inner, flags) }; 112 | if ret < 0 { 113 | Err(Error::RemoveModule(errno::errno())) 114 | } else { 115 | Ok(()) 116 | } 117 | } 118 | } 119 | 120 | impl fmt::Debug for Module { 121 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 122 | f.pad("Module { .. }") 123 | } 124 | } 125 | 126 | /// Iterator over a kmod_list of modules 127 | pub struct ModuleIterator { 128 | list: *mut kmod_list, 129 | iter: *mut kmod_list, 130 | } 131 | 132 | impl Drop for ModuleIterator { 133 | fn drop(&mut self) { 134 | trace!("dropping kmod_list: {:?}", self.list); 135 | let _ = unsafe { kmod_sys::kmod_module_unref_list(self.list) }; 136 | } 137 | } 138 | 139 | impl ModuleIterator { 140 | #[inline] 141 | pub(crate) fn new(list: *mut kmod_list) -> ModuleIterator { 142 | trace!("creating kmod_list: {:?}", list); 143 | ModuleIterator { list, iter: list } 144 | } 145 | } 146 | 147 | impl Iterator for ModuleIterator { 148 | type Item = Module; 149 | 150 | #[inline] 151 | fn next(&mut self) -> Option { 152 | trace!("kmod_list->next: {:?}", self.iter); 153 | if !self.iter.is_null() { 154 | let module = unsafe { kmod_sys::kmod_module_get_module(self.iter) }; 155 | self.iter = unsafe { kmod_sys::kmod_list_next(self.list, self.iter) }; 156 | Some(Module::new(module)) 157 | } else { 158 | None 159 | } 160 | } 161 | } 162 | 163 | impl fmt::Debug for ModuleIterator { 164 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 165 | f.pad("ModuleIterator { .. }") 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/ctx.rs: -------------------------------------------------------------------------------- 1 | use crate::errors::*; 2 | use crate::modules::{Module, ModuleIterator}; 3 | use std::ffi::{CStr, CString, OsStr, OsString}; 4 | use std::os::unix::ffi::OsStrExt; 5 | use std::path::Path; 6 | use std::{fmt, ptr}; 7 | 8 | /// The kmod context 9 | /// 10 | /// ``` 11 | /// let ctx = kmod::Context::new().unwrap(); 12 | /// ``` 13 | pub struct Context { 14 | ctx: *mut kmod_sys::kmod_ctx, 15 | } 16 | 17 | impl Drop for Context { 18 | fn drop(&mut self) { 19 | trace!("dropping kmod: {:?}", self.ctx); 20 | let _ = unsafe { kmod_sys::kmod_unref(self.ctx) }; 21 | } 22 | } 23 | 24 | impl Context { 25 | /// Create a new kmod context. 26 | /// 27 | /// ``` 28 | /// let ctx = kmod::Context::new().unwrap(); 29 | /// ``` 30 | #[inline] 31 | pub fn new() -> Result { 32 | let ctx = unsafe { kmod_sys::kmod_new(ptr::null(), ptr::null()) }; 33 | if ctx.is_null() { 34 | Err(Error::NewCtx) 35 | } else { 36 | trace!("creating kmod: {:?}", ctx); 37 | Ok(Context { ctx }) 38 | } 39 | } 40 | 41 | /// Create a new kmod context with given directory to search for kernel modules. 42 | /// 43 | /// ``` 44 | /// use std::path::Path; 45 | /// let ctx = kmod::Context::new_with_dirname(&Path::new("/lib/modules/6.0.9")).unwrap(); 46 | /// ``` 47 | pub fn new_with_dirname(dirname: &Path) -> Result { 48 | let dirname = CString::new(dirname.as_os_str().as_bytes())?; 49 | 50 | let ctx = unsafe { kmod_sys::kmod_new(dirname.as_ptr(), ptr::null()) }; 51 | 52 | if ctx.is_null() { 53 | Err(Error::NewCtx) 54 | } else { 55 | trace!("creating kmod: {:?}", ctx); 56 | Ok(Context { ctx }) 57 | } 58 | } 59 | 60 | /// Get an iterator of all loaded modules. 61 | /// 62 | /// ``` 63 | /// let ctx = kmod::Context::new().unwrap(); 64 | /// for module in ctx.modules_loaded().unwrap() { 65 | /// // ... 66 | /// } 67 | /// ``` 68 | #[inline] 69 | pub fn modules_loaded(&self) -> Result { 70 | let mut list = ptr::null::() as *mut kmod_sys::kmod_list; 71 | let ret = unsafe { kmod_sys::kmod_module_new_from_loaded(self.ctx, &mut list) }; 72 | 73 | if ret < 0 { 74 | Err(Error::LoadedModules) 75 | } else { 76 | trace!("kmod_module_new_from_loaded: {:?}", list); 77 | Ok(ModuleIterator::new(list)) 78 | } 79 | } 80 | 81 | /// Create a module struct by looking up a name or alias. 82 | /// 83 | /// ``` 84 | /// # fn main() { foo(); } 85 | /// # fn foo() -> anyhow::Result<()> { 86 | /// use std::ffi::{OsStr, OsString}; 87 | /// let ctx = kmod::Context::new()?; 88 | /// let module = ctx.module_new_from_lookup(&OsString::from("vfat"))?; 89 | /// # Ok(()) 90 | /// # } 91 | /// ``` 92 | pub fn module_new_from_lookup>(&self, alias: S) -> Result { 93 | let mut list = ptr::null::() as *mut kmod_sys::kmod_list; 94 | let alias = CString::new(alias.as_ref().as_bytes())?; 95 | let ret = 96 | unsafe { kmod_sys::kmod_module_new_from_lookup(self.ctx, alias.as_ptr(), &mut list) }; 97 | 98 | if ret < 0 { 99 | Err(Error::ModuleFromLookup) 100 | } else { 101 | trace!("kmod_module_new_from_lookup: {:?}", list); 102 | Ok(ModuleIterator::new(list)) 103 | } 104 | } 105 | 106 | /// Create a module struct by path. 107 | /// 108 | /// ``` 109 | /// let ctx = kmod::Context::new().unwrap(); 110 | /// let module = ctx.module_new_from_path("foo.ko"); 111 | /// ``` 112 | pub fn module_new_from_path>(&self, filename: S) -> Result { 113 | let mut module = ptr::null::() as *mut kmod_sys::kmod_module; 114 | 115 | let filename = CString::new(filename.as_ref().as_bytes())?; 116 | let ret = unsafe { 117 | kmod_sys::kmod_module_new_from_path(self.ctx, filename.as_ptr(), &mut module) 118 | }; 119 | 120 | if ret < 0 { 121 | Err(Error::ModuleFromPath(errno::errno())) 122 | } else { 123 | trace!("kmod_module_new_from_path: {:?}", module); 124 | Ok(Module::new(module)) 125 | } 126 | } 127 | 128 | /// Create a module struct by name. 129 | /// 130 | /// ``` 131 | /// let ctx = kmod::Context::new().unwrap(); 132 | /// let module = ctx.module_new_from_name("tun").unwrap(); 133 | /// ``` 134 | pub fn module_new_from_name(&self, name: &str) -> Result { 135 | let mut module = ptr::null::() as *mut kmod_sys::kmod_module; 136 | 137 | let name = CString::new(name)?; 138 | let ret = 139 | unsafe { kmod_sys::kmod_module_new_from_name(self.ctx, name.as_ptr(), &mut module) }; 140 | 141 | if ret < 0 { 142 | Err(Error::ModuleFromName) 143 | } else { 144 | trace!("kmod_module_new_from_name: {:?}", module); 145 | Ok(Module::new(module)) 146 | } 147 | } 148 | 149 | /// Get the directory where kernel modules are stored 150 | /// 151 | /// ``` 152 | /// let ctx = kmod::Context::new().unwrap(); 153 | /// let dirname = ctx.dirname(); 154 | /// ``` 155 | pub fn dirname(&self) -> OsString { 156 | use std::os::unix::ffi::OsStringExt; 157 | 158 | let dirname = unsafe { kmod_sys::kmod_get_dirname(self.ctx) }; 159 | let dirname = unsafe { CStr::from_ptr(dirname) }; 160 | OsString::from_vec(dirname.to_bytes().to_vec()) 161 | } 162 | } 163 | 164 | impl fmt::Debug for Context { 165 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 166 | f.pad("Context { .. }") 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /kmod-sys/fallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libkmod - interface to kernel module operations 3 | * 4 | * Copyright (C) 2011-2013 ProFUSION embedded systems 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, see . 18 | */ 19 | 20 | #pragma once 21 | #ifndef _LIBKMOD_H_ 22 | #define _LIBKMOD_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /* 34 | * kmod_ctx 35 | * 36 | * library user context - reads the config and system 37 | * environment, user variables, allows custom logging 38 | */ 39 | struct kmod_ctx; 40 | struct kmod_ctx *kmod_new(const char *dirname, const char * const *config_paths); 41 | struct kmod_ctx *kmod_ref(struct kmod_ctx *ctx); 42 | struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx); 43 | void kmod_set_log_fn(struct kmod_ctx *ctx, 44 | void (*log_fn)(void *log_data, 45 | int priority, const char *file, int line, 46 | const char *fn, const char *format, 47 | va_list args), 48 | const void *data); 49 | int kmod_get_log_priority(const struct kmod_ctx *ctx); 50 | void kmod_set_log_priority(struct kmod_ctx *ctx, int priority); 51 | void *kmod_get_userdata(const struct kmod_ctx *ctx); 52 | void kmod_set_userdata(struct kmod_ctx *ctx, const void *userdata); 53 | 54 | const char *kmod_get_dirname(const struct kmod_ctx *ctx); 55 | 56 | /* 57 | * Management of libkmod's resources 58 | */ 59 | int kmod_load_resources(struct kmod_ctx *ctx); 60 | void kmod_unload_resources(struct kmod_ctx *ctx); 61 | 62 | enum kmod_resources { 63 | KMOD_RESOURCES_OK = 0, 64 | KMOD_RESOURCES_MUST_RELOAD = 1, 65 | KMOD_RESOURCES_MUST_RECREATE = 2, 66 | }; 67 | int kmod_validate_resources(struct kmod_ctx *ctx); 68 | 69 | enum kmod_index { 70 | KMOD_INDEX_MODULES_DEP = 0, 71 | KMOD_INDEX_MODULES_ALIAS, 72 | KMOD_INDEX_MODULES_SYMBOL, 73 | KMOD_INDEX_MODULES_BUILTIN_ALIAS, 74 | KMOD_INDEX_MODULES_BUILTIN, 75 | /* Padding to make sure enum is not mapped to char */ 76 | _KMOD_INDEX_PAD = 1U << 31, 77 | }; 78 | int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, int fd); 79 | 80 | /* 81 | * kmod_list 82 | * 83 | * access to kmod generated lists 84 | */ 85 | struct kmod_list; 86 | struct kmod_list *kmod_list_next(const struct kmod_list *list, 87 | const struct kmod_list *curr); 88 | struct kmod_list *kmod_list_prev(const struct kmod_list *list, 89 | const struct kmod_list *curr); 90 | struct kmod_list *kmod_list_last(const struct kmod_list *list); 91 | 92 | #define kmod_list_foreach(list_entry, first_entry) \ 93 | for (list_entry = first_entry; \ 94 | list_entry != NULL; \ 95 | list_entry = kmod_list_next(first_entry, list_entry)) 96 | 97 | #define kmod_list_foreach_reverse(list_entry, first_entry) \ 98 | for (list_entry = kmod_list_last(first_entry); \ 99 | list_entry != NULL; \ 100 | list_entry = kmod_list_prev(first_entry, list_entry)) 101 | 102 | /* 103 | * kmod_config_iter 104 | * 105 | * access to configuration lists - it allows to get each configuration's 106 | * key/value stored by kmod 107 | */ 108 | struct kmod_config_iter; 109 | struct kmod_config_iter *kmod_config_get_blacklists(const struct kmod_ctx *ctx); 110 | struct kmod_config_iter *kmod_config_get_install_commands(const struct kmod_ctx *ctx); 111 | struct kmod_config_iter *kmod_config_get_remove_commands(const struct kmod_ctx *ctx); 112 | struct kmod_config_iter *kmod_config_get_aliases(const struct kmod_ctx *ctx); 113 | struct kmod_config_iter *kmod_config_get_options(const struct kmod_ctx *ctx); 114 | struct kmod_config_iter *kmod_config_get_softdeps(const struct kmod_ctx *ctx); 115 | const char *kmod_config_iter_get_key(const struct kmod_config_iter *iter); 116 | const char *kmod_config_iter_get_value(const struct kmod_config_iter *iter); 117 | bool kmod_config_iter_next(struct kmod_config_iter *iter); 118 | void kmod_config_iter_free_iter(struct kmod_config_iter *iter); 119 | 120 | /* 121 | * kmod_module 122 | * 123 | * Operate on kernel modules 124 | */ 125 | struct kmod_module; 126 | int kmod_module_new_from_name(struct kmod_ctx *ctx, const char *name, 127 | struct kmod_module **mod); 128 | int kmod_module_new_from_path(struct kmod_ctx *ctx, const char *path, 129 | struct kmod_module **mod); 130 | int kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *given_alias, 131 | struct kmod_list **list); 132 | int kmod_module_new_from_name_lookup(struct kmod_ctx *ctx, 133 | const char *modname, 134 | struct kmod_module **mod); 135 | int kmod_module_new_from_loaded(struct kmod_ctx *ctx, 136 | struct kmod_list **list); 137 | 138 | struct kmod_module *kmod_module_ref(struct kmod_module *mod); 139 | struct kmod_module *kmod_module_unref(struct kmod_module *mod); 140 | int kmod_module_unref_list(struct kmod_list *list); 141 | struct kmod_module *kmod_module_get_module(const struct kmod_list *entry); 142 | 143 | 144 | /* Removal flags */ 145 | enum kmod_remove { 146 | KMOD_REMOVE_FORCE = O_TRUNC, 147 | KMOD_REMOVE_NOWAIT = O_NONBLOCK, /* always set */ 148 | /* libkmod-only defines, not passed to kernel */ 149 | KMOD_REMOVE_NOLOG = 1, 150 | }; 151 | 152 | /* Insertion flags */ 153 | enum kmod_insert { 154 | KMOD_INSERT_FORCE_VERMAGIC = 0x1, 155 | KMOD_INSERT_FORCE_MODVERSION = 0x2, 156 | }; 157 | 158 | /* Flags to kmod_module_probe_insert_module() */ 159 | enum kmod_probe { 160 | KMOD_PROBE_FORCE_VERMAGIC = 0x00001, 161 | KMOD_PROBE_FORCE_MODVERSION = 0x00002, 162 | KMOD_PROBE_IGNORE_COMMAND = 0x00004, 163 | KMOD_PROBE_IGNORE_LOADED = 0x00008, 164 | KMOD_PROBE_DRY_RUN = 0x00010, 165 | KMOD_PROBE_FAIL_ON_LOADED = 0x00020, 166 | 167 | /* codes below can be used in return value, too */ 168 | KMOD_PROBE_APPLY_BLACKLIST_ALL = 0x10000, 169 | KMOD_PROBE_APPLY_BLACKLIST = 0x20000, 170 | KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY = 0x40000, 171 | }; 172 | 173 | /* Flags to kmod_module_apply_filter() */ 174 | enum kmod_filter { 175 | KMOD_FILTER_BLACKLIST = 0x00001, 176 | KMOD_FILTER_BUILTIN = 0x00002, 177 | }; 178 | 179 | int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags); 180 | int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags, 181 | const char *options); 182 | int kmod_module_probe_insert_module(struct kmod_module *mod, 183 | unsigned int flags, const char *extra_options, 184 | int (*run_install)(struct kmod_module *m, 185 | const char *cmdline, void *data), 186 | const void *data, 187 | void (*print_action)(struct kmod_module *m, bool install, 188 | const char *options)); 189 | 190 | 191 | const char *kmod_module_get_name(const struct kmod_module *mod); 192 | const char *kmod_module_get_path(const struct kmod_module *mod); 193 | const char *kmod_module_get_options(const struct kmod_module *mod); 194 | const char *kmod_module_get_install_commands(const struct kmod_module *mod); 195 | const char *kmod_module_get_remove_commands(const struct kmod_module *mod); 196 | struct kmod_list *kmod_module_get_dependencies(const struct kmod_module *mod); 197 | int kmod_module_get_softdeps(const struct kmod_module *mod, 198 | struct kmod_list **pre, struct kmod_list **post); 199 | int kmod_module_get_filtered_blacklist(const struct kmod_ctx *ctx, 200 | const struct kmod_list *input, 201 | struct kmod_list **output) __attribute__ ((deprecated)); 202 | int kmod_module_apply_filter(const struct kmod_ctx *ctx, 203 | enum kmod_filter filter_type, 204 | const struct kmod_list *input, 205 | struct kmod_list **output); 206 | 207 | 208 | 209 | /* 210 | * Information regarding "live information" from module's state, as returned 211 | * by kernel 212 | */ 213 | 214 | enum kmod_module_initstate { 215 | KMOD_MODULE_BUILTIN = 0, 216 | KMOD_MODULE_LIVE, 217 | KMOD_MODULE_COMING, 218 | KMOD_MODULE_GOING, 219 | /* Padding to make sure enum is not mapped to char */ 220 | _KMOD_MODULE_PAD = 1U << 31, 221 | }; 222 | const char *kmod_module_initstate_str(enum kmod_module_initstate state); 223 | int kmod_module_get_initstate(const struct kmod_module *mod); 224 | int kmod_module_get_refcnt(const struct kmod_module *mod); 225 | struct kmod_list *kmod_module_get_holders(const struct kmod_module *mod); 226 | struct kmod_list *kmod_module_get_sections(const struct kmod_module *mod); 227 | const char *kmod_module_section_get_name(const struct kmod_list *entry); 228 | unsigned long kmod_module_section_get_address(const struct kmod_list *entry); 229 | void kmod_module_section_free_list(struct kmod_list *list); 230 | long kmod_module_get_size(const struct kmod_module *mod); 231 | 232 | 233 | 234 | /* 235 | * Information retrieved from ELF headers and sections 236 | */ 237 | 238 | int kmod_module_get_info(const struct kmod_module *mod, struct kmod_list **list); 239 | const char *kmod_module_info_get_key(const struct kmod_list *entry); 240 | const char *kmod_module_info_get_value(const struct kmod_list *entry); 241 | void kmod_module_info_free_list(struct kmod_list *list); 242 | 243 | int kmod_module_get_versions(const struct kmod_module *mod, struct kmod_list **list); 244 | const char *kmod_module_version_get_symbol(const struct kmod_list *entry); 245 | uint64_t kmod_module_version_get_crc(const struct kmod_list *entry); 246 | void kmod_module_versions_free_list(struct kmod_list *list); 247 | 248 | int kmod_module_get_symbols(const struct kmod_module *mod, struct kmod_list **list); 249 | const char *kmod_module_symbol_get_symbol(const struct kmod_list *entry); 250 | uint64_t kmod_module_symbol_get_crc(const struct kmod_list *entry); 251 | void kmod_module_symbols_free_list(struct kmod_list *list); 252 | 253 | enum kmod_symbol_bind { 254 | KMOD_SYMBOL_NONE = '\0', 255 | KMOD_SYMBOL_LOCAL = 'L', 256 | KMOD_SYMBOL_GLOBAL = 'G', 257 | KMOD_SYMBOL_WEAK = 'W', 258 | KMOD_SYMBOL_UNDEF = 'U' 259 | }; 260 | 261 | int kmod_module_get_dependency_symbols(const struct kmod_module *mod, struct kmod_list **list); 262 | const char *kmod_module_dependency_symbol_get_symbol(const struct kmod_list *entry); 263 | int kmod_module_dependency_symbol_get_bind(const struct kmod_list *entry); 264 | uint64_t kmod_module_dependency_symbol_get_crc(const struct kmod_list *entry); 265 | void kmod_module_dependency_symbols_free_list(struct kmod_list *list); 266 | 267 | #ifdef __cplusplus 268 | } /* extern "C" */ 269 | #endif 270 | #endif 271 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------