Ejemplo n.º 1
0
def ls_cmd(dir_list):

	# we want to print the dirname if we are ls'ing multiple dirs
	print_dir = 0
	if len(dir_list) > 1:
		print_dir = 1
	
	for dir in dir_list:
		try:
			lindfd = lind_test_server.open_syscall(dir, lind_test_server.O_RDONLY, lind_test_server.S_IRWXU) #first open the file
		except lind_test_server.SyscallError, e:
			print "Could not open the local file. Error: %s" % e
			return -1
		
		getdents_size = 20 #the number of nodes to check per getdents
		ls_list = [] #the list that will hold all the subfiles
		prev_ls_list_count = -1#keeps track of the list count during the previous iteration
		
		#while there are still files to look at, add them to the list. Once the list size is the same for 2 iterations in a row, we know there is nothing left to look at!
		while not len(ls_list) == prev_ls_list_count:
			try:
				prev_ls_list_count = len(ls_list)#update the count
				ls_list.extend(lind_test_server.getdents_syscall(lindfd, getdents_size))#add the current group of <getdents_size> files to the list of all files
			except lind_test_server.SyscallError, e:
				print "getdents failed. Error: %s" % e
Ejemplo n.º 2
0
    def readdir(self, path, offset):
        log("readdir", path, offset)
        lindfd = lind.open_syscall(path, lind.O_RDONLY, lind.S_IRWXU)
        dents = map(lambda x: x[1], lind.getdents_syscall(lindfd, 999))

        assert len(dents) < 998, "Readdir max was hit..."
        for e in dents:
            yield fuse.Direntry(e)
Ejemplo n.º 3
0
    def readdir(self, path, offset):
        log("readdir", path, offset)
        lindfd = lind.open_syscall(path, lind.O_RDONLY, lind.S_IRWXU)
        dents = map(lambda x: x[1], lind.getdents_syscall(lindfd, 999))

        assert len(dents) < 998, "Readdir max was hit..."
        for e in dents:
            yield fuse.Direntry(e)
Ejemplo n.º 4
0
def _find_all_paths_recursively(startingpath):
  # helper for list_all_lind_paths.   It recursively looks at all child dirs
  
  knownitems = []

  # I need to open the dir to use getdents...
  dirfd = lind_test_server.open_syscall(startingpath,0,0)

  # build a list of all dents.   These have an odd format:
  #  [(inode, filename, d_type (DT_DIR, DR_REG, etc.), length of entry), ...]
  # We only care about the filename and d_type.
  mydentslist = []

  # Note: the length parameter is odd, it's related to data structure space, so
  # it doesn't map to python cleanly.   So long as it's > the largest possible
  # entry size, this code should work though.
  thesedents = lind_test_server.getdents_syscall(dirfd,10000)
  while thesedents:
    mydentslist += thesedents
    thesedents = lind_test_server.getdents_syscall(dirfd,10000)

  lind_test_server.close_syscall(dirfd)

  # to make the output correct, if the dir is '/', don't print it.
  if startingpath == '/':
    startingpath = ''

  for dent in mydentslist:
    # ignore '.' and '..' because they aren't interesting and we don't want
    # to loop forever.
    if dent[1]=='.' or dent[1]=='..':
      continue
   
    thisitem = (dent[0], startingpath+'/'+dent[1])

    # add it...
    knownitems.append(thisitem)
    print thisitem

    # if it's a directory, recurse...
    if dent[2]==DT_DIR:
      knownitems = knownitems + _find_all_paths_recursively(thisitem[1])

  return knownitems
Ejemplo n.º 5
0
def deltree_lind(dirname):
  # took part of the code from _find_all_paths_recursively method below.
  # It recursively looks at all child dirs

  # I need to open the dir to use getdents...
  dirfd = lind_test_server.open_syscall(dirname,0,0)

  # build a list of all dents.   These have an odd format:
  #  [(inode, filename, d_type (DT_DIR, DR_REG, etc.), length of entry), ...]
  # We only care about the filename and d_type.
  mydentslist = []

  # Note: the length parameter is odd, it's related to data structure space, so
  # it doesn't map to python cleanly.   So long as it's > the largest possible
  # entry size, this code should work though.
  thesedents = lind_test_server.getdents_syscall(dirfd,10000)
  while thesedents:
    mydentslist += thesedents
    thesedents = lind_test_server.getdents_syscall(dirfd,10000)

  lind_test_server.close_syscall(dirfd)

  for dent in mydentslist:
    # ignore '.' and '..' because they aren't interesting and we don't want
    # to loop forever.
    if dent[1]=='.' or dent[1]=='..':
      continue
   
    thisitem = (dent[0], dirname+'/'+dent[1])
    
    print "deleting",thisitem[1]

    # if it's a directory, recurse...
    if dent[2]==DT_DIR:
      deltree_lind(thisitem[1])
    else:
      lind_test_server.unlink_syscall(thisitem[1])

  lind_test_server.rmdir_syscall(dirname)
  return  
Ejemplo n.º 6
0
from lind_fs_constants import *

lind_test_server._blank_fs_init()

# Let's add a few directories to the system and see if it works...
lind_test_server.mkdir_syscall('/bar',S_IRWXA)
lind_test_server.mkdir_syscall('/bar/baz',S_IRWXA)
lind_test_server.mkdir_syscall('/bar/bap',0)

# Create a new file...
fd = lind_test_server.open_syscall('/bar/bam',O_CREAT,0)
lind_test_server.close_syscall(fd)

# Read the root directory...
rootfd = lind_test_server.open_syscall('/',0,0)
val = lind_test_server.getdents_syscall(rootfd, 100)
assert (val==[(3, 'bar', DT_DIR, 24), (1, '..', DT_DIR, 24),\
  (1, '.', DT_DIR, 24)]), "Found: %s"%(str(val))

# Read the /bar directory...
barfd = lind_test_server.open_syscall('/bar',0,0)

# The buffer size is given small, only few entries are read. 
val = lind_test_server.getdents_syscall(barfd, 80)
assert (val == [(6, 'bam', DT_REG, 24), (4, 'baz', DT_DIR, 24),\
  (5, 'bap', DT_DIR, 24)]), "Found: %s"%(str(val))

# Again call on the same FD, should continue parsing the /bar directory.
val = lind_test_server.getdents_syscall(barfd, 80)
assert (val == [(1, '..', DT_DIR, 24), (3, '.', DT_DIR, 24)]),\
  "Found: %s"%(str(val))