xref: /haiku/src/add-ons/kernel/file_systems/xfs/xfs.cpp (revision 830f67ef991407f287dbc1238aa5f5906d90c991)
1 /*
2 * Copyright 2020, Shubham Bhagat, shubhambhagat111@yahoo.com
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5 
6 #include "xfs.h"
7 
8 
9 uint8
10 XfsSuperBlock::Flags() const
11 {
12 	return sb_flags;
13 }
14 
15 
16 bool
17 XfsSuperBlock::IsValid() const
18 {
19 	if (sb_magicnum != XFS_SB_MAGIC)
20 		return false;
21 
22 	if (BASICBLOCKSIZE > sb_blocksize) {
23 		ERROR("Basic block is less than 512 bytes!");
24 		return false;
25 	}
26 
27 	// Checking version 4 file system
28 	ASSERT((Version() & 0x000f) == 4)
29 
30 	return true;
31 }
32 
33 
34 uint16
35 XfsSuperBlock::Version() const
36 {
37 	return sb_versionnum;
38 }
39 
40 
41 uint32
42 XfsSuperBlock::Features2() const
43 {
44 	return sb_features2;
45 }
46 
47 
48 uint32
49 XfsSuperBlock::BlockSize() const
50 {
51 	return sb_blocksize;
52 }
53 
54 
55 uint32
56 XfsSuperBlock::DirBlockLog() const
57 {
58 	return sb_dirblklog;
59 }
60 
61 
62 uint8
63 XfsSuperBlock::BlockLog() const
64 {
65 	return sb_blocklog;
66 }
67 
68 
69 uint32
70 XfsSuperBlock::DirBlockSize() const
71 {
72 	return BlockSize() * (1 << sb_dirblklog);
73 }
74 
75 
76 uint8
77 XfsSuperBlock::AgInodeBits() const
78 {
79 	return AgBlocksLog() + InodesPerBlkLog();
80 }
81 
82 
83 uint8
84 XfsSuperBlock::InodesPerBlkLog() const
85 {
86 	return sb_inopblog;
87 }
88 
89 
90 uint8
91 XfsSuperBlock::AgBlocksLog() const
92 {
93 	return sb_agblklog;
94 }
95 
96 
97 uint32
98 XfsSuperBlock::Size() const
99 {
100 	return XFS_SB_MAXSIZE;
101 }
102 
103 
104 uint16
105 XfsSuperBlock::InodeSize() const
106 {
107 	return sb_inodesize;
108 }
109 
110 
111 xfs_rfsblock_t
112 XfsSuperBlock::TotalBlocks() const
113 {
114 	return sb_dblocks;
115 }
116 
117 
118 xfs_rfsblock_t
119 XfsSuperBlock::TotalBlocksWithLog() const
120 {
121 	return TotalBlocks() + sb_logblocks;
122 }
123 
124 
125 uint64
126 XfsSuperBlock::FreeBlocks() const
127 {
128 	return sb_fdblocks;
129 }
130 
131 
132 uint64
133 XfsSuperBlock::UsedBlocks() const
134 {
135 	return TotalBlocks() - FreeBlocks();
136 }
137 
138 
139 const char*
140 XfsSuperBlock::Name() const
141 {
142 	return sb_fname;
143 }
144 
145 
146 xfs_ino_t
147 XfsSuperBlock::Root() const
148 {
149 	return sb_rootino;
150 }
151 
152 
153 xfs_agnumber_t
154 XfsSuperBlock::AgCount() const
155 {
156 	return sb_agcount;
157 }
158 
159 
160 xfs_agblock_t
161 XfsSuperBlock::AgBlocks() const
162 {
163 	return sb_agblocks;
164 }
165 
166 
167 void
168 XfsSuperBlock::SwapEndian()
169 {
170 	sb_magicnum		=	B_BENDIAN_TO_HOST_INT32(sb_magicnum);
171 	sb_blocksize	=	B_BENDIAN_TO_HOST_INT32(sb_blocksize);
172 	sb_dblocks		=	B_BENDIAN_TO_HOST_INT64(sb_dblocks);
173 	sb_rblocks		=	B_BENDIAN_TO_HOST_INT64(sb_rblocks);
174 	sb_rextents		=	B_BENDIAN_TO_HOST_INT64(sb_rextents);
175 	sb_logstart		=	B_BENDIAN_TO_HOST_INT64(sb_logstart);
176 	sb_rootino		=	B_BENDIAN_TO_HOST_INT64(sb_rootino);
177 	sb_rbmino		=	B_BENDIAN_TO_HOST_INT64(sb_rbmino);
178 	sb_rsumino		=	B_BENDIAN_TO_HOST_INT64(sb_rsumino);
179 	sb_rextsize		=	B_BENDIAN_TO_HOST_INT32(sb_rextsize);
180 	sb_agblocks		=	B_BENDIAN_TO_HOST_INT32(sb_agblocks);
181 	sb_agcount		=	B_BENDIAN_TO_HOST_INT32(sb_agcount);
182 	sb_rbmblocks	=	B_BENDIAN_TO_HOST_INT32(sb_rbmblocks);
183 	sb_logblocks	=	B_BENDIAN_TO_HOST_INT32(sb_logblocks);
184 	sb_versionnum	=	B_BENDIAN_TO_HOST_INT16(sb_versionnum);
185 	sb_sectsize		=	B_BENDIAN_TO_HOST_INT16(sb_sectsize);
186 	sb_inodesize	=	B_BENDIAN_TO_HOST_INT16(sb_inodesize);
187 	sb_inopblock	=	B_BENDIAN_TO_HOST_INT16(sb_inopblock);
188 	sb_icount		=	B_BENDIAN_TO_HOST_INT64(sb_icount);
189 	sb_ifree		=	B_BENDIAN_TO_HOST_INT64(sb_ifree);
190 	sb_fdblocks		=	B_BENDIAN_TO_HOST_INT64(sb_fdblocks);
191 	sb_frextents	=	B_BENDIAN_TO_HOST_INT64(sb_frextents);
192 	sb_uquotino		=	B_BENDIAN_TO_HOST_INT64(sb_uquotino);
193 	sb_gquotino		=	B_BENDIAN_TO_HOST_INT64(sb_gquotino);
194 	sb_qflags		=	B_BENDIAN_TO_HOST_INT16(sb_qflags);
195 	sb_inoalignmt	=	B_BENDIAN_TO_HOST_INT32(sb_inoalignmt);
196 	sb_unit			=	B_BENDIAN_TO_HOST_INT32(sb_unit);
197 	sb_width		=	B_BENDIAN_TO_HOST_INT32(sb_width);
198 	sb_logsectsize	=	B_BENDIAN_TO_HOST_INT16(sb_logsectsize);
199 	sb_logsunit		=	B_BENDIAN_TO_HOST_INT32(sb_logsunit);
200 	sb_features2	=	B_BENDIAN_TO_HOST_INT32(sb_features2);
201 }
202