إعـــــــلان

تقليص
لا يوجد إعلان حتى الآن.

pipe implementation

تقليص
X
 
  • تصفية - فلترة
  • الوقت
  • عرض
إلغاء تحديد الكل
مشاركات جديدة

  • pipe implementation

    pipe implementation : link # http://programming-fr34ks.net/forum/...?showtopic=435
    اهو فضيان بقي :angry_red:
    module بسيط تقدر تستخدمه زي pipe لاي application بتاعتك
    ال user يقدر يبعت 265kb array وانت تستقبلها وتقدر تقرأها اول ماتتبعت
    طبعا استخدم completion method الي موجودده في ال كيرنيل
    كان ممكن semaphore بس كنت عايز اجرب ديت

    كود PHP:
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/errno.h>
    #include <linux/moduleparam.h>
    #include <linux/fs.h>
    #include <linux/kdev_t.h>
    #include <linux/stat.h>
    #include <linux/types.h>
    #include <linux/cdev.h>
    #include <linux/sched.h>
    #include <asm/uaccess.h>

    #include <linux/completion.h>

    static int major;
    static 
    int minor;
    static 
    dev_t device_node;

    static 
    char buffer[265];

    module_param(major int S_IWUSR S_IRUSR);
    module_param(minor int S_IWUSR S_IRUSR);

    struct cdev device;
    struct completion complete_task;

    static 
    int pipe_open(struct inode *node struct file *filp)
    {
            
    /* No defice specification Will be Done */

            
    return 0;
    }
    static 
    int pipe_read(struct file *filp char __user *buf size_t size loff_t *pos)
    {

            
    wait_for_completion(&complete_task);

            if(
    copy_to_user(buf buffer strlen(buffer)) > 0)
                    return -
    1;
            else
                    return 
    strlen(buffer);
    }
    static 
    int pipe_write(struct file *filp ,
                    const 
    char __user *buf ,
                    
    size_t size ,
                    
    loff_t *pos)
    {
            
    int count size;

            if(
    count 264)
                    
    count 264;

            if(
    copy_from_user(buffer buf count) > 0)
                    return -
    1;
            
    complete(&complete_task);
            return 
    count;
    }

    static 
    int pipe_release(struct inode *node struct file *filp)
    {
            return 
    0;
    }

    struct file_operations fops =
    {
            .
    open pipe_open ,
            .
    read pipe_read ,
            .
    write pipe_write ,
            .
    release pipe_release,
    };

    static 
    int __init pipe_init(void)
    {
            
    int result;

            if(
    major)
            {
                    
    device_node MKDEV(major minor);

                    
    result register_chrdev_region(device_node "pipe");
            }else
            {
                    
    result alloc_chrdev_region(&device_node "pipe");
            }

            if(
    result == -1)
            {
                    
    printk(KERN_INFO"Failed To Register Device Number\n\n");
                    return 
    result;
            }

            
    printk(KERN_INFO
                            
    "Registred with major:minor %d:%d\n",
                            
    MAJOR(device_node) , MINOR(device_node));

            
    cdev_init(&device , &fops);
            
    device.owner THIS_MODULE;

            
    result cdev_add(&device device_node 1);
            if(
    result == -1)
            {
                    
    printk(KERN_INFO"Failed To register Char device\n\n");
                    return 
    result;
            }

            
    printk(KERN_INFO"Device Is live\n\n");

            
    /* initialize Complete Structure */
            
    init_completion(&complete_task);
            return 
    0;

    }


    static 
    void __exit pipe_exit(void)
    {
            
    unregister_chrdev_region(device_node 1);
            
    cdev_del(&device);

            
    printk(KERN_INFO"Device Is Removed\n\n");

    }
    module_init(pipe_init);
    module_exit(pipe_exit); 
    كود:
    [email protected]:~/Desktop/linux.programming/kernel/pipe# insmod pipe_char.ko major=100 minor=0
    [email protected]:~/Desktop/linux.programming/kernel/pipe# mknod /dev/pipe_char c 100 0
    [email protected]:~/Desktop/linux.programming/kernel/pipe# echo "It's only after we have lost every thing that we are free to do anything" > /dev/pipe_char
    [email protected]:~/Desktop/linux.programming/kernel/pipe# cat /dev/pipe_char
    It's only after we have lost every thing that we are free to do anything
    BOOOF , I AM GONE
    Still , you gotta wait for my PRESENT :D
    C programming arabic Tutorial|Programming-fr34ks

  • #2
    فكره اضافيه :
    حتي لو كنت مش تعرف اي حاجه في ال kernel programming
    تقدر تعدل علي ال code بشكل بسيط حيث
    انه قبل مايكتب لل user الكلام يعمل حاجه من ال 2 :
    1- encrypt it md5
    2- encrypt it crc
    ليك حرية الاختيار طبعا
    وانا حعتبر دوا تحدي ! ونشوف المبرمجين !
    BOOOF , I AM GONE
    Still , you gotta wait for my PRESENT :D
    C programming arabic Tutorial|Programming-fr34ks

    تعليق

    يعمل...
    X