Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teaching: labs: filesystems part 2: Add lab documentation #117

Conversation

valighita
Copy link

@valighita valighita commented Apr 16, 2019

Signed-off-by: Valentin Ghita [email protected]

tavip pushed a commit to linux-kernel-labs/linux-kernel-labs.github.io that referenced this pull request Apr 16, 2019
An inode uniquely identifies a file on disk and holds information about it (uid, gid, access rights, access times, pointers to data blocks, etc.).
An important aspect is that an inode does not have information about the file name (it is retained by the associated ``dentry`` structure).

The inode refers to a file on the disk. To refer an open file (associated with a file descriptor within a process), the :c:type:`struct file` structure is used.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency use "struct dentry" above as you do here

The inode structure
-------------------

The inode structure is the same for all file systems. In general, file systems also have particular information. These are referenced through the ``i_private`` field of the structure.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest replacing "particular" with "private"


Some of the important fields of :c:type:`struct inode` are:

* ``i_sb`` : The superblock structure of the file system to which the inode belongs to.
Copy link

@claudiughioc claudiughioc Apr 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the superblock structure of the file system the inode belongs to"


* ``i_size``: file/directory/etc. size in bytes
* ``i_mtime``, ``i_atime``, ``i_ctime``: change, access, and creation time
* ``i_nlink``: the number of names entries (dentries) that use this inode; for file systems without links (either hard or symbolic) is always set to 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the subject here, I suggest adding "this is always set to 1"

* ``i_size``: file/directory/etc. size in bytes
* ``i_mtime``, ``i_atime``, ``i_ctime``: change, access, and creation time
* ``i_nlink``: the number of names entries (dentries) that use this inode; for file systems without links (either hard or symbolic) is always set to 1
* ``i_blocks``: the number of blocks used by the file (all blocks, not just data); is only used by the quota subsystem

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only...


.. warning::

An inode created with :c:func:`new_inode` is not in the hash table, and unless you have serious reasons, you must enter it in the hash table;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't very clear. "unless you have serios resons not to, you should add it in the hash table"

One of the main inode operations is obtaining an inode (the :c:type:`struct inode` in VFS).
Until version ``2.6.24`` of the Linux kernel, the developer defined a ``read_inode`` function.
Starting with version ``2.6.25``, the developer must define a ``<fsname>_iget`` where ``<fsname>`` is the name of the file system.
This function is responsible for finding the VFS inode if it exists or creating a new one and filling it with the information from the disk.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

responsible with*

Superoperations
^^^^^^^^^^^^^^^

Many of the superoperations (components of the :c:type:`struct super_operations` structure used by the superbloc) are used when working with inodes. These operations are described next:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superblock*

* ``evict_inode``: removes any information about the inode with the number received in the ``i_ino`` field from the disk and memory (both the inode on the disk and the associated data blocks). This involves performing the following operations:

* delete the inode from the disk;
* updates disk bitmaps (if any)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add ;


* delete the inode from the disk;
* updates disk bitmaps (if any)
* delete the inode the page cache by calling :c:func:`truncate_inode_pages`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete the inode from the page cache

The file structure
==================

The ``file`` structure corresponds to a file open by a process and exists only in memory, being associated with an inode

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period after the first sentence.

==================

The ``file`` structure corresponds to a file open by a process and exists only in memory, being associated with an inode
It is the VFS entity closest to user-space; the structure fields contain familiar information of a user-space file (access mode, file position, etc.) and the operations with it are known system calls (``read``, ``write`` , etc.).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the closest VFS entity to user-space

return generic_block_bmap(mapping, block, minix_get_block);
}

All that needs to be done is implement :c:type:`minix_get_block`, which has to translate a block of a file into a block on the device.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is to implement

All that needs to be done is implement :c:type:`minix_get_block`, which has to translate a block of a file into a block on the device.
If the flag ``create`` received as a parameter is set, a new block must be allocated.
In case a new block is created, the bit map must be updated accordingly.
To notify the kernel not to read the block from the disk, ``bh`` must be marked bh with :c:func:`set_buffer_new`. The buffer must be associated with the block through :c:func:`map_bh`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double bh

* ``d_make_root``: allocates the root dentry. It is generally used in the function that is called to read the superblock (``fill_super``), which must initialize the root directory.
So the root inode is obtained from the superblock and is used as an argument to this function, to fill the ``s_root`` field from the :c:type:`struct super_block` structure.
* ``d_add``: associates a dentry with an inode; the dentry received as a parameter in the calls discussed above signifies the entry (name, length) that needs to be created. This function will be used when creating/loading a new inode that does not have a dentry associated with it and has not yet been introduced to the hash (at ``lookup``);
* ``d_instantiate``: The lighter version of the previous call, in which the dentry was previously added in hash.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the term hash table, both here and above


.. warning::

``d_instantiate`` must be used for create calls (``mkdir``, ``mknod``, ``rename``, ``symlink``) and NOT ``d_add``.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be used to implement:...

In the minix case, the function is :c:func:`minix_create`.
This function is called by the ``open`` and ``creat`` system calls. Such a function performs the following operations:

#. Introduces a new entry into the physical structure on the disk; the update of the bit maps on the disk must bot be forgotten.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not

tavip pushed a commit to linux-kernel-labs/linux-kernel-labs.github.io that referenced this pull request Apr 16, 2019
@valighita valighita merged commit e118554 into linux-kernel-labs:master Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants