Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Representing a hierarchical file system |
| Date | 2011-08-16 04:00 -0700 |
| Organization | albasani.net |
| Message-ID | <j2ditp$c5e$1@news.albasani.net> (permalink) |
| References | <j2as5n$4gl$1@speranza.aioe.org> <chine.bleu-2A8469.10350815082011@news.eternal-september.org> <j2bm0p$14f$3@speranza.aioe.org> <pan.2011.08.16.10.45.24.199000@nowhere.com> |
On 8/16/2011 3:45 AM, Nobody wrote:
> On Mon, 15 Aug 2011 19:46:03 +0200, jacob navia wrote:
>
>> I would rather ignore links, and avoid anything Unix specific (or DOS
>> specific)
>>
>> Just a simple hierarchical representation with some attibutes like size
>> and time
>>
>> I would like it to be as portable as possible
>
> These are self-contradictory.
>
> If you /really/ ignore links then, on Unix, your filesystem will be empty;
> a Unix filesystem is nothing but links. A common Unix noob mistake is
> asking how to identify or distinguish a hard link (i.e. something created
> by link()) from a "real" file. This is a meaningless question; a hard link
> is just a directory entry; the links created by "ln" are no different to
> those created when the file itself was originally created with open() or
> creat().
>
> You can only create a "hierarchical representation" of a Unix filesystem
> by losing the distinction between a (hard) link and the file to which it
> refers, so you can't distinguish between N links to a single file and N
> distinct files. On the bright side, modern Unices don't normally allow
> creating hard links to directories, so you can't have cycles (assuming
> that you ignore the "." and ".." links).
>
> If you just discard symbolic links, many filenames will simply be invalid
> according to your representation, which is likely to impair its utility.
> OTOH, if you treat symbolic links as synonymous with the object to which
> they refer, not only will your representation not be hierarchical, it will
> probably be cyclic (if you actually manage to construct it without going
> into infinite recursion).
>
> [Actually, you can end up going into infinite recursion anyhow, if you try
> to traverse a directory tree without explicitly checking for loops, as
> directories can be renamed (i.e. moved) at any time.]
>
> If you want portability, you really have to support the key features of
> all of the target systems (i.e. the common superset, not the common
> subset). So e.g. if you want to support Unix, the data model has to
> support the concepts of hard and symbolic links. On Windows, these will
> still exist as concepts, but you just won't encounter any in practice.
>
note: on newer Windows one may actually encounter links, as Windows has
added them and does actually use them for some things.
how I would probably do things:
typedef struct DirEntry_s DirEntry;
typedef struct DirHead_s DirHead;
struct DirEntry_s
{
char *name;
DirHead *dir; //holds something if a directory
int64_t size; //file size
...
};
struct DirHead_s
{
DirEntry **ents; //directory entries
size_t n_files; //num files in directory
size_t m_files; //current max size of ents list
...
};
or, alternatively, use a linked list:
struct DirEntry_s
{
DirEntry *next;
char *name;
DirHead *dir; //holds something if a directory, NULL for file
int64_t size; //file size
...
};
struct DirHead_s
{
DirEntry *first; //directory entries
...
};
note that implementing a trivial file-system is not necessarily all that
much different (although, more common is to have space reserved for the
filename in-struct and use an endianess-agnostic means of representing
values, typically so that the dir-ents can map 1:1 with their on-disk
format, ... but all this is technically optional, and a more filesystem
agnostic means may have merits as well).
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
Representing a hierarchical file system jacob navia <jacob@spamsink.net> - 2011-08-15 12:24 +0200
Re: Representing a hierarchical file system Ian Collins <ian-news@hotmail.com> - 2011-08-15 22:36 +1200
Re: Representing a hierarchical file system jacob navia <jacob@spamsink.net> - 2011-08-15 19:43 +0200
Re: Representing a hierarchical file system Keith Thompson <kst-u@mib.org> - 2011-08-15 09:23 -0700
Re: Representing a hierarchical file system David Thompson <dave.thompson2@verizon.net> - 2011-08-21 03:22 -0400
Re: Representing a hierarchical file system Nobody <nobody@nowhere.com> - 2011-08-15 18:02 +0100
Re: Representing a hierarchical file system jacob navia <jacob@spamsink.net> - 2011-08-15 19:44 +0200
Re: Representing a hierarchical file system China Blue Tip Wrench <chine.bleu@yahoo.com> - 2011-08-15 10:35 -0700
Re: Representing a hierarchical file system jacob navia <jacob@spamsink.net> - 2011-08-15 19:46 +0200
Re: Representing a hierarchical file system "Heinrich Wolf" <invalid@invalid.invalid> - 2011-08-15 20:31 +0200
Re: Representing a hierarchical file system Ian Collins <ian-news@hotmail.com> - 2011-08-16 08:32 +1200
Re: Representing a hierarchical file system Nobody <nobody@nowhere.com> - 2011-08-16 11:45 +0100
Re: Representing a hierarchical file system BGB <cr88192@hotmail.com> - 2011-08-16 04:00 -0700
csiph-web