• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to find particular file in which partition of hard disk in linux?  RSS feed

 
Mandar Khire
Ranch Hand
Posts: 587
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to find out particular files details in Linux(Centos) by java program.
I create one text file & stored on Desktop.
Now i want to get info like at which partition of hard disk it stored?
at what block it used? exact location in terms of hdd internal?

I know few commands which show me hdd details like
df -l
fdisk -l
mount

but that not sufficient?
Any idea/clue/help?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But fdisk and mount won't show you the location of individual files; at best, fdisk will show the sizes of the partitions.
I don't know that you can actually get at the locations of file from the file tables.
 
Tim Holloway
Saloon Keeper
Posts: 18799
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Linux runs data management through multiple layers of abstractions, some of which are plug-replaceable. The absolute sector address of a particular byte in a particular file can be calculated, but unless you're writing a low-level disk utility, it's not usually worth the trouble.

For example:

the "df" command issued using the directory of the file will tell you what partition the file is located in. That may be a raw partition (/dev/sda1), an LVM Logical Volume (/dev/VolGroup0/LogVol00), or even a network share ("host1:/export/myfiles"), although in the case of a network share, you might was well give up right now.

For a raw partition, the classical next step would be to get the sector extent which used to be something that the fdisk utility could display, but the old partition tables are on their way out.

For LVM, a logical volume consists of one or more transparent blocks of sectors which may be moved around at need. You'd have to use the LVM utilities to get the logical and physical sector addresses, then get the extents of whatever raw partition the LVM Physical Volume was working out of. And that's not even counting the mapper, which also gets into the act.

Nor did I allow for how different filesystems map sectors, RAID, or other considerations.

Or how the disk hardware itself may remap things owing to stuff like badblock remapping.

Virtually none of the services that you need to ferret out all this information is available to straight Java code, since it's extremely system-dependent and thus doesn't all under Java's "write once/run anywhere" constraints.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The closest thing I have used is Sigar, but it doesn't go go down to the metal like what you are looking for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!