예제 #1
0
파일: Lock.py 프로젝트: simontoens/amitools
 def examine_file(self, fib_mem, name, sys_path):
     # name
     name_addr = fib_mem.s_get_addr('fib_FileName')
     # clear 32 name bytes
     mem = fib_mem.mem
     mem.clear_block(name_addr, 32, 0)
     mem.w_cstr(name_addr, name)
     # comment
     comment_addr = fib_mem.s_get_addr('fib_Comment')
     mem.w_cstr(comment_addr, "")
     # create the "inode" information
     key = self.keygen(sys_path)
     fib_mem.w_s('fib_DiskKey', key)
     log_lock.debug("examine key: %08x", key)
     # type
     if os.path.isdir(sys_path):
         dirEntryType = 2
     else:
         dirEntryType = -3
     fib_mem.w_s('fib_DirEntryType', dirEntryType)
     fib_mem.w_s('fib_EntryType', dirEntryType)
     # protection
     prot = DosProtection(0)
     try:
         os_stat = os.stat(sys_path)
         mode = os_stat.st_mode
         if mode & stat.S_IXUSR == 0:
             prot.clr(DosProtection.FIBF_EXECUTE)
         if mode & stat.S_IRUSR == 0:
             prot.clr(DosProtection.FIBF_READ)
         if mode & stat.S_IWUSR == 0:
             prot.clr(DosProtection.FIBF_WRITE)
         log_lock.debug("examine lock: '%s' mode=%03o: prot=%s", name, mode,
                        prot)
     except OSError:
         return ERROR_OBJECT_IN_USE
     fib_mem.w_s('fib_Protection', prot.mask)
     # size
     if os.path.isfile(sys_path):
         size = os.path.getsize(sys_path)
         fib_mem.w_s('fib_Size', size)
         blocks = int((size + 511) / 512)
         fib_mem.w_s('fib_NumBlocks', blocks)
     else:
         fib_mem.w_s('fib_NumBlocks', 1)
     # date (use mtime here)
     date_addr = fib_mem.s_get_addr('fib_Date')
     date = AccessStruct(fib_mem.mem, DateStampStruct, date_addr)
     t = os.path.getmtime(sys_path)
     at = sys_to_ami_time(t)
     date.w_s('ds_Days', at.tday)
     date.w_s('ds_Minute', at.tmin)
     date.w_s('ds_Tick', at.tick)
     # fill in UID/GID
     fib_mem.w_s('fib_OwnerUID', 0)
     fib_mem.w_s('fib_OwnerGID', 0)
     return NO_ERROR
예제 #2
0
파일: Lock.py 프로젝트: cnvogelg/amitools
 def examine_file(self, fib_mem, name, sys_path):
   # name
   name_addr = fib_mem.s_get_addr('fib_FileName')
   # clear 32 name bytes
   mem = fib_mem.mem
   mem.clear_block(name_addr, 32, 0)
   mem.w_cstr(name_addr, name)
   # comment
   comment_addr = fib_mem.s_get_addr('fib_Comment')
   mem.w_cstr(comment_addr, "")
   # create the "inode" information
   key = self.keygen(sys_path)
   fib_mem.w_s('fib_DiskKey',key)
   log_lock.debug("examine key: %08x", key)
   # type
   if os.path.isdir(sys_path):
     dirEntryType = 2
   else:
     dirEntryType = -3
   fib_mem.w_s('fib_DirEntryType', dirEntryType )
   fib_mem.w_s('fib_EntryType',    dirEntryType )
   # protection
   prot = DosProtection(0)
   try:
     os_stat = os.stat(sys_path)
     mode = os_stat.st_mode
     if mode & stat.S_IXUSR == 0:
       prot.clr(DosProtection.FIBF_EXECUTE)
     if mode & stat.S_IRUSR == 0:
       prot.clr(DosProtection.FIBF_READ)
     if mode & stat.S_IWUSR == 0:
       prot.clr(DosProtection.FIBF_WRITE)
     log_lock.debug("examine lock: '%s' mode=%03o: prot=%s", name, mode, prot)
   except OSError:
     return ERROR_OBJECT_IN_USE
   fib_mem.w_s('fib_Protection', prot.mask)
   # size
   if os.path.isfile(sys_path):
     size = os.path.getsize(sys_path)
     fib_mem.w_s('fib_Size', size)
     blocks = int((size + 511) / 512)
     fib_mem.w_s('fib_NumBlocks', blocks)
   else:
     fib_mem.w_s('fib_NumBlocks', 1)
   # date (use mtime here)
   date_addr = fib_mem.s_get_addr('fib_Date')
   date = AccessStruct(fib_mem.mem, DateStampStruct, date_addr)
   t = os.path.getmtime(sys_path)
   at = sys_to_ami_time(t)
   date.w_s('ds_Days', at.tday)
   date.w_s('ds_Minute', at.tmin)
   date.w_s('ds_Tick', at.tick)
   # fill in UID/GID
   fib_mem.w_s('fib_OwnerUID', 0)
   fib_mem.w_s('fib_OwnerGID', 0)
   return NO_ERROR
예제 #3
0
 def _register_lock(self, lock):
   # look up volume
   volume_name = self.path_mgr.ami_volume_of_path(lock.ami_path)
   log_lock.debug("fl_Volume: looking up volume '%s' of %s",volume_name,lock)
   volume = self.dos_list.get_entry_by_name(volume_name)
   if volume is None:
     vol_baddr = 0
     log_lock.warn("lock volume? volume=%s lock=%s",volume,lock)
   else:
     vol_baddr = volume.mem.addr
   # allocate lock struct
   b_addr = lock.alloc(self.alloc, vol_baddr, self.generate_key)
   self.locks_by_baddr[b_addr] = lock
   log_lock.info("registered: %s" % lock)
예제 #4
0
 def get_by_b_addr(self, b_addr, none_if_missing=False):
     if b_addr == 0:
         return None
     else:
         raw_lock = AccessStruct(self.mem, FileLockStruct, b_addr << 2)
         key = raw_lock.r_s("fl_Key")
         lock_key = self.keys[key]
         log_lock.debug(
             "lookup key in baddr=%08x: %s -> lock_key=%r", b_addr, key, lock_key
         )
         lock = lock_key.find_lock_by_baddr(b_addr)
         if lock:
             return lock
         else:
             raise VamosInternalError("lock not found by b_addr?!")
예제 #5
0
    def _register_lock(self, lock):
        # look up volume
        volume_name = self.path_mgr.ami_volume_of_path(lock.ami_path)
        log_lock.debug("fl_Volume: looking up volume '%s' of %s", volume_name, lock)
        volume = self.dos_list.get_entry_by_name(volume_name)
        if volume is None:
            vol_baddr = 0
            log_lock.warning("lock volume? volume=%s lock=%s", volume, lock)
        else:
            vol_baddr = volume.mem.addr

        # is key already assigned to sys_path?
        lock_key = self.sys_path_to_key_map.get(lock.sys_path)
        if not lock_key:
            # allocate new slot id
            lock_key = LockKey(lock.sys_path)
            slot_id = self.keys.alloc(lock_key)
            log_lock.debug(
                "allocate log key slot %s for sys_path '%s'", slot_id, lock.sys_path
            )
            if slot_id is None:
                log_lock.error("no more lock slots! max=%d", len(self.keys))
                return None
            lock_key.slot_id = slot_id
        else:
            slot_id = lock_key.slot_id
            log_lock.debug(
                "found log key slot %s for sys_path '%s'", slot_id, lock.sys_path
            )

        # allocate lock struct and use slot_id for key
        lock.alloc(self.alloc, vol_baddr, slot_id)

        # register lock in key (with baddr allocated above)
        lock_key.add_lock(lock)

        log_lock.info("registered: %s" % lock)
        return lock
예제 #6
0
 def _examine_file(self, fib_mem, name, sys_path, key):
     # name
     name_addr = fib_mem.s_get_addr("fib_FileName")
     # clear 32 name bytes
     mem = fib_mem.mem
     mem.clear_block(name_addr, 32, 0)
     mem.w_cstr(name_addr, name)
     # comment
     comment_addr = fib_mem.s_get_addr("fib_Comment")
     mem.w_cstr(comment_addr, "")
     # create the "inode" information
     fib_mem.w_s("fib_DiskKey", key)
     log_lock.debug("examine key: %08x", key)
     # type
     if os.path.isdir(sys_path):
         dirEntryType = 2
     else:
         dirEntryType = -3
     fib_mem.w_s("fib_DirEntryType", dirEntryType)
     fib_mem.w_s("fib_EntryType", dirEntryType)
     # protection
     prot = DosProtection(0)
     try:
         os_stat = os.stat(sys_path)
         mode = os_stat.st_mode
         if mode & stat.S_IXUSR == 0:
             prot.clr(DosProtection.FIBF_EXECUTE)
         if mode & stat.S_IRUSR == 0:
             prot.clr(DosProtection.FIBF_READ)
         if mode & stat.S_IWUSR == 0:
             prot.clr(DosProtection.FIBF_WRITE)
         log_lock.debug("examine lock: '%s' mode=%03o: prot=%s", name, mode,
                        prot)
     except OSError:
         return ERROR_OBJECT_IN_USE
     fib_mem.w_s("fib_Protection", prot.mask)
     # size
     if os.path.isfile(sys_path):
         size = os.path.getsize(sys_path)
         # limit to 32bit
         if size > 0xFFFFFFFF:
             size = 0xFFFFFFFF
         fib_mem.w_s("fib_Size", size)
         blocks = (size + 511) // 512
         fib_mem.w_s("fib_NumBlocks", blocks)
         log_lock.debug("examine lock: '%s' size=%d, blocks=%d", sys_path,
                        size, blocks)
     else:
         fib_mem.w_s("fib_NumBlocks", 1)
         log_lock.debug("examine lock: '%s' no file", sys_path)
     # date (use mtime here)
     date_addr = fib_mem.s_get_addr("fib_Date")
     date = AccessStruct(fib_mem.mem, DateStampStruct, date_addr)
     t = os.path.getmtime(sys_path)
     at = sys_to_ami_time(t)
     date.w_s("ds_Days", at.tday)
     date.w_s("ds_Minute", at.tmin)
     date.w_s("ds_Tick", at.tick)
     # fill in UID/GID
     fib_mem.w_s("fib_OwnerUID", 0)
     fib_mem.w_s("fib_OwnerGID", 0)
     return NO_ERROR