Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Device Attributes in sysfs

    Hi there...
    I try to build additional device attributes in my module so they will appear in sysfs. But I can't build them and i can't find how to do it!?
    Plz help...the atributes are "name", "pid", "pgdir"...

    My source-code is:

    #include <linux/kernel.h>
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/moduleparam.h>
    #include <linux/device.h>
    #include <linux/fs.h>

    MODULE_DESCRIPTION("My kernel module");

    static char *name;
    module_param(name, charp, 0644);

    struct class *bs_class;
    struct device *bs_device;
    static int bs_Major;

    //static int device_open(struct inode *, struct file *);
    //static int device_release(struct inode *, struct file *);
    //static ssize_t device_read(struct file *, char *, size_t, loff_t *);
    //static ssize_t device_write(struct file *, const char *, size_t, loff_t *);

    static struct file_operations fops = {
    // .read = device_read,
    // .write = device_write,
    // .open = device_open,
    // .release = device_release

    static int bs1_init_module(void)
    printk("<0>Module BS1 init\n" );
    bs_Major = register_chrdev(0,"bs-device", &fops);
    if (bs_Major<0) {
    printk(KERN_WARNING "Kann keine Major-Nummer bekommen!");
    return bs_Major;
    bs_class = class_create(THIS_MODULE,"bs-class");
    bs_device = device_create(bs_class,NULL,MKDEV(bs_Major,0),"bs-device");
    // DEVICE_ATTR(name,0644,show_debug, NULL);
    return 0;

    static void bs1_exit_module(void)
    printk("<0>Module BS1 exit\n" );


  2. #2

    device attribute functions call


    I am facing one problem with device attribute functions.

    I am using below macro for registering

    static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, xmd_boot_modem_state_show,

    status = device_create_file(&pdev->dev, &dev_attr_state);

    here in my code xmd_boot_modem_state_store() is not getting called.

    Just i wanted to know what makes these functions gets called.

    Kindly help me in this regard.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts