hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/fs/xfs/libxfs/xfs_format.h
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+/* SPDX-License-Identifier: GPL-2.0 */
22 /*
33 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
44 * All Rights Reserved.
....@@ -287,6 +287,8 @@
287287 {
288288 if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
289289 return false;
290
+ if (!(sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT))
291
+ return false;
290292
291293 /* check for unknown features in the fs */
292294 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
....@@ -355,12 +357,6 @@
355357 {
356358 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
357359 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
358
-}
359
-
360
-static inline bool xfs_sb_version_hasextflgbit(struct xfs_sb *sbp)
361
-{
362
- return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
363
- (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
364360 }
365361
366362 static inline bool xfs_sb_version_hassector(struct xfs_sb *sbp)
....@@ -453,10 +449,12 @@
453449 #define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0) /* free inode btree */
454450 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1) /* reverse map btree */
455451 #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2) /* reflinked files */
452
+#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3) /* inobt block counts */
456453 #define XFS_SB_FEAT_RO_COMPAT_ALL \
457454 (XFS_SB_FEAT_RO_COMPAT_FINOBT | \
458455 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
459
- XFS_SB_FEAT_RO_COMPAT_REFLINK)
456
+ XFS_SB_FEAT_RO_COMPAT_REFLINK| \
457
+ XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
460458 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL
461459 static inline bool
462460 xfs_sb_has_ro_compat_feature(
....@@ -469,10 +467,12 @@
469467 #define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */
470468 #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */
471469 #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */
470
+#define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */
472471 #define XFS_SB_FEAT_INCOMPAT_ALL \
473472 (XFS_SB_FEAT_INCOMPAT_FTYPE| \
474473 XFS_SB_FEAT_INCOMPAT_SPINODES| \
475
- XFS_SB_FEAT_INCOMPAT_META_UUID)
474
+ XFS_SB_FEAT_INCOMPAT_META_UUID| \
475
+ XFS_SB_FEAT_INCOMPAT_BIGTIME)
476476
477477 #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL
478478 static inline bool
....@@ -499,6 +499,23 @@
499499 static inline bool xfs_sb_version_hascrc(struct xfs_sb *sbp)
500500 {
501501 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
502
+}
503
+
504
+/*
505
+ * v5 file systems support V3 inodes only, earlier file systems support
506
+ * v2 and v1 inodes.
507
+ */
508
+static inline bool xfs_sb_version_has_v3inode(struct xfs_sb *sbp)
509
+{
510
+ return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
511
+}
512
+
513
+static inline bool xfs_dinode_good_version(struct xfs_sb *sbp,
514
+ uint8_t version)
515
+{
516
+ if (xfs_sb_version_has_v3inode(sbp))
517
+ return version == 3;
518
+ return version == 1 || version == 2;
502519 }
503520
504521 static inline bool xfs_sb_version_has_pquotino(struct xfs_sb *sbp)
....@@ -550,6 +567,23 @@
550567 (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_REFLINK);
551568 }
552569
570
+static inline bool xfs_sb_version_hasbigtime(struct xfs_sb *sbp)
571
+{
572
+ return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
573
+ (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_BIGTIME);
574
+}
575
+
576
+/*
577
+ * Inode btree block counter. We record the number of inobt and finobt blocks
578
+ * in the AGI header so that we can skip the finobt walk at mount time when
579
+ * setting up per-AG reservations.
580
+ */
581
+static inline bool xfs_sb_version_hasinobtcounts(struct xfs_sb *sbp)
582
+{
583
+ return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
584
+ (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT);
585
+}
586
+
553587 /*
554588 * end of superblock version macros
555589 */
....@@ -564,7 +598,6 @@
564598
565599 #define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
566600 #define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
567
-#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
568601
569602 #define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
570603 #define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
....@@ -711,7 +744,6 @@
711744 /* disk block (xfs_daddr_t) in the AG */
712745 #define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
713746 #define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
714
-#define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)((bp)->b_addr))
715747
716748 /*
717749 * Size of the unlinked inode hash table in the agi.
....@@ -754,6 +786,9 @@
754786 __be32 agi_free_root; /* root of the free inode btree */
755787 __be32 agi_free_level;/* levels in free inode btree */
756788
789
+ __be32 agi_iblocks; /* inobt blocks used */
790
+ __be32 agi_fblocks; /* finobt blocks used */
791
+
757792 /* structure must be padded to 64 bit alignment */
758793 } xfs_agi_t;
759794
....@@ -774,12 +809,12 @@
774809 #define XFS_AGI_ALL_BITS_R1 ((1 << XFS_AGI_NUM_BITS_R1) - 1)
775810 #define XFS_AGI_FREE_ROOT (1 << 11)
776811 #define XFS_AGI_FREE_LEVEL (1 << 12)
777
-#define XFS_AGI_NUM_BITS_R2 13
812
+#define XFS_AGI_IBLOCKS (1 << 13) /* both inobt/finobt block counters */
813
+#define XFS_AGI_NUM_BITS_R2 14
778814
779815 /* disk block (xfs_daddr_t) in the AG */
780816 #define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
781817 #define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
782
-#define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)((bp)->b_addr))
783818
784819 /*
785820 * The third a.g. block contains the a.g. freelist, an array
....@@ -787,21 +822,15 @@
787822 */
788823 #define XFS_AGFL_DADDR(mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
789824 #define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
790
-#define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)((bp)->b_addr))
825
+#define XFS_BUF_TO_AGFL(bp) ((struct xfs_agfl *)((bp)->b_addr))
791826
792
-#define XFS_BUF_TO_AGFL_BNO(mp, bp) \
793
- (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
794
- &(XFS_BUF_TO_AGFL(bp)->agfl_bno[0]) : \
795
- (__be32 *)(bp)->b_addr)
796
-
797
-typedef struct xfs_agfl {
827
+struct xfs_agfl {
798828 __be32 agfl_magicnum;
799829 __be32 agfl_seqno;
800830 uuid_t agfl_uuid;
801831 __be64 agfl_lsn;
802832 __be32 agfl_crc;
803
- __be32 agfl_bno[]; /* actually xfs_agfl_size(mp) */
804
-} __attribute__((packed)) xfs_agfl_t;
833
+} __attribute__((packed));
805834
806835 #define XFS_AGFL_CRC_OFF offsetof(struct xfs_agfl, agfl_crc)
807836
....@@ -827,10 +856,87 @@
827856 ASSERT(xfs_daddr_to_agno(mp, d) == \
828857 xfs_daddr_to_agno(mp, (d) + (len) - 1)))
829858
830
-typedef struct xfs_timestamp {
859
+/*
860
+ * XFS Timestamps
861
+ * ==============
862
+ *
863
+ * Traditional ondisk inode timestamps consist of signed 32-bit counters for
864
+ * seconds and nanoseconds; time zero is the Unix epoch, Jan 1 00:00:00 UTC
865
+ * 1970, which means that the timestamp epoch is the same as the Unix epoch.
866
+ * Therefore, the ondisk min and max defined here can be used directly to
867
+ * constrain the incore timestamps on a Unix system. Note that we actually
868
+ * encode a __be64 value on disk.
869
+ *
870
+ * When the bigtime feature is enabled, ondisk inode timestamps become an
871
+ * unsigned 64-bit nanoseconds counter. This means that the bigtime inode
872
+ * timestamp epoch is the start of the classic timestamp range, which is
873
+ * Dec 31 20:45:52 UTC 1901. Because the epochs are not the same, callers
874
+ * /must/ use the bigtime conversion functions when encoding and decoding raw
875
+ * timestamps.
876
+ */
877
+typedef __be64 xfs_timestamp_t;
878
+
879
+/* Legacy timestamp encoding format. */
880
+struct xfs_legacy_timestamp {
831881 __be32 t_sec; /* timestamp seconds */
832882 __be32 t_nsec; /* timestamp nanoseconds */
833
-} xfs_timestamp_t;
883
+};
884
+
885
+/*
886
+ * Smallest possible ondisk seconds value with traditional timestamps. This
887
+ * corresponds exactly with the incore timestamp Dec 13 20:45:52 UTC 1901.
888
+ */
889
+#define XFS_LEGACY_TIME_MIN ((int64_t)S32_MIN)
890
+
891
+/*
892
+ * Largest possible ondisk seconds value with traditional timestamps. This
893
+ * corresponds exactly with the incore timestamp Jan 19 03:14:07 UTC 2038.
894
+ */
895
+#define XFS_LEGACY_TIME_MAX ((int64_t)S32_MAX)
896
+
897
+/*
898
+ * Smallest possible ondisk seconds value with bigtime timestamps. This
899
+ * corresponds (after conversion to a Unix timestamp) with the traditional
900
+ * minimum timestamp of Dec 13 20:45:52 UTC 1901.
901
+ */
902
+#define XFS_BIGTIME_TIME_MIN ((int64_t)0)
903
+
904
+/*
905
+ * Largest supported ondisk seconds value with bigtime timestamps. This
906
+ * corresponds (after conversion to a Unix timestamp) with an incore timestamp
907
+ * of Jul 2 20:20:24 UTC 2486.
908
+ *
909
+ * We round down the ondisk limit so that the bigtime quota and inode max
910
+ * timestamps will be the same.
911
+ */
912
+#define XFS_BIGTIME_TIME_MAX ((int64_t)((-1ULL / NSEC_PER_SEC) & ~0x3ULL))
913
+
914
+/*
915
+ * Bigtime epoch is set exactly to the minimum time value that a traditional
916
+ * 32-bit timestamp can represent when using the Unix epoch as a reference.
917
+ * Hence the Unix epoch is at a fixed offset into the supported bigtime
918
+ * timestamp range.
919
+ *
920
+ * The bigtime epoch also matches the minimum value an on-disk 32-bit XFS
921
+ * timestamp can represent so we will not lose any fidelity in converting
922
+ * to/from unix and bigtime timestamps.
923
+ *
924
+ * The following conversion factor converts a seconds counter from the Unix
925
+ * epoch to the bigtime epoch.
926
+ */
927
+#define XFS_BIGTIME_EPOCH_OFFSET (-(int64_t)S32_MIN)
928
+
929
+/* Convert a timestamp from the Unix epoch to the bigtime epoch. */
930
+static inline uint64_t xfs_unix_to_bigtime(time64_t unix_seconds)
931
+{
932
+ return (uint64_t)unix_seconds + XFS_BIGTIME_EPOCH_OFFSET;
933
+}
934
+
935
+/* Convert a timestamp from the bigtime epoch to the Unix epoch. */
936
+static inline time64_t xfs_bigtime_to_unix(uint64_t ondisk_seconds)
937
+{
938
+ return (time64_t)ondisk_seconds - XFS_BIGTIME_EPOCH_OFFSET;
939
+}
834940
835941 /*
836942 * On-disk inode structure.
....@@ -920,14 +1026,24 @@
9201026
9211027 /*
9221028 * Values for di_format
1029
+ *
1030
+ * This enum is used in string mapping in xfs_trace.h; please keep the
1031
+ * TRACE_DEFINE_ENUMs for it up to date.
9231032 */
924
-typedef enum xfs_dinode_fmt {
1033
+enum xfs_dinode_fmt {
9251034 XFS_DINODE_FMT_DEV, /* xfs_dev_t */
9261035 XFS_DINODE_FMT_LOCAL, /* bulk data */
9271036 XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */
9281037 XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */
9291038 XFS_DINODE_FMT_UUID /* added long ago, but never used */
930
-} xfs_dinode_fmt_t;
1039
+};
1040
+
1041
+#define XFS_INODE_FORMAT_STR \
1042
+ { XFS_DINODE_FMT_DEV, "dev" }, \
1043
+ { XFS_DINODE_FMT_LOCAL, "local" }, \
1044
+ { XFS_DINODE_FMT_EXTENTS, "extent" }, \
1045
+ { XFS_DINODE_FMT_BTREE, "btree" }, \
1046
+ { XFS_DINODE_FMT_UUID, "uuid" }
9311047
9321048 /*
9331049 * Inode minimum and maximum sizes.
....@@ -940,23 +1056,22 @@
9401056 /*
9411057 * Inode size for given fs.
9421058 */
943
-#define XFS_LITINO(mp, version) \
944
- ((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version)))
1059
+#define XFS_DINODE_SIZE(sbp) \
1060
+ (xfs_sb_version_has_v3inode(sbp) ? \
1061
+ sizeof(struct xfs_dinode) : \
1062
+ offsetof(struct xfs_dinode, di_crc))
1063
+#define XFS_LITINO(mp) \
1064
+ ((mp)->m_sb.sb_inodesize - XFS_DINODE_SIZE(&(mp)->m_sb))
9451065
9461066 /*
9471067 * Inode data & attribute fork sizes, per inode.
9481068 */
949
-#define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0)
9501069 #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3))
9511070
9521071 #define XFS_DFORK_DSIZE(dip,mp) \
953
- (XFS_DFORK_Q(dip) ? \
954
- XFS_DFORK_BOFF(dip) : \
955
- XFS_LITINO(mp, (dip)->di_version))
1072
+ ((dip)->di_forkoff ? XFS_DFORK_BOFF(dip) : XFS_LITINO(mp))
9561073 #define XFS_DFORK_ASIZE(dip,mp) \
957
- (XFS_DFORK_Q(dip) ? \
958
- XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \
959
- 0)
1074
+ ((dip)->di_forkoff ? XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : 0)
9601075 #define XFS_DFORK_SIZE(dip,mp,w) \
9611076 ((w) == XFS_DATA_FORK ? \
9621077 XFS_DFORK_DSIZE(dip, mp) : \
....@@ -1048,12 +1163,22 @@
10481163 #define XFS_DIFLAG2_DAX_BIT 0 /* use DAX for this inode */
10491164 #define XFS_DIFLAG2_REFLINK_BIT 1 /* file's blocks may be shared */
10501165 #define XFS_DIFLAG2_COWEXTSIZE_BIT 2 /* copy on write extent size hint */
1166
+#define XFS_DIFLAG2_BIGTIME_BIT 3 /* big timestamps */
1167
+
10511168 #define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT)
10521169 #define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT)
10531170 #define XFS_DIFLAG2_COWEXTSIZE (1 << XFS_DIFLAG2_COWEXTSIZE_BIT)
1171
+#define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT)
10541172
10551173 #define XFS_DIFLAG2_ANY \
1056
- (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE)
1174
+ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \
1175
+ XFS_DIFLAG2_BIGTIME)
1176
+
1177
+static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
1178
+{
1179
+ return dip->di_version >= 3 &&
1180
+ (dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_BIGTIME));
1181
+}
10571182
10581183 /*
10591184 * Inode number format:
....@@ -1065,7 +1190,7 @@
10651190 #define XFS_INO_MASK(k) (uint32_t)((1ULL << (k)) - 1)
10661191 #define XFS_INO_OFFSET_BITS(mp) (mp)->m_sb.sb_inopblog
10671192 #define XFS_INO_AGBNO_BITS(mp) (mp)->m_sb.sb_agblklog
1068
-#define XFS_INO_AGINO_BITS(mp) (mp)->m_agino_log
1193
+#define XFS_INO_AGINO_BITS(mp) ((mp)->m_ino_geo.agino_log)
10691194 #define XFS_INO_AGNO_BITS(mp) (mp)->m_agno_log
10701195 #define XFS_INO_BITS(mp) \
10711196 XFS_INO_AGNO_BITS(mp) + XFS_INO_AGINO_BITS(mp)
....@@ -1087,6 +1212,8 @@
10871212 ((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
10881213 #define XFS_OFFBNO_TO_AGINO(mp,b,o) \
10891214 ((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o)))
1215
+#define XFS_FSB_TO_INO(mp, b) ((xfs_ino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
1216
+#define XFS_AGB_TO_AGINO(mp, b) ((xfs_agino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
10901217
10911218 #define XFS_MAXINUMBER ((xfs_ino_t)((1ULL << 56) - 1ULL))
10921219 #define XFS_MAXINUMBER_32 ((xfs_ino_t)((1ULL << 32) - 1ULL))
....@@ -1134,16 +1261,111 @@
11341261 #define XFS_DQUOT_MAGIC 0x4451 /* 'DQ' */
11351262 #define XFS_DQUOT_VERSION (uint8_t)0x01 /* latest version number */
11361263
1264
+#define XFS_DQTYPE_USER 0x01 /* user dquot record */
1265
+#define XFS_DQTYPE_PROJ 0x02 /* project dquot record */
1266
+#define XFS_DQTYPE_GROUP 0x04 /* group dquot record */
1267
+#define XFS_DQTYPE_BIGTIME 0x80 /* large expiry timestamps */
1268
+
1269
+/* bitmask to determine if this is a user/group/project dquot */
1270
+#define XFS_DQTYPE_REC_MASK (XFS_DQTYPE_USER | \
1271
+ XFS_DQTYPE_PROJ | \
1272
+ XFS_DQTYPE_GROUP)
1273
+
1274
+#define XFS_DQTYPE_ANY (XFS_DQTYPE_REC_MASK | \
1275
+ XFS_DQTYPE_BIGTIME)
1276
+
11371277 /*
1138
- * This is the main portion of the on-disk representation of quota
1139
- * information for a user. This is the q_core of the xfs_dquot_t that
1140
- * is kept in kernel memory. We pad this with some more expansion room
1141
- * to construct the on disk structure.
1278
+ * XFS Quota Timers
1279
+ * ================
1280
+ *
1281
+ * Traditional quota grace period expiration timers are an unsigned 32-bit
1282
+ * seconds counter; time zero is the Unix epoch, Jan 1 00:00:01 UTC 1970.
1283
+ * Note that an expiration value of zero means that the quota limit has not
1284
+ * been reached, and therefore no expiration has been set. Therefore, the
1285
+ * ondisk min and max defined here can be used directly to constrain the incore
1286
+ * quota expiration timestamps on a Unix system.
1287
+ *
1288
+ * When bigtime is enabled, we trade two bits of precision to expand the
1289
+ * expiration timeout range to match that of big inode timestamps. The min and
1290
+ * max recorded here are the on-disk limits, not a Unix timestamp.
1291
+ *
1292
+ * The grace period for each quota type is stored in the root dquot (id = 0)
1293
+ * and is applied to a non-root dquot when it exceeds the soft or hard limits.
1294
+ * The length of quota grace periods are unsigned 32-bit quantities measured in
1295
+ * units of seconds. A value of zero means to use the default period.
11421296 */
1143
-typedef struct xfs_disk_dquot {
1297
+
1298
+/*
1299
+ * Smallest possible ondisk quota expiration value with traditional timestamps.
1300
+ * This corresponds exactly with the incore expiration Jan 1 00:00:01 UTC 1970.
1301
+ */
1302
+#define XFS_DQ_LEGACY_EXPIRY_MIN ((int64_t)1)
1303
+
1304
+/*
1305
+ * Largest possible ondisk quota expiration value with traditional timestamps.
1306
+ * This corresponds exactly with the incore expiration Feb 7 06:28:15 UTC 2106.
1307
+ */
1308
+#define XFS_DQ_LEGACY_EXPIRY_MAX ((int64_t)U32_MAX)
1309
+
1310
+/*
1311
+ * Smallest possible ondisk quota expiration value with bigtime timestamps.
1312
+ * This corresponds (after conversion to a Unix timestamp) with the incore
1313
+ * expiration of Jan 1 00:00:04 UTC 1970.
1314
+ */
1315
+#define XFS_DQ_BIGTIME_EXPIRY_MIN (XFS_DQ_LEGACY_EXPIRY_MIN)
1316
+
1317
+/*
1318
+ * Largest supported ondisk quota expiration value with bigtime timestamps.
1319
+ * This corresponds (after conversion to a Unix timestamp) with an incore
1320
+ * expiration of Jul 2 20:20:24 UTC 2486.
1321
+ *
1322
+ * The ondisk field supports values up to -1U, which corresponds to an incore
1323
+ * expiration in 2514. This is beyond the maximum the bigtime inode timestamp,
1324
+ * so we cap the maximum bigtime quota expiration to the max inode timestamp.
1325
+ */
1326
+#define XFS_DQ_BIGTIME_EXPIRY_MAX ((int64_t)4074815106U)
1327
+
1328
+/*
1329
+ * The following conversion factors assist in converting a quota expiration
1330
+ * timestamp between the incore and ondisk formats.
1331
+ */
1332
+#define XFS_DQ_BIGTIME_SHIFT (2)
1333
+#define XFS_DQ_BIGTIME_SLACK ((int64_t)(1ULL << XFS_DQ_BIGTIME_SHIFT) - 1)
1334
+
1335
+/* Convert an incore quota expiration timestamp to an ondisk bigtime value. */
1336
+static inline uint32_t xfs_dq_unix_to_bigtime(time64_t unix_seconds)
1337
+{
1338
+ /*
1339
+ * Round the expiration timestamp up to the nearest bigtime timestamp
1340
+ * that we can store, to give users the most time to fix problems.
1341
+ */
1342
+ return ((uint64_t)unix_seconds + XFS_DQ_BIGTIME_SLACK) >>
1343
+ XFS_DQ_BIGTIME_SHIFT;
1344
+}
1345
+
1346
+/* Convert an ondisk bigtime quota expiration value to an incore timestamp. */
1347
+static inline time64_t xfs_dq_bigtime_to_unix(uint32_t ondisk_seconds)
1348
+{
1349
+ return (time64_t)ondisk_seconds << XFS_DQ_BIGTIME_SHIFT;
1350
+}
1351
+
1352
+/*
1353
+ * Default quota grace periods, ranging from zero (use the compiled defaults)
1354
+ * to ~136 years. These are applied to a non-root dquot that has exceeded
1355
+ * either limit.
1356
+ */
1357
+#define XFS_DQ_GRACE_MIN ((int64_t)0)
1358
+#define XFS_DQ_GRACE_MAX ((int64_t)U32_MAX)
1359
+
1360
+/*
1361
+ * This is the main portion of the on-disk representation of quota information
1362
+ * for a user. We pad this with some more expansion room to construct the on
1363
+ * disk structure.
1364
+ */
1365
+struct xfs_disk_dquot {
11441366 __be16 d_magic; /* dquot magic = XFS_DQUOT_MAGIC */
11451367 __u8 d_version; /* dquot version */
1146
- __u8 d_flags; /* XFS_DQ_USER/PROJ/GROUP */
1368
+ __u8 d_type; /* XFS_DQTYPE_USER/PROJ/GROUP */
11471369 __be32 d_id; /* user,project,group id */
11481370 __be64 d_blk_hardlimit;/* absolute limit on disk blks */
11491371 __be64 d_blk_softlimit;/* preferred limit on disk blks */
....@@ -1163,15 +1385,15 @@
11631385 __be32 d_rtbtimer; /* similar to above; for RT disk blocks */
11641386 __be16 d_rtbwarns; /* warnings issued wrt RT disk blocks */
11651387 __be16 d_pad;
1166
-} xfs_disk_dquot_t;
1388
+};
11671389
11681390 /*
11691391 * This is what goes on disk. This is separated from the xfs_disk_dquot because
11701392 * carrying the unnecessary padding would be a waste of memory.
11711393 */
11721394 typedef struct xfs_dqblk {
1173
- xfs_disk_dquot_t dd_diskdq; /* portion that lives incore as well */
1174
- char dd_fill[4]; /* filling for posterity */
1395
+ struct xfs_disk_dquot dd_diskdq; /* portion living incore as well */
1396
+ char dd_fill[4];/* filling for posterity */
11751397
11761398 /*
11771399 * These two are only present on filesystems with the CRC bits set.
....@@ -1182,6 +1404,22 @@
11821404 } xfs_dqblk_t;
11831405
11841406 #define XFS_DQUOT_CRC_OFF offsetof(struct xfs_dqblk, dd_crc)
1407
+
1408
+/*
1409
+ * This defines the unit of allocation of dquots.
1410
+ *
1411
+ * Currently, it is just one file system block, and a 4K blk contains 30
1412
+ * (136 * 30 = 4080) dquots. It's probably not worth trying to make
1413
+ * this more dynamic.
1414
+ *
1415
+ * However, if this number is changed, we have to make sure that we don't
1416
+ * implicitly assume that we do allocations in chunks of a single filesystem
1417
+ * block in the dquot/xqm code.
1418
+ *
1419
+ * This is part of the ondisk format because the structure size is not a power
1420
+ * of two, which leaves slack at the end of the disk block.
1421
+ */
1422
+#define XFS_DQUOT_CLUSTER_SIZE_FSB (xfs_filblks_t)1
11851423
11861424 /*
11871425 * Remote symlink format and access functions.
....@@ -1532,6 +1770,13 @@
15321770 #define BMBT_BLOCKCOUNT_BITLEN 21
15331771
15341772 #define BMBT_STARTOFF_MASK ((1ULL << BMBT_STARTOFF_BITLEN) - 1)
1773
+#define BMBT_BLOCKCOUNT_MASK ((1ULL << BMBT_BLOCKCOUNT_BITLEN) - 1)
1774
+
1775
+/*
1776
+ * bmbt records have a file offset (block) field that is 54 bits wide, so this
1777
+ * is the largest xfs_fileoff_t that we ever expect to see.
1778
+ */
1779
+#define XFS_MAX_FILEOFF (BMBT_STARTOFF_MASK + BMBT_BLOCKCOUNT_MASK)
15351780
15361781 typedef struct xfs_bmbt_rec {
15371782 __be64 l0, l1;
....@@ -1658,7 +1903,7 @@
16581903
16591904 struct xfs_acl {
16601905 __be32 acl_cnt;
1661
- struct xfs_acl_entry acl_entry[0];
1906
+ struct xfs_acl_entry acl_entry[];
16621907 };
16631908
16641909 /*