pub fn new_connection_validate_flags(
    parent_flags: u32,
    mut flags: u32,
    mode: u32,
) -> Result<u32, Status> {
    // There should be no MODE_TYPE_* flags set, except for, possibly, MODE_TYPE_DIRECTORY when
    // the target is a directory.
    if (mode & !MODE_PROTECTION_MASK) & !MODE_TYPE_DIRECTORY != 0 {
        if (mode & !MODE_PROTECTION_MASK) & MODE_TYPE_FILE != 0 {
            return Err(Status::NOT_FILE);
        } else {
            return Err(Status::INVALID_ARGS);
        };
    }

    if flags & OPEN_FLAG_NODE_REFERENCE != 0 {
        flags &= !OPEN_FLAG_NODE_REFERENCE;
        flags &= OPEN_FLAG_DIRECTORY | OPEN_FLAG_DESCRIBE;
    }

    // For directories OPEN_FLAG_POSIX means that WRITABLE permission need to be inherited from the
    // parent connection.  As this method is only used for directories, here it applies always.
    if flags & OPEN_FLAG_POSIX != 0 {
        if parent_flags & OPEN_RIGHT_WRITABLE != 0 {
            flags |= OPEN_RIGHT_WRITABLE;
        }
        flags &= !OPEN_FLAG_POSIX;
    }

    let allowed_flags =
        OPEN_FLAG_DESCRIBE | OPEN_FLAG_DIRECTORY | OPEN_RIGHT_READABLE | OPEN_RIGHT_WRITABLE;

    let prohibited_flags =
        OPEN_FLAG_APPEND | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_IF_ABSENT | OPEN_FLAG_TRUNCATE;

    if !stricter_or_same_rights(flags, parent_flags) {
        return Err(Status::ACCESS_DENIED);
    }

    // Pseudo directories do not allow mounting at this point.
    if flags & OPEN_RIGHT_ADMIN != 0 {
        return Err(Status::ACCESS_DENIED);
    }

    if flags & prohibited_flags != 0 {
        return Err(Status::INVALID_ARGS);
    }

    if flags & !allowed_flags != 0 {
        return Err(Status::NOT_SUPPORTED);
    }

    Ok(flags)
}
/// Compares flags provided for a new connection with the flags of a parent connection.  Returns
/// adjusted flags for the new connection (cleaning up some ambiguities) or a fidl Status error, in
/// case new new connection flags are not permitting the connection to be opened.
Compares flags provided for a new connection with the flags of a parent connection.  Returns
adjusted flags for the new connection (cleaning up some ambiguities) or a fidl Status error, in
case new new connection flags are not permitting the connection to be opened.
Compares flags provided for a new connection with the flags of a parent connection . Returns adjusted flags for the new connection ( cleaning up some ambiguities ) or a fidl Status error in case new new connection flags are not permitting the connection to be opened .
pub fn new_connection_validate_flags(
    parent_flags: u32,
    mut flags: u32,
    mode: u32,
) -> Result<u32, Status> {
    // There should be no MODE_TYPE_* flags set, except for, possibly, MODE_TYPE_DIRECTORY when
    // the target is a directory.
    if (mode & !MODE_PROTECTION_MASK) & !MODE_TYPE_DIRECTORY != 0 {
        if (mode & !MODE_PROTECTION_MASK) & MODE_TYPE_FILE != 0 {
            return Err(Status::NOT_FILE);
        } else {
            return Err(Status::INVALID_ARGS);
        };
    }
    if flags & OPEN_FLAG_NODE_REFERENCE != 0 {
        flags &= !OPEN_FLAG_NODE_REFERENCE;
        flags &= OPEN_FLAG_DIRECTORY | OPEN_FLAG_DESCRIBE;
    }
    // For directories OPEN_FLAG_POSIX means that WRITABLE permission need to be inherited from the
    // parent connection.  As this method is only used for directories, here it applies always.
    if flags & OPEN_FLAG_POSIX != 0 {
        if parent_flags & OPEN_RIGHT_WRITABLE != 0 {
            flags |= OPEN_RIGHT_WRITABLE;
        }
        flags &= !OPEN_FLAG_POSIX;
    }
    let allowed_flags =
        OPEN_FLAG_DESCRIBE | OPEN_FLAG_DIRECTORY | OPEN_RIGHT_READABLE | OPEN_RIGHT_WRITABLE;
    let prohibited_flags =
        OPEN_FLAG_APPEND | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_IF_ABSENT | OPEN_FLAG_TRUNCATE;
    if !stricter_or_same_rights(flags, parent_flags) {
        return Err(Status::ACCESS_DENIED);
    }
    // Pseudo directories do not allow mounting at this point.
    if flags & OPEN_RIGHT_ADMIN != 0 {
        return Err(Status::ACCESS_DENIED);
    }
    if flags & prohibited_flags != 0 {
        return Err(Status::INVALID_ARGS);
    }
    if flags & !allowed_flags != 0 {
        return Err(Status::NOT_SUPPORTED);
    }
    Ok(flags)
}
pub fn new_connection_validate_flags ( parent_flags : u32 , mut flags : u32 , mode : u32 , ) -> Result < u32 , Status > { // There should be no MODE_TYPE_* flags set, except for, possibly, MODE_TYPE_DIRECTORY when // the target is a directory. if ( mode & ! MODE_PROTECTION_MASK ) & ! MODE_TYPE_DIRECTORY != 0 { if ( mode & ! MODE_PROTECTION_MASK ) & MODE_TYPE_FILE != 0 { return Err ( Status :: NOT_FILE ) ; } else { return Err ( Status :: INVALID_ARGS ) ; } ; } if flags & OPEN_FLAG_NODE_REFERENCE != 0 { flags &= ! OPEN_FLAG_NODE_REFERENCE ; flags &= OPEN_FLAG_DIRECTORY | OPEN_FLAG_DESCRIBE ; } // For directories OPEN_FLAG_POSIX means that WRITABLE permission need to be inherited from the // parent connection.  As this method is only used for directories, here it applies always. if flags & OPEN_FLAG_POSIX != 0 { if parent_flags & OPEN_RIGHT_WRITABLE != 0 { flags |= OPEN_RIGHT_WRITABLE ; } flags &= ! OPEN_FLAG_POSIX ; } let allowed_flags = OPEN_FLAG_DESCRIBE | OPEN_FLAG_DIRECTORY | OPEN_RIGHT_READABLE | OPEN_RIGHT_WRITABLE ; let prohibited_flags = OPEN_FLAG_APPEND | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_IF_ABSENT | OPEN_FLAG_TRUNCATE ; if ! stricter_or_same_rights ( flags , parent_flags ) { return Err ( Status :: ACCESS_DENIED ) ; } // Pseudo directories do not allow mounting at this point. if flags & OPEN_RIGHT_ADMIN != 0 { return Err ( Status :: ACCESS_DENIED ) ; } if flags & prohibited_flags != 0 { return Err ( Status :: INVALID_ARGS ) ; } if flags & ! allowed_flags != 0 { return Err ( Status :: NOT_SUPPORTED ) ; } Ok ( flags ) }
Compares flags provided for a new connection with the flags of a parent connection.
Compares flags provided for a new connection with the flags of a parent connection .
parent_flags
u32
flags
u32
mode
u32
parent_flags
u32
flags
u32
mode
u32