inode.c 32 KB

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