ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 디바이스 드라이버 / 헤더 파일별 함수 정의
    Linux/Linux Device Driver 2020. 8. 30. 00:00

    유저

    #include <fcntl.h>

    int open(const char *__file, int __oflag, ...)

     

     

    #include <unistd.h> : /usr/include/unistd.h

    __off_t lseek(int __fd, __off_t __offset, int __whence)

    int close(int __fd)

    ssize_t read(int __fd, void *buf, size_t __nbytes)

    ssize_t write(int __fd, const void *__buf, size_t __n)

    unsigned int sleep(unsigned int __seconds)

    int usleep(__useconds_t __useconds)

     

     

    #include <sys/ioctl.h> : /usr/include/arm-linux-gnueabihf/sys/ioctl.h

    int ioctl(int __fd, unsigned long int __request, ...)

     

     

    #include <stdlib.h> : /usr/include/stdlib.h

    int atoi(const char *__nptr)

    void *malloc(size_t __size)

    void free(void *__ptr)

    void exit(int __status)

     

     

    #include <string.h> : /usr/include/string.h

    size_t strlen(const char *__string, size_t __maxlen)

     

     

     

     

     

    커널

    커널 디렉터리/include/asm-generic은 필요시 사용되는 것 같다.

    asm은 asm-generic로 심볼릭 링크되어있다고 한다.??

     

     

    #include <linux/cdev.h> : 커널 디렉터리/include/linux/cdev.h

    struct cdev{

       struct kobject kobj;

       struct module *owner;

       const struct file_operations *ops;

       struct list_head list;

       dev_t dev;

       unsigned int count;

    } __randomize_layout;

     

    struct cdev *cdev_alloc(void)

    void cdev_init(struct cdev *, const struct file_opertaions *)

    int cdev_add(struct cdev *, dev_t, unsigned);

    void cdev_del(struct cdev *);

     

     

     

    #include <linux/fs.h> : 커널 디렉터리/include/linux/fs.h

    int register_chrdev(unsigned int major, const char *name, const struct file_operations *fops)

    void unregister_chrdev(unsigned int major, const char *name)

    int register_chrdev_region(dev_t, unsigned, const char *)

    void unregister_chrdev_region(dev_t, unsigned);

    int register_blkdev(unsigned int, const char *) 

    void unregister_blkdev(unsigned int, const char *)

    static inline unsigned iminor(const struct inode *inode)

    static inline unsigned imajor(const struct inode *inode)

     

    struct file_operations {

    struct module *owner;

    loff_t (*llseek) (struct file *, loff_t, int);

    ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);

    ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);

    ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);

    ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);

    int (*iterate) (struct file *, struct dir_context *);

    int (*iterate_shared) (struct file *, struct dir_context *);

    __poll_t (*poll) (struct file *, struct poll_table_struct *);

    long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);

    long (*compat_ioctl) (struct file *, unsigned int, unsigned long);

    int (*mmap) (struct file *, struct vm_area_struct *);

    unsigned long mmap_supported_flags;

    int (*open) (struct inode *, struct file *);

    int (*flush) (struct file *, fl_owner_t id);

    int (*release) (struct inode *, struct file *);

    int (*fsync) (struct file *, loff_t, loff_t, int datasync);

    int (*fasync) (int, struct file *, int);

    int (*lock) (struct file *, int, struct file_lock *);

    ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);

    unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);

    int (*check_flags)(int);

    int (*flock) (struct file *, int, struct file_lock *);

    ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);

    ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);

    int (*setlease)(struct file *, long, struct file_lock **, void **);

    long (*fallocate)(struct file *file, int mode, loff_t offset, loff_t len);

    void (*show_fdinfo)(struct seq_file *m, struct file *f);

    #ifndef CONFIG_MMU

    unsigned (*mmap_capabilities)(struct file *);

    #endif

    ssize_t (*copy_file_range)(struct file *, loff_t, struct file *, loff_t, size_t, unsigned int);

    int (*clone_file_range)(struct file *, loff_t, struct file *, loff_t, u64);

    int (*dedupe_file_range)(struct file *, loff_t, struct file *, loff_t, u64);

    int (*fadvise)(struct file *, loff_t, loff_t, int);

    } __randomize_layout;

     

     

     

    #include <linux/kdev_t.h> : 커널 디렉터리/include/linux/kdev_t.h

    #define MINOR(dev)

    #define MAJOR(dev)

    #define MKDEV(ma, mi)

     

     

     

    #include <linux/netdevice.h> : 커널 디렉터리/include/linux/netdevice.h

    int register_netdevice(struct net_device * dev)

    void unregister_netdevice(struct net_device *dev);

     

     

     

    #include <linux/io.h> : 커널 디렉터리/include/linux/io.h

    +#include <asm/io.h>  :  커널 디렉터리/arch/arm/include/asm/io.h 

    void __iomem *ioremap(resource_size_t res_cookie, size_t size)

    void iounmap(volatile void __iomem *iomem_cookie)

     

     

     

     

    #include <linux/uaccess.h> : 커널 디렉터리/include/linux/uaccess.h

    unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)

    unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)

    #define VERIFY_READ

    #define VERIFY_WRITE

    +#include <asm/uaccess.h> : 커널 디렉너리/arch/arm/include/asm/uaccess.h

    #define access_ok(type, addr, size)

     

     

     

     

    #include <linux/slab.h> : 커널 디렉터리/include/linux/slab.h

    void *kmalloc(size_t size, gfp_t flags)

    void kfree(const void *)

     

     

     

    #include <linux/vmalloc.h> : 커널 디렉터리/include/linux/vmalloc.h

    void *vmalloc(unsigned long size)

    void vfree(const void *addr)

     

     

     

    #include <linux/module.h> : 커널 디렉터리/include/linux/module.h

    #define module_init(initfn)

    #define module_exit(exitfn)

    bool try_module_get(struct module *module)

    void module_put(struct module *module)

     

     

     

    #include <linux/interrupt.h> : 커널 디렉터리/include/linux/interrupt.h

    int __must_check request_irq(unsigned int irq, irq_handle_t handler, unsigned long flags, const char *name, void *dev)

    void *free_irq(unsigned int, void *);

     

     

     

    #include <linux/export.h> : 커널 디렉터리/include/linux/export.h

    #define THIS_MODULE

     

     

     

     

     

    #include <linux/ioctl.h> : 커널 디렉터리/include/uapi/linux/ioctl.h

    +#include <asm/ioctl.h> : 커널 디렉터리/arch/arm/include/generated/uapi/asm/ioctl.h

    ++#include <asm-generic/ioctl.h> : 커널 디렉터리/include/asm-generic/ioctl.h

    +++#include <uapi/asm-generic/ioctl.h> : 커널 디렉터리/include/uapi/asm-generic/ioctl.h

     

    #define _IOC_NONE

    #define _IOC_WRITE

    #define _IOC_READ

     

    #define _IOC(dir, type, nr, size)

    #define _IO(type, nr)

    #define _IOR(type, nr, size)

    #define _IOW(type, nr, size)

    #define _IOWR(type, nr, size)

     

    #define _IOC_DIR(nr)

    #define _IOC_TYPE(nr)

    #define _IOC_NR(nr)

    #define _IOC_SIZE(nr)

     

     

     

    #include <linux/delay.h> : 커널 디렉터리/include/linux/delay.h

    #define mdelay(n)

    void ndelay(unsigned long x)

    +#include <asm/delay.h> : 커널 디렉터리/arch/arm/include/asm/delay.h

    #define udelay(n)

     

     

    #include <linux/string.h> : 커널 디렉터리/include/linux/string.h

    void *memset(void *, int, __kernel_size_t)

     

     

    #include <linux/timer.h> : 커널 디렉터리/include/linux/timer.h

    struct timer_list{

    struct hlist_node entry;

    unsigned long expire;

    void (*function)(struct timer_list *);

    u32 flags;

    #ifdef CONFIG_LOCKDEP

    struct lockdep_map lockdep_map;

    #endif

    };

    #define timer_setup(timer, callback, flags)

    void add_timer(struct timer_list *timer)

    int mod_timer(struct timer_list *timer, unsigned long expires)

    int del_timer(struct timer_list *timer)

     

     

    #include <linux/delay.h> : 커널 디렉터리/include/linux/delay.h

    #define mdelay(n)

    void ndelay(unsigned int x)

    +#include <asm/delay.h> : 커널 디렉터리/arch/arm/include/asm/delay.h

    #define udelay(n)

     

     

     

    #include <linux/jiffies.h> : 커널 디렉터리/include/linux/jiffies.h

    u64 get_jiffies_64(void)

    +#include <asm/param.h> : 커널 디렉터리/arch/arm/include/generated/uapi/asm/param.h

    ++#include <asm-generic/param.h> : 커널 디렉터리/include/asm-generic/param.h

    #define HZ

    #define USER_HZ

     

     

     

    #include <linux/irqreturn.h> : 커널 디렉터리/include/linux/irqreturn.h

    enum irqreturn{

    IRQ_NONE

    IRQ_HANDLED

    IRQ_WAKE_THREAD

    }

     

    #include <linux/errno.h> : 커널 디렉터리/include/linux/errno.h

    #define ERESTARTSYS 512
    #define ERESTARTNOINTR 513
    #define ERESTARTNOHAND 514 /* restart if no handler.. */
    #define ENOIOCTLCMD 515 /* No ioctl command */
    #define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
    #define EPROBE_DEFER 517 /* Driver requests probe retry */
    #define EOPENSTALE 518 /* open found a stale dentry */
    /* Defined for the NFSv3 protocol */
    #define EBADHANDLE 521 /* Illegal NFS file handle */
    #define ENOTSYNC 522 /* Update synchronization mismatch */
    #define EBADCOOKIE 523 /* Cookie is stale */
    #define ENOTSUPP 524 /* Operation is not supported */
    #define ETOOSMALL 525 /* Buffer or request is too small */
    #define ESERVERFAULT 526 /* An untranslatable error occurred */
    #define EBADTYPE 527 /* Type not supported by server */
    #define EJUKEBOX 528 /* Request initiated, but will not complete before timeout */
    #define EIOCBQUEUED 529 /* iocb queued, will get completion event */
    #define ERECALLCONFLICT 530 /* conflict with recalled state */

     

    +#include <uapi/linux/errno.h> : 커널 디렉터리/include/uapi/linux/errno.h

    ++#include <asm/errno.h> : 커널 디렉터리/arch/arm/include/generated/uapi/asm/errno.h

    +++#include <asm-generic/errno.h> : 커널 디렉터리/include/uapi/asm-generic/errno.h

    #define EDEADLK 35 /* Resource deadlock would occur */
    #define ENAMETOOLONG 36 /* File name too long */
    #define ENOLCK 37 /* No record locks available */
    /*
    * This error code is special: arch syscall entry code will return
    * -ENOSYS if users try to call a syscall that doesn't exist. To keep
    * failures of syscalls that really do exist distinguishable from
    * failures due to attempts to use a nonexistent syscall, syscall
    * implementations should refrain from returning -ENOSYS.
    */
    #define ENOSYS 38 /* Invalid system call number */
    #define ENOTEMPTY 39 /* Directory not empty */
    #define ELOOP 40 /* Too many symbolic links encountered */
    #define EWOULDBLOCK EAGAIN /* Operation would block */
    #define ENOMSG 42 /* No message of desired type */
    #define EIDRM 43 /* Identifier removed */
    #define ECHRNG 44 /* Channel number out of range */
    #define EL2NSYNC 45 /* Level 2 not synchronized */
    #define EL3HLT 46 /* Level 3 halted */
    #define EL3RST 47 /* Level 3 reset */
    #define ELNRNG 48 /* Link number out of range */
    #define EUNATCH 49 /* Protocol driver not attached */
    #define ENOCSI 50 /* No CSI structure available */
    #define EL2HLT 51 /* Level 2 halted */
    #define EBADE 52 /* Invalid exchange */
    #define EBADR 53 /* Invalid request descriptor */
    #define EXFULL 54 /* Exchange full */
    #define ENOANO 55 /* No anode */
    #define EBADRQC 56 /* Invalid request code */
    #define EBADSLT 57 /* Invalid slot */
    #define EDEADLOCK EDEADLK
    #define EBFONT 59 /* Bad font file format */
    #define ENOSTR 60 /* Device not a stream */
    #define ENODATA 61 /* No data available */
    #define ETIME 62 /* Timer expired */
    #define ENOSR 63 /* Out of streams resources */
    #define ENONET 64 /* Machine is not on the network */
    #define ENOPKG 65 /* Package not installed */
    #define EREMOTE 66 /* Object is remote */
    #define ENOLINK 67 /* Link has been severed */
    #define EADV 68 /* Advertise error */
    #define ESRMNT 69 /* Srmount error */
    #define ECOMM 70 /* Communication error on send */
    #define EPROTO 71 /* Protocol error */
    #define EMULTIHOP 72 /* Multihop attempted */
    #define EDOTDOT 73 /* RFS specific error */
    #define EBADMSG 74 /* Not a data message */
    #define EOVERFLOW 75 /* Value too large for defined data type */
    #define ENOTUNIQ 76 /* Name not unique on network */
    #define EBADFD 77 /* File descriptor in bad state */
    #define EREMCHG 78 /* Remote address changed */
    #define ELIBACC 79 /* Can not access a needed shared library */
    #define ELIBBAD 80 /* Accessing a corrupted shared library */
    #define ELIBSCN 81 /* .lib section in a.out corrupted */
    #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
    #define ELIBEXEC 83 /* Cannot exec a shared library directly */
    #define EILSEQ 84 /* Illegal byte sequence */
    #define ERESTART 85 /* Interrupted system call should be restarted */
    #define ESTRPIPE 86 /* Streams pipe error */
    #define EUSERS 87 /* Too many users */
    #define ENOTSOCK 88 /* Socket operation on non-socket */
    #define EDESTADDRREQ 89 /* Destination address required */
    #define EMSGSIZE 90 /* Message too long */
    #define EPROTOTYPE 91 /* Protocol wrong type for socket */
    #define ENOPROTOOPT 92 /* Protocol not available */
    #define EPROTONOSUPPORT 93 /* Protocol not supported */
    #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
    #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
    #define EPFNOSUPPORT 96 /* Protocol family not supported */
    #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
    #define EADDRINUSE 98 /* Address already in use */
    #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
    #define ENETDOWN 100 /* Network is down */
    #define ENETUNREACH 101 /* Network is unreachable */
    #define ENETRESET 102 /* Network dropped connection because of reset */
    #define ECONNABORTED 103 /* Software caused connection abort */
    #define ECONNRESET 104 /* Connection reset by peer */
    #define ENOBUFS 105 /* No buffer space available */
    #define EISCONN 106 /* Transport endpoint is already connected */
    #define ENOTCONN 107 /* Transport endpoint is not connected */
    #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
    #define ETOOMANYREFS 109 /* Too many references: cannot splice */
    #define ETIMEDOUT 110 /* Connection timed out */
    #define ECONNREFUSED 111 /* Connection refused */
    #define EHOSTDOWN 112 /* Host is down */
    #define EHOSTUNREACH 113 /* No route to host */
    #define EALREADY 114 /* Operation already in progress */
    #define EINPROGRESS 115 /* Operation now in progress */
    #define ESTALE 116 /* Stale file handle */
    #define EUCLEAN 117 /* Structure needs cleaning */
    #define ENOTNAM 118 /* Not a XENIX named type file */
    #define ENAVAIL 119 /* No XENIX semaphores available */
    #define EISNAM 120 /* Is a named type file */
    #define EREMOTEIO 121 /* Remote I/O error */
    #define EDQUOT 122 /* Quota exceeded */
    #define ENOMEDIUM 123 /* No medium found */
    #define EMEDIUMTYPE 124 /* Wrong medium type */
    #define ECANCELED 125 /* Operation Canceled */
    #define ENOKEY 126 /* Required key not available */
    #define EKEYEXPIRED 127 /* Key has expired */
    #define EKEYREVOKED 128 /* Key has been revoked */
    #define EKEYREJECTED 129 /* Key was rejected by service */
    /* for robust mutexes */
    #define EOWNERDEAD 130 /* Owner died */
    #define ENOTRECOVERABLE 131 /* State not recoverable */
    #define ERFKILL 132 /* Operation not possible due to RF-kill */
    #define EHWPOISON 133 /* Memory page has hardware error */

     

    ++#include <uapi/asm-generic/errno-base.h> : 커널 디렉터리/include/uapi/asm-generic/errno-base.h

    #define EPERM 1 /* Operation not permitted */
    #define ENOENT 2 /* No such file or directory */
    #define ESRCH 3 /* No such process */
    #define EINTR 4 /* Interrupted system call */
    #define EIO 5 /* I/O error */
    #define ENXIO 6 /* No such device or address */
    #define E2BIG 7 /* Argument list too long */
    #define ENOEXEC 8 /* Exec format error */
    #define EBADF 9 /* Bad file number */
    #define ECHILD 10 /* No child processes */
    #define EAGAIN 11 /* Try again */
    #define ENOMEM 12 /* Out of memory */
    #define EACCES 13 /* Permission denied */
    #define EFAULT 14 /* Bad address */
    #define ENOTBLK 15 /* Block device required */
    #define EBUSY 16 /* Device or resource busy */
    #define EEXIST 17 /* File exists */
    #define EXDEV 18 /* Cross-device link */
    #define ENODEV 19 /* No such device */
    #define ENOTDIR 20 /* Not a directory */
    #define EISDIR 21 /* Is a directory */
    #define EINVAL 22 /* Invalid argument */
    #define ENFILE 23 /* File table overflow */
    #define EMFILE 24 /* Too many open files */
    #define ENOTTY 25 /* Not a typewriter */
    #define ETXTBSY 26 /* Text file busy */
    #define EFBIG 27 /* File too large */
    #define ENOSPC 28 /* No space left on device */
    #define ESPIPE 29 /* Illegal seek */
    #define EROFS 30 /* Read-only file system */
    #define EMLINK 31 /* Too many links */
    #define EPIPE 32 /* Broken pipe */
    #define EDOM 33 /* Math argument out of domain of func */
    #define ERANGE 34 /* Math result not representable */

     

     

    #include <linux/preempt.h> // 커널 디렉터리/include/linux/preempt.h

    #define in_interrupt()

    댓글

Designed by Tistory.