Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1435279
  • 博文数量: 1334
  • 博客积分: 645
  • 博客等级: 上士
  • 技术积分: 5762
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-25 16:56
文章分类

全部博文(1334)

文章存档

2014年(108)

2013年(1059)

2012年(169)

分类: LINUX

2013-02-21 05:36:20

在新版本的内核中struct device 已经没有bus_id成员,取而代之的是通过dev_name和dev_set_name对设备的名字进行操作。

        dev_name和dev_set_name在2.6.35.6内核中的源代码如下:

        static inline const char *dev_name(const struct device *dev)
        {
                /* Use the init name until the kobject becomes available */
                if (dev->init_name)
                        return dev->init_name;

                return kobject_name(&dev->kobj);
        }

        extern int dev_set_name(struct device *dev, const char *name, ...)
                __attribute__((format(printf, 2, 3)));

 

 

kernel 邮件列表

中讲了:struct device - replace bus_id with dev_name(),以后只要使用dev->bus_id的时候,改成dev_name(dev)就可以了。




查看了kernel 邮件列表,有如下一段:

From: Linux Kernel Mailing List
Subject: block: struct device - replace bus_id with dev_name(), dev_set_name()
Date: Tuesday, January 6, 2009 - 7:02 pm

Gitweb: http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=3ada8b...

Commit: 3ada8b7e980dac7cc42937d42d90ee51b19204fe
Parent: 4383fc3d9a98759a1ec3c57a30781e95a4cfcfa9
Author: Kay Sievers <kay.sievers@vrfy.org>
AuthorDate: Tue Jan 6 10:44:43 2009 -0800
Committer: Greg Kroah-Hartman <gregkh@suse.de>
CommitDate: Tue Jan 6 10:44:43 2009 -0800

    block: struct device - replace bus_id with dev_name(), dev_set_name()
    
    Cc: Jens Axboe <jens.axboe@oracle.com>
    Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 block/bsg.c | 6 +++---
 block/genhd.c | 2 +-
 fs/partitions/check.c | 11 +++--------
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/block/bsg.c b/block/bsg.c
index e73e50d..d414bb5 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -42,7 +42,7 @@ struct bsg_device {
     int done_cmds;
     wait_queue_head_t wq_done;
     wait_queue_head_t wq_free;
-    char name[BUS_ID_SIZE];
+    char name[20];
     int max_queue;
     unsigned long flags;
 };
@@ -781,7 +781,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
     mutex_lock(&bsg_mutex);
     hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
 
-    strncpy(bd->name, rq->bsg_dev.class_dev->bus_id, sizeof(bd->name) - 1);
+    strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
     dprintk("bound to <%s>, max queue %d\n",
         format_dev_t(buf, inode->i_rdev), bd->max_queue);
 
@@ -992,7 +992,7 @@ int bsg_register_queue(struct request_queue *q, struct device *parent,
     if (name)
         devname = name;
     else
-        devname = parent->bus_id;
+        devname = dev_name(parent);
 
     /*
      * we need a proper transport to send commands, not a stacked device
diff --git a/block/genhd.c b/block/genhd.c
index d84a7df..397960c 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1084,7 +1084,7 @@ dev_t blk_lookup_devt(const char *name, int partno)
         struct gendisk *disk = dev_to_disk(dev);
         struct hd_struct *part;
 
-        if (strcmp(dev->bus_id, name))
+        if (strcmp(dev_name(dev), name))
             continue;
 
         part = disk_get_part(disk, partno);
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 6d5b213..5198ada 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -384,9 +384,9 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
 
     dname = dev_name(ddev);
     if (isdigit(dname[strlen(dname) - 1]))
-        snprintf(pdev->bus_id, BUS_ID_SIZE, "%sp%d", dname, partno);
+        dev_set_name(pdev, "%sp%d", dname, partno);
     else
-        snprintf(pdev->bus_id, BUS_ID_SIZE, "%s%d", dname, partno);
+        dev_set_name(pdev, "%s%d", dname, partno);
 
     device_initialize(pdev);
     pdev->class = &block_class;
@@ -447,16 +447,11 @@ void register_disk(struct gendisk *disk)
     struct block_device *bdev;
     struct disk_part_iter piter;
     struct hd_struct *part;
-    char *s;
     int err;
 
     ddev->parent = disk->driverfs_dev;
 
-    strlcpy(ddev->bus_id, disk->disk_name, BUS_ID_SIZE);
-    /* e some of these buggers have / in the name... */

-    s = strchr(ddev->bus_id, '/');
-    if (s)
-        *s = '!';
+    dev_set_name(ddev, disk->disk_name);
 
     /* delay uevents, until we scanned partition table */
     ddev->uevent_suppress = 1;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html


Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]


其中讲了:struct device - replace bus_id with dev_name()
阅读(583) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~