Exemplo n.º 1
0
 def _register_file(self, fh):
     addr = self.cur_addr
     self.cur_addr += self.fh_size
     fh.addr = addr
     fh.b_addr = addr >> 2
     self.files_by_b_addr[fh.b_addr] = fh
     log_file.info("registered: %s" % fh)
Exemplo n.º 2
0
 def set_protection(self, ami_path, mask):
     sys_path = self.path_mgr.ami_to_sys_path(ami_path)
     if sys_path == None or not os.path.exists(sys_path):
         log_file.info("file to set proteciton not found: '%s'", ami_path)
         return ERROR_OBJECT_NOT_FOUND
     prot = DosProtection(mask)
     posix_mask = 0
     if prot.is_e():
         posix_mask |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
     if prot.is_w():
         posix_mask |= stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH
     if prot.is_r():
         posix_mask |= stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
     posix_mask &= ~self.umask
     log_file.info(
         "set protection: '%s': %s -> '%s': posix_mask=%03o umask=%03o",
         ami_path,
         prot,
         sys_path,
         posix_mask,
         self.umask,
     )
     try:
         os.chmod(sys_path, posix_mask)
         return NO_ERROR
     except OSError:
         return ERROR_OBJECT_WRONG_TYPE
Exemplo n.º 3
0
    def open(self, ami_path, f_mode):
        try:
            # special names
            uname = ami_path.upper()
            if uname == 'NIL:':
                sys_name = "/dev/null"
                fobj = open(sys_name, f_mode)
                fh = AmiFile(fobj, ami_path, sys_name)
            elif uname in ('*', 'CONSOLE:'):
                sys_name = ''
                fh = AmiFile(sys.stdout, '*', '', need_close=False)
            else:
                sys_path = self.path_mgr.ami_to_sys_path(ami_path)
                if sys_path == None:
                    log_file.info("file not found: '%s' -> '%s'" %
                                  (ami_path, sys_path))
                    return None
                fobj = open(sys_path, f_mode)
                fh = AmiFile(fobj, ami_path, sys_path)

            self._register_file(fh)
            return fh
        except IOError:
            log_file.info("error opening: '%s' -> '%s'" % (ami_path, sys_path))
            return None
Exemplo n.º 4
0
 def _register_file(self, fh):
     addr = self.cur_addr
     self.cur_addr += self.fh_size
     fh.addr = addr
     fh.b_addr = addr >> 2
     self.files_by_b_addr[fh.b_addr] = fh
     log_file.info("registered: %s" % fh)
Exemplo n.º 5
0
    def open(self, ami_path, f_mode):
        try:
            # special names
            uname = ami_path.upper()
            if uname == "NIL:":
                sys_name = "/dev/null"
                fobj = open(sys_name, f_mode)
                fh = AmiFile(fobj, ami_path, sys_name)
            elif uname in ("*", "CONSOLE:"):
                sys_name = ""
                fh = AmiFile(sys.stdout, "*", "", need_close=False)
            else:
                # map to system path
                sys_path = self.path_mgr.ami_to_sys_path(ami_path)
                if sys_path == None:
                    log_file.info("file not found: '%s' -> '%s'" % (ami_path, sys_path))
                    return None

                # make some checks on existing file
                if os.path.exists(sys_path):
                    # if not writeable -> no append mode
                    if not os.access(sys_path, os.W_OK):
                        if f_mode[-1] == "+":
                            f_mode = f_mode[:-1]

                log_file.debug("opening file: '%s' -> '%s' f_mode=%s" % (ami_path, sys_path, f_mode))
                fobj = open(sys_path, f_mode)
                fh = AmiFile(fobj, ami_path, sys_path)

            self._register_file(fh)
            return fh
        except IOError as e:
            log_file.info("error opening: '%s' -> '%s' f_mode=%s -> %s" % (ami_path, sys_path, f_mode, e))
            return None
Exemplo n.º 6
0
 def _unregister_file(self, fh):
     check = self.files_by_b_addr[fh.b_addr]
     if check != fh:
         raise ValueError("Invalid File to unregister: %s" % fh)
     del self.files_by_b_addr[fh.b_addr]
     log_file.info("unregistered: %s" % fh)
     fh.addr = 0
     fh.b_addr = 0
Exemplo n.º 7
0
 def _unregister_file(self, fh):
     check = self.files_by_b_addr[fh.b_addr]
     if check != fh:
         raise ValueError("Invalid File to unregister: %s" % fh)
     del self.files_by_b_addr[fh.b_addr]
     log_file.info("unregistered: %s" % fh)
     fh.addr = 0
     fh.b_addr = 0
Exemplo n.º 8
0
    def __init__(self, path_mgr, base_addr, size):
        self.path_mgr = path_mgr
        self.base_addr = base_addr
        self.cur_addr = base_addr
        log_file.info("init manager: base=%06x" % self.base_addr)
        self.files_by_b_addr = {}
        LabelRange.__init__(self, "files", base_addr, size)
        self.fh_def = FileHandleDef
        self.fh_size = FileHandleDef.get_size()
        self.fh_size = (self.fh_size + 3) & ~3

        # setup std input/output
        self.std_input = AmiFile(sys.stdin, '<STDIN>', '', need_close=False)
        self.std_output = AmiFile(sys.stdout, '<STDOUT>', '', need_close=False)
        self._register_file(self.std_input)
        self._register_file(self.std_output)

        # get current umask
        self.umask = os.umask(0)
        os.umask(self.umask)
Exemplo n.º 9
0
    def __init__(self, path_mgr, base_addr, size):
        self.path_mgr = path_mgr
        self.base_addr = base_addr
        self.cur_addr = base_addr
        log_file.info("init manager: base=%06x" % self.base_addr)
        self.files_by_b_addr = {}
        LabelRange.__init__(self, "files", base_addr, size)
        self.fh_def = FileHandleDef
        self.fh_size = FileHandleDef.get_size()
        self.fh_size = (self.fh_size + 3) & ~3

        # setup std input/output
        self.std_input = AmiFile(sys.stdin, "<STDIN>", "", need_close=False)
        self.std_output = AmiFile(sys.stdout, "<STDOUT>", "", need_close=False)
        self._register_file(self.std_input)
        self._register_file(self.std_output)

        # get current umask
        self.umask = os.umask(0)
        os.umask(self.umask)
Exemplo n.º 10
0
 def set_protection(self, ami_path, mask):
     sys_path = self.path_mgr.ami_to_sys_path(ami_path)
     if sys_path == None or not os.path.exists(sys_path):
         log_file.info("file to set proteciton not found: '%s'", ami_path)
         return ERROR_OBJECT_NOT_FOUND
     prot = DosProtection(mask)
     posix_mask = 0
     if prot.is_e():
         posix_mask |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
     if prot.is_w():
         posix_mask |= stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH
     if prot.is_r():
         posix_mask |= stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
     posix_mask &= ~self.umask
     log_file.info(
         "set protection: '%s': %s -> '%s': posix_mask=%03o umask=%03o",
         ami_path, prot, sys_path, posix_mask, self.umask)
     try:
         os.chmod(sys_path, posix_mask)
         return NO_ERROR
     except OSError:
         return ERROR_OBJECT_WRONG_TYPE
Exemplo n.º 11
0
 def open(self, ami_path, f_mode):
   try:
     # special names
     uname = ami_path.upper()
     if uname == 'NIL:':
       sys_name = "/dev/null" 
       fobj = open(sys_name, f_mode)
       fh = AmiFile(fobj, ami_path, sys_name)
     elif uname in ('*','CONSOLE:'):
       sys_name = ''
       fh = AmiFile(sys.stdout,'*','',need_close=False)
     else:
       sys_path = self.path_mgr.ami_to_sys_path(ami_path)
       if sys_path == None:
         log_file.info("file not found: '%s' -> '%s'" % (ami_path, sys_path))
         return None
       fobj = open(sys_path, f_mode)
       fh = AmiFile(fobj, ami_path, sys_path)
   
     self._register_file(fh)
     return fh
   except IOError:
     log_file.info("error opening: '%s' -> '%s'" % (ami_path, sys_path))
     return None
Exemplo n.º 12
0
 def rename(self, old_ami_path, new_ami_path):
     old_sys_path = self.path_mgr.ami_to_sys_path(old_ami_path)
     new_sys_path = self.path_mgr.ami_to_sys_path(new_ami_path)
     if old_sys_path == None or not os.path.exists(old_sys_path):
         log_file.info("old file to rename not found: '%s'" % old_ami_path)
         return ERROR_OBJECT_NOT_FOUND
     if new_sys_path == None:
         log_file.info("new file to rename not found: '%s'" % new_ami_path)
         return ERROR_OBJECT_NOT_FOUND
     try:
         os.rename(old_sys_path, new_sys_path)
         return 0
     except OSError as e:
         log_file.info("can't rename file: '%s','%s' -> %s" % (old_ami_path, new_ami_path, e))
         return ERROR_OBJECT_IN_USE
Exemplo n.º 13
0
 def rename(self, old_ami_path, new_ami_path):
     old_sys_path = self.path_mgr.ami_to_sys_path(old_ami_path)
     new_sys_path = self.path_mgr.ami_to_sys_path(new_ami_path)
     if old_sys_path == None or not os.path.exists(old_sys_path):
         log_file.info("old file to rename not found: '%s'" % old_ami_path)
         return ERROR_OBJECT_NOT_FOUND
     if new_sys_path == None:
         log_file.info("new file to rename not found: '%s'" % new_ami_path)
         return ERROR_OBJECT_NOT_FOUND
     try:
         os.rename(old_sys_path, new_sys_path)
         return 0
     except OSError as e:
         log_file.info("can't rename file: '%s','%s' -> %s" %
                       (old_ami_path, new_amipath, e))
         return ERROR_OBJECT_IN_USE
Exemplo n.º 14
0
 def delete(self, ami_path):
     sys_path = self.path_mgr.ami_to_sys_path(ami_path)
     if sys_path == None or not os.path.exists(sys_path):
         log_file.info("file to delete not found: '%s'" % (ami_path))
         return ERROR_OBJECT_NOT_FOUND
     try:
         if os.path.isdir(sys_path):
             os.rmdir(sys_path)
         else:
             os.remove(sys_path)
         return 0
     except OSError as e:
         if e.errno == errno.ENOTEMPTY:  # Directory not empty
             log_file.info("can't delete directory: '%s' -> not empty!" % (ami_path))
             return ERROR_DIRECTORY_NOT_EMPTY
         else:
             log_file.info("can't delete file: '%s' -> %s" % (ami_path, e))
             return ERROR_OBJECT_IN_USE
Exemplo n.º 15
0
 def delete(self, ami_path):
     sys_path = self.path_mgr.ami_to_sys_path(ami_path)
     if sys_path == None or not os.path.exists(sys_path):
         log_file.info("file to delete not found: '%s'" % (ami_path))
         return ERROR_OBJECT_NOT_FOUND
     try:
         if os.path.isdir(sys_path):
             os.rmdir(sys_path)
         else:
             os.remove(sys_path)
         return 0
     except OSError as e:
         if e.errno == errno.ENOTEMPTY:  # Directory not empty
             log_file.info("can't delete directory: '%s' -> not empty!" %
                           (ami_path))
             return ERROR_DIRECTORY_NOT_EMPTY
         else:
             log_file.info("can't delete file: '%s' -> %s" % (ami_path, e))
             return ERROR_OBJECT_IN_USE