Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv26646/libntfs
Modified Files:
attrib.c attrib_RE.c inode.c volume.c
Log Message:
Finished provisional inode.c::ntfs_{open,close}_inode() functions. Also, started defining API provided by attrib.[ch], so far only done search context related stuff.
Index: attrib.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/attrib.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -U2 -r1.23 -r1.24
--- attrib.c 16 Apr 2002 15:34:32 -0000 1.23
+++ attrib.c 19 Apr 2002 21:09:55 -0000 1.24
@@ -85,5 +85,5 @@
const IGNORE_CASE_BOOL ic, const uchar_t *upcase,
const __u32 upcase_len, const __u8 *val, const __u32 val_len,
- attr_search_context *ctx)
+ ntfs_attr_search_ctx *ctx)
{
ATTR_RECORD *a;
@@ -191,5 +191,5 @@
ATTR_RECORD *r;
VOLUME_INFORMATION *c;
- attr_search_context *ctx;
+ ntfs_attr_search_ctx *ctx;
/* Sanity checks. */
@@ -197,5 +197,5 @@
return 0;
/* Get a pointer to the volume information attribute. */
- ctx = get_attr_search_ctx(NULL, b);
+ ctx = ntfs_get_attr_search_ctx(NULL, b);
if (!ctx) {
Dperror("Failed to allocate attribute search context");
@@ -228,9 +228,9 @@
/* Set the volume flags. */
c->flags = cpu_to_le16(flags);
- put_attr_search_ctx(ctx);
+ ntfs_put_attr_search_ctx(ctx);
/* Success! */
return 1;
err_out:
- put_attr_search_ctx(ctx);
+ ntfs_put_attr_search_ctx(ctx);
return 0;
}
@@ -740,5 +740,5 @@
/**
- * init_attr_search_ctx - initialize an attribute search context
+ * ntfs_init_attr_search_ctx - initialize an attribute search context
* @ctx: attribute search context to initialize
* @ni: ntfs inode with which to initialize the search context
@@ -747,8 +747,11 @@
* Initialize the attribute search context @ctx with @ni and @mrec.
*/
-static __inline__ void init_attr_search_ctx(attr_search_context *ctx,
+static __inline__ void ntfs_init_attr_search_ctx(ntfs_attr_search_ctx *ctx,
ntfs_inode *ni, MFT_RECORD *mrec)
{
- ctx->mrec = mrec;
+ if (ni && !mrec)
+ ctx->mrec = ni->mrec;
+ else
+ ctx->mrec = mrec;
/* Sanity checks are performed elsewhere. */
ctx->attr = (ATTR_RECORD*)((char*)mrec +
@@ -763,5 +766,5 @@
/**
- * reinit_attr_search_ctx - reinitialize an attribute search context
+ * ntfs_reinit_attr_search_ctx - reinitialize an attribute search context
* @ctx: attribute search context to reinitialize
*
@@ -772,5 +775,5 @@
* the search context to the beginning.
*/
-void reinit_attr_search_ctx(attr_search_context *ctx)
+void ntfs_reinit_attr_search_ctx(ntfs_attr_search_ctx *ctx)
{
if (!ctx->base_ntfs_ino) {
@@ -785,10 +788,10 @@
fprintf(stderr, __FUNCTION__ "(): FIXME: EEEEEK!\n");
// unmap_mft_record(READ, ctx->ntfs_ino);
- init_attr_search_ctx(ctx, ctx->base_ntfs_ino, ctx->base_mrec);
+ ntfs_init_attr_search_ctx(ctx, ctx->base_ntfs_ino, ctx->base_mrec);
return;
}
/**
- * get_attr_search_ctx - allocate and initialize a new attribute search context
+ * ntfs_get_attr_search_ctx - allocate/initialize a new attribute search context
* @ctx: address of pointer in which to return the new search context
* @ni: ntfs inode with which to initialize the search context
@@ -798,14 +801,14 @@
* and return it. Return NULL on error with errno set to ENOMEM.
*/
-attr_search_context *get_attr_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec)
+ntfs_attr_search_ctx *ntfs_get_attr_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec)
{
- attr_search_context *ctx = malloc(sizeof(attr_search_context));
+ ntfs_attr_search_ctx *ctx = malloc(sizeof(ntfs_attr_search_ctx));
if (ctx)
- init_attr_search_ctx(ctx, ni, mrec);
+ ntfs_init_attr_search_ctx(ctx, ni, mrec);
return ctx;
}
/**
- * put_attr_search_ctx - release an attribute search context
+ * ntfs_put_attr_search_ctx - release an attribute search context
* @ctx: attribute search context to free
*
@@ -813,5 +816,5 @@
* mft record if present.
*/
-void put_attr_search_ctx(attr_search_context *ctx)
+void ntfs_put_attr_search_ctx(ntfs_attr_search_ctx *ctx)
{
if (ctx->base_ntfs_ino && ctx->ntfs_ino != ctx->base_ntfs_ino)
Index: attrib_RE.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/attrib_RE.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -U2 -r1.1 -r1.2
--- attrib_RE.c 2 Apr 2001 02:04:37 -0000 1.1
+++ attrib_RE.c 19 Apr 2002 21:09:55 -0000 1.2
@@ -7,5 +7,5 @@
const wchar_t *name, const __u32 name_len,
const IGNORE_CASE_BOOL ic, const __u8 *val, const __u32 val_len,
- attr_search_context *ctx)
+ ntfs_attr_search_ctx *ctx)
{
ATTR_RECORD *a;
@@ -94,5 +94,5 @@
const __u32 name_len, const IGNORE_CASE_BOOL ic,
const __s64 lowest_vcn, const __u8 *val,
- const __u32 val_len, attr_search_context *ctx)
+ const __u32 val_len, ntfs_attr_search_ctx *ctx)
{
ATTR_LIST_ENTRY *al_pos, **al_val, *al_val_start, *al_next_pos;
@@ -282,5 +282,5 @@
const __u32 name_len, const IGNORE_CASE_BOOL ic,
const __s64 lowest_vcn, const __u8 *val, const __u32 val_len,
- attr<F12_search_context *ctx)
+ ntfs_attr_search_ctx *ctx)
{
MFT_RECORD *m;
Index: inode.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/inode.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -U2 -r1.1 -r1.2
--- inode.c 19 Apr 2002 18:23:56 -0000 1.1
+++ inode.c 19 Apr 2002 21:09:55 -0000 1.2
@@ -30,6 +30,7 @@
#include "debug.h"
#include "mft.h"
+#include "attrib.h"
-static __inline__ ntfs_inode *__allocate_ntfs_inode(ntfs_volume *vol)
+static __inline__ ntfs_inode *__allocate_ntfs_inode(const ntfs_volume *vol)
{
ntfs_inode *ni;
@@ -43,15 +44,10 @@
static __inline__ int __release_ntfs_inode(ntfs_inode *ni)
{
- // TODO: This needs to be replaced with a flush to disk attempt.
- if (NInoDirty(ni) || NInoAttrListDirty(ni)) {
- errno = EBUSY;
- return -1;
- }
if (NInoAttrList(ni) && ni->attr_list)
free(ni->attr_list);
if (NInoAttrListNonResident(ni) && ni->attr_list_rl)
free(ni->attr_list_rl);
- if (ni->mft_rec)
- free(ni->mft_rec);
+ if (ni->mrec)
+ free(ni->mrec);
free(ni);
return 0;
@@ -69,7 +65,6 @@
*
* Then, allocate a buffer for the mft record, read the mft record from the
- * volume @vol, and attach it to the ntfs_inode structure (->mft_rec).
- *
- * Also, mst deprotect and sanity check for validity the mft record and abort
+ * volume @vol, and attach it to the ntfs_inode structure (->mrec). The
+ * mft record is mst deprotected and sanity checked for validity and we abort
* if deprotection or checks fail.
*
@@ -86,5 +81,8 @@
ntfs_inode *ntfs_open_inode(const ntfs_volume *vol, const MFT_REF mref)
{
+ __s64 l;
ntfs_inode *ni;
+ ntfs_attr_search_ctx *ctx;
+ int err = 0;
if (!vol) {
@@ -92,7 +90,61 @@
return NULL;
}
- ni = NULL;
- errno = ENOTSUP;
- return ni;
+ ni = __allocate_ntfs_inode(vol);
+ if (!ni)
+ return NULL;
+ if (read_file_record(vol, mref, &ni->mrec, NULL))
+ goto err_out;
+ ni->mft_no = MREF(mref);
+ ctx = ntfs_get_attr_search_ctx(ni, NULL);
+ if (!ctx)
+ goto err_out;
+ if (!find_attr($ATTRIBUTE_LIST, NULL, 0, 0, NULL, 0, NULL, 0, ctx)) {
+ /* Attribute list attribute not present so we are done. */
+ ntfs_put_attr_search_ctx(ctx);
+ return ni;
+ }
+ NInoSetAttrList(ni);
+ l = get_attribute_value_length(ctx->attr);
+ if (!l)
+ goto put_err_out;
+ if (l > 0x40000) {
+ err = EIO;
+ goto put_err_out;
+ }
+ ni->attr_list_size = l;
+ ni->attr_list = malloc(ni->attr_list_size);
+ if (!ni->attr_list)
+ goto put_err_out;
+ l = get_attribute_value(vol, ni->mrec, ctx->attr, ni->attr_list);
+ if (!l)
+ goto put_err_out;
+ if (l != ni->attr_list_size) {
+ err = EIO;
+ goto put_err_out;
+ }
+ if (!ctx->attr->non_resident) {
+ /* Attribute list attribute is resident so we are done. */
+ ntfs_put_attr_search_ctx(ctx);
+ return ni;
+ }
+ NInoSetAttrListNonResident(ni);
+ // FIXME: We are duplicating work here! (AIA)
+ ni->attr_list_rl = decompress_run_list(ctx->attr);
+ if (ni->attr_list_rl) {
+ /* We got the run list, so we are done. */
+ ntfs_put_attr_search_ctx(ctx);
+ return ni;
+ }
+ err = EIO;
+put_err_out:
+ if (!err)
+ err = errno;
+ ntfs_put_attr_search_ctx(ctx);
+err_out:
+ if (!err)
+ err = errno;
+ __release_ntfs_inode(ni);
+ errno = err;
+ return NULL;
}
@@ -112,4 +164,9 @@
int ntfs_close_inode(ntfs_inode *ni)
{
+ // TODO: This needs to be replaced with a flush to disk attempt. (AIA)
+ if (NInoDirty(ni) || NInoAttrListDirty(ni)) {
+ errno = EBUSY;
+ return -1;
+ }
return __release_ntfs_inode(ni);
}
Index: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -U2 -r1.28 -r1.29
--- volume.c 16 Apr 2002 20:56:01 -0000 1.28
+++ volume.c 19 Apr 2002 21:09:55 -0000 1.29
@@ -98,5 +98,5 @@
NTFS_BOOT_SECTOR *bs = NULL;
MFT_RECORD *mb = NULL;
- attr_search_context *ctx = NULL;
+ ntfs_attr_search_ctx *ctx = NULL;
ATTR_RECORD *a;
VOLUME_INFORMATION *vinf;
@@ -257,5 +257,5 @@
}
/* Find the bitmap attribute. */
- ctx = get_attr_search_ctx(NULL, mb);
+ ctx = ntfs_get_attr_search_ctx(NULL, mb);
if (!ctx) {
Dputs(FAILED);
@@ -310,5 +310,5 @@
#endif
/* Find the $DATA attribute in $Mft. */
- reinit_attr_search_ctx(ctx);
+ ntfs_reinit_attr_search_ctx(ctx);
if (!find_attr($DATA, NULL, 0, 0, NULL, 0, NULL, 0, ctx)) {
Dputs(FAILED);
@@ -338,5 +338,5 @@
Dputs(OK);
/* Done with the $Mft mft record. */
- put_attr_search_ctx(ctx);
+ ntfs_put_attr_search_ctx(ctx);
ctx = NULL;
free(mb);
@@ -350,5 +350,5 @@
goto error_exit;
}
- ctx = get_attr_search_ctx(NULL, mb);
+ ctx = ntfs_get_attr_search_ctx(NULL, mb);
if (!ctx) {
Dputs(FAILED);
@@ -389,5 +389,5 @@
/* Done with the $BitMap mft record. */
Dputs(OK);
- put_attr_search_ctx(ctx);
+ ntfs_put_attr_search_ctx(ctx);
ctx = NULL;
free(mb);
@@ -401,5 +401,5 @@
goto error_exit;
}
- ctx = get_attr_search_ctx(NULL, mb);
+ ctx = ntfs_get_attr_search_ctx(NULL, mb);
if (!ctx) {
Dputs(FAILED);
@@ -452,5 +452,5 @@
/* Done with the $UpCase mft record. */
Dputs(OK);
- put_attr_search_ctx(ctx);
+ ntfs_put_attr_search_ctx(ctx);
ctx = NULL;
free(mb);
@@ -465,5 +465,5 @@
goto error_exit;
}
- ctx = get_attr_search_ctx(NULL, mb);
+ ctx = ntfs_get_attr_search_ctx(NULL, mb);
if (!ctx) {
Dputs(FAILED);
@@ -509,5 +509,5 @@
vol->flags = vinf->flags;
/* Find the $VOLUME_NAME attribute. */
- reinit_attr_search_ctx(ctx);
+ ntfs_reinit_attr_search_ctx(ctx);
if (!find_attr($VOLUME_NAME, NULL, 0, 0, NULL, 0, NULL, 0, ctx)) {
Dputs(FAILED);
@@ -550,5 +550,5 @@
}
Dputs(OK);
- put_attr_search_ctx(ctx);
+ ntfs_put_attr_search_ctx(ctx);
ctx = NULL;
free(mb);
@@ -564,5 +564,5 @@
free(bs);
if (ctx)
- put_attr_search_ctx(ctx);
+ ntfs_put_attr_search_ctx(ctx);
if (mb)
free(mb);
|