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