Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. static unsigned int check_sharing( struct fd *fd, unsigned int access, unsigned int sharing,
  2.                                    unsigned int open_flags, unsigned int options )
  3. {
  4.     unsigned int existing_sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
  5.     unsigned int existing_access = 0;
  6.     struct list *ptr;
  7.  
  8.     fd->access = access;
  9.     fd->sharing = sharing;
  10.  
  11.     LIST_FOR_EACH( ptr, &fd->inode->open )
  12.     {
  13.         struct fd *fd_ptr = LIST_ENTRY( ptr, struct fd, inode_entry );
  14.         if (fd_ptr != fd)
  15.         {
  16.             /* if access mode is 0, sharing mode is ignored */
  17.             if (fd_ptr->access & (FILE_READ_DATA | FILE_WRITE_DATA | DELETE))
  18.                 existing_sharing &= fd_ptr->sharing;
  19.             existing_access  |= fd_ptr->access;
  20.         }
  21.     }
  22.  
  23.     if (((access & FILE_READ_DATA) && !(existing_sharing & FILE_SHARE_READ)) ||
  24.         ((access & FILE_WRITE_DATA) && !(existing_sharing & FILE_SHARE_WRITE)) ||
  25.         ((access & DELETE) && !(existing_sharing & FILE_SHARE_DELETE)))
  26.         return STATUS_SHARING_VIOLATION;
  27.     if (((existing_access & FILE_MAPPING_WRITE) && !(sharing & FILE_SHARE_WRITE)) ||
  28.         ((existing_access & FILE_MAPPING_IMAGE) && (access & FILE_SHARE_WRITE)))
  29.         return STATUS_SHARING_VIOLATION;
  30.     if ((existing_access & FILE_MAPPING_IMAGE) && (options & FILE_DELETE_ON_CLOSE))
  31.         return STATUS_CANNOT_DELETE;
  32.     if ((existing_access & FILE_MAPPING_ACCESS) && (open_flags & O_TRUNC))
  33.         return STATUS_USER_MAPPED_FILE;
  34.     if (!access) return 0;  /* if access mode is 0, sharing mode is ignored (except for mappings) */
  35.     if (((existing_access & FILE_READ_DATA) && !(sharing & FILE_SHARE_READ)) ||
  36.         ((existing_access & FILE_WRITE_DATA) && !(sharing & FILE_SHARE_WRITE)) ||
  37.         ((existing_access & DELETE) && !(sharing & FILE_SHARE_DELETE)))
  38.         return STATUS_SHARING_VIOLATION;
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement