declaration of variables which supports connection to database | |
char * | server = "localhost" |
char * | user = "mysqlfs" |
char * | password = "mysqlfs" |
char * | database = "mysqlfs" |
declaration of functions for connect and close database | |
MYSQL * | fsd_db_connect (char *server, char *user, char *password, char *database) |
Connect to database. | |
void | fsd_db_close (MYSQL *conn) |
Close connection to database. | |
declaration of functions for filesystem to use database | |
int | fsd_test (MYSQL *conn) |
Test database connection. | |
int | fsd_create (MYSQL *conn, char *dir, char *filename, char *return_text) |
Create new empty file. | |
int | fsd_mkdir (MYSQL *conn, char *dir, char *dirname, char *return_text) |
Create new directory. | |
int | fsd_clear_file (MYSQL *conn, char *file, char *return_text) |
Clear file. | |
int | fsd_add_block (MYSQL *conn, char *file, int block_size, char *block, char *return_text) |
Add block to file. | |
int | fsd_remove_file (MYSQL *conn, char *file, char *return_text) |
Remove file. | |
int | fsd_remove_dir (MYSQL *conn, char *dir, char *return_text) |
Remove dir. | |
int | fsd_get_block (MYSQL *conn, char *file, char *offset, int *block_size, char *block, char *return_text) |
Get block of file. | |
int | fsd_lookup (MYSQL *conn, char *dir, char *name, char *return_text) |
Lookup for file or directory defined by name. | |
int | fsd_read_inode (MYSQL *conn, char *inode_nr, char *return_text) |
Used for super read inode. Returns information about inode. | |
int | fsd_read_dir (MYSQL *conn, char *dir, rd_item **rd_list, char *return_text) |
Read files and directories in directory. | |
int | fsd_file_info (MYSQL *conn, char *file, char *return_text) |
Return file info - file size. | |
int | fsd_dir_info (MYSQL *conn, char *dir, char *return_text) |
Return dir info - count of items. | |
int | fsd_replace_block (MYSQL *conn, char *file, char *offset, int block_size, char *block, char *return_text) |
Replace block of file. | |
int | fsd_move_file (MYSQL *conn, char *file, char *dir, char *return_text) |
Move file. | |
int | fsd_rename_file (MYSQL *conn, char *file, char *name, char *return_text) |
Rename file. | |
int | fsd_rename_dir (MYSQL *conn, char *dir, char *name, char *return_text) |
Rename directory. | |
int | fsd_truncate_file (MYSQL *conn, char *file, char *new_file_size, char *return_text) |
Truncate file. | |
Defines | |
#define | UNLOCK_TABLES() |
#define | FSD_MYSQL_QUERY(qtext, args...) |
#define | FSD_MYSQL_QUERY_SMPL(qtext, args...) |
Functions | |
int | fsd_dir_exists (MYSQL *conn, char *dir) |
Determine that directory id exists in db. | |
int | fsd_file_exists (MYSQL *conn, char *file) |
Determine that file id exists in db. | |
int | fsd_dir_name_exists (MYSQL *conn, char *dir, char *dirname) |
Determine that directory name exists in parent directory. | |
int | fsd_file_name_exists (MYSQL *conn, char *dir, char *filename) |
Determine that file name exists in parent directory. |
This file contents declaration of functions which established and close connection to database. And function which execute commands that interacts with database.
#define FSD_MYSQL_QUERY | ( | qtext, | |||
args... | ) |
Value:
snprintf(query, sizeof(query), qtext, ## args); \ if (mysql_query(conn, query)) { \ fprintf(stderr, "%s\n", mysql_error(conn)); \ strcpy(return_text, "ER DB_ERROR"); \ return EDB_ERROR; \ }
Definition at line 34 of file fsd_mysql.c.
Referenced by fsd_add_block(), fsd_clear_file(), fsd_create(), fsd_dir_info(), fsd_file_info(), fsd_get_block(), fsd_lookup(), fsd_mkdir(), fsd_move_file(), fsd_read_dir(), fsd_read_inode(), fsd_remove_dir(), fsd_remove_file(), fsd_rename_dir(), fsd_rename_file(), fsd_replace_block(), and fsd_truncate_file().
#define FSD_MYSQL_QUERY_SMPL | ( | qtext, | |||
args... | ) |
Value:
snprintf(query, sizeof(query), qtext, ## args); \ if (mysql_query(conn, query)) { \ fprintf(stderr, "%s\n", mysql_error(conn)); \ return EDB_ERROR; \ }
Definition at line 43 of file fsd_mysql.c.
Referenced by fsd_dir_exists(), fsd_dir_name_exists(), fsd_file_exists(), and fsd_file_name_exists().
#define UNLOCK_TABLES | ( | ) |
Value:
if (mysql_query(conn, "UNLOCK TABLES")) { \ fprintf(stderr, "%s\n", mysql_error(conn)); \ strcpy(return_text, "ER DB_ERROR"); \ return EDB_ERROR; \ }
Definition at line 26 of file fsd_mysql.c.
Referenced by fsd_add_block(), fsd_clear_file(), fsd_create(), fsd_dir_info(), fsd_file_info(), fsd_get_block(), fsd_lookup(), fsd_mkdir(), fsd_move_file(), fsd_read_dir(), fsd_read_inode(), fsd_remove_dir(), fsd_remove_file(), fsd_rename_dir(), fsd_rename_file(), fsd_replace_block(), and fsd_truncate_file().
int fsd_add_block | ( | MYSQL * | conn, | |
char * | file, | |||
int | block_size, | |||
char * | block, | |||
char * | return_text | |||
) |
Add block to file.
This function add new block to the end of file. If passed file doesnt exists it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
file | File id. | |
block_size | Size of new block. | |
block | Block of data. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 556 of file fsd_mysql.c.
References EDB_ERROR, EFILE_NOT_EXISTS, fsd_file_exists(), FSD_MYSQL_QUERY, MAX_BLOCK_LENGTH, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_clear_file | ( | MYSQL * | conn, | |
char * | file, | |||
char * | return_text | |||
) |
Clear file.
This function remove all blocks from file. If passed file doesnt exists it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
file | File id. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 507 of file fsd_mysql.c.
References EDB_ERROR, EFILE_NOT_EXISTS, fsd_file_exists(), FSD_MYSQL_QUERY, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_create | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | filename, | |||
char * | return_text | |||
) |
Create new empty file.
This function create new empty file and return its id. If passed parent directory doesnt exists, or passed name exists in directory it returns error. Error value is returned also if there is problem with connection to database. Return_text must be allocated.
conn | MySQL handler. | |
dir | Parent directory id. | |
filename | File name. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 299 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NAME_NOT_EXISTS, EDIR_NOT_EXISTS, EFILE_NAME_NOT_EXISTS, ENAME_EXISTS, fsd_dir_exists(), fsd_dir_name_exists(), fsd_file_name_exists(), FSD_MYSQL_QUERY, MAX_NAME_LENGTH, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
void fsd_db_close | ( | MYSQL * | conn | ) |
Close connection to database.
This function close connection to database, that handler is passed in parameter.
conn | Pointer to MySQL handler. |
Definition at line 87 of file fsd_mysql.c.
Referenced by exit_deamon().
MYSQL * fsd_db_connect | ( | char * | server, | |
char * | user, | |||
char * | password, | |||
char * | database | |||
) |
Connect to database.
This function established connection to database described in parameters.
server | Name of a server. | |
user | User name to database server. | |
password | Password to database server. | |
database | Name of a database. |
Definition at line 62 of file fsd_mysql.c.
References conn.
Referenced by main().
int fsd_dir_exists | ( | MYSQL * | conn, | |
char * | dir | |||
) |
Determine that directory id exists in db.
This function determine that id exists in table dirs. It try to find out it. If it isnt found function return EDIR_NOT_EXISTS. If it is return value is OK. If some error occurs EDB_ERROR is return value.
conn | MySQL handler. | |
dir | Directory id. |
OK - dir exists.
EDB_ERROR - error.
Definition at line 133 of file fsd_mysql.c.
References EDIR_NOT_EXISTS, FSD_MYSQL_QUERY_SMPL, MAX_QUERY_LENGTH, OK, and query().
Referenced by fsd_create(), fsd_dir_info(), fsd_lookup(), fsd_mkdir(), fsd_move_file(), fsd_read_dir(), fsd_read_inode(), fsd_remove_dir(), and fsd_rename_dir().
int fsd_dir_info | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | return_text | |||
) |
Return dir info - count of items.
This function returns information about directory. The only info at this time is count of items in directory.
conn | MySQL handler. | |
dir | Dir id. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 1316 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NOT_EXISTS, fsd_dir_exists(), FSD_MYSQL_QUERY, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_dir_name_exists | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | dirname | |||
) |
Determine that directory name exists in parent directory.
This function determine that directory name exists in parent directory. It ask db, if there exists directory with passed name and parent dir id. If it isnt found function return EDIR_NAME_NOT_EXISTS. If it is return value is dir id. If some error occurs EDB_ERROR is return value.
conn | MySQL handler. | |
dir | Parent directory id. | |
dirname | Directory name. |
Dir_id - dir name exists.
EDB_ERROR - error.
Definition at line 209 of file fsd_mysql.c.
References EDIR_NAME_NOT_EXISTS, FSD_MYSQL_QUERY_SMPL, MAX_NAME_LENGTH, MAX_QUERY_LENGTH, and query().
Referenced by fsd_create(), fsd_lookup(), fsd_mkdir(), fsd_rename_dir(), and fsd_rename_file().
int fsd_file_exists | ( | MYSQL * | conn, | |
char * | file | |||
) |
Determine that file id exists in db.
This function determine that id exists in table files. It try to find out it. If it isnt found function return EFILE_NOT_EXISTS. If it is return value is OK. If some error occurs EDB_ERROR is return value.
conn | MySQL handler. | |
file | File id. |
OK - file exists.
EDB_ERROR - error.
Definition at line 170 of file fsd_mysql.c.
References EFILE_NOT_EXISTS, FSD_MYSQL_QUERY_SMPL, MAX_QUERY_LENGTH, OK, and query().
Referenced by fsd_add_block(), fsd_clear_file(), fsd_file_info(), fsd_get_block(), fsd_move_file(), fsd_read_inode(), fsd_remove_file(), fsd_rename_file(), fsd_replace_block(), and fsd_truncate_file().
int fsd_file_info | ( | MYSQL * | conn, | |
char * | file, | |||
char * | return_text | |||
) |
Return file info - file size.
This function returns information about file.
conn | MySQL handler. | |
file | File id. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 1244 of file fsd_mysql.c.
References EDB_ERROR, EFILE_NOT_EXISTS, fsd_file_exists(), FSD_MYSQL_QUERY, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_file_name_exists | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | filename | |||
) |
Determine that file name exists in parent directory.
This function determine that file name exists in directory. It ask db, if there exists file with passed filename and parent dir id. If it isnt found function return EFILE_NAME_NOT_EXISTS. If it is return value is file id. If some error occurs EDB_ERROR is return value.
conn | MySQL handler. | |
dir | Parent directory id. | |
filename | File name. |
File_id - file exists.
EDB_ERROR - error.
Definition at line 254 of file fsd_mysql.c.
References EFILE_NAME_NOT_EXISTS, FSD_MYSQL_QUERY_SMPL, MAX_NAME_LENGTH, MAX_QUERY_LENGTH, and query().
Referenced by fsd_create(), fsd_lookup(), fsd_mkdir(), fsd_rename_dir(), and fsd_rename_file().
int fsd_get_block | ( | MYSQL * | conn, | |
char * | file, | |||
char * | offset, | |||
int * | block_size, | |||
char * | block, | |||
char * | return_text | |||
) |
Get block of file.
This function return block of file defined by offset. If passed file or block doesnt exists it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
file | File id. | |
offset | Block offset. | |
block_size | Size of returned block. | |
block | Returned block of data. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 769 of file fsd_mysql.c.
References EBLOCK_NOT_EXISTS, EDB_ERROR, EFILE_NOT_EXISTS, fsd_file_exists(), FSD_MYSQL_QUERY, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_lookup | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | name, | |||
char * | return_text | |||
) |
Lookup for file or directory defined by name.
This function determine if there is file or directory in passed parent directory with passed name. If passed directory doesnt exists it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
dir | Dir id. | |
name | Lookuped name. | |
return_text | Buffer for return string. |
IS_FILE file_id - there exists file with passed name.
IS_DIR dir_id - there exists directory with passed name.
Error constanttant.
Definition at line 840 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NAME_NOT_EXISTS, EDIR_NOT_EXISTS, EFILE_NAME_NOT_EXISTS, ENAME_NOT_EXISTS, fsd_dir_exists(), fsd_dir_name_exists(), fsd_file_name_exists(), FSD_MYSQL_QUERY, IS_DIR, IS_FILE, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_mkdir | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | dirname, | |||
char * | return_text | |||
) |
Create new directory.
This function create new directory and return its id. If passed parent directory doesnt exists, or passed name exists in directory it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
dir | Parent directory id. | |
dirname | Dir name. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 404 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NAME_NOT_EXISTS, EDIR_NOT_EXISTS, EFILE_NAME_NOT_EXISTS, ENAME_EXISTS, fsd_dir_exists(), fsd_dir_name_exists(), fsd_file_name_exists(), FSD_MYSQL_QUERY, MAX_NAME_LENGTH, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_move_file | ( | MYSQL * | conn, | |
char * | file, | |||
char * | dir, | |||
char * | return_text | |||
) |
Move file.
Move file to directory defined in parameter dir. The file could be directory also.
conn | MySQL handler. | |
file | File id. | |
dir | New parent dir id. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 1504 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NOT_EXISTS, EFILE_NOT_EXISTS, EPARENT_NOT_EXISTS, fsd_dir_exists(), fsd_file_exists(), FSD_MYSQL_QUERY, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_read_dir | ( | MYSQL * | conn, | |
char * | dir, | |||
rd_item ** | rd_list, | |||
char * | return_text | |||
) |
Read files and directories in directory.
This function return all files and directory which have passed dir_id as parent dir id. If passed directory doesnt exists it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
dir | File id. | |
rd_list | List of dir items. | |
return_text | Buffer for return string. |
DIR_NOT_EXISTS - directory doesnt exists.
Error constant.
Definition at line 1142 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NOT_EXISTS, fsd_dir_exists(), FSD_MYSQL_QUERY, read_dir_item::id, MAX_QUERY_LENGTH, read_dir_item::name, read_dir_item::next, OK, query(), read_dir_item::type, and UNLOCK_TABLES.
Referenced by main().
int fsd_read_inode | ( | MYSQL * | conn, | |
char * | inode_nr, | |||
char * | return_text | |||
) |
Used for super read inode. Returns information about inode.
This function return information about inode (satisfies super_read)inode_operation) Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
inode_nr | Id of inode. | |
return_text | Buffer for return string. |
IS_FILE - there exists file with passed name.
IS_DIR - there exists directory with passed name.
OK -on command succesfully done, but error ocured on unlocking tables.
Definition at line 1000 of file fsd_mysql.c.
References EDB_ERROR, EINODE_NOT_EXISTS, fsd_dir_exists(), fsd_file_exists(), FSD_MYSQL_QUERY, IS_DIR, IS_FILE, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_remove_dir | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | return_text | |||
) |
Remove dir.
This function remove dir from db. An error is returned when dir is not empty. If passed dir doesnt exists it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
dir | Dir id. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 681 of file fsd_mysql.c.
References EDB_ERROR, EDIR_IS_NOT_EMPTY, EDIR_NOT_EXISTS, fsd_dir_exists(), FSD_MYSQL_QUERY, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_remove_file | ( | MYSQL * | conn, | |
char * | file, | |||
char * | return_text | |||
) |
Remove file.
This function remove all blocks from file and remove file from db. If passed file doesnt exists it returns error. Error value is returned also if there is problem with connection to database.
conn | MySQL handler. | |
file | File id. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 629 of file fsd_mysql.c.
References EDB_ERROR, EFILE_NOT_EXISTS, fsd_file_exists(), FSD_MYSQL_QUERY, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_rename_dir | ( | MYSQL * | conn, | |
char * | dir, | |||
char * | name, | |||
char * | return_text | |||
) |
Rename directory.
Rename directory to name defined in parameter name. It must checked if name is allready in directory.
conn | MySQL handler. | |
dir | Dir id. | |
name | New file name. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 1681 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NAME_NOT_EXISTS, EFILE_NAME_NOT_EXISTS, EFILE_NOT_EXISTS, ENAME_EXISTS, fsd_dir_exists(), fsd_dir_name_exists(), fsd_file_name_exists(), FSD_MYSQL_QUERY, MAX_NAME_LENGTH, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_rename_file | ( | MYSQL * | conn, | |
char * | file, | |||
char * | name, | |||
char * | return_text | |||
) |
Rename file.
Rename file to name defined in parameter name. It must checked if name is allready in directory.
conn | MySQL handler. | |
file | File id. | |
name | New file name. | |
return_text | Buffer for return string. |
Error constant.
Definition at line 1581 of file fsd_mysql.c.
References EDB_ERROR, EDIR_NAME_NOT_EXISTS, EFILE_NAME_NOT_EXISTS, EFILE_NOT_EXISTS, ENAME_EXISTS, fsd_dir_name_exists(), fsd_file_exists(), fsd_file_name_exists(), FSD_MYSQL_QUERY, MAX_ID_LENGTH, MAX_NAME_LENGTH, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_replace_block | ( | MYSQL * | conn, | |
char * | file, | |||
char * | offset, | |||
int | block_size, | |||
char * | block, | |||
char * | return_text | |||
) |
Replace block of file.
This function replace block of file defined in parametr offset. It updates data in data table.
conn | MySQL handler. | |
file | Dir id. | |
offset | Block offset. | |
block_size | New block size. | |
return_text | Buffer for return string. | |
block | Block data. |
Error constant.
Definition at line 1404 of file fsd_mysql.c.
References EBLOCK_NOT_EXISTS, EDB_ERROR, EFILE_NOT_EXISTS, fsd_file_exists(), FSD_MYSQL_QUERY, MAX_BLOCK_LENGTH, MAX_ID_LENGTH, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().
int fsd_test | ( | MYSQL * | conn | ) |
Test database connection.
This function tests database connection. Is used when FS is mounted to determine that database is running and is reachable. Sends query for id = 1 from directories. Query return string is ignored.
conn | MySQL handler. |
Definition at line 103 of file fsd_mysql.c.
References EDB_ERROR, OK, and PDEBUG.
Referenced by main().
int fsd_truncate_file | ( | MYSQL * | conn, | |
char * | file, | |||
char * | new_file_size, | |||
char * | return_text | |||
) |
Truncate file.
This function truncates file. It cut file or write 0 to the end of file.
conn | MySQL handler. | |
file | File id. | |
new_file_size | Size of new file. | |
return_text | Buffer for return string. |
Error name.
Definition at line 1780 of file fsd_mysql.c.
References EDB_ERROR, EFILE_NOT_EXISTS, fsd_file_exists(), FSD_MYSQL_QUERY, MAX_BLOCK_LENGTH, MAX_ID_LENGTH, MAX_QUERY_LENGTH, OK, query(), and UNLOCK_TABLES.
Referenced by main().