sfs.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _KERN_SFS_H_
  30. #define _KERN_SFS_H_
  31. /*
  32. * SFS definitions visible to userspace. This covers the on-disk format
  33. * and is used by tools that work on SFS volumes, such as mksfs.
  34. */
  35. #define SFS_MAGIC 0xabadf001 /* magic number identifying us */
  36. #define SFS_BLOCKSIZE 512 /* size of our blocks */
  37. #define SFS_VOLNAME_SIZE 32 /* max length of volume name */
  38. #define SFS_NDIRECT 15 /* # of direct blocks in inode */
  39. #define SFS_DBPERIDB 128 /* # direct blks per indirect blk */
  40. #define SFS_NAMELEN 60 /* max length of filename */
  41. #define SFS_SB_LOCATION 0 /* block the superblock lives in */
  42. #define SFS_ROOT_LOCATION 1 /* loc'n of the root dir inode */
  43. #define SFS_MAP_LOCATION 2 /* 1st block of the freemap */
  44. #define SFS_NOINO 0 /* inode # for free dir entry */
  45. /* Number of bits in a block */
  46. #define SFS_BLOCKBITS (SFS_BLOCKSIZE * CHAR_BIT)
  47. /* Utility macro */
  48. #define SFS_ROUNDUP(a,b) ((((a)+(b)-1)/(b))*b)
  49. /* Size of bitmap (in bits) */
  50. #define SFS_BITMAPSIZE(nblocks) SFS_ROUNDUP(nblocks, SFS_BLOCKBITS)
  51. /* Size of bitmap (in blocks) */
  52. #define SFS_BITBLOCKS(nblocks) (SFS_BITMAPSIZE(nblocks)/SFS_BLOCKBITS)
  53. /* File types for sfi_type */
  54. #define SFS_TYPE_INVAL 0 /* Should not appear on disk */
  55. #define SFS_TYPE_FILE 1
  56. #define SFS_TYPE_DIR 2
  57. /*
  58. * On-disk superblock
  59. */
  60. struct sfs_super {
  61. uint32_t sp_magic; /* Magic number, should be SFS_MAGIC */
  62. uint32_t sp_nblocks; /* Number of blocks in fs */
  63. char sp_volname[SFS_VOLNAME_SIZE]; /* Name of this volume */
  64. uint32_t reserved[118];
  65. };
  66. /*
  67. * On-disk inode
  68. */
  69. struct sfs_inode {
  70. uint32_t sfi_size; /* Size of this file (bytes) */
  71. uint16_t sfi_type; /* One of SFS_TYPE_* above */
  72. uint16_t sfi_linkcount; /* # hard links to this file */
  73. uint32_t sfi_direct[SFS_NDIRECT]; /* Direct blocks */
  74. uint32_t sfi_indirect; /* Indirect block */
  75. uint32_t sfi_waste[128-3-SFS_NDIRECT]; /* unused space, set to 0 */
  76. };
  77. /*
  78. * On-disk directory entry
  79. */
  80. struct sfs_dir {
  81. uint32_t sfd_ino; /* Inode number */
  82. char sfd_name[SFS_NAMELEN]; /* Filename */
  83. };
  84. #endif /* _KERN_SFS_H_ */