EmbLogic's Blog

Module code showing how to read data in a single quantum using copy_to_user() function.

RCS file: readf.c,v
Working file: readf.c
head: 1.11
branch:
locks: strict
root: 1.11
access list:
symbolic names:
keyword substitution: kv
total revisions: 11;    selected revisions: 11
description:
chardev_read() function is implemented here in this file.
—————————-
revision 1.11    locked by: root;
date: 2014/03/04 00:31:32;  author: root;  state: Exp;  lines: +1 -1
Status : reading data from a single quantum is implemented successfully.
—————————-
revision 1.10
date: 2014/03/02 17:33:44;  author: root;  state: Exp;  lines: +1 -1
Typecasting is done.
—————————-
revision 1.9
date: 2014/03/02 17:32:15;  author: root;  state: Exp;  lines: +4 -0
Checking the data inside the quantum by printing it using lsculldev->scullqset->data[0].
—————————-
revision 1.8
date: 2014/03/02 17:30:51;  author: root;  state: Exp;  lines: +1 -0
Logical error while using copy_to_read().
Debugging……
—————————-
revision 1.7
date: 2014/03/02 17:27:23;  author: root;  state: Exp;  lines: +1 -1
Bug fixed.
Issue:type-casting not performed.
—————————-
revision 1.6
date: 2014/03/02 17:24:51;  author: root;  state: Exp;  lines: +11 -0
copy_to_user() function is used to copy the data from the quantum to the ubuff.It is similar to the copy_from_user() function.
Declared an ret variable which represents the number of characters not successfully read.
—————————-
revision 1.5
date: 2014/03/02 17:08:52;  author: root;  state: Exp;  lines: +7 -1
Printing the address contained inside the filep->private_data.
—————————-
revision 1.4
date: 2014/03/02 17:05:12;  author: root;  state: Exp;  lines: +2 -1
Declared a pointer of type struct Sculldev.
Assigning the filep->private_data to lsculldev.
—————————-
revision 1.3
date: 2014/03/02 16:53:58;  author: root;  state: Exp;  lines: +6 -1
ubuff is a user space pointer that points to the data in the application.Therefore, it cannot be directly dereferenced by kernel code.
Using this pointer the data inside the application and its size is printed here.
Checking…….
—————————-
revision 1.2
date: 2014/03/02 16:20:56;  author: root;  state: Exp;  lines: +13 -0
Gave two printk() statements inside chardev_read() function to mark the start and end of this function.Also included the prototype of this function using extern.
—————————-
revision 1.1
date: 2014/03/02 16:14:35;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Character Driver, Device Drivers | Leave a comment

Module code showing how to write data in multiple quantums from a user application.

RCS file: writef.c,v
Working file: writef.c
head: 1.19
branch:
locks: strict
root: 1.19
access list:
symbolic names:
keyword substitution: kv
total revisions: 19;    selected revisions: 19
description:
chardev_write() function reside here.
—————————-
revision 1.19    locked by: root;
date: 2014/03/03 19:00:50;  author: root;  state: Exp;  lines: +2 -2
Status : Writing in multiple quantums is successfully done.

Previous Issues:
1.Allocating memory for qset array incorrectly.
2.Wrongly calculating the number of qset arrays.
Such logical errors are identified and corrected successfully.
—————————-
revision 1.18
date: 2014/03/03 18:55:17;  author: root;  state: Exp;  lines: +13 -13
Corrected the argument inside kmalloc().The size of the qset array is calculated by multiplying the qset size with the size of the pointer.
Also modified a message to display how many qset arrays are created.
—————————-
revision 1.17
date: 2014/03/01 21:01:35;  author: root;  state: Exp;  lines: +2 -2
Status : Writing in multiple quantums successfully implemented.
—————————-
revision 1.16
date: 2014/03/01 20:53:57;  author: root;  state: Exp;  lines: +20 -10
Modifying the code to work for writing in more than one quantums.
—————————-
revision 1.15
date: 2014/03/01 11:19:07;  author: root;  state: Exp;  lines: +5 -0
One printk statement is added to test whether the data is actually copied into the kernel buffer or not.
Testing……….
—————————-
revision 1.14
date: 2014/03/01 11:13:18;  author: root;  state: Exp;  lines: +15 -7
The copy_from_user() function is used to copy a block of data from user space into the kernel buffer.copy_from_user() function contains 3 arguments:
1.A destination buffer,
2.A source buffer,and
3.length in bytes.
—————————-
revision 1.13
date: 2014/03/01 11:06:21;  author: root;  state: Exp;  lines: +2 -1
Done memset().
Testing the code…..
—————————-
revision 1.12
date: 2014/03/01 11:01:16;  author: root;  state: Exp;  lines: +54 -5
Implemented the create_quantums() function that will create the required number of quantums.
Kmalloc() is used to allocate memory for each quantum.
Filling the memory allocated using kmalloc() with memset() so that it does not contain any garbage.
—————————-
revision 1.11
date: 2014/03/01 10:39:39;  author: root;  state: Exp;  lines: +1 -0
memset() function is used to fill the memory allocated for the qset array to ”.
—————————-
revision 1.10
date: 2014/03/01 10:36:59;  author: root;  state: Exp;  lines: +14 -4
Using kmalloc() memory is allocated to the required number of qsets.
Checking whether it is working fine or not.
—————————-
revision 1.9
date: 2014/03/01 10:26:27;  author: root;  state: Exp;  lines: +36 -2
Implemented create_scullqset() function.Now checking the number of qsets that needs to created by using the size argument of the chardev_write().After determining the number of qsets that needs to be created create_qset() function is called.
—————————-
revision 1.8
date: 2014/03/01 10:07:44;  author: root;  state: Exp;  lines: +2 -1
memset() function is used to fill the memory allocated using kmalloc() with ” .
—————————-
revision 1.7
date: 2014/03/01 10:04:21;  author: root;  state: Exp;  lines: +10 -0
Allocating memory for 1 scullqset to check whether the create_scullqset() function is working properly or not.
—————————-
revision 1.6
date: 2014/03/01 09:56:22;  author: root;  state: Exp;  lines: +22 -2
After finding out the number of scullqsets,create_scullqset() function is called to create the specified number of scullqsets.
Checking whether the function calling is taking place or not……
—————————-
revision 1.5
date: 2014/03/01 09:47:56;  author: root;  state: Exp;  lines: +19 -0
The size argument that specifies the size of the buffer pointed to by ubuff is used to find the number of scullqsets that needs to be created.
After finding out the exact number of scullqsets that needs to be created,the number of scullqsets are printed.
Creating scullqsets…….
—————————-
revision 1.4
date: 2014/03/01 09:32:34;  author: root;  state: Exp;  lines: +1 -1
Fixed the warning by type-casting size_t to int.
—————————-
revision 1.3
date: 2014/03/01 09:28:31;  author: root;  state: Exp;  lines: +6 -1
Checking whether the ubuff pointer is actually pointing to the buffer in the application.Also checking the size field inside the 3rd argument of chardev_write().
—————————-
revision 1.2
date: 2014/03/01 09:20:00;  author: root;  state: Exp;  lines: +9 -1
Printing the address inside filep->private_data to check whether it matches with the address returned by container_of() macro.
A local variable of type Sculldev is declared which will store the address that is present inside filep->private_data.
—————————-
revision 1.1
date: 2014/02/28 21:33:05;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Character Driver, Device Drivers | Leave a comment

Module code showing how to write data in multiple qset arrays from a user application.

RCS file: writef.c,v
Working file: writef.c
head: 1.37
branch:
locks: strict
root: 1.37
access list:
symbolic names:
keyword substitution: kv
total revisions: 37;    selected revisions: 37
description:
chardev_write() function reside here.
—————————-
revision 1.37    locked by: root;
date: 2014/03/04 18:55:04;  author: root;  state: Exp;  lines: +0 -21
Status : Writing in multiple qset arrays is successfully implemented.

Issue:The data pointer to the qset array was updated to point to the last qset array.Because of this reason the crash is taking place.
Bug fixed.
—————————-
revision 1.36
date: 2014/03/04 18:43:52;  author: root;  state: Exp;  lines: +18 -4
Input/output crash is taking place.
Debugging…..
—————————-
revision 1.35
date: 2014/03/04 07:36:31;  author: root;  state: Exp;  lines: +3 -1
Logical error fixed.
Issue : flag variable is not set to 1 due to which it is not able to link the scullqsets.
—————————-
revision 1.34
date: 2014/03/04 07:21:30;  author: root;  state: Exp;  lines: +7 -2
Declared a count variable inside create_scullqset() function too to make sure that exactly how many scullqsets are created.
The number of scullqsets are properly created inside the create_scullqset() function,but inside the chardev_write() it is showing 1 only same is the case with qset_arrays.
—————————-
revision 1.33
date: 2014/03/04 07:16:19;  author: root;  state: Exp;  lines: +10 -6
The messages inside two error conditions are changed to make them more meaningful.Also declared a count variable to make sure exactly how many qset arrays are exactly created by the create_qset() function.
—————————-
revision 1.32
date: 2014/03/04 07:10:31;  author: root;  state: Exp;  lines: +5 -1
Kernel crash taking place.The second qset array is not getting created or linked properly.
Debugging….
—————————-
revision 1.31
date: 2014/03/04 07:05:36;  author: root;  state: Exp;  lines: +30 -33
Properly placing the debugging statements to help finding out the error quickly.
—————————-
revision 1.30
date: 2014/03/03 23:19:07;  author: root;  state: Exp;  lines: +33 -2
Logical error fixed.
Issue:Kernel is crashing while running the module code.The problem lies in the check statement where the dereferencing of NULL pointer is taking placing.
—————————-
revision 1.29
date: 2014/03/03 22:58:55;  author: root;  state: Exp;  lines: +5 -2
Declared a pointer variable of type struct Scullqset to verify whether the number of scullqsets , qset arrays and quantums are actually created or not.
—————————-
revision 1.28
date: 2014/03/03 22:22:42;  author: root;  state: Exp;  lines: +11 -1
A check is made to move to the next lscullqset when the loop variable i equals to 7.Also a loop variable j is used to break the loop when the j becomes equal to noq variable.
Checking………….
—————————-
revision 1.27
date: 2014/03/03 22:17:47;  author: root;  state: Exp;  lines: +9 -6
Optimized the code by allocating the exact number of bytes required for each quantum.
—————————-
revision 1.26
date: 2014/03/03 21:58:52;  author: root;  state: Exp;  lines: +34 -10
Modified the create_qset() function to create the required number of qset arrays.
—————————-
revision 1.25
date: 2014/03/03 21:05:42;  author: root;  state: Exp;  lines: +3 -0
Declared a variable lscullqset of type struct Scullqset and it is initialized with fsculldev->scullqset.
This is done inside create_qset().
—————————-
revision 1.24
date: 2014/03/03 20:59:42;  author: root;  state: Exp;  lines: +2 -1
Logical error fixed.
Issue:kernel crash is taking place because the starting address of the lscullqset is not saved inside fsculldev->scullqset due to which while creating qset arrays it is not getting updated lscullqset address from fsculldev->scullqset.
—————————-
revision 1.23
date: 2014/03/03 20:53:32;  author: root;  state: Exp;  lines: +1 -1
While compilation a warning is coming indicating mixed declerations.
fixed the warning by placing all the declerations above the initializations.
—————————-
revision 1.22
date: 2014/03/03 20:52:17;  author: root;  state: Exp;  lines: +15 -0
Linking between lscullqsets is done.
Checking………….
—————————-
revision 1.21
date: 2014/03/03 20:44:14;  author: root;  state: Exp;  lines: +19 -11
Modifying the code so that writing in multiple qset arrays can be performed.
A flag variable is used to keep track on the number of scullqsets and with the help of this variable linking in lscullqset is also done.
—————————-
revision 1.20
date: 2014/03/03 20:38:05;  author: root;  state: Exp;  lines: +3 -0
Declared a structure variable lscullqset of type struct Scullqset.
—————————-
revision 1.19
date: 2014/03/03 19:00:50;  author: root;  state: Exp;  lines: +2 -2
Status : Writing in multiple quantums is successfully done.

Previous Issues:
1.Allocating memory for qset array incorrectly.
2.Wrongly calculating the number of qset arrays.
Such logical errors are identified and corrected successfully.
—————————-
revision 1.18
date: 2014/03/03 18:55:17;  author: root;  state: Exp;  lines: +13 -13
Corrected the argument inside kmalloc().The size of the qset array is calculated by multiplying the qset size with the size of the pointer.
Also modified a message to display how many qset arrays are created.
—————————-
revision 1.17
date: 2014/03/01 21:01:35;  author: root;  state: Exp;  lines: +2 -2
Status : Writing in multiple quantums successfully implemented.
—————————-
revision 1.16
date: 2014/03/01 20:53:57;  author: root;  state: Exp;  lines: +20 -10
Modifying the code to work for writing in more than one quantums.
—————————-
revision 1.15
date: 2014/03/01 11:19:07;  author: root;  state: Exp;  lines: +5 -0
One printk statement is added to test whether the data is actually copied into the kernel buffer or not.
Testing……….
—————————-
revision 1.14
date: 2014/03/01 11:13:18;  author: root;  state: Exp;  lines: +15 -7
The copy_from_user() function is used to copy a block of data from user space into the kernel buffer.copy_from_user() function contains 3 arguments:
1.A destination buffer,
2.A source buffer,and
3.length in bytes.
—————————-
revision 1.13
date: 2014/03/01 11:06:21;  author: root;  state: Exp;  lines: +2 -1
Done memset().
Testing the code…..
—————————-
revision 1.12
date: 2014/03/01 11:01:16;  author: root;  state: Exp;  lines: +54 -5
Implemented the create_quantums() function that will create the required number of quantums.
Kmalloc() is used to allocate memory for each quantum.
Filling the memory allocated using kmalloc() with memset() so that it does not contain any garbage.
—————————-
revision 1.11
date: 2014/03/01 10:39:39;  author: root;  state: Exp;  lines: +1 -0
memset() function is used to fill the memory allocated for the qset array to ”.
—————————-
revision 1.10
date: 2014/03/01 10:36:59;  author: root;  state: Exp;  lines: +14 -4
Using kmalloc() memory is allocated to the required number of qsets.
Checking whether it is working fine or not.
—————————-
revision 1.9
date: 2014/03/01 10:26:27;  author: root;  state: Exp;  lines: +36 -2
Implemented create_scullqset() function.Now checking the number of qsets that needs to created by using the size argument of the chardev_write().After determining the number of qsets that needs to be created create_qset() function is called.
—————————-
revision 1.8
date: 2014/03/01 10:07:44;  author: root;  state: Exp;  lines: +2 -1
memset() function is used to fill the memory allocated using kmalloc() with ” .
—————————-
revision 1.7
date: 2014/03/01 10:04:21;  author: root;  state: Exp;  lines: +10 -0
Allocating memory for 1 scullqset to check whether the create_scullqset() function is working properly or not.
—————————-
revision 1.6
date: 2014/03/01 09:56:22;  author: root;  state: Exp;  lines: +22 -2
After finding out the number of scullqsets,create_scullqset() function is called to create the specified number of scullqsets.
Checking whether the function calling is taking place or not……
—————————-
revision 1.5
date: 2014/03/01 09:47:56;  author: root;  state: Exp;  lines: +19 -0
The size argument that specifies the size of the buffer pointed to by ubuff is used to find the number of scullqsets that needs to be created.
After finding out the exact number of scullqsets that needs to be created,the number of scullqsets are printed.
Creating scullqsets…….
—————————-
revision 1.4
date: 2014/03/01 09:32:34;  author: root;  state: Exp;  lines: +1 -1
Fixed the warning by type-casting size_t to int.
—————————-
revision 1.3
date: 2014/03/01 09:28:31;  author: root;  state: Exp;  lines: +6 -1
Checking whether the ubuff pointer is actually pointing to the buffer in the application.Also checking the size field inside the 3rd argument of chardev_write().
—————————-
revision 1.2
date: 2014/03/01 09:20:00;  author: root;  state: Exp;  lines: +9 -1
Printing the address inside filep->private_data to check whether it matches with the address returned by container_of() macro.
A local variable of type Sculldev is declared which will store the address that is present inside filep->private_data.
—————————-
revision 1.1
date: 2014/02/28 21:33:05;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Character Driver, Device Drivers | Leave a comment

Character Device Driver

Presently i am implementing character device driver,there are short description of my work on driver till now.
>1st initialize the character driver by allocating memory on physical memory by registering in the kernel as a kernel module.
>And extracting major & minor number,with the help of this number, create NOD between the user sapce and kernel space
>After that performed file oprations:
@ with help of NOD open the file then write in kernel space from user space and read that same again in user space from kernel sapce.then close operation performed.
>Same file operation performed for the more memory by creating multiple SCULLQSET.(Ongoing)
>lseek which is a system call that is used to change the location of the read/write pointer of a file descriptor. The location can be set either in absolute or relative terms.(not working correctly)

Posted in Uncategorized | Leave a comment

FACTS ABOUT BITWISE OPERATORS..

Interesting Facts about Bitwise Operators in C

In C, following 6 operators are bitwise operators (work at bit-level)

& (bitwise AND) Takes two numbers as operand and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.

| (bitwise OR) Takes two numbers as operand and does OR on every bit of two numbers. The result of OR is 1 any of the two bits is 1.

^ (bitwise XOR) Takes two numbers as operand and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different.

<< (left shift) Takes two numbers, left shifts the bits of first operand, the second operand decides the number of places to shift.

>> (right shift) Takes two numbers, right shifts the bits of first operand, the second operand decides the number of places to shift.

~ (bitwise NOT) Takes one number and inverts all bits of it

Following is example C program.

/* C Program to demonstrate use of bitwise operators */
#include<stdio.h>
int main()
{
    unsigned char a = 5, b = 9; // a = 4(00000101), b = 8(00001001)
    printf("a = %d, b = %d\n", a, b);
    printf("a&b = %d\n", a&b); // The result is 00000001
    printf("a|b = %d\n", a|b);  // The result is 00001101
    printf("a^b = %d\n", a^b); // The result is 00001100
    printf("~a = %d\n", a = ~a);   // The result is 11111010
    printf("b<<1 = %d\n", b<<1);  // The result is 00010010
    printf("b>>1 = %d\n", b>>1);  // The result is 00000100
    return 0;
}

Output:

a = 5, b = 9
a&b = 1
a|b = 13
a^b = 12
~a = 250
b<<1 = 18
b>>1 = 4

Following are interesting facts about bitwise operators.

1) The left shift and right shift operators should not be used for negative numbers The result of << and >> is undefined behabiour if any of the operands is a negative number. For example results of both -1 << 1 and 1 << -1 is undefined. Also, if the number is shifted more than the size of integer, the behaviour is undefined. For example, 1 << 33 is undefined if integers are stored using 32 bits. See this for more details.

2) The bitwise XOR operator is the most useful operator from technical interview perspective. It is used in many problems. A simple example could be “Given a set of numbers where all elements occur even number of times except one number, find the odd occuring number” This problem can be efficiently solved by just doing XOR of all numbers.

// Function to return the only odd occurring element
int findOdd(int arr[], int n) {
   int res = 0, i;
   for (i = 0; i < n; i++)
     res ^= arr[i];
   return res;
}
int main(void) {
   int arr[] = {12, 12, 14, 90, 14, 14, 14};
   int n = sizeof(arr)/sizeof(arr[0]);
   printf ("The odd occurring element is %d ", findOdd(arr, n));
   return 0;
}
// Output: The odd occurring element is 90

The following are many other interesting problems which can be used using XOR operator.
Find the Missing Number, swap two numbers without using a temporary variable, A Memory Efficient Doubly Linked List, and Find the two non-repeating elements. There are many more (See this, this, this, this, this and this)

3) The bitwise operators should not be used in-place of logical operators.
The result of logical operators (&&, || and !) is either 0 or 1, but bitwise operators return an integer value. Also, the logical operators consider any non-zero operand as 1. For example consider the following program, the results of & and && are different for same operands.

int main()
{
   int x = 2, y = 5;
   (x & y)? printf("True ") : printf("False ");
   (x && y)? printf("True ") : printf("False ");
   return 0;
}
// Output: False True

4) The left-shift and right-shift operators are equivalent to multiplication and division by 2 respectively.
As mentioned in point 1, it works only if numbers are positive.

int main()
{
   int x = 19;
   printf ("x << 1 = %d\n", x << 1);
   printf ("x >> 1 = %d\n", x >> 1);
   return 0;
}
// Output: 38 9

5) The & operator can be used to quickly check if a number is odd or even
The value of expression (x & 1) would be non-zero only if x is odd, otherwise the value would be zero.

int main()
{
   int x = 19;
   (x & 1)? printf("Odd"): printf("Even");
   return 0;
}
// Output: Odd

6) The ~ operator should be used carefully
The result of ~ operator on a small number can be a big number if result is stored in a unsigned variable. And result may be negative number if result is stored in signed variable (assuming that the negative numbers are stored in 2?s complement form where leftmost bit is the sign bit)

// Note that the output of following program is compiler dependent
int main()
{
   unsigned int x = 1;
   printf("Signed Result %d \n", ~x);
   printf("Unsigned Result %ud \n", ~x);
   return 0;
}
/* Output:
Signed Result -2
Unsigned Result 4294967294d */
Posted in Uncategorized | Leave a comment

Servers

FTP AND TFTP—
These are the servers for used for file transfer.
FTP-file transfer protocol
:uses TCP
:FTP uses port 20 (for data) and 21 (for control)
:in this connections are made and then file transfer is done
:in this acknowledgement is provided
:for example – email
:for FTP we have package VSFTPD(very secure file transfer protocol demon)
TFTP-Trivial file transfer protocol
:Uses UDP
:it uses port 69
:no connection is made
:no acknowledgement is needed
:only need port no. and ip address
:for fast transfer.
:example- sms
:for TFTP we have package called XINETD.

SSH AND TELNET—–
These servers are used for remote login.
SSH-Secure shell
:it is more secured as it is in encrypted form
:it can be used only in network
:if outside the network then port forwarding is done
:it uses TCP port 22
:using this we cannot transfer the file but
:we can copy it by using—–
scp source destination —-scp 192.168.1.12/filename home/emblogic
:we use SSHD server for this
:we have a intresting thing in this i.e WALL
:try out afer installing ssh
:write ssh 127.0.0.1(an ip address of your friend)
:then write wall “hello”
:hello will be shown on your friends desktop….
TELNET
:This server has more authentication
:i.e ask for password and username
:uses TCP
:the WALL function does not work in this
:uses port no.23

Posted in Uncategorized | Tagged , | Leave a comment

STRUCTURES

STRUCTURES is basically a user define datatype. it is a collection of elements of different datatype stored in continues memory location.
SYNTAX:
struct name
{
type element;
type element;
};
struct name variable;

where struct is a keyword.
name is a name of user define data type.
struct name variable is used to define variable globally.
EXAMPLE:
struct distance
{
int feet;
float inches;
};
struct distance d;

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

character driver

We develop a character driver because this class is suitable for most simple hardware devices. Char drivers are also easier to understand than block drivers or network drivers.we present code fragments extracted from a real device driver: scull (Simple Character Utility for Loading Localities). scull is a char driverthat acts on a memory area as though it were a device.The advantage of scull is that it isn’t hardware dependent. scull just acts on somememory, allocated from the kernel. Anyone can compile and run scull, and scull is portable across the computer architectures on which Linux runs.

The Design of scull

struct scull_dev {
struct scull_qset *data; /* Pointer to first quantum set */
int quantum;
/* the current quantum size */
int qset;
/* the current array size */
unsigned long size;
/* amount of data stored here */
unsigned int access_key; /* used by sculluid and scullpriv */
struct semaphore sem;
/* mutual exclusion semaphore
*/
struct cdev cdev;
/* Char device structure
*/
};

Allocating and Freeing Device Numbers
One of the first things your driver will need to do when setting up a char device is to
obtain one or more device numbers to work with. The necessary function for this
task is register_chrdev_region, which is declared in <linux/fs.h>:
int register_chrdev_region(dev_t first, unsigned int count,
char *name);
Here, first is the beginning device number of the range you would like to allocate.
The minor number portion of first is often 0, but there is no requirement to that
effect. count is the total number of contiguous device numbers you are requesting.
Note that, if count is large, the range you request could spill over to the next major
number; but everything will still work properly as long as the number range you
request is available. Finally, name is the name of the device that should be associated
with this number range; it will appear in /proc/devices and sysfs.
The kernelwill happily allocate a major number for you on the fly, but you must request this allocation by using a different function:
int alloc_chrdev_region(dev_t *dev, unsigned int firstminor,
unsigned int count, char *name);
Regardless of how you allocate your device numbers, you should free them when
they are no longer in use. Device numbers are freed with:
void unregister_chrdev_region(dev_t first, unsigned int count);
File Operations
The scull device driver implements only the most important device methods. Its
file_operations structure is initialized as follows:
struct file_operations scull_fops = {
.owner =
THIS_MODULE,
.llseek =
scull_llseek,
.read =
scull_read,
.write =
scull_write,
.ioctl =
scull_ioctl,
.open =
scull_open,
.release = scull_release,
};

 

Posted in Uncategorized | Leave a comment

Bit Recognition Time

Time taken to give low input or low voltage plus closing of a switch and the propagation time is known as Bit Recognition Time(BRT).The switch is connected to the Flip Flop,thus input is entered into the flip flop.

If threshold voltage is crossover in BRT then its an invalid bit,if not crossover then its a valid bit.Bit is a small unit of information or data.Low input is logical 0.

Posted in Data Structures with C | Leave a comment

what is BIT

Bit is a smallest unit of information.For defineing a bit we use the Voltage,Bit recognization,flow of wave or signal.

Posted in Uncategorized | Leave a comment

SIMPLEX TYPE CODE OF BINARY SEARCH

/*condition for binary search is this that… u have to use sorted array & u should know size of array in which element is to be searched otherwise do sorting 1st*/
#include<stdio.h>
int main()
{
int search;
int hi=10,lw=0,mid=0,i,k,proceed;
int arr[10];//{3,5,6,7,9,10,13,14,16,17};
for(k=0;k<10;k++)
{
printf(“\nGIVE ME ARRAY:”);
scanf(“%d”,&arr[k]);
}
i=hi;
for(proceed=0;i>1;proceed++)//inti then cond check ….back……1st it inc.then check cond.
{
i=i/2;
//pro=3
}
printf(“\nproceed=%d”,proceed);
do
{
printf(“\nenter the element to be searched:”);
scanf(“%d”,&search);
mid=0;
hi=10;lw=0;
mid=(hi+lw)/2;
for(i=0;i<proceed;i++)//loop should operate at 0,1& 2 times.
{
//mid=(hi+lw)/2;
if(arr[mid]>search)
{
hi=mid;
mid=(lw+hi)/2;
//printf(“\nmid in if=%d”,mid);

}
else if(arr[mid]<search)
{
lw=mid;//now func will work in else for these initialised values.
mid=(lw+hi)/2;//7th pos=14//again come back at 8th pos
//printf(“\nmid in else if=%d”,mid);

}
if(arr[mid]==search)//by using else if here one loop will proceed extra again by proceed=3 value.
{
printf(“\nsearched at %d pos”,mid);
break;

}
}
}while(search != 0);

return 0;
}

Posted in Uncategorized | Leave a comment

MDC PROJECT

MDC

MDC stands for MULTIPLE DATA COMPRESSION AND ENCRYPTION using Iterative techniques, It is the back-end process for every communication via internet. Whatsapp, Facebook, Viber and all the latest messangers have adapted this technique of encryption and decryption. Sometimes this is also reffered to as cryptography. In this technique first of all data is compressed before sending and compressed data is send with a key popularly know n as cypher key. On the other side it is retrieved, this techniques can be extended for sending images and videos also.

HOW MDC WORKS- The basic idea of MDC based project is to send the required characters simultaneously without wastage of space. For instance if we have to send a series of 38 characters that forms a sentence, we can re present these 38 characters just by 4 bytes, Instead of sending 8 byte code, we can send the represented sentence in 4 bytes. This process can provide compression upto 50%. The sent message is totally encrypted.

“SHE SELLS SEA SHELLS ON THE SEA SHORE.” contains 38 characters in which only 10 characters are distinct, s o a space in memory is created that stores these 10 distinct characters only. This memory space is called as MASTER ARRAY and is used as cypher key for retrieving the code at other side. This technique is called as 4b it compression. Similarly another sentences can be compressed easily with 3bit,4bit,5bit etc compression tec hnique.

Imagine if MDC wont worked, delay in retrieving the information at other side would have been very large.

Posted in Uncategorized | Leave a comment

Parameters in C functions

Parameters in C functions

 

A Parameter is the symbolic name for “data” that goes into a function. There are two types of parameters in C: Pass by Value, Pass by Reference.

Pass by Value-Pass by Value, means that a copy of the data is made and stored by way of the name of the parameter. Any changes to the parameter have NO affect on data in the calling function.

Pass by Raference-A reference parameter “refers” to the original data in the calling function. Thus any changes made to the parameter are also made to the original variable.

There are two ways to make a pass by reference parameter:

ARRAYS-Arrays are always pass by reference in C. Any change made to the parameter containing the array will change the value of the original array.

The ampersand used in the function prototype.

function ( & parameter_name )

To make a normal parameter into a pass by reference parameter, we use the “& param” notation. The ampersand (&) is the syntax to tell C that any changes made to the parameter also modify the original variable containing the data.

Posted in Data Structures with C | Leave a comment

PARALLEL PORT

what is parallel port?
A connector for a device  that send and recieve several bits of data simultaneously.

three modes for parallel communication:-

1)compatible mode   2)nibble mode    3)byte mode
1) personal computers today are equipped with a parallel port Because the parallel port is a perfect choice for connection to other peripheral devices.
to transfer data parallely.
2) communication to parallel ports limited beacause it is unidirectional and no standard for interface.
3) In 1994,the new parallelport standard devloped by IEEE is 1284 standard.
4) this standard based on centronic standard parallel port(SPP).
5)standard parallel port is known as centronic paralel port.
6) in centronic mode ,it is unidirectional which means from host to peripherals.for example—printer.
7)1284 standard compatible with EPP and ECP.
8) 1284 standard provide improved performance while retaining backward compatibility.

9)In nibble and byte mode data can be transfered in reverse direction.
>why there is a need of communication in reverse dirction?
As the technology grows its strands with time ,we have scanner from which we scan the documents.

For bidirectional communication ,firstly,we have option at boot time and second by setting control register 5th bit set for input and zero for output.
what is handshaking?
i) reciever busy’s output tells the sender when it’s ready to recieve data.
ii)sender’s strobe output tells the reciever that a byte is available to read on data lines.
iii)reciever read data and sends acknowledgement that byte is recieved.

Posted in Uncategorized | Leave a comment

syntax of c function pointer

1.Define a Function Pointer
Since a function pointer is nothing else than a variable, it must be defined as usual. In the following example we define a function pointers named pt2Function. It points to a function, which take one float and two char and return an int.
//  define a function pointer and initialize to NULL
int (*pt2Function)(float, char, char) = NULL;

2.Calling Convention….

Normally you don’t have to think about a function’s calling convention: The compiler assumes cdecl as default if you don’t specify another convention. However if you want to know more, keep on reading … The calling convention tells the compiler things like how to pass the arguments or how to generate the name of a function. Examples for other calling conventions are stdcall, pascal, fastcall. The calling convention belongs to a functions signature: Thus functions and function pointers with different calling convention are incompatible with each other!  For the GNU GCC you use the attribute keyword: Write the
function definition followed by the keyword attribute and then state the calling convention in double parentheses.

//  define the calling convention
void DoIt(float a, char b, char c) __attribute__((cdecl));
3.Assign an Address to a Function Pointer
It’s quite easy to assign the address of a function to a function pointer. You simply take the name of a suitable and known function or member function. Although it’s optional for most compilers you should use the address operator & infront of the function’s name in order to write portable code.
// assign an address to the function pointer..

int DoIt (float a, char b, char c){ printf(“DoIt\n”); return a+b+c; }
int DoMore(float a, char b, char c){ printf(“DoMore\n”); return a-b+c; }
pt2Function = DoIt; // short form
pt2Function = &DoMore; // correct assignment using address operator

Posted in Uncategorized | Leave a comment