Beispiel #1
0
	def link ( self, targetPath, linkPath ):
		nodetok = linkpath.split('/')
		lname = nodetok[len(nodetok)-1]
		nodetok.remove(lname)
		dir = ""
		for i in nodetok:
			if i != '':
				dir = dir + "/" + i
		if dir == "":
			dir = "/"
	
		dirnode = self.FSData.findNode(dir)
		if dirnode == None:
			return -errno.ENOENT

		tnode = self.FSData.findNode(targetPath)
		if tnode == None:
			return -errno.ENOENT

		lnode = KeyLayoutElement(lname)
		lnode.runtimeSetup()
		ndnode.stat.st_mode = S_IFLNK | 0777
		lnode.target_path = targetPath
		dirnode.addChild(lnode)
		return 0
Beispiel #2
0
    def link(self, targetPath, linkPath):
        nodetok = linkpath.split('/')
        lname = nodetok[len(nodetok) - 1]
        nodetok.remove(lname)
        dir = ""
        for i in nodetok:
            if i != '':
                dir = dir + "/" + i
        if dir == "":
            dir = "/"

        dirnode = self.FSData.findNode(dir)
        if dirnode == None:
            return -errno.ENOENT

        tnode = self.FSData.findNode(targetPath)
        if tnode == None:
            return -errno.ENOENT

        lnode = KeyLayoutElement(lname)
        lnode.runtimeSetup()
        ndnode.stat.st_mode = S_IFLNK | 0777
        lnode.target_path = targetPath
        dirnode.addChild(lnode)
        return 0
Beispiel #3
0
    def rename(self, oldPath, newPath):
        oldnode = self.FSData.findNode(oldPath)
        if oldnode == None:
            return -errno.ENOENT
        newnode = self.FSData.findNode(newPath)
        if newnode != None:
            return -errno.EEXIST

        newntok = newPath.split('/')
        newname = newntok[len(newntok) - 1]
        newntok.remove(newname)
        dir = ""
        for i in newntok:
            if i != '':
                dir = dir + "/" + i
        if dir == "":
            dir = "/"

        newdirnode = self.FSData.findNode(dir)
        if newdirnode == None:
            return -errno.ENOENT

        newnode = KeyLayoutElement(newname)
        newnode.runtimeSetup()
        newnode.stat = oldnode.stat

        newdirnode.addChild(newnode)

        newfile = newnode.open(self, os.O_RDWR | os.O_CREAT)
        oldfile = oldnode.open(self, os.O_RDWR)

        newnode.iolock.acquire()
        oldnode.iolock.acquire()

        shutil.copyfileobj(oldfile, newfile)

        newnode.dirty = True

        newnode.iolock.release()
        oldnode.iolock.release()

        newnode.close(self)
        oldnode.close(self)

        oldnode.delete(self)

        return 0
Beispiel #4
0
class MetaData:
	def __init__(self):
		self.version = 2 
		self.size_unlimited = True
		self.root = KeyLayoutElement('/') 
		self.root.runtimeSetup()

	def findNode(self, name):
		if name == "/":
			return self.root
		tokens = name.split("/")
		return self.root.pathWalk(tokens)

	def cloneForSave(self):
		clone = MetaData()
		clone.root = None
		clone.version = self.version
		clone.size_unlimited = self.size_unlimited
		clone.root = self.root.cloneSubtree() 
		return clone
Beispiel #5
0
	def mkdir ( self, path, mode ):
		nodetok = path.split('/')
		newdir = nodetok[len(nodetok)-1]
		nodetok.remove(newdir)
		dir = ""
		for i in nodetok:
			if i != '':
				dir = dir + "/" + i

		if dir == "":
			dir = "/"
	
		dirnode = self.FSData.findNode(dir)
		if dirnode == None:
			return -errno.ENOENT

		ndnode = KeyLayoutElement(newdir)
		ndnode.runtimeSetup()
		ndnode.stat.st_mode = stat.S_IFDIR | mode
		dirnode.addChild(ndnode)
		return 0
Beispiel #6
0
    def mkdir(self, path, mode):
        nodetok = path.split('/')
        newdir = nodetok[len(nodetok) - 1]
        nodetok.remove(newdir)
        dir = ""
        for i in nodetok:
            if i != '':
                dir = dir + "/" + i

        if dir == "":
            dir = "/"

        dirnode = self.FSData.findNode(dir)
        if dirnode == None:
            return -errno.ENOENT

        ndnode = KeyLayoutElement(newdir)
        ndnode.runtimeSetup()
        ndnode.stat.st_mode = stat.S_IFDIR | mode
        dirnode.addChild(ndnode)
        return 0
Beispiel #7
0
	def __init__(self, path, flags, *mode):
		self.file = None
		self.direct_io = True 
		self.keep_cache = "no" 
		self.node = None
		node = self.myFS.FSData.findNode(path)
		nodetok = path.split('/')
		dir=""
		filename = nodetok[len(nodetok)-1]
		nodetok.remove(filename)
		for i in nodetok:
			if i != '':
				dir = dir + "/" + i
		if dir == "":
			dir = "/"

		dirnode = self.myFS.FSData.findNode(dir)
		if dirnode == None:
			return None 

		if node == None:
			#Check to see if we are supposed to be creating a file
			if (flags & os.O_CREAT) == os.O_CREAT:
				node = KeyLayoutElement(filename)
				node.runtimeSetup()
				node.stat.st_mode = stat.S_IFREG | 0755
				node.sha_sum = ''
				dirnode.addChild(node)
			else:
				return None 
		else:
			if (flags & os.O_EXCL) == os.O_EXCL:
				return None

		self.file = node.open(self.myFS, flags)
		self.fd = self.file.fileno()
		self.node = node
		return None 
Beispiel #8
0
	def mknod ( self, path, mode, dev ):
		node = self.FSData.findNode(path)
		if node != None:
			return -errno.EEXIST
		nodetok = path.split('/')
		dir=""
		filename = nodetok[len(nodetok)-1]
		nodetok.remove(filename)
		for i in nodetok:
			if i != '':
				dir = dir + "/" + i
		if dir == "":
			dir = "/"

		dirnode = self.FSData.findNode(dir)
		file = KeyLayoutElement(filename)
		file.runtimeSetup()
		file.stat.st_mode = mode
		dirnode.addChild(file)
		node = self.FSData.findNode(path)
		fd = file.open(self) 
		fd.close()
		return 0
Beispiel #9
0
    def mknod(self, path, mode, dev):
        node = self.FSData.findNode(path)
        if node != None:
            return -errno.EEXIST
        nodetok = path.split('/')
        dir = ""
        filename = nodetok[len(nodetok) - 1]
        nodetok.remove(filename)
        for i in nodetok:
            if i != '':
                dir = dir + "/" + i
        if dir == "":
            dir = "/"

        dirnode = self.FSData.findNode(dir)
        file = KeyLayoutElement(filename)
        file.runtimeSetup()
        file.stat.st_mode = mode
        dirnode.addChild(file)
        node = self.FSData.findNode(path)
        fd = file.open(self)
        fd.close()
        return 0
Beispiel #10
0
	def rename ( self, oldPath, newPath ):
		oldnode = self.FSData.findNode(oldPath)
		if oldnode == None:
			return -errno.ENOENT
		newnode = self.FSData.findNode(newPath)
		if newnode != None:
			return -errno.EEXIST

		newntok = newPath.split('/')
		newname = newntok[len(newntok)-1]
		newntok.remove(newname)
		dir = ""
		for i in newntok:
			if i != '':
				dir = dir + "/" + i
		if dir == "":
			dir = "/"

		newdirnode = self.FSData.findNode(dir)
		if newdirnode == None:
			return -errno.ENOENT
	
		newnode = KeyLayoutElement(newname)
		newnode.runtimeSetup()
		newnode.stat = oldnode.stat

		newdirnode.addChild(newnode)

		newfile = newnode.open(self, os.O_RDWR|os.O_CREAT)
		oldfile = oldnode.open(self, os.O_RDWR)

		newnode.iolock.acquire()
		oldnode.iolock.acquire()

		shutil.copyfileobj(oldfile,newfile)
	
		newnode.dirty = True

		newnode.iolock.release()
		oldnode.iolock.release()

		newnode.close(self)
		oldnode.close(self)

		oldnode.delete(self)

		return 0	
Beispiel #11
0
    def __init__(self, path, flags, *mode):
        self.file = None
        self.direct_io = True
        self.keep_cache = "no"
        self.node = None
        node = self.myFS.FSData.findNode(path)
        nodetok = path.split('/')
        dir = ""
        filename = nodetok[len(nodetok) - 1]
        nodetok.remove(filename)
        for i in nodetok:
            if i != '':
                dir = dir + "/" + i
        if dir == "":
            dir = "/"

        dirnode = self.myFS.FSData.findNode(dir)
        if dirnode == None:
            return None

        if node == None:
            #Check to see if we are supposed to be creating a file
            if (flags & os.O_CREAT) == os.O_CREAT:
                node = KeyLayoutElement(filename)
                node.runtimeSetup()
                node.stat.st_mode = stat.S_IFREG | 0755
                node.sha_sum = ''
                dirnode.addChild(node)
            else:
                return None
        else:
            if (flags & os.O_EXCL) == os.O_EXCL:
                return None

        self.file = node.open(self.myFS, flags)
        self.fd = self.file.fileno()
        self.node = node
        return None
Beispiel #12
0
	def __init__(self):
		self.version = 2 
		self.size_unlimited = True
		self.root = KeyLayoutElement('/') 
		self.root.runtimeSetup()