Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv14399
Modified Files:
attrib.c dir.c inode.c volume.c
Log Message:
sorry flatcap. - remove a lot of reorganization which rips the code into incomprehensible order. - all functions were and are again now placed together by logicnot by sheer randomness. - functions which call each other are placed together for example...
Index: attrib.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/attrib.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -U2 -r1.59 -r1.60
--- attrib.c 11 Jul 2002 23:44:13 -0000 1.59
+++ attrib.c 12 Jul 2002 08:18:15 -0000 1.60
@@ -408,1020 +408,1099 @@
/**
- * Internal:
- *
- * ntfs_find_attr - find (next) attribute in mft record
- * @type: attribute type to find
- * @name: attribute name to find (optional, i.e. NULL means don't care)
- * @name_len: attribute name length (only needed if @name present)
- * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present)
- * @val: attribute value to find (optional, resident attributes only)
- * @val_len: attribute value length
[...2737 lines suppressed...]
+ ctx->attr = (ATTR_RECORD*)((char*)mrec +
+ le16_to_cpu(mrec->attrs_offset));
+ ctx->is_first = TRUE;
+ ctx->ntfs_ino = ni;
+ ctx->al_entry = NULL;
+ ctx->base_ntfs_ino = NULL;
+ ctx->base_mrec = NULL;
+ ctx->base_attr = NULL;
+}
+
+/**
* ntfs_reinit_attr_search_ctx - reinitialize an attribute search context
* @ctx: attribute search context to reinitialize
@@ -2006,6 +2005,4 @@
/**
- * Inline:
- *
* ntfs_get_nr_significant_bytes - get number of bytes needed to store a number
* @n: number for which to get the number of bytes for
Index: dir.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/dir.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -U2 -r1.8 -r1.9
--- dir.c 11 Jul 2002 23:44:13 -0000 1.8
+++ dir.c 12 Jul 2002 08:18:15 -0000 1.9
@@ -40,130 +40,4 @@
const_cpu_to_le16('\0') };
-/*
- * The little endian Unicode string ".." as a static global constant.
- */
-static const uchar_t dotdot[3] = { const_cpu_to_le16('.'),
- const_cpu_to_le16('.'),
- const_cpu_to_le16('\0') };
-
-typedef union {
- INDEX_ROOT *ir;
- INDEX_ALLOCATION *ia;
-} index_union __attribute__ ((__transparent_union__));
-
-typedef enum {
- INDEX_TYPE_ROOT, /* index root */
- INDEX_TYPE_ALLOCATION, /* index allocation */
-} INDEX_TYPE;
-
-/**
- * Internal:
- *
- * ntfs_filldir - ntfs specific filldir method
- * @dir_ni: ntfs inode of current directory
- * @pos: current position in directory
- * @ivcn_bits: log(2) of index vcn size
- * @index_type: specifies whether @iu is an index root or an index allocation
- * @iu: index root or index block to which @ie belongs
- * @ie: current index entry
- * @dirent: context for filldir callback supplied by the caller
- * @filldir: filldir callback supplied by the caller
- *
- * Pass information specifying the current directory entry @ie to the @filldir
- * callback.
- */
-static inline int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits,
- const INDEX_TYPE index_type, index_union iu, INDEX_ENTRY *ie,
- void *dirent, ntfs_filldir_t filldir)
-{
- FILE_NAME_ATTR *fn = &ie->key.file_name;
- unsigned dt_type;
-
- /* Advance the position even if going to skip the entry. */
- if (index_type == INDEX_TYPE_ALLOCATION)
- *pos = (u8*)ie - (u8*)iu.ia + (sle64_to_cpu(
- iu.ia->index_block_vcn) << ivcn_bits) +
- dir_ni->vol->mft_record_size;
- else /* if (index_type == INDEX_TYPE_ROOT) */
- *pos = (u8*)ie - (u8*)iu.ir;
- /* Skip root directory self reference entry. */
- if (MREF_LE(ie->indexed_file) == FILE_root)
- return 0;
- if (ie->key.file_name.file_attributes &
- FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT)
- dt_type = NTFS_DT_DIR;
- else
- dt_type = NTFS_DT_REG;
- return filldir(dirent, fn->file_name, fn->file_name_length,
- fn->file_name_type, *pos,
- le64_to_cpu(ie->indexed_file), dt_type);
-}
-
-/**
- * Internal:
- *
- * ntfs_get_parent_mft_ref - find mft reference of parent directory of an inode
- * @ni: ntfs inode whose parent directory to find
- *
- * Find the parent directory of the ntfs inode @ni. To do this, find the first
- * file name attribute in the mft record of @ni and return the parent mft
- * reference from that.
- *
- * Note this only makes sense for directories, since files can be hard linked
- * from multiple directories and there is no way for us to tell which one is
- * being looked for.
- *
- * Technically directories can have hard links, too, but we consider that as
- * illegal as Linux/UNIX do not support directory hard links.
- *
- * Return the mft reference of the parent directory on success or -1 on error
- * with errno set to the error code.
- */
-static MFT_REF ntfs_get_parent_mft_ref(ntfs_inode *ni)
-{
- MFT_REF mref;
- ntfs_attr_search_ctx *ctx;
- FILE_NAME_ATTR *fn;
- int eo;
-
- if (!ni) {
- errno = EINVAL;
- return -1;
- }
-
- ctx = ntfs_get_attr_search_ctx(ni, NULL);
- if (!ctx)
- return -1;
- if (ntfs_lookup_attr(AT_FILE_NAME, AT_NONAME, 0, 0, 0, NULL, 0, ctx)) {
- Dprintf("No file name found in inode 0x%Lx. Corrupt inode.\n",
- (unsigned long long)ni->mft_no);
- goto err_out;
- }
- if (ctx->attr->non_resident) {
- Dprintf("File name attribute must be resident. Corrupt inode "
- "0x%Lx.\n", (unsigned long long)ni->mft_no);
- goto io_err_out;
- }
- fn = (FILE_NAME_ATTR*)((u8*)ctx->attr +
- le16_to_cpu(ctx->attr->value_offset));
- if ((u8*)fn + le32_to_cpu(ctx->attr->value_length) >
- (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) {
- Dprintf("Corrupt file name attribute in inode 0x%Lx.\n",
- (unsigned long long)ni->mft_no);
- goto io_err_out;
- }
- mref = le64_to_cpu(fn->parent_directory);
- ntfs_put_attr_search_ctx(ctx);
- return mref;
-io_err_out:
- errno = EIO;
-err_out:
- eo = errno;
- ntfs_put_attr_search_ctx(ctx);
- errno = eo;
- return -1;
-}
-
-
/**
* ntfs_lookup_inode_by_name - find an inode in a directory given its name
@@ -577,4 +451,132 @@
}
+/*
+ * The little endian Unicode string ".." for ntfs_readdir().
+ */
+static const uchar_t dotdot[3] = { const_cpu_to_le16('.'),
+ const_cpu_to_le16('.'),
+ const_cpu_to_le16('\0') };
+
+/*
+ * More helpers for ntfs_readdir().
+ */
+typedef union {
+ INDEX_ROOT *ir;
+ INDEX_ALLOCATION *ia;
+} index_union __attribute__ ((__transparent_union__));
+
+typedef enum {
+ INDEX_TYPE_ROOT, /* index root */
+ INDEX_TYPE_ALLOCATION, /* index allocation */
+} INDEX_TYPE;
+
+/**
+ * Internal:
+ *
+ * ntfs_filldir - ntfs specific filldir method
+ * @dir_ni: ntfs inode of current directory
+ * @pos: current position in directory
+ * @ivcn_bits: log(2) of index vcn size
+ * @index_type: specifies whether @iu is an index root or an index allocation
+ * @iu: index root or index block to which @ie belongs
+ * @ie: current index entry
+ * @dirent: context for filldir callback supplied by the caller
+ * @filldir: filldir callback supplied by the caller
+ *
+ * Pass information specifying the current directory entry @ie to the @filldir
+ * callback.
+ */
+static inline int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits,
+ const INDEX_TYPE index_type, index_union iu, INDEX_ENTRY *ie,
+ void *dirent, ntfs_filldir_t filldir)
+{
+ FILE_NAME_ATTR *fn = &ie->key.file_name;
+ unsigned dt_type;
+
+ /* Advance the position even if going to skip the entry. */
+ if (index_type == INDEX_TYPE_ALLOCATION)
+ *pos = (u8*)ie - (u8*)iu.ia + (sle64_to_cpu(
+ iu.ia->index_block_vcn) << ivcn_bits) +
+ dir_ni->vol->mft_record_size;
+ else /* if (index_type == INDEX_TYPE_ROOT) */
+ *pos = (u8*)ie - (u8*)iu.ir;
+ /* Skip root directory self reference entry. */
+ if (MREF_LE(ie->indexed_file) == FILE_root)
+ return 0;
+ if (ie->key.file_name.file_attributes &
+ FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT)
+ dt_type = NTFS_DT_DIR;
+ else
+ dt_type = NTFS_DT_REG;
+ return filldir(dirent, fn->file_name, fn->file_name_length,
+ fn->file_name_type, *pos,
+ le64_to_cpu(ie->indexed_file), dt_type);
+}
+
+/**
+ * Internal:
+ *
+ * ntfs_get_parent_mft_ref - find mft reference of parent directory of an inode
+ * @ni: ntfs inode whose parent directory to find
+ *
+ * Find the parent directory of the ntfs inode @ni. To do this, find the first
+ * file name attribute in the mft record of @ni and return the parent mft
+ * reference from that.
+ *
+ * Note this only makes sense for directories, since files can be hard linked
+ * from multiple directories and there is no way for us to tell which one is
+ * being looked for.
+ *
+ * Technically directories can have hard links, too, but we consider that as
+ * illegal as Linux/UNIX do not support directory hard links.
+ *
+ * Return the mft reference of the parent directory on success or -1 on error
+ * with errno set to the error code.
+ */
+static MFT_REF ntfs_get_parent_mft_ref(ntfs_inode *ni)
+{
+ MFT_REF mref;
+ ntfs_attr_search_ctx *ctx;
+ FILE_NAME_ATTR *fn;
+ int eo;
+
+ if (!ni) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ ctx = ntfs_get_attr_search_ctx(ni, NULL);
+ if (!ctx)
+ return -1;
+ if (ntfs_lookup_attr(AT_FILE_NAME, AT_NONAME, 0, 0, 0, NULL, 0, ctx)) {
+ Dprintf("No file name found in inode 0x%Lx. Corrupt inode.\n",
+ (unsigned long long)ni->mft_no);
+ goto err_out;
+ }
+ if (ctx->attr->non_resident) {
+ Dprintf("File name attribute must be resident. Corrupt inode "
+ "0x%Lx.\n", (unsigned long long)ni->mft_no);
+ goto io_err_out;
+ }
+ fn = (FILE_NAME_ATTR*)((u8*)ctx->attr +
+ le16_to_cpu(ctx->attr->value_offset));
+ if ((u8*)fn + le32_to_cpu(ctx->attr->value_length) >
+ (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) {
+ Dprintf("Corrupt file name attribute in inode 0x%Lx.\n",
+ (unsigned long long)ni->mft_no);
+ goto io_err_out;
+ }
+ mref = le64_to_cpu(fn->parent_directory);
+ ntfs_put_attr_search_ctx(ctx);
+ return mref;
+io_err_out:
+ errno = EIO;
+err_out:
+ eo = errno;
+ ntfs_put_attr_search_ctx(ctx);
+ errno = eo;
+ return -1;
+}
+
/**
* ntfs_readdir - read the contents of an ntfs directory
@@ -893,7 +895,4 @@
}
goto find_next_index_buffer;
-
-
-
EOD:
/* We are finished, set *pos to EOD. */
Index: inode.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/inode.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -U2 -r1.16 -r1.17
--- inode.c 11 Jul 2002 23:44:13 -0000 1.16
+++ inode.c 12 Jul 2002 08:18:15 -0000 1.17
@@ -51,4 +51,14 @@
* Internal:
*
+ * allocate_ntfs_inode - desc
+ */
+ntfs_inode *allocate_ntfs_inode(ntfs_volume *vol)
+{
+ return __allocate_ntfs_inode(vol);
+}
+
+/**
+ * Internal:
+ *
* __release_ntfs_inode - desc
*/
@@ -65,13 +75,4 @@
free(ni);
return 0;
-}
-
-
-/**
- * allocate_ntfs_inode - desc
- */
-ntfs_inode *allocate_ntfs_inode(ntfs_volume *vol)
-{
- return __allocate_ntfs_inode(vol);
}
Index: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -U2 -r1.51 -r1.52
--- volume.c 12 Jul 2002 07:10:44 -0000 1.51
+++ volume.c 12 Jul 2002 08:18:15 -0000 1.52
@@ -83,4 +83,7 @@
}
+/* External declaration for internal function. */
+extern ntfs_inode *allocate_ntfs_inode(ntfs_volume *);
+
/**
* Internal:
@@ -355,38 +358,4 @@
}
-#ifdef HAVE_MNTENT_H
-/**
- * Internal:
- *
- * ntfs_check_mntent - desc
- *
- * If you are wanting to use this, you actually wanted to use
- * ntfs_check_if_mounted(), you just didn't realize. (-:
- *
- * See description of ntfs_check_if_mounted(), below.
- */
-static int ntfs_check_mntent(const char *file, unsigned long *mnt_flags)
-{
- struct mntent *mnt;
- FILE *f;
-
- if (!(f = setmntent(MOUNTED, "r")))
- return -1;
- while ((mnt = getmntent(f)))
- if (!strcmp(file, mnt->mnt_fsname))
- break;
- endmntent(f);
- if (!mnt)
- return 0;
- *mnt_flags = NTFS_MF_MOUNTED;
- if (!strcmp(mnt->mnt_dir, "/"))
- *mnt_flags |= NTFS_MF_ISROOT;
- if (hasmntopt(mnt, "ro") && !hasmntopt(mnt, "rw"))
- *mnt_flags |= NTFS_MF_READONLY;
- return 0;
-}
-
-#endif
-
/**
* ntfs_startup_volume - allocate and setup an ntfs volume
@@ -839,4 +808,37 @@
}
+#ifdef HAVE_MNTENT_H
+/**
+ * Internal:
+ *
+ * ntfs_check_mntent - desc
+ *
+ * If you are wanting to use this, you actually wanted to use
+ * ntfs_check_if_mounted(), you just didn't realize. (-:
+ *
+ * See description of ntfs_check_if_mounted(), below.
+ */
+static int ntfs_check_mntent(const char *file, unsigned long *mnt_flags)
+{
+ struct mntent *mnt;
+ FILE *f;
+
+ if (!(f = setmntent(MOUNTED, "r")))
+ return -1;
+ while ((mnt = getmntent(f)))
+ if (!strcmp(file, mnt->mnt_fsname))
+ break;
+ endmntent(f);
+ if (!mnt)
+ return 0;
+ *mnt_flags = NTFS_MF_MOUNTED;
+ if (!strcmp(mnt->mnt_dir, "/"))
+ *mnt_flags |= NTFS_MF_ISROOT;
+ if (hasmntopt(mnt, "ro") && !hasmntopt(mnt, "rw"))
+ *mnt_flags |= NTFS_MF_READONLY;
+ return 0;
+}
+
+#endif
/**
|