| /****************************************************************************** |
| *(C) Copyright 2011 Marvell International Ltd. |
| * All Rights Reserved |
| ******************************************************************************/ |
| /*-------------------------------------------------------------------------------------------------------------------- |
| * ------------------------------------------------------------------------------------------------------------------- |
| * |
| * Filename: sql_repo.c |
| * |
| * Description: The API to record the file states and opreations. |
| * |
| * History: |
| * July, 22 2013 - Zhongmin Wu(zmwu@marvell.com) Creation of file |
| * |
| * Notes: |
| * |
| ******************************************************************************/ |
| |
| #ifndef NVM_REPO_HEAD |
| #define NVM_REPO_HEAD |
| |
| #ifdef __cplusplus |
| extern "C" { |
| #endif |
| |
| typedef enum{ |
| UNTRACKED, |
| CHANGED, |
| STAGED, |
| COMMITTED, |
| }enum_file_status; |
| |
| |
| typedef enum{ |
| UPDATE, |
| DELETE, |
| RENAME, |
| CREATED, |
| }enum_file_operation; |
| |
| typedef struct file_info_tag{ |
| char * file_name; |
| char * target_name; |
| unsigned int crc; |
| enum_file_status status; |
| enum_file_operation operation; |
| struct file_info_tag * next; |
| }list_file_info; |
| |
| /* |
| ** Initialize the repository of NVM |
| ** @repo_name: the name of repository, it may be used for the implementation a data base file name |
| ** @return value: 0 - successful, -1 - fail; |
| */ |
| int nvm_repo_init(const char * repo_name); |
| |
| /* |
| ** De-Initialize the repository of NVM |
| ** @return value: 0 - successful, -1 - fail; |
| */ |
| int nvm_repo_deinit(void); |
| |
| /* |
| ** Get the tracked files list. Never modify the content of returned the structure list. |
| ** @return value: the returned tracked files information list. |
| */ |
| list_file_info * get_tracked_files(void); |
| |
| |
| /* |
| ** Get file status by file name |
| ** @file_name: the file name; |
| ** @return value: the file information; NULL if not found |
| */ |
| list_file_info * get_file_info(const char * file_name); |
| |
| |
| /* |
| ** Add the file to the repository, if the file is already tracked, it will do nothing. |
| ** @file_name: the file name to be tracked. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int track_file(const char * file_name); |
| |
| |
| /* |
| ** remove the file to the repository, if the file is already untracked, it will do nothing. |
| ** @file_name: the file name to be removed to track. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int untrack_file(const char * file_name); |
| |
| |
| /* |
| ** update the file in the repository, set its status to CHANGED. if the file is not tracked, it will return fail. |
| ** @file_name: the file name to be updated. |
| ** @operation: the operation to update the file |
| ** @return value: 0 - successful, 1 - fail |
| */ |
| //int update_file(const char * file_name, enum_file_operation operation); |
| |
| |
| /* |
| ** insert the file in the repository, set its status to CHANGED. if the file is not tracked, it will return fail. |
| ** @file_name: the file name to be updated. |
| ** @target_name: the target name to be renamed. |
| ** @operation: the operation to update the file |
| ** @offset: the offset where update the file |
| ** @size: the size of bytes data updated |
| ** @data: the data updated |
| ** @return value: row id of last insert, -1 - fail |
| */ |
| int insert_file_operation(const char * file_name, const char * target_name, enum_file_operation opertion, int offset, int size, const void * data); |
| |
| /* |
| ** insert the file in the repository, if the file is not tracked, it will return fail. |
| ** @file_name: the file name to be updated. |
| ** @target_name: the target name to be renamed. |
| ** @operation: the operation to update the file |
| ** @offset: the offset where update the file |
| ** @size: the size of bytes data updated |
| ** @crc: crc of the file to be updated |
| ** @status: current file status |
| ** @return value: row id of last insert, -1 - fail |
| */ |
| int record_file_operation(const char * file_name, const char * target_name, enum_file_operation operation, |
| int offset, int size, unsigned crc, enum_file_status status); |
| |
| /* |
| ** stage the file in the repository, set its status to STAGED. |
| ** @file_name: the file name to be updated. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int stage_file(const char * file_name); |
| |
| /* |
| ** stage the file in the repository with the file validation number , set its status to STAGED. |
| ** @file_name: the file name to be updated. |
| ** @crc: the file validation number. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int stage_file_crc(const char * file_name, unsigned int crc); |
| |
| /* |
| ** commit the file in the repository, set its status to COMMITTED. |
| ** @file_name: the file name to be updated. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int commit_file(const char * file_name); |
| |
| /* |
| ** commit the file in the repository with validation number, set its status to COMMITTED and the its crc to specified crc. |
| ** @file_name: the file name to be updated. |
| ** @crc: the file validation number. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int commit_file_crc(const char * file_name, unsigned int crc); |
| |
| /* |
| ** revert the file to the last commit in the repository. |
| ** @file_name: the file name to be revert. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int revert_last_commit(const char * file_name); |
| |
| /* |
| ** find the commit index with specified state and crc. |
| ** @file_name: the file name to be find. |
| ** @crc: the specified crc. |
| ** @return value: the index if found, 0 if not found. |
| */ |
| unsigned int find_commit(const char * file_name, enum_file_status state, unsigned long crc); |
| |
| /* |
| ** reset the commit to the specified index. |
| ** @file_name: the file name to be reset. |
| ** @id: the specified index. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int reset_file_id(const char * file_name, unsigned int id); |
| |
| /* |
| ** reset the commit to the specified state and crc. |
| ** @file_name: the file name to be reset. |
| ** @state: the specified state. |
| ** @crc: the specified crc. |
| ** @return value: 0 - successful, -1 - fail |
| */ |
| int reset_to_commit(const char * file_name, enum_file_status state, unsigned long crc); |
| |
| /* |
| ** dump the process of the file in the repository. The place where the log output is platform dependent. |
| ** @file_name: the file name to be dump. |
| */ |
| void dump_history_file(const char * file_name); |
| |
| int begin_transaction(void); |
| |
| int end_transaction(void); |
| |
| #ifdef __cplusplus |
| } |
| #endif |
| #endif |