/dev/dog

After reading a post on edd's blog about a cat and that it wasn't a device I though ?Why not?
14:12 <> the cat is not a device driver ffs
14:13 < #4> cat /dev/cat ;)
So her you go. Now you can have a device called dog in Linux and feed it with
echo "Food" > /dev/dog
cat /dev/dog

If you want more features just tell me :)

 1: /*
2: * The Dog kernel module
3: * Creates a /dev/dog
4: *
5: * Hoffmann Geerd-Dietger
6: * Thx to:
7: * Valerie Henson
8: *
9: */

10: #define BUFFER 80
11:
12: #include <linux/fs.h>
13: #include <linux/init.h>
14: #include <linux/miscdevice.h>
15: #include <linux/module.h>
16: #include <asm/uaccess.h>
17:
18: MODULE_LICENSE("DUAL GPL/BSD");
19: MODULE_AUTHOR("Hoffmann Geerd-Dietger ");
20: MODULE_DESCRIPTION("A little dog living in /dev");
21: MODULE_VERSION("0.1");
22:
23:
24: static char hello_str[BUFFER]="Hello Master, just echo to me and then cat\n";
25:
26: static ssize_t dog_write(struct file *filp, const char __user *buff,
27: size_t count, loff_t *offp)
28: {
29: /* We don't care just chop it off */
30: if (count >= BUFFER)
31: count = BUFFER;
32:
33: if (copy_from_user(hello_str,buff, count))
34: return -EINVAL;
35:
36: return count;
37: }
38:
39:
40: static ssize_t dog_read(struct file * file, char * buf,
41: size_t count, loff_t *ppos)
42: {
43:
44: if (count < BUFFER)
45: return -EINVAL;
46:
47: if (*ppos != 0)
48: return 0;
49:
50: if (copy_to_user(buf, hello_str, BUFFER))
51: return -EINVAL;
52:
53: *ppos = BUFFER;
54:
55: return BUFFER;
56: }
57:
58:
59: static const struct file_operations dog_fops = {
60: .owner = THIS_MODULE,
61: .read = dog_read,
62: .write = dog_write,
63: };
64:
65: static struct miscdevice dog_dev = {MISC_DYNAMIC_MINOR,"dog",&dog_fops };
66:
67: static int __init
68: dog_init(void)
69: {
70: int ret;
71:
72: ret = misc_register(&dog_dev);
73: if (ret)
74: printk(KERN_ERR
75: "Unable to register \"Dog\" misc device\n");
76:
77: printk("dog: Woof Woof\n");
78:
79: return ret;
80: }
81:
82: module_init(dog_init);
83:
84: static void __exit
85: dog_exit(void)
86: {
87: misc_deregister(&dog_dev);
88: printk("dog: Grrrrrrrrrrrrrrrrr");
89: }
90:
91: module_exit(dog_exit);


Makefile:

obj-m := dog_dev.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

default:
$(MAKE) -C $(KDIR) M=$(PWD) modules


Of course you have to insmod the module

Cern Week 22

This week I spent most of my tim elerning how kernel modules work. To do this I write a new device node called /edv/dog that will save 80 chars, that you can pipe into and echo from. This was just to lern how the kernel works. I further optimized the ldap to file translation program. More in other posts. At Cern there is a program called phone that I started reviewing because Dan and me are thinking of rewriting it in Perl to make it platform independant on not rely on old REXX scripts. Further everyone has gone on holiday so there is not much to do

Google Ads beeing just a little bit racist


How can google post this ???

Other Ads might include :
My Son is Black?
My Son has Sex with a condom?
My Son ...

Google should start reviewing their ads. Really we are not in the Dark Ages anymore. Maybe the mothers struggle was about the boy friend not beeing able to cook good food. But I sort of doupt that.

A little bit of advice

While reviewing some scripts, I saw this quite a lot
chmod a+x *.pl
So everyone becomes execute rights. After some research I found out that this is not really needed only the user needed execute rights. So instead why didn't the author write
chmod u+x *.pl
I don't know but if everyone can execute your script you might have a security risk at hand. So never give everyone execute on your stuff.

Cern Week 21

I am still spending most of my time on quattor. Even if this was not really in my job spec. But now everything seems to work fine and the installs are working without errors. I spent most of the week writing documentation and updating man pages, for all the little changes I made. Further I wrote a perl script that queries the ldap server every x minutes. If the server fails to reply 2 times in a row the program will install the massive /etc/passwd file. This is created every time the server does reply.
On Thursday I gave my talk about OpenBSD and OpenCon, which everyone really liked. Lots of people came into my office and asked more questions. (Especially about OpenNtp). Further there was the group Christmas Lunch to attend, which was a good laugh, as there was as much vine as you could drink.

Cern Week 20

I spent this week writing a presentation about my visit to OpenCON. As we use Linux at Cern quite a few people don't really know what OpenBSD is, so I suggested that I could hold a little talk. For this I did loads of reading about latex and beamer. (Now there is a beamer rpm for cern)
Slides will be available [here]
Further I spent my time on improving userlib and my quattor modules as the first few bugfixes had to be written. Quattor went into code freeze on Friday so I had to hurry to fix the known errors, so they could be rolled out in the next stable version. There is a code freeze every six months. There were quite a few meeting to attend as the section is currently being reorganised. This was mostly boring stuff that didn't really relate to me as I am staying with my boss.

Duplicate a line in emacs

When coding you often have to duplicate a line. This is a little script for your .emacs file to do this:

;; Duplicate it
(defun duplicate()
"Duplicate it."
(interactive)
(let (
(beg (line-beginning-position))
(end (line-end-position)))
(copy-region-as-kill beg end)
(beginning-of-line)
(forward-line 1)
(yank)
(newline)
(forward-line -1)))