Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
mtdcore.c File Reference
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
#include <linux/seq_file.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/major.h>
#include <linux/fs.h>
#include <linux/err.h>
#include <linux/ioctl.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/idr.h>
#include <linux/backing-dev.h>
#include <linux/gfp.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include "mtdcore.h"

Go to the source code of this file.

Macros

#define MTD_DEVT(index)   0
 

Functions

 DEFINE_MUTEX (mtd_table_mutex)
 
 EXPORT_SYMBOL_GPL (mtd_table_mutex)
 
struct mtd_info__mtd_next_device (int i)
 
 EXPORT_SYMBOL_GPL (__mtd_next_device)
 
int add_mtd_device (struct mtd_info *mtd)
 
int del_mtd_device (struct mtd_info *mtd)
 
int mtd_device_parse_register (struct mtd_info *mtd, const char **types, struct mtd_part_parser_data *parser_data, const struct mtd_partition *parts, int nr_parts)
 
 EXPORT_SYMBOL_GPL (mtd_device_parse_register)
 
int mtd_device_unregister (struct mtd_info *master)
 
 EXPORT_SYMBOL_GPL (mtd_device_unregister)
 
void register_mtd_user (struct mtd_notifier *new)
 
 EXPORT_SYMBOL_GPL (register_mtd_user)
 
int unregister_mtd_user (struct mtd_notifier *old)
 
 EXPORT_SYMBOL_GPL (unregister_mtd_user)
 
struct mtd_infoget_mtd_device (struct mtd_info *mtd, int num)
 
 EXPORT_SYMBOL_GPL (get_mtd_device)
 
int __get_mtd_device (struct mtd_info *mtd)
 
 EXPORT_SYMBOL_GPL (__get_mtd_device)
 
: MTD device name to open

get_mtd_device_nm - obtain a validated handle for an MTD device by device name

This function returns MTD device description structure in case of success and an error code in case of failure.

struct mtd_infoget_mtd_device_nm (const char *name)
 
 EXPORT_SYMBOL_GPL (get_mtd_device_nm)
 
void put_mtd_device (struct mtd_info *mtd)
 
 EXPORT_SYMBOL_GPL (put_mtd_device)
 
void __put_mtd_device (struct mtd_info *mtd)
 
 EXPORT_SYMBOL_GPL (__put_mtd_device)
 
int mtd_erase (struct mtd_info *mtd, struct erase_info *instr)
 
 EXPORT_SYMBOL_GPL (mtd_erase)
 
int mtd_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, void **virt, resource_size_t *phys)
 
 EXPORT_SYMBOL_GPL (mtd_point)
 
int mtd_unpoint (struct mtd_info *mtd, loff_t from, size_t len)
 
 EXPORT_SYMBOL_GPL (mtd_unpoint)
 
unsigned long mtd_get_unmapped_area (struct mtd_info *mtd, unsigned long len, unsigned long offset, unsigned long flags)
 
 EXPORT_SYMBOL_GPL (mtd_get_unmapped_area)
 
int mtd_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 
 EXPORT_SYMBOL_GPL (mtd_read)
 
int mtd_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
 
 EXPORT_SYMBOL_GPL (mtd_write)
 
int mtd_panic_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
 
 EXPORT_SYMBOL_GPL (mtd_panic_write)
 
int mtd_read_oob (struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
 
 EXPORT_SYMBOL_GPL (mtd_read_oob)
 
int mtd_get_fact_prot_info (struct mtd_info *mtd, struct otp_info *buf, size_t len)
 
 EXPORT_SYMBOL_GPL (mtd_get_fact_prot_info)
 
int mtd_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 
 EXPORT_SYMBOL_GPL (mtd_read_fact_prot_reg)
 
int mtd_get_user_prot_info (struct mtd_info *mtd, struct otp_info *buf, size_t len)
 
 EXPORT_SYMBOL_GPL (mtd_get_user_prot_info)
 
int mtd_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 
 EXPORT_SYMBOL_GPL (mtd_read_user_prot_reg)
 
int mtd_write_user_prot_reg (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, u_char *buf)
 
 EXPORT_SYMBOL_GPL (mtd_write_user_prot_reg)
 
int mtd_lock_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len)
 
 EXPORT_SYMBOL_GPL (mtd_lock_user_prot_reg)
 
int mtd_lock (struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 EXPORT_SYMBOL_GPL (mtd_lock)
 
int mtd_unlock (struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 EXPORT_SYMBOL_GPL (mtd_unlock)
 
int mtd_is_locked (struct mtd_info *mtd, loff_t ofs, uint64_t len)
 
 EXPORT_SYMBOL_GPL (mtd_is_locked)
 
int mtd_block_isbad (struct mtd_info *mtd, loff_t ofs)
 
 EXPORT_SYMBOL_GPL (mtd_block_isbad)
 
int mtd_block_markbad (struct mtd_info *mtd, loff_t ofs)
 
 EXPORT_SYMBOL_GPL (mtd_block_markbad)
 
int mtd_writev (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen)
 
 EXPORT_SYMBOL_GPL (mtd_writev)
 
voidmtd_kmalloc_up_to (const struct mtd_info *mtd, size_t *size)
 
 EXPORT_SYMBOL_GPL (mtd_kmalloc_up_to)
 
 module_init (init_mtd)
 
 module_exit (cleanup_mtd)
 
 MODULE_LICENSE ("GPL")
 
 MODULE_AUTHOR ("David Woodhouse <[email protected]>")
 
 MODULE_DESCRIPTION ("Core MTD registration and access routines")
 

Macro Definition Documentation

#define MTD_DEVT (   index)    0

Definition at line 102 of file mtdcore.c.

Function Documentation

int __get_mtd_device ( struct mtd_info mtd)

Definition at line 649 of file mtdcore.c.

struct mtd_info* __mtd_next_device ( int  i)
read

Definition at line 90 of file mtdcore.c.

void __put_mtd_device ( struct mtd_info mtd)

Definition at line 716 of file mtdcore.c.

int add_mtd_device ( struct mtd_info mtd)

add_mtd_device - register an MTD device : pointer to new MTD device info structure

Add a device to the list of MTD devices present in the system, and notify each currently active MTD 'user' of its arrival. Returns zero on success or 1 on failure, which currently will only happen if there is insufficient memory or a sysfs error.

Definition at line 330 of file mtdcore.c.

DEFINE_MUTEX ( mtd_table_mutex  )
int del_mtd_device ( struct mtd_info mtd)

del_mtd_device - unregister an MTD device : pointer to MTD device info structure

Remove a device from the list of MTD devices present in the system, and notify each currently active MTD 'user' of its departure. Returns zero on success or 1 on failure, which currently will happen if the requested device does not appear to be present in the list.

Definition at line 437 of file mtdcore.c.

EXPORT_SYMBOL_GPL ( mtd_table_mutex  )
EXPORT_SYMBOL_GPL ( __mtd_next_device  )
EXPORT_SYMBOL_GPL ( mtd_device_parse_register  )
EXPORT_SYMBOL_GPL ( mtd_device_unregister  )
EXPORT_SYMBOL_GPL ( register_mtd_user  )
EXPORT_SYMBOL_GPL ( unregister_mtd_user  )
EXPORT_SYMBOL_GPL ( get_mtd_device  )
EXPORT_SYMBOL_GPL ( __get_mtd_device  )
EXPORT_SYMBOL_GPL ( get_mtd_device_nm  )
EXPORT_SYMBOL_GPL ( put_mtd_device  )
EXPORT_SYMBOL_GPL ( __put_mtd_device  )
EXPORT_SYMBOL_GPL ( mtd_erase  )
EXPORT_SYMBOL_GPL ( mtd_point  )
EXPORT_SYMBOL_GPL ( mtd_unpoint  )
EXPORT_SYMBOL_GPL ( mtd_get_unmapped_area  )
EXPORT_SYMBOL_GPL ( mtd_read  )
EXPORT_SYMBOL_GPL ( mtd_write  )
EXPORT_SYMBOL_GPL ( mtd_panic_write  )
EXPORT_SYMBOL_GPL ( mtd_read_oob  )
EXPORT_SYMBOL_GPL ( mtd_get_fact_prot_info  )
EXPORT_SYMBOL_GPL ( mtd_read_fact_prot_reg  )
EXPORT_SYMBOL_GPL ( mtd_get_user_prot_info  )
EXPORT_SYMBOL_GPL ( mtd_read_user_prot_reg  )
EXPORT_SYMBOL_GPL ( mtd_write_user_prot_reg  )
EXPORT_SYMBOL_GPL ( mtd_lock_user_prot_reg  )
EXPORT_SYMBOL_GPL ( mtd_lock  )
EXPORT_SYMBOL_GPL ( mtd_unlock  )
EXPORT_SYMBOL_GPL ( mtd_is_locked  )
EXPORT_SYMBOL_GPL ( mtd_block_isbad  )
EXPORT_SYMBOL_GPL ( mtd_block_markbad  )
EXPORT_SYMBOL_GPL ( mtd_writev  )
EXPORT_SYMBOL_GPL ( mtd_kmalloc_up_to  )
struct mtd_info* get_mtd_device ( struct mtd_info mtd,
int  num 
)
read

get_mtd_device - obtain a validated handle for an MTD device : last known address of the required MTD device : internal device number of the required MTD device

Given a number and NULL address, return the num'th entry in the device table, if any. Given an address and num == -1, search the device table for a device with that address and return if it's still present. Given both, return the num'th driver only if its address matches. Return error code if not.

Definition at line 614 of file mtdcore.c.

struct mtd_info* get_mtd_device_nm ( const char name)
read

Definition at line 677 of file mtdcore.c.

MODULE_AUTHOR ( "David Woodhouse <[email protected]>"  )
MODULE_DESCRIPTION ( "Core MTD registration and access routines )
module_exit ( cleanup_mtd  )
module_init ( init_mtd  )
MODULE_LICENSE ( "GPL"  )
int mtd_block_isbad ( struct mtd_info mtd,
loff_t  ofs 
)

Definition at line 992 of file mtdcore.c.

int mtd_block_markbad ( struct mtd_info mtd,
loff_t  ofs 
)

Definition at line 1002 of file mtdcore.c.

int mtd_device_parse_register ( struct mtd_info mtd,
const char **  types,
struct mtd_part_parser_data parser_data,
const struct mtd_partition parts,
int  nr_parts 
)

mtd_device_parse_register - parse partitions and register an MTD device.

: the MTD device to register : the list of MTD partition probes to try, see 'parse_mtd_partitions()' for more information : MTD partition parser-specific data : fallback partition information to register, if parsing fails; only valid if nr_parts > %0 : the number of partitions in parts, if zero then the full MTD device is registered if no partition info is found

This function aggregates MTD partitions parsing (done by 'parse_mtd_partitions()') and MTD device and partitions registering. It basically follows the most common pattern found in many MTD drivers:

  • It first tries to probe partitions on MTD device using parsers specified in (if is NULL, then the default list of parsers is used, see 'parse_mtd_partitions()' for more information). If none are found this functions tries to fallback to information specified in /.
  • If any partitioning info was found, this function registers the found partitions.
  • If no partitions were found this function just registers the MTD device and exits.

Returns zero in case of success and a negative error code in case of failure.

Definition at line 500 of file mtdcore.c.

int mtd_device_unregister ( struct mtd_info master)

mtd_device_unregister - unregister an existing MTD device.

: the MTD device to unregister. This will unregister both the master and any partitions if registered.

Definition at line 537 of file mtdcore.c.

int mtd_erase ( struct mtd_info mtd,
struct erase_info instr 
)

Definition at line 735 of file mtdcore.c.

int mtd_get_fact_prot_info ( struct mtd_info mtd,
struct otp_info buf,
size_t  len 
)

Definition at line 887 of file mtdcore.c.

unsigned long mtd_get_unmapped_area ( struct mtd_info mtd,
unsigned long  len,
unsigned long  offset,
unsigned long  flags 
)

Definition at line 789 of file mtdcore.c.

int mtd_get_user_prot_info ( struct mtd_info mtd,
struct otp_info buf,
size_t  len 
)

Definition at line 910 of file mtdcore.c.

int mtd_is_locked ( struct mtd_info mtd,
loff_t  ofs,
uint64_t  len 
)

Definition at line 980 of file mtdcore.c.

void* mtd_kmalloc_up_to ( const struct mtd_info mtd,
size_t size 
)

mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size : mtd device description object pointer : a pointer to the ideal or maximum size of the allocation, points to the actual allocation size on success.

This routine attempts to allocate a contiguous kernel buffer up to the specified size, backing off the size of the request exponentially until the request succeeds or until the allocation size falls below the system page size. This attempts to make sure it does not adversely impact system performance, so when allocating more than one page, we ask the memory allocator to avoid re-trying, swapping, writing back or performing I/O.

Note, this function also makes sure that the allocated buffer is aligned to the MTD device's min. I/O unit, i.e. the "mtd->writesize" value.

This is called, for example by mtd_{read,write} and jffs2_scan_medium, to handle smaller (i.e. degraded) buffer allocations under low- or fragmented-memory situations where such reduced allocations, from a requested ideal, are allowed.

Returns a pointer to the allocated buffer on success; otherwise, NULL.

Definition at line 1093 of file mtdcore.c.

int mtd_lock ( struct mtd_info mtd,
loff_t  ofs,
uint64_t  len 
)

Definition at line 956 of file mtdcore.c.

int mtd_lock_user_prot_reg ( struct mtd_info mtd,
loff_t  from,
size_t  len 
)

Definition at line 945 of file mtdcore.c.

int mtd_panic_write ( struct mtd_info mtd,
loff_t  to,
size_t  len,
size_t retlen,
const u_char buf 
)

Definition at line 845 of file mtdcore.c.

int mtd_point ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t retlen,
void **  virt,
resource_size_t phys 
)

Definition at line 754 of file mtdcore.c.

int mtd_read ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t retlen,
u_char buf 
)

Definition at line 800 of file mtdcore.c.

int mtd_read_fact_prot_reg ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t retlen,
u_char buf 
)

Definition at line 898 of file mtdcore.c.

int mtd_read_oob ( struct mtd_info mtd,
loff_t  from,
struct mtd_oob_ops ops 
)

Definition at line 861 of file mtdcore.c.

int mtd_read_user_prot_reg ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t retlen,
u_char buf 
)

Definition at line 921 of file mtdcore.c.

int mtd_unlock ( struct mtd_info mtd,
loff_t  ofs,
uint64_t  len 
)

Definition at line 968 of file mtdcore.c.

int mtd_unpoint ( struct mtd_info mtd,
loff_t  from,
size_t  len 
)

Definition at line 772 of file mtdcore.c.

int mtd_write ( struct mtd_info mtd,
loff_t  to,
size_t  len,
size_t retlen,
const u_char buf 
)

Definition at line 824 of file mtdcore.c.

int mtd_write_user_prot_reg ( struct mtd_info mtd,
loff_t  to,
size_t  len,
size_t retlen,
u_char buf 
)

Definition at line 933 of file mtdcore.c.

int mtd_writev ( struct mtd_info mtd,
const struct kvec vecs,
unsigned long  count,
loff_t  to,
size_t retlen 
)

Definition at line 1057 of file mtdcore.c.

void put_mtd_device ( struct mtd_info mtd)

Definition at line 707 of file mtdcore.c.

void register_mtd_user ( struct mtd_notifier new)

register_mtd_user - register a 'user' of MTD devices. : pointer to notifier info structure

Registers a pair of callbacks function to be called upon addition or removal of MTD devices. Causes the 'add' callback to be immediately invoked for each MTD device currently present in the system.

Definition at line 560 of file mtdcore.c.

int unregister_mtd_user ( struct mtd_notifier old)

unregister_mtd_user - unregister a 'user' of MTD devices. : pointer to notifier info structure

Removes a callback function pair from the list of 'users' to be notified upon addition or removal of MTD devices. Causes the 'remove' callback to be immediately invoked for each MTD device currently present in the system.

Definition at line 586 of file mtdcore.c.