inode.c 32 KB

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