inode.c 33 KB

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