inode.c 32 KB

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