inode.c 32 KB

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