노무현 대통령 배너


2006. 7. 20. 13:14

The Linux Kernel API

출처http://www.gelato.unsw.edu.au/~dsw/public-files/kernel-docs/kernel-api/

The Linux Kernel API

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.


Table of Contents
1. Driver Basics
1.1. Driver Entry and Exit points
module_init-- driver initialization entry point
module_exit-- driver exit entry point
1.2. Atomic and pointer manipulation
atomic_read-- read atomic variable
atomic_set-- set atomic variable
atomic_add-- add integer to atomic variable
atomic_sub-- subtract the atomic variable
atomic_sub_and_test-- subtract value from variable and test result
atomic_inc-- increment atomic variable
atomic_dec-- decrement atomic variable
atomic_dec_and_test-- decrement and test
atomic_inc_and_test-- increment and test
atomic_add_negative-- add and test if negative
get_unaligned-- get value from possibly mis-aligned location
put_unaligned-- put value to a possibly mis-aligned location
2. Data Types
2.1. Doubly Linked Lists
list_add-- add a new entry
list_add_tail-- add a new entry
list_add_rcu-- add a new entry to rcu-protected list
list_add_tail_rcu-- add a new entry to rcu-protected list
list_del-- deletes entry from list.
list_del_rcu-- deletes entry from list without re-initialization
list_del_init-- deletes entry from list and reinitialize it.
list_move-- delete from one list and add as another's head
list_move_tail-- delete from one list and add as another's tail
list_empty-- tests whether a list is empty
list_splice-- join two lists
list_splice_init-- join two lists and reinitialise the emptied list.
list_entry-- get the struct for this entry
list_for_each-- iterate over a list
__list_for_each-- iterate over a list
list_for_each_prev-- iterate over a list backwards
list_for_each_safe-- iterate over a list safe against removal of list entry
list_for_each_entry-- iterate over list of given type
list_for_each_entry_reverse-- iterate backwards over list of given type.
list_for_each_entry_safe-- iterate over list of given type safe against removal of list entry
list_for_each_rcu-- iterate over an rcu-protected list
list_for_each_safe_rcu-- iterate over an rcu-protected list safe
list_for_each_entry_rcu-- iterate over rcu list of given type
list_for_each_continue_rcu-- iterate over an rcu-protected list
hlist_del_rcu-- deletes entry from hash list without re-initialization
hlist_for_each_entry-- iterate over list of given type
hlist_for_each_entry_continue-- iterate over a hlist continuing after existing point
hlist_for_each_entry_from-- iterate over a hlist continuing from existing point
hlist_for_each_entry_safe-- iterate over list of given type safe against removal of list entry
3. Basic C Library Functions
3.1. String Conversions
simple_strtoll-- convert a string to a signed long long
simple_strtoul-- convert a string to an unsigned long
simple_strtol-- convert a string to a signed long
simple_strtoull-- convert a string to an unsigned long long
vsnprintf-- Format a string and place it in a buffer
snprintf-- Format a string and place it in a buffer
vsprintf-- Format a string and place it in a buffer
sprintf-- Format a string and place it in a buffer
vsscanf-- Unformat a buffer into a list of arguments
sscanf-- Unformat a buffer into a list of arguments
3.2. String Manipulation
strcpy-- Copy a NUL terminated string
strncpy-- Copy a length-limited, NUL-terminated string
strcat-- Append one NUL-terminated string to another
strncat-- Append a length-limited, NUL-terminated string to another
strcmp-- Compare two strings
strncmp-- Compare two length-limited strings
strchr-- Find the first occurrence of a character in a string
strrchr-- Find the last occurrence of a character in a string
strlen-- Find the length of a string
strnlen-- Find the length of a length-limited string
strcspn-- Calculate the length of the initial substring of s which does
strpbrk-- Find the first occurrence of a set of characters
memset-- Fill a region of memory with the given value
bcopy-- Copy one area of memory to another
memcpy-- Copy one area of memory to another
memmove-- Copy one area of memory to another
memcmp-- Compare two areas of memory
memscan-- Find a character in an area of memory.
strstr-- Find the first substring in a NUL terminated string
memchr-- Find a character in an area of memory.
strnicmp-- Case insensitive, length-limited string comparison
strlcpy-- Copy a NUL terminated string into a sized buffer
strlcat-- Append a length-limited, NUL-terminated string to another
strspn-- Calculate the length of the initial substring of s which only
strsep-- Split a string into tokens
3.3. Bit Operations
set_bit-- Atomically set a bit in memory
__set_bit-- Set a bit in memory
clear_bit-- Clears a bit in memory
__change_bit-- Toggle a bit in memory
change_bit-- Toggle a bit in memory
test_and_set_bit-- Set a bit and return its old value
__test_and_set_bit-- Set a bit and return its old value
test_and_clear_bit-- Clear a bit and return its old value
__test_and_clear_bit-- Clear a bit and return its old value
test_and_change_bit-- Change a bit and return its new value
test_bit-- Determine whether a bit is set
find_first_zero_bit-- find the first zero bit in a memory region
find_first_bit-- find the first set bit in a memory region
find_next_zero_bit-- find the first zero bit in a memory region
find_next_bit-- find the first set bit in a memory region
ffz-- find first zero in word.
__ffs-- find first bit in word.
ffs-- find first bit set
hweight32-- returns the hamming weight of a N-bit word
4. Memory Management in Linux
4.1. The Slab Cache
kmem_cache_create-- Create a cache.
kmem_cache_shrink-- Shrink a cache.
kmem_cache_destroy-- delete a cache
kmem_cache_alloc-- Allocate an object
__kmalloc-- allocate memory
__alloc_percpu-- allocate one copy of the object for every present
kmem_cache_free-- Deallocate an object
kfree-- free previously allocated memory
free_percpu-- free previously allocated percpu memory
4.2. User Space Memory Access
access_ok-- Checks if a user space pointer is valid
verify_area-- Obsolete, use access_ok
get_user-- Get a simple variable from user space.
put_user-- Write a simple value into user space.
__get_user-- Get a simple variable from user space, with less checking.
__put_user-- Write a simple value into user space, with less checking.
__copy_to_user-- Copy a block of data into user space, with less checking.
__copy_from_user-- Copy a block of data from user space, with less checking.
copy_to_user-- Copy a block of data into user space.
copy_from_user-- Copy a block of data from user space.
strlen_user-- Get the size of a string in user space.
__strncpy_from_user-- Copy a NUL terminated string from userspace, with less checking.
strncpy_from_user-- Copy a NUL terminated string from userspace.
clear_user-- Zero a block of memory in user space.
__clear_user-- Zero a block of memory in user space, with less checking.
strnlen_user-- Get the size of a string in user space.
5. The proc filesystem
5.1. sysctl interface
register_sysctl_table-- register a sysctl hierarchy
unregister_sysctl_table-- unregister a sysctl table hierarchy
proc_dostring-- read a string sysctl
proc_dointvec-- read a vector of integers
proc_dointvec_minmax-- read a vector of integers with min/max values
proc_doulongvec_minmax-- read a vector of long integers with min/max values
proc_doulongvec_ms_jiffies_minmax-- read a vector of millisecond values with min/max values
proc_dointvec_jiffies-- read a vector of integers as seconds
6. The Linux VFS
6.1. The Directory Cache
d_invalidate-- invalidate a dentry
d_find_alias-- grab a hashed alias of inode
shrink_dcache_sb-- shrink dcache for a superblock
have_submounts-- check for mounts over a dentry
shrink_dcache_parent-- prune dcache
shrink_dcache_anon-- further prune the cache
d_alloc-- allocate a dcache entry
d_instantiate-- fill in inode information for a dentry
d_alloc_root-- allocate root dentry
d_alloc_anon-- allocate an anonymous dentry
d_splice_alias-- splice a disconnected dentry into the tree if one exists
d_lookup-- search for a dentry
d_validate-- verify dentry provided from insecure source
d_delete-- delete a dentry
d_rehash-- add an entry back to the hash
d_move-- move a dentry
is_subdir-- is new dentry a subdirectory of old_dentry
find_inode_number-- check for dentry with name
__d_drop-- drop a dentry
d_add-- add dentry to hash queues
dget-- get a reference to a dentry
d_unhashed-- is dentry hashed
6.2. Inode Handling
clear_inode-- clear an inode
invalidate_inodes-- discard the inodes on a device
new_inode-- obtain an inode
iunique-- get a unique inode number
ilookup5-- search for an inode in the inode cache
ilookup-- search for an inode in the inode cache
iget5_locked-- obtain an inode from a mounted file system
iget_locked-- obtain an inode from a mounted file system
__insert_inode_hash-- hash an inode
remove_inode_hash-- remove an inode from the hash
iput-- put an inode
bmap-- find a block number in a file
update_atime-- update the access time
inode_update_time-- update mtime and ctime time
make_bad_inode-- mark an inode bad due to an I/O error
is_bad_inode-- is an inode errored
6.3. Registration and Superblocks
deactivate_super-- drop an active reference to superblock
generic_shutdown_super-- common helper for ->kill_sb
sget-- find or create a superblock
get_super-- get the superblock of a device
6.4. File Locks
posix_lock_file-- Apply a POSIX-style lock to a file
locks_mandatory_area-- Check for a conflicting lock
__break_lease-- revoke all outstanding leases on file
lease_get_mtime--
posix_block_lock-- blocks waiting for a file lock
posix_unblock_lock-- stop waiting for a file lock
lock_may_read-- checks that the region is free of locks
lock_may_write-- checks that the region is free of locks
locks_mandatory_locked-- Check for an active lock
fcntl_getlease-- Enquire what lease is currently active
fcntl_setlease-- sets a lease on an open file
sys_flock-- flock system call.
get_locks_status-- reports lock usage in /proc/locks
7. Linux Networking
7.1. Socket Buffer Functions
struct sk_buff-- socket buffer
skb_queue_empty-- check if a queue is empty
skb_get-- reference buffer
kfree_skb-- free an sk_buff
skb_cloned-- is the buffer a clone
skb_shared-- is the buffer shared
skb_share_check-- check if buffer is shared and if so clone it
skb_unshare-- make a copy of a shared buffer
skb_peek--
skb_peek_tail--
skb_queue_len-- get queue length
__skb_queue_head-- queue a buffer at the list head
skb_queue_head-- queue a buffer at the list head
__skb_queue_tail-- queue a buffer at the list tail
skb_queue_tail-- queue a buffer at the list tail
__skb_dequeue-- remove from the head of the queue