Subversion Repositories HelenOS

Rev

Rev 3499 | Rev 3501 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3499 Rev 3500
Line 847... Line 847...
847
 
847
 
848
    fat_node_put(nodep);
848
    fat_node_put(nodep);
849
    ipc_answer_1(rid, EOK, (ipcarg_t)bytes);
849
    ipc_answer_1(rid, EOK, (ipcarg_t)bytes);
850
}
850
}
851
 
851
 
-
 
852
static void
852
static void fat_fill_gap(fat_node_t *nodep, off_t start, off_t stop)
853
fat_fill_gap(fat_node_t *nodep, fat_cluster_t mclst, off_t pos)
853
{
854
{
854
    /* TODO */
855
    /* TODO */
855
}
856
}
856
 
857
 
-
 
858
static int
-
 
859
fat_alloc_clusters(unsigned nclsts, fat_cluster_t *mcl, fat_cluster_t *lcl)
-
 
860
{
-
 
861
    return ENOTSUP; /* TODO */
-
 
862
}
-
 
863
 
-
 
864
static void
-
 
865
fat_append_clusters(fat_node_t *nodep, fat_cluster_t mcl)
-
 
866
{
-
 
867
}
-
 
868
 
857
void fat_write(ipc_callid_t rid, ipc_call_t *request)
869
void fat_write(ipc_callid_t rid, ipc_call_t *request)
858
{
870
{
859
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
871
    dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);
860
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
872
    fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request);
861
    off_t pos = (off_t)IPC_GET_ARG3(*request);
873
    off_t pos = (off_t)IPC_GET_ARG3(*request);
Line 907... Line 919...
907
         * This is the easier case - we are either overwriting already
919
         * This is the easier case - we are either overwriting already
908
         * existing contents or writing behind the EOF, but still within
920
         * existing contents or writing behind the EOF, but still within
909
         * the limits of the last cluster. The node size may grow to the
921
         * the limits of the last cluster. The node size may grow to the
910
         * next block size boundary.
922
         * next block size boundary.
911
         */
923
         */
912
        if (pos > nodep->size)
-
 
913
            fat_fill_gap(nodep, nodep->size, pos);
924
        fat_fill_gap(nodep, FAT_CLST_RES0, pos);
914
        b = fat_block_get(nodep, pos / bps);
925
        b = fat_block_get(nodep, pos / bps);
915
        (void) ipc_data_write_finalize(callid, b->data + pos % bps,
926
        (void) ipc_data_write_finalize(callid, b->data + pos % bps,
916
            bytes);
927
            bytes);
917
        b->dirty = true;        /* need to sync block */
928
        b->dirty = true;        /* need to sync block */
-
 
929
        block_put(b);
918
        if (pos + bytes > nodep->size) {
930
        if (pos + bytes > nodep->size) {
919
            nodep->size = pos + bytes;
931
            nodep->size = pos + bytes;
920
            nodep->dirty = true;    /* need to sync node */
932
            nodep->dirty = true;    /* need to sync node */
921
        }
933
        }
922
        block_put(b);
-
 
923
        fat_node_put(nodep);
934
        fat_node_put(nodep);
924
        ipc_answer_1(rid, EOK, bytes); 
935
        ipc_answer_1(rid, EOK, bytes); 
925
        return;
936
        return;
926
    } else {
937
    } else {
927
        /*
938
        /*
928
         * This is the more difficult case. We must allocate new
939
         * This is the more difficult case. We must allocate new
929
         * clusters for the node and zero them out.
940
         * clusters for the node and zero them out.
930
         */
941
         */
-
 
942
        int status;
931
        unsigned nclsts;
943
        unsigned nclsts;
-
 
944
        fat_cluster_t mcl, lcl;
932
       
945
   
933
        nclsts = (ROUND_UP(pos + bytes, bps * spc) - clst_boundary) /
946
        nclsts = (ROUND_UP(pos + bytes, bps * spc) - clst_boundary) /
934
            bps * spc;
947
            bps * spc;
-
 
948
        /* create an independent chain of nclsts clusters in all FATs */
-
 
949
        status = fat_alloc_clusters(nclsts, &mcl, &lcl);
-
 
950
        if (status != EOK) {
-
 
951
            /* could not allocate a chain of nclsts clusters */
-
 
952
            fat_node_put(nodep);
-
 
953
            ipc_answer_0(callid, status);
-
 
954
            ipc_answer_0(rid, status);
-
 
955
            return;
935
 
956
        }
-
 
957
        /* zero fill any gaps */
-
 
958
        fat_fill_gap(nodep, mcl, pos);
-
 
959
        b = _fat_block_get(dev_handle, lcl, (pos / bps) % spc);
-
 
960
        (void) ipc_data_write_finalize(callid, b->data + pos % bps,
-
 
961
            bytes);
-
 
962
        b->dirty = true;
-
 
963
        block_put(b);
-
 
964
        /*
-
 
965
         * Append the cluster chain starting in mcl to the end of the
-
 
966
         * node's cluster chain.
-
 
967
         */
-
 
968
        fat_append_clusters(nodep, mcl);
-
 
969
        nodep->size = pos + bytes;
-
 
970
        nodep->dirty = true;
-
 
971
        fat_node_put(nodep);
-
 
972
        ipc_answer_1(rid, EOK, bytes);
-
 
973
        return;
936
    }
974
    }
937
   
-
 
938
}
975
}
939
 
976
 
940
/**
977
/**
941
 * @}
978
 * @}
942
 */
979
 */