From: Patrick Mansfield Date: Sun, 22 Feb 2004 23:03:27 +0000 Subject: Re: [PATCH] udev - create all partitions of blockdevice Message-Id: <20040222150327.A2545@beaverton.ibm.com> List-Id: References: <20040216033452.GA3523@vrfy.org> In-Reply-To: <20040216033452.GA3523@vrfy.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org On Fri, Feb 20, 2004 at 04:47:00PM -0800, Greg KH wrote: > On Mon, Feb 16, 2004 at 06:25:35PM -0800, Patrick Mansfield wrote: > > Should we export the scsi 'removable' flag via sysfs attribute for > > use with all_partitions? Kernel patch is a trivial: > > > > Yes, this is a good idea. More general patch below. > Then we can just trigger off of this, right? Will this flag always be > correct, even for the very cheap flash readers on the market? Yes for the first question. And it should not matter for the second: If a device gets it wrong and says media is not removable, the user would have to manually recheck partitions - maybe by removing (via software or hardware) and adding the device or via fdisk. Then udev would get hotplugs for the partitions. So such borken devices will interact OK way with udev. > > So you could have rules such as: > > > > KERNEL="sd*", BUS="scsi", SYSFS{removable}="1", NAME{all_partitions}="%k" > > KERNEL="sd*", BUS="scsi", SYSFS{removable}="0", NAME="%k" > > > > AFAIUI CD-ROM never wants all_partitions even though they are marked > > removable. Tape is also removable. So, the KERNEL="sd*". > > Yeah, that would make sense. > > > Though it won't help for non-scsi (implies non-usb mass storage) media. > > Do you know of any? Old zip drives use scsi, right? What about floppy > drives? No, but I know less about linux and non-scsi removable media than the little I know about scsi removable media, though I'm learning. Here is a better patch to have the block layer export an attribute based on the gd->flags GENHD_FL_REMOVABLE. Then it can be used for all block devices. I'm not sure if non-ide floppy drivers set it. Jens or others need to OK this. But a simple udev rule will not stop hd cdrom's (and you can't use KERNEL="sd*" with this method), but st won't have the field. I ran with this patch: diff -uprN -X /home/patman/dontdiff base-2.6/drivers/block/genhd.c blk-attr-2.6/drivers/block/genhd.c --- base-2.6/drivers/block/genhd.c Fri Feb 20 07:36:56 2004 +++ blk-attr-2.6/drivers/block/genhd.c Sun Feb 22 13:55:48 2004 @@ -352,6 +352,12 @@ static ssize_t disk_range_read(struct ge { return sprintf(page, "%d\n", disk->minors); } +static ssize_t disk_removable_read(struct gendisk * disk, char *page) +{ + return sprintf(page, "%d\n", + (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0)); + +} static ssize_t disk_size_read(struct gendisk * disk, char *page) { return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk)); @@ -394,6 +400,10 @@ static struct disk_attribute disk_attr_r .attr = {.name = "range", .mode = S_IRUGO }, .show = disk_range_read }; +static struct disk_attribute disk_attr_removable = { + .attr = {.name = "removable", .mode = S_IRUGO }, + .show = disk_removable_read +}; static struct disk_attribute disk_attr_size = { .attr = {.name = "size", .mode = S_IRUGO }, .show = disk_size_read @@ -406,6 +416,7 @@ static struct disk_attribute disk_attr_s static struct attribute * default_attrs[] = { &disk_attr_dev.attr, &disk_attr_range.attr, + &disk_attr_removable.attr, &disk_attr_size.attr, &disk_attr_stat.attr, NULL, And then I see: [root@laptop root]# for i in /sys/block/*; do echo $i removable is $(cat $i/removable); done /sys/block/fd0 removable is 1 /sys/block/hda removable is 0 /sys/block/hdc removable is 1 /sys/block/sda removable is 1 hda is my boot/root disk. hdc my cd drive. For sda, both my fairly cheap dazzle xd card reader and my olympus c750 give the same result. (The ide floppy is the bay thing on my laptop, though it has a cd drive in it.) -- Patrick Mansfield ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id56&alloc_id438&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel