inode.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. /**
  2. * eCryptfs: Linux filesystem encryption layer
  3. *
  4. * Copyright (C) 1997-2004 Erez Zadok
  5. * Copyright (C) 2001-2004 Stony Brook University
  6. * Copyright (C) 2004-2007 International Business Machines Corp.
  7. * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  8. * Michael C. Thompsion <mcthomps@us.ibm.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. * 02111-1307, USA.
  24. */
  25. #include <linux/file.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/dcache.h>
  29. #include <linux/namei.h>
  30. #include <linux/mount.h>
  31. #include <linux/crypto.h>
  32. #include <linux/fs_stack.h>
  33. #include <linux/slab.h>
  34. #include <linux/xattr.h>
  35. #include <asm/unaligned.h>
  36. #include "ecryptfs_kernel.h"
  37. static struct dentry *lock_parent(struct dentry *dentry)
  38. {
  39. struct dentry *dir;
  40. dir = dget_parent(dentry);
  41. mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT);
  42. return dir;
  43. }
  44. static void unlock_dir(struct dentry *dir)
  45. {
  46. mutex_unlock(&dir->d_inode->i_mutex);
  47. dput(dir);
  48. }
  49. static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
  50. {
  51. return ecryptfs_inode_to_lower(inode) == lower_inode;
  52. }
  53. static int ecryptfs_inode_set(struct inode *inode, void *opaque)
  54. {
  55. struct inode *lower_inode = opaque;
  56. ecryptfs_set_inode_lower(inode, lower_inode);
  57. fsstack_copy_attr_all(inode, lower_inode);
  58. /* i_size will be overwritten for encrypted regular files */
  59. fsstack_copy_inode_size(inode, lower_inode);
  60. inode->i_ino = lower_inode->i_ino;
  61. inode->i_version++;
  62. inode->i_mapping->a_ops = &ecryptfs_aops;
  63. inode->i_mapping->backing_dev_info = inode->i_sb->s_bdi;
  64. if (S_ISLNK(inode->i_mode))
  65. inode->i_op = &ecryptfs_symlink_iops;
  66. else if (S_ISDIR(inode->i_mode))
  67. inode->i_op = &ecryptfs_dir_iops;
  68. else
  69. inode->i_op = &ecryptfs_main_iops;
  70. if (S_ISDIR(inode->i_mode))
  71. inode->i_fop = &ecryptfs_dir_fops;
  72. else if (special_file(inode->i_mode))
  73. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  74. else
  75. inode->i_fop = &ecryptfs_main_fops;
  76. return 0;
  77. }
  78. static struct inode *__ecryptfs_get_inode(struct inode *lower_inode,
  79. struct super_block *sb)
  80. {
  81. struct inode *inode;
  82. if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb))
  83. return ERR_PTR(-EXDEV);
  84. if (!igrab(lower_inode))
  85. return ERR_PTR(-ESTALE);
  86. inode = iget5_locked(sb, (unsigned long)lower_inode,
  87. ecryptfs_inode_test, ecryptfs_inode_set,
  88. lower_inode);
  89. if (!inode) {
  90. iput(lower_inode);
  91. return ERR_PTR(-EACCES);
  92. }
  93. if (!(inode->i_state & I_NEW))
  94. iput(lower_inode);
  95. return inode;
  96. }
  97. struct inode *ecryptfs_get_inode(struct inode *lower_inode,
  98. struct super_block *sb)
  99. {
  100. struct inode *inode = __ecryptfs_get_inode(lower_inode, sb);
  101. if (!IS_ERR(inode) && (inode->i_state & I_NEW))
  102. unlock_new_inode(inode);
  103. return inode;
  104. }
  105. /**
  106. * ecryptfs_interpose
  107. * @lower_dentry: Existing dentry in the lower filesystem
  108. * @dentry: ecryptfs' dentry
  109. * @sb: ecryptfs's super_block
  110. *
  111. * Interposes upper and lower dentries.
  112. *
  113. * Returns zero on success; non-zero otherwise
  114. */
  115. static int ecryptfs_interpose(struct dentry *lower_dentry,
  116. struct dentry *dentry, struct super_block *sb)
  117. {
  118. struct inode *inode = ecryptfs_get_inode(lower_dentry->d_inode, sb);
  119. if (IS_ERR(inode))
  120. return PTR_ERR(inode);
  121. d_instantiate(dentry, inode);
  122. return 0;
  123. }
  124. static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry,
  125. struct inode *inode)
  126. {
  127. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  128. struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
  129. struct dentry *lower_dir_dentry;
  130. int rc;
  131. dget(lower_dentry);
  132. lower_dir_dentry = lock_parent(lower_dentry);
  133. rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
  134. if (rc) {
  135. printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
  136. goto out_unlock;
  137. }
  138. fsstack_copy_attr_times(dir, lower_dir_inode);
  139. set_nlink(inode, ecryptfs_inode_to_lower(inode)->i_nlink);
  140. inode->i_ctime = dir->i_ctime;
  141. d_drop(dentry);
  142. out_unlock:
  143. unlock_dir(lower_dir_dentry);
  144. dput(lower_dentry);
  145. return rc;
  146. }
  147. /**
  148. * ecryptfs_do_create
  149. * @directory_inode: inode of the new file's dentry's parent in ecryptfs
  150. * @ecryptfs_dentry: New file's dentry in ecryptfs
  151. * @mode: The mode of the new file
  152. * @nd: nameidata of ecryptfs' parent's dentry & vfsmount
  153. *
  154. * Creates the underlying file and the eCryptfs inode which will link to
  155. * it. It will also update the eCryptfs directory inode to mimic the
  156. * stat of the lower directory inode.
  157. *
  158. * Returns the new eCryptfs inode on success; an ERR_PTR on error condition
  159. */
  160. static struct inode *
  161. ecryptfs_do_create(struct inode *directory_inode,
  162. struct dentry *ecryptfs_dentry, umode_t mode)
  163. {
  164. int rc;
  165. struct dentry *lower_dentry;
  166. struct dentry *lower_dir_dentry;
  167. struct inode *inode;
  168. lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
  169. lower_dir_dentry = lock_parent(lower_dentry);
  170. if (IS_ERR(lower_dir_dentry)) {
  171. ecryptfs_printk(KERN_ERR, "Error locking directory of "
  172. "dentry\n");
  173. inode = ERR_CAST(lower_dir_dentry);
  174. goto out;
  175. }
  176. rc = vfs_create(lower_dir_dentry->d_inode, lower_dentry, mode, true);
  177. if (rc) {
  178. printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
  179. "rc = [%d]\n", __func__, rc);
  180. inode = ERR_PTR(rc);
  181. goto out_lock;
  182. }
  183. inode = __ecryptfs_get_inode(lower_dentry->d_inode,
  184. directory_inode->i_sb);
  185. if (IS_ERR(inode)) {
  186. vfs_unlink(lower_dir_dentry->d_inode, lower_dentry, NULL);
  187. goto out_lock;
  188. }
  189. fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode);
  190. fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
  191. out_lock:
  192. unlock_dir(lower_dir_dentry);
  193. out:
  194. return inode;
  195. }
  196. /**
  197. * ecryptfs_initialize_file
  198. *
  199. * Cause the file to be changed from a basic empty file to an ecryptfs
  200. * file with a header and first data page.
  201. *
  202. * Returns zero on success
  203. */
  204. int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
  205. struct inode *ecryptfs_inode)
  206. {
  207. struct ecryptfs_crypt_stat *crypt_stat =
  208. &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
  209. int rc = 0;
  210. if (S_ISDIR(ecryptfs_inode->i_mode)) {
  211. ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
  212. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  213. goto out;
  214. }
  215. ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
  216. rc = ecryptfs_new_file_context(ecryptfs_inode);
  217. if (rc) {
  218. ecryptfs_printk(KERN_ERR, "Error creating new file "
  219. "context; rc = [%d]\n", rc);
  220. goto out;
  221. }
  222. rc = ecryptfs_get_lower_file(ecryptfs_dentry, ecryptfs_inode);
  223. if (rc) {
  224. printk(KERN_ERR "%s: Error attempting to initialize "
  225. "the lower file for the dentry with name "
  226. "[%pd]; rc = [%d]\n", __func__,
  227. ecryptfs_dentry, rc);
  228. goto out;
  229. }
  230. rc = ecryptfs_write_metadata(ecryptfs_dentry, ecryptfs_inode);
  231. if (rc)
  232. printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc);
  233. ecryptfs_put_lower_file(ecryptfs_inode);
  234. out:
  235. return rc;
  236. }
  237. /**
  238. * ecryptfs_create
  239. * @dir: The inode of the directory in which to create the file.
  240. * @dentry: The eCryptfs dentry
  241. * @mode: The mode of the new file.
  242. *
  243. * Creates a new file.
  244. *
  245. * Returns zero on success; non-zero on error condition
  246. */
  247. static int
  248. ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
  249. umode_t mode, bool excl)
  250. {
  251. struct inode *ecryptfs_inode;
  252. int rc;
  253. ecryptfs_inode = ecryptfs_do_create(directory_inode, ecryptfs_dentry,
  254. mode);
  255. if (unlikely(IS_ERR(ecryptfs_inode))) {
  256. ecryptfs_printk(KERN_WARNING, "Failed to create file in"
  257. "lower filesystem\n");
  258. rc = PTR_ERR(ecryptfs_inode);
  259. goto out;
  260. }
  261. /* At this point, a file exists on "disk"; we need to make sure
  262. * that this on disk file is prepared to be an ecryptfs file */
  263. rc = ecryptfs_initialize_file(ecryptfs_dentry, ecryptfs_inode);
  264. if (rc) {
  265. ecryptfs_do_unlink(directory_inode, ecryptfs_dentry,
  266. ecryptfs_inode);
  267. make_bad_inode(ecryptfs_inode);
  268. unlock_new_inode(ecryptfs_inode);
  269. iput(ecryptfs_inode);
  270. goto out;
  271. }
  272. unlock_new_inode(ecryptfs_inode);
  273. d_instantiate(ecryptfs_dentry, ecryptfs_inode);
  274. out:
  275. return rc;
  276. }
  277. static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
  278. {
  279. struct ecryptfs_crypt_stat *crypt_stat;
  280. int rc;
  281. rc = ecryptfs_get_lower_file(dentry, inode);
  282. if (rc) {
  283. printk(KERN_ERR "%s: Error attempting to initialize "
  284. "the lower file for the dentry with name "
  285. "[%pd]; rc = [%d]\n", __func__,
  286. dentry, rc);
  287. return rc;
  288. }
  289. crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
  290. /* TODO: lock for crypt_stat comparison */
  291. if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
  292. ecryptfs_set_default_sizes(crypt_stat);
  293. rc = ecryptfs_read_and_validate_header_region(inode);
  294. ecryptfs_put_lower_file(inode);
  295. if (rc) {
  296. rc = ecryptfs_read_and_validate_xattr_region(dentry, inode);
  297. if (!rc)
  298. crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
  299. }
  300. /* Must return 0 to allow non-eCryptfs files to be looked up, too */
  301. return 0;
  302. }
  303. /**
  304. * ecryptfs_lookup_interpose - Dentry interposition for a lookup
  305. */
  306. static int ecryptfs_lookup_interpose(struct dentry *dentry,
  307. struct dentry *lower_dentry,
  308. struct inode *dir_inode)
  309. {
  310. struct inode *inode, *lower_inode = lower_dentry->d_inode;
  311. struct ecryptfs_dentry_info *dentry_info;
  312. struct vfsmount *lower_mnt;
  313. int rc = 0;
  314. dentry_info = kmem_cache_alloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
  315. if (!dentry_info) {
  316. printk(KERN_ERR "%s: Out of memory whilst attempting "
  317. "to allocate ecryptfs_dentry_info struct\n",
  318. __func__);
  319. dput(lower_dentry);
  320. return -ENOMEM;
  321. }
  322. lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
  323. fsstack_copy_attr_atime(dir_inode, lower_dentry->d_parent->d_inode);
  324. BUG_ON(!d_count(lower_dentry));
  325. ecryptfs_set_dentry_private(dentry, dentry_info);
  326. dentry_info->lower_path.mnt = lower_mnt;
  327. dentry_info->lower_path.dentry = lower_dentry;
  328. if (!lower_dentry->d_inode) {
  329. /* We want to add because we couldn't find in lower */
  330. d_add(dentry, NULL);
  331. return 0;
  332. }
  333. inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb);
  334. if (IS_ERR(inode)) {
  335. printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
  336. __func__, PTR_ERR(inode));
  337. return PTR_ERR(inode);
  338. }
  339. if (S_ISREG(inode->i_mode)) {
  340. rc = ecryptfs_i_size_read(dentry, inode);
  341. if (rc) {
  342. make_bad_inode(inode);
  343. return rc;
  344. }
  345. }
  346. if (inode->i_state & I_NEW)
  347. unlock_new_inode(inode);
  348. d_add(dentry, inode);
  349. return rc;
  350. }
  351. /**
  352. * ecryptfs_lookup
  353. * @ecryptfs_dir_inode: The eCryptfs directory inode
  354. * @ecryptfs_dentry: The eCryptfs dentry that we are looking up
  355. * @ecryptfs_nd: nameidata; may be NULL
  356. *
  357. * Find a file on disk. If the file does not exist, then we'll add it to the
  358. * dentry cache and continue on to read it from the disk.
  359. */
  360. static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
  361. struct dentry *ecryptfs_dentry,
  362. unsigned int flags)
  363. {
  364. char *encrypted_and_encoded_name = NULL;
  365. size_t encrypted_and_encoded_name_size;
  366. struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
  367. struct dentry *lower_dir_dentry, *lower_dentry;
  368. int rc = 0;
  369. lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
  370. mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
  371. lower_dentry = lookup_one_len(ecryptfs_dentry->d_name.name,
  372. lower_dir_dentry,
  373. ecryptfs_dentry->d_name.len);
  374. mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
  375. if (IS_ERR(lower_dentry)) {
  376. rc = PTR_ERR(lower_dentry);
  377. ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
  378. "[%d] on lower_dentry = [%pd]\n", __func__, rc,
  379. ecryptfs_dentry);
  380. goto out;
  381. }
  382. if (lower_dentry->d_inode)
  383. goto interpose;
  384. mount_crypt_stat = &ecryptfs_superblock_to_private(
  385. ecryptfs_dentry->d_sb)->mount_crypt_stat;
  386. if (!(mount_crypt_stat
  387. && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)))
  388. goto interpose;
  389. dput(lower_dentry);
  390. rc = ecryptfs_encrypt_and_encode_filename(
  391. &encrypted_and_encoded_name, &encrypted_and_encoded_name_size,
  392. NULL, mount_crypt_stat, ecryptfs_dentry->d_name.name,
  393. ecryptfs_dentry->d_name.len);
  394. if (rc) {
  395. printk(KERN_ERR "%s: Error attempting to encrypt and encode "
  396. "filename; rc = [%d]\n", __func__, rc);
  397. goto out;
  398. }
  399. mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
  400. lower_dentry = lookup_one_len(encrypted_and_encoded_name,
  401. lower_dir_dentry,
  402. encrypted_and_encoded_name_size);
  403. mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
  404. if (IS_ERR(lower_dentry)) {
  405. rc = PTR_ERR(lower_dentry);
  406. ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
  407. "[%d] on lower_dentry = [%s]\n", __func__, rc,
  408. encrypted_and_encoded_name);
  409. goto out;
  410. }
  411. interpose:
  412. rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry,
  413. ecryptfs_dir_inode);
  414. out:
  415. kfree(encrypted_and_encoded_name);
  416. return ERR_PTR(rc);
  417. }
  418. static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
  419. struct dentry *new_dentry)
  420. {
  421. struct dentry *lower_old_dentry;
  422. struct dentry *lower_new_dentry;
  423. struct dentry *lower_dir_dentry;
  424. u64 file_size_save;
  425. int rc;
  426. file_size_save = i_size_read(old_dentry->d_inode);
  427. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  428. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  429. dget(lower_old_dentry);
  430. dget(lower_new_dentry);
  431. lower_dir_dentry = lock_parent(lower_new_dentry);
  432. rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
  433. lower_new_dentry, NULL);
  434. if (rc || !lower_new_dentry->d_inode)
  435. goto out_lock;
  436. rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb);
  437. if (rc)
  438. goto out_lock;
  439. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  440. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  441. set_nlink(old_dentry->d_inode,
  442. ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink);
  443. i_size_write(new_dentry->d_inode, file_size_save);
  444. out_lock:
  445. unlock_dir(lower_dir_dentry);
  446. dput(lower_new_dentry);
  447. dput(lower_old_dentry);
  448. return rc;
  449. }
  450. static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
  451. {
  452. return ecryptfs_do_unlink(dir, dentry, dentry->d_inode);
  453. }
  454. static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
  455. const char *symname)
  456. {
  457. int rc;
  458. struct dentry *lower_dentry;
  459. struct dentry *lower_dir_dentry;
  460. char *encoded_symname;
  461. size_t encoded_symlen;
  462. struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
  463. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  464. dget(lower_dentry);
  465. lower_dir_dentry = lock_parent(lower_dentry);
  466. mount_crypt_stat = &ecryptfs_superblock_to_private(
  467. dir->i_sb)->mount_crypt_stat;
  468. rc = ecryptfs_encrypt_and_encode_filename(&encoded_symname,
  469. &encoded_symlen,
  470. NULL,
  471. mount_crypt_stat, symname,
  472. strlen(symname));
  473. if (rc)
  474. goto out_lock;
  475. rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
  476. encoded_symname);
  477. kfree(encoded_symname);
  478. if (rc || !lower_dentry->d_inode)
  479. goto out_lock;
  480. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  481. if (rc)
  482. goto out_lock;
  483. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  484. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  485. out_lock:
  486. unlock_dir(lower_dir_dentry);
  487. dput(lower_dentry);
  488. if (!dentry->d_inode)
  489. d_drop(dentry);
  490. return rc;
  491. }
  492. static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  493. {
  494. int rc;
  495. struct dentry *lower_dentry;
  496. struct dentry *lower_dir_dentry;
  497. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  498. lower_dir_dentry = lock_parent(lower_dentry);
  499. rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
  500. if (rc || !lower_dentry->d_inode)
  501. goto out;
  502. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  503. if (rc)
  504. goto out;
  505. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  506. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  507. set_nlink(dir, lower_dir_dentry->d_inode->i_nlink);
  508. out:
  509. unlock_dir(lower_dir_dentry);
  510. if (!dentry->d_inode)
  511. d_drop(dentry);
  512. return rc;
  513. }
  514. static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
  515. {
  516. struct dentry *lower_dentry;
  517. struct dentry *lower_dir_dentry;
  518. int rc;
  519. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  520. dget(dentry);
  521. lower_dir_dentry = lock_parent(lower_dentry);
  522. dget(lower_dentry);
  523. rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
  524. dput(lower_dentry);
  525. if (!rc && dentry->d_inode)
  526. clear_nlink(dentry->d_inode);
  527. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  528. set_nlink(dir, lower_dir_dentry->d_inode->i_nlink);
  529. unlock_dir(lower_dir_dentry);
  530. if (!rc)
  531. d_drop(dentry);
  532. dput(dentry);
  533. return rc;
  534. }
  535. static int
  536. ecryptfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
  537. {
  538. int rc;
  539. struct dentry *lower_dentry;
  540. struct dentry *lower_dir_dentry;
  541. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  542. lower_dir_dentry = lock_parent(lower_dentry);
  543. rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
  544. if (rc || !lower_dentry->d_inode)
  545. goto out;
  546. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  547. if (rc)
  548. goto out;
  549. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  550. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  551. out:
  552. unlock_dir(lower_dir_dentry);
  553. if (!dentry->d_inode)
  554. d_drop(dentry);
  555. return rc;
  556. }
  557. static int
  558. ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  559. struct inode *new_dir, struct dentry *new_dentry)
  560. {
  561. int rc;
  562. struct dentry *lower_old_dentry;
  563. struct dentry *lower_new_dentry;
  564. struct dentry *lower_old_dir_dentry;
  565. struct dentry *lower_new_dir_dentry;
  566. struct dentry *trap = NULL;
  567. struct inode *target_inode;
  568. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  569. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  570. dget(lower_old_dentry);
  571. dget(lower_new_dentry);
  572. lower_old_dir_dentry = dget_parent(lower_old_dentry);
  573. lower_new_dir_dentry = dget_parent(lower_new_dentry);
  574. target_inode = new_dentry->d_inode;
  575. trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  576. /* source should not be ancestor of target */
  577. if (trap == lower_old_dentry) {
  578. rc = -EINVAL;
  579. goto out_lock;
  580. }
  581. /* target should not be ancestor of source */
  582. if (trap == lower_new_dentry) {
  583. rc = -ENOTEMPTY;
  584. goto out_lock;
  585. }
  586. rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
  587. lower_new_dir_dentry->d_inode, lower_new_dentry,
  588. NULL);
  589. if (rc)
  590. goto out_lock;
  591. if (target_inode)
  592. fsstack_copy_attr_all(target_inode,
  593. ecryptfs_inode_to_lower(target_inode));
  594. fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode);
  595. if (new_dir != old_dir)
  596. fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode);
  597. out_lock:
  598. unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  599. dput(lower_new_dir_dentry);
  600. dput(lower_old_dir_dentry);
  601. dput(lower_new_dentry);
  602. dput(lower_old_dentry);
  603. return rc;
  604. }
  605. static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
  606. size_t *bufsiz)
  607. {
  608. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  609. char *lower_buf;
  610. mm_segment_t old_fs;
  611. int rc;
  612. lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
  613. if (!lower_buf) {
  614. rc = -ENOMEM;
  615. goto out;
  616. }
  617. old_fs = get_fs();
  618. set_fs(get_ds());
  619. rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
  620. (char __user *)lower_buf,
  621. PATH_MAX);
  622. set_fs(old_fs);
  623. if (rc < 0)
  624. goto out;
  625. rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry->d_sb,
  626. lower_buf, rc);
  627. out:
  628. kfree(lower_buf);
  629. return rc;
  630. }
  631. static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  632. {
  633. char *buf;
  634. size_t len = PATH_MAX;
  635. int rc;
  636. rc = ecryptfs_readlink_lower(dentry, &buf, &len);
  637. if (rc)
  638. goto out;
  639. fsstack_copy_attr_atime(dentry->d_inode,
  640. ecryptfs_dentry_to_lower(dentry)->d_inode);
  641. buf[len] = '\0';
  642. out:
  643. nd_set_link(nd, buf);
  644. return NULL;
  645. }
  646. /**
  647. * upper_size_to_lower_size
  648. * @crypt_stat: Crypt_stat associated with file
  649. * @upper_size: Size of the upper file
  650. *
  651. * Calculate the required size of the lower file based on the
  652. * specified size of the upper file. This calculation is based on the
  653. * number of headers in the underlying file and the extent size.
  654. *
  655. * Returns Calculated size of the lower file.
  656. */
  657. static loff_t
  658. upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
  659. loff_t upper_size)
  660. {
  661. loff_t lower_size;
  662. lower_size = ecryptfs_lower_header_size(crypt_stat);
  663. if (upper_size != 0) {
  664. loff_t num_extents;
  665. num_extents = upper_size >> crypt_stat->extent_shift;
  666. if (upper_size & ~crypt_stat->extent_mask)
  667. num_extents++;
  668. lower_size += (num_extents * crypt_stat->extent_size);
  669. }
  670. return lower_size;
  671. }
  672. /**
  673. * truncate_upper
  674. * @dentry: The ecryptfs layer dentry
  675. * @ia: Address of the ecryptfs inode's attributes
  676. * @lower_ia: Address of the lower inode's attributes
  677. *
  678. * Function to handle truncations modifying the size of the file. Note
  679. * that the file sizes are interpolated. When expanding, we are simply
  680. * writing strings of 0's out. When truncating, we truncate the upper
  681. * inode and update the lower_ia according to the page index
  682. * interpolations. If ATTR_SIZE is set in lower_ia->ia_valid upon return,
  683. * the caller must use lower_ia in a call to notify_change() to perform
  684. * the truncation of the lower inode.
  685. *
  686. * Returns zero on success; non-zero otherwise
  687. */
  688. static int truncate_upper(struct dentry *dentry, struct iattr *ia,
  689. struct iattr *lower_ia)
  690. {
  691. int rc = 0;
  692. struct inode *inode = dentry->d_inode;
  693. struct ecryptfs_crypt_stat *crypt_stat;
  694. loff_t i_size = i_size_read(inode);
  695. loff_t lower_size_before_truncate;
  696. loff_t lower_size_after_truncate;
  697. if (unlikely((ia->ia_size == i_size))) {
  698. lower_ia->ia_valid &= ~ATTR_SIZE;
  699. return 0;
  700. }
  701. rc = ecryptfs_get_lower_file(dentry, inode);
  702. if (rc)
  703. return rc;
  704. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  705. /* Switch on growing or shrinking file */
  706. if (ia->ia_size > i_size) {
  707. char zero[] = { 0x00 };
  708. lower_ia->ia_valid &= ~ATTR_SIZE;
  709. /* Write a single 0 at the last position of the file;
  710. * this triggers code that will fill in 0's throughout
  711. * the intermediate portion of the previous end of the
  712. * file and the new and of the file */
  713. rc = ecryptfs_write(inode, zero,
  714. (ia->ia_size - 1), 1);
  715. } else { /* ia->ia_size < i_size_read(inode) */
  716. /* We're chopping off all the pages down to the page
  717. * in which ia->ia_size is located. Fill in the end of
  718. * that page from (ia->ia_size & ~PAGE_CACHE_MASK) to
  719. * PAGE_CACHE_SIZE with zeros. */
  720. size_t num_zeros = (PAGE_CACHE_SIZE
  721. - (ia->ia_size & ~PAGE_CACHE_MASK));
  722. if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
  723. truncate_setsize(inode, ia->ia_size);
  724. lower_ia->ia_size = ia->ia_size;
  725. lower_ia->ia_valid |= ATTR_SIZE;
  726. goto out;
  727. }
  728. if (num_zeros) {
  729. char *zeros_virt;
  730. zeros_virt = kzalloc(num_zeros, GFP_KERNEL);
  731. if (!zeros_virt) {
  732. rc = -ENOMEM;
  733. goto out;
  734. }
  735. rc = ecryptfs_write(inode, zeros_virt,
  736. ia->ia_size, num_zeros);
  737. kfree(zeros_virt);
  738. if (rc) {
  739. printk(KERN_ERR "Error attempting to zero out "
  740. "the remainder of the end page on "
  741. "reducing truncate; rc = [%d]\n", rc);
  742. goto out;
  743. }
  744. }
  745. truncate_setsize(inode, ia->ia_size);
  746. rc = ecryptfs_write_inode_size_to_metadata(inode);
  747. if (rc) {
  748. printk(KERN_ERR "Problem with "
  749. "ecryptfs_write_inode_size_to_metadata; "
  750. "rc = [%d]\n", rc);
  751. goto out;
  752. }
  753. /* We are reducing the size of the ecryptfs file, and need to
  754. * know if we need to reduce the size of the lower file. */
  755. lower_size_before_truncate =
  756. upper_size_to_lower_size(crypt_stat, i_size);
  757. lower_size_after_truncate =
  758. upper_size_to_lower_size(crypt_stat, ia->ia_size);
  759. if (lower_size_after_truncate < lower_size_before_truncate) {
  760. lower_ia->ia_size = lower_size_after_truncate;
  761. lower_ia->ia_valid |= ATTR_SIZE;
  762. } else
  763. lower_ia->ia_valid &= ~ATTR_SIZE;
  764. }
  765. out:
  766. ecryptfs_put_lower_file(inode);
  767. return rc;
  768. }
  769. static int ecryptfs_inode_newsize_ok(struct inode *inode, loff_t offset)
  770. {
  771. struct ecryptfs_crypt_stat *crypt_stat;
  772. loff_t lower_oldsize, lower_newsize;
  773. crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
  774. lower_oldsize = upper_size_to_lower_size(crypt_stat,
  775. i_size_read(inode));
  776. lower_newsize = upper_size_to_lower_size(crypt_stat, offset);
  777. if (lower_newsize > lower_oldsize) {
  778. /*
  779. * The eCryptfs inode and the new *lower* size are mixed here
  780. * because we may not have the lower i_mutex held and/or it may
  781. * not be appropriate to call inode_newsize_ok() with inodes
  782. * from other filesystems.
  783. */
  784. return inode_newsize_ok(inode, lower_newsize);
  785. }
  786. return 0;
  787. }
  788. /**
  789. * ecryptfs_truncate
  790. * @dentry: The ecryptfs layer dentry
  791. * @new_length: The length to expand the file to
  792. *
  793. * Simple function that handles the truncation of an eCryptfs inode and
  794. * its corresponding lower inode.
  795. *
  796. * Returns zero on success; non-zero otherwise
  797. */
  798. int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
  799. {
  800. struct iattr ia = { .ia_valid = ATTR_SIZE, .ia_size = new_length };
  801. struct iattr lower_ia = { .ia_valid = 0 };
  802. int rc;
  803. rc = ecryptfs_inode_newsize_ok(dentry->d_inode, new_length);
  804. if (rc)
  805. return rc;
  806. rc = truncate_upper(dentry, &ia, &lower_ia);
  807. if (!rc && lower_ia.ia_valid & ATTR_SIZE) {
  808. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  809. mutex_lock(&lower_dentry->d_inode->i_mutex);
  810. rc = notify_change(lower_dentry, &lower_ia, NULL);
  811. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  812. }
  813. return rc;
  814. }
  815. static int
  816. ecryptfs_permission(struct inode *inode, int mask)
  817. {
  818. return inode_permission(ecryptfs_inode_to_lower(inode), mask);
  819. }
  820. /**
  821. * ecryptfs_setattr
  822. * @dentry: dentry handle to the inode to modify
  823. * @ia: Structure with flags of what to change and values
  824. *
  825. * Updates the metadata of an inode. If the update is to the size
  826. * i.e. truncation, then ecryptfs_truncate will handle the size modification
  827. * of both the ecryptfs inode and the lower inode.
  828. *
  829. * All other metadata changes will be passed right to the lower filesystem,
  830. * and we will just update our inode to look like the lower.
  831. */
  832. static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
  833. {
  834. int rc = 0;
  835. struct dentry *lower_dentry;
  836. struct iattr lower_ia;
  837. struct inode *inode;
  838. struct inode *lower_inode;
  839. struct ecryptfs_crypt_stat *crypt_stat;
  840. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  841. if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED))
  842. ecryptfs_init_crypt_stat(crypt_stat);
  843. inode = dentry->d_inode;
  844. lower_inode = ecryptfs_inode_to_lower(inode);
  845. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  846. mutex_lock(&crypt_stat->cs_mutex);
  847. if (S_ISDIR(dentry->d_inode->i_mode))
  848. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  849. else if (S_ISREG(dentry->d_inode->i_mode)
  850. && (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
  851. || !(crypt_stat->flags & ECRYPTFS_KEY_VALID))) {
  852. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  853. mount_crypt_stat = &ecryptfs_superblock_to_private(
  854. dentry->d_sb)->mount_crypt_stat;
  855. rc = ecryptfs_get_lower_file(dentry, inode);
  856. if (rc) {
  857. mutex_unlock(&crypt_stat->cs_mutex);
  858. goto out;
  859. }
  860. rc = ecryptfs_read_metadata(dentry);
  861. ecryptfs_put_lower_file(inode);
  862. if (rc) {
  863. if (!(mount_crypt_stat->flags
  864. & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
  865. rc = -EIO;
  866. printk(KERN_WARNING "Either the lower file "
  867. "is not in a valid eCryptfs format, "
  868. "or the key could not be retrieved. "
  869. "Plaintext passthrough mode is not "
  870. "enabled; returning -EIO\n");
  871. mutex_unlock(&crypt_stat->cs_mutex);
  872. goto out;
  873. }
  874. rc = 0;
  875. crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
  876. | ECRYPTFS_ENCRYPTED);
  877. }
  878. }
  879. mutex_unlock(&crypt_stat->cs_mutex);
  880. rc = inode_change_ok(inode, ia);
  881. if (rc)
  882. goto out;
  883. if (ia->ia_valid & ATTR_SIZE) {
  884. rc = ecryptfs_inode_newsize_ok(inode, ia->ia_size);
  885. if (rc)
  886. goto out;
  887. }
  888. memcpy(&lower_ia, ia, sizeof(lower_ia));
  889. if (ia->ia_valid & ATTR_FILE)
  890. lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);
  891. if (ia->ia_valid & ATTR_SIZE) {
  892. rc = truncate_upper(dentry, ia, &lower_ia);
  893. if (rc < 0)
  894. goto out;
  895. }
  896. /*
  897. * mode change is for clearing setuid/setgid bits. Allow lower fs
  898. * to interpret this in its own way.
  899. */
  900. if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
  901. lower_ia.ia_valid &= ~ATTR_MODE;
  902. mutex_lock(&lower_dentry->d_inode->i_mutex);
  903. rc = notify_change(lower_dentry, &lower_ia, NULL);
  904. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  905. out:
  906. fsstack_copy_attr_all(inode, lower_inode);
  907. return rc;
  908. }
  909. static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
  910. struct kstat *stat)
  911. {
  912. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  913. int rc = 0;
  914. mount_crypt_stat = &ecryptfs_superblock_to_private(
  915. dentry->d_sb)->mount_crypt_stat;
  916. generic_fillattr(dentry->d_inode, stat);
  917. if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) {
  918. char *target;
  919. size_t targetsiz;
  920. rc = ecryptfs_readlink_lower(dentry, &target, &targetsiz);
  921. if (!rc) {
  922. kfree(target);
  923. stat->size = targetsiz;
  924. }
  925. }
  926. return rc;
  927. }
  928. static int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  929. struct kstat *stat)
  930. {
  931. struct kstat lower_stat;
  932. int rc;
  933. rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat);
  934. if (!rc) {
  935. fsstack_copy_attr_all(dentry->d_inode,
  936. ecryptfs_inode_to_lower(dentry->d_inode));
  937. generic_fillattr(dentry->d_inode, stat);
  938. stat->blocks = lower_stat.blocks;
  939. }
  940. return rc;
  941. }
  942. int
  943. ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  944. size_t size, int flags)
  945. {
  946. int rc = 0;
  947. struct dentry *lower_dentry;
  948. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  949. if (!lower_dentry->d_inode->i_op->setxattr) {
  950. rc = -EOPNOTSUPP;
  951. goto out;
  952. }
  953. rc = vfs_setxattr(lower_dentry, name, value, size, flags);
  954. if (!rc)
  955. fsstack_copy_attr_all(dentry->d_inode, lower_dentry->d_inode);
  956. out:
  957. return rc;
  958. }
  959. ssize_t
  960. ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
  961. void *value, size_t size)
  962. {
  963. int rc = 0;
  964. if (!lower_dentry->d_inode->i_op->getxattr) {
  965. rc = -EOPNOTSUPP;
  966. goto out;
  967. }
  968. mutex_lock(&lower_dentry->d_inode->i_mutex);
  969. rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value,
  970. size);
  971. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  972. out:
  973. return rc;
  974. }
  975. static ssize_t
  976. ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
  977. size_t size)
  978. {
  979. return ecryptfs_getxattr_lower(ecryptfs_dentry_to_lower(dentry), name,
  980. value, size);
  981. }
  982. static ssize_t
  983. ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size)
  984. {
  985. int rc = 0;
  986. struct dentry *lower_dentry;
  987. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  988. if (!lower_dentry->d_inode->i_op->listxattr) {
  989. rc = -EOPNOTSUPP;
  990. goto out;
  991. }
  992. mutex_lock(&lower_dentry->d_inode->i_mutex);
  993. rc = lower_dentry->d_inode->i_op->listxattr(lower_dentry, list, size);
  994. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  995. out:
  996. return rc;
  997. }
  998. static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
  999. {
  1000. int rc = 0;
  1001. struct dentry *lower_dentry;
  1002. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  1003. if (!lower_dentry->d_inode->i_op->removexattr) {
  1004. rc = -EOPNOTSUPP;
  1005. goto out;
  1006. }
  1007. mutex_lock(&lower_dentry->d_inode->i_mutex);
  1008. rc = lower_dentry->d_inode->i_op->removexattr(lower_dentry, name);
  1009. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  1010. out:
  1011. return rc;
  1012. }
  1013. const struct inode_operations ecryptfs_symlink_iops = {
  1014. .readlink = generic_readlink,
  1015. .follow_link = ecryptfs_follow_link,
  1016. .put_link = kfree_put_link,
  1017. .permission = ecryptfs_permission,
  1018. .setattr = ecryptfs_setattr,
  1019. .getattr = ecryptfs_getattr_link,
  1020. .setxattr = ecryptfs_setxattr,
  1021. .getxattr = ecryptfs_getxattr,
  1022. .listxattr = ecryptfs_listxattr,
  1023. .removexattr = ecryptfs_removexattr
  1024. };
  1025. const struct inode_operations ecryptfs_dir_iops = {
  1026. .create = ecryptfs_create,
  1027. .lookup = ecryptfs_lookup,
  1028. .link = ecryptfs_link,
  1029. .unlink = ecryptfs_unlink,
  1030. .symlink = ecryptfs_symlink,
  1031. .mkdir = ecryptfs_mkdir,
  1032. .rmdir = ecryptfs_rmdir,
  1033. .mknod = ecryptfs_mknod,
  1034. .rename = ecryptfs_rename,
  1035. .permission = ecryptfs_permission,
  1036. .setattr = ecryptfs_setattr,
  1037. .setxattr = ecryptfs_setxattr,
  1038. .getxattr = ecryptfs_getxattr,
  1039. .listxattr = ecryptfs_listxattr,
  1040. .removexattr = ecryptfs_removexattr
  1041. };
  1042. const struct inode_operations ecryptfs_main_iops = {
  1043. .permission = ecryptfs_permission,
  1044. .setattr = ecryptfs_setattr,
  1045. .getattr = ecryptfs_getattr,
  1046. .setxattr = ecryptfs_setxattr,
  1047. .getxattr = ecryptfs_getxattr,
  1048. .listxattr = ecryptfs_listxattr,
  1049. .removexattr = ecryptfs_removexattr
  1050. };