xfs_iops.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_bit.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_dir.h"
  27. #include "xfs_dir2.h"
  28. #include "xfs_alloc.h"
  29. #include "xfs_dmapi.h"
  30. #include "xfs_quota.h"
  31. #include "xfs_mount.h"
  32. #include "xfs_bmap_btree.h"
  33. #include "xfs_alloc_btree.h"
  34. #include "xfs_ialloc_btree.h"
  35. #include "xfs_dir_sf.h"
  36. #include "xfs_dir2_sf.h"
  37. #include "xfs_attr_sf.h"
  38. #include "xfs_dinode.h"
  39. #include "xfs_inode.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_btree.h"
  42. #include "xfs_ialloc.h"
  43. #include "xfs_rtalloc.h"
  44. #include "xfs_error.h"
  45. #include "xfs_itable.h"
  46. #include "xfs_rw.h"
  47. #include "xfs_acl.h"
  48. #include "xfs_cap.h"
  49. #include "xfs_mac.h"
  50. #include "xfs_attr.h"
  51. #include "xfs_buf_item.h"
  52. #include "xfs_utils.h"
  53. #include <linux/xattr.h>
  54. #include <linux/namei.h>
  55. #define IS_NOATIME(inode) ((inode->i_sb->s_flags & MS_NOATIME) || \
  56. (S_ISDIR(inode->i_mode) && inode->i_sb->s_flags & MS_NODIRATIME))
  57. /*
  58. * Bring the atime in the XFS inode uptodate.
  59. * Used before logging the inode to disk or when the Linux inode goes away.
  60. */
  61. void
  62. xfs_synchronize_atime(
  63. xfs_inode_t *ip)
  64. {
  65. vnode_t *vp;
  66. vp = XFS_ITOV_NULL(ip);
  67. if (vp) {
  68. struct inode *inode = &vp->v_inode;
  69. ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
  70. ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
  71. }
  72. }
  73. /*
  74. * Change the requested timestamp in the given inode.
  75. * We don't lock across timestamp updates, and we don't log them but
  76. * we do record the fact that there is dirty information in core.
  77. *
  78. * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG
  79. * with XFS_ICHGTIME_ACC to be sure that access time
  80. * update will take. Calling first with XFS_ICHGTIME_ACC
  81. * and then XFS_ICHGTIME_MOD may fail to modify the access
  82. * timestamp if the filesystem is mounted noacctm.
  83. */
  84. void
  85. xfs_ichgtime(
  86. xfs_inode_t *ip,
  87. int flags)
  88. {
  89. struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip));
  90. timespec_t tv;
  91. nanotime(&tv);
  92. if (flags & XFS_ICHGTIME_MOD) {
  93. inode->i_mtime = tv;
  94. ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
  95. ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
  96. }
  97. if (flags & XFS_ICHGTIME_ACC) {
  98. inode->i_atime = tv;
  99. ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
  100. ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
  101. }
  102. if (flags & XFS_ICHGTIME_CHG) {
  103. inode->i_ctime = tv;
  104. ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
  105. ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
  106. }
  107. /*
  108. * We update the i_update_core field _after_ changing
  109. * the timestamps in order to coordinate properly with
  110. * xfs_iflush() so that we don't lose timestamp updates.
  111. * This keeps us from having to hold the inode lock
  112. * while doing this. We use the SYNCHRONIZE macro to
  113. * ensure that the compiler does not reorder the update
  114. * of i_update_core above the timestamp updates above.
  115. */
  116. SYNCHRONIZE();
  117. ip->i_update_core = 1;
  118. if (!(inode->i_state & I_LOCK))
  119. mark_inode_dirty_sync(inode);
  120. }
  121. /*
  122. * Variant on the above which avoids querying the system clock
  123. * in situations where we know the Linux inode timestamps have
  124. * just been updated (and so we can update our inode cheaply).
  125. */
  126. void
  127. xfs_ichgtime_fast(
  128. xfs_inode_t *ip,
  129. struct inode *inode,
  130. int flags)
  131. {
  132. timespec_t *tvp;
  133. /*
  134. * Atime updates for read() & friends are handled lazily now, and
  135. * explicit updates must go through xfs_ichgtime()
  136. */
  137. ASSERT((flags & XFS_ICHGTIME_ACC) == 0);
  138. /*
  139. * We're not supposed to change timestamps in readonly-mounted
  140. * filesystems. Throw it away if anyone asks us.
  141. */
  142. if (unlikely(IS_RDONLY(inode)))
  143. return;
  144. if (flags & XFS_ICHGTIME_MOD) {
  145. tvp = &inode->i_mtime;
  146. ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
  147. ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
  148. }
  149. if (flags & XFS_ICHGTIME_CHG) {
  150. tvp = &inode->i_ctime;
  151. ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
  152. ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
  153. }
  154. /*
  155. * We update the i_update_core field _after_ changing
  156. * the timestamps in order to coordinate properly with
  157. * xfs_iflush() so that we don't lose timestamp updates.
  158. * This keeps us from having to hold the inode lock
  159. * while doing this. We use the SYNCHRONIZE macro to
  160. * ensure that the compiler does not reorder the update
  161. * of i_update_core above the timestamp updates above.
  162. */
  163. SYNCHRONIZE();
  164. ip->i_update_core = 1;
  165. if (!(inode->i_state & I_LOCK))
  166. mark_inode_dirty_sync(inode);
  167. }
  168. /*
  169. * Pull the link count and size up from the xfs inode to the linux inode
  170. */
  171. STATIC void
  172. validate_fields(
  173. struct inode *ip)
  174. {
  175. vnode_t *vp = LINVFS_GET_VP(ip);
  176. vattr_t va;
  177. int error;
  178. va.va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS;
  179. VOP_GETATTR(vp, &va, ATTR_LAZY, NULL, error);
  180. if (likely(!error)) {
  181. ip->i_nlink = va.va_nlink;
  182. ip->i_blocks = va.va_nblocks;
  183. /* we're under i_mutex so i_size can't change under us */
  184. if (i_size_read(ip) != va.va_size)
  185. i_size_write(ip, va.va_size);
  186. }
  187. }
  188. /*
  189. * Determine whether a process has a valid fs_struct (kernel daemons
  190. * like knfsd don't have an fs_struct).
  191. *
  192. * XXX(hch): nfsd is broken, better fix it instead.
  193. */
  194. STATIC inline int
  195. has_fs_struct(struct task_struct *task)
  196. {
  197. return (task->fs != init_task.fs);
  198. }
  199. STATIC int
  200. linvfs_mknod(
  201. struct inode *dir,
  202. struct dentry *dentry,
  203. int mode,
  204. dev_t rdev)
  205. {
  206. struct inode *ip;
  207. vattr_t va;
  208. vnode_t *vp = NULL, *dvp = LINVFS_GET_VP(dir);
  209. xfs_acl_t *default_acl = NULL;
  210. attrexists_t test_default_acl = _ACL_DEFAULT_EXISTS;
  211. int error;
  212. /*
  213. * Irix uses Missed'em'V split, but doesn't want to see
  214. * the upper 5 bits of (14bit) major.
  215. */
  216. if (!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)
  217. return -EINVAL;
  218. if (test_default_acl && test_default_acl(dvp)) {
  219. if (!_ACL_ALLOC(default_acl))
  220. return -ENOMEM;
  221. if (!_ACL_GET_DEFAULT(dvp, default_acl)) {
  222. _ACL_FREE(default_acl);
  223. default_acl = NULL;
  224. }
  225. }
  226. if (IS_POSIXACL(dir) && !default_acl && has_fs_struct(current))
  227. mode &= ~current->fs->umask;
  228. memset(&va, 0, sizeof(va));
  229. va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
  230. va.va_mode = mode;
  231. switch (mode & S_IFMT) {
  232. case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK:
  233. va.va_rdev = sysv_encode_dev(rdev);
  234. va.va_mask |= XFS_AT_RDEV;
  235. /*FALLTHROUGH*/
  236. case S_IFREG:
  237. VOP_CREATE(dvp, dentry, &va, &vp, NULL, error);
  238. break;
  239. case S_IFDIR:
  240. VOP_MKDIR(dvp, dentry, &va, &vp, NULL, error);
  241. break;
  242. default:
  243. error = EINVAL;
  244. break;
  245. }
  246. if (default_acl) {
  247. if (!error) {
  248. error = _ACL_INHERIT(vp, &va, default_acl);
  249. if (!error) {
  250. VMODIFY(vp);
  251. } else {
  252. struct dentry teardown = {};
  253. int err2;
  254. /* Oh, the horror.
  255. * If we can't add the ACL we must back out.
  256. * ENOSPC can hit here, among other things.
  257. */
  258. teardown.d_inode = ip = LINVFS_GET_IP(vp);
  259. teardown.d_name = dentry->d_name;
  260. vn_mark_bad(vp);
  261. if (S_ISDIR(mode))
  262. VOP_RMDIR(dvp, &teardown, NULL, err2);
  263. else
  264. VOP_REMOVE(dvp, &teardown, NULL, err2);
  265. VN_RELE(vp);
  266. }
  267. }
  268. _ACL_FREE(default_acl);
  269. }
  270. if (!error) {
  271. ASSERT(vp);
  272. ip = LINVFS_GET_IP(vp);
  273. if (S_ISCHR(mode) || S_ISBLK(mode))
  274. ip->i_rdev = rdev;
  275. else if (S_ISDIR(mode))
  276. validate_fields(ip);
  277. d_instantiate(dentry, ip);
  278. validate_fields(dir);
  279. }
  280. return -error;
  281. }
  282. STATIC int
  283. linvfs_create(
  284. struct inode *dir,
  285. struct dentry *dentry,
  286. int mode,
  287. struct nameidata *nd)
  288. {
  289. return linvfs_mknod(dir, dentry, mode, 0);
  290. }
  291. STATIC int
  292. linvfs_mkdir(
  293. struct inode *dir,
  294. struct dentry *dentry,
  295. int mode)
  296. {
  297. return linvfs_mknod(dir, dentry, mode|S_IFDIR, 0);
  298. }
  299. STATIC struct dentry *
  300. linvfs_lookup(
  301. struct inode *dir,
  302. struct dentry *dentry,
  303. struct nameidata *nd)
  304. {
  305. struct vnode *vp = LINVFS_GET_VP(dir), *cvp;
  306. int error;
  307. if (dentry->d_name.len >= MAXNAMELEN)
  308. return ERR_PTR(-ENAMETOOLONG);
  309. VOP_LOOKUP(vp, dentry, &cvp, 0, NULL, NULL, error);
  310. if (error) {
  311. if (unlikely(error != ENOENT))
  312. return ERR_PTR(-error);
  313. d_add(dentry, NULL);
  314. return NULL;
  315. }
  316. return d_splice_alias(LINVFS_GET_IP(cvp), dentry);
  317. }
  318. STATIC int
  319. linvfs_link(
  320. struct dentry *old_dentry,
  321. struct inode *dir,
  322. struct dentry *dentry)
  323. {
  324. struct inode *ip; /* inode of guy being linked to */
  325. vnode_t *tdvp; /* target directory for new name/link */
  326. vnode_t *vp; /* vp of name being linked */
  327. int error;
  328. ip = old_dentry->d_inode; /* inode being linked to */
  329. if (S_ISDIR(ip->i_mode))
  330. return -EPERM;
  331. tdvp = LINVFS_GET_VP(dir);
  332. vp = LINVFS_GET_VP(ip);
  333. VOP_LINK(tdvp, vp, dentry, NULL, error);
  334. if (!error) {
  335. VMODIFY(tdvp);
  336. VN_HOLD(vp);
  337. validate_fields(ip);
  338. d_instantiate(dentry, ip);
  339. }
  340. return -error;
  341. }
  342. STATIC int
  343. linvfs_unlink(
  344. struct inode *dir,
  345. struct dentry *dentry)
  346. {
  347. struct inode *inode;
  348. vnode_t *dvp; /* directory containing name to remove */
  349. int error;
  350. inode = dentry->d_inode;
  351. dvp = LINVFS_GET_VP(dir);
  352. VOP_REMOVE(dvp, dentry, NULL, error);
  353. if (!error) {
  354. validate_fields(dir); /* For size only */
  355. validate_fields(inode);
  356. }
  357. return -error;
  358. }
  359. STATIC int
  360. linvfs_symlink(
  361. struct inode *dir,
  362. struct dentry *dentry,
  363. const char *symname)
  364. {
  365. struct inode *ip;
  366. vattr_t va;
  367. vnode_t *dvp; /* directory containing name of symlink */
  368. vnode_t *cvp; /* used to lookup symlink to put in dentry */
  369. int error;
  370. dvp = LINVFS_GET_VP(dir);
  371. cvp = NULL;
  372. memset(&va, 0, sizeof(va));
  373. va.va_mode = S_IFLNK |
  374. (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
  375. va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
  376. error = 0;
  377. VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error);
  378. if (!error && cvp) {
  379. ip = LINVFS_GET_IP(cvp);
  380. d_instantiate(dentry, ip);
  381. validate_fields(dir);
  382. validate_fields(ip); /* size needs update */
  383. }
  384. return -error;
  385. }
  386. STATIC int
  387. linvfs_rmdir(
  388. struct inode *dir,
  389. struct dentry *dentry)
  390. {
  391. struct inode *inode = dentry->d_inode;
  392. vnode_t *dvp = LINVFS_GET_VP(dir);
  393. int error;
  394. VOP_RMDIR(dvp, dentry, NULL, error);
  395. if (!error) {
  396. validate_fields(inode);
  397. validate_fields(dir);
  398. }
  399. return -error;
  400. }
  401. STATIC int
  402. linvfs_rename(
  403. struct inode *odir,
  404. struct dentry *odentry,
  405. struct inode *ndir,
  406. struct dentry *ndentry)
  407. {
  408. struct inode *new_inode = ndentry->d_inode;
  409. vnode_t *fvp; /* from directory */
  410. vnode_t *tvp; /* target directory */
  411. int error;
  412. fvp = LINVFS_GET_VP(odir);
  413. tvp = LINVFS_GET_VP(ndir);
  414. VOP_RENAME(fvp, odentry, tvp, ndentry, NULL, error);
  415. if (error)
  416. return -error;
  417. if (new_inode)
  418. validate_fields(new_inode);
  419. validate_fields(odir);
  420. if (ndir != odir)
  421. validate_fields(ndir);
  422. return 0;
  423. }
  424. /*
  425. * careful here - this function can get called recursively, so
  426. * we need to be very careful about how much stack we use.
  427. * uio is kmalloced for this reason...
  428. */
  429. STATIC void *
  430. linvfs_follow_link(
  431. struct dentry *dentry,
  432. struct nameidata *nd)
  433. {
  434. vnode_t *vp;
  435. uio_t *uio;
  436. iovec_t iov;
  437. int error;
  438. char *link;
  439. ASSERT(dentry);
  440. ASSERT(nd);
  441. link = (char *)kmalloc(MAXNAMELEN+1, GFP_KERNEL);
  442. if (!link) {
  443. nd_set_link(nd, ERR_PTR(-ENOMEM));
  444. return NULL;
  445. }
  446. uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL);
  447. if (!uio) {
  448. kfree(link);
  449. nd_set_link(nd, ERR_PTR(-ENOMEM));
  450. return NULL;
  451. }
  452. vp = LINVFS_GET_VP(dentry->d_inode);
  453. iov.iov_base = link;
  454. iov.iov_len = MAXNAMELEN;
  455. uio->uio_iov = &iov;
  456. uio->uio_offset = 0;
  457. uio->uio_segflg = UIO_SYSSPACE;
  458. uio->uio_resid = MAXNAMELEN;
  459. uio->uio_iovcnt = 1;
  460. VOP_READLINK(vp, uio, 0, NULL, error);
  461. if (error) {
  462. kfree(link);
  463. link = ERR_PTR(-error);
  464. } else {
  465. link[MAXNAMELEN - uio->uio_resid] = '\0';
  466. }
  467. kfree(uio);
  468. nd_set_link(nd, link);
  469. return NULL;
  470. }
  471. STATIC void
  472. linvfs_put_link(
  473. struct dentry *dentry,
  474. struct nameidata *nd,
  475. void *p)
  476. {
  477. char *s = nd_get_link(nd);
  478. if (!IS_ERR(s))
  479. kfree(s);
  480. }
  481. #ifdef CONFIG_XFS_POSIX_ACL
  482. STATIC int
  483. linvfs_permission(
  484. struct inode *inode,
  485. int mode,
  486. struct nameidata *nd)
  487. {
  488. vnode_t *vp = LINVFS_GET_VP(inode);
  489. int error;
  490. mode <<= 6; /* convert from linux to vnode access bits */
  491. VOP_ACCESS(vp, mode, NULL, error);
  492. return -error;
  493. }
  494. #else
  495. #define linvfs_permission NULL
  496. #endif
  497. STATIC int
  498. linvfs_getattr(
  499. struct vfsmount *mnt,
  500. struct dentry *dentry,
  501. struct kstat *stat)
  502. {
  503. struct inode *inode = dentry->d_inode;
  504. vnode_t *vp = LINVFS_GET_VP(inode);
  505. int error = 0;
  506. if (unlikely(vp->v_flag & VMODIFIED))
  507. error = vn_revalidate(vp);
  508. if (!error)
  509. generic_fillattr(inode, stat);
  510. return 0;
  511. }
  512. STATIC int
  513. linvfs_setattr(
  514. struct dentry *dentry,
  515. struct iattr *attr)
  516. {
  517. struct inode *inode = dentry->d_inode;
  518. unsigned int ia_valid = attr->ia_valid;
  519. vnode_t *vp = LINVFS_GET_VP(inode);
  520. vattr_t vattr;
  521. int flags = 0;
  522. int error;
  523. memset(&vattr, 0, sizeof(vattr_t));
  524. if (ia_valid & ATTR_UID) {
  525. vattr.va_mask |= XFS_AT_UID;
  526. vattr.va_uid = attr->ia_uid;
  527. }
  528. if (ia_valid & ATTR_GID) {
  529. vattr.va_mask |= XFS_AT_GID;
  530. vattr.va_gid = attr->ia_gid;
  531. }
  532. if (ia_valid & ATTR_SIZE) {
  533. vattr.va_mask |= XFS_AT_SIZE;
  534. vattr.va_size = attr->ia_size;
  535. }
  536. if (ia_valid & ATTR_ATIME) {
  537. vattr.va_mask |= XFS_AT_ATIME;
  538. vattr.va_atime = attr->ia_atime;
  539. }
  540. if (ia_valid & ATTR_MTIME) {
  541. vattr.va_mask |= XFS_AT_MTIME;
  542. vattr.va_mtime = attr->ia_mtime;
  543. }
  544. if (ia_valid & ATTR_CTIME) {
  545. vattr.va_mask |= XFS_AT_CTIME;
  546. vattr.va_ctime = attr->ia_ctime;
  547. }
  548. if (ia_valid & ATTR_MODE) {
  549. vattr.va_mask |= XFS_AT_MODE;
  550. vattr.va_mode = attr->ia_mode;
  551. if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
  552. inode->i_mode &= ~S_ISGID;
  553. }
  554. if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
  555. flags |= ATTR_UTIME;
  556. #ifdef ATTR_NO_BLOCK
  557. if ((ia_valid & ATTR_NO_BLOCK))
  558. flags |= ATTR_NONBLOCK;
  559. #endif
  560. VOP_SETATTR(vp, &vattr, flags, NULL, error);
  561. if (error)
  562. return -error;
  563. vn_revalidate(vp);
  564. return error;
  565. }
  566. STATIC void
  567. linvfs_truncate(
  568. struct inode *inode)
  569. {
  570. block_truncate_page(inode->i_mapping, inode->i_size, linvfs_get_block);
  571. }
  572. STATIC int
  573. linvfs_setxattr(
  574. struct dentry *dentry,
  575. const char *name,
  576. const void *data,
  577. size_t size,
  578. int flags)
  579. {
  580. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  581. char *attr = (char *)name;
  582. attrnames_t *namesp;
  583. int xflags = 0;
  584. int error;
  585. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  586. if (!namesp)
  587. return -EOPNOTSUPP;
  588. attr += namesp->attr_namelen;
  589. error = namesp->attr_capable(vp, NULL);
  590. if (error)
  591. return error;
  592. /* Convert Linux syscall to XFS internal ATTR flags */
  593. if (flags & XATTR_CREATE)
  594. xflags |= ATTR_CREATE;
  595. if (flags & XATTR_REPLACE)
  596. xflags |= ATTR_REPLACE;
  597. xflags |= namesp->attr_flag;
  598. return namesp->attr_set(vp, attr, (void *)data, size, xflags);
  599. }
  600. STATIC ssize_t
  601. linvfs_getxattr(
  602. struct dentry *dentry,
  603. const char *name,
  604. void *data,
  605. size_t size)
  606. {
  607. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  608. char *attr = (char *)name;
  609. attrnames_t *namesp;
  610. int xflags = 0;
  611. ssize_t error;
  612. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  613. if (!namesp)
  614. return -EOPNOTSUPP;
  615. attr += namesp->attr_namelen;
  616. error = namesp->attr_capable(vp, NULL);
  617. if (error)
  618. return error;
  619. /* Convert Linux syscall to XFS internal ATTR flags */
  620. if (!size) {
  621. xflags |= ATTR_KERNOVAL;
  622. data = NULL;
  623. }
  624. xflags |= namesp->attr_flag;
  625. return namesp->attr_get(vp, attr, (void *)data, size, xflags);
  626. }
  627. STATIC ssize_t
  628. linvfs_listxattr(
  629. struct dentry *dentry,
  630. char *data,
  631. size_t size)
  632. {
  633. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  634. int error, xflags = ATTR_KERNAMELS;
  635. ssize_t result;
  636. if (!size)
  637. xflags |= ATTR_KERNOVAL;
  638. xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
  639. error = attr_generic_list(vp, data, size, xflags, &result);
  640. if (error < 0)
  641. return error;
  642. return result;
  643. }
  644. STATIC int
  645. linvfs_removexattr(
  646. struct dentry *dentry,
  647. const char *name)
  648. {
  649. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  650. char *attr = (char *)name;
  651. attrnames_t *namesp;
  652. int xflags = 0;
  653. int error;
  654. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  655. if (!namesp)
  656. return -EOPNOTSUPP;
  657. attr += namesp->attr_namelen;
  658. error = namesp->attr_capable(vp, NULL);
  659. if (error)
  660. return error;
  661. xflags |= namesp->attr_flag;
  662. return namesp->attr_remove(vp, attr, xflags);
  663. }
  664. struct inode_operations linvfs_file_inode_operations = {
  665. .permission = linvfs_permission,
  666. .truncate = linvfs_truncate,
  667. .getattr = linvfs_getattr,
  668. .setattr = linvfs_setattr,
  669. .setxattr = linvfs_setxattr,
  670. .getxattr = linvfs_getxattr,
  671. .listxattr = linvfs_listxattr,
  672. .removexattr = linvfs_removexattr,
  673. };
  674. struct inode_operations linvfs_dir_inode_operations = {
  675. .create = linvfs_create,
  676. .lookup = linvfs_lookup,
  677. .link = linvfs_link,
  678. .unlink = linvfs_unlink,
  679. .symlink = linvfs_symlink,
  680. .mkdir = linvfs_mkdir,
  681. .rmdir = linvfs_rmdir,
  682. .mknod = linvfs_mknod,
  683. .rename = linvfs_rename,
  684. .permission = linvfs_permission,
  685. .getattr = linvfs_getattr,
  686. .setattr = linvfs_setattr,
  687. .setxattr = linvfs_setxattr,
  688. .getxattr = linvfs_getxattr,
  689. .listxattr = linvfs_listxattr,
  690. .removexattr = linvfs_removexattr,
  691. };
  692. struct inode_operations linvfs_symlink_inode_operations = {
  693. .readlink = generic_readlink,
  694. .follow_link = linvfs_follow_link,
  695. .put_link = linvfs_put_link,
  696. .permission = linvfs_permission,
  697. .getattr = linvfs_getattr,
  698. .setattr = linvfs_setattr,
  699. .setxattr = linvfs_setxattr,
  700. .getxattr = linvfs_getxattr,
  701. .listxattr = linvfs_listxattr,
  702. .removexattr = linvfs_removexattr,
  703. };