1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
5 #include "platform_defs.h"
13 struct xfs_fsop_geom
*geo
,
35 isint
= geo
->logstart
> 0;
36 lazycount
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_LAZYSB
? 1 : 0;
37 dirversion
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_DIRV2
? 2 : 1;
38 logversion
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_LOGV2
? 2 : 1;
39 attrversion
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_ATTR2
? 2 : \
40 (geo
->flags
& XFS_FSOP_GEOM_FLAGS_ATTR
? 1 : 0);
41 cimode
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_DIRV2CI
? 1 : 0;
42 projid32bit
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_PROJID32
? 1 : 0;
43 crcs_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_V5SB
? 1 : 0;
44 ftype_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_FTYPE
? 1 : 0;
45 finobt_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_FINOBT
? 1 : 0;
46 spinodes
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_SPINODES
? 1 : 0;
47 rmapbt_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_RMAPBT
? 1 : 0;
48 reflink_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_REFLINK
? 1 : 0;
49 bigtime_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_BIGTIME
? 1 : 0;
50 inobtcount
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_INOBTCNT
? 1 : 0;
51 nrext64
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_NREXT64
? 1 : 0;
54 "meta-data=%-22s isize=%-6d agcount=%u, agsize=%u blks\n"
55 " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
56 " =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n"
57 " =%-22s reflink=%-4u bigtime=%u inobtcount=%u nrext64=%u\n"
58 "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
59 " =%-22s sunit=%-6u swidth=%u blks\n"
60 "naming =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d\n"
61 "log =%-22s bsize=%-6d blocks=%u, version=%d\n"
62 " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
63 "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
64 mntpoint
, geo
->inodesize
, geo
->agcount
, geo
->agblocks
,
65 "", geo
->sectsize
, attrversion
, projid32bit
,
66 "", crcs_enabled
, finobt_enabled
, spinodes
, rmapbt_enabled
,
67 "", reflink_enabled
, bigtime_enabled
, inobtcount
, nrext64
,
68 "", geo
->blocksize
, (unsigned long long)geo
->datablocks
,
70 "", geo
->sunit
, geo
->swidth
,
71 dirversion
, geo
->dirblocksize
, cimode
, ftype_enabled
,
72 isint
? _("internal log") : logname
? logname
: _("external"),
73 geo
->blocksize
, geo
->logblocks
, logversion
,
74 "", geo
->logsectsize
, geo
->logsunit
/ geo
->blocksize
, lazycount
,
75 !geo
->rtblocks
? _("none") : rtname
? rtname
: _("external"),
76 geo
->rtextsize
* geo
->blocksize
, (unsigned long long)geo
->rtblocks
,
77 (unsigned long long)geo
->rtextents
);
80 /* Try to obtain the xfs geometry. On error returns a negative error code. */
84 struct xfs_fsop_geom
*fsgeo
)
88 memset(fsgeo
, 0, sizeof(*fsgeo
));
90 ret
= ioctl(fd
, XFS_IOC_FSGEOMETRY
, fsgeo
);
94 ret
= ioctl(fd
, XFS_IOC_FSGEOMETRY_V4
, fsgeo
);
98 ret
= ioctl(fd
, XFS_IOC_FSGEOMETRY_V1
, fsgeo
);
106 * Prepare xfs_fd structure for future ioctl operations by computing the xfs
107 * geometry for @xfd->fd. Returns zero or a negative error code.
110 xfd_prepare_geometry(
115 ret
= xfrog_geometry(xfd
->fd
, &xfd
->fsgeom
);
119 xfd
->agblklog
= log2_roundup(xfd
->fsgeom
.agblocks
);
120 xfd
->blocklog
= highbit32(xfd
->fsgeom
.blocksize
);
121 xfd
->inodelog
= highbit32(xfd
->fsgeom
.inodesize
);
122 xfd
->inopblog
= xfd
->blocklog
- xfd
->inodelog
;
123 xfd
->aginolog
= xfd
->agblklog
+ xfd
->inopblog
;
124 xfd
->blkbb_log
= xfd
->blocklog
- BBSHIFT
;
128 /* Open a file on an XFS filesystem. Returns zero or a negative error code. */
132 const char *pathname
,
137 xfd
->fd
= open(pathname
, flags
);
141 ret
= xfd_prepare_geometry(xfd
);
151 * Release any resources associated with this xfs_fd structure. Returns zero
152 * or a negative error code.
163 ret
= close(xfd
->fd
);
171 /* Try to obtain an AG's geometry. Returns zero or a negative error code. */
176 struct xfs_ag_geometry
*ageo
)
180 ageo
->ag_number
= agno
;
181 ret
= ioctl(fd
, XFS_IOC_AG_GEOMETRY
, ageo
);