Skip to content

Commit a493c36

Browse files
committed
added assignment module for Lab3
1 parent a42ffab commit a493c36

File tree

10 files changed

+96
-1
lines changed

10 files changed

+96
-1
lines changed
File renamed without changes.

Lab2/README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
# Lab 2
1+
# Lab 2
2+
3+
The file_operations structure is defined in linux/fs.h, and holds pointers to functions defined by the driver that perform various operations on the device. Each field of the structure corresponds to the address of some function defined by the driver to handle a requested operation.
4+
5+
For example, every character driver needs to define a function that reads from the device. The file_operations structure holds the address of the module's function that performs that operation.
6+
7+
8+
### Module - chardev.c
9+
The next code sample creates a char driver named chardev. You can cat its device file (or open the file with a program) and the driver will put the number of times the device file has been read from into the file. We don't support writing to the file (like echo "hi" > /dev/hello), but catch these attempts and tell the user that the operation isn't supported.
10+

Lab2/assignment.c

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Assignment module
3+
*
4+
*/
5+
6+
7+
#include <linux/module.h> /* Needed by all modules */
8+
#include <linux/kernel.h> /* Needed for KERN_ALERT */
9+
#include <linux/init.h> /* Needed for the macros */
10+
11+
/* Include other required Header Files*/
12+
13+
14+
/* Prototypes for the functions you have to implement*/
15+
16+
int init_module(void);
17+
void cleanup_module(void);
18+
static int device_open(struct inode *, struct file *);
19+
static int device_release(struct inode *, struct file *);
20+
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
21+
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
22+
23+
static int __init assignment_init(void)
24+
{
25+
/* Your Code here */
26+
return 0;
27+
}
28+
29+
static void __exit assignment_exit(void)
30+
{
31+
/* Your Code here */
32+
}
33+
34+
module_init(assignment_init);
35+
module_exit(assignment_exit);
File renamed without changes.
File renamed without changes.

Lab3/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@ procfs3.c - create a "file" in /proc
1717

1818
This program uses the seq_file library to manage the /proc file to reimplement the functionality of Module 2.
1919

20+
### Assignment Module
21+
22+
- Take a string as input from the user by implementing write for the procfs file.
23+
- Have an integer variable 'key' defined as 13
24+
- Perform a single key xor on the string with the given key and print the resulting hex encoded string by implementing read for the procfs file.
25+
- Add to Makefile and test.
26+
27+
**Note**: You can either use the normal or seq_file implementation
28+
2029
#### References
2130
<https://www.kernel.org/doc/Documentation/filesystems/seq_file.txt>
31+

Lab3/assignment.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Perform a single key xor on the string with the given key and print
3+
* the resulting hex encoded string by implementing read
4+
* for the procfs file.
5+
*
6+
*/
7+
#include <linux/module.h> /* Needed by all modules */
8+
#include <linux/kernel.h> /* Needed for KERN_ALERT */
9+
#include <linux/init.h> /* Needed for the macros */
10+
11+
/* Include other required Header Files*/
12+
13+
static struct file_operations fops_struct = {
14+
15+
/* Your Code here */
16+
17+
};
18+
19+
static ssize_t procfile_write(struct file *file,const char *buffer, size_t count, loff_t *offset)
20+
{
21+
/* Your Code here */
22+
}
23+
24+
static ssize_t procfile_read(struct file *file, char *buffer, size_t buffer_length, loff_t *offset)
25+
{
26+
/* Your Code here */
27+
}
28+
29+
static int __init assignment_init(void)
30+
{
31+
/* Your Code here */
32+
return 0;
33+
}
34+
35+
static void __exit assignment_exit(void)
36+
{
37+
/* Your Code here */
38+
}
39+
40+
module_init(assignment_init);
41+
module_exit(assignment_exit);
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)