inode.c 33 KB

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