SunSolve Internal

Infodoc ID   Synopsis   Date
15654   How to find the disk blocks used by a file   13 Jan 1998

Description Top

How do I find out what disk blocks are used by a particular file?

There are two ways to find out which disk blocks a file has.  The first is
to read the raw disk and read the information from the inode.  The second
is to open the file and read the file from the kernel.

The following describes an algorithm that could be used in a program
to read the information from the kernel.

1.  Open the file using open(2), get its file descriptor (fd)
2.  Use getpid(2) to get the process id the current process
3.  Use kvm_open(3K) to access the currently running kernel
4.  Use kvm_getproc(3K) to get the proc structure (defined in   
    /usr/include/sys/proc.h) for the current process 
5.  Use kvm_getu(3K) to get the user structure (defined in
    /usr/include/sys/user.h) for the current process
6.  Look at the u_flist field of the user structure to get the
    pointer to the list of open files (uf_entry strucure defined
    in /usr/include/sys/user.h)
7.  Using the file descriptor (fd) as an index into the array of
    file structures (defined in /usr/include/sys/file.h), look at
    the appropriate uf_ofile field of the uf_entry structure to
    locate the opened file
8.  Look at the f_vnode field of the file structure to get the 
    pointer to the vnode structure (defined in /usr/include/sys/vnode.h)
9.  Look at the v_data field of the vnode structure to get the
    address of the inode structure (defined in /usr/include/sys/fs/ufs_inode.h)
10. Look at the i_db and i_ib fields of the inode structure to get the pointer
    to the list of blocks for the opened file
11. Use kvm_close(3K) to close access to the currently running kernel
12. Use close(2) to close the file
 
You'll need to read through the man pages for the noted functions,
study the structure definitions in the noted header files, and write 
and test the utility.

SOLUTION SUMMARY:
Product Area Kernel
Product general
OS Solaris 2.x
Hardware any

Top

SunWeb Home SunWeb Search SunSolve Home Simple Search

Sun Proprietary/Confidential: Internal Use Only
Feedback to SunSolve Team