コード例 #1
0
ファイル: Lock.py プロジェクト: cmsj/amitools
 def examine_file(self, fib_mem, name, sys_path):
   # name
   name_addr = fib_mem.s_get_addr('fib_FileName')
   # clear 32 name bytes
   fib_mem.clear_data(name_addr, 32, 0)
   fib_mem.w_cstr(name_addr, name)
   # comment
   comment_addr = fib_mem.s_get_addr('fib_Comment')
   fib_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) & 0xffffffff
   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, DateStampDef, 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
ファイル: LockManager.py プロジェクト: apiraino/amitools
 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)
コード例 #3
0
ファイル: Lock.py プロジェクト: gbraad/amitools
 def examine_file(self, fib_mem, name, sys_path):
   # name
   name_addr = fib_mem.s_get_addr('fib_FileName')
   fib_mem.w_cstr(name_addr, name)
   # dummy key
   fib_mem.w_s('fib_DiskKey',0xcafebabe)
   # type
   if os.path.isdir(sys_path):
     dirEntryType = 0x2 # dir
   else:
     dirEntryType = 0xfffffffd # file
   fib_mem.w_s('fib_DirEntryType', 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)
   # date (use mtime here)
   date_addr = fib_mem.s_get_addr('fib_Date')
   date = AccessStruct(fib_mem.mem, DateStampDef, 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)
   return NO_ERROR