Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
abcd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
valentin.acevedoa
abcd
Commits
fd13f03a
Commit
fd13f03a
authored
2 years ago
by
valentin.acevedoa
Browse files
Options
Downloads
Patches
Plain Diff
master commit
parent
9e55a316
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
abcd.c
+96
-0
96 additions, 0 deletions
abcd.c
abcd.mod.c
+29
-0
29 additions, 0 deletions
abcd.mod.c
with
125 additions
and
0 deletions
abcd.c
0 → 100644
+
96
−
0
View file @
fd13f03a
#include
<linux/module.h>
#include
<linux/init.h>
#include
<linux/fs.h>
#include
<linux/slab.h>
#include
<linux/cdev.h>
#include
<linux/types.h>
MODULE_LICENSE
(
"Dual BSD/GPL"
);
MODULE_AUTHOR
(
"Valentin Acevedo <valentin.acevedo-arroyo@etu.hesge.ch>"
);
MODULE_DESCRIPTION
(
"Alphabet buffer"
);
MODULE_VERSION
(
"1.0"
);
// Buffer
static
int
buff_size
=
26
;
static
char
*
buff
;
static
dev_t
major
;
struct
mydevice
{
char
*
string_data
;
int
int_data
;
struct
cdev
mycdev
;
};
static
struct
mydevice
peripherique
;
static
ssize_t
custom_write
(
struct
file
*
file
,
const
char
*
buff
,
size_t
len
,
loff_t
*
ppos
)
{
int
real_buff_size
=
0
,
write_buff_size
=
0
;
if
(
len
<=
buff_size
-
*
ppos
)
{
real_buff_size
=
len
;
}
else
{
real_buff_size
=
buff_size
-
*
ppos
;
}
if
(
real_buff_size
)
{
write_buff_size
=
copy_from_user
((
void
*
)
buff
+
*
ppos
,
buff
,
real_buff_size
);
}
if
(
buff_size
<*
ppos
+
real_buff_size
)
{
*
ppos
=
0
;
}
else
{
*
ppos
+=
real_buff_size
;
}
return
real_buff_size
-
write_buff_size
;
}
static
ssize_t
custom_read
(
struct
file
*
file
,
char
*
buff
,
size_t
len
,
loff_t
*
ppos
)
{
int
real_buff_size
=
0
,
read_buff_size
=
0
;
if
(
buff_size
-
*
ppos
>
len
)
{
real_buff_size
=
len
;
}
else
{
real_buff_size
=
buff_size
-
*
ppos
;
}
if
(
real_buff_size
)
{
read_buff_size
=
copy_to_user
(
buff
,
buff
+
*
ppos
,
real_buff_size
);
}
if
(
buff_size
<
*
ppos
+
real_buff_size
)
{
*
ppos
=
0
;
}
else
{
*
ppos
+=
real_buff_size
;
}
return
real_buff_size
-
read_buff_size
;
}
//Map used functions to custom created functions
static
struct
file_operations
custom_operations
=
{
read
:
custom_read
,
write
:
custom_write
};
static
int
__init
custom_init
(
void
)
{
int
val
;
buff
=
kmalloc
(
buff_size
*
sizeof
(
char
),
GFP_KERNEL
);
memcpy
(
buff
,
"abcdefghijklmnopqrstuvwxyz"
,
buff_size
*
sizeof
(
char
));
val
=
alloc_chrdev_region
(
&
major
,
0
,
1
,
"abcd"
);
if
(
val
<
0
)
{
printk
(
KERN_WARNING
"Module loading failure
\n
"
);
return
val
;
}
cdev_init
(
&
(
peripherique
.
mycdev
),
&
custom_operations
);
cdev_add
(
&
(
peripherique
.
mycdev
),
major
,
1
);
printk
(
KERN_DEBUG
"Debug"
);
return
0
;
}
static
void
__exit
custom_exit
(
void
)
{
//Freeing buffer
unregister_chrdev_region
(
major
,
1
);
kfree
(
buff
),
buff
=
NULL
;
cdev_del
(
&
(
peripherique
.
mycdev
));
}
module_init
(
custom_init
);
module_exit
(
custom_exit
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
abcd.mod.c
0 → 100644
+
29
−
0
View file @
fd13f03a
#include
<linux/module.h>
#define INCLUDE_VERMAGIC
#include
<linux/build-salt.h>
#include
<linux/vermagic.h>
#include
<linux/compiler.h>
BUILD_SALT
;
MODULE_INFO
(
vermagic
,
VERMAGIC_STRING
);
MODULE_INFO
(
name
,
KBUILD_MODNAME
);
__visible
struct
module
__this_module
__section
(
".gnu.linkonce.this_module"
)
=
{
.
name
=
KBUILD_MODNAME
,
.
init
=
init_module
,
#ifdef CONFIG_MODULE_UNLOAD
.
exit
=
cleanup_module
,
#endif
.
arch
=
MODULE_ARCH_INIT
,
};
#ifdef CONFIG_RETPOLINE
MODULE_INFO
(
retpoline
,
"Y"
);
#endif
MODULE_INFO
(
depends
,
""
);
MODULE_INFO
(
srcversion
,
"907842194018E903497EAD0"
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment