xref: /haiku/src/add-ons/kernel/file_systems/xfs/xfs.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
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 uint8
56 XfsSuperBlock::BlockLog() const
57 {
58 	return sb_blocklog;
59 }
60 
61 
62 uint32
63 XfsSuperBlock::DirBlockSize() const
64 {
65 	return BlockSize() * (1 << sb_dirblklog);
66 }
67 
68 
69 uint8
70 XfsSuperBlock::AgInodeBits() const
71 {
72 	return AgBlocksLog() + InodesPerBlkLog();
73 }
74 
75 
76 uint8
77 XfsSuperBlock::InodesPerBlkLog() const
78 {
79 	return sb_inopblog;
80 }
81 
82 
83 uint8
84 XfsSuperBlock::AgBlocksLog() const
85 {
86 	return sb_agblklog;
87 }
88 
89 
90 uint32
91 XfsSuperBlock::Size() const
92 {
93 	return XFS_SB_MAXSIZE;
94 }
95 
96 
97 uint16
98 XfsSuperBlock::InodeSize() const
99 {
100 	return sb_inodesize;
101 }
102 
103 
104 xfs_rfsblock_t
105 XfsSuperBlock::TotalBlocks() const
106 {
107 	return sb_dblocks;
108 }
109 
110 
111 xfs_rfsblock_t
112 XfsSuperBlock::TotalBlocksWithLog() const
113 {
114 	return TotalBlocks() + sb_logblocks;
115 }
116 
117 
118 uint64
119 XfsSuperBlock::FreeBlocks() const
120 {
121 	return sb_fdblocks;
122 }
123 
124 
125 uint64
126 XfsSuperBlock::UsedBlocks() const
127 {
128 	return TotalBlocks() - FreeBlocks();
129 }
130 
131 
132 const char*
133 XfsSuperBlock::Name() const
134 {
135 	return sb_fname;
136 }
137 
138 
139 xfs_ino_t
140 XfsSuperBlock::Root() const
141 {
142 	return sb_rootino;
143 }
144 
145 
146 xfs_agnumber_t
147 XfsSuperBlock::AgCount() const
148 {
149 	return sb_agcount;
150 }
151 
152 
153 xfs_agblock_t
154 XfsSuperBlock::AgBlocks() const
155 {
156 	return sb_agblocks;
157 }
158 
159 
160 void
161 XfsSuperBlock::SwapEndian()
162 {
163 	sb_magicnum		=	B_BENDIAN_TO_HOST_INT32(sb_magicnum);
164 	sb_blocksize	=	B_BENDIAN_TO_HOST_INT32(sb_blocksize);
165 	sb_dblocks		=	B_BENDIAN_TO_HOST_INT64(sb_dblocks);
166 	sb_rblocks		=	B_BENDIAN_TO_HOST_INT64(sb_rblocks);
167 	sb_rextents		=	B_BENDIAN_TO_HOST_INT64(sb_rextents);
168 	sb_logstart		=	B_BENDIAN_TO_HOST_INT64(sb_logstart);
169 	sb_rootino		=	B_BENDIAN_TO_HOST_INT64(sb_rootino);
170 	sb_rbmino		=	B_BENDIAN_TO_HOST_INT64(sb_rbmino);
171 	sb_rsumino		=	B_BENDIAN_TO_HOST_INT64(sb_rsumino);
172 	sb_rextsize		=	B_BENDIAN_TO_HOST_INT32(sb_rextsize);
173 	sb_agblocks		=	B_BENDIAN_TO_HOST_INT32(sb_agblocks);
174 	sb_agcount		=	B_BENDIAN_TO_HOST_INT32(sb_agcount);
175 	sb_rbmblocks	=	B_BENDIAN_TO_HOST_INT32(sb_rbmblocks);
176 	sb_logblocks	=	B_BENDIAN_TO_HOST_INT32(sb_logblocks);
177 	sb_versionnum	=	B_BENDIAN_TO_HOST_INT16(sb_versionnum);
178 	sb_sectsize		=	B_BENDIAN_TO_HOST_INT16(sb_sectsize);
179 	sb_inodesize	=	B_BENDIAN_TO_HOST_INT16(sb_inodesize);
180 	sb_inopblock	=	B_BENDIAN_TO_HOST_INT16(sb_inopblock);
181 	sb_icount		=	B_BENDIAN_TO_HOST_INT64(sb_icount);
182 	sb_ifree		=	B_BENDIAN_TO_HOST_INT64(sb_ifree);
183 	sb_fdblocks		=	B_BENDIAN_TO_HOST_INT64(sb_fdblocks);
184 	sb_frextents	=	B_BENDIAN_TO_HOST_INT64(sb_frextents);
185 	sb_uquotino		=	B_BENDIAN_TO_HOST_INT64(sb_uquotino);
186 	sb_gquotino		=	B_BENDIAN_TO_HOST_INT64(sb_gquotino);
187 	sb_qflags		=	B_BENDIAN_TO_HOST_INT16(sb_qflags);
188 	sb_inoalignmt	=	B_BENDIAN_TO_HOST_INT32(sb_inoalignmt);
189 	sb_unit			=	B_BENDIAN_TO_HOST_INT32(sb_unit);
190 	sb_width		=	B_BENDIAN_TO_HOST_INT32(sb_width);
191 	sb_logsectsize	=	B_BENDIAN_TO_HOST_INT16(sb_logsectsize);
192 	sb_logsunit		=	B_BENDIAN_TO_HOST_INT32(sb_logsunit);
193 	sb_features2	=	B_BENDIAN_TO_HOST_INT32(sb_features2);
194 }
195