본문 바로가기

Programming/Linux_Platform

The result of getmntent() function

The example code

FILE* fp = setmntent("/proc/mounts", "r");

    if (fp == NULL) {

        ALOGE("Error opening /proc/mounts: %s", strerror(errno));

        return -errno;

    }


    // Some volumes can be stacked on each other, so force unmount in

    // reverse order to give us the best chance of success.

    std::list<std::string> toUnmount;

    mntent* mentry;

    while ((mentry = getmntent(fp)) != NULL) {

        if (strncmp(mentry->mnt_dir, path, path_len) == 0) {

            toUnmount.push_front(std::string(mentry->mnt_dir));

        }

    }

    endmntent(fp);



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 */

};





 # cat /proc/mounts | grep storage                          

/mnt/media_rw/F8BC-080E /storage/F8BC-080E sdcardfs rw,nosuid,nodev,noexec,noatime,low_uid=1023,low_gid=1023,gid=1015,mask=0006 0 0



mnt_fsname

 /mnt/media_rw/F8BC-080E

 mnt_dir

 /storage/emulated

 mnt_type

 sdcardfs

 mnt_opts

 rw,nosuid,nodev,noexec,noatime,low_uid=1023,low_gid=1023,gid=1015,mask=0006

 mnt_freq

 0

 mnt_passno 0