Python os.O_SYNC Examples
The following are 30
code examples of os.O_SYNC().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: qemu.py From redqueen with GNU Affero General Public License v3.0 | 6 votes |
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
Example #2
Source File: test_fileno.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_open_sync(self): if not hasattr(os, 'O_SYNC'): return # Just ensure this works self.fd = os.open(self.filename, os.O_SYNC | os.O_WRONLY | os.O_CREAT) self.assert_(os.path.exists(self.filename)) os.write(self.fd, 'jython') raises(OSError, 9, os.read, self.fd, 99) os.close(self.fd) os.remove(self.filename) self.fd = os.open(self.filename, os.O_SYNC | os.O_RDWR | os.O_CREAT) self.assert_(os.path.exists(self.filename)) os.write(self.fd, 'jython') os.lseek(self.fd, 0, 0) self.assertEquals(os.read(self.fd, len('jython')), 'jython') os.close(self.fd)
Example #3
Source File: pyfakewebcam.py From pyfakewebcam with GNU Lesser General Public License v3.0 | 6 votes |
def __init__(self, video_device, width, height, channels=3, input_pixfmt='RGB'): if channels != 3: raise NotImplementedError('Code only supports inputs with 3 channels right now. You tried to intialize with {} channels'.format(channels)) if input_pixfmt != 'RGB': raise NotImplementedError('Code only supports RGB pixfmt. You tried to intialize with {}'.format(input_pixfmt)) if not os.path.exists(video_device): sys.stderr.write('\n--- Make sure the v4l2loopback kernel module is loaded ---\n') sys.stderr.write('sudo modprobe v4l2loopback devices=1\n\n') raise FileNotFoundError('device does not exist: {}'.format(video_device)) self._channels = channels self._video_device = os.open(video_device, os.O_WRONLY | os.O_SYNC) self._settings = _v4l2.v4l2_format() self._settings.type = _v4l2.V4L2_BUF_TYPE_VIDEO_OUTPUT self._settings.fmt.pix.pixelformat = _v4l2.V4L2_PIX_FMT_YUYV self._settings.fmt.pix.width = width self._settings.fmt.pix.height = height self._settings.fmt.pix.field = _v4l2.V4L2_FIELD_NONE self._settings.fmt.pix.bytesperline = width * 2 self._settings.fmt.pix.sizeimage = width * height * 2 self._settings.fmt.pix.colorspace = _v4l2.V4L2_COLORSPACE_JPEG self._buffer = np.zeros((self._settings.fmt.pix.height, 2*self._settings.fmt.pix.width), dtype=np.uint8) self._yuv = np.zeros((self._settings.fmt.pix.height, self._settings.fmt.pix.width, 3), dtype=np.uint8) self._ones = np.ones((self._settings.fmt.pix.height, self._settings.fmt.pix.width, 1), dtype=np.uint8) self._rgb2yuv = np.array([[0.299, 0.587, 0.114, 0], [-0.168736, -0.331264, 0.5, 128], [0.5, -0.418688, -0.081312, 128]]) fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings)
Example #4
Source File: test_fileno.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_open_sync(self): if not hasattr(os, 'O_SYNC'): return # Just ensure this works self.fd = os.open(self.filename, os.O_SYNC | os.O_WRONLY | os.O_CREAT) self.assert_(os.path.exists(self.filename)) os.write(self.fd, 'jython') raises(OSError, 9, os.read, self.fd, 99) os.close(self.fd) os.remove(self.filename) self.fd = os.open(self.filename, os.O_SYNC | os.O_RDWR | os.O_CREAT) self.assert_(os.path.exists(self.filename)) os.write(self.fd, 'jython') os.lseek(self.fd, 0, 0) self.assertEquals(os.read(self.fd, len('jython')), 'jython') os.close(self.fd)
Example #5
Source File: master.py From redqueen with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #6
Source File: motordevice.py From ev3 with Apache License 2.0 | 6 votes |
def open_device(): global _initialized if not _initialized: global _pwmfile _pwmfile = os.open(lms2012.PWM_DEVICE_NAME, os.O_RDWR | os.O_SYNC) global _motorfile _motorfile = os.open(lms2012.MOTOR_DEVICE_NAME, os.O_RDWR | os.O_SYNC) MOTORDATAArrray = lms2012.MOTORDATA * 4 global _motormm _motormm = mmap(fileno=_motorfile, length=sizeof(MOTORDATAArrray), flags=MAP_SHARED, prot=PROT_READ | PROT_WRITE, offset=0) global _motordata _motordata = MOTORDATAArrray.from_buffer(_motormm) _initialized = True os.write(_pwmfile, struct.pack('B', lms2012.opPROGRAM_START)) # This does not look required. Types are TACHO (for the big engines) and MINITACHO for the gun one # and firmware should recognize them properly. # def set_types(types): # os.write(_pwmfile, struct.pack('5B', lms2012.opOUTPUT_SET_TYPE, *types))
Example #7
Source File: qemu.py From kAFL with GNU General Public License v2.0 | 6 votes |
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
Example #8
Source File: qemu.py From kAFL with GNU General Public License v2.0 | 6 votes |
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)
Example #9
Source File: qemu.py From redqueen with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #10
Source File: master.py From kAFL with GNU General Public License v2.0 | 6 votes |
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)
Example #11
Source File: test_fileno.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_open_sync(self): if not hasattr(os, 'O_SYNC'): return # Just ensure this works self.fd = os.open(self.filename, os.O_SYNC | os.O_WRONLY | os.O_CREAT) self.assert_(os.path.exists(self.filename)) os.write(self.fd, 'jython') raises(OSError, 9, os.read, self.fd, 99) os.close(self.fd) os.remove(self.filename) self.fd = os.open(self.filename, os.O_SYNC | os.O_RDWR | os.O_CREAT) self.assert_(os.path.exists(self.filename)) os.write(self.fd, 'jython') os.lseek(self.fd, 0, 0) self.assertEquals(os.read(self.fd, len('jython')), 'jython') os.close(self.fd)
Example #12
Source File: posixfile.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #13
Source File: test_fileno.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_open_sync_dir(self): if not hasattr(os, 'O_SYNC'): return self.dir = tempfile.mkdtemp() try: self.fd = os.open(self.dir, os.O_SYNC | os.O_RDWR) except OSError, ose: assert ose.errno == errno.EISDIR, ose.errno
Example #14
Source File: posixfile.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #15
Source File: posixfile.py From unity-python with MIT License | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #16
Source File: mmio.py From throttled with MIT License | 5 votes |
def _open(self, physaddr, size): if not isinstance(physaddr, (int, long)): raise TypeError("Invalid physaddr type, should be integer.") if not isinstance(size, (int, long)): raise TypeError("Invalid size type, should be integer.") pagesize = os.sysconf(os.sysconf_names['SC_PAGESIZE']) self._physaddr = physaddr self._size = size self._aligned_physaddr = physaddr - (physaddr % pagesize) self._aligned_size = size + (physaddr - self._aligned_physaddr) try: fd = os.open("/dev/mem", os.O_RDWR | os.O_SYNC) except OSError as e: raise MMIOError(e.errno, "Opening /dev/mem: " + e.strerror) try: self.mapping = mmap.mmap( fd, self._aligned_size, flags=mmap.MAP_SHARED, prot=mmap.PROT_WRITE, offset=self._aligned_physaddr) except OSError as e: raise MMIOError(e.errno, "Mapping /dev/mem: " + e.strerror) try: os.close(fd) except OSError as e: raise MMIOError(e.errno, "Closing /dev/mem: " + e.strerror) # Methods
Example #17
Source File: communicator.py From redqueen with GNU Affero General Public License v3.0 | 5 votes |
def __get_shm(self, type_id, slave_id): if slave_id in self.tmp_shm[type_id]: shm = self.tmp_shm[type_id][slave_id] else: shm_fd = os.open(self.files[type_id] + str(slave_id), os.O_RDWR | os.O_SYNC) shm = mmap.mmap(shm_fd, self.sizes[type_id]*self.tasks_per_requests, mmap.MAP_SHARED, mmap.PROT_WRITE | mmap.PROT_READ) self.tmp_shm[type_id][slave_id] = shm return shm
Example #18
Source File: communicator.py From redqueen with GNU Affero General Public License v3.0 | 5 votes |
def create_shm(self): for j in range(len(self.files)): for i in range(self.num_processes): shm_f = os.open(self.files[j]+str(i), os.O_CREAT | os.O_RDWR | os.O_SYNC) os.ftruncate(shm_f, self.sizes[j]*self.tasks_per_requests) os.close(shm_f)
Example #19
Source File: posixfile.py From canape with GNU General Public License v3.0 | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #20
Source File: posixfile.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #21
Source File: posixfile.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #22
Source File: test_fileno.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_open_sync_dir(self): if not hasattr(os, 'O_SYNC'): return self.dir = tempfile.mkdtemp() try: self.fd = os.open(self.dir, os.O_SYNC | os.O_RDWR) except OSError, ose: assert ose.errno == errno.EISDIR, ose.errno
Example #23
Source File: test_fileno.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_open_sync_dir(self): if not hasattr(os, 'O_SYNC'): return self.dir = tempfile.mkdtemp() try: self.fd = os.open(self.dir, os.O_SYNC | os.O_RDWR) except OSError, ose: assert ose.errno == errno.EISDIR, ose.errno
Example #24
Source File: mmio.py From python-periphery with MIT License | 5 votes |
def _open(self, physaddr, size): if not isinstance(physaddr, (int, long)): raise TypeError("Invalid physaddr type, should be integer.") if not isinstance(size, (int, long)): raise TypeError("Invalid size type, should be integer.") pagesize = os.sysconf(os.sysconf_names['SC_PAGESIZE']) self._physaddr = physaddr self._size = size self._aligned_physaddr = physaddr - (physaddr % pagesize) self._aligned_size = size + (physaddr - self._aligned_physaddr) try: fd = os.open("/dev/mem", os.O_RDWR | os.O_SYNC) except OSError as e: raise MMIOError(e.errno, "Opening /dev/mem: " + e.strerror) try: self.mapping = mmap.mmap(fd, self._aligned_size, flags=mmap.MAP_SHARED, prot=(mmap.PROT_READ | mmap.PROT_WRITE), offset=self._aligned_physaddr) except OSError as e: raise MMIOError(e.errno, "Mapping /dev/mem: " + e.strerror) try: os.close(fd) except OSError as e: raise MMIOError(e.errno, "Closing /dev/mem: " + e.strerror) # Methods
Example #25
Source File: posixfile.py From meddle with MIT License | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #26
Source File: posixfile.py From ironpython2 with Apache License 2.0 | 5 votes |
def flags(self, *which): import fcntl, os if which: if len(which) > 1: raise TypeError, 'Too many arguments' which = which[0] else: which = '?' l_flags = 0 if 'n' in which: l_flags = l_flags | os.O_NDELAY if 'a' in which: l_flags = l_flags | os.O_APPEND if 's' in which: l_flags = l_flags | os.O_SYNC file = self._file_ if '=' not in which: cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if '!' in which: l_flags = cur_fl & ~ l_flags else: l_flags = cur_fl | l_flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags) if 'c' in which: arg = ('!' not in which) # 0 is don't, 1 is do close on exec l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg) if '?' in which: which = '' # Return current flags l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0) if os.O_APPEND & l_flags: which = which + 'a' if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1: which = which + 'c' if os.O_NDELAY & l_flags: which = which + 'n' if os.O_SYNC & l_flags: which = which + 's' return which
Example #27
Source File: bitmap.py From grimoire with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #28
Source File: qemu.py From grimoire with GNU Affero General Public License v3.0 | 5 votes |
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
Example #29
Source File: rpgpio_private.py From PyCNC with MIT License | 5 votes |
def _open_dev(name): fd = os.open(name, os.O_SYNC | os.O_RDWR) if fd < 0: raise IOError("Failed to open " + name) return fd
Example #30
Source File: ads111x.py From PyCNC with MIT License | 5 votes |
def __init__(self): self._os_close = os.close # Initialize i2c interface and register it for closing on exit. self._dev = os.open("/dev/i2c-1", os.O_SYNC | os.O_RDWR) if self._dev < 0: raise ImportError("i2c device not found") else: if fcntl.ioctl(self._dev, I2C_SLAVE, ADS111x_ADDRESS) < 0: self._close() raise ImportError("Failed to set up i2c address") else: atexit.register(self._close)