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  
示例#2
0
def main():
  # I can be imported as a module too!!!
  if len(sys.argv)==1:
    print_usage()
    return

  command = sys.argv[1]
  args = sys.argv[2:]



#help                       : print this message
#usage                      : print this message
  if command == 'help' or command == 'usage':
    print_usage()



#cp root file1 [file2...]   : copies files from the root into the lindfs.   For
#                             example, cp bar /etc/passwd /bin/ls will copy
#                             bar/etc/passwd, bar/bin/ls as /etc/passwd, /bin/ls
  elif command == 'cp':
    lind_test_server.load_fs()

    if len(args)<2:
      print 'Too few arguments to cp.   Must specify root and at least one file'
      return

    root = args[0]
    for filetocp in args[1:]:
      cp_into_lind(filetocp, rootpath=root)



#find [startingpath]        : print the names of all files / paths in the fs
#                             This is much like 'find /'
  elif command == 'find':
    lind_test_server.load_fs()

    if len(args)>1:
      print 'Too many arguments to find.   Takes an optional path'
      return
    elif len(args) == 0:
      startingpath = '/'
    elif len(args)==1:
      startingpath = args[0]
      
    allpathlist = list_all_lind_paths(startingdir=startingpath)
    # want to print this more cleanly than as a list
    for thispath in allpathlist:
      print thispath


#format                     : make a new blank fs, removing the current one.
  elif command == 'format':
    lind_test_server._blank_fs_init()


#deltree dirname            : delete a directory and all it contains
  elif command == 'deltree':
    lind_test_server.load_fs()

    if len(args)!= 1:
      print 'deltree takes exactly one argument, the dir to remove'
      return

    print 'Unimplemented...'

#rm file1 [file2...]        : delete a file
  elif command == 'rm':
    lind_test_server.load_fs()

    if len(args) == 0:
      print 'rm takes one or more arguments'
      return

    for filename in args:
      lind_test_server.unlink_syscall(filename)



#mkdir dir1 [dir2...]       : create a directory
  elif command == 'mkdir':
    lind_test_server.load_fs()

    if len(args) == 0:
      print 'mkdir takes one or more arguments'
      return

    for dirname in args:
      lind_test_server.mkdir_syscall(dirname,S_IRWXA)



#rmdir dir1 [dir2...]       : delete a directory
  elif command == 'rmdir':
    lind_test_server.load_fs()

    if len(args) == 0:
      print 'rmdir takes one or more arguments'
      return

    for dirname in args:
      lind_test_server.rmdir_syscall(dirname)


# OTHERWISE?
  else:
    print "ERROR: command unknown"
    print
    print_usage()
    return
示例#3
0
 def unlink(self, path):
     log("unlink", path)
     try:
         ret = lind.unlink_syscall(path)
     except lind.SyscallError, e:
         ret = -errno[e[1]]
def main():
  # I can be imported as a module too!!!
  if len(sys.argv)==1:
    print_usage()
    return

  command = sys.argv[1]
  args = sys.argv[2:]



#help                       : print this message
#usage                      : print this message
  if command == 'help' or command == 'usage':
    print_usage()



#cp root file1 [file2...]   : copies files from the root into the lindfs.   For
#                             example, cp bar /etc/passwd /bin/ls will copy
#                             bar/etc/passwd, bar/bin/ls as /etc/passwd, /bin/ls
  elif command == 'cp':
    lind_test_server.load_fs()

    if len(args)<2:
      print 'Too few arguments to cp.   Must specify root and at least one file'
      return

    root = args[0]
    for filetocp in args[1:]:
      cp_dir_into_lind(filetocp, rootpath=root)

#update root file1 [file2...]   : copies files from the root into the lindfs if they are different.   For
#                                 example, cp bar /etc/passwd /bin/ls will copy
#                                 bar/etc/passwd, bar/bin/ls as /etc/passwd, /bin/ls
  elif command == 'update':
    lind_test_server.load_fs()

    if len(args)<2:
      print 'Too few arguments to update.   Must specify root and at least one file'
      return

    root = args[0]
    for filetoup in args[1:]:
      update_dir_into_lind(filetoup, rootpath=root)


#find [startingpath]        : print the names of all files / paths in the fs
#                             This is much like 'find /'
  elif command == 'find':
    lind_test_server.load_fs()

    if len(args)>1:
      print 'Too many arguments to find.   Takes an optional path'
      return
    elif len(args) == 0:
      startingpath = '/'
    elif len(args)==1:
      startingpath = args[0]
      
    allpathlist = list_all_lind_paths(startingdir=startingpath)
    # want to print this more cleanly than as a list
    #for thispath in allpathlist:
    #  print thispath


#format                     : make a new blank fs, removing the current one.
  elif command == 'format':
    lind_test_server._blank_fs_init()


#deltree dirname            : delete a directory and all it contains
  elif command == 'deltree':
    lind_test_server.load_fs()

    if len(args)!= 1:
      print 'deltree takes exactly one argument, the dir to remove'
      return
 
    deltree_lind(args[0])

#rm file1 [file2...]        : delete a file
  elif command == 'rm':
    lind_test_server.load_fs()

    if len(args) == 0:
      print 'rm takes one or more arguments'
      return

    for filename in args:
      lind_test_server.unlink_syscall(filename)



#mkdir dir1 [dir2...]       : create a directory
  elif command == 'mkdir':
    lind_test_server.load_fs()

    if len(args) == 0:
      print 'mkdir takes one or more arguments'
      return

    for dirname in args:
      lind_test_server.mkdir_syscall(dirname,S_IRWXA)



#rmdir dir1 [dir2...]       : delete a directory
  elif command == 'rmdir':
    lind_test_server.load_fs()

    if len(args) == 0:
      print 'rmdir takes one or more arguments'
      return

    for dirname in args:
      lind_test_server.rmdir_syscall(dirname)


# OTHERWISE?
  else:
    print "ERROR: command unknown"
    print
    print_usage()
    return
    fd = open(posixfn, "rb")
    host_content = fd.read()
    fd.close()
    
    lindfd = lind_test_server.open_syscall(fullfilename, O_RDONLY, 0)
    lind_content = lind_test_server.read_syscall(lindfd, lind_size)
    lind_test_server.close_syscall(lindfd)
    
    samefile = (host_content == lind_content)
  else:
    samefile = False
  
  if not samefile:
    if lind_exists:
      print "removing "+fullfilename
      lind_test_server.unlink_syscall(fullfilename)
    
    cp_into_lind(fullfilename, rootpath, True)
  else:
    print "same file, skipping"
  
  
  
  
def cp_dir_into_lind(fullfilename, rootpath='.', createmissingdirs=True):
  
  if fullfilename.startswith(os.pathsep):
    fullfilename = '.'+fullfilename
  posixfn = os.path.join(rootpath,fullfilename)

  if not os.path.exists(posixfn):
示例#6
0
# create a file with no perms...
lind_test_server.link_syscall('/foo', '/foo2')

stat_result = lind_test_server.stat_syscall('/foo')
stat_result2 = lind_test_server.stat_syscall('/foo2')

# ensure they are the same now...
assert (stat_result2 == stat_result)

# and that the link count is 2
assert (stat_result[3] == 2)

# let's unlink one now...

lind_test_server.unlink_syscall('/foo')

stat_result = lind_test_server.stat_syscall('/foo2')

# ensure the link count is 1
assert (stat_result[3] == 1)

# file is gone...
try:
    stat_result = lind_test_server.stat_syscall('/foo')
except:
    pass
else:
    print "stat worked after unlinked!!!"

lind_test_server.unlink_syscall('/foo2')
示例#7
0
    # read the first 5 bytes (hello)
    assert (lind_test_server.read_syscall(myfd, 5) == 'hello')

    # change it to hello world!
    assert (lind_test_server.write_syscall(myfd, ' world') == 6)

    # seek to the beginning again...
    assert (lind_test_server.lseek_syscall(myfd, 0, SEEK_SET) == 0)

    # and read it all...
    assert (lind_test_server.read_syscall(myfd, 100) == 'hello world!')

    lind_test_server.close_syscall(myfd)

    # Now make and remove a file:
    myfd = lind_test_server.open_syscall(TEST2_FILENAME, \
                                      O_CREAT | O_EXCL | O_RDWR, S_IRWXA)

    # write should succeed
    message = '================================================================================================================================'
    assert (lind_test_server.write_syscall(myfd, message) == len(message))

    lind_test_server.close_syscall(myfd)

    lind_test_server.unlink_syscall(TEST2_FILENAME)

    lind_test_server.persist_metadata(DEFAULT_METADATA_FILENAME)

    # ensure the metadata exists...
    assert (os.access(DEFAULT_METADATA_FILENAME, os.W_OK))
# create a file with no perms...
lind_test_server.link_syscall('/foo','/foo2')

stat_result = lind_test_server.stat_syscall('/foo')
stat_result2 = lind_test_server.stat_syscall('/foo2')

# ensure they are the same now...
assert(stat_result2 == stat_result)

# and that the link count is 2
assert(stat_result[3] == 2)


# let's unlink one now...

lind_test_server.unlink_syscall('/foo')


stat_result = lind_test_server.stat_syscall('/foo2')

# ensure the link count is 1
assert(stat_result[3] == 1)

# file is gone...
try:
  stat_result = lind_test_server.stat_syscall('/foo')
except:
  pass
else:
  print "stat worked after unlinked!!!"
示例#9
0
 def unlink(self, path):
     log("unlink", path)
     try:
         ret = lind.unlink_syscall(path)
     except lind.SyscallError, e:
         ret = -errno[e[1]]
    # read the first 5 bytes (hello)
    assert lind_test_server.read_syscall(myfd, 5) == "hello"

    # change it to hello world!
    assert lind_test_server.write_syscall(myfd, " world") == 6

    # seek to the beginning again...
    assert lind_test_server.lseek_syscall(myfd, 0, SEEK_SET) == 0

    # and read it all...
    assert lind_test_server.read_syscall(myfd, 100) == "hello world!"

    lind_test_server.close_syscall(myfd)

    # Now make and remove a file:
    myfd = lind_test_server.open_syscall(TEST2_FILENAME, O_CREAT | O_EXCL | O_RDWR, S_IRWXA)

    # write should succeed
    message = "================================================================================================================================"
    assert lind_test_server.write_syscall(myfd, message) == len(message)

    lind_test_server.close_syscall(myfd)

    lind_test_server.unlink_syscall(TEST2_FILENAME)

    lind_test_server.persist_metadata(DEFAULT_METADATA_FILENAME)

    # ensure the metadata exists...
    assert os.access(DEFAULT_METADATA_FILENAME, os.W_OK)