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.
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?
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.
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.
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.
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.
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").
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.