inode.c 32 KB

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