LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-18-2007, 04:40 PM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,469

Rep: Reputation: 64
File serial numbers


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.
 
Old 07-19-2007, 09:47 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
UNIX file systems have an inode number, which is like a "serial number" I guess.
The number is unique only to a given file system.

NTFS does not have such a thing.
 
Old 07-19-2007, 06:03 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Code:
 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.

Last edited by jschiwal; 07-19-2007 at 06:10 PM.
 
Old 07-20-2007, 03:10 PM   #4
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,469

Original Poster
Rep: Reputation: 64
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.


Thanks for all the responses.
 
Old 07-20-2007, 04:57 PM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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.

Last edited by jschiwal; 07-20-2007 at 05:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File system magic numbers bgbranko Linux - General 5 09-23-2006 04:37 PM
[SOLVED] file locations and version numbers politik Linux - Newbie 2 08-21-2005 09:32 PM
numbers as file owners stabu Linux - General 3 04-27-2004 12:29 PM
Checking a file for numbers chrisk5527 Linux - General 1 09-12-2003 08:50 AM
file version numbers tjones11 Programming 2 03-15-2002 12:51 PM


All times are GMT -5. The time now is 04:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration