EmbLogic's Blog

question regarding to c???

int main()
{
int b;
char a;
a=&b;
printf(“%p”,a);
}
output=? and why so???

Posted in Uncategorized | Tagged | Leave a comment

the process of booting in linux

The following are the 6 high level stages of a typical Linux boot process.

1. BIOS

BIOS stands for Basic Input/Output System
Performs some system integrity checks
Searches, loads, and executes the boot loader program.
It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR

MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.

3. GRUB

GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which one to be executed.
GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.

#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img

As you notice from the above info, it contains kernel and initrd image.
So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel

Mounts the root file system as specified in the “root=” in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init

Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
Depending on your default init level setting, the system will execute the programs from one of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/
Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
Programs starts with S are used during startup. S for startup.
Programs starts with K are used during shutdown. K for kill.
There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.

Posted in Uncategorized | Leave a comment

Function in c

DIFINATION-it is a block of code that has a property that it is reusable.it may be executed from many different point in c program.

Name of the function is globaly decleared therefore it can be accesed from anywhere in the program.
Use of functions reduce the complexity of the c program and it gives the return type, function name, passing arguments.All the c program have a function ‘main’.

STRUCTURE OF FUNCTION–-

There are three parts of function.

1.FUNCTION PROTOTYPE
2.FUNCTION CALL
3.FUNCTION DEFINITION

FUNCTION PROTOTYPE–>Function prototype gives the return type ,function name and the data type of the arguments that is to be passed.

Return_type Function_name(data type of arguments);
eg- int fun_name(int , int);
Note-In prototype only the data type is define.And the order of the arguement will do matter.
and the prototype will be define globally.

FUNCTION CALL-> Function call will be define in main.In the call function argument will be pass, according to the reqirment of the program.It will declear the element which is about to pass.
And if we want to return a value from defination then store the value in different variable.
There are tthree different way to passing an argument.
a.Pass by value
b.Pass by reference
c.Passing a array
=>In pass by value:-value of deta type will be pass to a function.
=>In pass by reference:-Address of the data type will be pass.
=>In pass by array:-Name and the size of array will be pass to afunction.

eg- function_name(i , j);

//where iand j are the variables,here when we pass the address of the i and j ,then it will be the pass by reference.

function_name(size , name of the array); // pass by array

FUNCTION DEFINITION–>

it gives the return type ,function name and the passing argument with the data type and the body of the difinition is—-

return_type function _name(passed argument with their data types)
{
statements
—————-
}

Posted in Uncategorized | Leave a comment

Drivers to write the data in the multiple quantum from the user space and read the dat in the user space .

//////////////////////////////////////////////////////////////////
head 1.1;
access;
symbols;
locks
abhishek:1.1; strict;
comment @ * @;

1.1
date 2014.02.24.08.43.11; author abhishek; state Exp;
branches;
next ;

desc
@this is the driver to read the data in the application
@

1.1
log
@Initial revision
@
text

/////////////////////////////////////////////////////////////////////////

head 1.3;
access;
symbols;
locks
abhishek:1.3; strict;
comment @ * @;

1.3
date 2014.02.24.08.43.02; author abhishek; state Exp;
branches;
next 1.2;

1.2
date 2014.02.23.11.25.37; author abhishek; state Exp;
branches;
next 1.1;

1.1
date 2014.02.22.11.59.54; author abhishek; state Exp;
branches;
next ;

desc
@This is the driver to write tha dat from the application in the one quanyum.
@

1.3
log
@*** empty log message ***
@
text

/////////////////////////////////////////////////////////////

Posted in Uncategorized | Comments Off

Functions

DEFINATION—A function is a group of statements that together perform a task. Every C program has at least one function, which is main(),

We can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is so each function performs a specific task.

A function declaration tells the compiler about a function’s name, return type, and parameters. A function definitionprovides the actual

Defining a Function:

The general form of a function definition in C programming language is as follows:

return_type function_name( parameter list )
{
   body of the function
}

body of the function.

A function definition in C programming language consists of a function header and a function body. Here are all the parts of a function:

  • Return Type: A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
  • Function Name: This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • Parameters: A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
  • Function Body:The function body contains a collection of statements that define what the function does.

    Function Declarations:

    A function declaration tells the compiler about a function name and how to call the function. The actual body of the function can be defined separately.

    A function declaration has the following parts:

    return_type function_name( parameter list );

    Calling a Function:

    While creating a C function, you give a definition of what the function has to do. To use a function, you will have to call that function to perform the defined task.

    When a program calls a function, program control is transferred to the called function. A called function performs defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns program control back to the main program.

    To call a function, you simply need to pass the required parameters along with function name, and if function returns a value, then you can store returned value

Function Arguments:

If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables are called the formal parameters of the function.

The formal parameters behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit.

While calling a function, there are three ways that arguments can be passed to a function:

1.call by value

2.call by reference

3.call by pointers.

 

Posted in Uncategorized | Leave a comment

Creating a linked list

RCS file: prog.c,v
Working file: prog.c
head: 1.1
branch:
locks: strict
akshat: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;    selected revisions: 1
description:
insertion in link list without functions.
—————————-
revision 1.1    locked by: akshat;
date: 2014/02/24 05:44:24;  author: akshat;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Insertion in link list

RCS file: prog1.c,v
Working file: prog1.c
head: 1.13
branch:
locks: strict
akshat: 1.13
access list:
symbolic names:
keyword substitution: kv
total revisions: 13;    selected revisions: 13
description:
creating a linked list.
with help of functions.
—————————-
revision 1.13    locked by: akshat;
date: 2014/02/24 02:56:51;  author: akshat;  state: Exp;  lines: +10 -7
continued.
—————————-
revision 1.12
date: 2014/02/24 01:40:54;  author: akshat;  state: Exp;  lines: +2 -1
*** empty log message ***
—————————-
revision 1.11
date: 2014/02/24 01:39:54;  author: akshat;  state: Exp;  lines: +13 -11
checking for errors.
ptr is not storing values.
—————————-
revision 1.10
date: 2014/02/24 01:00:14;  author: akshat;  state: Exp;  lines: +10 -9
use of flag.
value of node given was not inserted in pointer array.
—————————-
revision 1.9
date: 2014/02/24 00:52:36;  author: akshat;  state: Exp;  lines: +2 -1
pointer array used for saving values in nodes.
—————————-
revision 1.8
date: 2014/02/24 00:44:17;  author: akshat;  state: Exp;  lines: +1 -0
using debugging tools and statements.
checking for wrong output.
—————————-
revision 1.7
date: 2014/02/23 22:45:30;  author: akshat;  state: Exp;  lines: +2 -2
incorrect output.
—————————-
revision 1.6
date: 2014/02/23 22:43:39;  author: akshat;  state: Exp;  lines: +1 -0
output is not good.
—————————-
revision 1.5
date: 2014/02/23 22:42:15;  author: akshat;  state: Exp;  lines: +1 -1
errors are eliminated.
correction for warnings
—————————-
revision 1.4
date: 2014/02/23 22:40:33;  author: akshat;  state: Exp;  lines: +1 -1
a was declared again.
—————————-
revision 1.3
date: 2014/02/23 22:39:29;  author: akshat;  state: Exp;  lines: +3 -3
checking the errors.
—————————-
revision 1.2
date: 2014/02/23 22:36:59;  author: akshat;  state: Exp;  lines: +3 -2
checking for errors.
passing of correct parameters
—————————-
revision 1.1
date: 2014/02/23 22:33:20;  author: akshat;  state: Exp;
Initial revision

Posted in Uncategorized | Leave a comment

Character driver: Write Operation For Multiple Quantum

head 1.18;
access;
symbols;
locks; strict;
comment @ * @;

1.8
date 2014.02.23.16.17.34; author root; state Exp;
branches;
next 1.7;

1.7
date 2014.02.23.16.16.23; author root; state Exp;
branches;
next 1.6;

1.6
date 2014.02.23.16.13.47; author root; state Exp;
branches;
next 1.5;

1.5
date 2014.02.23.16.12.39; author root; state Exp;
branches;
next 1.4;

1.4
date 2014.02.23.16.11.31; author root; state Exp;
branches;
next 1.3;

1.3
date 2014.02.23.16.07.57; author root; state Exp;
branches;
next 1.2;

1.2
date 2014.02.23.16.01.14; author root; state Exp;
branches;
next 1.1;

1.1
date 2014.02.23.15.43.40; author root; state Exp;
branches;
next ;

Posted in Uncategorized | Leave a comment

character driver

Finally i completed the writing in multiple quantum.

Description of my Character driver-

step-1-> registered the driver by alloc_chrdev_region() and unregistered in exit function by unregister_chrdev_region(). After registering the driver you have major number that is given by by kernel.

step-2->Now initialize device by cdev_init() and use cdev-add() for mapping device to our kernel.

step -3->After that write an application in user space that give the open call to the device and also write an function in driver for opening the device.

step-4->in application write something into device, also write a function to write into device.

 

 

Posted in Character Driver | Leave a comment

Writing data to character device driver

RCS file: wwrite.c,v
Working file: wwrite.c
head: 1.7
branch:
locks: strict
raghav: 1.7
access list:
symbolic names:
keyword substitution: kv
total revisions: 7;    selected revisions: 7
description:
The file_operations structure is defined in linux/fs.h
—————————-
revision 1.7    locked by: raghav;
date: 2014/02/23 13:27:46;  author: raghav;  state: Exp;  lines: +3 -2
displayed the data in kernel using copy_from_user
—————————-
revision 1.6
date: 2014/02/23 13:25:54;  author: raghav;  state: Exp;  lines: +1 -1
implemented copy_from_user to copy the data from application layer
—————————-
revision 1.5
date: 2014/02/23 13:25:12;  author: raghav;  state: Exp;  lines: +1 -1
using kalloc : creating memory for required number of quantums
—————————-
revision 1.4
date: 2014/02/23 13:23:58;  author: raghav;  state: Exp;  lines: +1 -1
now count the number of qset required
allocating memory for required number of qset
implemented memset for qset memory
—————————-
revision 1.3
date: 2014/02/23 13:22:57;  author: raghav;  state: Exp;  lines: +1 -1
Allocating memory for scullqset and also clean this memory using memset
—————————-
revision 1.2
date: 2014/02/23 13:22:09;  author: raghav;  state: Exp;  lines: +1 -2
count the number of scullQset required
—————————-
revision 1.1
date: 2014/02/23 13:20:43;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Implementing cdev_del() — remove a cdev from the system

RCS file: clean.c,v
Working file: clean.c
head: 1.3
branch:
locks: strict
raghav: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;    selected revisions: 3
description:
to delete the chr_dev structure which we had initialized during chr_dev init
—————————-
revision 1.3    locked by: raghav;
date: 2014/02/23 13:09:42;  author: raghav;  state: Exp;  lines: +2 -2
now unregistering the driver from the driver table using major minor number.
—————————-
revision 1.2
date: 2014/02/23 13:09:07;  author: raghav;  state: Exp;  lines: +1 -1
kfree — free previously allocated memory
—————————-
revision 1.1
date: 2014/02/23 13:08:14;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

structure.

structure- we can say that it is user defined array but it contains diff data types in a continuous memory location.
syntax-
struct name — user defined data type
{
type1 element1;
type2 element2;

};
struct name variable; –to allocate space
To access elements
there are two methods to access elements
a.) when structure variable is used.
an operator scope resolution operator( . ) is used.
variable.element;
b.) when structure pointer is used.
first of all we must allocate memory to the pointer which can be done by using malloc.
But typecasting is reqired.
pointer name = (struct name *)malloc(sizeof(struct name));
( struct name *) is used for type casting.
operator (->) is used to access elements.
pointer->element;

Posted in Uncategorized | Leave a comment

Structures

Structure is a user defined data type which is a collection of different elements of different data types stored at a continuous memory location.

Syntax for structure is:

struct name

{

data-type element;

data_type element;

………;

………;

};

struct name variable;

structure function is always declared globally. struct name variable can be written inside the scope of the main function().

eg:                  struct distance

{

int feet;

float inches;

};

struct distance d;

Here d is the variable of struct distance type. And the memory is automatically given to d variable. then inside the main function, value given to feet and inches will b as shown:

int main()

{

d.feet=5;

d.inches=6.1;

printf(“distance in feet is:%d and in inches:%d\n”,d.feet,d.inches);

}

If variable d is a pointer of struct distance type,then the memory is not allocated directly to the d pointer. then inside main function() the value to feet and inches will be given as follows:

int main()

{

d->feet=5;

d->inches=4.1;

printf(“distance in feet:%d and inches:%d\n”,d->feet,d->inches);

}

when variable is declared of struct distance type then accessing the value is in the form d.feet and d.inches,where ” . ” represents the scope resolution operator.

When pointer is declared of struct distance type then accessing the value is in the form of d->feet and d->inches,where ” . ” is changed to ” -> “.

Posted in Uncategorized | Leave a comment

Drivers to write the data from the apploication in the one quantum.

head 1.4;
access;
symbols;
locks
root:1.4; strict;
comment @ * @;

1.4
date 2014.02.13.12.11.39; author root; state Exp;
branches;
next 1.3;

1.3
date 2014.02.13.06.09.15; author root; state Exp;
branches;
next 1.2;

1.2
date 2014.02.12.16.08.56; author root; state Exp;
branches;
next 1.1;

1.1
date 2014.02.11.07.35.45; author root; state Exp;
branches;
next ;

desc
@Declare the macros
@

head 1.4;
access;
symbols;
locks
root:1.4; strict;
comment @ * @;

1.4
date 2014.02.13.12.12.31; author root; state Exp;
branches;
next 1.3;

1.3
date 2014.02.13.06.09.15; author root; state Exp;
branches;
next 1.2;

1.2
date 2014.02.12.16.08.59; author root; state Exp;
branches;
next 1.1;

1.1
date 2014.02.11.07.36.10; author root; state Exp;
branches;
next ;

desc
@Defi8ne the device struct ScullDev
@

1.4
log
@Remove the structre struct ScullDev .
Only declare the objects as sculldev and scull_local.
@
text

head 1.5;
access;
symbols;
locks
root:1.5; strict;
comment @ * @;

1.5
date 2014.02.13.12.11.07; author root; state Exp;
branches;
next 1.4;

1.4
date 2014.02.13.06.08.26; author root; state Exp;
branches;
next 1.3;

1.3
date 2014.02.12.16.08.36; author root; state Exp;
branches;
next 1.2;

1.2
date 2014.02.11.07.28.57; author root; state Exp;
branches;
next 1.1;

1.1
date 2014.02.11.04.24.33; author root; state Exp;
branches;
next ;

desc
@this is the kernel file to find the major and minor numbers.
@

1.5
log
@extern the file_operations fops.
@
text

head 1.3;
access;
symbols;
locks
root:1.3; strict;
comment @ * @;

1.3
date 2014.02.13.06.09.11; author root; state Exp;
branches;
next 1.2;

1.2
date 2014.02.12.16.08.44; author root; state Exp;
branches;
next 1.1;

1.1
date 2014.02.11.07.35.06; author root; state Exp;
branches;
next ;

desc
@free the memmory of ScullDev
@

1.3
log
@*** empty log message ***
@
text

head 1.2;
access;
symbols;
locks
abhishek:1.2; strict;
comment @ * @;

1.2
date 2014.02.22.11.59.36; author abhishek; state Exp;
branches;
next 1.1;

1.1
date 2014.02.15.10.34.19; author abhishek; state Exp;
branches;
next ;

desc
@release function used to close the application .
@

1.2
log
@*** empty log message ***
@
text

head 1.2;
access;
symbols;
locks
abhishek:1.2; strict;
comment @ * @;

1.2
date 2014.02.22.11.58.23; author abhishek; state Exp;
branches;
next 1.1;

1.1
date 2014.02.15.09.56.50; author abhishek; state Exp;
branches;
next ;

desc
@open function: to open the file.
@

1.2
log
@give the address passed by container_of() in the private_data.
@
text

//////////////////////////////////////////////////////////////////////////

head 1.1;
access;
symbols;
locks
abhishek:1.1; strict;
comment @ * @;

1.1
date 2014.02.22.11.59.54; author abhishek; state Exp;
branches;
next ;

desc
@This is the driver to write tha dat from the application in the one quanyum.
@

1.1
log
@Initial revision
@
text

//////////////////////////////////////////////////////////////////////////////////////////

Posted in Uncategorized | Comments Off

boot-up process

                                                                        BOOT- UP PROCESS

When you switch ON your system within a few seconds a login window appears. Ever wandered how this window appears? What all steps are performed before this window
appears?
The whole process starting from the switching ON the power supply till the time your
computer is ready for you to work on is called bootup process.
It is 6 stage process that includes steps:

step1: BIOS(Basic Input Output System)
it performs some system integrity tests.
It searches for the boot loader in floppy, cd-rom,or hard drive depending on the
priority set by you,.and after finding it loads it and executes it.
This boot loader is called MBR(Master Boot Record) which is in the 1st sector of the
booting device.
So basically BIOS loads and executes MBR boot loader.
Step 2: MBR(Master Boot Record)
It is located in the first sector of booting device in less than 512 bytes. It has 3
components 1. primary boot loader info in 1st 446 bytes 2nd partition table info in
next 64 bytes 3rd MBR validation check in last 2 bytes.
It contain the info of the secondary boot loader i.e. The GRUB or LILO.
So in short MBR loads and executes the GRUB boot loader.
Step 3: GRUB(Grand Unified Bootloader)
it loads the kernel image and initrd images
it is the GRUB that displays the screen asking you to choose the kernel image to load
among the various kernel images you have on your system.
GRUB configuration file is in /boot/grub/grub.conf which contains info about the
kernel and initrd image to load.
Step 4: Kernel
it mounts the root file system as specified in grub.conf.
Kernel then executes the /sbin/init program which is the first program to beexecuted by the kernel so it has a pid of 1.
initrd stands for initial RAM disk.
It is used by kernel as the temporary root file system until kernel is booted and the
real root file system is mounted. It also contains necessary drivers compiled inside,
which helps in access of hard drives partitions and other hardware.
\

Step 5: Init program
this program checks the /etc/inittab file to decide the linux runlevel.
The run levels availabe are
0-halt
1-single user mode
2-multiuser without NFS
3-full multiuser mode
4-unused
5-X11
6-reboot
Step 6:Runlevel Programs
Depending upon the runlevel set the system wilRun level 0- /etc/rc.d/rc0.d/l execute
the programs from one of the directories.Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/

Posted in Uncategorized | Leave a comment