func (decoderData *decoderData) addFile(header *tar.Header, parent *filesystem.Directory, name string) error { var newInode filesystem.Inode if header.Typeflag == tar.TypeChar { newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) | syscall.S_IFCHR) } else if header.Typeflag == tar.TypeBlock { newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) | syscall.S_IFBLK) } else if header.Typeflag == tar.TypeFifo { newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) | syscall.S_IFIFO) } else { return errors.New(fmt.Sprintf("unsupported type: %v", header.Typeflag)) } newInode.Uid = uint32(header.Uid) newInode.Gid = uint32(header.Gid) newInode.MtimeNanoSeconds = int32(header.ModTime.Nanosecond()) newInode.MtimeSeconds = header.ModTime.Unix() if header.Devminor > 255 { return errors.New(fmt.Sprintf("minor device number: %d too large", header.Devminor)) } newInode.Rdev = uint64(header.Devmajor<<8 | header.Devminor) decoderData.inodeTable[header.Name] = decoderData.nextInodeNumber decoderData.fileSystem.InodeTable[decoderData.nextInodeNumber] = &newInode var newEntry filesystem.File newEntry.Name = name newEntry.InodeNumber = decoderData.nextInodeNumber parent.FileList = append(parent.FileList, &newEntry) decoderData.nextInodeNumber++ return nil }
func (fileSystem *FileSystem) getInode(stat *syscall.Stat_t) ( *filesystem.Inode, bool) { inode := fileSystem.InodeTable[stat.Ino] new := false if inode == nil { var _inode filesystem.Inode inode = &_inode _inode.Mode = filesystem.FileMode(stat.Mode) _inode.Uid = stat.Uid _inode.Gid = stat.Gid _inode.MtimeSeconds = stat.Mtim.Sec _inode.MtimeNanoSeconds = int32(stat.Mtim.Nsec) _inode.Rdev = stat.Rdev fileSystem.InodeTable[stat.Ino] = inode new = true } return inode, new }