1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
11 struct xfs_fsop_geom
*geo
,
30 isint
= geo
->logstart
> 0;
31 lazycount
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_LAZYSB
? 1 : 0;
32 dirversion
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_DIRV2
? 2 : 1;
33 logversion
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_LOGV2
? 2 : 1;
34 attrversion
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_ATTR2
? 2 : \
35 (geo
->flags
& XFS_FSOP_GEOM_FLAGS_ATTR
? 1 : 0);
36 cimode
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_DIRV2CI
? 1 : 0;
37 projid32bit
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_PROJID32
? 1 : 0;
38 crcs_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_V5SB
? 1 : 0;
39 ftype_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_FTYPE
? 1 : 0;
40 finobt_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_FINOBT
? 1 : 0;
41 spinodes
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_SPINODES
? 1 : 0;
42 rmapbt_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_RMAPBT
? 1 : 0;
43 reflink_enabled
= geo
->flags
& XFS_FSOP_GEOM_FLAGS_REFLINK
? 1 : 0;
46 "meta-data=%-22s isize=%-6d agcount=%u, agsize=%u blks\n"
47 " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
48 " =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n"
49 " =%-22s reflink=%u\n"
50 "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
51 " =%-22s sunit=%-6u swidth=%u blks\n"
52 "naming =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d\n"
53 "log =%-22s bsize=%-6d blocks=%u, version=%d\n"
54 " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
55 "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
56 mntpoint
, geo
->inodesize
, geo
->agcount
, geo
->agblocks
,
57 "", geo
->sectsize
, attrversion
, projid32bit
,
58 "", crcs_enabled
, finobt_enabled
, spinodes
, rmapbt_enabled
,
60 "", geo
->blocksize
, (unsigned long long)geo
->datablocks
,
62 "", geo
->sunit
, geo
->swidth
,
63 dirversion
, geo
->dirblocksize
, cimode
, ftype_enabled
,
64 isint
? _("internal log") : logname
? logname
: _("external"),
65 geo
->blocksize
, geo
->logblocks
, logversion
,
66 "", geo
->logsectsize
, geo
->logsunit
/ geo
->blocksize
, lazycount
,
67 !geo
->rtblocks
? _("none") : rtname
? rtname
: _("external"),
68 geo
->rtextsize
* geo
->blocksize
, (unsigned long long)geo
->rtblocks
,
69 (unsigned long long)geo
->rtextents
);
72 /* Try to obtain the xfs geometry. On error returns a positive error code. */
76 struct xfs_fsop_geom
*fsgeo
)
80 memset(fsgeo
, 0, sizeof(*fsgeo
));
82 ret
= ioctl(fd
, XFS_IOC_FSGEOMETRY
, fsgeo
);
86 ret
= ioctl(fd
, XFS_IOC_FSGEOMETRY_V4
, fsgeo
);
90 ret
= ioctl(fd
, XFS_IOC_FSGEOMETRY_V1
, fsgeo
);
98 * Prepare xfs_fd structure for future ioctl operations by computing the xfs
99 * geometry for @xfd->fd. Returns zero or a positive error code.
102 xfd_prepare_geometry(
107 ret
= xfrog_geometry(xfd
->fd
, &xfd
->fsgeom
);
111 xfd
->agblklog
= log2_roundup(xfd
->fsgeom
.agblocks
);
112 xfd
->blocklog
= highbit32(xfd
->fsgeom
.blocksize
);
113 xfd
->inodelog
= highbit32(xfd
->fsgeom
.inodesize
);
114 xfd
->inopblog
= xfd
->blocklog
- xfd
->inodelog
;
115 xfd
->aginolog
= xfd
->agblklog
+ xfd
->inopblog
;
116 xfd
->blkbb_log
= xfd
->blocklog
- BBSHIFT
;
120 /* Open a file on an XFS filesystem. Returns zero or a positive error code. */
124 const char *pathname
,
129 xfd
->fd
= open(pathname
, flags
);
133 ret
= xfd_prepare_geometry(xfd
);
143 * Release any resources associated with this xfs_fd structure. Returns zero
144 * or a positive error code.
155 ret
= close(xfd
->fd
);
163 /* Try to obtain an AG's geometry. Returns zero or a positive error code. */
168 struct xfs_ag_geometry
*ageo
)
172 ageo
->ag_number
= agno
;
173 ret
= ioctl(fd
, XFS_IOC_AG_GEOMETRY
, ageo
);