LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 12-03-2007, 05:35 AM   #1
Aymenov
LQ Newbie
 
Registered: Dec 2007
Posts: 2

Rep: Reputation: 0
How to recognize the file system used? (FAT32?)


Hello,

Is there a function that can tell us the type of file systm used?
In fact, I'm working on a program that does some treatments according to the file system partition. In particular, I need to know if a device (portable mp3 player for exemple) is a FAT32 partition?
How can do that by programming?

Thank you for your help
 
Old 12-03-2007, 07:32 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Dont know about any function but here is a possibile pseudo code.

If a file is available in a partition that is mounted as FAT32 - say, then the file must be in FAT32 format. So I would look for the full DIRNAME portion of the file name and see if it is in a mounted path.

End
 
Old 12-03-2007, 08:01 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
the mount command can show you the file system mounted.
 
Old 12-03-2007, 08:05 AM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
You mean a system call ? May be you can inspect the source code of the command file(1).
The command file with the flag "-s" can tell you what is the filesystem of a device.

Code:
[root@babylon5 ~]# file -s /dev/sda2
/dev/sda2: Linux rev 1.0 ext3 filesystem data (needs journal recovery)
[root@babylon5 ~]# file -s /dev/sdc1
/dev/sdc1: x86 boot sector, mkdosfs boot message display, code offset 0x3c, OEM-ID " mkdosfs", sectors/cluster 16, root entries 512, Media descriptor 0xf8, sectors/FAT 249, heads 32, sectors 1017824 (volumes > 32 MB) , serial number 0x4744ab1a, label: "disk512    ", FAT (16 bit)
[root@babylon5 ~]#
In the above example, /dev/sdc1 is a usb memory stick.
There is no need to mount the device to do that.

Last edited by marozsas; 12-03-2007 at 08:07 AM.
 
Old 12-03-2007, 09:25 AM   #5
Aymenov
LQ Newbie
 
Registered: Dec 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by marozsas View Post
You mean a system call ? May be you can inspect the source code of the command file(1).
The command file with the flag "-s" can tell you what is the filesystem of a device.

Code:
[root@babylon5 ~]# file -s /dev/sda2
/dev/sda2: Linux rev 1.0 ext3 filesystem data (needs journal recovery)
[root@babylon5 ~]# file -s /dev/sdc1
/dev/sdc1: x86 boot sector, mkdosfs boot message display, code offset 0x3c, OEM-ID " mkdosfs", sectors/cluster 16, root entries 512, Media descriptor 0xf8, sectors/FAT 249, heads 32, sectors 1017824 (volumes > 32 MB) , serial number 0x4744ab1a, label: "disk512    ", FAT (16 bit)
[root@babylon5 ~]#
In the above example, /dev/sdc1 is a usb memory stick.
There is no need to mount the device to do that.

Yes I think it is possible to use the cmd "file -s /dev/*".
I think that we can also use the getmntany routine:
int getmntany(FILE *fp, struct mnttab *mp, struct mnttab *mpref);
It searches the file referenced by fp until a match is found between a line in the file and mpref.
The mp (it is a structure) will contain useful information:
char *mnt_special; /* name of mounted resource */
char *mnt_mountp; /* mount point */
char *mnt_fstype; /* type of file system mounted */
char *mnt_mntopts; /* options for this mount */
char *mnt_time; /* time file system mounted */

But, I have another question. How can I get the name of the device? For example, how do you know that the line corresponding to the usb memory stick is /dev/sdc1? "sdc1" is the default name for usb memory stick?
The answer may be evident but I am beginner in Linux programmation.

Thank you for your help
 
Old 12-03-2007, 09:49 AM   #6
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
Quote:
But, I have another question. How can I get the name of the device?
I'm sorry, I am not a programmer.
From an user's point of view, I need to look at "/var/log/message" for messages like this:
Code:
Dec  3 13:35:06 babylon5 kernel: sd 9:0:0:0: [sdc] Attached SCSI removable disk
Dec  3 13:35:06 babylon5 kernel: sd 9:0:0:0: Attached scsi generic sg3 type 0
Dec  3 13:35:06 babylon5 hald: mounted /dev/sdc1 on behalf of uid 500
I believe the sub-system HAL can give you with the tools and functions to receive notifications when a device is plugged in/out or to browse the current devices(see "lshal").

Last edited by marozsas; 12-03-2007 at 09:51 AM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to access to FAT32 file system? cotne Fedora 4 09-01-2007 07:10 PM
fdisk and mount dont agree on file system type (fat32 vs. ntfs) schneidz Linux - Software 4 07-20-2006 11:17 AM
fat32 file system 100% safe with linux? vlatko Linux - Newbie 4 06-26-2006 01:14 AM
Browsing Win file system slow to recognize network deanbrown3d Linux - Newbie 2 08-17-2004 03:19 PM
How to format freespace to fat32 file system pyschomike15 Linux - General 4 07-20-2003 11:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:35 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration