Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
io.c File Reference
#include <linux/crc32.h>
#include <linux/slab.h>
#include "ubifs.h"

Go to the source code of this file.

Functions

void ubifs_ro_mode (struct ubifs_info *c, int err)
 
int ubifs_leb_read (const struct ubifs_info *c, int lnum, void *buf, int offs, int len, int even_ebadmsg)
 
int ubifs_leb_write (struct ubifs_info *c, int lnum, const void *buf, int offs, int len)
 
int ubifs_leb_change (struct ubifs_info *c, int lnum, const void *buf, int len)
 
int ubifs_leb_unmap (struct ubifs_info *c, int lnum)
 
int ubifs_leb_map (struct ubifs_info *c, int lnum)
 
int ubifs_is_mapped (const struct ubifs_info *c, int lnum)
 
int ubifs_check_node (const struct ubifs_info *c, const void *buf, int lnum, int offs, int quiet, int must_chk_crc)
 
void ubifs_pad (const struct ubifs_info *c, void *buf, int pad)
 
void ubifs_prepare_node (struct ubifs_info *c, void *node, int len, int pad)
 
void ubifs_prep_grp_node (struct ubifs_info *c, void *node, int len, int last)
 
int ubifs_wbuf_sync_nolock (struct ubifs_wbuf *wbuf)
 
int ubifs_wbuf_seek_nolock (struct ubifs_wbuf *wbuf, int lnum, int offs)
 
int ubifs_bg_wbufs_sync (struct ubifs_info *c)
 
int ubifs_wbuf_write_nolock (struct ubifs_wbuf *wbuf, void *buf, int len)
 
int ubifs_write_node (struct ubifs_info *c, void *buf, int len, int lnum, int offs)
 
int ubifs_read_node_wbuf (struct ubifs_wbuf *wbuf, void *buf, int type, int len, int lnum, int offs)
 
int ubifs_read_node (const struct ubifs_info *c, void *buf, int type, int len, int lnum, int offs)
 
int ubifs_wbuf_init (struct ubifs_info *c, struct ubifs_wbuf *wbuf)
 
void ubifs_wbuf_add_ino_nolock (struct ubifs_wbuf *wbuf, ino_t inum)
 
int ubifs_sync_wbufs_by_inode (struct ubifs_info *c, struct inode *inode)
 

Function Documentation

int ubifs_bg_wbufs_sync ( struct ubifs_info c)

ubifs_bg_wbufs_sync - synchronize write-buffers. : UBIFS file-system description object

This function is called by background thread to synchronize write-buffers. Returns zero in case of success and a negative error code in case of failure.

Definition at line 603 of file io.c.

int ubifs_check_node ( const struct ubifs_info c,
const void buf,
int  lnum,
int  offs,
int  quiet,
int  must_chk_crc 
)

ubifs_check_node - check node. : UBIFS file-system description object : node to check : logical eraseblock number : offset within the logical eraseblock : print no messages : indicates whether to always check the CRC

This function checks node magic number and CRC checksum. This function also validates node length to prevent UBIFS from becoming crazy when an attacker feeds it a file-system image with incorrect nodes. For example, too large node length in the common header could cause UBIFS to read memory outside of allocated buffer when checking the CRC checksum.

This function may skip data nodes CRC checking if ->no_chk_data_crc is true, which is controlled by corresponding UBIFS mount option. However, if is true, then ->no_chk_data_crc is ignored and CRC is checked. Similarly, if ->mounting or ->remounting_rw is true (we are mounting or re-mounting to R/W mode), ->no_chk_data_crc is ignored and CRC is checked. This is because during mounting or re-mounting from R/O mode to R/W mode we may read journal nodes (when replying the journal or doing the recovery) and the journal nodes may potentially be corrupted, so checking is required.

This function returns zero in case of success and %-EUCLEAN in case of bad CRC or magic.

Definition at line 237 of file io.c.

int ubifs_is_mapped ( const struct ubifs_info c,
int  lnum 
)

Definition at line 196 of file io.c.

int ubifs_leb_change ( struct ubifs_info c,
int  lnum,
const void buf,
int  len 
)

Definition at line 138 of file io.c.

int ubifs_leb_map ( struct ubifs_info c,
int  lnum 
)

Definition at line 177 of file io.c.

int ubifs_leb_read ( const struct ubifs_info c,
int  lnum,
void buf,
int  offs,
int  len,
int  even_ebadmsg 
)

Definition at line 99 of file io.c.

int ubifs_leb_unmap ( struct ubifs_info c,
int  lnum 
)

Definition at line 158 of file io.c.

int ubifs_leb_write ( struct ubifs_info c,
int  lnum,
const void buf,
int  offs,
int  len 
)

Definition at line 117 of file io.c.

void ubifs_pad ( const struct ubifs_info c,
void buf,
int  pad 
)

ubifs_pad - pad flash space. : UBIFS file-system description object : buffer to put padding to : how many bytes to pad

The flash media obliges us to write only in chunks of c->min_io_size and when we have to write less data we add padding node to the write-buffer and pad it to the next minimal I/O unit's boundary. Padding nodes help when the media is being scanned. If the amount of wasted space is not enough to fit a padding node which takes UBIFS_PAD_NODE_SZ bytes, we write padding bytes pattern (UBIFS_PADDING_BYTE).

Padding nodes are also used to fill gaps when the "commit-in-gaps" method is used.

Definition at line 318 of file io.c.

void ubifs_prep_grp_node ( struct ubifs_info c,
void node,
int  len,
int  last 
)

ubifs_prep_grp_node - prepare node of a group to be written to flash. : UBIFS file-system description object : the node to pad : node length : indicates the last node of the group

This function prepares node at to be written to the media - it calculates node CRC and fills the common header.

Definition at line 412 of file io.c.

void ubifs_prepare_node ( struct ubifs_info c,
void node,
int  len,
int  pad 
)

ubifs_prepare_node - prepare node to be written to flash. : UBIFS file-system description object : the node to pad : node length : if the buffer has to be padded

This function prepares node at to be written to the media - it calculates node CRC, fills the common header, and adds proper padding up to the next minimum I/O unit if is not zero.

Definition at line 379 of file io.c.

int ubifs_read_node ( const struct ubifs_info c,
void buf,
int  type,
int  len,
int  lnum,
int  offs 
)

ubifs_read_node - read node. : UBIFS file-system description object : buffer to read to : node type : node length (not aligned) : logical eraseblock number : offset within the logical eraseblock

This function reads a node of known type and and length, checks it and stores in . Returns zero in case of success, %-EUCLEAN if CRC mismatched and a negative error code in case of failure.

Definition at line 974 of file io.c.

int ubifs_read_node_wbuf ( struct ubifs_wbuf wbuf,
void buf,
int  type,
int  len,
int  lnum,
int  offs 
)

ubifs_read_node_wbuf - read node from the media or write-buffer. : wbuf to check for un-written data : buffer to read to : node type : node length : logical eraseblock number : offset within the logical eraseblock

This function reads a node of known type and length, checks it and stores in . If the node partially or fully sits in the write-buffer, this function takes data from the buffer, otherwise it reads the flash media. Returns zero in case of success, %-EUCLEAN if CRC mismatched and a negative error code in case of failure.

Definition at line 897 of file io.c.

void ubifs_ro_mode ( struct ubifs_info c,
int  err 
)

ubifs_ro_mode - switch UBIFS to read read-only mode. : UBIFS file-system description object : error code which is the reason of switching to R/O mode

Definition at line 82 of file io.c.

int ubifs_sync_wbufs_by_inode ( struct ubifs_info c,
struct inode inode 
)

ubifs_sync_wbufs_by_inode - synchronize write-buffers for an inode. : UBIFS file-system description object : inode to synchronize

This function synchronizes write-buffers which contain nodes belonging to . Returns zero in case of success and a negative error code in case of failure.

Definition at line 1118 of file io.c.

void ubifs_wbuf_add_ino_nolock ( struct ubifs_wbuf wbuf,
ino_t  inum 
)

ubifs_wbuf_add_ino_nolock - add an inode number into the wbuf inode array. : the write-buffer where to add : the inode number

This function adds an inode number to the inode array of the write-buffer.

Definition at line 1074 of file io.c.

int ubifs_wbuf_init ( struct ubifs_info c,
struct ubifs_wbuf wbuf 
)

ubifs_wbuf_init - initialize write-buffer. : UBIFS file-system description object : write-buffer to initialize

This function initializes write-buffer. Returns zero in case of success %-ENOMEM in case of failure.

Definition at line 1026 of file io.c.

int ubifs_wbuf_seek_nolock ( struct ubifs_wbuf wbuf,
int  lnum,
int  offs 
)

ubifs_wbuf_seek_nolock - seek write-buffer. : write-buffer : logical eraseblock number to seek to : logical eraseblock offset to seek to

This function targets the write-buffer to logical eraseblock :. The write-buffer has to be empty. Returns zero in case of success and a negative error code in case of failure.

Definition at line 568 of file io.c.

int ubifs_wbuf_sync_nolock ( struct ubifs_wbuf wbuf)

ubifs_wbuf_sync_nolock - synchronize write-buffer. : write-buffer to synchronize

This function synchronizes write-buffer and returns zero in case of success or a negative error code in case of failure.

Note, although write-buffers are of ->max_write_size, this function does not necessarily writes all ->max_write_size bytes to the flash. Instead, if the write-buffer is only partially filled with data, only the used part of the write-buffer (aligned on ->min_io_size boundary) is synchronized. This way we waste less space.

Definition at line 493 of file io.c.

int ubifs_wbuf_write_nolock ( struct ubifs_wbuf wbuf,
void buf,
int  len 
)

ubifs_wbuf_write_nolock - write data to flash via write-buffer. : write-buffer : node to write : node length

This function writes data to flash via write-buffer . This means that the last piece of the node won't reach the flash media immediately if it does not take whole max. write unit (->max_write_size). Instead, the node will sit in RAM until the write-buffer is synchronized (e.g., by timer, or because more data are appended to the write-buffer).

This function returns zero in case of success and a negative error code in case of failure. If the node cannot be written because there is no more space in this logical eraseblock, %-ENOSPC is returned.

Definition at line 675 of file io.c.

int ubifs_write_node ( struct ubifs_info c,
void buf,
int  len,
int  lnum,
int  offs 
)

ubifs_write_node - write node to the media. : UBIFS file-system description object : the node to write : node length : logical eraseblock number : offset within the logical eraseblock

This function automatically fills node magic number, assigns sequence number, and calculates node CRC checksum. The length of the buffer has to be aligned to the minimal I/O unit size. This function automatically appends padding node and padding bytes if needed. Returns zero in case of success and a negative error code in case of failure.

Definition at line 858 of file io.c.