fs/ntfs3/attrib.c

Source file repositories/reference/linux-study-clean/fs/ntfs3/attrib.c

File Facts

System
Linux kernel
Corpus path
fs/ntfs3/attrib.c
Extension
.c
Size
62718 bytes
Lines
2777
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!clen) {
			err = -EINVAL;
			goto out;
		}

		if (lcn != SPARSE_LCN) {
			if (sbi) {
				/* mark bitmap range [lcn + clen) as free and trim clusters. */
				mark_as_free_ex(sbi, lcn, clen, trim);

				if (run_da) {
					CLST da_len;
					if (!run_remove_range(run_da, vcn, clen,
							      &da_len)) {
						err = -ENOMEM;
						goto failed;
					}
					ntfs_sub_da(sbi, da_len);
				}
			}
			dn += clen;
		}

		len -= clen;
		if (!len)
			break;

		vcn_next = vcn + clen;
		if (!run_get_entry(run, ++idx, &vcn, &lcn, &clen) ||
		    vcn != vcn_next) {
			/* Save memory - don't load entire run. */
			goto failed;
		}
	}

out:
	if (done)
		*done += dn;

	return err;
}

/*
 * attr_allocate_clusters - Find free space, mark it as used and store in @run.
 */
int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run,
			   struct runs_tree *run_da, CLST vcn, CLST lcn,
			   CLST len, CLST *pre_alloc, enum ALLOCATE_OPT opt,
			   CLST *alen, const size_t fr, CLST *new_lcn,
			   CLST *new_len)
{
	int err;
	CLST flen, vcn0 = vcn, pre = pre_alloc ? *pre_alloc : 0;
	size_t cnt = run->count;

	for (;;) {
		err = ntfs_look_for_free_space(sbi, lcn, len + pre, &lcn, &flen,
					       opt);

		if (err == -ENOSPC && pre) {
			pre = 0;
			if (pre_alloc)
				*pre_alloc = 0;
			continue;
		}

		if (err == -ENOSPC && new_len && vcn - vcn0) {
			/* Keep already allocated clusters. */
			*alen = vcn - vcn0;
			return 0;
		}

		if (err)
			goto out;

		if (vcn == vcn0) {
			/* Return the first fragment. */
			if (new_lcn)
				*new_lcn = lcn;
			if (new_len)
				*new_len = flen;
		}

		/* Add new fragment into run storage. */
		if (!run_add_entry(run, vcn, lcn, flen, opt & ALLOCATE_MFT)) {
undo_alloc:
			/* Undo last 'ntfs_look_for_free_space' */
			mark_as_free_ex(sbi, lcn, len, false);
			err = -ENOMEM;
			goto out;

Annotation

Implementation Notes