dev.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/device.h>
  4. #include <linux/types.h>
  5. #include <linux/cdev.h>
  6. #include <linux/fs.h>
  7. #include <linux/slab.h>
  8. #include "mod.h"
  9. #include "dev.h"
  10. #include "debug.h"
  11. #define sysfs_attr(name) do { \
  12. if (device_create_file(dev->dev, &dev_attr_##name) != 0) \
  13. goto probe_device_create_fail; \
  14. } while (0)
  15. int test_device_open(struct inode *inode, struct file *filp)
  16. {
  17. test_dev_t *test;
  18. test = container_of( inode->i_cdev, test_dev_t, cdev);
  19. filp->private_data = test;
  20. mod_info("open\n");
  21. return 0;
  22. }
  23. int test_device_release(struct inode *inode, struct file *filp)
  24. {
  25. test_dev_t *test = (test_dev_t*)filp->private_data;
  26. mod_info("close\n");
  27. return 0;
  28. }
  29. static struct file_operations test_fops = {
  30. .owner = THIS_MODULE,
  31. // .unlocked_ioctl = pcidriver_ioctl,
  32. // .mmap = pcidriver_mmap,
  33. .open = test_device_open,
  34. .release = test_device_release,
  35. };
  36. const struct file_operations *test_get_fops(void)
  37. {
  38. return &test_fops;
  39. }