~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/lockd/svcshare.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * linux/fs/lockd/svcshare.c
  4  *
  5  * Management of DOS shares.
  6  *
  7  * Copyright (C) 1996 Olaf Kirch <okir@monad.swb.de>
  8  */
  9 
 10 #include <linux/time.h>
 11 #include <linux/unistd.h>
 12 #include <linux/string.h>
 13 #include <linux/slab.h>
 14 
 15 #include <linux/sunrpc/clnt.h>
 16 #include <linux/sunrpc/svc.h>
 17 #include <linux/lockd/lockd.h>
 18 #include <linux/lockd/share.h>
 19 
 20 static inline int
 21 nlm_cmp_owner(struct nlm_share *share, struct xdr_netobj *oh)
 22 {
 23         return share->s_owner.len == oh->len
 24             && !memcmp(share->s_owner.data, oh->data, oh->len);
 25 }
 26 
 27 __be32
 28 nlmsvc_share_file(struct nlm_host *host, struct nlm_file *file,
 29                         struct nlm_args *argp)
 30 {
 31         struct nlm_share        *share;
 32         struct xdr_netobj       *oh = &argp->lock.oh;
 33         u8                      *ohdata;
 34 
 35         for (share = file->f_shares; share; share = share->s_next) {
 36                 if (share->s_host == host && nlm_cmp_owner(share, oh))
 37                         goto update;
 38                 if ((argp->fsm_access & share->s_mode)
 39                  || (argp->fsm_mode   & share->s_access ))
 40                         return nlm_lck_denied;
 41         }
 42 
 43         share = kmalloc(sizeof(*share) + oh->len,
 44                                                 GFP_KERNEL);
 45         if (share == NULL)
 46                 return nlm_lck_denied_nolocks;
 47 
 48         /* Copy owner handle */
 49         ohdata = (u8 *) (share + 1);
 50         memcpy(ohdata, oh->data, oh->len);
 51 
 52         share->s_file       = file;
 53         share->s_host       = host;
 54         share->s_owner.data = ohdata;
 55         share->s_owner.len  = oh->len;
 56         share->s_next       = file->f_shares;
 57         file->f_shares      = share;
 58 
 59 update:
 60         share->s_access = argp->fsm_access;
 61         share->s_mode   = argp->fsm_mode;
 62         return nlm_granted;
 63 }
 64 
 65 /*
 66  * Delete a share.
 67  */
 68 __be32
 69 nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
 70                         struct nlm_args *argp)
 71 {
 72         struct nlm_share        *share, **shpp;
 73         struct xdr_netobj       *oh = &argp->lock.oh;
 74 
 75         for (shpp = &file->f_shares; (share = *shpp) != NULL;
 76                                         shpp = &share->s_next) {
 77                 if (share->s_host == host && nlm_cmp_owner(share, oh)) {
 78                         *shpp = share->s_next;
 79                         kfree(share);
 80                         return nlm_granted;
 81                 }
 82         }
 83 
 84         /* X/Open spec says return success even if there was no
 85          * corresponding share. */
 86         return nlm_granted;
 87 }
 88 
 89 /*
 90  * Traverse all shares for a given file, and delete
 91  * those owned by the given (type of) host
 92  */
 93 void nlmsvc_traverse_shares(struct nlm_host *host, struct nlm_file *file,
 94                 nlm_host_match_fn_t match)
 95 {
 96         struct nlm_share        *share, **shpp;
 97 
 98         shpp = &file->f_shares;
 99         while ((share = *shpp) !=  NULL) {
100                 if (match(share->s_host, host)) {
101                         *shpp = share->s_next;
102                         kfree(share);
103                         continue;
104                 }
105                 shpp = &share->s_next;
106         }
107 }
108 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php