user666042
user666042

Reputation:

File System metaphor

I'm wondering how to rapresent the file system metaphor (ntfs is based on btree right?) inside a SQL database. Obviously data are stored as rows into tables and don't use the NTFS storing method; so, how NTFS (and other FS) logically works to rapresent the files/folders hierachy? Any advice or references?

Thanks for the support.

Upvotes: 1

Views: 125

Answers (1)

If you want to have some kind of database, stored in DBMS, simply build the table with the following fields:

  • ID
  • Parent ID
  • Name
  • Type (directory or file)
  • Modification date (creation date and last access date are optional)
  • Data (BLOB)

and that's it. ID/ParentID would let you build a hierarchy, and the rest is details.

Most filesystems have inverted structure of ID/ChildrenIDList instead of ID/ParentID but this is caused by specifics of filesystem design. If the filesystem is backed by some relational DBMS, then having a parent ID might be more optimal for lookup.

Upvotes: 1

Related Questions