inode.c 32 KB

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