inode.c 32 KB

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