Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Tim Watts Newsgroups: comp.os.linux.misc Subject: Re: File real location Followup-To: comp.os.linux.misc Date: Tue, 26 Apr 2011 19:25:22 +0100 Organization: A noiseless patient Spider Lines: 65 Message-ID: References: <87pqo9apss.fsf@araminta.anjou.terraraq.org.uk> <91og0jFfucU15@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Info: mx02.eternal-september.org; posting-host="6oIlEBqCjOm0MjsSUEk5CA"; logging-data="11320"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187LlNSGjnJJ0qxXbeZ1TAAURNtQZBNSN4=" User-Agent: KNode/4.4.6 Cancel-Lock: sha1:Uj0iU5Bhy0uD12MTtqvNbfVE87g= Xref: x330-a1.tempe.blueboxinc.net comp.os.linux.misc:928 notbob wrote: > On 2011-04-26, The Natural Philosopher wrote: >> Richard Kettlewell wrote: >>> JimR 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