chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

Linux驅(qū)動(dòng)debugfs接口代碼實(shí)現(xiàn)

麥辣雞腿堡 ? 來(lái)源:嵌入式Linux充電站 ? 作者:Vincent ? 2023-09-27 11:12 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

實(shí)現(xiàn)效果

/sys/kernel/debug/目錄下創(chuàng)建一個(gè)ion/test文件,通過(guò)cat、echo的方式進(jìn)行讀寫(xiě)操作:

圖片

圖片

前期準(zhǔn)備

內(nèi)核配置打開(kāi)debugfs:

CONFIG_DEBUG_FS=y

掛載debugfs文件系統(tǒng):

mount -t debugfs none /sys/kernel/debug

代碼實(shí)現(xiàn)

讀寫(xiě)變量:

#include < linux/debugfs.h >
#include < linux/module.h >
#include < linux/types.h >

static struct dentry *ion_dir;
static u64 test_u64 = 0;

static int __init debugfs_init(void)
{

    //創(chuàng)建一個(gè)/sys/kernel/debug/ion目錄
    ion_dir = debugfs_create_dir("ion", NULL);
    if (!ion_dir) {
        printk("ion_dir is nulln");
        return -1;
    }

    /* 創(chuàng)建/sys/kernel/debug/ion/test_u64文件 */
    debugfs_create_u64("test_u64", 0644,
                        ion_dir, &test_u64);

    return 0;
}

static void __exit debugfs_exit(void)
{
    debugfs_remove_recursive(ion_dir);
}

module_init(debugfs_init);
module_exit(debugfs_exit);
MODULE_LICENSE("GPL");

運(yùn)行結(jié)果:

圖片

讀寫(xiě)字符串:

#include < linux/debugfs.h >
#include < linux/module.h >
#include < linux/fs.h >
#include < linux/uaccess.h >
#include < linux/errno.h >
#include < linux/dcache.h >
#include < linux/types.h >

static char ion_buf[512] = "hellon";
static struct dentry *ion_dir;

static int ion_open(struct inode *inode, struct file *filp)
{
    //printk("ion openn");
    return 0;
}

ssize_t ion_read(struct file *filp, char __user *buf, size_t count, loff_t *offp)
{
    int retval = 0;
    if ((*offp + count) > 512)
        count = 512 - *offp;

    if (copy_to_user(buf, ion_buf+*offp, count)) {
        printk("copy to user failed, count:%ldn", count);
        retval = -EFAULT;
        goto out;
    }
    *offp += count;
    retval = count;
out:
    return retval;
}

ssize_t ion_write(struct file *filp, const char __user *buff, size_t count, loff_t *offp)
{
    int retval;

    if (*offp > 512)
        return 0;

    if (*offp + count > 512)
        count = 512 - *offp;

    if (copy_from_user(ion_buf+*offp, buff, count)) {
        printk("copy from user failed, count:%ldn", count);
        retval = -EFAULT;
        goto out;
    }
    *offp += count;
    retval = count;
out:
    return retval;
}

struct file_operations my_fops = {
    .owner = THIS_MODULE,
    .read = ion_read,
    .write = ion_write,
    .open = ion_open,
};

static int __init debugfs_init(void)
{
    printk("INIT MODULEn");

    //創(chuàng)建一個(gè)/sys/kernel/debug/ion目錄
    ion_dir = debugfs_create_dir("ion", NULL);
    if (!ion_dir) {
        printk("ion_dir is nulln");
        return -1;
    }

    /* 創(chuàng)建/sys/kernel/debug/ion/test文件 */
    struct dentry *filent = debugfs_create_file("test", 0644, ion_dir, NULL, &my_fops);
    if (!filent) {
        printk("test file is nulln");
        return -1;
    }

    return 0;
}

static void __exit debugfs_exit(void)
{
    debugfs_remove_recursive(ion_dir);
}

module_init(debugfs_init);
module_exit(debugfs_exit);
MODULE_LICENSE("GPL");

運(yùn)行結(jié)果:

圖片

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 接口
    +關(guān)注

    關(guān)注

    33

    文章

    9450

    瀏覽量

    156165
  • 驅(qū)動(dòng)
    +關(guān)注

    關(guān)注

    12

    文章

    1928

    瀏覽量

    88210
  • Linux
    +關(guān)注

    關(guān)注

    88

    文章

    11628

    瀏覽量

    218015
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4942

    瀏覽量

    73160
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    Linux驅(qū)動(dòng)中創(chuàng)建procfs接口的方法

    上篇介紹了Linux驅(qū)動(dòng)中sysfs接口的創(chuàng)建,今天介紹procfs接口的創(chuàng)建。
    發(fā)表于 05-31 16:48 ?1053次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>驅(qū)動(dòng)</b>中創(chuàng)建procfs<b class='flag-5'>接口</b>的方法

    Linux驅(qū)動(dòng)中創(chuàng)建debugfs接口的方法

    上篇介紹了procfs接口的創(chuàng)建,今天再介紹一種debugfs接口的創(chuàng)建。
    發(fā)表于 05-31 16:53 ?1506次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>驅(qū)動(dòng)</b>中創(chuàng)建<b class='flag-5'>debugfs</b><b class='flag-5'>接口</b>的方法

    如何去實(shí)現(xiàn)嵌入式LINUX驅(qū)動(dòng)的軟件代碼

    如何對(duì)嵌入式LINUX驅(qū)動(dòng)的硬件信息進(jìn)行配置呢?如何去實(shí)現(xiàn)嵌入式LINUX驅(qū)動(dòng)的軟件代碼呢?
    發(fā)表于 12-24 07:31

    Linux MTD 源代碼分析

    Linux MTD 源代碼分析 Linux MTD介紹:設(shè)備層和原始設(shè)備層的函數(shù)調(diào)用關(guān)系(紅色部分需要我們實(shí)現(xiàn)):NOR型Flash芯片驅(qū)動(dòng)
    發(fā)表于 02-08 16:43 ?9次下載

    Linux內(nèi)核源代碼漫游

    Linux內(nèi)核源代碼漫游 本章試圖以順序的方式來(lái)解釋Linux代碼,以幫助讀者對(duì)源代碼的體系結(jié)構(gòu)以及很多相關(guān)的unix特性的
    發(fā)表于 02-09 15:27 ?26次下載

    基于Linux下的LCD驅(qū)動(dòng)程序實(shí)現(xiàn)

    基于Linux下的LCD驅(qū)動(dòng)程序實(shí)現(xiàn)
    發(fā)表于 10-30 16:45 ?12次下載
    基于<b class='flag-5'>Linux</b>下的LCD<b class='flag-5'>驅(qū)動(dòng)</b>程序<b class='flag-5'>實(shí)現(xiàn)</b>

    你知道Linux內(nèi)核里的DebugFS?

    DebugFS,顧名思義,是一種用于內(nèi)核調(diào)試的虛擬文件系統(tǒng),內(nèi)核開(kāi)發(fā)者通過(guò)debugfs和用戶(hù)空間交換數(shù)據(jù)。
    發(fā)表于 04-25 18:55 ?2058次閱讀
    你知道<b class='flag-5'>Linux</b>內(nèi)核里的<b class='flag-5'>DebugFS</b>?

    要學(xué)會(huì)調(diào)試內(nèi)核打印debugfs

    name是創(chuàng)建的目錄名字,parent是該目錄的父目錄。如果填NULL,則直接出現(xiàn)在debugfs的根目錄。
    發(fā)表于 04-27 19:01 ?1480次閱讀

    嵌入式Linux系統(tǒng)的驅(qū)動(dòng)原理和使用ARM Linux實(shí)現(xiàn)SPI驅(qū)動(dòng)程序的說(shuō)明

    介紹嵌入式Linux系統(tǒng)的驅(qū)動(dòng)原理;分析SPI協(xié)議的通信原理和微處理器S3C2440A中SPI接口的硬件結(jié)構(gòu);闡述SPI驅(qū)動(dòng)程序的實(shí)現(xiàn)過(guò)程。
    發(fā)表于 11-14 16:36 ?11次下載
    嵌入式<b class='flag-5'>Linux</b>系統(tǒng)的<b class='flag-5'>驅(qū)動(dòng)</b>原理和使用ARM <b class='flag-5'>Linux</b><b class='flag-5'>實(shí)現(xiàn)</b>SPI<b class='flag-5'>驅(qū)動(dòng)</b>程序的說(shuō)明

    linux spi應(yīng)用層驅(qū)動(dòng)以及回環(huán)測(cè)試代碼

    linux spi應(yīng)用層驅(qū)動(dòng)以及回環(huán)測(cè)試代碼
    發(fā)表于 10-22 15:47 ?2次下載

    linux系統(tǒng)的驅(qū)動(dòng)實(shí)現(xiàn)原理

    原理就是將硬件操作的接口全都放到驅(qū)動(dòng)鏈表上,在驅(qū)動(dòng)實(shí)現(xiàn)device的open、read、write等操作。當(dāng)然這樣做也有弊端,就是驅(qū)動(dòng)fi
    發(fā)表于 11-02 09:59 ?1255次閱讀

    Linux的PWM驅(qū)動(dòng)框架及實(shí)現(xiàn)方法

    本文主要講述了Linux的PWM驅(qū)動(dòng)框架、實(shí)現(xiàn)方法、驅(qū)動(dòng)添加方法和調(diào)試方法。
    的頭像 發(fā)表于 05-14 15:24 ?2305次閱讀
    <b class='flag-5'>Linux</b>的PWM<b class='flag-5'>驅(qū)動(dòng)</b>框架及<b class='flag-5'>實(shí)現(xiàn)</b>方法

    Linux內(nèi)核代碼60%都是驅(qū)動(dòng)?

    為什么Linux內(nèi)核代碼60%都是驅(qū)動(dòng)? 如果每支持新的設(shè)備就加入驅(qū)動(dòng),內(nèi)核會(huì)不會(huì)變得越來(lái)越臃腫?
    的頭像 發(fā)表于 07-11 11:48 ?1655次閱讀
    <b class='flag-5'>Linux</b>內(nèi)核<b class='flag-5'>代碼</b>60%都是<b class='flag-5'>驅(qū)動(dòng)</b>?

    linux內(nèi)核中的debugfs該怎樣去使用呢?

    debugfs可用于內(nèi)核向用戶(hù)空間提供信息,debugfs是個(gè)小型的文件系統(tǒng),與/proc和sysfs不同,debugfs沒(méi)有較為嚴(yán)苛的規(guī)則和定義,我們可以在里面放置想要的任何信息,以便于系統(tǒng)開(kāi)發(fā)和調(diào)試。
    的頭像 發(fā)表于 08-21 09:01 ?5072次閱讀
    <b class='flag-5'>linux</b>內(nèi)核中的<b class='flag-5'>debugfs</b>該怎樣去使用呢?

    Linux驅(qū)動(dòng)函數(shù)接口說(shuō)明

    函數(shù)接口說(shuō)明 創(chuàng)建目錄、文件函數(shù): /* 創(chuàng)建目錄 */ struct dentry *debugfs_create_dir( const char *name, struct dentry
    的頭像 發(fā)表于 09-27 11:20 ?958次閱讀