xattr.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * This file is part of UBIFS.
  3. *
  4. * Copyright (C) 2006-2008 Nokia Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc., 51
  17. * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * Authors: Artem Bityutskiy (Битюцкий Артём)
  20. * Adrian Hunter
  21. */
  22. /*
  23. * This file implements UBIFS extended attributes support.
  24. *
  25. * Extended attributes are implemented as regular inodes with attached data,
  26. * which limits extended attribute size to UBIFS block size (4KiB). Names of
  27. * extended attributes are described by extended attribute entries (xentries),
  28. * which are almost identical to directory entries, but have different key type.
  29. *
  30. * In other words, the situation with extended attributes is very similar to
  31. * directories. Indeed, any inode (but of course not xattr inodes) may have a
  32. * number of associated xentries, just like directory inodes have associated
  33. * directory entries. Extended attribute entries store the name of the extended
  34. * attribute, the host inode number, and the extended attribute inode number.
  35. * Similarly, direntries store the name, the parent and the target inode
  36. * numbers. Thus, most of the common UBIFS mechanisms may be re-used for
  37. * extended attributes.
  38. *
  39. * The number of extended attributes is not limited, but there is Linux
  40. * limitation on the maximum possible size of the list of all extended
  41. * attributes associated with an inode (%XATTR_LIST_MAX), so UBIFS makes sure
  42. * the sum of all extended attribute names of the inode does not exceed that
  43. * limit.
  44. *
  45. * Extended attributes are synchronous, which means they are written to the
  46. * flash media synchronously and there is no write-back for extended attribute
  47. * inodes. The extended attribute values are not stored in compressed form on
  48. * the media.
  49. *
  50. * Since extended attributes are represented by regular inodes, they are cached
  51. * in the VFS inode cache. The xentries are cached in the LNC cache (see
  52. * tnc.c).
  53. *
  54. * ACL support is not implemented.
  55. */
  56. #include "ubifs.h"
  57. #include <linux/fs.h>
  58. #include <linux/slab.h>
  59. #include <linux/xattr.h>
  60. /*
  61. * Limit the number of extended attributes per inode so that the total size
  62. * (@xattr_size) is guaranteeded to fit in an 'unsigned int'.
  63. */
  64. #define MAX_XATTRS_PER_INODE 65535
  65. /*
  66. * Extended attribute type constants.
  67. *
  68. * USER_XATTR: user extended attribute ("user.*")
  69. * TRUSTED_XATTR: trusted extended attribute ("trusted.*)
  70. * SECURITY_XATTR: security extended attribute ("security.*")
  71. */
  72. enum {
  73. USER_XATTR,
  74. TRUSTED_XATTR,
  75. SECURITY_XATTR,
  76. };
  77. static const struct inode_operations empty_iops;
  78. static const struct file_operations empty_fops;
  79. /**
  80. * create_xattr - create an extended attribute.
  81. * @c: UBIFS file-system description object
  82. * @host: host inode
  83. * @nm: extended attribute name
  84. * @value: extended attribute value
  85. * @size: size of extended attribute value
  86. *
  87. * This is a helper function which creates an extended attribute of name @nm
  88. * and value @value for inode @host. The host inode is also updated on flash
  89. * because the ctime and extended attribute accounting data changes. This
  90. * function returns zero in case of success and a negative error code in case
  91. * of failure.
  92. */
  93. static int create_xattr(struct ubifs_info *c, struct inode *host,
  94. const struct fscrypt_name *nm, const void *value, int size)
  95. {
  96. int err, names_len;
  97. struct inode *inode;
  98. struct ubifs_inode *ui, *host_ui = ubifs_inode(host);
  99. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  100. .new_ino_d = ALIGN(size, 8), .dirtied_ino = 1,
  101. .dirtied_ino_d = ALIGN(host_ui->data_len, 8) };
  102. if (host_ui->xattr_cnt >= MAX_XATTRS_PER_INODE) {
  103. ubifs_err(c, "inode %lu already has too many xattrs (%d), cannot create more",
  104. host->i_ino, host_ui->xattr_cnt);
  105. return -ENOSPC;
  106. }
  107. /*
  108. * Linux limits the maximum size of the extended attribute names list
  109. * to %XATTR_LIST_MAX. This means we should not allow creating more
  110. * extended attributes if the name list becomes larger. This limitation
  111. * is artificial for UBIFS, though.
  112. */
  113. names_len = host_ui->xattr_names + host_ui->xattr_cnt + fname_len(nm) + 1;
  114. if (names_len > XATTR_LIST_MAX) {
  115. ubifs_err(c, "cannot add one more xattr name to inode %lu, total names length would become %d, max. is %d",
  116. host->i_ino, names_len, XATTR_LIST_MAX);
  117. return -ENOSPC;
  118. }
  119. err = ubifs_budget_space(c, &req);
  120. if (err)
  121. return err;
  122. inode = ubifs_new_inode(c, host, S_IFREG | S_IRWXUGO);
  123. if (IS_ERR(inode)) {
  124. err = PTR_ERR(inode);
  125. goto out_budg;
  126. }
  127. /* Re-define all operations to be "nothing" */
  128. inode->i_mapping->a_ops = &empty_aops;
  129. inode->i_op = &empty_iops;
  130. inode->i_fop = &empty_fops;
  131. inode->i_flags |= S_SYNC | S_NOATIME | S_NOCMTIME | S_NOQUOTA;
  132. ui = ubifs_inode(inode);
  133. ui->xattr = 1;
  134. ui->flags |= UBIFS_XATTR_FL;
  135. ui->data = kmemdup(value, size, GFP_NOFS);
  136. if (!ui->data) {
  137. err = -ENOMEM;
  138. goto out_free;
  139. }
  140. inode->i_size = ui->ui_size = size;
  141. ui->data_len = size;
  142. mutex_lock(&host_ui->ui_mutex);
  143. host->i_ctime = ubifs_current_time(host);
  144. host_ui->xattr_cnt += 1;
  145. host_ui->xattr_size += CALC_DENT_SIZE(fname_len(nm));
  146. host_ui->xattr_size += CALC_XATTR_BYTES(size);
  147. host_ui->xattr_names += fname_len(nm);
  148. /*
  149. * We handle UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT here because we
  150. * have to set the UBIFS_CRYPT_FL flag on the host inode.
  151. * To avoid multiple updates of the same inode in the same operation,
  152. * let's do it here.
  153. */
  154. if (strcmp(fname_name(nm), UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
  155. host_ui->flags |= UBIFS_CRYPT_FL;
  156. err = ubifs_jnl_update(c, host, nm, inode, 0, 1);
  157. if (err)
  158. goto out_cancel;
  159. mutex_unlock(&host_ui->ui_mutex);
  160. ubifs_release_budget(c, &req);
  161. insert_inode_hash(inode);
  162. iput(inode);
  163. return 0;
  164. out_cancel:
  165. host_ui->xattr_cnt -= 1;
  166. host_ui->xattr_size -= CALC_DENT_SIZE(fname_len(nm));
  167. host_ui->xattr_size -= CALC_XATTR_BYTES(size);
  168. host_ui->xattr_names -= fname_len(nm);
  169. host_ui->flags &= ~UBIFS_CRYPT_FL;
  170. mutex_unlock(&host_ui->ui_mutex);
  171. out_free:
  172. make_bad_inode(inode);
  173. iput(inode);
  174. out_budg:
  175. ubifs_release_budget(c, &req);
  176. return err;
  177. }
  178. /**
  179. * change_xattr - change an extended attribute.
  180. * @c: UBIFS file-system description object
  181. * @host: host inode
  182. * @inode: extended attribute inode
  183. * @value: extended attribute value
  184. * @size: size of extended attribute value
  185. *
  186. * This helper function changes the value of extended attribute @inode with new
  187. * data from @value. Returns zero in case of success and a negative error code
  188. * in case of failure.
  189. */
  190. static int change_xattr(struct ubifs_info *c, struct inode *host,
  191. struct inode *inode, const void *value, int size)
  192. {
  193. int err;
  194. struct ubifs_inode *host_ui = ubifs_inode(host);
  195. struct ubifs_inode *ui = ubifs_inode(inode);
  196. void *buf = NULL;
  197. int old_size;
  198. struct ubifs_budget_req req = { .dirtied_ino = 2,
  199. .dirtied_ino_d = ALIGN(size, 8) + ALIGN(host_ui->data_len, 8) };
  200. ubifs_assert(ui->data_len == inode->i_size);
  201. err = ubifs_budget_space(c, &req);
  202. if (err)
  203. return err;
  204. buf = kmemdup(value, size, GFP_NOFS);
  205. if (!buf) {
  206. err = -ENOMEM;
  207. goto out_free;
  208. }
  209. mutex_lock(&ui->ui_mutex);
  210. kfree(ui->data);
  211. ui->data = buf;
  212. inode->i_size = ui->ui_size = size;
  213. old_size = ui->data_len;
  214. ui->data_len = size;
  215. mutex_unlock(&ui->ui_mutex);
  216. mutex_lock(&host_ui->ui_mutex);
  217. host->i_ctime = ubifs_current_time(host);
  218. host_ui->xattr_size -= CALC_XATTR_BYTES(old_size);
  219. host_ui->xattr_size += CALC_XATTR_BYTES(size);
  220. /*
  221. * It is important to write the host inode after the xattr inode
  222. * because if the host inode gets synchronized (via 'fsync()'), then
  223. * the extended attribute inode gets synchronized, because it goes
  224. * before the host inode in the write-buffer.
  225. */
  226. err = ubifs_jnl_change_xattr(c, inode, host);
  227. if (err)
  228. goto out_cancel;
  229. mutex_unlock(&host_ui->ui_mutex);
  230. ubifs_release_budget(c, &req);
  231. return 0;
  232. out_cancel:
  233. host_ui->xattr_size -= CALC_XATTR_BYTES(size);
  234. host_ui->xattr_size += CALC_XATTR_BYTES(old_size);
  235. mutex_unlock(&host_ui->ui_mutex);
  236. make_bad_inode(inode);
  237. out_free:
  238. ubifs_release_budget(c, &req);
  239. return err;
  240. }
  241. static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
  242. {
  243. struct inode *inode;
  244. inode = ubifs_iget(c->vfs_sb, inum);
  245. if (IS_ERR(inode)) {
  246. ubifs_err(c, "dead extended attribute entry, error %d",
  247. (int)PTR_ERR(inode));
  248. return inode;
  249. }
  250. if (ubifs_inode(inode)->xattr)
  251. return inode;
  252. ubifs_err(c, "corrupt extended attribute entry");
  253. iput(inode);
  254. return ERR_PTR(-EINVAL);
  255. }
  256. int ubifs_xattr_set(struct inode *host, const char *name, const void *value,
  257. size_t size, int flags)
  258. {
  259. struct inode *inode;
  260. struct ubifs_info *c = host->i_sb->s_fs_info;
  261. struct fscrypt_name nm = { .disk_name = FSTR_INIT((char *)name, strlen(name))};
  262. struct ubifs_dent_node *xent;
  263. union ubifs_key key;
  264. int err;
  265. /*
  266. * Creating an encryption context is done unlocked since we
  267. * operate on a new inode which is not visible to other users
  268. * at this point.
  269. */
  270. if (strcmp(name, UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) != 0)
  271. ubifs_assert(inode_is_locked(host));
  272. if (size > UBIFS_MAX_INO_DATA)
  273. return -ERANGE;
  274. if (fname_len(&nm) > UBIFS_MAX_NLEN)
  275. return -ENAMETOOLONG;
  276. xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS);
  277. if (!xent)
  278. return -ENOMEM;
  279. /*
  280. * The extended attribute entries are stored in LNC, so multiple
  281. * look-ups do not involve reading the flash.
  282. */
  283. xent_key_init(c, &key, host->i_ino, &nm);
  284. err = ubifs_tnc_lookup_nm(c, &key, xent, &nm);
  285. if (err) {
  286. if (err != -ENOENT)
  287. goto out_free;
  288. if (flags & XATTR_REPLACE)
  289. /* We are asked not to create the xattr */
  290. err = -ENODATA;
  291. else
  292. err = create_xattr(c, host, &nm, value, size);
  293. goto out_free;
  294. }
  295. if (flags & XATTR_CREATE) {
  296. /* We are asked not to replace the xattr */
  297. err = -EEXIST;
  298. goto out_free;
  299. }
  300. inode = iget_xattr(c, le64_to_cpu(xent->inum));
  301. if (IS_ERR(inode)) {
  302. err = PTR_ERR(inode);
  303. goto out_free;
  304. }
  305. err = change_xattr(c, host, inode, value, size);
  306. iput(inode);
  307. out_free:
  308. kfree(xent);
  309. return err;
  310. }
  311. ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
  312. size_t size)
  313. {
  314. struct inode *inode;
  315. struct ubifs_info *c = host->i_sb->s_fs_info;
  316. struct fscrypt_name nm = { .disk_name = FSTR_INIT((char *)name, strlen(name))};
  317. struct ubifs_inode *ui;
  318. struct ubifs_dent_node *xent;
  319. union ubifs_key key;
  320. int err;
  321. if (fname_len(&nm) > UBIFS_MAX_NLEN)
  322. return -ENAMETOOLONG;
  323. xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS);
  324. if (!xent)
  325. return -ENOMEM;
  326. xent_key_init(c, &key, host->i_ino, &nm);
  327. err = ubifs_tnc_lookup_nm(c, &key, xent, &nm);
  328. if (err) {
  329. if (err == -ENOENT)
  330. err = -ENODATA;
  331. goto out_unlock;
  332. }
  333. inode = iget_xattr(c, le64_to_cpu(xent->inum));
  334. if (IS_ERR(inode)) {
  335. err = PTR_ERR(inode);
  336. goto out_unlock;
  337. }
  338. ui = ubifs_inode(inode);
  339. ubifs_assert(inode->i_size == ui->data_len);
  340. ubifs_assert(ubifs_inode(host)->xattr_size > ui->data_len);
  341. mutex_lock(&ui->ui_mutex);
  342. if (buf) {
  343. /* If @buf is %NULL we are supposed to return the length */
  344. if (ui->data_len > size) {
  345. ubifs_err(c, "buffer size %zd, xattr len %d",
  346. size, ui->data_len);
  347. err = -ERANGE;
  348. goto out_iput;
  349. }
  350. memcpy(buf, ui->data, ui->data_len);
  351. }
  352. err = ui->data_len;
  353. out_iput:
  354. mutex_unlock(&ui->ui_mutex);
  355. iput(inode);
  356. out_unlock:
  357. kfree(xent);
  358. return err;
  359. }
  360. static bool xattr_visible(const char *name)
  361. {
  362. /* File encryption related xattrs are for internal use only */
  363. if (strcmp(name, UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
  364. return false;
  365. /* Show trusted namespace only for "power" users */
  366. if (strncmp(name, XATTR_TRUSTED_PREFIX,
  367. XATTR_TRUSTED_PREFIX_LEN) == 0 && !capable(CAP_SYS_ADMIN))
  368. return false;
  369. return true;
  370. }
  371. ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
  372. {
  373. union ubifs_key key;
  374. struct inode *host = d_inode(dentry);
  375. struct ubifs_info *c = host->i_sb->s_fs_info;
  376. struct ubifs_inode *host_ui = ubifs_inode(host);
  377. struct ubifs_dent_node *xent, *pxent = NULL;
  378. int err, len, written = 0;
  379. struct fscrypt_name nm = {0};
  380. dbg_gen("ino %lu ('%pd'), buffer size %zd", host->i_ino,
  381. dentry, size);
  382. len = host_ui->xattr_names + host_ui->xattr_cnt;
  383. if (!buffer)
  384. /*
  385. * We should return the minimum buffer size which will fit a
  386. * null-terminated list of all the extended attribute names.
  387. */
  388. return len;
  389. if (len > size)
  390. return -ERANGE;
  391. lowest_xent_key(c, &key, host->i_ino);
  392. while (1) {
  393. xent = ubifs_tnc_next_ent(c, &key, &nm);
  394. if (IS_ERR(xent)) {
  395. err = PTR_ERR(xent);
  396. break;
  397. }
  398. fname_name(&nm) = xent->name;
  399. fname_len(&nm) = le16_to_cpu(xent->nlen);
  400. if (xattr_visible(xent->name)) {
  401. memcpy(buffer + written, fname_name(&nm), fname_len(&nm) + 1);
  402. written += fname_len(&nm) + 1;
  403. }
  404. kfree(pxent);
  405. pxent = xent;
  406. key_read(c, &xent->key, &key);
  407. }
  408. kfree(pxent);
  409. if (err != -ENOENT) {
  410. ubifs_err(c, "cannot find next direntry, error %d", err);
  411. return err;
  412. }
  413. ubifs_assert(written <= size);
  414. return written;
  415. }
  416. static int remove_xattr(struct ubifs_info *c, struct inode *host,
  417. struct inode *inode, const struct fscrypt_name *nm)
  418. {
  419. int err;
  420. struct ubifs_inode *host_ui = ubifs_inode(host);
  421. struct ubifs_inode *ui = ubifs_inode(inode);
  422. struct ubifs_budget_req req = { .dirtied_ino = 2, .mod_dent = 1,
  423. .dirtied_ino_d = ALIGN(host_ui->data_len, 8) };
  424. ubifs_assert(ui->data_len == inode->i_size);
  425. err = ubifs_budget_space(c, &req);
  426. if (err)
  427. return err;
  428. mutex_lock(&host_ui->ui_mutex);
  429. host->i_ctime = ubifs_current_time(host);
  430. host_ui->xattr_cnt -= 1;
  431. host_ui->xattr_size -= CALC_DENT_SIZE(fname_len(nm));
  432. host_ui->xattr_size -= CALC_XATTR_BYTES(ui->data_len);
  433. host_ui->xattr_names -= fname_len(nm);
  434. err = ubifs_jnl_delete_xattr(c, host, inode, nm);
  435. if (err)
  436. goto out_cancel;
  437. mutex_unlock(&host_ui->ui_mutex);
  438. ubifs_release_budget(c, &req);
  439. return 0;
  440. out_cancel:
  441. host_ui->xattr_cnt += 1;
  442. host_ui->xattr_size += CALC_DENT_SIZE(fname_len(nm));
  443. host_ui->xattr_size += CALC_XATTR_BYTES(ui->data_len);
  444. host_ui->xattr_names += fname_len(nm);
  445. mutex_unlock(&host_ui->ui_mutex);
  446. ubifs_release_budget(c, &req);
  447. make_bad_inode(inode);
  448. return err;
  449. }
  450. static int ubifs_xattr_remove(struct inode *host, const char *name)
  451. {
  452. struct inode *inode;
  453. struct ubifs_info *c = host->i_sb->s_fs_info;
  454. struct fscrypt_name nm = { .disk_name = FSTR_INIT((char *)name, strlen(name))};
  455. struct ubifs_dent_node *xent;
  456. union ubifs_key key;
  457. int err;
  458. ubifs_assert(inode_is_locked(host));
  459. if (fname_len(&nm) > UBIFS_MAX_NLEN)
  460. return -ENAMETOOLONG;
  461. xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS);
  462. if (!xent)
  463. return -ENOMEM;
  464. xent_key_init(c, &key, host->i_ino, &nm);
  465. err = ubifs_tnc_lookup_nm(c, &key, xent, &nm);
  466. if (err) {
  467. if (err == -ENOENT)
  468. err = -ENODATA;
  469. goto out_free;
  470. }
  471. inode = iget_xattr(c, le64_to_cpu(xent->inum));
  472. if (IS_ERR(inode)) {
  473. err = PTR_ERR(inode);
  474. goto out_free;
  475. }
  476. ubifs_assert(inode->i_nlink == 1);
  477. clear_nlink(inode);
  478. err = remove_xattr(c, host, inode, &nm);
  479. if (err)
  480. set_nlink(inode, 1);
  481. /* If @i_nlink is 0, 'iput()' will delete the inode */
  482. iput(inode);
  483. out_free:
  484. kfree(xent);
  485. return err;
  486. }
  487. static int init_xattrs(struct inode *inode, const struct xattr *xattr_array,
  488. void *fs_info)
  489. {
  490. const struct xattr *xattr;
  491. char *name;
  492. int err = 0;
  493. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  494. name = kmalloc(XATTR_SECURITY_PREFIX_LEN +
  495. strlen(xattr->name) + 1, GFP_NOFS);
  496. if (!name) {
  497. err = -ENOMEM;
  498. break;
  499. }
  500. strcpy(name, XATTR_SECURITY_PREFIX);
  501. strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name);
  502. err = ubifs_xattr_set(inode, name, xattr->value,
  503. xattr->value_len, 0);
  504. kfree(name);
  505. if (err < 0)
  506. break;
  507. }
  508. return err;
  509. }
  510. int ubifs_init_security(struct inode *dentry, struct inode *inode,
  511. const struct qstr *qstr)
  512. {
  513. int err;
  514. err = security_inode_init_security(inode, dentry, qstr,
  515. &init_xattrs, 0);
  516. if (err) {
  517. struct ubifs_info *c = dentry->i_sb->s_fs_info;
  518. ubifs_err(c, "cannot initialize security for inode %lu, error %d",
  519. inode->i_ino, err);
  520. }
  521. return err;
  522. }
  523. static int xattr_get(const struct xattr_handler *handler,
  524. struct dentry *dentry, struct inode *inode,
  525. const char *name, void *buffer, size_t size)
  526. {
  527. dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name,
  528. inode->i_ino, dentry, size);
  529. name = xattr_full_name(handler, name);
  530. return ubifs_xattr_get(inode, name, buffer, size);
  531. }
  532. static int xattr_set(const struct xattr_handler *handler,
  533. struct dentry *dentry, struct inode *inode,
  534. const char *name, const void *value,
  535. size_t size, int flags)
  536. {
  537. dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd",
  538. name, inode->i_ino, dentry, size);
  539. name = xattr_full_name(handler, name);
  540. if (value)
  541. return ubifs_xattr_set(inode, name, value, size, flags);
  542. else
  543. return ubifs_xattr_remove(inode, name);
  544. }
  545. static const struct xattr_handler ubifs_user_xattr_handler = {
  546. .prefix = XATTR_USER_PREFIX,
  547. .get = xattr_get,
  548. .set = xattr_set,
  549. };
  550. static const struct xattr_handler ubifs_trusted_xattr_handler = {
  551. .prefix = XATTR_TRUSTED_PREFIX,
  552. .get = xattr_get,
  553. .set = xattr_set,
  554. };
  555. static const struct xattr_handler ubifs_security_xattr_handler = {
  556. .prefix = XATTR_SECURITY_PREFIX,
  557. .get = xattr_get,
  558. .set = xattr_set,
  559. };
  560. const struct xattr_handler *ubifs_xattr_handlers[] = {
  561. &ubifs_user_xattr_handler,
  562. &ubifs_trusted_xattr_handler,
  563. &ubifs_security_xattr_handler,
  564. NULL
  565. };