Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:48:41+00:00 2026-06-14T07:48:41+00:00

I have partition structure like : $ df Filesystem 1K-blocks Used Available Use% Mounted

  • 0

I have partition structure like :

$ df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda6       51606140 16939248  34142692  34% /
/dev/sda5         495844    72969    397275  16% /boot
/dev/sda7      113022648 57515608  49765728  50% /home
/dev/sda8     113022648 57515608  49765728  4% /mnt

while parsing directories content using readdir() – how to find out which file resides on what device?

readdir() invoked from root directory and parses the file name and prints its size.
like from device : /dev/sda6 and list the filenames under that partition.
When it reads contents from /home – it should display reading content from /dev/sda7 and list filenames

Please let me know,if you need more details/info

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:48:42+00:00Added an answer on June 14, 2026 at 7:48 am

    There is a st_dev member in struct stat, it should uniquely identify one partition.

    Example in bash:

    stat ~/.vimrc
      File: `/home2//leonard/.vimrc' -> `local-priv/vimrc'
      Size: 16              Blocks: 0          IO Block: 4096   symbolic link
    Device: 802h/2050d      Inode: 6818899     Links: 1
    Access: (0777/lrwxrwxrwx)  Uid: ( 1024/ leonard)   Gid: ( 1024/ leonard)
    Access: 2012-06-22 16:36:45.341371003 +0300
    Modify: 2012-06-22 16:36:45.341371003 +0300
    Change: 2012-06-22 16:36:45.341371003 +0300
    

    The stat utility does no additional magic. Here is strace -vvv output:

    lstat64("/home2//leonard/.vimrc", {st_dev=makedev(8, 2), st_ino=6818899, st_mode=S_IFLNK|0777, st_nlink=1, st_uid=1024, st_gid=1024, st_blksize=4096, st_blocks=0, st_size=16, st_atime=2012/06/22-16:36:45, st_mtime=2012/06/22-16:36:45, st_ctime=2012/06/22-16:36:45}) = 0
    

    0x0802 is major 8(sd) partition 2, so /dev/sda2

    In order to map this to actual partitions you can iterate /proc/mounts and stat all the devices (first column). The contents of /proc/mounts is just like the output of mount(1) except it comes directly from the kernel. Some distros symlink /etc/mtab to /proc/mounts.

    Or you can parse /proc/partitions:

    $ cat /proc/partitions
    major minor  #blocks  name
    
       8        0  976762584 sda
       8        1    3998720 sda1
       8        2  972762112 sda2
    

    Of course /dev/sda might not actually exist, the device could be using a long udev name like /dev/disk/by-uuid/c4181217-a753-4cf3-b61d-190ee3981a3f. Major/Minor numbers should be a reliable unique identifier of a partition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an extra NTFS partition to store data that I want to use
I have a data structure that looks like this: Model Place primary key id
I have a table structure, simplified like so: period_id int suite_id varchar(20) suite_status varchar(50)
I have a partition in Android that's not mounted because it doesn't have a
I have a list of items which I would like to partition into subsets.
Have a table with 3 million rows and would like to partition it. There
I have a linux box with a partition full, the partition being full is
I have those partitions (in Windows) for example: Hard Disk 1 - Partition C,
Let's say you have multiple directories that all exist on the same partition. Let's
I have a query: select event_type, department_name, effective_time, row_number() OVER (PARTITION BY event_type,department_name ORDER

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.