I want to know the mounted file system type on my linux box, I got one useful stuff called getmntent(); which returns me the struct mntent, which contains the required information.
check out the usage of getmntent().
First one has to use setmntent();
The setmntent() function opens the file system description file fp and returns a file pointer which can be used by getmntent().
Syntax: FILE *setmntent(const char *filename, const char *type);
Then call for getmntent(),
The getmntent() function reads the next line from the file system description file fp and returns a pointer to a structure containing the broken out fields from a line in the file. The pointer points to a static area of memory which is overwritten by subsequent calls to getmntent().
syntax: struct mntent *getmntent(FILE *fp);
/etc/mtab mounted file system description file
Here is simple c program which i tried on linux box running on ARM9 processor.
$ arm-linux-gcc disk1.c
I have connected two mass storage devices one of type FAt32 and one of type EXT3.
The output I got is
check out the usage of getmntent().
First one has to use setmntent();
The setmntent() function opens the file system description file fp and returns a file pointer which can be used by getmntent().
Syntax: FILE *setmntent(const char *filename, const char *type);
Then call for getmntent(),
The getmntent() function reads the next line from the file system description file fp and returns a pointer to a structure containing the broken out fields from a line in the file. The pointer points to a static area of memory which is overwritten by subsequent calls to getmntent().
syntax: struct mntent *getmntent(FILE *fp);
The mntent structure is defined in/etc/fstab file system description fileas follows:
struct mntent {
char *mnt_fsname; /* name of mounted file system */
char *mnt_dir; /* file system path prefix */
char *mnt_type; /* mount type (see mntent.h) */
char *mnt_opts; /* mount options (see mntent.h) */
int mnt_freq; /* dump frequency in days */
int mnt_passno; /* pass number on parallel fsck */
};
/etc/mtab mounted file system description file
Here is simple c program which i tried on linux box running on ARM9 processor.
#includecompile the program as
#include
#include
#include
#include
int main(void)
{
FILE *f = setmntent("/etc/mtab", "r");
struct mntent *m;
while ((m = getmntent(f))) {
struct stat st;
dev_t dev = 0;
if (stat(m->mnt_dir, &st) == 0) {
dev = st.st_dev;
}
printf("%s %s %s 0x%llx\n",
m->mnt_fsname, m->mnt_dir, m->mnt_type, (unsigned long long)dev);
}
endmntent(f);
return 0;
}
$ arm-linux-gcc disk1.c
I have connected two mass storage devices one of type FAt32 and one of type EXT3.
The output I got is
# ./a.outAny suggestions.
/dev/ram1 /rdisk0 minix 0x101
none /proc/bus/usb usbfs 0xb
/dev/ram1 /rdisk0 minix 0x101
none /proc/bus/usb usbfs 0xb
/dev/sda4 /mnt/WD_800BEVSExternal_575845373036343130393738_4 vfat 0x804
/dev/sda1 /mnt/WD_800BEVSExternal_575845373036343130393738_1 ext3 0x801
Comments