EmbLogic's Blog

memory mapping and intilize to kernel

RCS file: cleanup.c,v
Working file: cleanup.c
head: 1.3
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 3; selected revisions: 3
description:
—————————-
revision 1.3
date: 2014/06/28 09:11:41; author: root; state: Exp; lines: +2 -2
exit function for unregister
—————————-
revision 1.2
date: 2014/06/27 10:22:45; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.1
date: 2014/06/27 07:06:14; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: default.h,v
Working file: default.h
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
—————————-
revision 1.2
date: 2014/06/28 09:12:31; author: root; state: Exp; lines: +10 -5
used majoe and minor no.
—————————-
revision 1.1
date: 2014/06/27 07:06:18; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: declartion.h,v
Working file: declartion.h
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
—————————-
revision 1.2
date: 2014/06/28 09:13:01; author: root; state: Exp; lines: +20 -0
used sculldev
—————————-
revision 1.1
date: 2014/06/27 07:06:19; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

memory mapping and intillize

RCS file: init1.c,v
enter description, terminated with single ‘.’ or end of file:
NOTE: This is NOT the log message!
>> mapping of kernel
>> .
done
[root@emblogic memory]# ci init1.c
init1.c,v init1.c
revision 1.1
done
[root@emblogic memory]# rlog init.c cleanup.c default.h declartion.h

RCS file: init.c,v
Working file: init.c
head: 1.2
branch:
locks: strict
root: 1.2
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
—————————-
revision 1.2 locked by: root;
date: 2014/06/27 10:28:50; author: root; state: Exp; lines: +10 -6
*** empty log message ***
—————————-
revision 1.1
date: 2014/06/27 07:06:07; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: cleanup.c,v
Working file: cleanup.c
head: 1.3
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 3; selected revisions: 3
description:
—————————-
revision 1.3
date: 2014/06/28 09:11:41; author: root; state: Exp; lines: +2 -2
exit function for unregister
—————————-
revision 1.2
date: 2014/06/27 10:22:45; author: root; state: Exp; lines: +3 -3
*** empty log message ***
—————————-
revision 1.1
date: 2014/06/27 07:06:14; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: default.h,v
Working file: default.h
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
—————————-
revision 1.2
date: 2014/06/28 09:12:31; author: root; state: Exp; lines: +10 -5
used majoe and minor no.
—————————-
revision 1.1
date: 2014/06/27 07:06:18; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: declartion.h,v
Working file: declartion.h
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
—————————-
revision 1.2
date: 2014/06/28 09:13:01; author: root; state: Exp; lines: +20 -0
used sculldev
—————————-
revision 1.1
date: 2014/06/27 07:06:19; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

project 1 : MDC

Added the characters of file to the master array.

created a script for bash shell to execute the repeated commands quickly.

Posted in Project 2: Multiple Data Compression and Encryption | Leave a comment

Print the no. in increasing and decreasing order with a single line in code

Hi,
Yesterday I came across a problem. The problem was to print no.(s); firstly in increasing order then decreasing order. It is not a problem at all. But the real trick was, to print it using a single line of code. I took it as challenge, and designed  this code. After getting the desired output, I realized that now I’ve better understanding of ternary operators.
If anyone has some better code, then please share.
Thank you Emblogic.

#include<stdio.h>
int main()
{
int i=-1,j=0,c = 0,n;
printf(“Enter the no.: “);
scanf(“%d”,&n);
while((j<=2*n+1)&&printf(“%d, “, c==0 ? ( i==n ? printf(“\n”), c=i–: ++i) : i– , j++));
return 0;
}

Posted in Uncategorized | Leave a comment

what is a Device Driver

What is a Device Driver?

Making hardware work is tedious. To write to a hard disk, for example, requires that you write magic numbers in magic places, wait for the hard drive to say that it is ready to receive data, and then feed it the data it wants, very carefully. To write to a floppy disk is even harder, and requires that the program supervise the floppy disk drive almost constantly while it is running.

Instead of putting code in each application you write to control each device, you share the code between applications. To make sure that that code is not compromised, you protect it from users and normal programs that use it. If you do it right, you will be able to add and remove devices from your system without changing your applications at all. Furthermore, you need to be able to load your program into memory and run it, which the operating system also does. So an operating system is essentially a priviledged, general, sharable library of low-level hardware and memory and process control functions and routines.

All versions of Unix have an abstract way of reading and writing devices. By making the devices act as much as possible like regular files, the same calls (read(), write(), etc.) can be used for devices and files. Within the kernel, there are a set of functions, registered with the filesystem, which are called to handle requests to do I/O on “device special files,” which are those which represent devices. (See mknod(1,2) for an explanation of how to make these files.)

All devices controlled by the same device driver are given the same major number, and of those with the same major number, different devices are distinguished by different minor numbers. (This is not strictly true, but it is close enough. If you understand where it is not true, you don’t need to read this section, and if you don’t but want to learn, read the code for the tty devices, which uses up 2 major numbers, and may use a third and possibly fourth by the time you read this. Also, the “misc” major device supports many minor devices that only need a few minor numbers; we’ll get to that later.)

This chapter explains how to write any type of Linux device driver that you might need to, including character, block, SCSI, and network drivers. It explains what functions you need to write, how to initialize your drivers and obtain memory for them efficiently, and what function are built in to Linux to make your job easier.

Creating device drivers for Linux is easier than you might think. It merely involves writing a few functions and registering them with the Virtual Filesystem Switch (VFS), so that when the proper device special files are accessed, the VFS can call your functions.

However, a word of warning is due here: Writing a device driver is writing a part of the Linux kernel. This means that your driver runs with kernel permissions, and can do anything it wants to: write to any memory, reformat your hard drive, damage your monitor or video card, or even break your dishes, if your dishwasher is controlled by your computer. Be careful.

Also, your driver will run in kernel mode, and the Linux kernel, like most Unix kernels, is non-pre-emptible. This means that if you driver takes a long time to work without giving other programs a chance to work, your computer will appear to “freeze” when your driver is running. Normal user-mode pre-emptive scheduling does not apply to your driver.

Posted in Device Drivers | Leave a comment

Parallel Port DD (Compatibility mode ).

#use the parallel port in the compatibility mode which is work in the forward direction and in this i use the read operation which is seems to be the reverse operation but its not the reverse operation because we reterive the data in the single PC wihch is in the form of the buffer....
RCS file: devopen.c,v
Working file: devopen.c
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;	selected revisions: 1
description:
mapp the devopen function with file_operation..
----------------------------
revision 1.1
date: 2014/06/23 10:13:11;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: devwrite.c,v
Working file: devwrite.c
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;	selected revisions: 2
description:
use copy_from_user which is used to receive the data from the application layer to kernel layer...
then use outb to send the information from kernel layer to parallel port...
----------------------------
revision 1.2
date: 2014/06/23 10:37:08;  author: root;  state: Exp;  lines: +1 -1
*** empty log message ***
----------------------------
revision 1.1
date: 2014/06/23 09:54:34;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: fileopr.h,v
Working file: fileopr.h
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;	selected revisions: 1
description:
file operation call which is used in init only...
this is not include in the header because if i include this is header then suffer a problem of multiple declaration...
----------------------------
revision 1.1
date: 2014/06/23 09:54:34;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: init.c,v
Working file: init.c
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;	selected revisions: 2
description:
call the module_init and module_exit for initilization and cleanup respectively..
alloc_chrdev_region, cdev_init, check_region,release_region, request_region, and cdev_add
in module_exit function call release_region, unregister_chrdev_region....
----------------------------
revision 1.2
date: 2014/06/23 09:54:16;  author: root;  state: Exp;  lines: +9 -1
include the file operation file in this
----------------------------
revision 1.1
date: 2014/06/23 05:08:09;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: devread.c,v
Working file: devread.c
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;	selected revisions: 1
description:
mapp the read in kernel layer with the application...
----------------------------
revision 1.1
date: 2014/06/23 09:54:34;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: header.h,v
Working file: header.h
head: 1.3
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;	selected revisions: 3
description:
include all the header file need for this project like init, module, fs, cdev, slab and ioport for the parallel port...
define some macros like DEVNAME as device name MAJORNO MINORNO QSET_SIZE QUANTUM_SIZE
define the struct ScullDev and ScullQset....
define the struct of file_operation for the mapping...
----------------------------
revision 1.3
date: 2014/06/23 10:12:33;  author: root;  state: Exp;  lines: +2 -0
give the prototype for the devopen
----------------------------
revision 1.2
date: 2014/06/23 09:53:30;  author: root;  state: Exp;  lines: +17 -3
remove the file_operation from this...
include the header file for the outb and copy_from_user
----------------------------
revision 1.1
date: 2014/06/23 05:08:09;  author: root;  state: Exp;
Initial revision
=============================================================================
Posted in Uncategorized | Leave a comment

kernel register

RCS file: init.c,v
Working file: init.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
print the hello kernel
used the register
\.
—————————-
revision 1.1 locked by: root;
date: 2014/06/26 05:29:50; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: cleanup.c,v
Working file: cleanup.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
used the unregister function
—————————-
revision 1.1 locked by: root;
date: 2014/06/26 05:29:50; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: header.h,v
Working file: header.h
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
used the headerfile init.h
used the headerfile module.h
also used the headerfile fs.h
—————————-
revision 1.1 locked by: root;
date: 2014/06/26 05:29:50; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: default.h,v
Working file: default.h
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
in this difine the majorno
also define the device name
—————————-
revision 1.1 locked by: root;
date: 2014/06/26 05:29:50; author: root; state: Exp;
Initial revision
=============================================================================

RCS file: declartion.h,v
Working file: declartion.h
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
used the extern
—————————-
revision 1.1 locked by: root;
date: 2014/06/26 05:29:50; author: root; state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Implementation of Register and Unregister in kernel

……………………………HEADER………………………………..

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

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

desc
@The test of register and unregister on kernels
@

……………………….DEFAULT…………………………..

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

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

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

desc
@The define is using
@

1.2
log
@chrdev is change
@
text

……………………………………DECLERATION…………………………………..

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

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

desc
@The declear is extern majorno.
@

1.1
log
@Initial revision
@

………………………………………….INITIALIZATION……………………………

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

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

desc
@This is initialization
@

1.1
log
@Initial revision
@
text

………………………………………….CLEANUP…………………………………………

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

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

desc
@This is cleanup.
@

1.1
log
@Initial revision
@

………………………………………….EDIT……………………………………..

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @# @;

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

desc
@The all file include chrdev
@

1.1
log
@Initial revision
@

Posted in Character Driver | Leave a comment

IPC

Posted in Uncategorized | Leave a comment

system administration

i’ve learnt today to create user with command-useradd, also difined user’s directory & shell,  using chown i’ve changed the user & group owner of the file & directory,  i also learnt the use of chmod,ll,userdel,passwd,ap,grep by practising them……

Posted in Data Structures with C | Leave a comment

A Program that reads integers untill 0 is entered. after input terminates, the program report the total number of even integers (excluding 0) entered,the average value of the even integers,the total number of odd integers entered , and the value of the odd integers.

#include<stdio.h>
int main()
{
int n,even=0,odd=0;
float sumodd=0,sumeven=0;
scanf(“%d”,&n);
while(n!=0)
{
if(n%2==0)
{
even++;
sumeven=sumeven+n;
}
else
{
odd++;
sumodd=sumodd+n;
}
scanf(“%d”,&n);
}

printf(“\nTotal even num are %d nd Their Average is %f    \n “, even, sumeven/even );
printf(“Total odd  num are %d nd Their Average is   %f \n “, odd, sumodd/odd);

return 0;
}

Posted in Uncategorized | Leave a comment

Implemented FTP SERVER USING SOCKETS

60    {
61       if(database_size==3)
62          goto label3;
63       i=i+43;
64       goto  label;
65    }
66    read(connect_fd,password,10);
67    j=11;
68 label1:
69    lseek(fd1,j,SEEK_SET);
70    database_size1++;
71    ret=read(fd1,m_password,10);
72    if(ret<0)
73       perror(“reading file\n”);
74    if(!(strcmp(password,m_password)))
75    {
76       flag_password=0;
77    lseek(fd1,j+11,SEEK_SET);
78    read(fd1,path,20);
79    }
80    else
81    {
82       if(database_size1==3)
83          goto label3;
“ftp_server.c,v” 180L, 3961C                                                        68,4          37%

Posted in Project 04: FTP based Client Server using Threads and Sockets | Leave a comment

FTP server using Sockets

RCS file: server.c,v
Working file: server.c
head:
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 0
description:
implemented GETS,PUTS functions in ftp using socket programming.
=============================================================================

Posted in Project 04: FTP based Client Server using Threads and Sockets, Uncategorized | Tagged | Leave a comment

Nested Structures Ft. Pointer

#include<stdio.h>
#include<stdlib.h>

struct disfeet
{
int *f;

};

struct distance
{
struct disfeet *d;
};

int main()
{
struct distance *d1;

d1=(struct distance *)malloc(sizeof(struct distance));
d1->d=(struct disfeet *)malloc(sizeof(struct disfeet));
d1->d->f=(int *)malloc(sizeof(int));

printf(“enter distance\n”);
scanf(“%d”,&d1->d->f);

printf(“distance is %d feet.\n\n”,d1->d->f);

return 0;

}

Posted in Uncategorized | Leave a comment

C Structure and It’s Simple Programme

1.What is Structure ?
Structure is the collection of variables of different types under a single name for better handling. For example: You want to store the information about person about his/her name, citizenship number and salary. You can create these information separately but, better approach will be collection of these information under single name because all these information are related to person.

2.Keyword struct is used for creating a structure.

3.Syntax of Sructure
struct structure_name
{
data_type vari.1;
data_type vari.2;
.
.
data_type vari.n;
};

4.We Can Create Structure according to above mention example and Formate of Structure

5.

struct person
{
char name[50];
int cit_no;
float salary;
};

6.Structure variable declaration

When a structure is defined, it creates a user-defined type but, no storage is allocated. For the above structure of person, variable can be declared as:

struct person
{
char name[50];
int cit_no;
float salary;
};

Inside main function:
struct person p1, p2, p[20];
when We declare variable then memory allocation done.

Another way of creating sturcture variable is:

struct person
{
char name[50];
int cit_no;
float salary;
}p1 ,p2 ,p[20];

7. Accessing members of a structure

There are two types of operators used for accessing members of a structure.

1. Member operator(.)
2.Structure pointer operator(->) (it is used when variable is Pointer)

Suppose, we want to access salary for variable p2. Then, it can be accessed as:

8. Example of structure

Write a C program to add two distances entered by user. Measurement of distance should be in inch and feet.

/// Header File ////
#include
struct Distance
{
int feet;
float inch;
}

///// C File ///////
#include”header.h”
int main()
{
struct Distance d1,d2,sum;
printf(“1st distance\n”);
printf(“Enter feet: “);
scanf(“%d”,&d1.feet); /* input of feet for structure variable d1 */
printf(“Enter inch: “);
scanf(“%f”,&d1.inch); /* input of inch for structure variable d1 */
printf(“2nd distance\n”);
printf(“Enter feet: “);
scanf(“%d”,&d2.feet); /* input of feet for structure variable d2 */
printf(“Enter inch: “);
scanf(“%f”,&d2.inch); /* input of inch for structure variable d2 */
sum.feet=d1.feet+d2.feet;
sum.inch=d1.inch+d2.inch;
if (sum.inch>12)
{
++sum.feet;
sum.inch=sum.inch-12;
} //If inch is greater than 12, changing it to feet.

printf(“Sum of distances=%d\’-%.1f\””,sum.feet,sum.inch);
/* printing sum of distance d1 and d2 */
return 0;
}

9.OUTPUT

1st distance
Enter feet: 10
Enter inch: 4.5
2nd distance
Enter feet: 4
Enter inch: 10.5
Sum of distances= 15′-3″

Posted in Data Structures with C | Leave a comment