bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Resizing root partition


From: Yury Umanets
Subject: Re: Resizing root partition
Date: Tue, 05 Aug 2003 14:56:35 +0400

On Tue, 2003-08-05 at 14:52, Andrew Clausen wrote:
> On Tue, Aug 05, 2003 at 02:38:40PM +0400, Yury Umanets wrote:
> > Probably it is time to change the stuff for determining is partition is
> > mounted? If you agree I can try to fix it.
> 

> I've thought a bit about this.
> 
> Perhaps the best way to do this is:
> (1) for each entry in /etc/mtab and /proc/mounts, run stat().  Also,
> stat "/".
> (2) for the partition, figure out one of it's corresponding devices,
> and run stat() on it.
> 
> If anything from (1) matches with (2), then there it is mounted.
> 
> This deals with the case where /proc/mounts lists entries in a devfs
> form, and Parted is invoked in a traditional manner.
> 
> Sound good?
> 
> It also has the advantage of being very easy to implement :)

Yep :)


What do you thing about the following stuff:


/* Checking if specified partition is mounted. It is possible devfs is
used, and all devices are links like
hda1->ide/host0/bus0/target0/lun0/part1. Therefore
   we use stat function, rather than lstat: stat(2) follows links and
return
   stat information for link target. In this case it will return stat
info for
   /dev/ide/host0/bus0/target0/lun0/part1 file. Then we compare its
st_rdev
   field with st_rdev filed of every device from /proc/mounts. If match
occurs
   then we have device existing in /proc/mounts file, which is therefore
mounted
   at the moment.
 
   Also this function checks whether passed device mounted with
specified
   options.  Options string may look like "ro,noatime".
     
   We are using stating of every mount entry instead of just name
comparing,
   because file /proc/mounts may contain as devices like /dev/hda1 as
well ide/host0/bus0/targ... */

errno_t misc_dev_mounted(
        const char *name,       /* device name to be checked */
        const char *mode)       /* mount options for check */
{
        FILE *mnt;
        errno_t res;
        struct mntent *ent;
        struct stat giv_st;
        struct stat mnt_st;
        struct statfs fs_st;
 
        /* Stating given device */
        if ((res = stat(name, &giv_st)) == -1)
                return res;
  
        /* Procfs magic is 0x9fa0 */
        if (statfs("/proc", &fs_st) == -1 || fs_st.f_type != 0x9fa0) {
 
                /* Proc is not mounted, check if it is the root
partition */
                if ((res = stat("/", &mnt_st)) == -1)
                        return res;
  
                if (mnt_st.st_dev == giv_st.st_rdev)
                        return 1;
         
                return -EINVAL;
        }
     
        /* Going to check /proc/mounts */
        if (!(mnt = setmntent("/proc/mounts", "r")))
                return -EINVAL;
     
        while ((ent = getmntent(mnt))) {
                if (stat(ent->mnt_fsname, &mnt_st) == 0) {
                        if (mnt_st.st_rdev == giv_st.st_rdev) {
                                char *token;
                                                                                
               
                                while (mode && (token = aal_strsep((char
**)&mode, ","))) {
                                        if (!hasmntopt(ent, token))
                                                goto error_free_mnt;
                                }
                                                                                
               
                                endmntent(mnt);
                                return 1;
                        }
                }
        }
                                                                                
               
 error_free_mnt:
        endmntent(mnt);
        return 0;
}

What can be added? If /proc is not mounted, /etc/mtab may be inspected.
And root may be checked as you have already said.

> 
> Cheers,
> Andrew
-- 
We're flying high, we're watching the world passes by...





reply via email to

[Prev in Thread] Current Thread [Next in Thread]