Advertisement
alsiva

alsiva_app.c

Dec 16th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <sys/ioctl.h>
  9. #include "driver.h"
  10. #include <linux/ioctl.h>
  11. #include <linux/types.h>
  12. #include <linux/pci.h>
  13.  
  14. #define WR_VALUE _IOW('a','a',int32_t*)
  15. #define RD_VALUE _IOR('a','b',char[])
  16.  
  17.  
  18. int main()
  19. {
  20.     int fd;
  21.     int32_t number;
  22.     printf("***Alexey Ivanov Lab 2 OS***\n");
  23.      
  24.  
  25.     printf("\nOpening Driver\n");
  26.     fd = open("/dev/etx_device", O_RDWR);
  27.     if(fd < 0) {
  28.         printf("Cannot open device file...\n");
  29.         return 0;
  30.     }
  31.  
  32.     printf("Enter pid to send\n");
  33.     scanf("%d",&number);
  34.     printf("Writing Value to Driver\n");
  35.     ioctl(fd, WR_VALUE, (int32_t*) &number);
  36.  
  37.     struct vm_area_struct_info value;
  38.     if (ioctl(fd, IOCTL_READ_VM_AREA_STRUCT, &value) < 0) {
  39.       perror("[ERROR]: ioctl");
  40.       exit(EXIT_FAILURE);
  41.     }
  42.     printf("%s: received ", "READ_VM_AREA_STRUCT");
  43.  
  44.     printf("vm_area_struct_info : ");
  45.     printf("vm_start = %hu\n", value.vm_start);
  46.     printf("vm_end = %hu\n", value.vm_end);
  47.     printf("vm_flags = %hu\n", value.vm_flags);
  48.     printf("vm_pgoff = %hu\n", value.vm_pgoff);
  49.     printf("rb_subtree_gap = %hu\n", value.rb_subtree_gap);
  50.    
  51.  
  52.  
  53.     struct pci_device_info data;
  54.     if (ioctl(fd, IOCTL_READ_PCI_DEVICE_INFO, &data) < 0) {
  55.       perror("[ERROR]: ioctl");
  56.       exit(EXIT_FAILURE);
  57.     }
  58.     printf("%s: received ", "READ_VM_AREA_STRUCT");
  59.  
  60.     printf("pci_device_info : ");
  61.     printf("vendor = %hu\n", data.vendor);
  62.     printf("device = %hu\n", data.device);
  63.     printf("devfn = %hu\n", data.devfn);
  64.     printf("pin = %hu\n", data.pin);
  65.     printf("pci_class = %hu\n", data.pci_class);
  66.     printf("revision = %hu\n", data.revision);
  67.  
  68.  
  69.     close(fd);
  70.  
  71. return;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement