Re: [PATCH] Btrfs-progs: detect if the disk we are formatting is a ssd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> +static int is_ssd(const char *file)
> +{
> +	char *dev = strrchr(file, '/');

 [ ... ]

> +	snprintf(path, PATH_MAX, "/sys/block/%s/queue/rotational", dev);
> +	fd = open(path, O_RDONLY);

Hmm, this doesn't seem right.  The last path component can have nothing
to do with the underlying device name.  And /sys/block doesn't have
entries for partition devices.

After some poking around (and hints from Eric), it looks like the thing
to do is stat the file to find that it's a block device and then use
blkid_devno_to_wholedisk().  That parses the link from
/sys/dev/block/$maj:$min to find the containing device.

Then it'll work for partitions and nutty udev vanity symlinks.

- z
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux