Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1+ WITH Linux-syscall-note */
0002 /*
0003  * nilfs2_api.h - NILFS2 user space API
0004  *
0005  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
0006  *
0007  * This program is free software; you can redistribute it and/or modify
0008  * it under the terms of the GNU Lesser General Public License as published
0009  * by the Free Software Foundation; either version 2.1 of the License, or
0010  * (at your option) any later version.
0011  */
0012 
0013 #ifndef _LINUX_NILFS2_API_H
0014 #define _LINUX_NILFS2_API_H
0015 
0016 #include <linux/types.h>
0017 #include <linux/ioctl.h>
0018 
0019 /**
0020  * struct nilfs_cpinfo - checkpoint information
0021  * @ci_flags: flags
0022  * @ci_pad: padding
0023  * @ci_cno: checkpoint number
0024  * @ci_create: creation timestamp
0025  * @ci_nblk_inc: number of blocks incremented by this checkpoint
0026  * @ci_inodes_count: inodes count
0027  * @ci_blocks_count: blocks count
0028  * @ci_next: next checkpoint number in snapshot list
0029  */
0030 struct nilfs_cpinfo {
0031     __u32 ci_flags;
0032     __u32 ci_pad;
0033     __u64 ci_cno;
0034     __u64 ci_create;
0035     __u64 ci_nblk_inc;
0036     __u64 ci_inodes_count;
0037     __u64 ci_blocks_count;
0038     __u64 ci_next;
0039 };
0040 
0041 /* checkpoint flags */
0042 enum {
0043     NILFS_CPINFO_SNAPSHOT,
0044     NILFS_CPINFO_INVALID,
0045     NILFS_CPINFO_SKETCH,
0046     NILFS_CPINFO_MINOR,
0047 };
0048 
0049 #define NILFS_CPINFO_FNS(flag, name)                    \
0050 static inline int                           \
0051 nilfs_cpinfo_##name(const struct nilfs_cpinfo *cpinfo)          \
0052 {                                   \
0053     return !!(cpinfo->ci_flags & (1UL << NILFS_CPINFO_##flag)); \
0054 }
0055 
0056 NILFS_CPINFO_FNS(SNAPSHOT, snapshot)
0057 NILFS_CPINFO_FNS(INVALID, invalid)
0058 NILFS_CPINFO_FNS(MINOR, minor)
0059 
0060 /**
0061  * nilfs_suinfo - segment usage information
0062  * @sui_lastmod: timestamp of last modification
0063  * @sui_nblocks: number of written blocks in segment
0064  * @sui_flags: segment usage flags
0065  */
0066 struct nilfs_suinfo {
0067     __u64 sui_lastmod;
0068     __u32 sui_nblocks;
0069     __u32 sui_flags;
0070 };
0071 
0072 /* segment usage flags */
0073 enum {
0074     NILFS_SUINFO_ACTIVE,
0075     NILFS_SUINFO_DIRTY,
0076     NILFS_SUINFO_ERROR,
0077 };
0078 
0079 #define NILFS_SUINFO_FNS(flag, name)                    \
0080 static inline int                           \
0081 nilfs_suinfo_##name(const struct nilfs_suinfo *si)          \
0082 {                                   \
0083     return si->sui_flags & (1UL << NILFS_SUINFO_##flag);        \
0084 }
0085 
0086 NILFS_SUINFO_FNS(ACTIVE, active)
0087 NILFS_SUINFO_FNS(DIRTY, dirty)
0088 NILFS_SUINFO_FNS(ERROR, error)
0089 
0090 static inline int nilfs_suinfo_clean(const struct nilfs_suinfo *si)
0091 {
0092     return !si->sui_flags;
0093 }
0094 
0095 /**
0096  * nilfs_suinfo_update - segment usage information update
0097  * @sup_segnum: segment number
0098  * @sup_flags: flags for which fields are active in sup_sui
0099  * @sup_reserved: reserved necessary for alignment
0100  * @sup_sui: segment usage information
0101  */
0102 struct nilfs_suinfo_update {
0103     __u64 sup_segnum;
0104     __u32 sup_flags;
0105     __u32 sup_reserved;
0106     struct nilfs_suinfo sup_sui;
0107 };
0108 
0109 enum {
0110     NILFS_SUINFO_UPDATE_LASTMOD,
0111     NILFS_SUINFO_UPDATE_NBLOCKS,
0112     NILFS_SUINFO_UPDATE_FLAGS,
0113     __NR_NILFS_SUINFO_UPDATE_FIELDS,
0114 };
0115 
0116 #define NILFS_SUINFO_UPDATE_FNS(flag, name)             \
0117 static inline void                          \
0118 nilfs_suinfo_update_set_##name(struct nilfs_suinfo_update *sup)     \
0119 {                                   \
0120     sup->sup_flags |= 1UL << NILFS_SUINFO_UPDATE_##flag;        \
0121 }                                   \
0122 static inline void                          \
0123 nilfs_suinfo_update_clear_##name(struct nilfs_suinfo_update *sup)   \
0124 {                                   \
0125     sup->sup_flags &= ~(1UL << NILFS_SUINFO_UPDATE_##flag);     \
0126 }                                   \
0127 static inline int                           \
0128 nilfs_suinfo_update_##name(const struct nilfs_suinfo_update *sup)   \
0129 {                                   \
0130     return !!(sup->sup_flags & (1UL << NILFS_SUINFO_UPDATE_##flag));\
0131 }
0132 
0133 NILFS_SUINFO_UPDATE_FNS(LASTMOD, lastmod)
0134 NILFS_SUINFO_UPDATE_FNS(NBLOCKS, nblocks)
0135 NILFS_SUINFO_UPDATE_FNS(FLAGS, flags)
0136 
0137 enum {
0138     NILFS_CHECKPOINT,
0139     NILFS_SNAPSHOT,
0140 };
0141 
0142 /**
0143  * struct nilfs_cpmode - change checkpoint mode structure
0144  * @cm_cno: checkpoint number
0145  * @cm_mode: mode of checkpoint
0146  * @cm_pad: padding
0147  */
0148 struct nilfs_cpmode {
0149     __u64 cm_cno;
0150     __u32 cm_mode;
0151     __u32 cm_pad;
0152 };
0153 
0154 /**
0155  * struct nilfs_argv - argument vector
0156  * @v_base: pointer on data array from userspace
0157  * @v_nmembs: number of members in data array
0158  * @v_size: size of data array in bytes
0159  * @v_flags: flags
0160  * @v_index: start number of target data items
0161  */
0162 struct nilfs_argv {
0163     __u64 v_base;
0164     __u32 v_nmembs; /* number of members */
0165     __u16 v_size;   /* size of members */
0166     __u16 v_flags;
0167     __u64 v_index;
0168 };
0169 
0170 /**
0171  * struct nilfs_period - period of checkpoint numbers
0172  * @p_start: start checkpoint number (inclusive)
0173  * @p_end: end checkpoint number (exclusive)
0174  */
0175 struct nilfs_period {
0176     __u64 p_start;
0177     __u64 p_end;
0178 };
0179 
0180 /**
0181  * struct nilfs_cpstat - checkpoint statistics
0182  * @cs_cno: checkpoint number
0183  * @cs_ncps: number of checkpoints
0184  * @cs_nsss: number of snapshots
0185  */
0186 struct nilfs_cpstat {
0187     __u64 cs_cno;
0188     __u64 cs_ncps;
0189     __u64 cs_nsss;
0190 };
0191 
0192 /**
0193  * struct nilfs_sustat - segment usage statistics
0194  * @ss_nsegs: number of segments
0195  * @ss_ncleansegs: number of clean segments
0196  * @ss_ndirtysegs: number of dirty segments
0197  * @ss_ctime: creation time of the last segment
0198  * @ss_nongc_ctime: creation time of the last segment not for GC
0199  * @ss_prot_seq: least sequence number of segments which must not be reclaimed
0200  */
0201 struct nilfs_sustat {
0202     __u64 ss_nsegs;
0203     __u64 ss_ncleansegs;
0204     __u64 ss_ndirtysegs;
0205     __u64 ss_ctime;
0206     __u64 ss_nongc_ctime;
0207     __u64 ss_prot_seq;
0208 };
0209 
0210 /**
0211  * struct nilfs_vinfo - virtual block number information
0212  * @vi_vblocknr: virtual block number
0213  * @vi_start: start checkpoint number (inclusive)
0214  * @vi_end: end checkpoint number (exclusive)
0215  * @vi_blocknr: disk block number
0216  */
0217 struct nilfs_vinfo {
0218     __u64 vi_vblocknr;
0219     __u64 vi_start;
0220     __u64 vi_end;
0221     __u64 vi_blocknr;
0222 };
0223 
0224 /**
0225  * struct nilfs_vdesc - descriptor of virtual block number
0226  * @vd_ino: inode number
0227  * @vd_cno: checkpoint number
0228  * @vd_vblocknr: virtual block number
0229  * @vd_period: period of checkpoint numbers
0230  * @vd_blocknr: disk block number
0231  * @vd_offset: logical block offset inside a file
0232  * @vd_flags: flags (data or node block)
0233  * @vd_pad: padding
0234  */
0235 struct nilfs_vdesc {
0236     __u64 vd_ino;
0237     __u64 vd_cno;
0238     __u64 vd_vblocknr;
0239     struct nilfs_period vd_period;
0240     __u64 vd_blocknr;
0241     __u64 vd_offset;
0242     __u32 vd_flags;
0243     __u32 vd_pad;
0244 };
0245 
0246 /**
0247  * struct nilfs_bdesc - descriptor of disk block number
0248  * @bd_ino: inode number
0249  * @bd_oblocknr: disk block address (for skipping dead blocks)
0250  * @bd_blocknr: disk block address
0251  * @bd_offset: logical block offset inside a file
0252  * @bd_level: level in the b-tree organization
0253  * @bd_pad: padding
0254  */
0255 struct nilfs_bdesc {
0256     __u64 bd_ino;
0257     __u64 bd_oblocknr;
0258     __u64 bd_blocknr;
0259     __u64 bd_offset;
0260     __u32 bd_level;
0261     __u32 bd_pad;
0262 };
0263 
0264 #define NILFS_IOCTL_IDENT   'n'
0265 
0266 #define NILFS_IOCTL_CHANGE_CPMODE                   \
0267     _IOW(NILFS_IOCTL_IDENT, 0x80, struct nilfs_cpmode)
0268 #define NILFS_IOCTL_DELETE_CHECKPOINT                   \
0269     _IOW(NILFS_IOCTL_IDENT, 0x81, __u64)
0270 #define NILFS_IOCTL_GET_CPINFO                      \
0271     _IOR(NILFS_IOCTL_IDENT, 0x82, struct nilfs_argv)
0272 #define NILFS_IOCTL_GET_CPSTAT                      \
0273     _IOR(NILFS_IOCTL_IDENT, 0x83, struct nilfs_cpstat)
0274 #define NILFS_IOCTL_GET_SUINFO                      \
0275     _IOR(NILFS_IOCTL_IDENT, 0x84, struct nilfs_argv)
0276 #define NILFS_IOCTL_GET_SUSTAT                      \
0277     _IOR(NILFS_IOCTL_IDENT, 0x85, struct nilfs_sustat)
0278 #define NILFS_IOCTL_GET_VINFO                       \
0279     _IOWR(NILFS_IOCTL_IDENT, 0x86, struct nilfs_argv)
0280 #define NILFS_IOCTL_GET_BDESCS                      \
0281     _IOWR(NILFS_IOCTL_IDENT, 0x87, struct nilfs_argv)
0282 #define NILFS_IOCTL_CLEAN_SEGMENTS                  \
0283     _IOW(NILFS_IOCTL_IDENT, 0x88, struct nilfs_argv[5])
0284 #define NILFS_IOCTL_SYNC                        \
0285     _IOR(NILFS_IOCTL_IDENT, 0x8A, __u64)
0286 #define NILFS_IOCTL_RESIZE                      \
0287     _IOW(NILFS_IOCTL_IDENT, 0x8B, __u64)
0288 #define NILFS_IOCTL_SET_ALLOC_RANGE                 \
0289     _IOW(NILFS_IOCTL_IDENT, 0x8C, __u64[2])
0290 #define NILFS_IOCTL_SET_SUINFO                      \
0291     _IOW(NILFS_IOCTL_IDENT, 0x8D, struct nilfs_argv)
0292 
0293 #endif /* _LINUX_NILFS2_API_H */