2 * fscrypt_common.h: common declarations for per-file encryption
4 * Copyright (C) 2015, Google, Inc.
6 * Written by Michael Halcrow, 2015.
7 * Modified by Jaegeuk Kim, 2015.
10 #ifndef _LINUX_FSCRYPT_COMMON_H
11 #define _LINUX_FSCRYPT_COMMON_H
13 #include <linux/key.h>
16 #include <linux/bio.h>
17 #include <linux/dcache.h>
18 #include <crypto/skcipher.h>
19 #include <uapi/linux/fs.h>
21 #define FS_CRYPTO_BLOCK_SIZE 16
28 struct page *bounce_page; /* Ciphertext page */
29 struct page *control_page; /* Original page */
33 struct work_struct work;
35 struct list_head free_list; /* Free list */
41 * For encrypted symlinks, the ciphertext length is stored at the beginning
42 * of the string in little-endian format.
44 struct fscrypt_symlink_data {
46 char encrypted_path[1];
50 * This function is used to calculate the disk space required to
51 * store a filename of length l in encrypted symlink format.
53 static inline u32 fscrypt_symlink_data_len(u32 l)
55 if (l < FS_CRYPTO_BLOCK_SIZE)
56 l = FS_CRYPTO_BLOCK_SIZE;
57 return (l + sizeof(struct fscrypt_symlink_data) - 1);
66 const struct qstr *usr_fname;
67 struct fscrypt_str disk_name;
70 struct fscrypt_str crypto_buf;
73 #define FSTR_INIT(n, l) { .name = n, .len = l }
74 #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
75 #define fname_name(p) ((p)->disk_name.name)
76 #define fname_len(p) ((p)->disk_name.len)
79 * fscrypt superblock flags
81 #define FS_CFLG_OWN_PAGES (1U << 1)
84 * crypto opertions for filesystems
86 struct fscrypt_operations {
88 const char *key_prefix;
89 int (*get_context)(struct inode *, void *, size_t);
90 int (*prepare_context)(struct inode *);
91 int (*set_context)(struct inode *, const void *, size_t, void *);
92 int (*dummy_context)(struct inode *);
93 bool (*is_encrypted)(struct inode *);
94 bool (*empty_dir)(struct inode *);
95 unsigned (*max_namelen)(struct inode *);
98 static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
100 if (inode->i_sb->s_cop->dummy_context &&
101 inode->i_sb->s_cop->dummy_context(inode))
106 static inline bool fscrypt_valid_contents_enc_mode(u32 mode)
108 return (mode == FS_ENCRYPTION_MODE_AES_256_XTS);
111 static inline bool fscrypt_valid_filenames_enc_mode(u32 mode)
113 return (mode == FS_ENCRYPTION_MODE_AES_256_CTS);
116 static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
118 if (str->len == 1 && str->name[0] == '.')
121 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
127 static inline struct page *fscrypt_control_page(struct page *page)
129 #if IS_ENABLED(CONFIG_FS_ENCRYPTION)
130 return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
133 return ERR_PTR(-EINVAL);
137 static inline int fscrypt_has_encryption_key(const struct inode *inode)
139 #if IS_ENABLED(CONFIG_FS_ENCRYPTION)
140 return (inode->i_crypt_info != NULL);
146 #endif /* _LINUX_FSCRYPT_COMMON_H */