// newFilesystemId returns a unique filesystem ID.
// If the host ID supplied is non-empty, the
// filesystem ID will incorporate it as the
// filesystem's machine scope.
177858
func newFilesystemId(mb modelBackend, hostId string) (string, error) {
	seq, err := sequence(mb, "filesystem")
	if err != nil {
		return "", errors.Trace(err)
	}
	id := fmt.Sprint(seq)
	if hostId != "" {
		id = hostId + "/" + id
	}
	return id, nil
}
269330
func (s *lxdFilesystemSource) ReleaseFilesystems(ctx context.ProviderCallContext, filesystemIds []string) ([]error, error) {
	results := make([]error, len(filesystemIds))
	for i, filesystemId := range filesystemIds {
		results[i] = s.releaseFilesystem(filesystemId)
		common.HandleCredentialError(IsAuthorisationFailure, results[i], ctx)
	}
	return results, nil
}
503371
func NewFakeFilesystemWithFiles(fs []FakeFile) FakeFilesystem {
	fileMap := make(map[string]FakeFile)
	for _, f := range fs {
		fileMap[f.Name] = f
	}

	return FakeFilesystem{files: fileMap}
}
44781
func NewFileEditType(Description string) *FileEditType {
	s := new(FileEditType)
	s.Description = Description
	return s
}
841001
func New(files Files) (vfs.FileSystem, error) {
	fs := make(MapFS)

	for path, file := range files {
		if err := fs.addFile(path, file); err != nil {
			return nil, err
		}
	}

	return fs, nil
}
458883
func NewWithFilesystem(fss ...http.FileSystem) i18n.Backend {
	backend := &Backend{}

	for _, fs := range fss {
		backend.contents = append(backend.contents, walkFilesystem(fs, nil, "/")...)
	}
	return backend
}
669673
func NewFilePersister(directory string) (*FilePersister, error) {
	err := os.MkdirAll(directory, 0777)
	return &FilePersister{
		directory: directory,
	}, err
}
1180318
func NewFile(fd uintptr, name string) *os.File {
	return newfile(fd, name)
}
1175223
func (f *filesystemAttachment) Filesystem() names.FilesystemTag {
	return names.NewFilesystemTag(f.doc.Filesystem)
}
1318699
func createMachineFilesystemAttachmentsOps(hostId string, attachments []filesystemAttachmentTemplate) []txn.Op {
	ops := make([]txn.Op, len(attachments))
	for i, attachment := range attachments {
		paramsCopy := attachment.params
		ops[i] = txn.Op{
			C:      filesystemAttachmentsC,
			Id:     filesystemAttachmentId(hostId, attachment.tag.Id()),
			Assert: txn.DocMissing,
			Insert: &filesystemAttachmentDoc{
				Filesystem: attachment.tag.Id(),
				Host:       hostId,
				Params:     &paramsCopy,
			},
		}
		if attachment.existing {
			ops = append(ops, txn.Op{
				C:      filesystemsC,
				Id:     attachment.tag.Id(),
				Assert: txn.DocExists,
				Update: bson.D{{"$inc", bson.D{{"attachmentcount", 1}}}},
			})
		}
	}
	return ops
}
1142182
func NewPrivateKeyFileStorage(baseDir, fileExt string) (*FilesystemStore, error) {
	baseDir = filepath.Join(baseDir, notary.PrivDir)
	myStore, err := NewFileStore(baseDir, fileExt)
	myStore.migrateTo0Dot4()
	return myStore, err
}
242824
func New(mapping map[string]http.FileSystem) http.FileSystem {
	u := &unionFS{
		ns: make(map[string]http.FileSystem),
		root: &dirInfo{
			name: "/",
		},
	}
	for mountPoint, fs := range mapping {
		u.bind(mountPoint, fs)
	}
	return u
}
1117738
func filesystemsChanged(ctx *context, changes []string) error {
	tags := make([]names.Tag, len(changes))
	for i, change := range changes {
		tags[i] = names.NewFilesystemTag(change)
	}
	alive, dying, dead, err := storageEntityLife(ctx, tags)
	if err != nil {
		return errors.Trace(err)
	}
	logger.Debugf("filesystems alive: %v, dying: %v, dead: %v", alive, dying, dead)
	if len(alive)+len(dying)+len(dead) == 0 {
		return nil
	}

	// Get filesystem information for filesystems, so we can provision,
	// deprovision, attach and detach.
	filesystemTags := make([]names.FilesystemTag, 0, len(alive)+len(dying)+len(dead))
	for _, tag := range alive {
		filesystemTags = append(filesystemTags, tag.(names.FilesystemTag))
	}
	for _, tag := range dying {
		filesystemTags = append(filesystemTags, tag.(names.FilesystemTag))
	}
	for _, tag := range dead {
		filesystemTags = append(filesystemTags, tag.(names.FilesystemTag))
	}
	filesystemResults, err := ctx.config.Filesystems.Filesystems(filesystemTags)
	if err != nil {
		return errors.Annotatef(err, "getting filesystem information")
	}

	aliveFilesystemTags := filesystemTags[:len(alive)]
	dyingFilesystemTags := filesystemTags[len(alive) : len(alive)+len(dying)]
	deadFilesystemTags := filesystemTags[len(alive)+len(dying):]
	aliveFilesystemResults := filesystemResults[:len(alive)]
	dyingFilesystemResults := filesystemResults[len(alive) : len(alive)+len(dying)]
	deadFilesystemResults := filesystemResults[len(alive)+len(dying):]

	if err := processDeadFilesystems(ctx, deadFilesystemTags, deadFilesystemResults); err != nil {
		return errors.Annotate(err, "deprovisioning filesystems")
	}
	if err := processDyingFilesystems(ctx, dyingFilesystemTags, dyingFilesystemResults); err != nil {
		return errors.Annotate(err, "processing dying filesystems")
	}
	if err := processAliveFilesystems(ctx, aliveFilesystemTags, aliveFilesystemResults); err != nil {
		return errors.Annotate(err, "provisioning filesystems")
	}
	return nil
}
401419
func filesystemAttachmentsChanged(ctx *context, watcherIds []watcher.MachineStorageId) error {
	ids := copyMachineStorageIds(watcherIds)
	alive, dying, dead, err := attachmentLife(ctx, ids)
	if err != nil {
		return errors.Trace(err)
	}
	logger.Debugf("filesystem attachment alive: %v, dying: %v, dead: %v", alive, dying, dead)
	if len(dead) != 0 {
		// We should not see dead filesystem attachments;
		// attachments go directly from Dying to removed.
		logger.Warningf("unexpected dead filesystem attachments: %v", dead)
	}
	if len(alive)+len(dying) == 0 {
		return nil
	}

	// Get filesystem information for alive and dying filesystem attachments, so
	// we can attach/detach.
	ids = append(alive, dying...)
	filesystemAttachmentResults, err := ctx.config.Filesystems.FilesystemAttachments(ids)
	if err != nil {
		return errors.Annotatef(err, "getting filesystem attachment information")
	}

	// Deprovision Dying filesystem attachments.
	dyingFilesystemAttachmentResults := filesystemAttachmentResults[len(alive):]
	if err := processDyingFilesystemAttachments(ctx, dying, dyingFilesystemAttachmentResults); err != nil {
		return errors.Annotate(err, "destroying filesystem attachments")
	}

	// Provision Alive filesystem attachments.
	aliveFilesystemAttachmentResults := filesystemAttachmentResults[:len(alive)]
	if err := processAliveFilesystemAttachments(ctx, alive, aliveFilesystemAttachmentResults); err != nil {
		return errors.Annotate(err, "creating filesystem attachments")
	}

	return nil
}
1122977
func New(device fs.BlockDevice) (*FileSystem, error) {
	bs, err := DecodeBootSector(device)
	if err != nil {
		return nil, err
	}

	fat, err := DecodeFAT(device, bs, 0)
	if err != nil {
		return nil, err
	}

	var rootDir *DirectoryCluster
	if bs.FATType() == FAT32 {
		panic("FAT32 not implemented yet")
	} else {
		rootDir, err = DecodeFAT16RootDirectoryCluster(device, bs)
		if err != nil {
			return nil, err
		}
	}

	result := &FileSystem{
		bs:      bs,
		device:  device,
		fat:     fat,
		rootDir: rootDir,
	}

	return result, nil
}
1258836
func (s *UpdateFileSystemOutput) SetFileSystemId(v string) *UpdateFileSystemOutput {
	s.FileSystemId = &v
	return s
}
558090
func MachineID(root string) string {
	fullPath := filepath.Join(root, "/etc/machine-id")
	id, err := ioutil.ReadFile(fullPath)
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(id))
}