Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static unsigned int check_sharing( struct fd *fd, unsigned int access, unsigned int sharing,
- unsigned int open_flags, unsigned int options )
- {
- unsigned int existing_sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
- unsigned int existing_access = 0;
- struct list *ptr;
- fd->access = access;
- fd->sharing = sharing;
- LIST_FOR_EACH( ptr, &fd->inode->open )
- {
- struct fd *fd_ptr = LIST_ENTRY( ptr, struct fd, inode_entry );
- if (fd_ptr != fd)
- {
- /* if access mode is 0, sharing mode is ignored */
- if (fd_ptr->access & (FILE_READ_DATA | FILE_WRITE_DATA | DELETE))
- existing_sharing &= fd_ptr->sharing;
- existing_access |= fd_ptr->access;
- }
- }
- if (((access & FILE_READ_DATA) && !(existing_sharing & FILE_SHARE_READ)) ||
- ((access & FILE_WRITE_DATA) && !(existing_sharing & FILE_SHARE_WRITE)) ||
- ((access & DELETE) && !(existing_sharing & FILE_SHARE_DELETE)))
- return STATUS_SHARING_VIOLATION;
- if (((existing_access & FILE_MAPPING_WRITE) && !(sharing & FILE_SHARE_WRITE)) ||
- ((existing_access & FILE_MAPPING_IMAGE) && (access & FILE_SHARE_WRITE)))
- return STATUS_SHARING_VIOLATION;
- if ((existing_access & FILE_MAPPING_IMAGE) && (options & FILE_DELETE_ON_CLOSE))
- return STATUS_CANNOT_DELETE;
- if ((existing_access & FILE_MAPPING_ACCESS) && (open_flags & O_TRUNC))
- return STATUS_USER_MAPPED_FILE;
- if (!access) return 0; /* if access mode is 0, sharing mode is ignored (except for mappings) */
- if (((existing_access & FILE_READ_DATA) && !(sharing & FILE_SHARE_READ)) ||
- ((existing_access & FILE_WRITE_DATA) && !(sharing & FILE_SHARE_WRITE)) ||
- ((existing_access & DELETE) && !(sharing & FILE_SHARE_DELETE)))
- return STATUS_SHARING_VIOLATION;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement