Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/include
In directory usw-pr-cvs1:/tmp/cvs-serv4600/include
Modified Files:
mft.h volume.h
Log Message:
More or less finished file handling. (Probably some useful functions are
still missing but they will be implemented as need arises.)
One thing that is stupid at the moment is we don't limit the amount of
cached mft_records so if you were to load loads the machine would eventually
run out of memory... Can't happen with files as they are limited to 1000,
unless you are short of memory. (Hard limit at the moment, set in ntfs_mount().
Maybe ntfsd should be monitoring memory usage and be throwing out unused cache
entries and closed_files? That would mean to have locking everywhere, though.)
Still missing: - Convert old code to use new stuff. - Add non-resident
attributes somewhere. Either into the mft_entry structure or into the
ntfs_file structure, but which? At the moment I tend to mft_entry so they can
be synced together with the entries by ntfsd.
Index: mft.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/include/mft.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -U2 -r1.16 -r1.17
--- mft.h 2001/04/08 01:58:29 1.16
+++ mft.h 2001/04/09 00:05:37 1.17
@@ -271,8 +271,4 @@
* max_files: Maximum number of nr_open_files + nr_closed_files.
*
- * files_lock: Spinlock to serialize access to the above
- * structure members (open_files, nr_open_files,
- * closed_files, nr_closed_files and max_files).
- *
* As files are opened/closed, records move from one list to the other. When a
* file is opened it moves to the front of files_open as we expect to do I/O on
@@ -292,7 +288,4 @@
* nr_mft_entries: Number of mft_entries.
*
- * mft_entries_lock: Spinlock to serialize access to
- * {nr_}mft_entries.
- *
* dirty_mft_entries: Linked list of all loaded mft records which are dirty.
* Used by the disk writer thread. When a mft_entry is
@@ -347,4 +340,6 @@
* m_vol: Volume this entry and its mft record belong to.
*
+ * m_file: Ntfs file this mft entry belongs to.
+ *
* Future:
*
@@ -362,11 +357,11 @@
* members:
*
- * f_mft_refs: The mft references of the file (i.e. the on disk inode number).
+ * m_refs: The mft references of the file (i.e. the on disk inode number).
* This is an array of MFT_REFERENCEs. The first reference is the
* base mft record and if any others exist they are the associated
* loaded extension mft records. Used for attribute list purposes.
*
- * f_mft_entries: The loaded mft records for the file. This is an array of
- * pointers to mft_entries, corresponding to the f_mft_refs. This
+ * m_entries: The loaded mft records for the file. This is an array of
+ * pointers to mft_entries, corresponding to the m_refs. This
* is not strictly necessary but results in a big speed up as we
* don't need to search the vol->mft_entries list every time...
@@ -375,12 +370,9 @@
* corresponding entry is increased by one.
*
- * f_nr_mft_refs: Number of records in the f_mft_* arrays. If > 1, we
+ * nr_mft_refs: Number of records in the m_* arrays. If > 1, we
* know there must be an attribute list attribute (but if 1, we
* cannot assume there isn't one). This is of course the same as
- * a possible f_nr_mft_entries, but refs is shorter to write. (-;
+ * a possible nr_m_entries, but refs is shorter to write. (-;
*
- * f_lock: Spinlock for serializing access to the above struct
- * members (f_mft_refs, f_mft_entries and f_nr_mft_refs).
- *
* f_count: Atomic usage count. When zero this file is not open by anyone
* and can be thrown away safely. No need to concern oneself with
@@ -388,5 +380,6 @@
* below the idea of files.
*
- * f_list: Anchor into vol->open/closed_files list.
+ * f_list: Anchor into vol->open/closed_files list. If f_count is > 0,
+ * into open_files list, otherwise into closed_files list.
*
* Notes:
@@ -422,4 +415,5 @@
MFT_REFERENCE m_ref;
atomic_t m_count;
+ ntfs_file *m_file;
struct spinlock_t m_lock;
struct list_head m_list;
@@ -429,10 +423,10 @@
typedef struct {
- MFT_REFERENCE *f_mft_refs;
- mft_entry *f_mft_entries;
- int f_nr_mft_refs;
- struct spinlock_t f_lock;
+ MFT_REFERENCE *m_refs;
+ mft_entry *m_entries;
+ int nr_m_refs;
atomic_t f_count;
struct list_head f_list;
+ ntfs_volume *f_vol;
} ntfs_file;
@@ -592,13 +586,16 @@
* insert_mft_entry - insert a mft_entry into a volume
* @vol: volume to insert into
- * @me: mft_entry to insert
- * @mref: mft reference the mft entry will have
+ * @me: mft_entry to insert (see notes)
+ * @mref: mft reference the mft_entry will have
* @mrec: loaded MFT_RECORD corresponding to @mref (optional)
* @dirty: true if @mrec is dirty, false otherwise (only if @mrec present)
+ * @f: file associated with the mft_entry (optional)
*
- * Initialize the mft_entry with the values of @mref, @mrec and @dirty and
+ * Initialize the mft_entry with the values of @mref, @f, @mrec and @dirty and
* insert it into the volume @vol. If @mrec is not present, the mft record
* corresponding to @mref is loaded from the volume.
*
+ * If *@me is NULL, a new mft_entry will be allocated and returned in *@me.
+ *
* Return 0 on success and -ERRNO on error. On error, the following values are
* returned:
@@ -608,6 +605,7 @@
* others Values returned by flush_mft_entry.
*/
-int insert_mft_entry(ntfs_volume *vol, mft_entry *me, const MFT_REFERENCE mref,
- const MFT_RECORD *mrec, const BOOL dirty);
+int insert_mft_entry(ntfs_volume *vol, mft_entry **me, const MFT_REFERENCE mref,
+ const MFT_RECORD *mrec, const BOOL dirty,
+ const ntfs_file *f);
/**
@@ -627,4 +625,71 @@
/**
+ * __allocate_ntfs_file - allocate a new ntfs_file and initialize it
+ *
+ * Return the new ntfs_file on success or NULL with errno set to the error
+ * code returned from malloc().
+ */
+extern __inline__ ntfs_file *__allocate_ntfs_file(void);
+
+/**
+ * __free_ntfs_file - free a ntfs_file
+ * @f: ntfs_file to free
+ *
+ * Return 0 on success and -EBUSY on error.
+ *
+ * To succeed, the file must have a use count of 0, as well as a nr_m_ref of
+ * zero. If any of these are false, return -EBUSY.
+ */
+extern __inline__ int __free_ntfs_file(ntfs_file *f);
+
+/**
+ * __remove_all_extension_records_from_ntfs_file - as name
+ * @f: ntfs_file on which to operate
+ *
+ * Remove all extension records from ntfs_file @f. Return 0 on success and
+ * -errno on error.
+ */
+int __remove_all_extension_records_from_ntfs_file(ntfs_file *f);
+
+/**
+ * __add_mtf_entry_to_ntfs_file - as name
+ * @f: ntfs_file to which to add the mft_entry
+ * @m: mft_entry to add
+ *
+ * Add @me to @f. Return 0 on success and -errno on error.
+ */
+int __add_mtf_entry_to_ntfs_file(ntfs_file *f, mft_entry *me);
+
+/**
+ * __remove_mft_entry_from_ntfs_file - as name
+ * @me: mft_entry to remove from its associated file
+ *
+ * Remove @me from @me->m_file. This will also remove the file if @me is the
+ * base mft record of @me->m_file. The file has to be closed for anything to
+ * happen. Return 0 on success and -errno on error.
+ */
+int __remove_mft_entry_from_ntfs_file(mft_entry *me);
+
+/**
+ * remove_closed_ntfs_file - remove closed ntfs_file from its volume
+ * @f: file to remove
+ *
+ * Remove @f from @f->f_vol. @f has to be closed. Return 0 on success and
+ * -errno on error.
+ */
+int remove_closed_ntfs_file(ntfs_file *f);
+
+/**
+ * __insert_open_ntfs_file - insert ntfs_file into volume opening it
+ * @v: volume to insert the ntfs_file into
+ * @f: ntfs_file to insert
+ * @m: base mft record to associate with the ntfs_file
+ *
+ * Adds @f to @v (as an open file) and vice versa. Same for @f and @m. Makes
+ * sure @m is mapped. Return 0 on success and -errno on error.
+ */
+int __insert_open_ntfs_file(ntfs_volume *v, ntfs_file *f, mft_entry *m);
+
+/**
* ntfs_open_by_mref - open an ntfs file (mft record), given its mft reference
* @vol: ntfs volume to operate on
@@ -634,8 +699,8 @@
* reference of the mft record (i.e. the inode number). To do this, allocate an
* ntfs_file structure (adding it to the vol->open_files array), or if the file
- * is already loaded, just find it in the vol->open_/closed_files arrays.
+ * is already loaded, just return that, incrementing the use count.
*
- * Return a pointer to the ntfs_file structure in the vol->open_files array or
- * NULL on error with errno containing the error code.
+ * Return a pointer to the ntfs_file structure or NULL on error with errno
+ * set to the appropriate error code.
*
* This pointer should be treated completely opaquely by the user! Never
@@ -643,12 +708,11 @@
* pointer as a parameter.
*/
-ntfs_file *ntfs_open_by_mref(ntfs_volume *vol, const MFT_REFERENCE *mref);
+ntfs_file *ntfs_open_by_mref(ntfs_volume *vol, const MFT_REFERENCE mref);
/**
* ntfs_close - close an ntfs_file
- * @vol: ntfs volume to operate on
- * @f: ntfs_file pointer to close
+ * @f: ntfs_file to close
*
- * Close a previously opened ntfs file. Return zero on success or -ERRNO on
+ * Close a previously opened ntfs file. Return zero on success or -errno on
* error.
*/
Index: volume.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/include/volume.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -U2 -r1.9 -r1.10
--- volume.h 2001/04/08 03:02:55 1.9
+++ volume.h 2001/04/09 00:05:37 1.10
@@ -112,8 +112,4 @@
files which are not open any more. */ int nr_closed_files; /* Number of closed files. */
int max_files; /* Maximum number of nr_open_files + nr_ closed_files. */
- spinlock_t files_lock; /* Spinlock to serialize
- access to open_files, nr_open_files,
- closed_files, nr_closed_files and
- max_files). */
struct list_head mft_entries; /* Linked list of all loaded mft records
(disk inodes) in order of ascending
@@ -123,6 +119,4 @@
struct pointers. */
int nr_mft_entries; /* Number of mft_entries. */
- spinlock_t mft_entries_lock; /* Spinlock to serialize
- access to {nr_}mft_entries. */
struct list_head dirty_mft_entries; /* Linked list of all loaded mft
records which are dirty. */
|