Professional Documents
Culture Documents
source code 1
Add the new system call (sys_listit() ) into the system call table
(syscall_32.tbl file)
cd arch/x86/syscalls
gedit syscall_32.tbl
add the following line in the end of the file :- 355
i386 listit
sys_listit
Add the new system call(sys_listit() ) in the system call header file.
cd
include/linux/
gedit syscalls.h
add the line : asmlinkage long sys_listit(char *path,char type);
update and upgrade sudo apt-get update && sudo apt-get upgrad e
cd /usr/src/linux-3.16/
To configure your kernel use the following command: sudo make defconfig
to compile the kernel :
make
Making Patch
cd /usr/src/linux-3.16/
make mrproper
make clean
cd /usr/src
diff -Nur oldpath newpath > patchname
diff -Nur /home/faiz/Downloads/linux-3.16 /usr/src/linux-3.16 >
patch2
Isuues
fix the syntax errors of syscall.c by writing appropriate function in
infinite loop.,
each directory is taking 5MB of size, if you have more folders in
your testing directory, critical for the system. Process may get killed.
userlevel process returns -1 , fix : select the right kernel from the
fix by typing f, or delete the /tmp folder and then create a new /tmp
Source_code#1
sys_listit()
#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <asm/uaccess.h>
#include <linux/syscalls.h>
#include <linux/linkage.h>
#include <linux/dirent.h>
#include <linux/string.h>
#include <linux/stat.h>
#include <linux/types.h>
#include <linux/time.h>
#include <linux/slab.h>
struct linux_dirent {
long
off_t
unsigned shortd_reclen;
char
//Filename (null-terminated)
d_name[];
/*
char
pad;
/*type
d- directory
f- regular file
s- symbolic link
a- all types.
*/
end=jiffies;
return 0;
}
mm_segment_t fs;
int fd;
char locBuf[100];
char buf[BUF_SIZE];
struct linux_dirent *d;
int bpos;
char d_type;
int nread;
fs=get_fs();
sprintf(locBuf, path);
set_fs(get_ds());
for(bpos=0;bpos<nread;)
{
d=(struct linux_dirent *) (buf+bpos);
d_type = *(buf + bpos + d->d_reclen - 1);
type="regular";
printk("%s\n",full);
printk("%8ld %-10s %10ld ", d->d_ino,type,statbuf.st_size);
printk("%o ",statbuf.st_mode & (S_IRWXU | S_IRWXG |
S_IRWXO));
printk("%5u ",statbuf.st_uid);
struct tm broken;
time_to_tm(statbuf.st_atime, 0, &broken);
printk(" %2d:%2d:%2d ", broken.tm_hour,
broken.tm_min,broken.tm_sec);
struct tm broken1;
time_to_tm(statbuf.st_mtime, 0, &broken1);
printk(" %2d:%2d:%2d \n", broken1.tm_hour,
broken1.tm_min,broken1.tm_sec);
}
else if(d_type==DT_DIR && t=='d'){
type="directory";
printk("%s\n",full);
printk("%8ld %-10s %10ld ", d->d_ino,type,statbuf.st_size);
printk("%o ",statbuf.st_mode & (S_IRWXU | S_IRWXG |
S_IRWXO));
printk("%5u ",statbuf.st_uid);
struct tm broken;
time_to_tm(statbuf.st_atime, 0, &broken);
printk(" %2d:%2d:%2d ", broken.tm_hour,
broken.tm_min,broken.tm_sec);
struct tm broken1;
time_to_tm(statbuf.st_mtime, 0, &broken1);
printk(" %2d:%2d:%2d \n", broken1.tm_hour,
broken1.tm_min,broken1.tm_sec);
}
else if(d_type==DT_LNK && t=='s'){
type="link";
printk("%s\n",full);
printk("%8ld %-10s %10ld ", d->d_ino,type,statbuf.st_size);
printk("%o ",statbuf.st_mode & (S_IRWXU | S_IRWXG |
S_IRWXO));
printk("%5u ",statbuf.st_uid);
struct tm broken;
time_to_tm(statbuf.st_atime, 0, &broken);
printk(" %2d:%2d:%2d ", broken.tm_hour,
broken.tm_min,broken.tm_sec);
struct tm broken1;
time_to_tm(statbuf.st_mtime, 0, &broken1);
printk(" %2d:%2d:%2d \n", broken1.tm_hour,
broken1.tm_min,broken1.tm_sec);
}
else if(t=='a'){
if(d_type==DT_REG)
type="regular";
else if(d_type==DT_DIR)
type="directory";
else if(d_type==DT_LNK)
type="link";
else
type="other";
printk("%s\n",full);
printk("%8ld %-10s %10ld ", d->d_ino,type,statbuf.st_size);
printk("%o ",statbuf.st_mode & (S_IRWXU | S_IRWXG |
S_IRWXO));
printk("%5u ",statbuf.st_uid);
struct tm broken;
time_to_tm(statbuf.st_atime, 0, &broken);
printk(" %2d:%2d:%2d ", broken.tm_hour,
broken.tm_min,broken.tm_sec);
struct tm broken1;
time_to_tm(statbuf.st_mtime, 0, &broken1);
printk(" %2d:%2d:%2d \n", broken1.tm_hour,
broken1.tm_min,broken1.tm_sec);
}
Source_code#2
test.c
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
/*type
d- directory
f- regular file
s- symbolic link
a- all types.
*/
int main()
{
int x=4;
char *loc= "/home/faiz/Downloads";
char type='f';
printf("\n Enter :\n");
printf("\n type :\t");
scanf("%c",&type);
printf("%ld",syscall(355,loc,type));
return 0;
}