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