EmbLogic's Blog

Module code to show how device numbers are allocated and deallocated using alloc_chrdev_region() and unregister_chrdev_region().

RCS file: header.h,v
Working file: header.h
head: 1.7
branch:
locks: strict
root: 1.7
access list:
symbolic names:
keyword substitution: kv
total revisions: 7;    selected revisions: 7
description:
Base header file that includes the definitions of all the macros,structures and contains the necessary header files required by the module code.
—————————-
revision 1.7    locked by: root;
date: 2014/02/27 19:28:38;  author: root;  state: Exp;  lines: +4 -0
A macro called DEVICE_NAME is defined using #define.
—————————-
revision 1.6
date: 2014/02/27 19:20:01;  author: root;  state: Exp;  lines: +1 -0
Header file:<linux/fs.h> is added to the base header file to support various functions like alloc_chrdev_region(),unregister_chrdev_region(),etc.
—————————-
revision 1.5
date: 2014/02/27 18:44:36;  author: root;  state: Exp;  lines: +4 -0
A macro called DEBUG is defined using #define.
—————————-
revision 1.4
date: 2014/02/27 18:41:13;  author: root;  state: Exp;  lines: +2 -0
A special macro called MODULE_LICENSE is used to tell the kernel that the module bears a free license without such a decleration the kernel complains.
—————————-
revision 1.3
date: 2014/02/27 18:38:11;  author: root;  state: Exp;  lines: +1 -1
Header file:<linux/module.h> is added to the base header file to provide support for a great many number of macros like:MODULE_LICENSE , MODULE_AUTHOR,etc.
—————————-
revision 1.2
date: 2014/02/27 18:36:07;  author: root;  state: Exp;  lines: +2 -0
Header file:<linux/init.h> is added to the base header file to provide support for module_init() and module_exit() macros.
—————————-
revision 1.1
date: 2014/02/27 18:35:18;  author: root;  state: Exp;
Initial revision
=============================================================================
RCS file: initial.c,v
Working file: initial.c
head: 1.4
branch:
locks: strict
root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;    selected revisions: 4
description:
File containing the module’s initialization function that is called at module insertion time.
—————————-
revision 1.4    locked by: root;
date: 2014/02/28 00:49:11;  author: root;  state: Exp;  lines: +1 -1
alloc_chrdev_region() function is used to allocate dynamically a major number.On success the first device number is stored inside the first argument of this function.
—————————-
revision 1.3
date: 2014/02/27 19:31:39;  author: root;  state: Exp;  lines: +11 -0
Header file: “decleration.h” is added to include all the variable declerations.
—————————-
revision 1.2
date: 2014/02/27 18:50:37;  author: root;  state: Exp;  lines: +7 -0
module_init() macro is used to define which function is called during module’s insertion time.
__init token hints to the kernel that the function is used only at the initialization time.
The function specified by the module_init() macro is declared static because it is not meant to be visible outside the file.
—————————-
revision 1.1
date: 2014/02/27 18:49:06;  author: root;  state: Exp;
Initial revision
=============================================================================
RCS file: cleanup.c,v
Working file: cleanup.c
head: 1.4
branch:
locks: strict
root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;    selected revisions: 4
description:
File that contains the cleanup function which returns all the resources back to the system.
—————————-
revision 1.4    locked by: root;
date: 2014/02/27 19:36:03;  author: root;  state: Exp;  lines: +1 -0
A variable dev of type dev_t storing the device number is included here using extern.
—————————-
revision 1.3
date: 2014/02/27 19:33:49;  author: root;  state: Exp;  lines: +3 -1
Called unregister_chrdev_region() which is having 2 arguments: device number and the total number of device numbers to unregister.
—————————-
revision 1.2
date: 2014/02/27 18:58:02;  author: root;  state: Exp;  lines: +14 -0
module_exit() macro is used to define which function is to be called at module removal time.\
The function specified by the module_exit() macro is declared static because it is not meant to be visible outside the file.
—————————-
revision 1.1
date: 2014/02/27 18:55:42;  author: root;  state: Exp;
Initial revision
=============================================================================

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>