Skip to content

Commit 9047897

Browse files
Suhel Mehtapulkomandy
authored andcommitted
Project Update: UFS2
1 parent 8d5c44e commit 9047897

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
+++
2+
type = "blog"
3+
title = "GSoC 2020 Project Update(UFS2): First Evaluation"
4+
author = "suhelmehta"
5+
date = "2020-07-10 00:57:38+05:30"
6+
tags = ["haiku", "software", "gsoc", "gsoc2020", "file system"]
7+
+++
8+
9+
Hello Everyone!
10+
11+
This is my second post related to my project, *Adding UFS2 file system in Haiku*
12+
13+
The link below provides the patches that I have worked on till now.
14+
15+
[Know more](https://review.haiku-os.org/q/owner:suhelmehta%2540outlook.com)
16+
17+
## Work done till now
18+
The following points briefly describes what I have done till now:
19+
20+
- Mount the root directory of a UFS2 formatted disk
21+
- Implemented *ufs2_mount()* in kernel_interface.cpp
22+
23+
- Reading inode from disk
24+
- Implemented *struct ufs2_inode* and *class Inode* in Inode.h and Inode.cpp
25+
- Implemented code to convert inode number to disk offset in Inode.cpp in *Inode::Inode()*
26+
27+
- Publishing the inode
28+
- Implemented publishing of root node in Volume.cpp in *Volume::Mount()* using *publish_vnode()*
29+
30+
- Important hooks implemented in kernel_interface.cpp
31+
- *read_stat()*
32+
- *fs_info()*
33+
- *open_dir()*
34+
- *read_dir()*
35+
- *lookup()*
36+
37+
---
38+
39+
### Directory Structure
40+
41+
UFS2 keeps the name of directory or file in direct blocks. The block number is stored in inode. In order to get the disk offset, the block number must be multiplied with *MINBSIZE* (defined in ufs2.h).
42+
43+
At that offset, information about the current directory(.) along with the parent directory or previous directory(..) is present. The structure for that is *dir_info* in DirectoryIterator.h and the information about directory will be _inode number, length of record, type(file or directory or symbolic link) and name of directory_.
44+
45+
After that name of sub directories or files with inode number would appear (structure implemented is *dir* in DirectoryIterator.h).
46+
47+
### Solving file or directory name bug
48+
49+
While implementing code to read file or directory name there was an issue that, due to less buffer size, the code did not read whole name of file or directory. To resolve it, the approach I used was that, before name of a file or directory there is a number that tells the length of name.
50+
51+
I took mod of that number with 4 and if that result is 0 then length of name is multiple of 4 otherwise the remainder obtained is subracted from 4 and the result is added to the length of name. It is done because the bytes allocated for name will be always multiple of 4 i.e. if name is "ab" then there will be 4 bytes allocated for name similarly if name is "Haiku" then 8 bytes will be allocated and so on.
52+
53+
I used above method and managed to get the next offset from where I read next directory or file name from disk.
54+
55+
## Making code efficient
56+
57+
Right now ls command is working fine and my current approach is explained by the following example.
58+
59+
Consider that there are 2 directories in root directories.
60+
61+
1) Haiku
62+
2) FileSystem
63+
64+
Now consider that we run ls command in root directory the outcome is, it reads name from root directory which is passed to *lookup()*, which initiates a loop that reads data from disk offset and continues adding value to offset, to read next directory name and it goes on until the name in lookup and anyone name read from disk matches.
65+
66+
The problem is that, if it has read "Haiku" directory from disk offset - 20742168(just assuming a number) and now it wants to read next directory, then it again start reading from offset 20742168(where "Haiku" directory is present) and then it adds 16(calculated with help of name length) to previous offset and reads from there this happens until the name in lookup matches name read from disk in the loop.
67+
68+
So right now I am working on making code efficient. I would love to have feedback about my blogs and my way of implementing the code. :)
69+
70+
## Learning new things
71+
72+
It is a great learning experience for me and I have learnt new things like
73+
74+
- Time is stored in the form of timeval or timespec in file system
75+
- Datatypes of C++
76+
- Git commands
77+
- Filessystem other than UFS2
78+
79+
## Resources
80+
81+
[UFS2 Inode](https://flylib.com/books/en/2.48.1/ufs2_inodes.html)
82+
83+
[Cylinder Group Summary](https://flylib.com/books/en/2.48.1/cylinder_group_summary.html)
84+
85+
[UFS2 Directory Information](https://github.com/freebsd/freebsd/blob/master/sys/ufs/ufs/dir.h#L79)

0 commit comments

Comments
 (0)