本文整理汇总了Python中os.ftruncate方法的典型用法代码示例。如果您正苦于以下问题:Python os.ftruncate方法的具体用法?Python os.ftruncate怎么用?Python os.ftruncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.ftruncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wipe
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def wipe(self):
filter_bitmap_fd = os.open("/dev/shm/kafl_filter0", os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(filter_bitmap_fd, self.config.config_values['BITMAP_SHM_SIZE'])
filter_bitmap = mmap.mmap(filter_bitmap_fd, self.config.config_values['BITMAP_SHM_SIZE'], mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
for i in range(self.config.config_values['BITMAP_SHM_SIZE']):
filter_bitmap[i] = '\x00'
filter_bitmap.close()
os.close(filter_bitmap_fd)
filter_bitmap_fd = os.open("/dev/shm/kafl_tfilter", os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(filter_bitmap_fd, 0x1000000)
filter_bitmap = mmap.mmap(filter_bitmap_fd, 0x1000000, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
for i in range(0x1000000):
filter_bitmap[i] = '\x00'
filter_bitmap.close()
os.close(filter_bitmap_fd)
示例2: __set_binary
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def __set_binary(self, filename, binaryfile, max_size):
shm_fd = os.open(filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(shm_fd, max_size)
shm = mmap.mmap(shm_fd, max_size, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
shm.seek(0x0)
shm.write('\x00' * max_size)
shm.seek(0x0)
f = open(binaryfile, "rb")
bytes = f.read(1024)
if bytes:
shm.write(bytes)
while bytes != "":
bytes = f.read(1024)
if bytes:
shm.write(bytes)
f.close()
shm.close()
os.close(shm_fd)
示例3: init
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def init(self):
self.control = socket.socket(socket.AF_UNIX)
while True:
try:
self.control.connect(self.control_filename)
#self.control.connect(self.control_filename)
break
except socket_error:
pass
#time.sleep(0.01)
self.kafl_shm_f = os.open(self.bitmap_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
self.fs_shm_f = os.open(self.payload_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
#argv_fd = os.open(self.argv_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(self.kafl_shm_f, self.bitmap_size)
os.ftruncate(self.fs_shm_f, (128 << 10))
#os.ftruncate(argv_fd, (4 << 10))
self.kafl_shm = mmap.mmap(self.kafl_shm_f, self.bitmap_size, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
self.fs_shm = mmap.mmap(self.fs_shm_f, (128 << 10), mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
return True
示例4: wipe
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def wipe(self):
filter_bitmap_fd = os.open("/dev/shm/kafl_filter0", os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(filter_bitmap_fd, self.config.config_values['BITMAP_SHM_SIZE'])
filter_bitmap = mmap.mmap(filter_bitmap_fd, self.config.config_values['BITMAP_SHM_SIZE'], mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
for i in range(self.config.config_values['BITMAP_SHM_SIZE']):
filter_bitmap[i] = '\x00'
filter_bitmap.close()
os.close(filter_bitmap_fd)
filter_bitmap_fd = os.open("/dev/shm/kafl_tfilter", os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(filter_bitmap_fd, 0x1000000)
filter_bitmap = mmap.mmap(filter_bitmap_fd, 0x1000000, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
for i in range(0x1000000):
filter_bitmap[i] = '\x00'
filter_bitmap.close()
os.close(filter_bitmap_fd)
示例5: __set_binary
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def __set_binary(self, filename, binaryfile, max_size):
shm_fd = os.open(filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(shm_fd, max_size)
shm = mmap.mmap(shm_fd, max_size, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
shm.seek(0x0)
shm.write('\x00' * max_size)
shm.seek(0x0)
f = open(binaryfile, "rb")
bytes = f.read(1024)
if bytes:
shm.write(bytes)
while bytes != "":
bytes = f.read(1024)
if bytes:
shm.write(bytes)
shm.flush()
f.close()
shm.close()
os.close(shm_fd)
示例6: init
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def init(self):
self.control = safe_socket(socket.AF_UNIX)
self.control.settimeout(None)
self.control.setblocking(1)
while True:
try:
self.control.connect(self.control_filename)
break
except socket_error:
pass
self.kafl_shm_f = os.open(self.bitmap_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
self.fs_shm_f = os.open(self.payload_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(self.kafl_shm_f, self.bitmap_size)
os.ftruncate(self.fs_shm_f, (128 << 10))
self.kafl_shm = mmap.mmap(self.kafl_shm_f, self.bitmap_size, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
self.fs_shm = mmap.mmap(self.fs_shm_f, (128 << 10), mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
return True
示例7: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def __init__(self, name, shape, dtype=np.float32, uuid=""):
self.shape = shape
self.dtype = dtype
size = reduce(lambda x, y: x * y, shape)
size_bytes = np.dtype(dtype).itemsize * size
self._mem_path = None
self._mem_pointer = None
if os.name == "nt":
self._mem_path = "/HOLODECK_MEM" + uuid + "_" + name
self._mem_pointer = mmap.mmap(0, size_bytes, self._mem_path)
elif os.name == "posix":
self._mem_path = "/dev/shm/HOLODECK_MEM" + uuid + "_" + name
f = os.open(self._mem_path, os.O_CREAT | os.O_TRUNC | os.O_RDWR)
self._mem_file = f
os.ftruncate(f, size_bytes)
os.fsync(f)
# TODO - I think we are leaking a file object here. Unfortunately, we
# can't just .close() it since numpy acquires a reference to it
# below and I can't find a way to release it in __linux_unlink__()
self._mem_pointer = mmap.mmap(f, size_bytes)
else:
raise HolodeckException("Currently unsupported os: " + os.name)
self.np_array = np.ndarray(shape, dtype=dtype)
self.np_array.data = (Shmem._numpy_to_ctype[dtype] * size).from_buffer(self._mem_pointer)
示例8: write_pid_file
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def write_pid_file(pid_file, pid):
import fcntl
import stat
try:
fd = os.open(pid_file, os.O_RDWR | os.O_CREAT,
stat.S_IRUSR | stat.S_IWUSR)
except OSError as e:
shell.print_exception(e)
return -1
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
assert flags != -1
flags |= fcntl.FD_CLOEXEC
r = fcntl.fcntl(fd, fcntl.F_SETFD, flags)
assert r != -1
# There is no platform independent way to implement fcntl(fd, F_SETLK, &fl)
# via fcntl.fcntl. So use lockf instead
try:
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB, 0, 0, os.SEEK_SET)
except IOError:
r = os.read(fd, 32)
if r:
logging.error('already started at pid %s' % common.to_str(r))
else:
logging.error('already started')
os.close(fd)
return -1
os.ftruncate(fd, 0)
os.write(fd, common.to_bytes(str(pid)))
return 0
示例9: test_ftruncate
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def test_ftruncate(self):
self.check(os.ftruncate, 0)
示例10: create_bitmap
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def create_bitmap(self, name):
self.bitmap_fd = os.open(self.config.argument_values['work_dir'] + "/bitmaps/" + name,
os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(self.bitmap_fd, self.config.config_values['BITMAP_SHM_SIZE'])
self.bitmap = mmap.mmap(self.bitmap_fd, self.bitmap_size, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
示例11: init
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def init(self):
self.control = safe_socket(socket.AF_UNIX)
self.control.settimeout(None)
self.control.setblocking(1)
while True:
try:
self.control.connect(self.control_filename)
# self.control.connect(self.control_filename)
break
except socket_error:
pass
# time.sleep(0.01)
self.kafl_shm_f = os.open(self.bitmap_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
self.fs_shm_f = os.open(self.payload_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
open(self.tracedump_filename, "wb").close()
os.symlink(self.tracedump_filename, self.config.argument_values['work_dir'] + "/pt_trace_dump_" + self.qemu_id)
os.symlink(self.payload_filename, self.config.argument_values['work_dir'] + "/payload_" + self.qemu_id)
os.symlink(self.bitmap_filename, self.config.argument_values['work_dir'] + "/bitmap_" + self.qemu_id)
# argv_fd = os.open(self.argv_filename, os.O_RDWR | os.O_SYNC | os.O_CREAT)
os.ftruncate(self.kafl_shm_f, self.bitmap_size)
os.ftruncate(self.fs_shm_f, (128 << 10))
# os.ftruncate(argv_fd, (4 << 10))
self.kafl_shm = mmap.mmap(self.kafl_shm_f, self.bitmap_size, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
self.c_bitmap = (ctypes.c_uint8 * self.bitmap_size).from_buffer(self.kafl_shm)
self.last_bitmap_wrapper = ExecutionResult(None, None, None, None)
self.fs_shm = mmap.mmap(self.fs_shm_f, (128 << 10), mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ)
return True
示例12: test_ftruncate
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def test_ftruncate(self):
if hasattr(os, "ftruncate"):
self.check(os.ftruncate, 0)
示例13: test_open_bag_with_malformed_bagit_txt
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def test_open_bag_with_malformed_bagit_txt(self):
logger.info(self.getTestHeader(sys._getframe().f_code.co_name))
bagit.make_bag(self.tmpdir)
with open(j(self.tmpdir, 'bagit.txt'), 'w') as f:
os.ftruncate(f.fileno(), 0)
with self.assertRaises(bagit.BagError) as error_catcher:
bagit.BDBag(self.tmpdir)
self.assertEqual('Missing required tag in bagit.txt: BagIt-Version, Tag-File-Character-Encoding',
str(error_catcher.exception))
示例14: __exit__
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def __exit__(self, type, value, traceback):
try:
os.lseek(self.opened, 0, os.SEEK_SET)
os.ftruncate(self.opened, 0)
if "removelockfile" in COVERAGE: # actually an optional implementation
lockfile = self.lockfile()
lockname = os.path.basename(lockfile)
os.unlink(lockfile) # ino is kept allocated because opened by this process
logg.debug("[%s] lockfile removed for %s", os.getpid(), lockname)
fcntl.flock(self.opened, fcntl.LOCK_UN)
os.close(self.opened) # implies an unlock but that has happend like 6 seconds later
self.opened = None
except Exception as e:
logg.warning("oops, %s", e)
示例15: setstat
# 需要导入模块: import os [as 别名]
# 或者: from os import ftruncate [as 别名]
def setstat(self, filename, attrs, fsetstat=False):
"""setstat and fsetstat requests.
Filename is an handle in the fstat variant.
If you're using Python < 3.3,
you could find useful the futimes file / function.
"""
if not fsetstat:
f = os.open(filename, os.O_WRONLY)
chown = os.chown
chmod = os.chmod
else: # filename is a fd
f = filename
chown = os.fchown
chmod = os.fchmod
if b'size' in attrs:
os.ftruncate(f, attrs[b'size'])
if all(k in attrs for k in (b'uid', b'gid')):
chown(filename, attrs[b'uid'], attrs[b'gid'])
if b'perm' in attrs:
chmod(filename, attrs[b'perm'])
if all(k in attrs for k in (b'atime', b'mtime')):
if not fsetstat:
os.utime(filename, (attrs[b'atime'], attrs[b'mtime']))
else:
futimes(filename, (attrs[b'atime'], attrs[b'mtime']))