inode.c 32 KB

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