Re: /proc/mounts, /dev/root

2000-03-19 Thread Andrew Clausen

"Patrick J. LoPresti" wrote:
 
 Try "cat /proc/sys/kernel/real-root-dev".  Convert to hex and maybe
 you will see something familiar.  Or maybe not :-).

This is exactly what I need!  Thanks!

Andrew Clausen



Re: /proc/mounts, /dev/root

2000-03-18 Thread Andrew Clausen

Tigran Aivazian wrote:
 
 if rdev is not there you copy it using cp(1) command.

I didn't explain myself very well.  Sorry.  I'll try
again...

I'm writing partition program, that needs to find out
if a partition is mounted.  Sometimes, /etc/mtab is
not available (eg / is mounted read-only).  Therefore,
I should check /proc/mounts first, if it's available.
But /proc/mounts has this /dev/root brain damage.  So
I need to find out what /dev/root really is.

I want to allow users to use Parted with chroot, because
this could be useful in a rescue situation.

Obviously, I can't force/recommend users use devfs.
Also, Parted will be run *after* any chroot, so copying
rdev is out of the question.

Anyone have any other suggestions?

Thanks,
Andrew Clausen



[patch-2.3.99-pre4] Re: /proc/mounts, /dev/root

2000-03-18 Thread Tigran Aivazian

 
 Hm. The chroot(2) call changes the apparent root to a directory. This
 isn't necessarily the root of a mounted FS. So /dev/root should stay 
 as the root filesystem.

I know - I thought that is all he wanted - perhaps I haven't read his
message carefully enough, i.e. current-fs-root-d_inode-i_dev 

 To get the apparent root, look at /proc/self/root instead.
   

I forgot about /proc/self/root :) (btw, shouldn't vfs_readlink() return   
EFAULT if copy_to_user() fails? It acts on userspace buffer and
readlink(2) manpage documents EFAULT if buffer is invalid, cc;d Linus to
confirm and if so, the patch is below)

Regards,
Tigran.
  

--- namei.c.0   Sat Mar 18 08:06:38 2000
+++ namei.c Sat Mar 18 08:07:08 2000
@@ -1506,7 +1506,8 @@
len = strlen(link);
if (len  buflen)
len = buflen;
-   copy_to_user(buffer, link, len);
+   if(copy_to_user(buffer, link, len))
+   return -EFAULT;
 out:
return len;
 }



Re: /proc/mounts, /dev/root

2000-03-18 Thread Guest section DW

On Fri, Mar 17, 2000 at 06:11:54PM +1100, Andrew Clausen wrote:

 I'm writing partition program, that needs to find out
 if a partition is mounted.  Sometimes, /etc/mtab is
 not available (eg / is mounted read-only).  Therefore,
 I should check /proc/mounts first, if it's available.
 But /proc/mounts has this /dev/root brain damage.  So
 I need to find out what /dev/root really is.

I think you should avoid both /etc/mtab and /proc/mounts.
Both are unreliable - /etc/mtab because it is just a file
and in principle can have arbitrary contents, and /proc/mounts
because /proc may not exist, and /dev/root is unresolved,
and spaces in names may make it impossible to parse /proc/mounts
uniquely, changes in names since things were mounted may make
it impossible to interpret a /proc/mounts line, etc.

Indeed, it is a bad idea in general to take some imprecise
output meant for human consumption only, and use that in a
program, except possibly as a vague heuristic to generate
a warning.

Why do you want to check whether a partition is mounted?
I can see two reasons:
(i) If a partition is in use then a subsequent BLKRRPART
will fail. This is worth a warning but is not catastrophic.
The new table will be used after a reboot or after
a command like "blockdev --rereadpt device".
(ii) The sectors describing logical partitions are scattered
all over the disk. If one of these overwrites a sector on
an active partition (mounted, or in use as swap) then
terrible things may happen.

My point of view is that (ii) is so serious that it does not
suffice to rely on the heuristic provided by looking at
/proc/mounts and /proc/swaps. Fortunately there is a very
easy way to get much more reliable information:
use the BLKPG_DEL_PARTITION ioctl.

Andries



Re: /proc/mounts, /dev/root

2000-03-17 Thread Andrew Clausen

Tigran Aivazian wrote:
 even if you chroot somewhere, rdev will still show the correct root:

What if rdev isn't on the chroot'ed root?  Also, does rdev need find
the kernel image, or does it ask the kernel?

Thanks!
Andrew Clausen



Re: /proc/mounts, /dev/root

2000-03-17 Thread Tigran Aivazian

if rdev is not there you copy it using cp(1) command.

On Fri, 17 Mar 2000, Andrew Clausen wrote:

 Tigran Aivazian wrote:
  even if you chroot somewhere, rdev will still show the correct root:
 
 What if rdev isn't on the chroot'ed root?  Also, does rdev need find
 the kernel image, or does it ask the kernel?
 
 Thanks!
 Andrew Clausen
 



Re: /proc/mounts, /dev/root

2000-03-17 Thread Jan-Benedict Glaw

On Fri, Mar 17, 2000 at 03:50:35AM +1100, Andrew Clausen wrote:
 Tigran Aivazian wrote:
  even if you chroot somewhere, rdev will still show the correct root:
 
 What if rdev isn't on the chroot'ed root?  Also, does rdev need find
 the kernel image, or does it ask the kernel?

You need to *have* rdev at all;) For Alpha it doesn't exist;(

MfG, JBG

-- 
Fehler eingestehen, Größe zeigen: Nehmt die Rechtschreibreform zurück!!!
keyID=0x8399E1BB fingerprint=250D 3BCF 7127 0D8C A444 A961 1DBD 5E75 8399 E1BB

 PGP signature


Re: /proc/mounts, /dev/root

2000-03-17 Thread Andrew Clausen

Tim Waugh wrote:
 
 On Fri, 17 Mar 2000, Andrew Clausen wrote:
 
   stat /
 
  Doesn't work with chroot :-(
 
 Can you mount proc?  stat /proc/1/cwd..?

Permission denied (even as root), for obvious reasons.

Andrew Clausen