Skip to content

Commit

Permalink
Assign inode for virtual dir entry
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Jun 23, 2023
1 parent f36da60 commit d93547c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 24 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.18

require (
github.com/cyverse/go-irodsclient v0.11.2
github.com/cyverse/irodsfs-common v0.0.0-20230308234020-6ab739dff839
github.com/cyverse/irodsfs-common v0.0.0-20230623171151-5e4370b83339
github.com/cyverse/irodsfs-monitor v0.0.0-20220809235922-daf13261a2dc
github.com/cyverse/irodsfs-pool v0.6.12
github.com/cyverse/irodsfs-pool v0.6.13
github.com/hanwen/go-fuse/v2 v2.1.0
github.com/pkg/profile v1.7.0
github.com/rs/xid v1.3.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cyverse/go-irodsclient v0.11.2 h1:nhVG3Nyzf4eoFFqAcWAvqeHVecsu0yz7CCp/rIQQSE4=
github.com/cyverse/go-irodsclient v0.11.2/go.mod h1:Qs1cjnDN1RaBaUcaZCsRGPFqCffg/cExSBIm466nvTw=
github.com/cyverse/irodsfs-common v0.0.0-20230308234020-6ab739dff839 h1:rOi3lMYkCQxJDGq9r13o8Eda5T6kDlVxr+bXl3ZAWFg=
github.com/cyverse/irodsfs-common v0.0.0-20230308234020-6ab739dff839/go.mod h1:6nBmND4wMHyiU4znH2MqXb6RCTqT0SVH8bbv0zH9wWo=
github.com/cyverse/irodsfs-common v0.0.0-20230623171151-5e4370b83339 h1:hxwOJ0nTrilI/sv6TNVdmSN4t+yB82Uo2/7AoiVtN5g=
github.com/cyverse/irodsfs-common v0.0.0-20230623171151-5e4370b83339/go.mod h1:6nBmND4wMHyiU4znH2MqXb6RCTqT0SVH8bbv0zH9wWo=
github.com/cyverse/irodsfs-monitor v0.0.0-20220809235922-daf13261a2dc h1:gIpG0ETQOEZloFwB5iU2zljVsoUDTpUEl/3WF19gLNk=
github.com/cyverse/irodsfs-monitor v0.0.0-20220809235922-daf13261a2dc/go.mod h1:8UE1mT26+0vAsqS9UJ6Q/vlKq3da6FLdt5p6Tt1AIC4=
github.com/cyverse/irodsfs-pool v0.6.12 h1:NSFi1PEO7HYHfmr4ttXy9tK8rqszfkOFWUBQTD6qDog=
github.com/cyverse/irodsfs-pool v0.6.12/go.mod h1:OePYtZFHvmjJLqdZPeTciz5Hkuj/jRViM05F/wdRQVM=
github.com/cyverse/irodsfs-pool v0.6.13 h1:1k+2AgahxCsCkuGog3fKDvzpG4PUptltKtm0Q+zsr4I=
github.com/cyverse/irodsfs-pool v0.6.13/go.mod h1:SIydk5Kq+cfmm1ilx8I3tyfyUvO2mYI29y444LtoEx8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
63 changes: 46 additions & 17 deletions irodsfs/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,31 @@ func (dir *Dir) newSubFileInode(ctx context.Context, entryID int64, path string)

func (dir *Dir) getStableAttr() fusefs.StableAttr {
return fusefs.StableAttr{
Mode: fuse.S_IFDIR,
Ino: uint64(dir.entryID),
Mode: uint32(fuse.S_IFDIR),
Ino: getInodeIDFromEntryID(dir.entryID),
Gen: 0,
}
}

func (dir *Dir) setAttrOut(vpathEntry *irodsfs_common_vpath.VPathEntry, out *fuse.Attr) {
logger := log.WithFields(log.Fields{
"package": "irodsfs",
"struct": "Dir",
"function": "setAttrOut",
})

if vpathEntry.Type == irodsfs_common_vpath.VPathVirtualDir {
// vpath
out.Ino = uint64(vpathEntry.VirtualDirEntry.ID)
logger.Debugf("vpath virtual dir - path: %s ino: %d", vpathEntry.Path, getInodeIDFromEntryID(vpathEntry.VirtualDirEntry.ID))
out.Ino = getInodeIDFromEntryID(vpathEntry.VirtualDirEntry.ID)
out.Uid = dir.fs.uid
out.Gid = dir.fs.gid
out.SetTimes(&vpathEntry.VirtualDirEntry.ModifyTime, &vpathEntry.VirtualDirEntry.ModifyTime, &vpathEntry.VirtualDirEntry.ModifyTime)
out.Size = uint64(vpathEntry.VirtualDirEntry.Size)
out.Mode = uint32(fuse.S_IFDIR | 0o500)
} else if vpathEntry.Type == irodsfs_common_vpath.VPathIRODS {
// irods
out.Ino = uint64(vpathEntry.IRODSEntry.ID)
out.Ino = getInodeIDFromEntryID(vpathEntry.IRODSEntry.ID)
out.Uid = dir.fs.uid
out.Gid = dir.fs.gid
out.SetTimes(&vpathEntry.IRODSEntry.ModifyTime, &vpathEntry.IRODSEntry.ModifyTime, &vpathEntry.IRODSEntry.ModifyTime)
Expand Down Expand Up @@ -732,37 +739,48 @@ func (dir *Dir) Readdir(ctx context.Context) (fusefs.DirStream, syscall.Errno) {

if vpathEntry.Type == irodsfs_common_vpath.VPathVirtualDir {
if vpathEntry.Path == dir.path {
dirEntries := make([]fuse.DirEntry, len(vpathEntry.VirtualDirEntry.DirEntries))
dirEntries := make([]fuse.DirEntry, len(vpathEntry.VirtualDirEntry.DirEntries)+2)

dirEntries[0] = fuse.DirEntry{
Ino: 0,
Mode: uint32(fuse.S_IFDIR),
Name: ".",
}
dirEntries[1] = fuse.DirEntry{
Ino: 0,
Mode: uint32(fuse.S_IFDIR),
Name: "..",
}

for idx, entry := range vpathEntry.VirtualDirEntry.DirEntries {
if entry.Type == irodsfs_common_vpath.VPathVirtualDir {
dirEntry := fuse.DirEntry{
Ino: uint64(entry.VirtualDirEntry.ID),
Mode: fuse.S_IFDIR,
Ino: getInodeIDFromEntryID(entry.VirtualDirEntry.ID),
Mode: uint32(fuse.S_IFDIR),
Name: entry.VirtualDirEntry.Name,
}

dirEntries[idx] = dirEntry
dirEntries[idx+2] = dirEntry
} else if entry.Type == irodsfs_common_vpath.VPathIRODS {
entryType := uint32(fuse.S_IFREG)

switch entry.IRODSEntry.Type {
case irodsclient_fs.FileEntry:
entryType = fuse.S_IFREG
entryType = uint32(fuse.S_IFREG)
case irodsclient_fs.DirectoryEntry:
entryType = fuse.S_IFDIR
entryType = uint32(fuse.S_IFDIR)
default:
logger.Errorf("unknown entry type - %s", entry.Type)
return nil, syscall.EREMOTEIO
}

dirEntry := fuse.DirEntry{
Ino: uint64(entry.IRODSEntry.ID),
Ino: getInodeIDFromEntryID(entry.IRODSEntry.ID),
Mode: entryType,
Name: irodsfs_common_utils.GetFileName(entry.Path),
}

dirEntries[idx] = dirEntry
dirEntries[idx+2] = dirEntry
} else {
logger.Errorf("unknown VPath Entry type : %s", entry.Type)
return nil, syscall.EREMOTEIO
Expand All @@ -785,28 +803,39 @@ func (dir *Dir) Readdir(ctx context.Context) (fusefs.DirStream, syscall.Errno) {
return nil, syscall.EREMOTEIO
}

dirEntries := make([]fuse.DirEntry, len(irodsEntries))
dirEntries := make([]fuse.DirEntry, len(irodsEntries)+2)

dirEntries[0] = fuse.DirEntry{
Ino: 0,
Mode: uint32(fuse.S_IFDIR),
Name: ".",
}
dirEntries[1] = fuse.DirEntry{
Ino: 0,
Mode: uint32(fuse.S_IFDIR),
Name: "..",
}

for idx, irodsEntry := range irodsEntries {
entryType := uint32(fuse.S_IFREG)

switch irodsEntry.Type {
case irodsclient_fs.FileEntry:
entryType = fuse.S_IFREG
entryType = uint32(fuse.S_IFREG)
case irodsclient_fs.DirectoryEntry:
entryType = fuse.S_IFDIR
entryType = uint32(fuse.S_IFDIR)
default:
logger.Errorf("unknown entry type - %s", irodsEntry.Type)
return nil, syscall.EREMOTEIO
}

dirEntry := fuse.DirEntry{
Ino: uint64(irodsEntry.ID),
Ino: getInodeIDFromEntryID(irodsEntry.ID),
Mode: entryType,
Name: irodsEntry.Name,
}

dirEntries[idx] = dirEntry
dirEntries[idx+2] = dirEntry
}

return fusefs.NewListDirStream(dirEntries), fusefs.OK
Expand Down
2 changes: 1 addition & 1 deletion irodsfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewFile(fs *IRODSFS, entryID int64, path string) *File {
func (file *File) getStableAttr() fusefs.StableAttr {
return fusefs.StableAttr{
Mode: fuse.S_IFREG,
Ino: uint64(file.entryID),
Ino: getInodeIDFromEntryID(file.entryID),
Gen: 0,
}
}
Expand Down
12 changes: 12 additions & 0 deletions irodsfs/inode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package irodsfs

import "github.com/cyverse/irodsfs/utils"

func getInodeIDFromEntryID(id int64) uint64 {
if id < 0 {
// virtual
return uint64(utils.MaxInt) + uint64(-1*id)
}

return uint64(id)
}
8 changes: 8 additions & 0 deletions utils/number.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package utils

const (
MaxUint = ^uint(0)
MinUint = 0
MaxInt = int(MaxUint >> 1)
MinInt = -MaxInt - 1
)

0 comments on commit d93547c

Please sign in to comment.