Skip to main content

Know Mounted File System Type getmntent() Usage

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);
The mntent structure is defined in as 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/fstab file system description file
/etc/mtab mounted file system description file

Here is simple c program which i tried on linux box running on ARM9 processor.
#include
#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;
}
compile the program as
$ 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.out
/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
Any suggestions.

Comments

Popular posts from this blog

Rajasthan Board 10th Results | rajedubord.nic.in | RBSE

Raj Board of Secondary Education, Rajasthan Results at rajeduboard.nic.in Board of Secondary Education, Rajasthan Ajmer declared result of secondary examination today at 4PM official site is rajedubord.nic.in check Secondary Examination- 2008 Result (To be announced on July 1st, 2008 at 4:00 PM) source http:// rajresults.nic.in / Declared result Praveshika Examination-2008 Result (Announced on June 25, 2008 at 4:00 PM) The history of the Board of Secondary Education Rajasthan (BSER) is a remarkable panorama of progressive record of the futurological vision for developing a dynamic system of various sub-systems of examinations and highlights of the academic excellence of the last four decades. The BSER took rapid strides for promotion and development of Secondary Education in Rajasthan, spread over 3,42,239 sq. km. and in more than 6000 schools located in 32 districts involving 8.5 lakhs students for Secondary and Senior Secondary Examination in the year 2000. At present the Board is

ahsec results 2008 | www.ahsec.nic.in

The official website of assam higher secondary education council Results of Assam is down seems they are uploading results , direct link to check ahsec results 2008 is http://resultsassam.nic.in/index.asp You can find results of AHSEC at the link above. current page The Website www.ahsec.nic.in Designed Developed & Hosted by NIC, Assam State Centre, Guwahati is down for result uploading. keep checking this page, I will update as soon as news comes. All the best to AHSEC - assam higher secondary education council students. Direct links http://assam.nic.in/ www.ahsec.nic.in http://resultsassam.nic.in/

Encyclopedia of Life - by the World's Leading Scientists

An epic effort to promote biodiversity and document all 1.8 million named species on the planet. When completed, http://www.eol.org will serve as a global biodiversity tool, providing scientists, policymakers, students, and citizens information they need to discover and protect the planet and encourage learning and conservation. The Encyclopedia of Life is a collaborative scientific effort led by the Field Museum of Natural History, Harvard University, Marine Biological Laboratory, Missouri Botanical Garden, Smithsonian Institution, and Biodiversity Heritage Library, a consortium including the core institutions and also the American Museum of Natural History (New York), Natural History Museum (London), New York Botanical Garden, and Royal Botanic Gardens (Kew). clipped from www.eol.org clipped from www.eol.org "Imagine an electronic page for each species of organism on Earth, available everywhere by single access on command." - Edward O. Wilson The Encyclopedia of Life (E