#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
import os
import six
"""Test if a sys attr is not in the list of ignored attributes."""
for i in ignore:
if i == attr:
return False
return True
"""Get the list of set system attributes for file specified by 'path'.
Returns a list of verbose attributes by default. If 'compact' is True,
return a string consisting of compact option identifiers."""
raise TypeError("filename must be string type")
# ffi.gc return a new cdata object that points to the same data. Later,
# when this new cdata object is garbage-collected, the destructor
# (in this case 'lib.nvlist_free' will be called.
attr_list = []
if fd == -1:
count = 0
# we ignore all non-boolean attrs
continue
raise OSError("could not read attr value")
if bval[0]:
if compact:
if count >= F_ATTR_ALL:
raise OSError("Too many system attributes found")
count += 1
else:
# ffi.string returns a bytes
if string:
if compact:
return cattrs
return attr_list
"""Set system attributes for a file. The system attributes can either be
passed as a list of verbose attribute names or a string that consists of
a sequence of compact attribute options.
Raises ValueError for invalid system attributes or OSError (with errno set)
if any of the library calls fail.
Input examples:
verbose attributes example: ['hidden', 'archive', 'sensitive', ... ]
compact attributes example: 'HAT'
"""
raise TypeError("filename must be string type")
if not attr:
sys_attr = -1
# A single string indicates system attributes are passed in compact
# form (e.g. AHi), verbose attributes are read as a list of strings.
for c in attr:
c = force_bytes(c)
if compact:
else:
if compact:
raise ValueError("{0} is not a valid compact system "
else:
raise ValueError("{0} is not a valid verbose system "
if not is_supported(sys_attr):
if compact:
raise ValueError("{0} is not a supported compact system "
else:
raise ValueError("{0} is not a supported verbose system "
1) != 0:
if fd == -1:
def get_attr_dict():
"""Get a dictionary containing all supported system attributes in the form:
{ <verbose_name>: <compact_option>,
...
}
"""
sys_attrs = {}
for i in range(F_ATTR_ALL):
if not is_supported(i):
continue
return sys_attrs