我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用stat.S_IFBLK。
def get_file_type(path): """Retrieve the file type of the path :param path: The path to get the file type for :return: The file type as a string or None on error """ f_types = { 'socket': stat.S_IFSOCK, 'regular': stat.S_IFREG, 'block': stat.S_IFBLK, 'directory': stat.S_IFDIR, 'character_device': stat.S_IFCHR, 'fifo': stat.S_IFIFO, } if not path or not os.path.exists(path): return None obj = os.stat(path).st_mode for key,val in f_types.items(): if obj & val == val: return key
def makedev(self, type, major, minor): """Make a special file with specified type, and major/minor nums""" if type == 'c': datatype = 'chr' mode = stat.S_IFCHR | 0600 elif type == 'b': datatype = 'blk' mode = stat.S_IFBLK | 0600 else: raise RPathException try: self.conn.os.mknod(self.path, mode, self.conn.os.makedev(major, minor)) except (OSError, AttributeError), e: if isinstance(e, AttributeError) or e.errno == errno.EPERM: # AttributeError will be raised by Python 2.2, which # doesn't have os.mknod log.Log("unable to mknod %s -- using touch instead" % self.path, 4) self.touch() self.setdata()
def _initialize_aci(self, mode, fileType): valid_types = [ stat.S_IFREG, stat.S_IFDIR, stat.S_IFCHR, stat.S_IFBLK, stat.S_IFIFO, stat.S_IFLNK, stat.S_IFSOCK] if fileType not in valid_types: raise RuntimeError("Invalid file type.") aci = self.aciCollection.new() uid = os.getuid() aci.dbobj.id = uid aci.dbobj.uname = pwd.getpwuid(uid).pw_name aci.dbobj.gname = grp.getgrgid(os.getgid()).gr_name aci.dbobj.mode = int(mode, 8) + fileType aci.save() return aci.key
def mknod(self, path, mode, dev): # File can't exist already or upper levels of VFS reject the call. if mode & stat.S_IFBLK != stat.S_IFBLK: raise TmfsOSError(errno.ENOTBLK) rsp = self.librarian(self.lcp('get_shelf', path=path), errorOK=True) if 'errmsg' not in rsp: raise TmfsOSError(errno.EEXIST) nbooks = dev & 0xFF # minor if not nbooks: raise TmfsOSError(errno.EINVAL) mode &= 0o777 fh = self.create(path, 0, supermode=stat.S_IFBLK + mode) # w/shadow self.setxattr(path, 'user.LFS.AllocationPolicy', 'LocalNode'.encode(), 0) self.truncate(path, nbooks * self.bsize, fh) self.release(path, fh) # mknod(1m) immediately does a stat looking for S_IFBLK. # Not sure what else to do about shadow mode... return 0
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
def makedev(self, cpioinfo, cpiogetpath): """Make a character or block device called cpiogetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = cpioinfo.mode if cpioinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(cpiogetpath, mode, os.makedev(cpioinfo.devmajor, cpioinfo.devminor))