0

I want to call kernel module driver.ko ioctl from user space with c program. when compiling I got this error

header.h:13:38: error: expected expression before ‘char’
 #define IOCTL_CMD _IORW(MAGIC_NO, 0, char *)

by definition I put the right arguments : _IORW(int type, int number, data_type)

main.c

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include "header.h"

int main()
{
    int fd;
    char * msg = "5";
    fd = open(DEVICE_PATH, O_RDWR);
    ioctl(fd, IOCTL_CMD, msg);
    printf("ioctl executed\n");
    close(fd);
    return 0;
}

header.h

#include <linux/ioctl.h>
#include <linux/kdev_t.h> /* for MKDEV */

#define DEVICE_NAME "driver"
#define DEVICE_PATH "/dev/driver"
#define WRITE 0
static int major_no;

#define MAGIC_NO '4'
    /* 
     * Set the message of the device driver 
     */
#define IOCTL_CMD _IORW(MAGIC_NO, 0, char *)
ALOToverflow
  • 2,679
  • 5
  • 36
  • 70
  • You might want to look at this question: http://stackoverflow.com/questions/2264384/how-do-i-use-ioctl-to-manipulate-my-kernel-module – ALOToverflow Aug 07 '14 at 15:04

1 Answers1

1

The macro _IORW doesn't seem to exist in the Linux headers, try using _IOWR instead. Also I don't think you're use of char * is correct here. That would imply the last parameter to ioctl is the address of a char * variable, not a string.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112