inode.c 33 KB

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