Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/include
In directory usw-pr-cvs1:/tmp/cvs-serv3426/include
Modified Files:
attrib.h bitmap.h mft.h
Log Message:
Commit of current state of development including locking a la kernel.
This doesn't work on user space (semaphores don't work).
Just want to have it committed. Will take out locking / modify it where
necessary to use pthreads ASAP.
Index: attrib.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/include/attrib.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -U2 -r1.21 -r1.22
--- attrib.h 2001/04/02 22:28:39 1.21
+++ attrib.h 2001/04/05 20:14:45 1.22
@@ -1704,6 +1704,17 @@
* Determine the logical cluster number given the virtual cluster number @vcn
* and the run list @rl describing the mapping between the LCNs and VCNs.
- * Return -ERRNO on error (ERRNO being the error number) and notably -NOENT
- * if vcn is outside the boundaries covered by the run list.
+ *
+ * Return values:
+ *
+ * > 0: The lcn corresponding to the vcn.
+ *
+ * 0: Check errno:
+ * If zero, the lcn corresponding to the vcn is zero.
+ * Otherwise, there was an error and errno contains the error code,
+ * the most interesting error being ENOENT indicating we are
+ * looking for a vcn which doesn't exist.
+ *
+ * -1: The lcn is sparse, i.e. it's contents are zero and there is no disk
+ * space allocated for it.
*/
LCN vcn_to_lcn(const run_list rl, const VCN vcn);
Index: bitmap.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/include/bitmap.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -U2 -r1.3 -r1.4
--- bitmap.h 2001/04/03 22:41:30 1.3
+++ bitmap.h 2001/04/05 20:14:45 1.4
@@ -43,6 +43,6 @@
* Set the bit @bit in the @bitmap to @new_value. Ignore all errors.
*/
-extern inline void ntfs_set_bit(__u8 *bitmap, const __u64 bit,
- const __u8 new_value);
+extern __inline__ void ntfs_set_bit(__u8 *bitmap, const __u64 bit,
+ const __u8 new_value);
/**
@@ -54,5 +54,5 @@
* Return -1 on error.
*/
-extern inline char ntfs_get_bit(const __u8 *bitmap, const __u64 bit);
+extern __inline__ char ntfs_get_bit(const __u8 *bitmap, const __u64 bit);
/**
@@ -65,5 +65,5 @@
* Return -1 on error.
*/
-extern inline char ntfs_get_and_set_bit(__u8 *bitmap, const __u64 bit,
+extern __inline__ char ntfs_get_and_set_bit(__u8 *bitmap, const __u64 bit,
const __u8 new_value);
Index: mft.h
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/include/mft.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -U2 -r1.14 -r1.15
--- mft.h 2001/04/03 23:38:54 1.14
+++ mft.h 2001/04/05 20:14:45 1.15
@@ -25,4 +25,8 @@
#define MFT_H
+#ifndef __KERNEL__
+#define __KERNEL__
+#endif
+
#include <asm/atomic.h>
#include <asm/semaphore.h>
@@ -31,4 +35,5 @@
#include "endians.h"
#include "ntfs_rec.h"
+#include "volume.h"
#define is_mft_record(x) ( is_file_record(x) )
@@ -324,4 +329,6 @@
* first if dirty flag is set).
*
+ * m_sem: Read write semaphore controlling access to this entry.
+ *
* m_list: Hook for the mft_entries linked list.
*
@@ -395,18 +402,11 @@
#define ClearMftEntryDirty(me) clear_bit(ME_dirty, &(me)->m_flags)
-extern void __set_mft_entry_dirty(mft_entry *);
-
-static inline void set_mft_entry_dirty(mft_entry *me)
-{
- if (!test_and_set_bit(ME_dirty, &me->m_flags))
- __set_mft_entry_dirty(me);
-}
-
typedef struct {
MFT_RECORD *m_rec;
- rw_semaphore m_rec_sem;
- unsigned int m_flags; /* mapped, dirty */
+ struct rw_semaphore m_rec_sem;
+ unsigned int m_flags;
MFT_REFERENCE m_ref;
atomic_t m_count;
+ struct rw_semaphore m_sem;
struct list_head m_list;
struct list_head m_dirty_list;
@@ -414,9 +414,17 @@
} mft_entry;
+void __set_mft_entry_dirty(mft_entry *me);
+
+static __inline__ void set_mft_entry_dirty(mft_entry *me)
+{
+ if (!test_and_set_bit(ME_dirty, &me->m_flags))
+ __set_mft_entry_dirty(me);
+}
+
typedef struct {
MFT_REFERENCE *f_mft_refs;
- mft_erntry *f_mft_entries;
+ mft_entry *f_mft_entries;
int f_nr_mft_refs;
- rw_semaphore f_sem;
+ struct rw_semaphore f_sem;
atomic_t f_count;
struct list_head f_list;
@@ -424,4 +432,113 @@
/**
+ * __allocate_mft_entry - allocate a new mft_entry and initialize it
+ *
+ * Return the new mft_entry on success or NULL with errno set to the error code.
+ */
+extern __inline__ mft_entry *__allocate_mft_entry(void);
+
+/**
+ * free_mft_entry - free a mft_entry
+ * @me: mft_entry to free
+ *
+ * Must be unlocked, use count 0, etc, or we return -EBUSY.
+ * Return 0 on success and -ERRNO on error.
+ */
+extern __inline__ int free_mft_entry(mft_entry *me);
+
+/**
+ * insert_mft_entry - insert a mft_entry in a volume
+ * @vol: volume to insert into
+ * @me: mft_entry to insert
+ * @mref: mft reference the mft entry will have
+ * @mrec: optional loaded MFT_RECORD corresponding to @mref
+ * @dirty: boolean whether @mrec is dirty or not (only if @mrec present)
+ *
+ * Initialize the mft_entry with the values of @mref, @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.
+ *
+ * Return 0 on success and -ERRNO on error.
+ */
+int insert_mft_entry(ntfs_volume *vol, mft_entry *me, MFT_REFERENCE mref,
+ MFT_RECORD *mrec, int dirty);
+
+/**
+ * remove_mft_entry - remove a mft_entry from it's volume and free it
+ * @me: mft_entry to remove and free
+ *
+ * The mft entry must have a use count of 0, or we return -EBUSY.
+ *
+ * Remove the mft entry from the volume, flush it to disk if necessary,
+ * and finally free all memory that was used by the entry including the entry
+ * itself.
+ *
+ * Return 0 on success and -ERRNO on error.
+ */
+int remove_mft_entry(mft_entry *me);
+
+/**
+ * __map_mft_entry - map an mft entry into memory
+ * @me: mft entry to map
+ *
+ * Map an (unmapped) mft entry into memory not increasing the use count.
+ *
+ * Return 0 on success or -ERRNO on error.
+ */
+int __map_mft_entry(mft_entry *me);
+
+/**
+ * map_mft_entry - map an mft entry into memory
+ * @me: mft entry to map
+ *
+ * Map an (unmapped) mft entry into memory and increase the use count.
+ *
+ * Return 0 on success or -ERRNO on error.
+ */
+static __inline__ int map_mft_entry(mft_entry *me)
+{
+ atomic_inc(&me->m_count);
+ if (MftEntryMapped(me))
+ return 0;
+ return __map_mft_entry(me);
+}
+
+/**
+ * unmap_mft_entry - unmap an mft entry
+ * @me: mft entry to unmap
+ *
+ * Decrease the use count of the mft entry (only if it is above 0). Do not
+ * actually unmap it. We always keep it cached in memory. However, when we
+ * have unmapped it and the count has reached zero, the entry can be safely
+ * unmapped if it is necessary but that happens elsewhere.
+ */
+static __inline__ void unmap_mft_entry(mft_entry *me)
+{
+ if (MftEntryMapped(me) && atomic_read(&me->m_count) > 0)
+ atomic_dec(&me->m_count);
+}
+
+/**
+ * __unmap_mft_entry - unmap an mft entry
+ * @me: mft entry to unmap
+ *
+ * Actually unmap the mft entry (only if use count is 0).
+ *
+ * Return zero on success or -ERRNO on error.
+ */
+int __unmap_mft_entry(mft_entry *me);
+
+/**
+ * flush_mft_entry - flush a mft_entry to disk
+ * @me: mft_entry to flush
+ *
+ * The mft entry is written to disk (if dirty) and marked clean. It is also
+ * removed from the dirty list of the volume.
+ *
+ * Return 0 on success and -ERRNO on error.
+ */
+int flush_mft_entry(mft_entry *me);
+
+/**
* ntfs_open_by_mref - open an ntfs file, i.e. mft record, given a mft reference
* @vol: ntfs volume to operate on
@@ -445,6 +562,6 @@
* @fref: ntfs_file pointer to close
*
- * Close a previously opened ntfs file. Return zero on success or -ERRNO on
- * error, where ERRNO is the error number.
+ * Close a previously opened ntfs file. Return zero on success or -1 on
+ * error, where errno is the error number.
*/
int ntfs_close(ntfs_file *fref);
|