Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #916 > unrolled thread
| Started by | JimR <NotReallyMyEmail@example.net> |
|---|---|
| First post | 2011-04-26 13:06 -0400 |
| Last post | 2011-04-26 17:52 +0000 |
| Articles | 15 — 8 participants |
Back to article view | Back to comp.os.linux.misc
File real location JimR <NotReallyMyEmail@example.net> - 2011-04-26 13:06 -0400
Re: File real location Richard Kettlewell <rjk@greenend.org.uk> - 2011-04-26 18:24 +0100
Re: File real location The Natural Philosopher <tnp@invalid.invalid> - 2011-04-26 18:28 +0100
Re: File real location notbob <notbob@notbob.invalid> - 2011-04-26 18:08 +0000
Re: File real location Richard Kettlewell <rjk@greenend.org.uk> - 2011-04-26 19:14 +0100
Re: File real location Tim Watts <tw@dionic.net> - 2011-04-26 19:25 +0100
Re: File real location unruh <unruh@wormhole.physics.ubc.ca> - 2011-04-26 18:43 +0000
Re: File real location Chris Davies <chris-usenet@roaima.co.uk> - 2011-04-27 16:31 +0100
Re: File real location Tim Watts <tw@dionic.net> - 2011-04-26 19:08 +0100
Re: File real location JimR <NotReallyMyEmail@example.net> - 2011-04-26 14:43 -0400
Re: File real location Richard Kettlewell <rjk@greenend.org.uk> - 2011-04-26 20:28 +0100
Re: File real location JimR <NotReallyMyEmail@example.net> - 2011-04-26 17:00 -0400
Re: File real location The Natural Philosopher <tnp@invalid.invalid> - 2011-04-26 18:27 +0100
Re: File real location "Chris F.A. Johnson" <cfajohnson@gmail.com> - 2011-04-26 13:44 -0400
Re: File real location unruh <unruh@wormhole.physics.ubc.ca> - 2011-04-26 17:52 +0000
| From | JimR <NotReallyMyEmail@example.net> |
|---|---|
| Date | 2011-04-26 13:06 -0400 |
| Subject | File real location |
| Message-ID | <pkaj88-cg8.ln1@myleafnode.oneyv.org> |
This applies to Unix as well as Linux, but has been bugging me for awhile. Supposed I have a filesystem that is optionally mounted. Let's says the mount point is /foo Now I create a file on it, let's call it bar. Now I have /foo/bar In an alternative case, the filesystem is not mounted. I can still create a file bar in the directory foo, but it will fall onto the default filesystem (likely root filesystem). How can I tell the difference between these 2 files, i.e., on which filesystem did the file land? Thanks, JimR
[toc] | [next] | [standalone]
| From | Richard Kettlewell <rjk@greenend.org.uk> |
|---|---|
| Date | 2011-04-26 18:24 +0100 |
| Message-ID | <87pqo9apss.fsf@araminta.anjou.terraraq.org.uk> |
| In reply to | #916 |
JimR <NotReallyMyEmail@example.net> writes: > This applies to Unix as well as Linux, but has been bugging me for awhile. > > Supposed I have a filesystem that is optionally mounted. Let's says > the mount point is > /foo > > Now I create a file on it, let's call it bar. Now I have > /foo/bar > > In an alternative case, the filesystem is not mounted. I can still > create a file bar in the directory foo, but it will fall onto the > default filesystem (likely root filesystem). > > How can I tell the difference between these 2 files, i.e., on which > filesystem did the file land? stat() it and look at st_dev. -- http://www.greenend.org.uk/rjk/
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2011-04-26 18:28 +0100 |
| Message-ID | <ip6vck$hod$2@news.albasani.net> |
| In reply to | #918 |
Richard Kettlewell wrote: > JimR <NotReallyMyEmail@example.net> writes: > >> This applies to Unix as well as Linux, but has been bugging me for awhile. >> >> Supposed I have a filesystem that is optionally mounted. Let's says >> the mount point is >> /foo >> >> Now I create a file on it, let's call it bar. Now I have >> /foo/bar >> >> In an alternative case, the filesystem is not mounted. I can still >> create a file bar in the directory foo, but it will fall onto the >> default filesystem (likely root filesystem). >> >> How can I tell the difference between these 2 files, i.e., on which >> filesystem did the file land? > > stat() it and look at st_dev. > I bow to a superior solution...
[toc] | [prev] | [next] | [standalone]
| From | notbob <notbob@notbob.invalid> |
|---|---|
| Date | 2011-04-26 18:08 +0000 |
| Message-ID | <91og0jFfucU15@mid.individual.net> |
| In reply to | #920 |
On 2011-04-26, The Natural Philosopher <tnp@invalid.invalid> wrote: > Richard Kettlewell wrote: >> JimR <NotReallyMyEmail@example.net> writes: >>> Now I create a file on it, let's call it bar. Now I have >>> /foo/bar >>> >>> In an alternative case, the filesystem is not mounted. I can still >>> create a file bar in the directory foo, but it will fall onto the >>> default filesystem (likely root filesystem). >>> >>> How can I tell the difference between these 2 files, i.e., on which >>> filesystem did the file land? >> >> stat() it and look at st_dev. >> > I bow to a superior solution... Ummm.... let's back up a bit. Nevermind I haven't a clue what stat() and st_dev are. If a "filesystem is not mounted", how could there be any root (/) dir? If the dir foo has not been mounted how can one put a file into a dir that doesn't exist ...in a filesystem that hasn't been mounted? Is there some editor ....cat, vi, emacs... that will create a filesystem and dir if a nonexistent dir/file is specified and doesn't exist? nb --confused
[toc] | [prev] | [next] | [standalone]
| From | Richard Kettlewell <rjk@greenend.org.uk> |
|---|---|
| Date | 2011-04-26 19:14 +0100 |
| Message-ID | <878vuwc221.fsf@araminta.anjou.terraraq.org.uk> |
| In reply to | #925 |
notbob <notbob@notbob.invalid> writes: > On 2011-04-26, The Natural Philosopher <tnp@invalid.invalid> wrote: >> Richard Kettlewell wrote: >>> JimR <NotReallyMyEmail@example.net> writes: >>>> Now I create a file on it, let's call it bar. Now I have >>>> /foo/bar >>>> >>>> In an alternative case, the filesystem is not mounted. I can still >>>> create a file bar in the directory foo, but it will fall onto the >>>> default filesystem (likely root filesystem). >>>> >>>> How can I tell the difference between these 2 files, i.e., on which >>>> filesystem did the file land? >>> >>> stat() it and look at st_dev. >>> >> I bow to a superior solution... > > Ummm.... let's back up a bit. Nevermind I haven't a clue what stat() > and st_dev are. If a "filesystem is not mounted", how could there be > any root (/) dir? If the dir foo has not been mounted how can one put > a file into a dir that doesn't exist ...in a filesystem that hasn't > been mounted? Is there some editor ....cat, vi, emacs... that will > create a filesystem and dir if a nonexistent dir/file is specified and > doesn't exist? Mount points are directories. If the filesystem usually mounted on /foo isn't mounted then the directory /foo nevertheless generally exists (on the root filesystem in this instance) and all the usual rules about putting files in it apply. -- http://www.greenend.org.uk/rjk/
[toc] | [prev] | [next] | [standalone]
| From | Tim Watts <tw@dionic.net> |
|---|---|
| Date | 2011-04-26 19:25 +0100 |
| Message-ID | <i9fj88-sdb.ln1@squidward.dionic.net> |
| In reply to | #925 |
notbob wrote: > On 2011-04-26, The Natural Philosopher <tnp@invalid.invalid> wrote: >> Richard Kettlewell wrote: >>> JimR <NotReallyMyEmail@example.net> writes: > >>>> Now I create a file on it, let's call it bar. Now I have >>>> /foo/bar >>>> >>>> In an alternative case, the filesystem is not mounted. I can still >>>> create a file bar in the directory foo, but it will fall onto the >>>> default filesystem (likely root filesystem). >>>> >>>> How can I tell the difference between these 2 files, i.e., on which >>>> filesystem did the file land? >>> >>> stat() it and look at st_dev. >>> >> I bow to a superior solution... > > > Ummm.... let's back up a bit. Nevermind I haven't a clue what stat() > and st_dev are. man -S2 stat returns a lot of what there is to know about a file/devicenode/other including size, timestamps, owner and st_dev which is the block device the file lives on. It doesn't matter for the question here what the actual st_dev numbers are - only whether they are the same (same block device ie same disk/partition) or different. > If a "filesystem is not mounted", how could there be > any root (/) dir? There's (almost) always at least one filesystem mounted and that is / (even if the mount is a fudge from a packed special file or embedded in the kernel). Every mount *must* happen on an existing directory - so if there is no filesystem mounted on /x/y/z/ and you stick a file in /x/y/z/ then the file lives in the filesystem that z/ is a member of which may or may not be the FS that / is from. If you mount another FS on /x/y/z/ and the stick a file in z/ then the file exists on the FS you just mounted there. > If the dir foo has not been mounted how can one put > a file into a dir that doesn't exist ...in a filesystem that hasn't > been mounted? Is there some editor ....cat, vi, emacs... that will > create a filesystem and dir if a nonexistent dir/file is specified and > doesn't exist? Sometimes. There are tools that allow (v)fat/msdos filesystem devices to be manipulated without mounting. In principle you can manipulate any raw device to add a file to its contained FS if any - whether there was any point to anyone writing such a tool is another matter altogether. If you are hard core, you could use hexedit on any FS device - but you would have to intimately know the data structures involved such as free block/extent lists, directory structures, inode structures and more. HTH Tim -- Tim Watts
[toc] | [prev] | [next] | [standalone]
| From | unruh <unruh@wormhole.physics.ubc.ca> |
|---|---|
| Date | 2011-04-26 18:43 +0000 |
| Message-ID | <slrnire4jf.ca5.unruh@wormhole.physics.ubc.ca> |
| In reply to | #925 |
On 2011-04-26, notbob <notbob@notbob.invalid> wrote: > On 2011-04-26, The Natural Philosopher <tnp@invalid.invalid> wrote: >> Richard Kettlewell wrote: >>> JimR <NotReallyMyEmail@example.net> writes: > >>>> Now I create a file on it, let's call it bar. Now I have >>>> /foo/bar >>>> >>>> In an alternative case, the filesystem is not mounted. I can still >>>> create a file bar in the directory foo, but it will fall onto the >>>> default filesystem (likely root filesystem). >>>> >>>> How can I tell the difference between these 2 files, i.e., on which >>>> filesystem did the file land? >>> >>> stat() it and look at st_dev. >>> >> I bow to a superior solution... > > > Ummm.... let's back up a bit. Nevermind I haven't a clue what stat() > and st_dev are. If a "filesystem is not mounted", how could there be > any root (/) dir? If the dir foo has not been mounted how can one put > a file into a dir that doesn't exist ...in a filesystem that hasn't > been mounted? Is there some editor ....cat, vi, emacs... that will > create a filesystem and dir if a nonexistent dir/file is specified and > doesn't exist? A mountpoint of a filesystem is a directory on another filesystem, often the so called root filesystem (because it contains the /directory). If the system is running at all it has a / filesystem already mounted. Now in the OP case, that contains a directory called /foo. That is just a regular directory, but on top of that directory (hiding anything which happens to be already in that directory) can be mounted another filesystem. Thus, contents of /foo can exist both on the original / filesystem and on the new mounted filesystem. If the mounted filesystem is actually mounted, all original contents of /foo on the / filesystem are inaccessible and hidden, until the new mounted filesystem is unmounted. > > nb --confused
[toc] | [prev] | [next] | [standalone]
| From | Chris Davies <chris-usenet@roaima.co.uk> |
|---|---|
| Date | 2011-04-27 16:31 +0100 |
| Message-ID | <dgpl88xojo.ln2@news.roaima.co.uk> |
| In reply to | #925 |
notbob <notbob@notbob.invalid> wrote:
> and st_dev are. If a "filesystem is not mounted", how could there be
> any root (/) dir? If the dir foo has not been mounted how can one put
> a file into a dir that doesn't exist ...in a filesystem that hasn't
> been mounted?
$ df -h /mnt
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 464M 180M 261M 41% /
$ echo 'this is on root' > /mnt/foo
$ ls -l /mnt/foo
-rw-r--r-- 1 chris chris 16 Apr 27 16:26 /mnt/foo
$ sudo mount /dev/mapper/vg-mnt /mnt
$ df -h /mnt
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-mnt 1008M 34M 924M 4% /mnt
$ ls -l /mnt/foo
ls: cannot access /mnt/foo: No such file or directory
$ echo 'this is on mnt' > /mnt/foo
$ ls -l /mnt/foo
-rw-r--r-- 1 chris chris 15 Apr 27 16:28 /mnt/foo
$ cat /tmp/foo
this is on root
$ sudo umount /mnt
$ ls -l /mnt/foo
-rw-r--r-- 1 chris chris 16 Apr 27 16:26 /mnt/foo
$ cat /tmp/foo
this is on root
Chris
[toc] | [prev] | [next] | [standalone]
| From | Tim Watts <tw@dionic.net> |
|---|---|
| Date | 2011-04-26 19:08 +0100 |
| Message-ID | <k9ej88-kd6.ln1@squidward.dionic.net> |
| In reply to | #918 |
Richard Kettlewell wrote: > JimR <NotReallyMyEmail@example.net> writes: > >> This applies to Unix as well as Linux, but has been bugging me for >> awhile. >> >> Supposed I have a filesystem that is optionally mounted. Let's says >> the mount point is >> /foo >> >> Now I create a file on it, let's call it bar. Now I have >> /foo/bar >> >> In an alternative case, the filesystem is not mounted. I can still >> create a file bar in the directory foo, but it will fall onto the >> default filesystem (likely root filesystem). >> >> How can I tell the difference between these 2 files, i.e., on which >> filesystem did the file land? > > stat() it and look at st_dev. > Wot he said ^ -- Tim Watts
[toc] | [prev] | [next] | [standalone]
| From | JimR <NotReallyMyEmail@example.net> |
|---|---|
| Date | 2011-04-26 14:43 -0400 |
| Message-ID | <mbgj88-84f.ln1@myleafnode.oneyv.org> |
| In reply to | #918 |
On 04/26/2011 01:24 PM, Richard Kettlewell wrote:
{snip}
> stat() it and look at st_dev.
>
OK, did stat with and without -f. Got the results below. The device ID
is different in each case. How do I relate that number back to the
filesystem?
Thanks,
JimR
on mounted fs
stat /mnt/backups/me
File: `/mnt/backups/me'
Size: 0 Blocks: 0 IO Block: 4096 regular
empty file
Device: 806h/2054d Inode: 18 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-04-26 14:29:12.105661329 -0400
Modify: 2011-04-26 14:29:12.105661329 -0400
Change: 2011-04-26 14:29:12.105661329 -0400
===
on unmounted fs
stat /mnt/backups/me
File: `/mnt/backups/me'
Size: 0 Blocks: 0 IO Block: 4096 regular
empty file
Device: 808h/2056d Inode: 132711 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-04-26 14:27:06.083765346 -0400
Modify: 2011-04-26 14:27:06.083765346 -0400
Change: 2011-04-26 14:27:06.083765346 -0400
===
stat -f
on mounted
stat -f /mnt/backups/me
File: "/mnt/backups/me"
ID: a9599914aa7bb43c Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 36910968 Free: 24913212 Available: 23038230
Inodes: Total: 9379840 Free: 9379599
===
on umounted
stat -f /mnt/backups/me
File: "/mnt/backups/me"
ID: f2e3d0e7c6681d85 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 4921158 Free: 3560882 Available: 3310898
Inodes: Total: 1250928 Free: 1073436
[toc] | [prev] | [next] | [standalone]
| From | Richard Kettlewell <rjk@greenend.org.uk> |
|---|---|
| Date | 2011-04-26 20:28 +0100 |
| Message-ID | <87tydkizhe.fsf@araminta.anjou.terraraq.org.uk> |
| In reply to | #930 |
JimR <NotReallyMyEmail@example.net> writes: > Richard Kettlewell wrote: >> stat() it and look at st_dev. > > OK, did stat with and without -f. Got the results below. The device > ID is different in each case. How do I relate that number back to the > filesystem? You can find it in the 'ls -l' output for the physical device underlying the filesystem. For instance, 806h corresponds to 8, 6 (probably sda6); in the example below fe00h = fe, 00 = 254, 0. richard@araminta:~/src/rsbackup$ stat /etc/motd | grep Device Device: fe00h/65024d Inode: 301455 Links: 1 richard@araminta:~/src/rsbackup$ mount | grep 'on / ' /dev/mapper/araminta-root on / type ext3 (rw,noatime,errors=remount-ro) richard@araminta:~/src/rsbackup$ ls -lL /dev/mapper/araminta-root brw-rw---- 1 root disk 254, 0 Apr 4 18:57 /dev/mapper/araminta-root -- http://www.greenend.org.uk/rjk/
[toc] | [prev] | [next] | [standalone]
| From | JimR <NotReallyMyEmail@example.net> |
|---|---|
| Date | 2011-04-26 17:00 -0400 |
| Message-ID | <mcoj88-jbd.ln1@myleafnode.oneyv.org> |
| In reply to | #931 |
On 04/26/2011 03:28 PM, Richard Kettlewell wrote: > JimR<NotReallyMyEmail@example.net> writes: >> Richard Kettlewell wrote: > >>> stat() it and look at st_dev. >> >> OK, did stat with and without -f. Got the results below. The device >> ID is different in each case. How do I relate that number back to the >> filesystem? > > You can find it in the 'ls -l' output for the physical device underlying > the filesystem. For instance, 806h corresponds to 8, 6 (probably sda6); > in the example below fe00h = fe, 00 = 254, 0. > > richard@araminta:~/src/rsbackup$ stat /etc/motd | grep Device > Device: fe00h/65024d Inode: 301455 Links: 1 > richard@araminta:~/src/rsbackup$ mount | grep 'on / ' > /dev/mapper/araminta-root on / type ext3 (rw,noatime,errors=remount-ro) > richard@araminta:~/src/rsbackup$ ls -lL /dev/mapper/araminta-root > brw-rw---- 1 root disk 254, 0 Apr 4 18:57 /dev/mapper/araminta-root > Perfect, thanks for your help. JimR
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2011-04-26 18:27 +0100 |
| Message-ID | <ip6v9s$hod$1@news.albasani.net> |
| In reply to | #916 |
JimR wrote: > This applies to Unix as well as Linux, but has been bugging me for awhile. > > Supposed I have a filesystem that is optionally mounted. Let's says the > mount point is > /foo > > Now I create a file on it, let's call it bar. Now I have > /foo/bar > > In an alternative case, the filesystem is not mounted. I can still > create a file bar in the directory foo, but it will fall onto the > default filesystem (likely root filesystem). > > How can I tell the difference between these 2 files, i.e., on which > filesystem did the file land? > parse /etc/mtab? > Thanks, > JimR
[toc] | [prev] | [next] | [standalone]
| From | "Chris F.A. Johnson" <cfajohnson@gmail.com> |
|---|---|
| Date | 2011-04-26 13:44 -0400 |
| Message-ID | <cscj88-hbe.ln1@206-248-139-163.dsl.teksavvy.com> |
| In reply to | #916 |
On 2011-04-26, JimR wrote: > This applies to Unix as well as Linux, but has been bugging me for awhile. > > Supposed I have a filesystem that is optionally mounted. Let's says the > mount point is > /foo > > Now I create a file on it, let's call it bar. Now I have > /foo/bar > > In an alternative case, the filesystem is not mounted. I can still > create a file bar in the directory foo, but it will fall onto the > default filesystem (likely root filesystem). > > How can I tell the difference between these 2 files, i.e., on which > filesystem did the file land? df /foo/bar -- Chris F.A. Johnson, <http://cfajohnson.com> Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
[toc] | [prev] | [next] | [standalone]
| From | unruh <unruh@wormhole.physics.ubc.ca> |
|---|---|
| Date | 2011-04-26 17:52 +0000 |
| Message-ID | <slrnire1i5.5de.unruh@wormhole.physics.ubc.ca> |
| In reply to | #916 |
On 2011-04-26, JimR <NotReallyMyEmail@example.net> wrote: > This applies to Unix as well as Linux, but has been bugging me for awhile. > > Supposed I have a filesystem that is optionally mounted. Let's says the > mount point is > /foo > > Now I create a file on it, let's call it bar. Now I have > /foo/bar > > In an alternative case, the filesystem is not mounted. I can still > create a file bar in the directory foo, but it will fall onto the > default filesystem (likely root filesystem). > > How can I tell the difference between these 2 files, i.e., on which > filesystem did the file land? By looking to see if there was a filesystem mounted on the /foo directory. > > Thanks, > JimR
[toc] | [prev] | [standalone]
Back to top | Article view | comp.os.linux.misc
csiph-web