Find the answer to your Linux question:
Results 1 to 2 of 2
gcc -c func1.c error: variable ‘memory_fops’ has initializer but incomplete type error: unknown field ‘read’ specified in initializer warning: excess elements in struct initializer warning: (near initialization for ‘memory_fops’) error: ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    1

    error in compile char device driver

    gcc -c func1.c
    error: variable ‘memory_fops’ has initializer but incomplete type



    error: unknown field ‘read’ specified in initializer
    warning: excess elements in struct initializer
    warning: (near initialization for ‘memory_fops’)
    error: unknown field ‘write’ specified in initializer
    warning: excess elements in struct initializer
    warning: (near initialization for ‘memory_fops’)
    error: unknown field ‘open’ specified in initializer
    warning: excess elements in struct initializer
    warning: (near initialization for ‘memory_fops’)
    error: unknown field ‘release’ specified in initializer
    warning: excess elements in struct initializer
    warning: (near initialization for ‘memory_fops’)
    error: unknown field ‘ioctl’ specified in initializer
    warning: excess elements in struct initializer
    warning: (near initialization for ‘memory_fops’)

    source code:

    #include <linux/gfp.h> */
    #include <linux/config.h>
    #include <linux/module.h>
    #include <linux/kernel.h> /* printk() */
    #include <linux/slab.h> /* kmalloc() */
    #include </usr/src/kernels/2.6.11-1.1369_FC4-smp-i686/include/linux/fs.h> /* everything... */
    #include <linux/errno.h> /* error codes */
    #include <linux/types.h> /* size_t */
    #include <linux/proc_fs.h>
    #include <linux/fcntl.h> /* O_ACCMODE */
    #include <asm/system.h> /* cli(), *_flags */
    #include <asm/uaccess.h> /* copy_from/to_user */
    MODULE_LICENSE("Dual BSD/GPL");



    /*P_ATOMIC */

    int memory_open(struct inode *inode, struct file *filp);
    int memory_release(struct inode *inode, struct file *filp);
    ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);
    ssize_t memory_write(struct file *filp, char *buf, size_t count, loff_t *f_pos);

    /* Structure that declares the usual file */
    /* access functions */
    struct file_operations memory_fops = {
    read: memory_read,
    write: memory_write,
    open: memory_open,
    release: memory_release
    };


    /* Global variables of the driver */
    /* Major number */
    int memory_major = 60;
    /* Buffer to store data */
    char *memory_buffer;

    /*<memory exit module> */
    void memory_exit(void) {
    /* Freeing the major number */
    unregister_chrdev(memory_major, "memory");
    /* Freeing buffer memory */
    if (memory_buffer) {
    kfree(memory_buffer);
    }
    printk("<1>Removing memory module\n");
    }


    /*<memory init module> */
    int memory_init(void) {
    int result;
    /* Registering device */
    result = register_chrdev(memory_major, "memory", &memory_fops);
    if (result < 0) {
    printk(
    "<1>memory: cannot obtain major number %d\n", memory_major);
    return result;
    }
    /* Allocating memory for the buffer GFP_KERNEL*/
    memory_buffer = kmalloc(1,2);
    if (!memory_buffer) {
    result = -ENOMEM;
    goto fail;
    }
    memset(memory_buffer, 0, 1);
    printk("<1>Inserting memory module\n");
    return 0;
    fail:
    memory_exit();
    return result;
    }

  2. #2
    Linux Newbie
    Join Date
    Mar 2008
    Location
    Hyderabad
    Posts
    109
    struct file_operations memory_fops = {
    .read = memory_read,
    .write = memory_write,
    .open = memory_open,
    .release = memory_release
    };

    There are many more too gud luck

Posting Permissions

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