I'm optimizing an I/O intensive Linux program. So is there any way to know whether two given files/folders path are in same hard disk?
If, by "same physical harddisk" you mean same fileystem, then you can use the stat command to get the device ID:
$ stat -c '%D' filename
$ fd03
If the device IDs match, they're in the same filesystem.
To actually determine the physical disk the file is on, you'd have to know the filesystem in use (some filesystems can span multiple disks), and even the "device" itself may be mapped to more than one actual physical disk by a volume manager such as LVM or a RAID controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With