mlocate.db(5)

πŸ’… mlocate.db β€” a mlocate database (yes bestie, the binary one)

okay so listen, this page is from mlocate's File Formats Manual, and it's literally about the database file that locate and updatedb pass around like a group chat. no cap, it's giving "receipts for every file on your system." let's get into it 🫢


🌸 NAME 🌸

mlocate.db β€” a mlocate database. that's it, that's the name, iconic and to the point πŸ’…


✨ DESCRIPTION ✨

so a mlocate database starts with a file header, and it is extremely particular about its bytes, okay? like, she has a whole routine:

  • 8 bytes for a magic number β€” "\0mlocate" like a C literal ✨
  • 4 bytes for the configuration block size in big endian (yes, big endian, she's fancy)
  • 1 byte for file format version β€” that's 0
  • 1 byte for the "require visibility" flag β€” either 0 or 1
  • 2 bytes padding (she just needs a little breathing room)
  • a NUL-terminated path name of the root of the database πŸŽ€

the header is followed by a configuration block. and why, you ask? because databases should not be reused if some configuration changes could affect their contents β€” like, imagine a database from a whole different config era showing up, embarrassing πŸ’€ so the size of the configuration block in bytes is stored right there in the file header.

the configuration block is a sequence of variable assignments, ordered by variable name. each assignment is:

  • a NUL-terminated variable name
  • an ordered list of NUL-terminated values
  • the value list is terminated by one more NUL character

the ordering used is defined by the strcmp () function β€” so alphabetical-ish, but technically strcmp-ish, iykyk.


πŸ¦‹ Currently defined variables πŸ¦‹

  • prune_bind_mounts β€” a single entry, the value of PRUNE_BIND_MOUNTS; one of the strings 0 or 1.
  • prunefs β€” the value of PRUNEFS, each entry converted to uppercase.
  • prunepaths β€” the value of PRUNEPATHS.

the rest of the file until EOF describes directories and their contents, and this part is where it gets juicy.

each directory starts with its own header:

  • 8 bytes for directory time (seconds) in big endian
  • 4 bytes for directory time (nanoseconds) in big endian β€” 0 if unknown, and it's always less than 1,000,000,000
  • 4 bytes padding (again with the padding, she's consistent)
  • a NUL-terminated path name of the the directory (yes, "the the," the original says it, I'm not fixing it, that's her voice πŸ’–)

after the header comes the directory contents β€” a sequence of file entries sorted by name. main character energy from start to finish πŸ‘‘

directory time is the maximum of st_ctime and st_mtime of the directory. updatedb(8) uses the original data if the directory time in the database and in the file system match exactly. but watch out: directory time equal to 0 always causes rescanning of the directory β€” this is necessary to handle directories which were being updated while building the database. no shortcuts, bestie.


πŸŽ€ File entry types (the little byte that tells you everything) πŸŽ€

each file entry starts with a single byte, and that byte is the whole personality:

  • 0 β€” a non-directory file. followed by a NUL-terminated file (not path) name.
  • 1 β€” a subdirectory. followed by a NUL-terminated file (not path) name.
  • 2 β€” marks the end of the current directory.

and real talk: locate(1) only reports file entries, directory names are not reported because they are reported as an entry in their parent directory. the only exception is the root directory of the database, which is stored in the file header. so the root is the one main character who gets her own header spot, periodt πŸ’…


🌈 AUTHOR 🌈

Miloslav Trmac <mitr@redhat.com> β€” the icon who made this whole byte party happen, we stan πŸ’œ


πŸ‘€ SEE ALSO πŸ‘€


okay that's the whole vibe check, bestie. go forth and read those bytes like the icon you are. and remember: mlocate, Jan 2007 β€” that's the source and date of this legendary manual page, so show her some respect πŸŽ€βœ¨

πŸ“¦ where this page comes from