ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was learning about some of the functions in dirent.h and wrote this small program that prints out the contents of whatever directory you happen to be in and I was wondering why in NTFS I get a file serial number of 0. Does ntfs not use these or do I just not have permission to see the number?
This proram was compiled by mingw and run in windows xp.
Code:
#include<stdio.h>
#include<dirent.h>
#include<sys/types.h>
int main()
{
DIR *currentdir;
int count = 0;
struct dirent *fname = NULL;
currentdir = opendir(".");
while((fname = readdir(currentdir)))
{
printf("\n%-13s FileID:%li",fname->d_name,fname->d_ino);
count++;
}
closedir(currentdir);
printf("\nNumber of directy entries are %i.\n",count);
return 0;
}
Sample output
Code:
. FileID:0
.. FILeID:0
some.txt FileID:0
Number of directory entries are 3.
ls
Application Data ErrorLog.txt hs_err_pid804.log NetHood ntuser.ini Recent Start Menu WINDOWS
Cookies Favorites Local Settings NTUSER.DAT PrintHood RECYCLE Templates
Desktop gsview32.ini My Documents ntuser.dat.LOG PUTTY.RND SendTo UserData
jschiwal@hpamd64:/mnt/windows/Documents and Settings/jschiwal> dirsamp
. FileID:3961
.. FileID:2179
.dvdcss FileID:97129
Application Data FileID:4009
Cookies FileID:4008
Desktop FileID:4007
ErrorLog.txt FileID:36370
Favorites FileID:4004
gsview32.ini FileID:3837
This is your program run in a directory on my Windows XP / SuSE 10.2 duel boot installation. This was compiled and run on Linux. Your example was compiled and run in Cygwin. Cygwin uses the windows filesystem and networking rather than replacing it. Linux will have a VFS layer so that an NTFS filesystem looks more like a native filesystem to the kernel. In Linux and Unix, the inodes for files on a fat or ntfs filesystem will be in memory in the VFS layer rather then actually be stored on the filesystem.
My example was not compiled in Cygwin it was compiled using gcc ported over to windows called mingw.
It was run in windows xp not on a NTFS directory in Linux. Just came off as curious as I thought all file systems use serial numbers for identification. I suppose its system specific then.
mingw is Cygwin's gcc compiler. My point is that running cygwin, you are using Windows to read the directory. You are not running a Linux or Unix kernel. Linux & Unix filesystems use inodes. If you mount an NTFS filesystem in Linux, there is a Virtual File System layer, so that the NTFS filesystem looks like a Unix filesystem to the kernel.
The comments in the header for dirent's d_ino field refer to both "inode" and "FileID", so they are synonyms. I hadn't heard of FileID before.
You may want to compare the header files you are using with the one's that mingw uses. They may point out some differences in the comments.
If you will be writing C programs to be run in cygwin, you may need to depend a lot on sysconf and pathconf to determine the limits and capabilities. There are probably bound to be many differences.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.