Skip to content

Commit

Permalink
2014.12.27
Browse files Browse the repository at this point in the history
  • Loading branch information
xianbintang committed Dec 27, 2014
1 parent 8c5758e commit ada52a1
Show file tree
Hide file tree
Showing 55 changed files with 2,861 additions and 564 deletions.
Binary file added doc/2012LAB/2012LAB/2012LAB(1).rar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added doc/2012LAB/2012LAB/2012LAB/2012lab.tar.gz
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file added doc/2012lab/Unix socket/a.out
Binary file not shown.
Binary file modified doc/2012lab/Unix socket/client
Binary file not shown.
Binary file modified doc/2012lab/Unix socket/server
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/2012lab/driver/.globalvar.ko.cmd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cmd_/home/zhangxiao/embededSystem/example/driver/globalvar.ko := ld -r -m elf_i386 -T /usr/src/linux-2.6.32.60/scripts/module-common.lds --build-id -o /home/zhangxiao/embededSystem/example/driver/globalvar.ko /home/zhangxiao/embededSystem/example/driver/globalvar.o /home/zhangxiao/embededSystem/example/driver/globalvar.mod.o
cmd_/home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko := ld -r -m elf_x86_64 -T /usr/src/linux-headers-3.11.0-26-generic/scripts/module-common.lds --build-id -o /home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko /home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.o /home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.mod.o
648 changes: 383 additions & 265 deletions doc/2012lab/driver/.globalvar.mod.o.cmd

Large diffs are not rendered by default.

688 changes: 417 additions & 271 deletions doc/2012lab/driver/.globalvar.o.cmd

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/2012lab/driver/.tmp_versions/globalvar.mod
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/home/zhangxiao/embededSystem/example/driver/globalvar.ko
/home/zhangxiao/embededSystem/example/driver/globalvar.o
/home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko
/home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.o
Binary file modified doc/2012lab/driver/globalvar.ko
Binary file not shown.
38 changes: 18 additions & 20 deletions doc/2012lab/driver/globalvar.mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,31 @@ MODULE_INFO(vermagic, VERMAGIC_STRING);

struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
.arch = MODULE_ARCH_INIT,
};

static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {
{ 0xfceff7dc, "module_layout" },
{ 0xf67ec283, "cdev_del" },
{ 0x93119e2c, "kmalloc_caches" },
{ 0xd7f78419, "cdev_init" },
{ 0x6980fe91, "param_get_int" },
{ 0x105e2727, "__tracepoint_kmalloc" },
{ 0x7485e15e, "unregister_chrdev_region" },
{ 0xff964b25, "param_set_int" },
{ 0xb72397d5, "printk" },
{ 0x2f287f0d, "copy_to_user" },
{ 0xb4390f9a, "mcount" },
{ 0xe9b1a2fa, "cdev_add" },
{ 0x57eb50b3, "kmem_cache_alloc" },
{ 0x37a0cba, "kfree" },
{ 0xd6c963c, "copy_from_user" },
{ 0x29537c9e, "alloc_chrdev_region" },
{ 0x4c46c04, __VMLINUX_SYMBOL_STR(module_layout) },
{ 0x15692c87, __VMLINUX_SYMBOL_STR(param_ops_int) },
{ 0xd1c71a37, __VMLINUX_SYMBOL_STR(cdev_add) },
{ 0xe62505cc, __VMLINUX_SYMBOL_STR(cdev_init) },
{ 0x7149fc2a, __VMLINUX_SYMBOL_STR(kmem_cache_alloc_trace) },
{ 0xbb323702, __VMLINUX_SYMBOL_STR(kmalloc_caches) },
{ 0x29537c9e, __VMLINUX_SYMBOL_STR(alloc_chrdev_region) },
{ 0x7485e15e, __VMLINUX_SYMBOL_STR(unregister_chrdev_region) },
{ 0x37a0cba, __VMLINUX_SYMBOL_STR(kfree) },
{ 0x2691f9d9, __VMLINUX_SYMBOL_STR(cdev_del) },
{ 0x4f8b5ddb, __VMLINUX_SYMBOL_STR(_copy_to_user) },
{ 0x4f6b400b, __VMLINUX_SYMBOL_STR(_copy_from_user) },
{ 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) },
{ 0xbdfb6dbb, __VMLINUX_SYMBOL_STR(__fentry__) },
};

static const char __module_depends[]
Expand Down
Binary file modified doc/2012lab/driver/globalvar.mod.o
Binary file not shown.
Binary file modified doc/2012lab/driver/globalvar.o
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/2012lab/driver/modules.order
Original file line number Diff line number Diff line change
@@ -1 +1 @@
kernel//home/zhangxiao/embededSystem/example/driver/globalvar.ko
kernel//home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko
1 change: 1 addition & 0 deletions doc/2012lab/poll/.char_dev.ko.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmd_/home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko := ld -r -m elf_x86_64 -T /usr/src/linux-headers-3.11.0-26-generic/scripts/module-common.lds --build-id -o /home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko /home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.o /home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.mod.o
549 changes: 549 additions & 0 deletions doc/2012lab/poll/.char_dev.mod.o.cmd

Large diffs are not rendered by default.

665 changes: 665 additions & 0 deletions doc/2012lab/poll/.char_dev.o.cmd

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions doc/2012lab/poll/.tmp_versions/char_dev.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko
/home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.o
2 changes: 1 addition & 1 deletion doc/2012lab/poll/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-m += char_dev.o
obj-m += char_dev_new.o
#obj-m += char_dev_new.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
Expand Down
Empty file added doc/2012lab/poll/Module.symvers
Empty file.
7 changes: 4 additions & 3 deletions doc/2012lab/poll/char_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <asm/uaccess.h>
#include <linux/init.h>
#include <linux/poll.h>

#include <linux/slab.h>


#define READ_BUF_SIZE 1024
Expand Down Expand Up @@ -107,7 +107,8 @@ int my_poll(struct file *filp, poll_table *wait)
mask |= 1<<DRIVER_EVENT_BIT;
return mask;
}
int my_ioctl (struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
//int my_ioctl (struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
int my_ioctl (struct file *filp,unsigned int cmd,unsigned long arg)
{
switch(cmd){
case 1 :{
Expand Down Expand Up @@ -136,7 +137,7 @@ open : my_open, /* openº¯Ê */
release: my_release, /* writeº¯Ê */
read: my_read, /* readº¯Ê */
write: my_write, /* writeº¯Ê */
ioctl: my_ioctl, /* ioctlº¯Ê */
unlocked_ioctl: my_ioctl, /* ioctlº¯Ê */
poll: my_poll, /* ioctlº¯Ê */

};
Expand Down
Binary file added doc/2012lab/poll/char_dev.ko
Binary file not shown.
42 changes: 42 additions & 0 deletions doc/2012lab/poll/char_dev.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

MODULE_INFO(vermagic, VERMAGIC_STRING);

struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

static const struct modversion_info ____versions[]
__used
__attribute__((section("__versions"))) = {
{ 0x4c46c04, __VMLINUX_SYMBOL_STR(module_layout) },
{ 0x15692c87, __VMLINUX_SYMBOL_STR(param_ops_int) },
{ 0x35b6b772, __VMLINUX_SYMBOL_STR(param_ops_charp) },
{ 0x6bc3fbc0, __VMLINUX_SYMBOL_STR(__unregister_chrdev) },
{ 0x9f3ac793, __VMLINUX_SYMBOL_STR(__register_chrdev) },
{ 0xf432dd3d, __VMLINUX_SYMBOL_STR(__init_waitqueue_head) },
{ 0x7149fc2a, __VMLINUX_SYMBOL_STR(kmem_cache_alloc_trace) },
{ 0xbb323702, __VMLINUX_SYMBOL_STR(kmalloc_caches) },
{ 0x37a0cba, __VMLINUX_SYMBOL_STR(kfree) },
{ 0x4f8b5ddb, __VMLINUX_SYMBOL_STR(_copy_to_user) },
{ 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) },
{ 0x4f6b400b, __VMLINUX_SYMBOL_STR(_copy_from_user) },
{ 0xd2b09ce5, __VMLINUX_SYMBOL_STR(__kmalloc) },
{ 0xbdfb6dbb, __VMLINUX_SYMBOL_STR(__fentry__) },
};

static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";


MODULE_INFO(srcversion, "5222B96E967A182D7A4AF6B");
Binary file added doc/2012lab/poll/char_dev.mod.o
Binary file not shown.
Binary file added doc/2012lab/poll/char_dev.o
Binary file not shown.
1 change: 1 addition & 0 deletions doc/2012lab/poll/modules.order
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kernel//home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko
Binary file added src/fifo/fifo_read
Binary file not shown.
41 changes: 41 additions & 0 deletions src/fifo/fifo_read.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

#define FIFO_FILE "/tmp/myfifo"
int main(void)
{
char buf[100];
int n = 0;
int fd;

if ((mkfifo(FIFO_FILE, S_IRWXU < 0) && (errno != EEXIST))) {
perror("mkfifo error");
exit(-1);
}

if ((fd = open(FIFO_FILE, O_RDONLY| O_NONBLOCK)) < 0) {
perror("open error");
exit(-1);
}

while (1) {
if ((n = read(fd, buf, 100)) < 0) {
/*已经被只写打开:返回 EAGAIN 错误*/
if (errno == EAGAIN) {
printf("No data yet\n");
}
} else if (n == 0)
printf("No opened by write_only\n");
else if (n > 0)
write(STDOUT_FILENO, buf, n);
sleep(1);
}

unlink(FIFO_FILE);
return 0;
}
Binary file added src/fifo/fifo_write
Binary file not shown.
29 changes: 29 additions & 0 deletions src/fifo/fifo_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

#define FIFO_FILE "/tmp/myfifo"
int main(void)
{
int fd = 0;
int n;
char buf[100];

if ((fd = open(FIFO_FILE, O_WRONLY | O_NONBLOCK)) < 0) {
perror("open error");
exit(-1);
}
while (1) {
fgets(buf, 100, stdin);
n = strlen(buf);
if ((n = write(fd, buf, n)) < 0) {
if (errno == EAGAIN) {
printf("The FIFO has not been read yet, Please try later\n");
}
}
}
return 0;
}
Binary file added src/fifo/pipetest_second
Binary file not shown.
51 changes: 51 additions & 0 deletions src/fifo/pipetest_second.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

int main(int argc, char **argv)
{
int pipe_fd[2];
pid_t pid;
char r_buf[4];
char* w_buf;
int writenum;
int cmd;

memset(r_buf,0,sizeof(r_buf));
if(pipe(pipe_fd)<0)
{
printf("pipe create error\n");
return -1;
}

if((pid=fork())==0)
{
/*子进程关闭写端口,这样的话pipe就不可用了*/
// close(pipe_fd[0]);
close(pipe_fd[1]);
sleep(2);
exit(0);
}
else if(pid>0)
{
sleep(1); //等待子进程完成关闭读端的操作
/*父进程关闭读端口*/
close(pipe_fd[0]);
w_buf="111";
printf("FILE: %s, LINE: %d\r\n", __FILE__, __LINE__);
/*父进程向子进程写入数据*/
writenum=write(pipe_fd[1],w_buf,4)==-1;

if((writenum=write(pipe_fd[1],w_buf,4))==-1)
printf("write to pipe error\n");
else
printf("the bytes write to pipe is %d \n", writenum);

printf("FILE: %s, LINE: %d\r\n", __FILE__, __LINE__);
close(pipe_fd[1]);
}
return 0;
}
Binary file added src/fifo/pipetest_simple
Binary file not shown.
48 changes: 48 additions & 0 deletions src/fifo/pipetest_simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>

int main(int argc, char ** argv)
{
int pipe_fd[2];
pid_t pid;
char r_buf[100];
char w_buf[4];
int r_num;
int cmd;

memset(r_buf, 0, sizeof(r_buf));
memset(w_buf, 0, sizeof(w_buf));

if (pipe(pipe_fd) < 0) {
printf("FILE: %s, LINE: %d.pipe create error\n", __FILE__, __LINE__);
return -1;
}

/*子进程关闭写端口,父进程关闭读端口,建立一个从父进程到到子进程的通道*/
if ((pid = fork()) == 0) {
printf("##################\n");
close(pipe_fd[1]); /*子进程关闭写端口*/
/*等待父进程向端口写入数据,然后子进程才能读数据*/
sleep(3);
/*父进程写入数据后进行读写数据*/
r_num = read(pipe_fd[0], r_buf, 100);
printf("child read num is %d, the data read from the pipe is %d\n", r_num, atoi(r_buf));
close(pipe_fd[0]);
} else if (pid > 0) {
close(pipe_fd[0]); /*父进程关闭读端口*/
strcpy(w_buf, "111");
/*向pipe里写入数据*/
if (write(pipe_fd[1], w_buf, 4) != -1) {
printf("parent write over\n");
}
/*父进程关闭写端口,也就是关闭了pipe了*/
close(pipe_fd[1]);
printf("parent close fd[1]-write over\n");
sleep(3);
}
return 0;
}
Binary file added src/mmap/mmap_read
Binary file not shown.
34 changes: 34 additions & 0 deletions src/mmap/mmap_read.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>

#define FILENAME "/tmp/test"
#define BUFLEN 256

typedef struct {
char name[BUFLEN];
int id;
}people;

int main(int argc, char ** argv)
{
int i;
unsigned int *pmap = 0;
int fd;
fd = open(FILENAME, O_CREAT | O_RDWR, 00777);
assert(fd != -1);
pmap = (unsigned int *)mmap(0, sizeof(people), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
unsigned int *addr;
addr = pmap;
addr = pmap + sizeof(char)*BUFLEN;
printf("id = %id name = %s\n\r", *((int *)addr), (char *)pmap);
munmap((void *)pmap, sizeof(char) * BUFLEN);
close(fd);
printf("umap os\n\r");
return 0;
}
Binary file added src/mmap/mmap_write
Binary file not shown.
39 changes: 39 additions & 0 deletions src/mmap/mmap_write.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>

#define FILENAME "/tmp/test"
#define BUFLEN 256

typedef struct {
char name[BUFLEN];
int id;
}people;

int main(int argc, char ** argv)
{
int i;
unsigned int *pmap = 0;
int fd;
fd = open(FILENAME, O_CREAT | O_RDWR | O_TRUNC, 00777);
assert(fd != -1);
pmap = (unsigned int *)mmap(0, sizeof(people), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
write(fd, "", sizeof(people));
unsigned int *addr;
addr = pmap;
char tempname[30] = "xianb";
int tempid = 253;
addr = pmap + sizeof(char) * BUFLEN;
memcpy((void *)pmap, tempname, strlen(tempname));
memcpy((void *)addr, &tempid, sizeof(int));

munmap((void *) pmap, sizeof(char) * BUFLEN);
close(fd);
printf("umap ok\r\n");
return 0;
}
Binary file added src/systemv/testread
Binary file not shown.
Loading

0 comments on commit ada52a1

Please sign in to comment.