xattr.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. /*
  2. * linux/fs/reiserfs/xattr.c
  3. *
  4. * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com>
  5. *
  6. */
  7. /*
  8. * In order to implement EA/ACLs in a clean, backwards compatible manner,
  9. * they are implemented as files in a "private" directory.
  10. * Each EA is in it's own file, with the directory layout like so (/ is assumed
  11. * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory,
  12. * directories named using the capital-hex form of the objectid and
  13. * generation number are used. Inside each directory are individual files
  14. * named with the name of the extended attribute.
  15. *
  16. * So, for objectid 12648430, we could have:
  17. * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access
  18. * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default
  19. * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type
  20. * .. or similar.
  21. *
  22. * The file contents are the text of the EA. The size is known based on the
  23. * stat data describing the file.
  24. *
  25. * In the case of system.posix_acl_access and system.posix_acl_default, since
  26. * these are special cases for filesystem ACLs, they are interpreted by the
  27. * kernel, in addition, they are negatively and positively cached and attached
  28. * to the inode so that unnecessary lookups are avoided.
  29. */
  30. #include <linux/reiserfs_fs.h>
  31. #include <linux/capability.h>
  32. #include <linux/dcache.h>
  33. #include <linux/namei.h>
  34. #include <linux/errno.h>
  35. #include <linux/fs.h>
  36. #include <linux/file.h>
  37. #include <linux/pagemap.h>
  38. #include <linux/xattr.h>
  39. #include <linux/reiserfs_xattr.h>
  40. #include <linux/reiserfs_acl.h>
  41. #include <asm/uaccess.h>
  42. #include <net/checksum.h>
  43. #include <linux/smp_lock.h>
  44. #include <linux/stat.h>
  45. #include <asm/semaphore.h>
  46. #define FL_READONLY 128
  47. #define FL_DIR_SEM_HELD 256
  48. #define PRIVROOT_NAME ".reiserfs_priv"
  49. #define XAROOT_NAME "xattrs"
  50. static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
  51. *prefix);
  52. /* Returns the dentry referring to the root of the extended attribute
  53. * directory tree. If it has already been retrieved, it is used. If it
  54. * hasn't been created and the flags indicate creation is allowed, we
  55. * attempt to create it. On error, we return a pointer-encoded error.
  56. */
  57. static struct dentry *get_xa_root(struct super_block *sb, int flags)
  58. {
  59. struct dentry *privroot = dget(REISERFS_SB(sb)->priv_root);
  60. struct dentry *xaroot;
  61. /* This needs to be created at mount-time */
  62. if (!privroot)
  63. return ERR_PTR(-ENODATA);
  64. mutex_lock_nested(&privroot->d_inode->i_mutex, I_MUTEX_XATTR);
  65. if (REISERFS_SB(sb)->xattr_root) {
  66. xaroot = dget(REISERFS_SB(sb)->xattr_root);
  67. goto out;
  68. }
  69. xaroot = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME));
  70. if (IS_ERR(xaroot)) {
  71. goto out;
  72. } else if (!xaroot->d_inode) {
  73. int err = -ENODATA;
  74. if (flags == 0 || flags & XATTR_CREATE)
  75. err = privroot->d_inode->i_op->mkdir(privroot->d_inode,
  76. xaroot, 0700);
  77. if (err) {
  78. dput(xaroot);
  79. xaroot = ERR_PTR(err);
  80. goto out;
  81. }
  82. }
  83. REISERFS_SB(sb)->xattr_root = dget(xaroot);
  84. out:
  85. mutex_unlock(&privroot->d_inode->i_mutex);
  86. dput(privroot);
  87. return xaroot;
  88. }
  89. /* Opens the directory corresponding to the inode's extended attribute store.
  90. * If flags allow, the tree to the directory may be created. If creation is
  91. * prohibited, -ENODATA is returned. */
  92. static struct dentry *open_xa_dir(const struct inode *inode, int flags)
  93. {
  94. struct dentry *xaroot, *xadir;
  95. char namebuf[17];
  96. xaroot = get_xa_root(inode->i_sb, flags);
  97. if (IS_ERR(xaroot))
  98. return xaroot;
  99. /* ok, we have xaroot open */
  100. snprintf(namebuf, sizeof(namebuf), "%X.%X",
  101. le32_to_cpu(INODE_PKEY(inode)->k_objectid),
  102. inode->i_generation);
  103. xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
  104. if (IS_ERR(xadir)) {
  105. dput(xaroot);
  106. return xadir;
  107. }
  108. if (!xadir->d_inode) {
  109. int err;
  110. if (flags == 0 || flags & XATTR_CREATE) {
  111. /* Although there is nothing else trying to create this directory,
  112. * another directory with the same hash may be created, so we need
  113. * to protect against that */
  114. err =
  115. xaroot->d_inode->i_op->mkdir(xaroot->d_inode, xadir,
  116. 0700);
  117. if (err) {
  118. dput(xaroot);
  119. dput(xadir);
  120. return ERR_PTR(err);
  121. }
  122. }
  123. if (!xadir->d_inode) {
  124. dput(xaroot);
  125. dput(xadir);
  126. return ERR_PTR(-ENODATA);
  127. }
  128. }
  129. dput(xaroot);
  130. return xadir;
  131. }
  132. /* Returns a dentry corresponding to a specific extended attribute file
  133. * for the inode. If flags allow, the file is created. Otherwise, a
  134. * valid or negative dentry, or an error is returned. */
  135. static struct dentry *get_xa_file_dentry(const struct inode *inode,
  136. const char *name, int flags)
  137. {
  138. struct dentry *xadir, *xafile;
  139. int err = 0;
  140. xadir = open_xa_dir(inode, flags);
  141. if (IS_ERR(xadir)) {
  142. return ERR_PTR(PTR_ERR(xadir));
  143. } else if (xadir && !xadir->d_inode) {
  144. dput(xadir);
  145. return ERR_PTR(-ENODATA);
  146. }
  147. xafile = lookup_one_len(name, xadir, strlen(name));
  148. if (IS_ERR(xafile)) {
  149. dput(xadir);
  150. return ERR_PTR(PTR_ERR(xafile));
  151. }
  152. if (xafile->d_inode) { /* file exists */
  153. if (flags & XATTR_CREATE) {
  154. err = -EEXIST;
  155. dput(xafile);
  156. goto out;
  157. }
  158. } else if (flags & XATTR_REPLACE || flags & FL_READONLY) {
  159. goto out;
  160. } else {
  161. /* inode->i_mutex is down, so nothing else can try to create
  162. * the same xattr */
  163. err = xadir->d_inode->i_op->create(xadir->d_inode, xafile,
  164. 0700 | S_IFREG, NULL);
  165. if (err) {
  166. dput(xafile);
  167. goto out;
  168. }
  169. }
  170. out:
  171. dput(xadir);
  172. if (err)
  173. xafile = ERR_PTR(err);
  174. return xafile;
  175. }
  176. /* Opens a file pointer to the attribute associated with inode */
  177. static struct file *open_xa_file(const struct inode *inode, const char *name,
  178. int flags)
  179. {
  180. struct dentry *xafile;
  181. struct file *fp;
  182. xafile = get_xa_file_dentry(inode, name, flags);
  183. if (IS_ERR(xafile))
  184. return ERR_PTR(PTR_ERR(xafile));
  185. else if (!xafile->d_inode) {
  186. dput(xafile);
  187. return ERR_PTR(-ENODATA);
  188. }
  189. fp = dentry_open(xafile, NULL, O_RDWR);
  190. /* dentry_open dputs the dentry if it fails */
  191. return fp;
  192. }
  193. /*
  194. * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but
  195. * we need to drop the path before calling the filldir struct. That
  196. * would be a big performance hit to the non-xattr case, so I've copied
  197. * the whole thing for now. --clm
  198. *
  199. * the big difference is that I go backwards through the directory,
  200. * and don't mess with f->f_pos, but the idea is the same. Do some
  201. * action on each and every entry in the directory.
  202. *
  203. * we're called with i_mutex held, so there are no worries about the directory
  204. * changing underneath us.
  205. */
  206. static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
  207. {
  208. struct inode *inode = filp->f_path.dentry->d_inode;
  209. struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
  210. INITIALIZE_PATH(path_to_entry);
  211. struct buffer_head *bh;
  212. int entry_num;
  213. struct item_head *ih, tmp_ih;
  214. int search_res;
  215. char *local_buf;
  216. loff_t next_pos;
  217. char small_buf[32]; /* avoid kmalloc if we can */
  218. struct reiserfs_de_head *deh;
  219. int d_reclen;
  220. char *d_name;
  221. off_t d_off;
  222. ino_t d_ino;
  223. struct reiserfs_dir_entry de;
  224. /* form key for search the next directory entry using f_pos field of
  225. file structure */
  226. next_pos = max_reiserfs_offset(inode);
  227. while (1) {
  228. research:
  229. if (next_pos <= DOT_DOT_OFFSET)
  230. break;
  231. make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3);
  232. search_res =
  233. search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
  234. &de);
  235. if (search_res == IO_ERROR) {
  236. // FIXME: we could just skip part of directory which could
  237. // not be read
  238. pathrelse(&path_to_entry);
  239. return -EIO;
  240. }
  241. if (search_res == NAME_NOT_FOUND)
  242. de.de_entry_num--;
  243. set_de_name_and_namelen(&de);
  244. entry_num = de.de_entry_num;
  245. deh = &(de.de_deh[entry_num]);
  246. bh = de.de_bh;
  247. ih = de.de_ih;
  248. if (!is_direntry_le_ih(ih)) {
  249. reiserfs_warning(inode->i_sb, "not direntry %h", ih);
  250. break;
  251. }
  252. copy_item_head(&tmp_ih, ih);
  253. /* we must have found item, that is item of this directory, */
  254. RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key),
  255. "vs-9000: found item %h does not match to dir we readdir %K",
  256. ih, &pos_key);
  257. if (deh_offset(deh) <= DOT_DOT_OFFSET) {
  258. break;
  259. }
  260. /* look for the previous entry in the directory */
  261. next_pos = deh_offset(deh) - 1;
  262. if (!de_visible(deh))
  263. /* it is hidden entry */
  264. continue;
  265. d_reclen = entry_length(bh, ih, entry_num);
  266. d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
  267. d_off = deh_offset(deh);
  268. d_ino = deh_objectid(deh);
  269. if (!d_name[d_reclen - 1])
  270. d_reclen = strlen(d_name);
  271. if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) {
  272. /* too big to send back to VFS */
  273. continue;
  274. }
  275. /* Ignore the .reiserfs_priv entry */
  276. if (reiserfs_xattrs(inode->i_sb) &&
  277. !old_format_only(inode->i_sb) &&
  278. deh_objectid(deh) ==
  279. le32_to_cpu(INODE_PKEY
  280. (REISERFS_SB(inode->i_sb)->priv_root->d_inode)->
  281. k_objectid))
  282. continue;
  283. if (d_reclen <= 32) {
  284. local_buf = small_buf;
  285. } else {
  286. local_buf = kmalloc(d_reclen, GFP_NOFS);
  287. if (!local_buf) {
  288. pathrelse(&path_to_entry);
  289. return -ENOMEM;
  290. }
  291. if (item_moved(&tmp_ih, &path_to_entry)) {
  292. kfree(local_buf);
  293. /* sigh, must retry. Do this same offset again */
  294. next_pos = d_off;
  295. goto research;
  296. }
  297. }
  298. // Note, that we copy name to user space via temporary
  299. // buffer (local_buf) because filldir will block if
  300. // user space buffer is swapped out. At that time
  301. // entry can move to somewhere else
  302. memcpy(local_buf, d_name, d_reclen);
  303. /* the filldir function might need to start transactions,
  304. * or do who knows what. Release the path now that we've
  305. * copied all the important stuff out of the deh
  306. */
  307. pathrelse(&path_to_entry);
  308. if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
  309. DT_UNKNOWN) < 0) {
  310. if (local_buf != small_buf) {
  311. kfree(local_buf);
  312. }
  313. goto end;
  314. }
  315. if (local_buf != small_buf) {
  316. kfree(local_buf);
  317. }
  318. } /* while */
  319. end:
  320. pathrelse(&path_to_entry);
  321. return 0;
  322. }
  323. /*
  324. * this could be done with dedicated readdir ops for the xattr files,
  325. * but I want to get something working asap
  326. * this is stolen from vfs_readdir
  327. *
  328. */
  329. static
  330. int xattr_readdir(struct file *file, filldir_t filler, void *buf)
  331. {
  332. struct inode *inode = file->f_path.dentry->d_inode;
  333. int res = -ENOTDIR;
  334. if (!file->f_op || !file->f_op->readdir)
  335. goto out;
  336. mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR);
  337. // down(&inode->i_zombie);
  338. res = -ENOENT;
  339. if (!IS_DEADDIR(inode)) {
  340. lock_kernel();
  341. res = __xattr_readdir(file, buf, filler);
  342. unlock_kernel();
  343. }
  344. // up(&inode->i_zombie);
  345. mutex_unlock(&inode->i_mutex);
  346. out:
  347. return res;
  348. }
  349. /* Internal operations on file data */
  350. static inline void reiserfs_put_page(struct page *page)
  351. {
  352. kunmap(page);
  353. page_cache_release(page);
  354. }
  355. static struct page *reiserfs_get_page(struct inode *dir, unsigned long n)
  356. {
  357. struct address_space *mapping = dir->i_mapping;
  358. struct page *page;
  359. /* We can deadlock if we try to free dentries,
  360. and an unlink/rmdir has just occured - GFP_NOFS avoids this */
  361. mapping_set_gfp_mask(mapping, GFP_NOFS);
  362. page = read_mapping_page(mapping, n, NULL);
  363. if (!IS_ERR(page)) {
  364. kmap(page);
  365. if (PageError(page))
  366. goto fail;
  367. }
  368. return page;
  369. fail:
  370. reiserfs_put_page(page);
  371. return ERR_PTR(-EIO);
  372. }
  373. static inline __u32 xattr_hash(const char *msg, int len)
  374. {
  375. return csum_partial(msg, len, 0);
  376. }
  377. /* Generic extended attribute operations that can be used by xa plugins */
  378. /*
  379. * inode->i_mutex: down
  380. */
  381. int
  382. reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
  383. size_t buffer_size, int flags)
  384. {
  385. int err = 0;
  386. struct file *fp;
  387. struct page *page;
  388. char *data;
  389. struct address_space *mapping;
  390. size_t file_pos = 0;
  391. size_t buffer_pos = 0;
  392. struct inode *xinode;
  393. struct iattr newattrs;
  394. __u32 xahash = 0;
  395. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  396. return -EOPNOTSUPP;
  397. /* Empty xattrs are ok, they're just empty files, no hash */
  398. if (buffer && buffer_size)
  399. xahash = xattr_hash(buffer, buffer_size);
  400. open_file:
  401. fp = open_xa_file(inode, name, flags);
  402. if (IS_ERR(fp)) {
  403. err = PTR_ERR(fp);
  404. goto out;
  405. }
  406. xinode = fp->f_path.dentry->d_inode;
  407. REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
  408. /* we need to copy it off.. */
  409. if (xinode->i_nlink > 1) {
  410. fput(fp);
  411. err = reiserfs_xattr_del(inode, name);
  412. if (err < 0)
  413. goto out;
  414. /* We just killed the old one, we're not replacing anymore */
  415. if (flags & XATTR_REPLACE)
  416. flags &= ~XATTR_REPLACE;
  417. goto open_file;
  418. }
  419. /* Resize it so we're ok to write there */
  420. newattrs.ia_size = buffer_size;
  421. newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
  422. mutex_lock(&xinode->i_mutex);
  423. err = notify_change(fp->f_path.dentry, &newattrs);
  424. if (err)
  425. goto out_filp;
  426. mapping = xinode->i_mapping;
  427. while (buffer_pos < buffer_size || buffer_pos == 0) {
  428. size_t chunk;
  429. size_t skip = 0;
  430. size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1));
  431. if (buffer_size - buffer_pos > PAGE_CACHE_SIZE)
  432. chunk = PAGE_CACHE_SIZE;
  433. else
  434. chunk = buffer_size - buffer_pos;
  435. page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
  436. if (IS_ERR(page)) {
  437. err = PTR_ERR(page);
  438. goto out_filp;
  439. }
  440. lock_page(page);
  441. data = page_address(page);
  442. if (file_pos == 0) {
  443. struct reiserfs_xattr_header *rxh;
  444. skip = file_pos = sizeof(struct reiserfs_xattr_header);
  445. if (chunk + skip > PAGE_CACHE_SIZE)
  446. chunk = PAGE_CACHE_SIZE - skip;
  447. rxh = (struct reiserfs_xattr_header *)data;
  448. rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC);
  449. rxh->h_hash = cpu_to_le32(xahash);
  450. }
  451. err = mapping->a_ops->prepare_write(fp, page, page_offset,
  452. page_offset + chunk + skip);
  453. if (!err) {
  454. if (buffer)
  455. memcpy(data + skip, buffer + buffer_pos, chunk);
  456. err =
  457. mapping->a_ops->commit_write(fp, page, page_offset,
  458. page_offset + chunk +
  459. skip);
  460. }
  461. unlock_page(page);
  462. reiserfs_put_page(page);
  463. buffer_pos += chunk;
  464. file_pos += chunk;
  465. skip = 0;
  466. if (err || buffer_size == 0 || !buffer)
  467. break;
  468. }
  469. /* We can't mark the inode dirty if it's not hashed. This is the case
  470. * when we're inheriting the default ACL. If we dirty it, the inode
  471. * gets marked dirty, but won't (ever) make it onto the dirty list until
  472. * it's synced explicitly to clear I_DIRTY. This is bad. */
  473. if (!hlist_unhashed(&inode->i_hash)) {
  474. inode->i_ctime = CURRENT_TIME_SEC;
  475. mark_inode_dirty(inode);
  476. }
  477. out_filp:
  478. mutex_unlock(&xinode->i_mutex);
  479. fput(fp);
  480. out:
  481. return err;
  482. }
  483. /*
  484. * inode->i_mutex: down
  485. */
  486. int
  487. reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
  488. size_t buffer_size)
  489. {
  490. ssize_t err = 0;
  491. struct file *fp;
  492. size_t isize;
  493. size_t file_pos = 0;
  494. size_t buffer_pos = 0;
  495. struct page *page;
  496. struct inode *xinode;
  497. __u32 hash = 0;
  498. if (name == NULL)
  499. return -EINVAL;
  500. /* We can't have xattrs attached to v1 items since they don't have
  501. * generation numbers */
  502. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  503. return -EOPNOTSUPP;
  504. fp = open_xa_file(inode, name, FL_READONLY);
  505. if (IS_ERR(fp)) {
  506. err = PTR_ERR(fp);
  507. goto out;
  508. }
  509. xinode = fp->f_path.dentry->d_inode;
  510. isize = xinode->i_size;
  511. REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
  512. /* Just return the size needed */
  513. if (buffer == NULL) {
  514. err = isize - sizeof(struct reiserfs_xattr_header);
  515. goto out_dput;
  516. }
  517. if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
  518. err = -ERANGE;
  519. goto out_dput;
  520. }
  521. while (file_pos < isize) {
  522. size_t chunk;
  523. char *data;
  524. size_t skip = 0;
  525. if (isize - file_pos > PAGE_CACHE_SIZE)
  526. chunk = PAGE_CACHE_SIZE;
  527. else
  528. chunk = isize - file_pos;
  529. page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
  530. if (IS_ERR(page)) {
  531. err = PTR_ERR(page);
  532. goto out_dput;
  533. }
  534. lock_page(page);
  535. data = page_address(page);
  536. if (file_pos == 0) {
  537. struct reiserfs_xattr_header *rxh =
  538. (struct reiserfs_xattr_header *)data;
  539. skip = file_pos = sizeof(struct reiserfs_xattr_header);
  540. chunk -= skip;
  541. /* Magic doesn't match up.. */
  542. if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
  543. unlock_page(page);
  544. reiserfs_put_page(page);
  545. reiserfs_warning(inode->i_sb,
  546. "Invalid magic for xattr (%s) "
  547. "associated with %k", name,
  548. INODE_PKEY(inode));
  549. err = -EIO;
  550. goto out_dput;
  551. }
  552. hash = le32_to_cpu(rxh->h_hash);
  553. }
  554. memcpy(buffer + buffer_pos, data + skip, chunk);
  555. unlock_page(page);
  556. reiserfs_put_page(page);
  557. file_pos += chunk;
  558. buffer_pos += chunk;
  559. skip = 0;
  560. }
  561. err = isize - sizeof(struct reiserfs_xattr_header);
  562. if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
  563. hash) {
  564. reiserfs_warning(inode->i_sb,
  565. "Invalid hash for xattr (%s) associated "
  566. "with %k", name, INODE_PKEY(inode));
  567. err = -EIO;
  568. }
  569. out_dput:
  570. fput(fp);
  571. out:
  572. return err;
  573. }
  574. static int
  575. __reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen)
  576. {
  577. struct dentry *dentry;
  578. struct inode *dir = xadir->d_inode;
  579. int err = 0;
  580. dentry = lookup_one_len(name, xadir, namelen);
  581. if (IS_ERR(dentry)) {
  582. err = PTR_ERR(dentry);
  583. goto out;
  584. } else if (!dentry->d_inode) {
  585. err = -ENODATA;
  586. goto out_file;
  587. }
  588. /* Skip directories.. */
  589. if (S_ISDIR(dentry->d_inode->i_mode))
  590. goto out_file;
  591. if (!is_reiserfs_priv_object(dentry->d_inode)) {
  592. reiserfs_warning(dir->i_sb, "OID %08x [%.*s/%.*s] doesn't have "
  593. "priv flag set [parent is %sset].",
  594. le32_to_cpu(INODE_PKEY(dentry->d_inode)->
  595. k_objectid), xadir->d_name.len,
  596. xadir->d_name.name, namelen, name,
  597. is_reiserfs_priv_object(xadir->
  598. d_inode) ? "" :
  599. "not ");
  600. dput(dentry);
  601. return -EIO;
  602. }
  603. err = dir->i_op->unlink(dir, dentry);
  604. if (!err)
  605. d_delete(dentry);
  606. out_file:
  607. dput(dentry);
  608. out:
  609. return err;
  610. }
  611. int reiserfs_xattr_del(struct inode *inode, const char *name)
  612. {
  613. struct dentry *dir;
  614. int err;
  615. dir = open_xa_dir(inode, FL_READONLY);
  616. if (IS_ERR(dir)) {
  617. err = PTR_ERR(dir);
  618. goto out;
  619. }
  620. err = __reiserfs_xattr_del(dir, name, strlen(name));
  621. dput(dir);
  622. if (!err) {
  623. inode->i_ctime = CURRENT_TIME_SEC;
  624. mark_inode_dirty(inode);
  625. }
  626. out:
  627. return err;
  628. }
  629. /* The following are side effects of other operations that aren't explicitly
  630. * modifying extended attributes. This includes operations such as permissions
  631. * or ownership changes, object deletions, etc. */
  632. static int
  633. reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
  634. loff_t offset, u64 ino, unsigned int d_type)
  635. {
  636. struct dentry *xadir = (struct dentry *)buf;
  637. return __reiserfs_xattr_del(xadir, name, namelen);
  638. }
  639. /* This is called w/ inode->i_mutex downed */
  640. int reiserfs_delete_xattrs(struct inode *inode)
  641. {
  642. struct file *fp;
  643. struct dentry *dir, *root;
  644. int err = 0;
  645. /* Skip out, an xattr has no xattrs associated with it */
  646. if (is_reiserfs_priv_object(inode) ||
  647. get_inode_sd_version(inode) == STAT_DATA_V1 ||
  648. !reiserfs_xattrs(inode->i_sb)) {
  649. return 0;
  650. }
  651. reiserfs_read_lock_xattrs(inode->i_sb);
  652. dir = open_xa_dir(inode, FL_READONLY);
  653. reiserfs_read_unlock_xattrs(inode->i_sb);
  654. if (IS_ERR(dir)) {
  655. err = PTR_ERR(dir);
  656. goto out;
  657. } else if (!dir->d_inode) {
  658. dput(dir);
  659. return 0;
  660. }
  661. fp = dentry_open(dir, NULL, O_RDWR);
  662. if (IS_ERR(fp)) {
  663. err = PTR_ERR(fp);
  664. /* dentry_open dputs the dentry if it fails */
  665. goto out;
  666. }
  667. lock_kernel();
  668. err = xattr_readdir(fp, reiserfs_delete_xattrs_filler, dir);
  669. if (err) {
  670. unlock_kernel();
  671. goto out_dir;
  672. }
  673. /* Leftovers besides . and .. -- that's not good. */
  674. if (dir->d_inode->i_nlink <= 2) {
  675. root = get_xa_root(inode->i_sb, XATTR_REPLACE);
  676. reiserfs_write_lock_xattrs(inode->i_sb);
  677. err = vfs_rmdir(root->d_inode, dir);
  678. reiserfs_write_unlock_xattrs(inode->i_sb);
  679. dput(root);
  680. } else {
  681. reiserfs_warning(inode->i_sb,
  682. "Couldn't remove all entries in directory");
  683. }
  684. unlock_kernel();
  685. out_dir:
  686. fput(fp);
  687. out:
  688. if (!err)
  689. REISERFS_I(inode)->i_flags =
  690. REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
  691. return err;
  692. }
  693. struct reiserfs_chown_buf {
  694. struct inode *inode;
  695. struct dentry *xadir;
  696. struct iattr *attrs;
  697. };
  698. /* XXX: If there is a better way to do this, I'd love to hear about it */
  699. static int
  700. reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen,
  701. loff_t offset, u64 ino, unsigned int d_type)
  702. {
  703. struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf;
  704. struct dentry *xafile, *xadir = chown_buf->xadir;
  705. struct iattr *attrs = chown_buf->attrs;
  706. int err = 0;
  707. xafile = lookup_one_len(name, xadir, namelen);
  708. if (IS_ERR(xafile))
  709. return PTR_ERR(xafile);
  710. else if (!xafile->d_inode) {
  711. dput(xafile);
  712. return -ENODATA;
  713. }
  714. if (!S_ISDIR(xafile->d_inode->i_mode))
  715. err = notify_change(xafile, attrs);
  716. dput(xafile);
  717. return err;
  718. }
  719. int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
  720. {
  721. struct file *fp;
  722. struct dentry *dir;
  723. int err = 0;
  724. struct reiserfs_chown_buf buf;
  725. unsigned int ia_valid = attrs->ia_valid;
  726. /* Skip out, an xattr has no xattrs associated with it */
  727. if (is_reiserfs_priv_object(inode) ||
  728. get_inode_sd_version(inode) == STAT_DATA_V1 ||
  729. !reiserfs_xattrs(inode->i_sb)) {
  730. return 0;
  731. }
  732. reiserfs_read_lock_xattrs(inode->i_sb);
  733. dir = open_xa_dir(inode, FL_READONLY);
  734. reiserfs_read_unlock_xattrs(inode->i_sb);
  735. if (IS_ERR(dir)) {
  736. if (PTR_ERR(dir) != -ENODATA)
  737. err = PTR_ERR(dir);
  738. goto out;
  739. } else if (!dir->d_inode) {
  740. dput(dir);
  741. goto out;
  742. }
  743. fp = dentry_open(dir, NULL, O_RDWR);
  744. if (IS_ERR(fp)) {
  745. err = PTR_ERR(fp);
  746. /* dentry_open dputs the dentry if it fails */
  747. goto out;
  748. }
  749. lock_kernel();
  750. attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
  751. buf.xadir = dir;
  752. buf.attrs = attrs;
  753. buf.inode = inode;
  754. err = xattr_readdir(fp, reiserfs_chown_xattrs_filler, &buf);
  755. if (err) {
  756. unlock_kernel();
  757. goto out_dir;
  758. }
  759. err = notify_change(dir, attrs);
  760. unlock_kernel();
  761. out_dir:
  762. fput(fp);
  763. out:
  764. attrs->ia_valid = ia_valid;
  765. return err;
  766. }
  767. /* Actual operations that are exported to VFS-land */
  768. /*
  769. * Inode operation getxattr()
  770. * Preliminary locking: we down dentry->d_inode->i_mutex
  771. */
  772. ssize_t
  773. reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
  774. size_t size)
  775. {
  776. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  777. int err;
  778. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  779. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  780. return -EOPNOTSUPP;
  781. reiserfs_read_lock_xattr_i(dentry->d_inode);
  782. reiserfs_read_lock_xattrs(dentry->d_sb);
  783. err = xah->get(dentry->d_inode, name, buffer, size);
  784. reiserfs_read_unlock_xattrs(dentry->d_sb);
  785. reiserfs_read_unlock_xattr_i(dentry->d_inode);
  786. return err;
  787. }
  788. /*
  789. * Inode operation setxattr()
  790. *
  791. * dentry->d_inode->i_mutex down
  792. */
  793. int
  794. reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  795. size_t size, int flags)
  796. {
  797. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  798. int err;
  799. int lock;
  800. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  801. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  802. return -EOPNOTSUPP;
  803. reiserfs_write_lock_xattr_i(dentry->d_inode);
  804. lock = !has_xattr_dir(dentry->d_inode);
  805. if (lock)
  806. reiserfs_write_lock_xattrs(dentry->d_sb);
  807. else
  808. reiserfs_read_lock_xattrs(dentry->d_sb);
  809. err = xah->set(dentry->d_inode, name, value, size, flags);
  810. if (lock)
  811. reiserfs_write_unlock_xattrs(dentry->d_sb);
  812. else
  813. reiserfs_read_unlock_xattrs(dentry->d_sb);
  814. reiserfs_write_unlock_xattr_i(dentry->d_inode);
  815. return err;
  816. }
  817. /*
  818. * Inode operation removexattr()
  819. *
  820. * dentry->d_inode->i_mutex down
  821. */
  822. int reiserfs_removexattr(struct dentry *dentry, const char *name)
  823. {
  824. int err;
  825. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  826. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  827. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  828. return -EOPNOTSUPP;
  829. reiserfs_write_lock_xattr_i(dentry->d_inode);
  830. reiserfs_read_lock_xattrs(dentry->d_sb);
  831. /* Deletion pre-operation */
  832. if (xah->del) {
  833. err = xah->del(dentry->d_inode, name);
  834. if (err)
  835. goto out;
  836. }
  837. err = reiserfs_xattr_del(dentry->d_inode, name);
  838. dentry->d_inode->i_ctime = CURRENT_TIME_SEC;
  839. mark_inode_dirty(dentry->d_inode);
  840. out:
  841. reiserfs_read_unlock_xattrs(dentry->d_sb);
  842. reiserfs_write_unlock_xattr_i(dentry->d_inode);
  843. return err;
  844. }
  845. /* This is what filldir will use:
  846. * r_pos will always contain the amount of space required for the entire
  847. * list. If r_pos becomes larger than r_size, we need more space and we
  848. * return an error indicating this. If r_pos is less than r_size, then we've
  849. * filled the buffer successfully and we return success */
  850. struct reiserfs_listxattr_buf {
  851. int r_pos;
  852. int r_size;
  853. char *r_buf;
  854. struct inode *r_inode;
  855. };
  856. static int
  857. reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
  858. loff_t offset, u64 ino, unsigned int d_type)
  859. {
  860. struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf;
  861. int len = 0;
  862. if (name[0] != '.'
  863. || (namelen != 1 && (name[1] != '.' || namelen != 2))) {
  864. struct reiserfs_xattr_handler *xah =
  865. find_xattr_handler_prefix(name);
  866. if (!xah)
  867. return 0; /* Unsupported xattr name, skip it */
  868. /* We call ->list() twice because the operation isn't required to just
  869. * return the name back - we want to make sure we have enough space */
  870. len += xah->list(b->r_inode, name, namelen, NULL);
  871. if (len) {
  872. if (b->r_pos + len + 1 <= b->r_size) {
  873. char *p = b->r_buf + b->r_pos;
  874. p += xah->list(b->r_inode, name, namelen, p);
  875. *p++ = '\0';
  876. }
  877. b->r_pos += len + 1;
  878. }
  879. }
  880. return 0;
  881. }
  882. /*
  883. * Inode operation listxattr()
  884. *
  885. * Preliminary locking: we down dentry->d_inode->i_mutex
  886. */
  887. ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
  888. {
  889. struct file *fp;
  890. struct dentry *dir;
  891. int err = 0;
  892. struct reiserfs_listxattr_buf buf;
  893. if (!dentry->d_inode)
  894. return -EINVAL;
  895. if (!reiserfs_xattrs(dentry->d_sb) ||
  896. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  897. return -EOPNOTSUPP;
  898. reiserfs_read_lock_xattr_i(dentry->d_inode);
  899. reiserfs_read_lock_xattrs(dentry->d_sb);
  900. dir = open_xa_dir(dentry->d_inode, FL_READONLY);
  901. reiserfs_read_unlock_xattrs(dentry->d_sb);
  902. if (IS_ERR(dir)) {
  903. err = PTR_ERR(dir);
  904. if (err == -ENODATA)
  905. err = 0; /* Not an error if there aren't any xattrs */
  906. goto out;
  907. }
  908. fp = dentry_open(dir, NULL, O_RDWR);
  909. if (IS_ERR(fp)) {
  910. err = PTR_ERR(fp);
  911. /* dentry_open dputs the dentry if it fails */
  912. goto out;
  913. }
  914. buf.r_buf = buffer;
  915. buf.r_size = buffer ? size : 0;
  916. buf.r_pos = 0;
  917. buf.r_inode = dentry->d_inode;
  918. REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir;
  919. err = xattr_readdir(fp, reiserfs_listxattr_filler, &buf);
  920. if (err)
  921. goto out_dir;
  922. if (buf.r_pos > buf.r_size && buffer != NULL)
  923. err = -ERANGE;
  924. else
  925. err = buf.r_pos;
  926. out_dir:
  927. fput(fp);
  928. out:
  929. reiserfs_read_unlock_xattr_i(dentry->d_inode);
  930. return err;
  931. }
  932. /* This is the implementation for the xattr plugin infrastructure */
  933. static struct list_head xattr_handlers = LIST_HEAD_INIT(xattr_handlers);
  934. static DEFINE_RWLOCK(handler_lock);
  935. static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
  936. *prefix)
  937. {
  938. struct reiserfs_xattr_handler *xah = NULL;
  939. struct list_head *p;
  940. read_lock(&handler_lock);
  941. list_for_each(p, &xattr_handlers) {
  942. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  943. if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0)
  944. break;
  945. xah = NULL;
  946. }
  947. read_unlock(&handler_lock);
  948. return xah;
  949. }
  950. static void __unregister_handlers(void)
  951. {
  952. struct reiserfs_xattr_handler *xah;
  953. struct list_head *p, *tmp;
  954. list_for_each_safe(p, tmp, &xattr_handlers) {
  955. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  956. if (xah->exit)
  957. xah->exit();
  958. list_del_init(p);
  959. }
  960. INIT_LIST_HEAD(&xattr_handlers);
  961. }
  962. int __init reiserfs_xattr_register_handlers(void)
  963. {
  964. int err = 0;
  965. struct reiserfs_xattr_handler *xah;
  966. struct list_head *p;
  967. write_lock(&handler_lock);
  968. /* If we're already initialized, nothing to do */
  969. if (!list_empty(&xattr_handlers)) {
  970. write_unlock(&handler_lock);
  971. return 0;
  972. }
  973. /* Add the handlers */
  974. list_add_tail(&user_handler.handlers, &xattr_handlers);
  975. list_add_tail(&trusted_handler.handlers, &xattr_handlers);
  976. #ifdef CONFIG_REISERFS_FS_SECURITY
  977. list_add_tail(&security_handler.handlers, &xattr_handlers);
  978. #endif
  979. #ifdef CONFIG_REISERFS_FS_POSIX_ACL
  980. list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers);
  981. list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers);
  982. #endif
  983. /* Run initializers, if available */
  984. list_for_each(p, &xattr_handlers) {
  985. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  986. if (xah->init) {
  987. err = xah->init();
  988. if (err) {
  989. list_del_init(p);
  990. break;
  991. }
  992. }
  993. }
  994. /* Clean up other handlers, if any failed */
  995. if (err)
  996. __unregister_handlers();
  997. write_unlock(&handler_lock);
  998. return err;
  999. }
  1000. void reiserfs_xattr_unregister_handlers(void)
  1001. {
  1002. write_lock(&handler_lock);
  1003. __unregister_handlers();
  1004. write_unlock(&handler_lock);
  1005. }
  1006. /* This will catch lookups from the fs root to .reiserfs_priv */
  1007. static int
  1008. xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name)
  1009. {
  1010. struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root;
  1011. if (name->len == priv_root->d_name.len &&
  1012. name->hash == priv_root->d_name.hash &&
  1013. !memcmp(name->name, priv_root->d_name.name, name->len)) {
  1014. return -ENOENT;
  1015. } else if (q1->len == name->len &&
  1016. !memcmp(q1->name, name->name, name->len))
  1017. return 0;
  1018. return 1;
  1019. }
  1020. static struct dentry_operations xattr_lookup_poison_ops = {
  1021. .d_compare = xattr_lookup_poison,
  1022. };
  1023. /* We need to take a copy of the mount flags since things like
  1024. * MS_RDONLY don't get set until *after* we're called.
  1025. * mount_flags != mount_options */
  1026. int reiserfs_xattr_init(struct super_block *s, int mount_flags)
  1027. {
  1028. int err = 0;
  1029. /* We need generation numbers to ensure that the oid mapping is correct
  1030. * v3.5 filesystems don't have them. */
  1031. if (!old_format_only(s)) {
  1032. set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1033. } else if (reiserfs_xattrs_optional(s)) {
  1034. /* Old format filesystem, but optional xattrs have been enabled
  1035. * at mount time. Error out. */
  1036. reiserfs_warning(s, "xattrs/ACLs not supported on pre v3.6 "
  1037. "format filesystem. Failing mount.");
  1038. err = -EOPNOTSUPP;
  1039. goto error;
  1040. } else {
  1041. /* Old format filesystem, but no optional xattrs have been enabled. This
  1042. * means we silently disable xattrs on the filesystem. */
  1043. clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1044. }
  1045. /* If we don't have the privroot located yet - go find it */
  1046. if (reiserfs_xattrs(s) && !REISERFS_SB(s)->priv_root) {
  1047. struct dentry *dentry;
  1048. dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
  1049. strlen(PRIVROOT_NAME));
  1050. if (!IS_ERR(dentry)) {
  1051. if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) {
  1052. struct inode *inode = dentry->d_parent->d_inode;
  1053. mutex_lock(&inode->i_mutex);
  1054. err = inode->i_op->mkdir(inode, dentry, 0700);
  1055. mutex_unlock(&inode->i_mutex);
  1056. if (err) {
  1057. dput(dentry);
  1058. dentry = NULL;
  1059. }
  1060. if (dentry && dentry->d_inode)
  1061. reiserfs_warning(s,
  1062. "Created %s on %s - reserved for "
  1063. "xattr storage.",
  1064. PRIVROOT_NAME,
  1065. reiserfs_bdevname
  1066. (inode->i_sb));
  1067. } else if (!dentry->d_inode) {
  1068. dput(dentry);
  1069. dentry = NULL;
  1070. }
  1071. } else
  1072. err = PTR_ERR(dentry);
  1073. if (!err && dentry) {
  1074. s->s_root->d_op = &xattr_lookup_poison_ops;
  1075. reiserfs_mark_inode_private(dentry->d_inode);
  1076. REISERFS_SB(s)->priv_root = dentry;
  1077. } else if (!(mount_flags & MS_RDONLY)) { /* xattrs are unavailable */
  1078. /* If we're read-only it just means that the dir hasn't been
  1079. * created. Not an error -- just no xattrs on the fs. We'll
  1080. * check again if we go read-write */
  1081. reiserfs_warning(s, "xattrs/ACLs enabled and couldn't "
  1082. "find/create .reiserfs_priv. Failing mount.");
  1083. err = -EOPNOTSUPP;
  1084. }
  1085. }
  1086. error:
  1087. /* This is only nonzero if there was an error initializing the xattr
  1088. * directory or if there is a condition where we don't support them. */
  1089. if (err) {
  1090. clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1091. clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt));
  1092. clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt));
  1093. }
  1094. /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */
  1095. s->s_flags = s->s_flags & ~MS_POSIXACL;
  1096. if (reiserfs_posixacl(s))
  1097. s->s_flags |= MS_POSIXACL;
  1098. return err;
  1099. }
  1100. static int reiserfs_check_acl(struct inode *inode, int mask)
  1101. {
  1102. struct posix_acl *acl;
  1103. int error = -EAGAIN; /* do regular unix permission checks by default */
  1104. reiserfs_read_lock_xattr_i(inode);
  1105. reiserfs_read_lock_xattrs(inode->i_sb);
  1106. acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
  1107. reiserfs_read_unlock_xattrs(inode->i_sb);
  1108. reiserfs_read_unlock_xattr_i(inode);
  1109. if (acl) {
  1110. if (!IS_ERR(acl)) {
  1111. error = posix_acl_permission(inode, acl, mask);
  1112. posix_acl_release(acl);
  1113. } else if (PTR_ERR(acl) != -ENODATA)
  1114. error = PTR_ERR(acl);
  1115. }
  1116. return error;
  1117. }
  1118. int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd)
  1119. {
  1120. /*
  1121. * We don't do permission checks on the internal objects.
  1122. * Permissions are determined by the "owning" object.
  1123. */
  1124. if (is_reiserfs_priv_object(inode))
  1125. return 0;
  1126. /*
  1127. * Stat data v1 doesn't support ACLs.
  1128. */
  1129. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  1130. return generic_permission(inode, mask, NULL);
  1131. else
  1132. return generic_permission(inode, mask, reiserfs_check_acl);
  1133. }