Changeset bff8619 in mainline
- Timestamp:
- 2024-08-20T22:07:31Z (3 months ago)
- Branches:
- master
- Children:
- ac9b4f2
- Parents:
- a3ba37d
- Location:
- uspace
- Files:
-
- 3 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/meson.build
ra3ba37d rbff8619 34 34 'blkdump', 35 35 'calculator', 36 'contacts',37 36 'corecfg', 38 37 'cpptest', -
uspace/app/taskbar-cfg/smeedit.c
ra3ba37d rbff8619 403 403 404 404 startmenu_repaint(smee->startmenu); 405 (void)tbarcfg_sync(smee->startmenu->tbarcfg->tbarcfg); 405 406 (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT); 406 407 } else { … … 418 419 return; 419 420 420 (void) smenu_entry_save(smee->smentry->entry);421 (void)tbarcfg_sync(smee->startmenu->tbarcfg->tbarcfg); 421 422 startmenu_entry_update(smee->smentry); 423 (void)tbarcfg_sync(smee->startmenu->tbarcfg->tbarcfg); 422 424 (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT); 423 425 } -
uspace/app/taskbar-cfg/startmenu.c
ra3ba37d rbff8619 515 515 516 516 (void)smee; 517 (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg); 517 518 (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT); 518 519 } … … 534 535 (void)startmenu_insert(smenu, entry, &smentry); 535 536 (void)ui_control_paint(ui_list_ctl(smenu->entries_list)); 537 (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg); 536 538 (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT); 537 539 } … … 620 622 startmenu_t *smenu = (startmenu_t *)arg; 621 623 startmenu_entry_t *smentry; 622 errno_t rc;623 624 624 625 (void)pbutton; … … 628 629 return; 629 630 630 rc = smenu_entry_destroy(smentry->entry); 631 if (rc != EOK) 632 return; 633 631 smenu_entry_destroy(smentry->entry); 634 632 ui_list_entry_delete(smentry->lentry); 635 633 free(smentry); 634 636 635 (void)ui_control_paint(ui_list_ctl(smenu->entries_list)); 636 (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg); 637 637 (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT); 638 638 } … … 673 673 startmenu_t *smenu = (startmenu_t *)arg; 674 674 startmenu_entry_t *smentry; 675 errno_t rc;676 675 677 676 (void)pbutton; … … 681 680 return; 682 681 683 rc = smenu_entry_move_up(smentry->entry); 684 if (rc != EOK) 685 return; 686 682 smenu_entry_move_up(smentry->entry); 687 683 ui_list_entry_move_up(smentry->lentry); 688 684 689 685 (void)ui_control_paint(ui_list_ctl(smenu->entries_list)); 686 (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg); 690 687 (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT); 691 688 } … … 700 697 startmenu_t *smenu = (startmenu_t *)arg; 701 698 startmenu_entry_t *smentry; 702 errno_t rc;703 699 704 700 (void)pbutton; … … 708 704 return; 709 705 710 rc = smenu_entry_move_down(smentry->entry); 711 if (rc != EOK) 712 return; 713 706 smenu_entry_move_down(smentry->entry); 714 707 ui_list_entry_move_down(smentry->lentry); 715 708 716 709 (void)ui_control_paint(ui_list_ctl(smenu->entries_list)); 710 (void)tbarcfg_sync(smenu->tbarcfg->tbarcfg); 717 711 (void)tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT); 718 712 } -
uspace/lib/sif/include/sif.h
ra3ba37d rbff8619 1 1 /* 2 * Copyright (c) 20 18Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 42 42 struct sif_sess; 43 typedef struct sif_sess sif_sess_t; 44 45 struct sif_trans; 46 typedef struct sif_trans sif_trans_t; 43 typedef struct sif_sess sif_doc_t; 47 44 48 45 struct sif_node; 49 46 typedef struct sif_node sif_node_t; 50 47 51 errno_t sif_create(const char *, sif_sess_t **); 52 errno_t sif_open(const char *, sif_sess_t **); 53 errno_t sif_close(sif_sess_t *); 54 sif_node_t *sif_get_root(sif_sess_t *); 48 errno_t sif_new(sif_doc_t **); 49 errno_t sif_load(const char *, sif_doc_t **); 50 errno_t sif_save(sif_doc_t *, const char *); 51 void sif_delete(sif_doc_t *); 52 sif_node_t *sif_get_root(sif_doc_t *); 55 53 56 54 sif_node_t *sif_node_first_child(sif_node_t *); … … 59 57 const char *sif_node_get_attr(sif_node_t *, const char *); 60 58 61 errno_t sif_trans_begin(sif_sess_t *, sif_trans_t **); 62 void sif_trans_abort(sif_trans_t *); 63 errno_t sif_trans_end(sif_trans_t *); 64 65 errno_t sif_node_prepend_child(sif_trans_t *, sif_node_t *, const char *, 66 sif_node_t **); 67 errno_t sif_node_append_child(sif_trans_t *, sif_node_t *, const char *, 68 sif_node_t **); 69 errno_t sif_node_insert_before(sif_trans_t *, sif_node_t *, const char *, 70 sif_node_t **); 71 errno_t sif_node_insert_after(sif_trans_t *, sif_node_t *, const char *, 72 sif_node_t **); 73 void sif_node_destroy(sif_trans_t *, sif_node_t *); 74 errno_t sif_node_set_attr(sif_trans_t *, sif_node_t *, const char *, 59 errno_t sif_node_prepend_child(sif_node_t *, const char *, sif_node_t **); 60 errno_t sif_node_append_child(sif_node_t *, const char *, sif_node_t **); 61 errno_t sif_node_insert_before(sif_node_t *, const char *, sif_node_t **); 62 errno_t sif_node_insert_after(sif_node_t *, const char *, sif_node_t **); 63 void sif_node_destroy(sif_node_t *); 64 errno_t sif_node_set_attr(sif_node_t *, const char *, 75 65 const char *); 76 void sif_node_unset_attr(sif_ trans_t *, sif_node_t *, const char *);66 void sif_node_unset_attr(sif_node_t *, const char *); 77 67 78 68 #endif -
uspace/lib/sif/src/sif.c
ra3ba37d rbff8619 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 33 33 * 34 34 * Structured Information Format (SIF) is an API that allows an application 35 * to maintain data in a persistent repository in a format that 36 * 37 * - is structured (and hence extensible) 38 * - allows atomic (transactional) updates 39 * - allows efficient updates 35 * to maintain data in a persistent repository in a format that is 36 * structured (and hence extensible). 40 37 * 41 38 * SIF is meant to be used as the basis for the storage backend used to … … 44 41 * similar to an XML document that contains just tags with attributes 45 42 * (but no text). 46 *47 * SIF can thus naturally express ordered lists (unlike a relational database).48 * When contrasted to a (relational) database, SIF is much more primitive.49 *50 * In particular, SIF51 *52 * - does not run on a separate server53 * - des not handle concurrency54 * - does not have a notion of types or data validation55 * - does not understand relations56 * - does not implement any kind of search/queries57 * - does not deal with data sets large enough not to fit in primary memory58 *59 * any kind of structure data validation is left up to the application.60 43 */ 61 44 … … 172 155 } 173 156 174 /** Create and open a SIF repository. 175 * 176 * @param fname File name 177 * @param rsess Place to store pointer to new session. 157 /** Create SIF document. 158 * 159 * @param rdoc Place to store pointer to new document. 178 160 * 179 161 * @return EOK on success or error code 180 162 */ 181 errno_t sif_ create(const char *fname, sif_sess_t **rsess)182 { 183 sif_ sess_t *sess;163 errno_t sif_new(sif_doc_t **rdoc) 164 { 165 sif_doc_t *doc; 184 166 sif_node_t *root = NULL; 185 sif_trans_t *trans = NULL;186 167 errno_t rc; 187 FILE *f; 188 189 sess = calloc(1, sizeof(sif_sess_t)); 190 if (sess == NULL) 191 return ENOMEM; 192 193 sess->fname = str_dup(fname); 194 if (sess->fname == NULL) { 195 rc = ENOMEM; 196 goto error; 197 } 168 169 doc = calloc(1, sizeof(sif_doc_t)); 170 if (doc == NULL) 171 return ENOMEM; 198 172 199 173 root = sif_node_new(NULL); … … 209 183 } 210 184 211 f = fopen(fname, "wx"); 212 if (f == NULL) { 213 rc = EIO; 214 goto error; 215 } 216 217 sess->f = f; 218 sess->root = root; 219 220 /* Run a dummy trasaction to marshall initial repo state to file */ 221 rc = sif_trans_begin(sess, &trans); 222 if (rc != EOK) 223 goto error; 224 225 rc = sif_trans_end(trans); 226 if (rc != EOK) 227 goto error; 228 229 *rsess = sess; 185 doc->root = root; 186 187 *rdoc = doc; 230 188 return EOK; 231 189 error: 232 if (trans != NULL)233 sif_trans_abort(trans);234 190 sif_node_delete(root); 235 if (sess->fname != NULL) 236 free(sess->fname); 237 free(sess); 191 free(doc); 238 192 return rc; 239 193 } 240 194 241 /** Open an existing SIF repository.195 /** Load SIF document. 242 196 * 243 197 * @param fname File name 244 * @param r sess Place to store pointer to new session.198 * @param rdoc Place to store pointer to new document. 245 199 * 246 200 * @return EOK on success or error code 247 201 */ 248 errno_t sif_ open(const char *fname, sif_sess_t **rsess)249 { 250 sif_ sess_t *sess;202 errno_t sif_load(const char *fname, sif_doc_t **rdoc) 203 { 204 sif_doc_t *doc; 251 205 sif_node_t *root = NULL; 252 206 errno_t rc; 253 207 FILE *f; 254 208 255 sess = calloc(1, sizeof(sif_sess_t));256 if ( sess== NULL)257 return ENOMEM; 258 259 sess->fname = str_dup(fname);260 if ( sess->fname == NULL) {209 doc = calloc(1, sizeof(sif_doc_t)); 210 if (doc == NULL) 211 return ENOMEM; 212 213 doc->fname = str_dup(fname); 214 if (doc->fname == NULL) { 261 215 rc = ENOMEM; 262 216 goto error; … … 278 232 } 279 233 280 sess->root = root; 281 282 sess->f = f; 283 sess->root = root; 284 *rsess = sess; 234 doc->root = root; 235 *rdoc = doc; 285 236 return EOK; 286 237 error: 287 238 sif_node_delete(root); 288 if (sess->fname != NULL) 289 free(sess->fname); 290 free(sess); 239 free(doc); 291 240 return rc; 292 241 } 293 242 294 /** Close SIF session.295 * 296 * @param sess SIF session243 /** Delete SIF document. 244 * 245 * @param doc SIF document 297 246 * @return EOK on success or error code 298 247 */ 299 errno_t sif_close(sif_sess_t *sess) 300 { 301 sif_node_delete(sess->root); 302 303 if (fclose(sess->f) < 0) { 304 free(sess); 305 return EIO; 306 } 307 308 if (sess->fname != NULL) 309 free(sess->fname); 310 free(sess); 311 return EOK; 248 void sif_delete(sif_doc_t *doc) 249 { 250 sif_node_delete(doc->root); 251 free(doc); 312 252 } 313 253 314 254 /** Return root node. 315 255 * 316 * @param sess SIF session317 */ 318 sif_node_t *sif_get_root(sif_ sess_t *sess)319 { 320 return sess->root;256 * @param doc SIF document 257 */ 258 sif_node_t *sif_get_root(sif_doc_t *doc) 259 { 260 return doc->root; 321 261 } 322 262 … … 383 323 } 384 324 385 /** Begin SIF transaction. 386 * 387 * @param trans Transaction 325 /** Save SIF document to file. 326 * * 327 * @param doc SIF document 328 * @param fname File name 388 329 * @return EOK on success or error code 389 330 */ 390 errno_t sif_trans_begin(sif_sess_t *sess, sif_trans_t **rtrans) 391 { 392 sif_trans_t *trans; 393 394 trans = calloc(1, sizeof(sif_trans_t)); 395 if (trans == NULL) 396 return ENOMEM; 397 398 trans->sess = sess; 399 *rtrans = trans; 400 return EOK; 401 } 402 403 /** Commit SIF transaction. 404 * 405 * Commit and free the transaction. If an error is returned, that means 406 * the transaction has not been freed (and sif_trans_abort() must be used). 407 * 408 * @param trans Transaction 409 * @return EOK on success or error code 410 */ 411 errno_t sif_trans_end(sif_trans_t *trans) 412 { 331 errno_t sif_save(sif_doc_t *doc, const char *fname) 332 { 333 FILE *f = NULL; 413 334 errno_t rc; 414 335 415 (void) fclose(trans->sess->f);416 417 trans->sess->f = fopen(trans->sess->fname, "w");418 if (trans->sess->f == NULL)419 return EIO;420 421 rc = sif_export_node( trans->sess->root, trans->sess->f);336 f = fopen(fname, "w"); 337 if (f == NULL) { 338 rc = EIO; 339 goto error; 340 } 341 342 rc = sif_export_node(doc->root, f); 422 343 if (rc != EOK) 423 return rc; 424 425 if (fputc('\n', trans->sess->f) == EOF) 426 return EIO; 427 428 if (fflush(trans->sess->f) == EOF) 429 return EIO; 430 431 free(trans); 432 return EOK; 433 } 434 435 /** Abort SIF transaction. 436 * 437 * @param trans Transaction 438 */ 439 void sif_trans_abort(sif_trans_t *trans) 440 { 441 free(trans); 344 goto error; 345 346 if (fputc('\n', f) == EOF) { 347 rc = EIO; 348 goto error; 349 } 350 351 if (fflush(f) == EOF) { 352 rc = EIO; 353 goto error; 354 } 355 356 return EOK; 357 error: 358 if (f != NULL) 359 fclose(f); 360 return rc; 442 361 } 443 362 … … 447 366 * @a parent. 448 367 * 449 * @param trans Transaction450 368 * @param parent Parent node 451 369 * @param ctype Child type … … 454 372 * @return EOK on success or ENOMEM if out of memory 455 373 */ 456 errno_t sif_node_prepend_child(sif_ trans_t *trans, sif_node_t *parent,457 const char *ctype,sif_node_t **rchild)374 errno_t sif_node_prepend_child(sif_node_t *parent, const char *ctype, 375 sif_node_t **rchild) 458 376 { 459 377 sif_node_t *child; … … 479 397 * Create a new child and append it at the end of children list of @a parent. 480 398 * 481 * @param trans Transaction482 399 * @param parent Parent node 483 400 * @param ctype Child type … … 486 403 * @return EOK on success or ENOMEM if out of memory 487 404 */ 488 errno_t sif_node_append_child(sif_ trans_t *trans, sif_node_t *parent,489 const char *ctype,sif_node_t **rchild)405 errno_t sif_node_append_child(sif_node_t *parent, const char *ctype, 406 sif_node_t **rchild) 490 407 { 491 408 sif_node_t *child; … … 511 428 * Create a new child and insert it before an existing child. 512 429 * 513 * @param trans Transaction514 430 * @param sibling Sibling before which to insert 515 431 * @param ctype Child type … … 518 434 * @return EOK on success or ENOMEM if out of memory 519 435 */ 520 errno_t sif_node_insert_before(sif_ trans_t *trans, sif_node_t *sibling,521 const char *ctype,sif_node_t **rchild)436 errno_t sif_node_insert_before(sif_node_t *sibling, const char *ctype, 437 sif_node_t **rchild) 522 438 { 523 439 sif_node_t *child; … … 543 459 * Create a new child and insert it after an existing child. 544 460 * 545 * @param trans Transaction546 461 * @param sibling Sibling after which to insert 547 462 * @param ctype Child type … … 550 465 * @return EOK on success or ENOMEM if out of memory 551 466 */ 552 errno_t sif_node_insert_after(sif_ trans_t *trans, sif_node_t *sibling,553 const char *ctype,sif_node_t **rchild)467 errno_t sif_node_insert_after(sif_node_t *sibling, const char *ctype, 468 sif_node_t **rchild) 554 469 { 555 470 sif_node_t *child; … … 573 488 /** Destroy SIF node. 574 489 * 575 * This function does not return an error, but the transaction may still576 * fail to complete.577 *578 * @param trans Transaction579 490 * @param node Node to destroy 580 491 */ 581 void sif_node_destroy(sif_ trans_t *trans, sif_node_t *node)492 void sif_node_destroy(sif_node_t *node) 582 493 { 583 494 list_remove(&node->lparent); … … 587 498 /** Set node attribute. 588 499 * 589 * @param trans Transaction590 500 * @param node SIF node 591 501 * @param aname Attribute name … … 594 504 * @return EOK on success, ENOMEM if out of memory 595 505 */ 596 errno_t sif_node_set_attr(sif_ trans_t *trans, sif_node_t *node,597 const char *a name, const char *avalue)506 errno_t sif_node_set_attr(sif_node_t *node, const char *aname, 507 const char *avalue) 598 508 { 599 509 odlink_t *link; … … 636 546 /** Unset node attribute. 637 547 * 638 * This function does not return an error, but the transaction may still639 * fail to complete.640 *641 * @param trans Transaction642 548 * @param node Node 643 549 * @param aname Attribute name 644 550 */ 645 void sif_node_unset_attr(sif_trans_t *trans, sif_node_t *node, 646 const char *aname) 551 void sif_node_unset_attr(sif_node_t *node, const char *aname) 647 552 { 648 553 odlink_t *link; -
uspace/lib/sif/test/sif.c
ra3ba37d rbff8619 1 1 /* 2 * Copyright (c) 20 18Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 37 37 PCUT_TEST_SUITE(sif); 38 39 /** Test sif_ create. */38 #if 0 39 /** Test sif_new and sif_delete. */ 40 40 PCUT_TEST(sif_create) 41 41 { 42 sif_sess_t *sess; 43 errno_t rc; 44 int rv; 45 char *fname; 46 char *p; 47 48 fname = calloc(L_tmpnam, 1); 49 PCUT_ASSERT_NOT_NULL(fname); 50 51 p = tmpnam(fname); 52 PCUT_ASSERT_TRUE(p == fname); 53 54 rc = sif_create(fname, &sess); 55 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 56 57 rc = sif_close(sess); 58 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 59 60 rv = remove(fname); 61 PCUT_ASSERT_INT_EQUALS(0, rv); 62 } 63 64 /** Test sif_open. */ 65 PCUT_TEST(sif_open) 42 sif_doc_t *doc; 43 errno_t rc; 44 45 rc = sif_new(&doc); 46 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 47 48 sif_delete(doc); 49 } 50 51 /** Test sif_load. */ 52 PCUT_TEST(sif_load) 66 53 { 67 54 sif_sess_t *sess; … … 601 588 PCUT_ASSERT_INT_EQUALS(0, rv); 602 589 } 603 590 #endif 604 591 PCUT_EXPORT(sif); -
uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h
ra3ba37d rbff8619 47 47 extern errno_t tbarcfg_open(const char *, tbarcfg_t **); 48 48 extern void tbarcfg_close(tbarcfg_t *); 49 extern errno_t tbarcfg_sync(tbarcfg_t *); 49 50 extern smenu_entry_t *tbarcfg_smenu_first(tbarcfg_t *); 50 51 extern smenu_entry_t *tbarcfg_smenu_next(smenu_entry_t *); … … 58 59 extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *); 59 60 extern void smenu_entry_set_terminal(smenu_entry_t *, bool); 60 extern errno_t smenu_entry_save(smenu_entry_t *);61 61 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *, 62 62 bool, smenu_entry_t **); 63 63 extern errno_t smenu_entry_sep_create(tbarcfg_t *, smenu_entry_t **); 64 extern errno_tsmenu_entry_destroy(smenu_entry_t *);65 extern errno_tsmenu_entry_move_up(smenu_entry_t *);66 extern errno_tsmenu_entry_move_down(smenu_entry_t *);64 extern void smenu_entry_destroy(smenu_entry_t *); 65 extern void smenu_entry_move_up(smenu_entry_t *); 66 extern void smenu_entry_move_down(smenu_entry_t *); 67 67 extern errno_t tbarcfg_listener_create(const char *, void (*)(void *), 68 68 void *, tbarcfg_listener_t **); -
uspace/lib/tbarcfg/private/tbarcfg.h
ra3ba37d rbff8619 39 39 40 40 #include <adt/list.h> 41 #include <sif.h>42 41 #include <stdbool.h> 43 42 #include <types/tbarcfg/tbarcfg.h> … … 45 44 /** Taskbar configuration */ 46 45 struct tbarcfg { 47 /** Repository session*/48 sif_sess_t *repo;46 /** Configuration file path */ 47 char *cfgpath; 49 48 /** List of start menu entries (smenu_entry_t) */ 50 49 list_t entries; 51 /** Entries SIF node */52 sif_node_t *nentries;53 50 }; 54 51 … … 59 56 /** Link to @c smenu->entries */ 60 57 link_t lentries; 61 /** SIF node (persistent storage) */62 sif_node_t *nentry;63 58 /** Is this a separator entry */ 64 59 bool separator; … … 79 74 } tbarcfg_listener_t; 80 75 81 extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *,82 const char *, bool, smenu_entry_t **);83 extern errno_t smenu_entry_sep_new(tbarcfg_t *, sif_node_t *, smenu_entry_t **);84 extern void smenu_entry_delete(smenu_entry_t *);85 86 76 #endif 87 77 -
uspace/lib/tbarcfg/src/tbarcfg.c
ra3ba37d rbff8619 47 47 48 48 static void tbarcfg_notify_conn(ipc_call_t *, void *); 49 static errno_t smenu_entry_save(smenu_entry_t *, sif_node_t *); 49 50 50 51 /** Create taskbar configuration. … … 57 58 { 58 59 tbarcfg_t *tbcfg; 59 sif_ sess_t *repo= NULL;60 sif_doc_t *doc = NULL; 60 61 sif_node_t *rnode; 61 errno_t rc;62 sif_trans_t *trans = NULL;62 sif_node_t *nentries; 63 errno_t rc; 63 64 64 65 tbcfg = calloc(1, sizeof(tbarcfg_t)); … … 69 70 70 71 list_initialize(&tbcfg->entries); 71 72 rc = sif_create(repopath, &repo); 73 if (rc != EOK) 74 goto error; 75 76 tbcfg->repo = repo; 77 78 rnode = sif_get_root(repo); 79 80 rc = sif_trans_begin(repo, &trans); 81 if (rc != EOK) 82 goto error; 83 84 rc = sif_node_append_child(trans, rnode, "entries", &tbcfg->nentries); 85 if (rc != EOK) 86 goto error; 87 88 rc = sif_trans_end(trans); 89 if (rc != EOK) 90 goto error; 72 tbcfg->cfgpath = str_dup(repopath); 73 if (tbcfg->cfgpath == NULL) { 74 rc = ENOMEM; 75 goto error; 76 } 77 78 rc = sif_new(&doc); 79 if (rc != EOK) 80 goto error; 81 82 rnode = sif_get_root(doc); 83 84 rc = sif_node_append_child(rnode, "entries", &nentries); 85 if (rc != EOK) 86 goto error; 87 88 (void)nentries; 89 90 rc = sif_save(doc, repopath); 91 if (rc != EOK) 92 goto error; 93 94 sif_delete(doc); 91 95 92 96 *rtbcfg = tbcfg; 93 97 return EOK; 94 98 error: 95 if ( trans!= NULL)96 sif_ trans_abort(trans);97 if ( repo!= NULL)98 sif_close(repo);99 if (doc != NULL) 100 sif_delete(doc); 101 if (tbcfg != NULL && tbcfg->cfgpath != NULL) 102 free(tbcfg->cfgpath); 99 103 if (tbcfg != NULL) 100 104 free(tbcfg); … … 111 115 { 112 116 tbarcfg_t *tbcfg; 113 sif_sess_t *repo = NULL; 117 sif_doc_t *doc = NULL; 118 sif_node_t *nentries; 114 119 sif_node_t *rnode; 115 120 sif_node_t *nentry; … … 128 133 129 134 list_initialize(&tbcfg->entries); 130 131 rc = sif_open(repopath, &repo); 132 if (rc != EOK) 133 goto error; 134 135 tbcfg->repo = repo; 136 137 rnode = sif_get_root(repo); 138 tbcfg->nentries = sif_node_first_child(rnode); 139 ntype = sif_node_get_type(tbcfg->nentries); 135 tbcfg->cfgpath = str_dup(repopath); 136 if (tbcfg->cfgpath == NULL) { 137 rc = ENOMEM; 138 goto error; 139 } 140 141 rc = sif_load(repopath, &doc); 142 if (rc != EOK) 143 goto error; 144 145 rnode = sif_get_root(doc); 146 nentries = sif_node_first_child(rnode); 147 ntype = sif_node_get_type(nentries); 140 148 if (str_cmp(ntype, "entries") != 0) { 141 149 rc = EIO; … … 143 151 } 144 152 145 nentry = sif_node_first_child( tbcfg->nentries);153 nentry = sif_node_first_child(nentries); 146 154 while (nentry != NULL) { 147 155 ntype = sif_node_get_type(nentry); … … 174 182 terminal = "n"; 175 183 176 rc = smenu_entry_ new(tbcfg, nentry, caption, cmd,184 rc = smenu_entry_create(tbcfg, caption, cmd, 177 185 str_cmp(terminal, "y") == 0, NULL); 178 186 if (rc != EOK) 179 187 goto error; 180 188 } else { 181 rc = smenu_entry_sep_ new(tbcfg, nentry, NULL);189 rc = smenu_entry_sep_create(tbcfg, NULL); 182 190 if (rc != EOK) 183 191 goto error; … … 187 195 } 188 196 197 sif_delete(doc); 189 198 *rtbcfg = tbcfg; 190 199 return EOK; 191 200 error: 192 if (repo != NULL) 193 sif_close(repo); 201 if (doc != NULL) 202 sif_delete(doc); 203 if (tbcfg != NULL && tbcfg->cfgpath != NULL) 204 free(tbcfg->cfgpath); 194 205 if (tbcfg != NULL) 195 206 free(tbcfg); … … 207 218 entry = tbarcfg_smenu_first(tbcfg); 208 219 while (entry != NULL) { 209 smenu_entry_de lete(entry);220 smenu_entry_destroy(entry); 210 221 entry = tbarcfg_smenu_first(tbcfg); 211 222 } 212 223 213 (void)sif_close(tbcfg->repo);224 free(tbcfg->cfgpath); 214 225 free(tbcfg); 226 } 227 228 /** Synchronize taskbar configuration to config file. 229 * 230 * @param repopath Pathname of the menu repository 231 * @param rtbcfg Place to store pointer to taskbar configuration 232 * @return EOK on success or an error code 233 */ 234 errno_t tbarcfg_sync(tbarcfg_t *tbcfg) 235 { 236 sif_doc_t *doc = NULL; 237 sif_node_t *nentries; 238 sif_node_t *rnode; 239 smenu_entry_t *entry; 240 errno_t rc; 241 242 rc = sif_new(&doc); 243 if (rc != EOK) 244 goto error; 245 246 rnode = sif_get_root(doc); 247 248 rc = sif_node_append_child(rnode, "entries", &nentries); 249 if (rc != EOK) 250 goto error; 251 252 entry = tbarcfg_smenu_first(tbcfg); 253 while (entry != NULL) { 254 rc = smenu_entry_save(entry, nentries); 255 if (rc != EOK) 256 goto error; 257 258 entry = tbarcfg_smenu_next(entry); 259 } 260 261 rc = sif_save(doc, tbcfg->cfgpath); 262 if (rc != EOK) 263 goto error; 264 265 sif_delete(doc); 266 return EOK; 267 error: 268 if (doc != NULL) 269 sif_delete(doc); 270 if (tbcfg != NULL && tbcfg->cfgpath != NULL) 271 free(tbcfg->cfgpath); 272 if (tbcfg != NULL) 273 free(tbcfg); 274 return rc; 215 275 } 216 276 … … 325 385 * 326 386 * Note: To make the change visible to others and persistent, 327 * you must call @c smenu_entry_save()387 * you must call @c tbarcfg_sync() 328 388 * 329 389 * @param entry Start menu entry … … 349 409 * 350 410 * Note: To make the change visible to others and persistent, 351 * you must call @c smenu_entry_save()411 * you must call @c tbarcfg_sync() 352 412 * 353 413 * @param entry Start menu entry … … 373 433 * 374 434 * Note: To make the change visible to others and persistent, 375 * you must call @c smenu_entry_save()435 * you must call @c tbarcfg_sync() 376 436 * 377 437 * @param entry Start menu entry … … 387 447 * 388 448 * @param entry Start menu entry 389 * @param trans Transaction 390 */ 391 static errno_t smenu_entry_save_trans(smenu_entry_t *entry, sif_trans_t *trans) 392 { 393 errno_t rc; 449 * @param nentries Entries node 450 */ 451 static errno_t smenu_entry_save(smenu_entry_t *entry, sif_node_t *nentries) 452 { 453 sif_node_t *nentry = NULL; 454 errno_t rc; 455 456 rc = sif_node_append_child(nentries, "entry", &nentry); 457 if (rc != EOK) 458 goto error; 394 459 395 460 if (entry->separator) { 396 rc = sif_node_set_attr( trans, entry->nentry, "separator", "y");461 rc = sif_node_set_attr(nentry, "separator", "y"); 397 462 if (rc != EOK) 398 463 goto error; 399 464 } else { 400 sif_node_unset_attr(trans, entry->nentry, "separator"); 401 402 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 465 rc = sif_node_set_attr(nentry, "cmd", entry->cmd); 403 466 if (rc != EOK) 404 467 goto error; 405 468 406 rc = sif_node_set_attr( trans, entry->nentry, "caption",469 rc = sif_node_set_attr(nentry, "caption", 407 470 entry->caption); 408 471 if (rc != EOK) 409 472 goto error; 410 473 411 rc = sif_node_set_attr( trans, entry->nentry, "terminal",474 rc = sif_node_set_attr(nentry, "terminal", 412 475 entry->terminal ? "y" : "n"); 413 476 if (rc != EOK) … … 417 480 return EOK; 418 481 error: 482 if (nentry != NULL) 483 sif_node_destroy(nentry); 419 484 return rc; 420 485 } 421 486 422 /** Save any changes to start menu entry. 423 * 424 * @param entry Start menu entry 425 */ 426 errno_t smenu_entry_save(smenu_entry_t *entry) 427 { 428 sif_trans_t *trans = NULL; 429 errno_t rc; 430 431 rc = sif_trans_begin(entry->smenu->repo, &trans); 432 if (rc != EOK) 433 goto error; 434 435 rc = smenu_entry_save_trans(entry, trans); 436 if (rc != EOK) 437 goto error; 438 439 rc = sif_trans_end(trans); 440 if (rc != EOK) 441 goto error; 442 443 return EOK; 444 error: 445 if (trans != NULL) 446 sif_trans_abort(trans); 447 return rc; 448 } 449 450 /** Allocate a start menu entry and append it to the start menu (internal). 487 /** Create new start menu entry and append it to the start menu (internal). 451 488 * 452 489 * This only creates the entry in memory, but does not update the repository. 453 490 * 454 491 * @param smenu Start menu 455 * @param nentry Backing SIF node456 492 * @param caption Caption 457 493 * @param cmd Command to run … … 459 495 * @param rentry Place to store pointer to new entry or @c NULL 460 496 */ 461 errno_t smenu_entry_ new(tbarcfg_t *smenu, sif_node_t *nentry,462 const char *c aption, const char *cmd, bool terminal, smenu_entry_t **rentry)497 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption, 498 const char *cmd, bool terminal, smenu_entry_t **rentry) 463 499 { 464 500 smenu_entry_t *entry; … … 470 506 goto error; 471 507 } 472 473 entry->nentry = nentry;474 508 475 509 entry->caption = str_dup(caption); … … 504 538 } 505 539 506 /** Allocate astart menu separator entry and append it to the start menu540 /** Create new start menu separator entry and append it to the start menu 507 541 * (internal). 508 542 * … … 510 544 * 511 545 * @param smenu Start menu 512 * @param nentry Backing SIF node513 546 * @param rentry Place to store pointer to new entry or @c NULL 514 547 */ 515 errno_t smenu_entry_sep_new(tbarcfg_t *smenu, sif_node_t *nentry, 516 smenu_entry_t **rentry) 548 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry) 517 549 { 518 550 smenu_entry_t *entry; … … 525 557 } 526 558 527 entry->nentry = nentry;528 559 entry->separator = true; 529 560 … … 538 569 } 539 570 540 /** De letestart menu entry.571 /** Destroy start menu entry. 541 572 * 542 573 * This only deletes the entry from, but does not update the … … 545 576 * @param entry Start menu entry 546 577 */ 547 void smenu_entry_de lete(smenu_entry_t *entry)578 void smenu_entry_destroy(smenu_entry_t *entry) 548 579 { 549 580 list_remove(&entry->lentries); … … 555 586 } 556 587 557 /** Create new start menu entry.558 *559 * @param smenu Start menu560 * @param nentry Backing SIF node561 * @param caption Caption562 * @param cmd Command to run563 * @param terminal Start in terminal564 * @param rentry Place to store pointer to new entry or @c NULL565 */566 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,567 const char *cmd, bool terminal, smenu_entry_t **rentry)568 {569 sif_node_t *nentry;570 smenu_entry_t *entry;571 errno_t rc;572 sif_trans_t *trans = NULL;573 574 rc = sif_trans_begin(smenu->repo, &trans);575 if (rc != EOK)576 goto error;577 578 rc = sif_node_append_child(trans, smenu->nentries, "entry",579 &nentry);580 if (rc != EOK)581 goto error;582 583 rc = sif_node_set_attr(trans, nentry, "cmd", cmd);584 if (rc != EOK)585 goto error;586 587 rc = sif_node_set_attr(trans, nentry, "caption", caption);588 if (rc != EOK)589 goto error;590 591 rc = sif_node_set_attr(trans, nentry, "terminal", terminal ? "y" : "n");592 if (rc != EOK)593 goto error;594 595 rc = smenu_entry_new(smenu, nentry, caption, cmd, terminal, &entry);596 if (rc != EOK)597 goto error;598 599 rc = sif_trans_end(trans);600 if (rc != EOK)601 goto error;602 603 if (rentry != NULL)604 *rentry = entry;605 return EOK;606 error:607 if (trans != NULL)608 sif_trans_abort(trans);609 return rc;610 }611 612 /** Create new start menu separator entry.613 *614 * @param smenu Start menu615 * @param nentry Backing SIF node616 * @param rentry Place to store pointer to new entry or @c NULL617 */618 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry)619 {620 sif_node_t *nentry;621 smenu_entry_t *entry;622 errno_t rc;623 sif_trans_t *trans = NULL;624 625 rc = sif_trans_begin(smenu->repo, &trans);626 if (rc != EOK)627 goto error;628 629 rc = sif_node_append_child(trans, smenu->nentries, "entry",630 &nentry);631 if (rc != EOK)632 goto error;633 634 rc = sif_node_set_attr(trans, nentry, "separator", "y");635 if (rc != EOK)636 goto error;637 638 rc = smenu_entry_sep_new(smenu, nentry, &entry);639 if (rc != EOK)640 goto error;641 642 rc = sif_trans_end(trans);643 if (rc != EOK)644 goto error;645 646 if (rentry != NULL)647 *rentry = entry;648 return EOK;649 error:650 if (trans != NULL)651 sif_trans_abort(trans);652 return rc;653 }654 655 /** Destroy start menu entry.656 *657 * @param entry Start menu entry658 * @return EOK on success or an error code659 */660 errno_t smenu_entry_destroy(smenu_entry_t *entry)661 {662 errno_t rc;663 sif_trans_t *trans = NULL;664 665 rc = sif_trans_begin(entry->smenu->repo, &trans);666 if (rc != EOK)667 goto error;668 669 sif_node_destroy(trans, entry->nentry);670 671 rc = sif_trans_end(trans);672 if (rc != EOK)673 goto error;674 675 smenu_entry_delete(entry);676 return EOK;677 error:678 if (trans != NULL)679 sif_trans_abort(trans);680 return rc;681 }682 683 588 /** Move start menu entry up. 684 589 * 685 590 * @param entry Start menu entry 686 * @return EOK on success or an error code 687 */ 688 errno_t smenu_entry_move_up(smenu_entry_t *entry) 689 { 690 errno_t rc; 691 sif_trans_t *trans = NULL; 692 sif_node_t *nnode = NULL; 693 sif_node_t *old_node; 591 */ 592 void smenu_entry_move_up(smenu_entry_t *entry) 593 { 694 594 smenu_entry_t *prev; 695 696 rc = sif_trans_begin(entry->smenu->repo, &trans);697 if (rc != EOK)698 goto error;699 595 700 596 prev = tbarcfg_smenu_prev(entry); 701 597 if (prev == NULL) { 702 598 /* Entry is already at first position, nothing to do. */ 703 return EOK; 704 } 705 706 rc = sif_node_insert_before(trans, prev->nentry, "entry", &nnode); 707 if (rc != EOK) 708 goto error; 709 710 old_node = entry->nentry; 711 entry->nentry = nnode; 712 713 rc = smenu_entry_save_trans(entry, trans); 714 if (rc != EOK) { 715 entry->nentry = old_node; 716 goto error; 717 } 718 719 sif_node_destroy(trans, old_node); 720 721 rc = sif_trans_end(trans); 722 if (rc != EOK) { 723 entry->nentry = old_node; 724 goto error; 599 return; 725 600 } 726 601 727 602 list_remove(&entry->lentries); 728 603 list_insert_before(&entry->lentries, &prev->lentries); 729 return EOK;730 error:731 if (nnode != NULL)732 sif_node_destroy(trans, nnode);733 if (trans != NULL)734 sif_trans_abort(trans);735 return rc;736 604 } 737 605 … … 739 607 * 740 608 * @param entry Start menu entry 741 * @return EOK on success or an error code 742 */ 743 errno_t smenu_entry_move_down(smenu_entry_t *entry) 744 { 745 errno_t rc; 746 sif_trans_t *trans = NULL; 747 sif_node_t *nnode = NULL; 748 sif_node_t *old_node; 609 */ 610 void smenu_entry_move_down(smenu_entry_t *entry) 611 { 749 612 smenu_entry_t *next; 750 751 rc = sif_trans_begin(entry->smenu->repo, &trans);752 if (rc != EOK)753 goto error;754 613 755 614 next = tbarcfg_smenu_next(entry); 756 615 if (next == NULL) { 757 616 /* Entry is already at last position, nothing to do. */ 758 return EOK; 759 } 760 761 rc = sif_node_insert_after(trans, next->nentry, "entry", &nnode); 762 if (rc != EOK) 763 goto error; 764 765 old_node = entry->nentry; 766 entry->nentry = nnode; 767 768 rc = smenu_entry_save_trans(entry, trans); 769 if (rc != EOK) { 770 entry->nentry = old_node; 771 goto error; 772 } 773 774 sif_node_destroy(trans, old_node); 775 776 rc = sif_trans_end(trans); 777 if (rc != EOK) { 778 entry->nentry = old_node; 779 goto error; 617 return; 780 618 } 781 619 782 620 list_remove(&entry->lentries); 783 621 list_insert_after(&entry->lentries, &next->lentries); 784 return EOK;785 error:786 if (nnode != NULL)787 sif_node_destroy(trans, nnode);788 if (trans != NULL)789 sif_trans_abort(trans);790 return rc;791 622 } 792 623 -
uspace/lib/tbarcfg/test/tbarcfg.c
ra3ba37d rbff8619 57 57 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 58 58 59 tbarcfg_sync(tbcfg); 59 60 tbarcfg_close(tbcfg); 60 61 … … 170 171 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2)); 171 172 173 tbarcfg_sync(tbcfg); 172 174 tbarcfg_close(tbcfg); 173 175 … … 261 263 smenu_entry_set_terminal(e, true); 262 264 263 rc = smenu_entry_save(e);265 rc = tbarcfg_sync(tbcfg); 264 266 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 265 267 … … 272 274 PCUT_ASSERT_TRUE(terminal); 273 275 276 tbarcfg_sync(tbcfg); 274 277 tbarcfg_close(tbcfg); 275 278 … … 359 362 PCUT_ASSERT_EQUALS(e, f); 360 363 361 rc = smenu_entry_destroy(e); 362 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 364 smenu_entry_destroy(e); 363 365 364 366 f = tbarcfg_smenu_first(tbcfg); … … 400 402 /* Moving the first entry up should have no effect */ 401 403 402 rc = smenu_entry_move_up(e1); 403 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 404 smenu_entry_move_up(e1); 404 405 405 406 f = tbarcfg_smenu_first(tbcfg); … … 408 409 /* Moving the second entry up should move it to first position */ 409 410 410 rc = smenu_entry_move_up(e2); 411 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 411 smenu_entry_move_up(e2); 412 412 413 413 f = tbarcfg_smenu_first(tbcfg); … … 416 416 /* Moving the last entry up should move it to second position */ 417 417 418 rc = smenu_entry_move_up(e3); 419 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 418 smenu_entry_move_up(e3); 420 419 421 420 f = tbarcfg_smenu_first(tbcfg); … … 428 427 PCUT_ASSERT_EQUALS(e1, f); 429 428 429 tbarcfg_sync(tbcfg); 430 430 tbarcfg_close(tbcfg); 431 431 … … 496 496 /* Moving the last entry down should have no effect */ 497 497 498 rc = smenu_entry_move_down(e3); 499 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 smenu_entry_move_down(e3); 500 499 501 500 f = tbarcfg_smenu_last(tbcfg); … … 504 503 /* Moving the second entry down should move it to last position */ 505 504 506 rc = smenu_entry_move_down(e2); 507 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 505 smenu_entry_move_down(e2); 508 506 509 507 f = tbarcfg_smenu_last(tbcfg); … … 512 510 /* Moving the first entry down should move it to second position */ 513 511 514 rc = smenu_entry_move_down(e1); 515 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 512 smenu_entry_move_down(e1); 516 513 517 514 f = tbarcfg_smenu_last(tbcfg); … … 524 521 PCUT_ASSERT_EQUALS(e3, f); 525 522 523 tbarcfg_sync(tbcfg); 526 524 tbarcfg_close(tbcfg); 527 525 -
uspace/srv/volsrv/types/volume.h
ra3ba37d rbff8619 1 1 /* 2 * Copyright (c) 20 18Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 #include <refcount.h> 42 42 #include <fibril_synch.h> 43 #include <sif.h>44 43 45 44 /** Volume */ … … 57 56 /** Mount point */ 58 57 char *mountp; 59 /** SIF node for this volume */60 sif_node_t *nvolume;61 58 } vol_volume_t; 62 59 … … 67 64 /** Volumes (list of vol_volume_t) */ 68 65 list_t volumes; 69 /** Cconfiguration repo session */70 sif_sess_t *repo;71 /** Volumes SIF node */72 sif_node_t *nvolumes;73 66 /** Next ID */ 74 67 sysarg_t next_id; 68 /** Configuration file path */ 69 char *cfg_path; 75 70 } vol_volumes_t; 76 71 -
uspace/srv/volsrv/volume.c
ra3ba37d rbff8619 1 1 /* 2 * Copyright (c) 20 18Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 #include <fibril_synch.h> 49 49 #include <io/log.h> 50 #include <sif.h> 50 51 #include <stdbool.h> 51 52 #include <stdlib.h> … … 60 61 vol_volume_t **); 61 62 static errno_t vol_volumes_load(sif_node_t *, vol_volumes_t *); 63 static errno_t vol_volumes_save(vol_volumes_t *, sif_node_t *); 62 64 63 65 /** Allocate new volume structure. … … 113 115 { 114 116 vol_volumes_t *volumes; 115 sif_sess_t *repo = NULL; 116 sif_trans_t *trans = NULL; 117 sif_doc_t *doc = NULL; 117 118 sif_node_t *node; 119 sif_node_t *nvolumes; 118 120 const char *ntype; 119 121 errno_t rc; … … 123 125 return ENOMEM; 124 126 127 volumes->cfg_path = str_dup(cfg_path); 128 if (volumes->cfg_path == NULL) { 129 rc = ENOMEM; 130 goto error; 131 } 132 125 133 fibril_mutex_initialize(&volumes->lock); 126 134 list_initialize(&volumes->volumes); … … 128 136 129 137 /* Try opening existing repository */ 130 rc = sif_ open(cfg_path, &repo);138 rc = sif_load(cfg_path, &doc); 131 139 if (rc != EOK) { 132 140 /* Failed to open existing, create new repository */ 133 rc = sif_ create(cfg_path, &repo);141 rc = sif_new(&doc); 134 142 if (rc != EOK) 135 143 goto error; 136 144 137 rc = sif_trans_begin(repo, &trans); 145 /* Create 'volumes' node. */ 146 rc = sif_node_append_child(sif_get_root(doc), "volumes", 147 &nvolumes); 138 148 if (rc != EOK) 139 149 goto error; 140 150 141 /* Create 'volumes' node. */ 142 rc = sif_node_append_child(trans, sif_get_root(repo), 143 "volumes", &volumes->nvolumes); 151 rc = sif_save(doc, cfg_path); 144 152 if (rc != EOK) 145 153 goto error; 146 154 147 rc = sif_trans_end(trans); 148 if (rc != EOK) 149 goto error; 150 151 trans = NULL; 155 sif_delete(doc); 152 156 } else { 153 157 /* 154 * Opened existing repo. Find 'volumes' node, should be155 * the first child of the root node.158 * Loaded existing configuration. Find 'volumes' node, should 159 * be the first child of the root node. 156 160 */ 157 node = sif_node_first_child(sif_get_root( repo));161 node = sif_node_first_child(sif_get_root(doc)); 158 162 159 163 /* Verify it's the correct node type */ … … 167 171 if (rc != EOK) 168 172 goto error; 169 } 170 171 volumes->repo = repo; 173 174 sif_delete(doc); 175 } 176 172 177 *rvolumes = volumes; 173 174 178 return EOK; 175 179 error: 176 if ( trans!= NULL)177 sif_trans_abort(trans);178 if ( repo!= NULL)179 (void) sif_close(repo);180 if (doc != NULL) 181 (void) sif_delete(doc); 182 if (volumes != NULL && volumes->cfg_path != NULL) 183 free(volumes->cfg_path); 180 184 if (volumes != NULL) 181 185 free(volumes); 182 186 187 return rc; 188 } 189 190 /** Sync volume configuration to config file. 191 * 192 * @param volumes List of volumes 193 * @return EOK on success, ENOMEM if out of memory 194 */ 195 errno_t vol_volumes_sync(vol_volumes_t *volumes) 196 { 197 sif_doc_t *doc = NULL; 198 errno_t rc; 199 200 rc = sif_new(&doc); 201 if (rc != EOK) 202 goto error; 203 204 rc = vol_volumes_save(volumes, sif_get_root(doc)); 205 if (rc != EOK) 206 goto error; 207 208 rc = sif_save(doc, volumes->cfg_path); 209 if (rc != EOK) 210 goto error; 211 212 sif_delete(doc); 213 return EOK; 214 error: 215 if (doc != NULL) 216 (void) sif_delete(doc); 183 217 return rc; 184 218 } … … 206 240 } 207 241 208 (void) sif_close(volumes->repo);242 free(volumes->cfg_path); 209 243 free(volumes); 210 244 } … … 383 417 char *mp; 384 418 char *old_mp; 385 errno_t rc; 386 sif_trans_t *trans = NULL; 387 sif_node_t *nvolume; 419 bool was_persist; 388 420 389 421 mp = str_dup(mountp); … … 391 423 return ENOMEM; 392 424 425 was_persist = vol_volume_is_persist(volume); 426 393 427 old_mp = volume->mountp; 394 428 volume->mountp = mp; 395 429 396 430 if (vol_volume_is_persist(volume)) { 397 /* Volume is now persistent */ 398 if (volume->nvolume == NULL) { 399 /* Prevent volume from being freed */ 431 if (!was_persist) { 432 /* 433 * Volume is now persistent. Prevent it from being 434 * freed. 435 */ 400 436 refcount_up(&volume->refcnt); 401 402 /* Create volume node */ 403 rc = sif_trans_begin(volume->volumes->repo, &trans); 404 if (rc != EOK) 405 goto error; 406 407 rc = sif_node_append_child(trans, 408 volume->volumes->nvolumes, "volume", &nvolume); 409 if (rc != EOK) 410 goto error; 411 412 rc = sif_node_set_attr(trans, nvolume, "label", 413 volume->label); 414 if (rc != EOK) 415 goto error; 416 417 rc = sif_node_set_attr(trans, nvolume, "mountp", 418 volume->mountp); 419 if (rc != EOK) 420 goto error; 421 422 rc = sif_trans_end(trans); 423 if (rc != EOK) 424 goto error; 425 426 trans = NULL; 427 volume->nvolume = nvolume; 428 } else { 429 /* Allow volume to be freed */ 437 } 438 } else { 439 if (was_persist) { 440 /* 441 * Volume is now non-persistent 442 * Allow volume to be freed. 443 */ 430 444 vol_volume_del_ref(volume); 431 432 /* Update volume node */ 433 rc = sif_trans_begin(volume->volumes->repo, &trans); 434 if (rc != EOK) 435 goto error; 436 437 rc = sif_node_set_attr(trans, volume->nvolume, 438 "mountp", volume->mountp); 439 if (rc != EOK) 440 goto error; 441 442 rc = sif_trans_end(trans); 443 if (rc != EOK) 444 goto error; 445 446 trans = NULL; 447 } 448 } else { 449 /* Volume is now non-persistent */ 450 if (volume->nvolume != NULL) { 451 /* Delete volume node */ 452 rc = sif_trans_begin(volume->volumes->repo, &trans); 453 if (rc != EOK) 454 goto error; 455 456 sif_node_destroy(trans, volume->nvolume); 457 458 rc = sif_trans_end(trans); 459 if (rc != EOK) 460 goto error; 461 462 volume->nvolume = NULL; 463 } 464 } 465 445 } 446 } 447 448 vol_volumes_sync(volume->volumes); 466 449 free(old_mp); 467 450 return EOK; 468 error:469 free(mp);470 volume->mountp = old_mp;471 472 if (trans != NULL)473 sif_trans_abort(trans);474 return rc;475 451 } 476 452 … … 521 497 } 522 498 523 /** Load volumes from SIF repository.499 /** Load volumes from SIF document. 524 500 * 525 501 * @param nvolumes Volumes node … … 536 512 errno_t rc; 537 513 538 volumes->nvolumes = nvolumes;539 540 514 nvolume = sif_node_first_child(nvolumes); 541 515 while (nvolume != NULL) { … … 565 539 volume->mountp = str_dup(mountp); 566 540 567 volume->nvolume = nvolume;568 541 fibril_mutex_lock(&volumes->lock); 569 542 vol_volume_add_locked(volumes, volume); … … 579 552 } 580 553 554 /** Save volumes to SIF document. 555 * 556 * @param volumes List of volumes 557 * @param rnode Configuration root node 558 * @return EOK on success, ENOMEM if out of memory 559 */ 560 errno_t vol_volumes_save(vol_volumes_t *volumes, sif_node_t *rnode) 561 { 562 sif_node_t *nvolumes; 563 sif_node_t *node; 564 link_t *link; 565 vol_volume_t *volume; 566 errno_t rc; 567 568 /* Create 'volumes' node. */ 569 rc = sif_node_append_child(rnode, "volumes", &nvolumes); 570 if (rc != EOK) 571 goto error; 572 573 link = list_first(&volumes->volumes); 574 while (link != NULL) { 575 volume = list_get_instance(link, vol_volume_t, lvolumes); 576 577 if (vol_volume_is_persist(volume)) { 578 /* Create 'volume' node. */ 579 rc = sif_node_append_child(rnode, "volume", &node); 580 if (rc != EOK) 581 goto error; 582 583 rc = sif_node_set_attr(node, "label", volume->label); 584 if (rc != EOK) 585 goto error; 586 587 rc = sif_node_set_attr(node, "mountp", volume->mountp); 588 if (rc != EOK) 589 goto error; 590 } 591 592 link = list_next(&volume->lvolumes, &volumes->volumes); 593 } 594 595 return EOK; 596 error: 597 return rc; 598 } 599 581 600 /** Get volume information. 582 601 * -
uspace/srv/volsrv/volume.h
ra3ba37d rbff8619 1 1 /* 2 * Copyright (c) 20 18Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 43 43 extern errno_t vol_volumes_create(const char *, vol_volumes_t **); 44 extern errno_t vol_volumes_sync(vol_volumes_t *); 44 45 extern void vol_volumes_destroy(vol_volumes_t *); 45 46 extern errno_t vol_volume_lookup_ref(vol_volumes_t *, const char *,
Note:
See TracChangeset
for help on using the changeset viewer.