inode.c 33 KB

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