* [PATCH] udev - create all partitions of blockdevice
@ 2004-02-16 3:34 Kay Sievers
2004-02-16 21:59 ` Greg KH
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Kay Sievers @ 2004-02-16 3:34 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]
Here is the first try to create all partitons of a blockdevice, since
removable media devices may need to acces the expected partition to
revalidate the media.
It uses the attribute syntax introduced with the last %s{file} patch.
I'm using this with my multi-slot-flash-card-reader:
SYSFS{model}="USB Storage-SMC ", NAME{all_partitions}="smartmedia"
SYSFS{model}="USB Storage-CFC ", NAME{all_partitions}="compactflash"
SYSFS{model}="USB Storage-MSC ", NAME{all_partitions}="memorystick"
SYSFS{model}="USB Storage-MMC ", NAME{all_partitions}="multimedia"
and I get:
tree /udev/
/udev/
|-- memorystick
|-- memorystick1
|-- memorystick10
|-- memorystick11
|-- memorystick12
|-- memorystick13
|-- memorystick14
|-- memorystick15
|-- memorystick2
|-- memorystick3
|-- memorystick4
|-- memorystick5
|-- memorystick6
|-- memorystick7
|-- memorystick8
|-- memorystick9
|-- multimedia
|-- multimedia1
|-- multimedia10
|-- multimedia11
|-- multimedia12
|-- multimedia13
|-- multimedia14
|-- multimedia15
|-- multimedia2
|-- multimedia3
|-- multimedia4
|-- multimedia5
|-- multimedia6
|-- multimedia7
|-- multimedia8
|-- multimedia9
...
If needed, we can make the number of partions to create
adjustable with the attribute?
thanks,
Kay
[-- Attachment #2: 03-create-all-partitons.patch --]
[-- Type: text/plain, Size: 7761 bytes --]
diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c Mon Feb 16 04:17:27 2004
+++ b/namedev.c Mon Feb 16 04:17:27 2004
@@ -820,7 +820,7 @@
/* substitute placeholder */
apply_format(udev, udev->name, class_dev, sysfs_device);
apply_format(udev, udev->symlink, class_dev, sysfs_device);
-
+ udev->partitions = dev->partitions;
done:
perm = find_perm(udev->name);
if (perm) {
diff -Nru a/namedev.h b/namedev.h
--- a/namedev.h Mon Feb 16 04:17:27 2004
+++ b/namedev.h Mon Feb 16 04:17:27 2004
@@ -28,25 +28,29 @@
struct sysfs_class_device;
-#define BUS_SIZE 30
-#define FILE_SIZE 50
-#define VALUE_SIZE 100
-#define ID_SIZE 50
-#define PLACE_SIZE 50
-#define PROGRAM_SIZE 100
-
-#define FIELD_BUS "BUS"
-#define FIELD_SYSFS "SYSFS"
-#define FIELD_ID "ID"
-#define FIELD_PLACE "PLACE"
-#define FIELD_PROGRAM "PROGRAM"
-#define FIELD_RESULT "RESULT"
-#define FIELD_KERNEL "KERNEL"
-#define FIELD_NAME "NAME"
-#define FIELD_SYMLINK "SYMLINK"
+#define BUS_SIZE 30
+#define FILE_SIZE 50
+#define VALUE_SIZE 100
+#define ID_SIZE 50
+#define PLACE_SIZE 50
+#define PROGRAM_SIZE 100
-#define PROGRAM_MAXARG 10
-#define MAX_SYSFS_PAIRS 5
+#define FIELD_BUS "BUS"
+#define FIELD_SYSFS "SYSFS"
+#define FIELD_ID "ID"
+#define FIELD_PLACE "PLACE"
+#define FIELD_PROGRAM "PROGRAM"
+#define FIELD_RESULT "RESULT"
+#define FIELD_KERNEL "KERNEL"
+#define FIELD_NAME "NAME"
+#define FIELD_SYMLINK "SYMLINK"
+
+#define ATTR_PARTITIONS "all_partitions"
+#define PARTITIONS_COUNT 15
+
+
+#define PROGRAM_MAXARG 10
+#define MAX_SYSFS_PAIRS 5
struct sysfs_pair {
char file[FILE_SIZE];
@@ -65,6 +69,7 @@
char name[NAME_SIZE];
char symlink[NAME_SIZE];
struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
+ int partitions;
int config_line;
};
diff -Nru a/namedev_parse.c b/namedev_parse.c
--- a/namedev_parse.c Mon Feb 16 04:17:27 2004
+++ b/namedev_parse.c Mon Feb 16 04:17:27 2004
@@ -91,13 +91,6 @@
char *pos;
char *attr;
- attr = strchr(str, '_');
- if (attr != NULL) {
- attr++;
- dbg("attribute='%s'", attr);
- return attr;
- }
-
attr = strchr(str, '{');
if (attr != NULL) {
attr++;
@@ -111,6 +104,13 @@
return attr;
}
+ attr = strchr(str, '_');
+ if (attr != NULL) {
+ attr++;
+ dbg("attribute='%s'", attr);
+ return attr;
+ }
+
return NULL;
}
@@ -221,7 +221,13 @@
continue;
}
- if (strcasecmp(temp2, FIELD_NAME) == 0) {
+ if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) {
+ attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1);
+ if (attr != NULL)
+ if (strcasecmp(attr, ATTR_PARTITIONS) == 0) {
+ dbg_parse("creation of partition nodes requested");
+ dev.partitions = PARTITIONS_COUNT;
+ }
strfieldcpy(dev.name, temp3);
continue;
}
diff -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl Mon Feb 16 04:17:27 2004
+++ b/test/udev-test.pl Mon Feb 16 04:17:27 2004
@@ -350,7 +350,16 @@
EOF
},
{
- desc => "sysfs parent heirachy",
+ desc => "create all possible partitions",
+ subsys => "block",
+ devpath => "block/sda",
+ expected => "boot_disk15" ,
+ conf => <<EOF
+BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME{all_partitions}="boot_disk"
+EOF
+ },
+ {
+ desc => "sysfs parent hierarchy",
subsys => "tty",
devpath => "class/tty/ttyUSB0",
expected => "visor" ,
diff -Nru a/udev-add.c b/udev-add.c
--- a/udev-add.c Mon Feb 16 04:17:27 2004
+++ b/udev-add.c Mon Feb 16 04:17:27 2004
@@ -99,11 +99,44 @@
return 0;
}
+static int make_node(char *filename, int major, int minor, unsigned int mode, uid_t uid, gid_t gid)
+{
+ int retval;
+
+ retval = mknod(filename, mode, makedev(major, minor));
+ if (retval != 0) {
+ dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
+ filename, mode, major, minor, strerror(errno));
+ return retval;
+ }
+
+ dbg("chmod(%s, %#o)", filename, mode);
+ retval = chmod(filename, mode);
+ if (retval != 0) {
+ dbg("chmod(%s, %#o) failed with error '%s'",
+ filename, mode, strerror(errno));
+ return retval;
+ }
+
+ if (uid != 0 || gid != 0) {
+ dbg("chown(%s, %u, %u)", filename, uid, gid);
+ retval = chown(filename, uid, gid);
+ if (retval != 0) {
+ dbg("chown(%s, %u, %u) failed with error '%s'",
+ filename, uid, gid, strerror(errno));
+ return retval;
+ }
+ }
+
+ return 0;
+}
+
static int create_node(struct udevice *dev, int fake)
{
struct stat stats;
char filename[255];
char linktarget[255];
+ char partitionname[255];
char *linkname;
char *symlinks;
int retval = 0;
@@ -135,23 +168,6 @@
if (strrchr(dev->name, '/'))
create_path(filename);
- info("creating device node '%s'", filename);
- dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
- if (!fake) {
- retval = mknod(filename, dev->mode, makedev(dev->major, dev->minor));
- if (retval != 0)
- dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
- filename, dev->mode, dev->major, dev->minor, strerror(errno));
- }
-
- dbg("chmod(%s, %#o)", filename, dev->mode);
- if (!fake) {
- retval = chmod(filename, dev->mode);
- if (retval != 0)
- dbg("chmod(%s, %#o) failed with error '%s'",
- filename, dev->mode, strerror(errno));
- }
-
if (dev->owner[0] != '\0') {
char *endptr;
unsigned long id = strtoul(dev->owner, &endptr, 10);
@@ -180,12 +196,18 @@
}
}
- if (uid != 0 || gid != 0) {
- dbg("chown(%s, %u, %u)", filename, uid, gid);
- retval = chown(filename, uid, gid);
- if (retval != 0)
- dbg("chown(%s, %u, %u) failed with error '%s'",
- filename, uid, gid, strerror(errno));
+ if (!fake)
+ info("creating device node '%s'", filename);
+ make_node(filename, dev->major, dev->minor, dev->mode, uid, gid);
+
+ /* create partitions if requested */
+ if (dev->partitions > 0) {
+ info("creating device partition nodes '%s[1-%i]'", filename, dev->partitions);
+ for (i = 1; i <= dev->partitions; i++) {
+ sprintf(partitionname, "%s%i", filename, i);
+ make_node(partitionname, dev->major, dev->minor + i,
+ dev->mode, uid, gid);
+ }
}
/* create symlink if requested */
@@ -222,8 +244,7 @@
strcpy(linktarget, "./");
strcat(linktarget, &dev->name[tail]);
- /* unlink existing non-directories to ensure that our symlink
- * is created */
+ /* unlink existing files to ensure that our symlink is created */
if (!fake && (lstat(filename, &stats) == 0)) {
if ((stats.st_mode & S_IFMT) != S_IFDIR) {
if (unlink(filename))
diff -Nru a/udev-remove.c b/udev-remove.c
--- a/udev-remove.c Mon Feb 16 04:17:27 2004
+++ b/udev-remove.c Mon Feb 16 04:17:27 2004
@@ -66,9 +66,11 @@
static int delete_node(struct udevice *dev)
{
char filename[255];
+ char partitionname[255];
char *symlinks;
char *linkname;
int retval;
+ int i;
strncpy(filename, udev_root, sizeof(filename));
strncat(filename, dev->name, sizeof(filename));
@@ -81,11 +83,20 @@
return retval;
}
+ /* remove partition nodes */
+ if (dev->partitions > 0) {
+ info("removing partitions '%s[1-%i]'", filename, dev->partitions);
+ for (i = 1; i <= dev->partitions; i++) {
+ sprintf(partitionname, "%s%i", filename, i);
+ unlink(partitionname);
+ }
+ }
+
/* remove subdirectories */
if (strchr(dev->name, '/'))
delete_path(filename);
- if (*dev->symlink) {
+ if (dev->symlink[0] != '\0') {
symlinks = dev->symlink;
while (1) {
linkname = strsep(&symlinks, " ");
diff -Nru a/udev.h b/udev.h
--- a/udev.h Mon Feb 16 04:17:27 2004
+++ b/udev.h Mon Feb 16 04:17:27 2004
@@ -46,6 +46,7 @@
int minor;
unsigned int mode; /* not mode_t due to conflicting definitions in different libcs */
char symlink[NAME_SIZE];
+ int partitions;
/* private data that help us in building strings */
char bus_id[SYSFS_NAME_LEN];
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] udev - create all partitions of blockdevice
2004-02-16 3:34 [PATCH] udev - create all partitions of blockdevice Kay Sievers
@ 2004-02-16 21:59 ` Greg KH
2004-02-17 2:25 ` Patrick Mansfield
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2004-02-16 21:59 UTC (permalink / raw)
To: linux-hotplug
On Mon, Feb 16, 2004 at 04:34:52AM +0100, Kay Sievers wrote:
> Here is the first try to create all partitons of a blockdevice, since
> removable media devices may need to acces the expected partition to
> revalidate the media.
>
> It uses the attribute syntax introduced with the last %s{file} patch.
> I'm using this with my multi-slot-flash-card-reader:
>
> SYSFS{model}="USB Storage-SMC ", NAME{all_partitions}="smartmedia"
> SYSFS{model}="USB Storage-CFC ", NAME{all_partitions}="compactflash"
> SYSFS{model}="USB Storage-MSC ", NAME{all_partitions}="memorystick"
> SYSFS{model}="USB Storage-MMC ", NAME{all_partitions}="multimedia"
>
> and I get:
>
> tree /udev/
> /udev/
> |-- memorystick
> |-- memorystick1
> |-- memorystick10
> |-- memorystick11
> |-- memorystick12
> |-- memorystick13
> |-- memorystick14
> |-- memorystick15
> |-- memorystick2
> |-- memorystick3
> |-- memorystick4
> |-- memorystick5
> |-- memorystick6
> |-- memorystick7
> |-- memorystick8
> |-- memorystick9
> |-- multimedia
> |-- multimedia1
> |-- multimedia10
> |-- multimedia11
> |-- multimedia12
> |-- multimedia13
> |-- multimedia14
> |-- multimedia15
> |-- multimedia2
> |-- multimedia3
> |-- multimedia4
> |-- multimedia5
> |-- multimedia6
> |-- multimedia7
> |-- multimedia8
> |-- multimedia9
> ...
>
>
> If needed, we can make the number of partions to create
> adjustable with the attribute?
Nice, this is great. I don't think we need to change the number of
partitions.
I've applied this, and checked in a fix for udev-add.c if 'fake' was
true (which it is for udevtest). I'll go test this for my devices with
partitions.
thanks,
greg k-h
-------------------------------------------------------
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_id\x1356&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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] udev - create all partitions of blockdevice
2004-02-16 3:34 [PATCH] udev - create all partitions of blockdevice Kay Sievers
2004-02-16 21:59 ` Greg KH
@ 2004-02-17 2:25 ` Patrick Mansfield
2004-02-21 0:47 ` Greg KH
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Patrick Mansfield @ 2004-02-17 2:25 UTC (permalink / raw)
To: linux-hotplug
On Mon, Feb 16, 2004 at 01:59:27PM -0800, Greg KH wrote:
> On Mon, Feb 16, 2004 at 04:34:52AM +0100, Kay Sievers wrote:
> > Here is the first try to create all partitons of a blockdevice, since
> > removable media devices may need to acces the expected partition to
> > revalidate the media.
> >
> > It uses the attribute syntax introduced with the last %s{file} patch.
> > I'm using this with my multi-slot-flash-card-reader:
> >
> > SYSFS{model}="USB Storage-SMC ", NAME{all_partitions}="smartmedia"
> > SYSFS{model}="USB Storage-CFC ", NAME{all_partitions}="compactflash"
> > SYSFS{model}="USB Storage-MSC ", NAME{all_partitions}="memorystick"
> > SYSFS{model}="USB Storage-MMC ", NAME{all_partitions}="multimedia"
> > If needed, we can make the number of partions to create
> > adjustable with the attribute?
>
> Nice, this is great. I don't think we need to change the number of
> partitions.
>
> I've applied this, and checked in a fix for udev-add.c if 'fake' was
> true (which it is for udevtest). I'll go test this for my devices with
> partitions.
Should we export the scsi 'removable' flag via sysfs attribute for
use with all_partitions? Kernel patch is a trivial:
=== drivers/scsi/scsi_sysfs.c 1.39 vs edited ==--- 1.39/drivers/scsi/scsi_sysfs.c Fri Jan 16 15:24:41 2004
+++ edited/drivers/scsi/scsi_sysfs.c Tue Feb 17 00:56:50 2004
@@ -266,6 +266,7 @@
sdev_rd_attr (model, "%.16s\n");
sdev_rd_attr (rev, "%.4s\n");
sdev_rw_attr_bit (online);
+sdev_rd_attr (removable, "%d\n");
static ssize_t
store_rescan_field (struct device *dev, const char *buf, size_t count)
@@ -295,6 +296,7 @@
&dev_attr_online,
&dev_attr_rescan,
&dev_attr_delete,
+ &dev_attr_removable,
NULL
};
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*".
Though it won't help for non-scsi (implies non-usb mass storage) media.
A global rule affecting all partitions or naming would be nice, so you
would not have to have a separate rule, but then like Kay's example rules
above, if you are specifically naming a device, you already know it is
removable, and can set all_partitions.
For example, you only need the first rule below, but if in some simliar
case, you required two rules, that is ugly:
SYSFS{model}="USB Storage-SMC ", SYSFS{removable}="1", NAME{all_partitions}="smartmedia"
SYSFS{model}="USB Storage-SMC ", SYSFS{removable}="0", NAME="smartmedia"
-- 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_id\x1356&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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] udev - create all partitions of blockdevice
2004-02-16 3:34 [PATCH] udev - create all partitions of blockdevice Kay Sievers
2004-02-16 21:59 ` Greg KH
2004-02-17 2:25 ` Patrick Mansfield
@ 2004-02-21 0:47 ` Greg KH
2004-02-22 23:03 ` Patrick Mansfield
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2004-02-21 0:47 UTC (permalink / raw)
To: linux-hotplug
On Mon, Feb 16, 2004 at 06:25:35PM -0800, Patrick Mansfield wrote:
> On Mon, Feb 16, 2004 at 01:59:27PM -0800, Greg KH wrote:
> > On Mon, Feb 16, 2004 at 04:34:52AM +0100, Kay Sievers wrote:
> > > Here is the first try to create all partitons of a blockdevice, since
> > > removable media devices may need to acces the expected partition to
> > > revalidate the media.
> > >
> > > It uses the attribute syntax introduced with the last %s{file} patch.
> > > I'm using this with my multi-slot-flash-card-reader:
> > >
> > > SYSFS{model}="USB Storage-SMC ", NAME{all_partitions}="smartmedia"
> > > SYSFS{model}="USB Storage-CFC ", NAME{all_partitions}="compactflash"
> > > SYSFS{model}="USB Storage-MSC ", NAME{all_partitions}="memorystick"
> > > SYSFS{model}="USB Storage-MMC ", NAME{all_partitions}="multimedia"
>
> > > If needed, we can make the number of partions to create
> > > adjustable with the attribute?
> >
> > Nice, this is great. I don't think we need to change the number of
> > partitions.
> >
> > I've applied this, and checked in a fix for udev-add.c if 'fake' was
> > true (which it is for udevtest). I'll go test this for my devices with
> > partitions.
>
> Should we export the scsi 'removable' flag via sysfs attribute for
> use with all_partitions? Kernel patch is a trivial:
<snip patch>
Yes, this is a good idea.
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?
> 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?
> A global rule affecting all partitions or naming would be nice, so you
> would not have to have a separate rule, but then like Kay's example rules
> above, if you are specifically naming a device, you already know it is
> removable, and can set all_partitions.
>
> For example, you only need the first rule below, but if in some simliar
> case, you required two rules, that is ugly:
>
> SYSFS{model}="USB Storage-SMC ", SYSFS{removable}="1", NAME{all_partitions}="smartmedia"
> SYSFS{model}="USB Storage-SMC ", SYSFS{removable}="0", NAME="smartmedia"
Yeah, it's cumbersome, I agree. Any one have any other ideas on how to
do this?
thanks,
greg k-h
-------------------------------------------------------
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_id\x1356&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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] udev - create all partitions of blockdevice
2004-02-16 3:34 [PATCH] udev - create all partitions of blockdevice Kay Sievers
` (2 preceding siblings ...)
2004-02-21 0:47 ` Greg KH
@ 2004-02-22 23:03 ` Patrick Mansfield
2004-03-07 14:01 ` Olaf Hering
2004-03-07 17:41 ` Olaf Hering
5 siblings, 0 replies; 7+ messages in thread
From: Patrick Mansfield @ 2004-02-22 23:03 UTC (permalink / raw)
To: linux-hotplug
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:
>
> <snip patch>
>
> 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_id\x1356&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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] udev - create all partitions of blockdevice
2004-02-16 3:34 [PATCH] udev - create all partitions of blockdevice Kay Sievers
` (3 preceding siblings ...)
2004-02-22 23:03 ` Patrick Mansfield
@ 2004-03-07 14:01 ` Olaf Hering
2004-03-07 17:41 ` Olaf Hering
5 siblings, 0 replies; 7+ messages in thread
From: Olaf Hering @ 2004-03-07 14:01 UTC (permalink / raw)
To: linux-hotplug
On Sun, Feb 22, Patrick Mansfield wrote:
> 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.)
This doesnt work for firewire at least.
/sys/block/hda removable is 0
/sys/block/hdb removable is 1
/sys/block/ram0 removable is 0
/sys/block/sda removable is 0
Can we mark all sbp2 and usb-storage devices as removeable somehow?
They can disappear at any time.
./drivers/usb/storage/isd200.c does modify the InquiryData as example.
--
USB is for mice, FireWire is for men!
sUse lINUX ag, n√úRNBERG
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&opÃk
_______________________________________________
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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] udev - create all partitions of blockdevice
2004-02-16 3:34 [PATCH] udev - create all partitions of blockdevice Kay Sievers
` (4 preceding siblings ...)
2004-03-07 14:01 ` Olaf Hering
@ 2004-03-07 17:41 ` Olaf Hering
5 siblings, 0 replies; 7+ messages in thread
From: Olaf Hering @ 2004-03-07 17:41 UTC (permalink / raw)
To: linux-hotplug
On Sun, Mar 07, Olaf Hering wrote:
> Can we mark all sbp2 and usb-storage devices as removeable somehow?
> They can disappear at any time.
ok, that doesnt really matter because it meant removeable media, not
device.
but, did anyone review that, can it go into the main kernel?
--
USB is for mice, FireWire is for men!
sUse lINUX ag, n√úRNBERG
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&opÃk
_______________________________________________
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-03-07 17:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-16 3:34 [PATCH] udev - create all partitions of blockdevice Kay Sievers
2004-02-16 21:59 ` Greg KH
2004-02-17 2:25 ` Patrick Mansfield
2004-02-21 0:47 ` Greg KH
2004-02-22 23:03 ` Patrick Mansfield
2004-03-07 14:01 ` Olaf Hering
2004-03-07 17:41 ` Olaf Hering
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).