Tuesday, October 25, 2005

System Calls for Attributes

The title is a link to Dominic Giampaolo's book Practical File System Design with the Be File System. The attribute related part is in Chapter 5. From the book:

BFS stores the list of attributes associated with a file in an attribute directory (the attributes field of the bfs.inode structure). The directory is not part of the normal directory hierarchy but rather "hangs" on the side of the file. The named entries of the attribute directory point to the corresponding attribute value.
So each file has a hidden attributes directory and the attributes themselves are files in that directory. The file name is the attribute name and the file contents are the attribute's value. This allows the inode data structure to be reused. As an optimization, unused portions of inodes are used for small attributes (to limit the disk head from having to open other directories to get attribute information).

A program can perform the following system calls on attributes:

  • Open attribute directory
  • Read attribute directory
  • Rewind attribute directory
  • Close attribute directory
  • Stat attribute
  • Remove attribute
  • Read attribute
  • Write attribute
An example system call looks like:
ssize_t fs_read_attr(int fd, const char *attribute, uint32 type, off_t pos, void *buf, size_t count);
The file descriptor indicates which file to operate on, the attribute name indicates which attribute to do the I/O to, the type indicates the type of data being written (integer, double, string, etc.), and the position specifies the offset into the attribute to do the I/O at.

The exact system calls for the above are

  • DIR *fs_open_attr_dir(char *path);
  • struct dirent *fs_read_attr_dir(DIR *dirp);
  • int fs_rewind_attr_dir(DIR *dirp);
  • int fs_close_attr_dir(DIR *dirp);
  • int fs_stat_attr(int fd, char *name, struct attr_info *info);
  • int fs_remove_attr(int fd, char *name);
  • ssize_t fs_read_attr(int fd, char *name, uint32 type, off_t pos, void *buffer, size_t count);
  • ssize_t fs_write_attr(int fd, char *name, uint32 type, off_t pos, void *buffer, size_t count);
Note the API style for the last four calls: both the file descriptor of the file that the attribute is associated with and the name of the attribute are required. Making attributes into full-fledged file descriptors would have made removing files considerably more complex, so attributes are not treated as file descriptors in their own right.

No comments: