[Top][All Lists]

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

Re: unable to determine if part'ns mounted via /proc/mounts or /etc/mtab

From: Yury Umanets
Subject: Re: unable to determine if part'ns mounted via /proc/mounts or /etc/mtab
Date: Mon, 10 Feb 2003 11:23:59 +0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130

Andrew Clausen wrote:

Hi David,

On Thu, Feb 06, 2003 at 11:45:53PM -0800, David Emerson wrote:
I am trying to resize a windoze partition for my first installation of linux. (ok, I did specify the disk-filling partition myself, but I didn't know I was going to get into linux.) Using Parted 1.6.4 (I d/l'd two disk images, partboot and partroot, from gnu)

Oh, that's odd...

I encountered the error message that Andrew Clausen and Juan Pedro Vallejo were discussing here:


Warning: Unable to determine if partitions are mounted via
/proc/mounts or /etc/mtab.  Make sure you don't attempt to resize or
modify mounted file systems.  (Even read-only mounted)

Does "cat /proc/partitions" do anything reasonable?

Mark Stone advises in the unofficial Debian Install guide http://www.debian.org/releases/potato/installguide/ that "You may see some warning messages appear when running parted [...] In our experience, these warnings can safely be ignored." But I don't think he was referring to warnings that say "Make sure you don't attempt to resize..."

So, shall I go ahead and ignore the warning and resize the windoze partition? (yes, I have backed up my stuff but I don't have a windoze image :P )

Yes.  Think of this partition mount check as a safety catch...
it just means you'll have to make your own judgement without
any hints from Parted.


Bug-parted mailing list

Hi all,

I have a function for determining if a partition mounted with specified options or not in reiser4progs. Probably it can be adoppted to be used in parted too. I mean, that there might be used /dev/root device and probaly some hurd-specific way to determine is a partition mounted or not. See bellow for details.

In the case this function cannot be adopted for using in hurd, probably it may be used in linux only. Any way, I hope it will be useful for parted :)

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

Also we use /proc/mounts, not /etc/mtab because the using of /rtc/mtab is not reliable enough, as its updating may be turned off by using -n mount option.

int progs_dev_mounted(
       const char *name,       /* device name to be checked */
       const char *mode)       /* mount options for check */
       FILE *mnt;
       struct mntent *ent;
       struct stat giv_st;
       struct stat mnt_st;
       struct statfs fs_st;

       /* Stating given device */
       if (stat(name, &giv_st) == -1)
               return -1;

       /* 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 (stat("/", &mnt_st) == -1)
                       return -1;

               if (mnt_st.st_dev == giv_st.st_rdev)
                       return 1;

               return -1;

       /* Going to check /proc/mounts */
       if (!(mnt = setmntent("/proc/mounts", "r")))
               return -1;

       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 = strsep((char **)&mode, ","))) {
                                       if (!hasmntopt(ent, token))
                                               goto error_free_mnt;

                               return 1;

       return 0;

reply via email to

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