libufs.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2002 Juli Mallett. All rights reserved.
  3. *
  4. * This software was written by Juli Mallett <jmallett@FreeBSD.org> for the
  5. * FreeBSD project. Redistribution and use in source and binary forms, with
  6. * or without modification, are permitted provided that the following
  7. * conditions are met:
  8. *
  9. * 1. Redistribution of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * 2. Redistribution in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  19. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * $FreeBSD$
  28. */
  29. /*
  30. * libufs structures.
  31. */
  32. /*
  33. * userland ufs disk.
  34. */
  35. typedef struct Uufsd {
  36. const char *d_name; /* disk name */
  37. int d_ufs; /* decimal UFS version */
  38. int d_fd; /* raw device file descriptor */
  39. long d_bsize; /* device bsize */
  40. ufs2_daddr_t d_sblock; /* superblock location */
  41. struct csum *d_sbcsum; /* Superblock summary info */
  42. caddr_t d_inoblock; /* inode block */
  43. ino_t d_inomin; /* low inode */
  44. ino_t d_inomax; /* high inode */
  45. union {
  46. Fs d_fs; /* filesystem information */
  47. char d_sb[MAXBSIZE];
  48. /* superblock as buffer */
  49. } d_sbunion;
  50. union {
  51. Cg d_cg; /* cylinder group */
  52. char d_buf[MAXBSIZE];
  53. /* cylinder group storage */
  54. } d_cgunion;
  55. int d_ccg; /* current cylinder group */
  56. int d_lcg; /* last cylinder group (in d_cg) */
  57. const char *d_error; /* human readable disk error */
  58. int d_mine; /* internal flags */
  59. #define d_fs d_sbunion.d_fs
  60. #define d_sb d_sbunion.d_sb
  61. #define d_cg d_cgunion.d_cg
  62. } Uufsd;
  63. /*
  64. * libufs prototypes.
  65. */
  66. /*
  67. * block.c
  68. */
  69. int32_t bread(Uufsd *, ufs2_daddr_t, void *, size_t);
  70. int32_t bwrite(Uufsd *, ufs2_daddr_t, const void *, size_t);
  71. int berase(Uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size);
  72. void libufserror(Uufsd *u, const char *str);
  73. /*
  74. * cgroup.c
  75. */
  76. ufs2_daddr_t cgballoc(Uufsd *);
  77. int cgbfree(Uufsd *, ufs2_daddr_t, long);
  78. ino_t cgialloc(Uufsd *);
  79. int cgread(Uufsd *);
  80. int cgread1(Uufsd *, int);
  81. int cgwrite(Uufsd *);
  82. int cgwrite1(Uufsd *, int);
  83. /*
  84. * inode.c
  85. */
  86. int getino(Uufsd *, void **, ino_t, int *);
  87. int putino(Uufsd *);
  88. /*
  89. * sblock.c
  90. */
  91. int sbread(Uufsd *);
  92. int sbwrite(Uufsd *, int);
  93. /*
  94. * type.c
  95. */
  96. int ufs_disk_close(Uufsd *);
  97. int ufs_disk_create(Uufsd *);
  98. int ufs_disk_write(Uufsd *);
  99. /*
  100. * libufs_subr.c
  101. */
  102. void ffs_clrblock(Fs *, uint8_t *, ufs1_daddr_t);
  103. void ffs_clusteracct(Fs *, Cg *, ufs1_daddr_t, int);
  104. void ffs_fragacct(Fs *, int, uint32_t [], int);
  105. int ffs_isblock(Fs *, uint8_t *, ufs1_daddr_t);
  106. int ffs_isfreeblock(Fs *, uint8_t *, ufs1_daddr_t);
  107. void ffs_setblock(Fs *, uint8_t *, ufs1_daddr_t);