diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 369e497ad..2db284059 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -117,7 +117,7 @@ jobs: - run: pytest - run: flake8 - run: /github/home/.local/bin/ruff check . - - run: find . -name '*.py' | xargs /github/home/.local/bin/pyupgrade --py38-plus + - run: find . -not -path "./test/files/*" -name '*.py' | xargs /github/home/.local/bin/pyupgrade --py38-plus - run: python3 -m cProfile -o profile.stats lint.py -V test/source/* test/binary/* > /dev/null - run: python3 test/dump_stats.py profile.stats - name: Collect the coveralls report diff --git a/pyproject.toml b/pyproject.toml index 0a5b5559b..2bb3479e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,5 +78,6 @@ rpmlint = ["configdefaults.toml"] "rpmlint.descriptions" = ["*.toml"] [tool.ruff] +exclude = ["test/files"] lint.ignore = ["E501"] diff --git a/rpmlint/checks/DocCheck.py b/rpmlint/checks/DocCheck.py index 4e77e7a6a..94189f4ce 100644 --- a/rpmlint/checks/DocCheck.py +++ b/rpmlint/checks/DocCheck.py @@ -1,9 +1,7 @@ from pathlib import Path import stat -import rpm from rpmlint.checks.AbstractCheck import AbstractCheck -from rpmlint.helpers import byte_to_string class DocCheck(AbstractCheck): @@ -60,15 +58,12 @@ def _check_doc_file_dependencies(self, pkg): core_reqs = {} # dependencies of non-doc files doc_reqs = {} # dependencies of doc files - for dep in rpm.ds(pkg.header, 'requires'): - # skip deps which were found by find-requires - if dep.Flags() & rpm.RPMSENSE_FIND_REQUIRES != 0: - continue - core_reqs[dep.N()] = [] + for dep in pkg.get_core_reqs(): + core_reqs[dep] = [] # register things which are provided by the package - for i in pkg.header[rpm.RPMTAG_PROVIDES]: - core_reqs[byte_to_string(i)] = [] + for i in pkg.provides: + core_reqs[i] = [] for i in files: core_reqs[i] = [] diff --git a/rpmlint/checks/FilesCheck.py b/rpmlint/checks/FilesCheck.py index 8ebb01142..60cb3cb85 100644 --- a/rpmlint/checks/FilesCheck.py +++ b/rpmlint/checks/FilesCheck.py @@ -1179,6 +1179,11 @@ def _check_file_normal_file_devel(self, pkg, fname, pkgfile): self.output.add_info('W', pkg, 'devel-file-in-non-devel-package', fname) def _check_file_normal_file_non_readable(self, pkg, fname, pkgfile): + # Do not check permissions for ghosts files + # https://github.com/rpm-software-management/rpmlint/issues/1287 + if pkgfile.is_ghost: + return + mode = pkgfile.mode perm = mode & 0o7777 if mode & 0o444 != 0o444 and perm & 0o7000 == 0: diff --git a/rpmlint/checks/SpecCheck.py b/rpmlint/checks/SpecCheck.py index 0abe6b354..c8abc83bc 100644 --- a/rpmlint/checks/SpecCheck.py +++ b/rpmlint/checks/SpecCheck.py @@ -814,6 +814,10 @@ def _check_suse_update_desktop_file(self, line): %suse_update_desktop_file is deprecated now. """ if suse_update_desktop_file_regex.match(line): + # Don't show the message for yast, there's no migration path yet. + if 'yast' in self.pkg.name.lower(): + return + self.output.add_info('W', self.pkg, 'suse-update-desktop-file-deprecated', '%suse_update_desktop_file is deprecated') diff --git a/rpmlint/checks/TagsCheck.py b/rpmlint/checks/TagsCheck.py index 14451c38b..c142a49d4 100644 --- a/rpmlint/checks/TagsCheck.py +++ b/rpmlint/checks/TagsCheck.py @@ -149,8 +149,7 @@ def check_description(self, pkg, lang, ignored_words): description = byte_to_string(description) self._unexpanded_macros(pkg, '%%description -l %s' % lang, description) if self.spellcheck: - pkgname = byte_to_string(pkg.header[rpm.RPMTAG_NAME]) - typos = self.spellchecker.spell_check(description, '%description -l {}', lang, pkgname, ignored_words) + typos = self.spellchecker.spell_check(description, '%description -l {}', lang, pkg.name, ignored_words) for typo in typos.items(): self.output.add_info('E', pkg, 'spelling-error', typo) for i in description.splitlines(): @@ -172,8 +171,7 @@ def check_summary(self, pkg, lang, ignored_words): summary = byte_to_string(summary) self._unexpanded_macros(pkg, 'Summary(%s)' % lang, summary) if self.spellcheck: - pkgname = byte_to_string(pkg.header[rpm.RPMTAG_NAME]) - typos = self.spellchecker.spell_check(summary, 'Summary({})', lang, pkgname, ignored_words) + typos = self.spellchecker.spell_check(summary, 'Summary({})', lang, pkg.name, ignored_words) for typo in typos.items(): self.output.add_info('E', pkg, 'spelling-error', typo) if any(nl in summary for nl in ('\n', '\r')): diff --git a/rpmlint/descriptions/SpecCheck.toml b/rpmlint/descriptions/SpecCheck.toml index 1160b57cb..970003879 100644 --- a/rpmlint/descriptions/SpecCheck.toml +++ b/rpmlint/descriptions/SpecCheck.toml @@ -226,5 +226,7 @@ The specfile contains a comparison of %suse_version against a suse release that does not exist. Please double check. """ suse-update-desktop-file-deprecated=""" -The usage of %suse_update_desktop_file is deprecated and should not be used. +The usage of %suse_update_desktop_file is deprecated and changes +should be migrated to the upstream. +Please check the build log for details. """ diff --git a/rpmlint/pkg.py b/rpmlint/pkg.py index 2e4211c67..ef35b1838 100644 --- a/rpmlint/pkg.py +++ b/rpmlint/pkg.py @@ -513,6 +513,15 @@ def read_with_mmap(self, filename): except Exception: return '' + def grep(self, regex, filename): + """Grep regex from a file, return first matching line number (starting with 1).""" + data = self.read_with_mmap(filename) + match = regex.search(data) + if match: + return data.count('\n', 0, match.start()) + 1 + else: + return None + class Pkg(AbstractPkg): _magic_from_compressed_re = re.compile(r'\([^)]+\s+compressed\s+data\b') @@ -642,15 +651,6 @@ def cleanup(self): if self.extracted and self.dirname: self.__tmpdir.cleanup() - def grep(self, regex, filename): - """Grep regex from a file, return first matching line number (starting with 1).""" - data = self.read_with_mmap(filename) - match = regex.search(data) - if match: - return data.count('\n', 0, match.start()) + 1 - else: - return None - def langtag(self, tag, lang): """Get value of tag in the given language.""" # LANGUAGE trumps other env vars per GNU gettext docs, see also #166 @@ -728,6 +728,21 @@ def readlink(self, pkgfile): result = self.files.get(linkpath) return result + def get_core_reqs(self): + """ + Return the list of dependencies that are not found by find-requires + withouth the flag RPM + """ + core_reqs = [] + + for dep in rpm.ds(self.header, 'requires'): + # skip deps which were found by find-requires + if dep.Flags() & rpm.RPMSENSE_FIND_REQUIRES != 0: + continue + core_reqs.append(dep.N()) + + return core_reqs + def get_installed_pkgs(name): """Get list of installed package objects by name.""" @@ -885,6 +900,7 @@ def add_dir(self, path, metadata=None): path = os.path.join(self.dir_name(), path.lstrip('/')) os.makedirs(Path(path), exist_ok=True) + pkgdir.inode = os.stat(Path(path)).st_ino pkgdir.path = path self.files[name] = pkgdir @@ -948,7 +964,7 @@ def add_header(self, header): tagname = k[:-1].upper() for i in v: name, flags, version = parse_deps(i)[0] - version = f'{version[0]}:{version[1]}-{version[2]}' + version = versionToString(version) self.header[getattr(rpm, f'RPMTAG_{tagname}NAME')].append(name) self.header[getattr(rpm, f'RPMTAG_{tagname}FLAGS')].append(flags) self.header[getattr(rpm, f'RPMTAG_{tagname}VERSION')].append(version) @@ -1006,6 +1022,10 @@ def cleanup(self): if self.dirname: self.__tmpdir.cleanup() + def get_core_reqs(self): + core_reqs = [] + return core_reqs + # access the tags like an array def __getitem__(self, key): return self.header.get(key, None) diff --git a/setup.cfg b/setup.cfg index 22a2021ee..99f53c692 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,4 +5,4 @@ test=pytest ignore = E122,E501,W504 import-order-style = google application-import-names = Testing - +exclude = test/files/* diff --git a/test/Testing.py b/test/Testing.py index 1cae21185..e9ca34596 100644 --- a/test/Testing.py +++ b/test/Testing.py @@ -83,7 +83,7 @@ def _fake_pkg(self): self._lazy_name) return self._lazy_pkg - def clone(self, files=None, header=None, name=None): + def clone(self, files=None, header=None, name=None, extend=False): """ Copies this LazyMock modifying some properties """ @@ -92,6 +92,8 @@ def clone(self, files=None, header=None, name=None): files = self._lazy_files if header is None: header = self._lazy_header + elif extend: + header = self._lazy_header | header if name is None: name = self._lazy_name diff --git a/test/binary/doc-file-dependency-1.0.0-0.noarch.rpm b/test/binary/doc-file-dependency-1.0.0-0.noarch.rpm deleted file mode 100644 index ee088ea5f..000000000 Binary files a/test/binary/doc-file-dependency-1.0.0-0.noarch.rpm and /dev/null differ diff --git a/test/binary/fPing-4.2~dev-1.2~.3.x86_64.rpm b/test/binary/fPing-4.2~dev-1.2~.3.x86_64.rpm deleted file mode 100644 index 09b258c7d..000000000 Binary files a/test/binary/fPing-4.2~dev-1.2~.3.x86_64.rpm and /dev/null differ diff --git a/test/binary/foo-devel-0-0.x86_64.rpm b/test/binary/foo-devel-0-0.x86_64.rpm deleted file mode 100644 index 433874fe1..000000000 Binary files a/test/binary/foo-devel-0-0.x86_64.rpm and /dev/null differ diff --git a/test/binary/fuse-common-3.10.2-5.el8.x86_64.rpm b/test/binary/fuse-common-3.10.2-5.el8.x86_64.rpm deleted file mode 100644 index 9b576ba0a..000000000 Binary files a/test/binary/fuse-common-3.10.2-5.el8.x86_64.rpm and /dev/null differ diff --git a/test/binary/install-file-in-docs-1.0-0.x86_64.rpm b/test/binary/install-file-in-docs-1.0-0.x86_64.rpm deleted file mode 100644 index b0633b49f..000000000 Binary files a/test/binary/install-file-in-docs-1.0-0.x86_64.rpm and /dev/null differ diff --git a/test/binary/invalid-exception-0-0.x86_64.rpm b/test/binary/invalid-exception-0-0.x86_64.rpm deleted file mode 100644 index 0bda10dae..000000000 Binary files a/test/binary/invalid-exception-0-0.x86_64.rpm and /dev/null differ diff --git a/test/binary/libreiserfscore-devel-3.6.27-0.x86_64.rpm b/test/binary/libreiserfscore-devel-3.6.27-0.x86_64.rpm deleted file mode 100644 index 7d8bb6ab9..000000000 Binary files a/test/binary/libreiserfscore-devel-3.6.27-0.x86_64.rpm and /dev/null differ diff --git a/test/binary/logrotate-0-0.x86_64.rpm b/test/binary/logrotate-0-0.x86_64.rpm deleted file mode 100644 index 34da83530..000000000 Binary files a/test/binary/logrotate-0-0.x86_64.rpm and /dev/null differ diff --git a/test/binary/missingprovides-devel-0-0.x86_64.rpm b/test/binary/missingprovides-devel-0-0.x86_64.rpm deleted file mode 100644 index b2e92178b..000000000 Binary files a/test/binary/missingprovides-devel-0-0.x86_64.rpm and /dev/null differ diff --git a/test/binary/mydoc-0-0.x86_64.rpm b/test/binary/mydoc-0-0.x86_64.rpm deleted file mode 100644 index ab0281527..000000000 Binary files a/test/binary/mydoc-0-0.x86_64.rpm and /dev/null differ diff --git a/test/binary/unexpanded1-0-0.noarch.rpm b/test/binary/unexpanded1-0-0.noarch.rpm deleted file mode 100644 index 8bbc61566..000000000 Binary files a/test/binary/unexpanded1-0-0.noarch.rpm and /dev/null differ diff --git a/test/binary/valid-exception-0-0.x86_64.rpm b/test/binary/valid-exception-0-0.x86_64.rpm deleted file mode 100644 index 7887e610f..000000000 Binary files a/test/binary/valid-exception-0-0.x86_64.rpm and /dev/null differ diff --git a/test/files/logrotate/logrotate.conf b/test/files/logrotate/logrotate.conf new file mode 100644 index 000000000..21a6ba9da --- /dev/null +++ b/test/files/logrotate/logrotate.conf @@ -0,0 +1,14 @@ +/var/log/myapp/*.log { + su appuser appuser + weekly + rotate 4 + compress + + delaycompress + missingok + create 644 appuser appuser +} + +/var/log/myapp/*.log { + su appuser2 appuser2 +} diff --git a/test/files/logrotate/logrotate2.conf b/test/files/logrotate/logrotate2.conf new file mode 100644 index 000000000..06b4277f6 --- /dev/null +++ b/test/files/logrotate/logrotate2.conf @@ -0,0 +1,12 @@ +/var/log/myapp/*.log { + su appuser2 appuser2 +} + +/tmp/foo/my.log { + # comment + su appuser2 appuser2 +} + +/tmp/foo2/my.log { + su appuser2 appuser2 +} diff --git a/test/files/python3-power/__init__.cpython-33.pyc b/test/files/python3-power/__init__.cpython-33.pyc new file mode 100644 index 000000000..d68530b62 Binary files /dev/null and b/test/files/python3-power/__init__.cpython-33.pyc differ diff --git a/test/files/python3-power/__init__.cpython-33.pyo b/test/files/python3-power/__init__.cpython-33.pyo new file mode 100644 index 000000000..d68530b62 Binary files /dev/null and b/test/files/python3-power/__init__.cpython-33.pyo differ diff --git a/test/files/python3-power/__init__.py b/test/files/python3-power/__init__.py new file mode 100644 index 000000000..5c1c64a97 --- /dev/null +++ b/test/files/python3-power/__init__.py @@ -0,0 +1,39 @@ +# coding=utf-8 +""" +Provides crossplatform checking of current power source, battery warning level and battery time remaining estimate. +Allows you to add observer for power notifications if platform supports it. + +Usage: + from power import PowerManagement, PowerManagementObserver # Automatically imports platform-specific implementation + + class Observer(PowerManagementObserver): + def on_power_sources_change(self, power_management): + print "Power sources did change." + + def on_time_remaining_change(self, power_management): + print "Time remaining did change." + + # class Observer(object): + # ... + # PowerManagementObserver.register(Observer) +""" +__author__ = 'kulakov.ilya@gmail.com' +__version__ = '1.1' + +from sys import platform +from power.common import * + + +try: + if platform.startswith('darwin'): + from power.darwin import PowerManagement + elif platform.startswith('win32'): + from power.win32 import PowerManagement + elif platform.startswith('linux'): + from power.linux import PowerManagement + else: + raise RuntimeError("{platform} is not supported.".format(platform=platform)) +except RuntimeError as e: + import warnings + warnings.warn("Unable to load PowerManagement for {platform}. No-op PowerManagement class is used: {error}".format(error=str(e), platform=platform)) + from power.common import PowerManagementNoop as PowerManagement diff --git a/test/files/python3-power/common.cpython-33.pyc b/test/files/python3-power/common.cpython-33.pyc new file mode 100644 index 000000000..3d59b6645 Binary files /dev/null and b/test/files/python3-power/common.cpython-33.pyc differ diff --git a/test/files/python3-power/common.cpython-33.pyo b/test/files/python3-power/common.cpython-33.pyo new file mode 100644 index 000000000..3d59b6645 Binary files /dev/null and b/test/files/python3-power/common.cpython-33.pyo differ diff --git a/test/files/python3-power/common.py b/test/files/python3-power/common.py new file mode 100644 index 000000000..487498778 --- /dev/null +++ b/test/files/python3-power/common.py @@ -0,0 +1,207 @@ +# coding=utf-8 +""" +Represents common constants and classes for all platforms. + +@group Power Source Type: POWER_TYPE_AC, POWER_TYPE_BATTERY, POWER_TYPE_UPS +@var POWER_TYPE_AC: The system is connected to the external power source. +@var POWER_TYPE_BATTERY: The system is connected to the battery. +@var POWER_TYPE_UPS: The system is connected to UPS. +@type POWER_TYPE_BATTERY: int +@type POWER_TYPE_AC: int +@type POWER_TYPE_UPS: int + +@group Low Battery Warning Levels: LOW_BATTERY_WARNING_NONE, LOW_BATTERY_WARNING_EARLY, LOW_BATTERY_WARNING_FINAL +@var LOW_BATTERY_WARNING_NONE: The system is connected to the unlimited power source. +@var LOW_BATTERY_WARNING_EARLY: The battery has dropped below 22% remaining power. +@var LOW_BATTERY_WARNING_FINAL: The battery can provide no more than 10 minutes of runtime. +@type LOW_BATTERY_WARNING_EARLY: int +@type LOW_BATTERY_WARNING_NONE: int +@type LOW_BATTERY_WARNING_FINAL: int + +@group Special Values For Time Remaining: TIME_REMAINING_UNKNOWN, TIME_REMAINING_UNLIMITED +@var TIME_REMAINING_UNKNOWN: Indicates the system is connected to a limited power source, but system is still + calculating a time remaining estimate. +@var TIME_REMAINING_UNLIMITED: Indicates that the system is connected to an external power source, without time limit. +@type TIME_REMAINING_UNKNOWN: float +@type TIME_REMAINING_UNLIMITED: float +""" +__author__ = 'kulakov.ilya@gmail.com' + +from abc import ABCMeta, abstractmethod +import weakref + +__all__ = [ + 'POWER_TYPE_AC', + 'POWER_TYPE_BATTERY', + 'POWER_TYPE_UPS', + 'LOW_BATTERY_WARNING_NONE', + 'LOW_BATTERY_WARNING_EARLY', + 'LOW_BATTERY_WARNING_FINAL', + 'TIME_REMAINING_UNKNOWN', + 'TIME_REMAINING_UNLIMITED', + 'PowerManagementObserver' + ] + + +POWER_TYPE_AC = 0 + +POWER_TYPE_BATTERY = 1 + +POWER_TYPE_UPS = 2 + + +LOW_BATTERY_WARNING_NONE = 1 + +LOW_BATTERY_WARNING_EARLY = 2 + +LOW_BATTERY_WARNING_FINAL = 3 + + +TIME_REMAINING_UNKNOWN = -1.0 + +TIME_REMAINING_UNLIMITED = -2.0 + + +class PowerManagementBase(object): + """ + Base class for platform dependent PowerManagement functions. + + @ivar _weak_observers: List of weak reference to added observers + @note: Platform's implementation may provide additional parameters for initialization + """ + __metaclass__ = ABCMeta + + def __init__(self): + self._weak_observers = [] + + @abstractmethod + def get_providing_power_source_type(self): + """ + Returns type of the providing power source. + + @return: Possible values: + - POWER_TYPE_AC + - POWER_TYPE_BATTERY + - POWER_TYPE_UPS + @rtype: int + """ + pass + + @abstractmethod + def get_low_battery_warning_level(self): + """ + Returns the system battery warning level. + + @return: Possible values: + - LOW_BATTERY_WARNING_NONE + - LOW_BATTERY_WARNING_EARLY + - LOW_BATTERY_WARNING_FINAL + @rtype: int + """ + pass + + @abstractmethod + def get_time_remaining_estimate(self): + """ + Returns the estimated minutes remaining until all power sources (battery and/or UPS) are empty. + + @return: Special values: + - TIME_REMAINING_UNKNOWN + - TIME_REMAINING_UNLIMITED + @rtype: float + """ + pass + + @abstractmethod + def add_observer(self, observer): + """ + Adds weak ref to an observer. + + @param observer: Instance of class registered with PowerManagementObserver + @raise TypeError: If observer is not registered with PowerManagementObserver abstract class + """ + if not isinstance(observer, PowerManagementObserver): + raise TypeError("observer MUST conform to power.PowerManagementObserver") + self._weak_observers.append(weakref.ref(observer)) + + @abstractmethod + def remove_observer(self, observer): + """ + Removes an observer. + + @param observer: Previously added observer + """ + self._weak_observers.remove(weakref.ref(observer)) + + def remove_all_observers(self): + """ + Removes all registered observers. + """ + for weak_observer in self._weak_observers: + observer = weak_observer() + if observer: + self.remove_observer(observer) + + +class PowerManagementObserver: + """ + Base class for PowerManagement observers. + Do not make assumptions in what thread or event loop these methods are called. + """ + __metaclass__ = ABCMeta + + @abstractmethod + def on_power_sources_change(self, power_management): + """ + @param power_management: Instance of PowerManagement posted notification + """ + pass + + @abstractmethod + def on_time_remaining_change(self, power_management): + """ + @param power_management: Instance of PowerManagement posted notification + """ + pass + + +class PowerManagementNoop(PowerManagementBase): + """ + No-op subclass of PowerManagement. + It operates like AC is always attached and power sources are never changed. + """ + def get_providing_power_source_type(self): + """ + @return: Always POWER_TYPE_AC + """ + return POWER_TYPE_AC + + def get_low_battery_warning_level(self): + """ + @return: Always LOW_BATTERY_WARNING_NONE + """ + return LOW_BATTERY_WARNING_NONE + + def get_time_remaining_estimate(self): + """ + @return: Always TIME_REMAINING_UNLIMITED + """ + return TIME_REMAINING_UNLIMITED + + def add_observer(self, observer): + """ + Does nothing. + """ + pass + + def remove_observer(self, observer): + """ + Does nothing. + """ + pass + + def remove_all_observers(self): + """ + Does nothing. + """ + pass diff --git a/test/files/reiserfs/io.h b/test/files/reiserfs/io.h new file mode 100644 index 000000000..6136964f2 --- /dev/null +++ b/test/files/reiserfs/io.h @@ -0,0 +1,85 @@ +/* + * Copyright 1996-2004 by Hans Reiser, licensing governed by + * reiserfsprogs/README + */ + +#ifndef REISERFSPROGS_IO_H +#define REISERFSPROGS_IO_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include + +#include "misc.h" + +struct buffer_head { + unsigned long b_blocknr; + int b_dev; + unsigned long b_size; + char *b_data; + unsigned long b_state; + unsigned int b_count; + unsigned int b_list; + void (*b_start_io) (unsigned long); + void (*b_end_io) (struct buffer_head * bh, int uptodate); + + struct buffer_head *b_next; + struct buffer_head *b_prev; + struct buffer_head *b_hash_next; + struct buffer_head *b_hash_prev; +}; + +#define BH_Uptodate 0 +#define BH_Dirty 1 +#define BH_Lock 2 +#define BH_Do_not_flush 3 + +#define buffer_uptodate(bh) misc_test_bit(BH_Uptodate, &(bh)->b_state) +#define buffer_dirty(bh) misc_test_bit(BH_Dirty, &(bh)->b_state) +#define buffer_locked(bh) misc_test_bit(BH_Lock, &(bh)->b_state) +#define buffer_clean(bh) !misc_test_bit(BH_Dirty, &(bh)->b_state) +#define buffer_do_not_flush(bh) misc_test_bit(BH_Do_not_flush, &(bh)->b_state) +#define mark_buffer_dirty(bh) misc_set_bit(BH_Dirty, &(bh)->b_state) +#define mark_buffer_uptodate(bh,i) misc_set_bit(BH_Uptodate, &(bh)->b_state) +#define mark_buffer_clean(bh) misc_clear_bit(BH_Dirty, &(bh)->b_state) +#define mark_buffer_do_not_flush(bh) misc_set_bit(BH_Do_not_flush, &(bh)->b_state) +#define clear_buffer_do_not_flush(bh) misc_clear_bit(BH_Do_not_flush, &(bh)->b_state) + +/* +printf ("%s:%s:%u %p %p %p\n", +__FILE__, __FUNCTION__, __LINE__, + __builtin_return_address (0), + __builtin_return_address (1), + __builtin_return_address (2)); +*/ + +void __wait_on_buffer(struct buffer_head *bh); +struct buffer_head *getblk(int dev, unsigned long block, int size); +struct buffer_head *reiserfs_getblk(int dev, unsigned long block, int size, + int *repeat); + +struct buffer_head *find_buffer(int dev, unsigned long block, + unsigned long size); +struct buffer_head *get_hash_table(dev_t dev, unsigned long block, int size); +struct buffer_head *bread(int dev, unsigned long block, size_t size); +struct buffer_head *reiserfs_bread(int dev, unsigned long block, int size, + int *repeat); +int bwrite(struct buffer_head *bh); +void brelse(struct buffer_head *bh); +void bforget(struct buffer_head *bh); +void init_rollback_file(char *rollback_file, unsigned int *blocksize, + FILE * log); +int open_rollback_file(char *rollback_file, FILE * log); +void close_rollback_file(); +void do_fsck_rollback(int fd_device, int fd_journal_device, FILE * log); + +void flush_buffers(int); +void free_buffers(void); +void invalidate_buffers(int); + +#endif diff --git a/test/files/reiserfs/libreiserfscore.a b/test/files/reiserfs/libreiserfscore.a new file mode 100644 index 000000000..f3c60fcd6 Binary files /dev/null and b/test/files/reiserfs/libreiserfscore.a differ diff --git a/test/files/reiserfs/libreiserfscore.la b/test/files/reiserfs/libreiserfscore.la new file mode 100755 index 000000000..d12ca8560 --- /dev/null +++ b/test/files/reiserfs/libreiserfscore.la @@ -0,0 +1,41 @@ +# libreiserfscore.la - a libtool library file +# Generated by libtool (GNU libtool) 2.4.6 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='libreiserfscore.so.0' + +# Names of this library. +library_names='libreiserfscore.so.0.0.0 libreiserfscore.so.0 libreiserfscore.so' + +# The name of the static archive. +old_library='libreiserfscore.a' + +# Linker flags that cannot go in dependency_libs. +inherited_linker_flags='' + +# Libraries that this one depends upon. +dependency_libs=' -lcom_err -luuid' + +# Names of additional weak libraries provided by this library +weak_library_names='' + +# Version information for libreiserfscore. +current=0 +age=0 +revision=0 + +# Is this an already installed library? +installed=yes + +# Should we warn about portability when linking against -modules? +shouldnotlink=no + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='/usr/lib64' diff --git a/test/files/reiserfs/misc.h b/test/files/reiserfs/misc.h new file mode 100644 index 000000000..1a60eb23a --- /dev/null +++ b/test/files/reiserfs/misc.h @@ -0,0 +1,325 @@ +/* + * Copyright 1996-2004 by Hans Reiser, licensing governed by + * reiserfsprogs/README + */ + +/* nothing abount reiserfs here */ + +#ifndef REISERFSPROGS_MISC_H +#define REISERFSPROGS_MISC_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include + +#if defined(MAJOR_IN_MKDEV) +# include +#elif defined(MAJOR_IN_SYSMACROS) +# include +#endif + +#include "swab.h" + +#define POSITION_FOUND 8 +#define POSITION_NOT_FOUND 9 + +#define INVAL_PTR (void *)-1 + +void check_memory_msg(void); +void die(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); +void *getmem(int size); +void *mem_alloc(int size); +void freemem(void *p); +void checkmem(const char *p, int size); +void *expandmem(void *p, int size, int by); +unsigned int get_mem_size(const char *p); +void check_and_free_mem(void); +char *kdevname(int dev); + +typedef enum mount_flags { + MF_NOT_MOUNTED = 0x0, + MF_RO = 0x1, + MF_RW = 0x2 +} mount_flags_t; + +typedef struct mount_hint { + char *point; /* Mount point. */ + __u32 psize; /* Mount point buffer size. */ + __u32 flags; /* Mount flags. */ +} mount_hint_t; + +struct mntent *misc_mntent(const char *device); +int misc_device_mounted(const char *device); + +typedef struct dma_info { + int fd; + struct stat st; + int support_type; + int dma; + __u64 speed; +} dma_info_t; + +int prepare_dma_check(dma_info_t *dma_info); +int get_dma_info(dma_info_t *dma_info); +void clean_after_dma_check(int fd, dma_info_t *dma_info); + +int valid_offset(int fd, loff_t offset); +unsigned long count_blocks(const char *filename, int blocksize); + +void print_how_far(FILE * fp, unsigned long *passed, unsigned long total, + unsigned int inc, int quiet); +void print_how_fast(unsigned long total, unsigned long passed, int cursor_pos, + int reset_time); +__u32 get_random(void); + +int user_confirmed(FILE * fp, const char *q, const char *yes); + +/* Only le bitops operations are used. */ +static inline int misc_set_bit(unsigned long long nr, void *addr) +{ + __u8 *p, mask; + int retval; + + p = (__u8 *) addr; + p += nr >> 3; + mask = 1 << (nr & 0x7); + /*cli(); */ + retval = (mask & *p) != 0; + *p |= mask; + /*sti(); */ + return retval; +} + +static inline int misc_clear_bit(unsigned long long nr, void *addr) +{ + __u8 *p, mask; + int retval; + + p = (__u8 *) addr; + p += nr >> 3; + mask = 1 << (nr & 0x7); + /*cli(); */ + retval = (mask & *p) != 0; + *p &= ~mask; + /*sti(); */ + return retval; +} + +static inline int misc_test_bit(unsigned long long nr, const void *addr) +{ + __u8 *p, mask; + + p = (__u8 *) addr; + p += nr >> 3; + mask = 1 << (nr & 0x7); + return ((mask & *p) != 0); +} + +static inline unsigned long long misc_find_first_zero_bit(const void *vaddr, + unsigned long long + size) +{ + const __u8 *p = vaddr, *addr = vaddr; + unsigned long long res; + + if (!size) + return 0; + + size = (size >> 3) + ((size & 0x7) > 0); + while (*p++ == 255) { + if (--size == 0) + return (unsigned long long)(p - addr) << 3; + } + + --p; + for (res = 0; res < 8; res++) + if (!misc_test_bit(res, p)) + break; + return res + (p - addr) * 8; +} + +static inline unsigned long long misc_find_next_zero_bit(const void *vaddr, + unsigned long long + size, + unsigned long long + offset) +{ + const __u8 *addr = vaddr; + const __u8 *p = addr + (offset >> 3); + int bit = offset & 7; + unsigned long long res; + + if (offset >= size) + return size; + + if (bit) { + /* Look for zero in first char */ + for (res = bit; res < 8; res++) + if (!misc_test_bit(res, p)) + return res + (p - addr) * 8; + p++; + } + /* No zero yet, search remaining full bytes for a zero */ + res = misc_find_first_zero_bit(p, size - 8 * (p - addr)); + return res + (p - addr) * 8; +} + +static inline unsigned long long misc_find_first_set_bit(const void *vaddr, + unsigned long long + size) +{ + const __u8 *p = vaddr, *addr = vaddr; + unsigned long long res; + + if (!size) + return 0; + + size = (size >> 3) + ((size & 0x7) > 0); + while (*p++ == 0) { + if (--size == 0) + return (unsigned long long)(p - addr) << 3; + } + + --p; + for (res = 0; res < 8; res++) + if (misc_test_bit(res, p)) + break; + + return res + (p - addr) * 8; +} + +static inline unsigned long long misc_find_next_set_bit(const void *vaddr, + unsigned long long size, + unsigned long long + offset) +{ + const __u8 *addr = vaddr; + const __u8 *p = addr + (offset >> 3); + int bit = offset & 7; + unsigned long long res; + + if (offset >= size) + return size; + + if (bit) { + /* Look for zero in first char */ + for (res = bit; res < 8; res++) + if (misc_test_bit(res, p)) + return res + (p - addr) * 8; + p++; + } + /* No set bit yet, search remaining full bytes for a 1 */ + res = misc_find_first_set_bit(p, size - 8 * (p - addr)); + return res + (p - addr) * 8; +} + +#define STAT_FIELD(Field, Type) \ +static inline Type misc_device_##Field(const char *device) \ +{ \ + struct stat st; \ + \ + if (stat(device, &st) == 0) \ + return st.st_##Field; \ + \ + fprintf(stderr, "Stat of the device '%s' failed.", device); \ + exit(8); \ +} + +STAT_FIELD(mode, mode_t); +STAT_FIELD(rdev, dev_t); +STAT_FIELD(size, off_t); +STAT_FIELD(blocks, blkcnt_t); + +__u16 mask16(int from, int count); +__u32 mask32(int from, int count); +__u64 mask64(int from, int count); + +int reiserfs_bin_search(const void *key, void *base, __u32 num, int width, + __u32 * ppos, __compar_fn_t comp_func); + +struct block_handler { + __u32 blocknr; + dev_t device; +}; + +int blocklist__is_block_saved(struct block_handler **base, __u32 * count, + __u32 blocknr, dev_t device, __u32 * position); +void blocklist__insert_in_position(void *block_h, void **base, __u32 * count, + int elem_size, __u32 * position); +int blockdev_list_compare(const void *block1, const void *block2); + +#define set_bit_field_XX(XX,vp,val,from,count) \ +{\ + __le##XX * p;\ + __u##XX tmp;\ +\ + /* make sure that given value can be put in 'count' bits */\ + if (val > (1 << count))\ + die ("set_bit_field: val %d is too big for %d bits", val, count);\ +\ + p = (__le##XX *)vp;\ + tmp = le##XX##_to_cpu (*p);\ +\ + /* clear 'count' bits starting from 'from'-th one */\ + tmp &= ~mask##XX (from, count);\ +\ + /* put given value in proper bits */\ + tmp |= (val << from);\ +\ + *p = cpu_to_le##XX (tmp);\ +} + +#define get_bit_field_XX(XX,vp,from,count) \ +\ + __le##XX * p;\ + __u##XX tmp;\ +\ + p = (__le##XX *)vp;\ + tmp = le##XX##_to_cpu (*p);\ +\ + /* clear all bits but 'count' bits starting from 'from'-th one */\ + tmp &= mask##XX (from, count);\ +\ + /* get value written in specified bits */\ + tmp >>= from;\ + return tmp; + +#ifndef major +#define major(rdev) ((rdev)>>8) +#define minor(rdev) ((rdev) & 0xff) +#endif /* major */ + +#ifndef SCSI_DISK_MAJOR +#define SCSI_DISK_MAJOR(maj) ((maj) == SCSI_DISK0_MAJOR || \ + ((maj) >= SCSI_DISK1_MAJOR && (maj) <= SCSI_DISK7_MAJOR)) +#endif /* SCSI_DISK_MAJOR */ + +#ifndef SCSI_BLK_MAJOR +#define SCSI_BLK_MAJOR(maj) (SCSI_DISK_MAJOR(maj) || (maj) == SCSI_CDROM_MAJOR) +#endif /* SCSI_BLK_MAJOR */ + +#ifndef IDE_DISK_MAJOR +#ifdef IDE9_MAJOR +#define IDE_DISK_MAJOR(maj) ((maj) == IDE0_MAJOR || (maj) == IDE1_MAJOR || \ + (maj) == IDE2_MAJOR || (maj) == IDE3_MAJOR || \ + (maj) == IDE4_MAJOR || (maj) == IDE5_MAJOR || \ + (maj) == IDE6_MAJOR || (maj) == IDE7_MAJOR || \ + (maj) == IDE8_MAJOR || (maj) == IDE9_MAJOR) +#else +#define IDE_DISK_MAJOR(maj) ((maj) == IDE0_MAJOR || (maj) == IDE1_MAJOR || \ + (maj) == IDE2_MAJOR || (maj) == IDE3_MAJOR || \ + (maj) == IDE4_MAJOR || (maj) == IDE5_MAJOR) +#endif /* IDE9_MAJOR */ +#endif /* IDE_DISK_MAJOR */ + +#endif /* REISERFS_MISC_H */ diff --git a/test/files/reiserfs/reiserfs_err.h b/test/files/reiserfs/reiserfs_err.h new file mode 100644 index 000000000..accaf1c1b --- /dev/null +++ b/test/files/reiserfs/reiserfs_err.h @@ -0,0 +1,25 @@ +/* + * reiserfs_err.h: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define REISERFS_ET_BREAD_FAILED (50094765501195648L) +#define REISERFS_ET_BAD_MAGIC (50094765501195647L) +#define REISERFS_ET_BAD_SUPER (50094765501195646L) +#define REISERFS_ET_SMALL_PARTITION (50094765501195645L) +#define REISERFS_ET_NOT_ENOUGH_BLOCKS (50094765501195644L) +#define REISERFS_ET_TOO_SMALL (50094765501195643L) +#define REISERFS_ET_GETBLK_FAILED (50094765501195642L) +extern const struct error_table et_reiserfs_error_table; +extern void initialize_reiserfs_error_table(void); + +/* For compatibility with Heimdal */ +extern void initialize_reiserfs_error_table_r(struct et_list **list); + +#define ERROR_TABLE_BASE_reiserfs (50094765501195648L) + +/* for compatibility with older versions... */ +#define init_reiserfs_err_tbl initialize_reiserfs_error_table +#define reiserfs_err_base ERROR_TABLE_BASE_reiserfs diff --git a/test/files/reiserfs/reiserfs_fs.h b/test/files/reiserfs/reiserfs_fs.h new file mode 100644 index 000000000..a12801733 --- /dev/null +++ b/test/files/reiserfs/reiserfs_fs.h @@ -0,0 +1,1625 @@ +/* + * Copyright 1996-2004 by Hans Reiser, licensing governed by + * reiserfsprogs/README + */ + +/* + * Reiser File System constants and structures + */ + +/* in reading the #defines, it may help to understand that they employ the + following abbreviations: + + B = Buffer + I = Item header + H = Height within the tree (should be changed to LEV) + N = Number of the item in the node + STAT = stat data + DEH = Directory Entry Header + EC = Entry Count + E = Entry number + UL = Unsigned Long + BLKH = BLocK Header + UNFM = UNForMatted node + DC = Disk Child + P = Path + + These #defines are named by concatenating these abbreviations, where first + comes the arguments, and last comes the return value, of the macro. + +*/ + +#ifndef REISERFSPROGS_FS_H +#define REISERFSPROGS_FS_H + +#include +#include "swab.h" + +typedef __u16 __bitwise __le16; +typedef __u32 __bitwise __le32; +typedef __u64 __bitwise __le64; + +typedef unsigned int blocknr_t; + +#ifndef get_unaligned +#define get_unaligned(ptr) \ +({ \ + __typeof__(*(ptr)) __tmp; \ + memcpy(&__tmp, (ptr), sizeof(*(ptr))); \ + __tmp; \ +}) +#endif + +#ifndef put_unaligned +#define put_unaligned(val, ptr) \ +({ \ + __typeof__(*(ptr)) __tmp = (val); \ + memcpy((ptr), &__tmp, sizeof(*(ptr))); \ + (void)0; \ +}) +#endif + +#define get_leXX(xx,p,field) (le##xx##_to_cpu ((p)->field)) +#define set_leXX(xx,p,field,val) do { (p)->field = cpu_to_le##xx(val); } while (0) + +#define get_le16(p,field) get_leXX (16, p, field) +#define set_le16(p,field,val) set_leXX (16, p, field, val) + +#define get_le32(p,field) get_leXX (32, p, field) +#define set_le32(p,field,val) set_leXX (32, p, field, val) + +#define get_le64(p,field) get_leXX (64, p, field) +#define set_le64(p,field,val) set_leXX (64, p, field, val) + +/***************************************************************************/ +/* SUPER BLOCK */ +/***************************************************************************/ + +#define UNSET_HASH 0 // read_super will guess about, what hash names + // in directories were sorted with +#define TEA_HASH 1 +#define YURA_HASH 2 +#define R5_HASH 3 +#define DEFAULT_HASH R5_HASH + +/* super block of prejournalled version */ +struct reiserfs_super_block_v0 { + __le32 s_block_count; + __le32 s_free_blocks; + __le32 s_root_block; + __le16 s_blocksize; + __le16 s_oid_maxsize; + __le16 s_oid_cursize; + __le16 s_state; + char s_magic[16]; + __le16 s_tree_height; + __le16 s_bmap_nr; + __le16 s_reserved; +}; + +struct journal_params { + __le32 jp_journal_1st_block; /* where does journal start from on its + device */ + __le32 jp_journal_dev; /* journal device st_rdev */ + __le32 jp_journal_size; /* size of the journal on FS creation. used to + make sure they don't overflow it */ + __le32 jp_journal_trans_max; /* max number of blocks in a transaction. */ + __le32 jp_journal_magic; /* random value made on fs creation (this was + sb_journal_block_count) */ + __le32 jp_journal_max_batch; /* max number of blocks to batch into a trans */ + __le32 jp_journal_max_commit_age; /* in seconds, how old can an async commit be */ + __le32 jp_journal_max_trans_age; /* in seconds, how old can a transaction be */ +}; + +#define get_jp_journal_1st_block(jp) get_le32 (jp, jp_journal_1st_block) +#define set_jp_journal_1st_block(jp,val) set_le32 (jp, jp_journal_1st_block, val) + +#define get_jp_journal_dev(jp) get_le32 (jp, jp_journal_dev) +#define set_jp_journal_dev(jp,val) set_le32 (jp, jp_journal_dev, val) + +#define get_jp_journal_size(jp) get_le32 (jp, jp_journal_size) +#define set_jp_journal_size(jp,val) set_le32 (jp, jp_journal_size, val) + +#define get_jp_journal_max_trans_len(jp) get_le32 (jp, jp_journal_trans_max) +#define set_jp_journal_max_trans_len(jp,val) set_le32 (jp, jp_journal_trans_max, val) + +#define get_jp_journal_magic(jp) get_le32 (jp, jp_journal_magic) +#define set_jp_journal_magic(jp,val) set_le32 (jp, jp_journal_magic, val) + +#define NEED_TUNE 0xffffffff + +#define get_jp_journal_max_batch(jp) get_le32 (jp, jp_journal_max_batch) +#define set_jp_journal_max_batch(jp,val) set_le32 (jp, jp_journal_max_batch, val) + +#define get_jp_journal_max_commit_age(jp) get_le32 (jp, jp_journal_max_commit_age) +#define set_jp_journal_max_commit_age(jp,val) set_le32 (jp, jp_journal_max_commit_age, val) + +#define get_jp_journal_max_trans_age(jp) get_le32 (jp, jp_journal_max_commit_age) +#define set_jp_journal_max_trans_age(jp,val) set_le32 (jp, jp_journal_max_commit_age, val) + +/* this is the super from 3.5.X */ +struct reiserfs_super_block_v1 { + __le32 sb_block_count; /* 0 number of block on data device */ + __le32 sb_free_blocks; /* 4 free blocks count */ + __le32 sb_root_block; /* 8 root of the tree */ + + struct journal_params sb_journal; /* 12 */ + + __le16 sb_blocksize; /* 44 */ + __le16 sb_oid_maxsize; /* 46 max size of object id array, see + get_objectid() commentary */ + __le16 sb_oid_cursize; /* 48 current size of object id array */ + __le16 sb_umount_state; /* 50 this is set to 1 when filesystem was + umounted, to 2 - when not */ + + char s_magic[10]; /* 52 reiserfs magic string indicates that + file system is reiserfs: "ReIsErFs" or + "ReIsEr2Fs" or "ReIsEr3Fs" */ + __le16 sb_fs_state; /* 62 it is set to used by fsck to mark which phase of + rebuilding is done (used for fsck debugging) */ + __le32 sb_hash_function_code; /* 64 code of fuction which was/is/will be + used to sort names in a directory. See + codes in above */ + __le16 sb_tree_height; /* 68 height of filesytem tree. Tree + consisting of only one root block has 2 + here */ + __le16 sb_bmap_nr; /* 70 amount of bitmap blocks needed to + address each block of file system */ + __le16 sb_version; /* 72 this field is only reliable on + filesystem with non-standard journal */ + __le16 sb_reserved_for_journal; /* 74 size in blocks of journal area on + main device, we need to keep after + non-standard journal relocation */ +}; + +#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1)) /* 76 bytes */ + +#define sb_jp(sb) (&((sb)->s_v1.sb_journal)) + +/* values for sb_version field of struct reiserfs_super_block. sb_version is + only reliable on filesystem with non-standard journal */ +#define REISERFS_FORMAT_3_5 0 +#define REISERFS_FORMAT_3_6 2 +#define REISERFS_FORMAT_UNKNOWN -1 + +/* values for sb_mount_state field */ +#define FS_CLEANLY_UMOUNTED 1 /* this was REISERFS_VALID_FS */ +#define FS_NOT_CLEANLY_UMOUNTED 2 /* this was REISERFS_ERROR. It + means that filesystem was not + cleanly unmounted */ + +/* Structure of super block on disk */ +struct reiserfs_super_block { +/* 0 */ struct reiserfs_super_block_v1 s_v1; +/* 76 */ __le32 sb_inode_generation; + /* 80 */ __le32 s_flags; + /* Right now used only by inode-attributes, if enabled */ + /* 84 */ unsigned char s_uuid[16]; + /* filesystem unique identifier */ + /*100 */ char s_label[16]; + /* filesystem volume label */ +/*116 */ __le16 s_mnt_count; +/*118 */ __le16 s_max_mnt_count; +/*120 */ __le32 s_lastcheck; +/*124 */ __le32 s_check_interval; + /*128 */ char s_unused[76]; + /* zero filled by mkreiserfs and reiserfs_convert_objectid_map_v1() + * so any additions must be updated there as well. */ +/*204*/ +} __attribute__ ((__packed__));; + +typedef enum { + reiserfs_attrs_cleared = 0x00000001, +} reiserfs_super_block_flags; + +#define SB_SIZE (sizeof(struct reiserfs_super_block)) /* 204 bytes */ + +/* set/get fields of super block with these defines */ +#define get_sb_block_count(sb) get_le32 (sb, s_v1.sb_block_count) +#define set_sb_block_count(sb,val) set_le32 (sb, s_v1.sb_block_count, val) + +#define get_sb_free_blocks(sb) get_le32 (sb, s_v1.sb_free_blocks) +#define set_sb_free_blocks(sb,val) set_le32 (sb, s_v1.sb_free_blocks, val) + +#define get_sb_root_block(sb) get_le32 (sb,s_v1.sb_root_block) +#define set_sb_root_block(sb,val) set_le32 (sb, s_v1.sb_root_block, val) + +#if 0 +#define get_sb_mount_id(sb) get_le32 (sb,s_v1.sb_mountid) +#define set_sb_mount_id(sb,val) set_le32 (sb, s_v1.sb_mountid, val) + +#define get_sb_journal_magic(sb) get_le32 (sb, s_v1.sb_journal_magic) +#define set_sb_journal_magic(sb,val) set_le32 (sb, s_v1.sb_journal_magic, val) +#endif + +#define get_sb_block_size(sb) get_le16 (sb, s_v1.sb_blocksize) +#define set_sb_block_size(sb,val) set_le16 (sb, s_v1.sb_blocksize, val) + +#define get_sb_oid_maxsize(sb) get_le16 (sb, s_v1.sb_oid_maxsize) +#define set_sb_oid_maxsize(sb,val) set_le16 (sb, s_v1.sb_oid_maxsize, val) + +#define get_sb_oid_cursize(sb) get_le16 (sb, s_v1.sb_oid_cursize) +#define set_sb_oid_cursize(sb,val) set_le16 (sb, s_v1.sb_oid_cursize, val) + +#define get_sb_umount_state(sb) get_le16 (sb, s_v1.sb_umount_state) +#define set_sb_umount_state(sb,val) set_le16 (sb, s_v1.sb_umount_state, val) + +#define get_sb_fs_state(sb) get_le16 (sb, s_v1.sb_fs_state) +#define set_sb_fs_state(sb,flag) set_le16 (sb, s_v1.sb_fs_state, flag) + +#define get_sb_hash_code(sb) get_le32 (sb, s_v1.sb_hash_function_code) +#define set_sb_hash_code(sb,val) set_le32 (sb, s_v1.sb_hash_function_code, val) + +#define get_sb_tree_height(sb) get_le16 (sb, s_v1.sb_tree_height) +#define set_sb_tree_height(sb,val) set_le16 (sb, s_v1.sb_tree_height, val) + +#define get_sb_bmap_nr(sb) get_le16 (sb, s_v1.sb_bmap_nr) +#define set_sb_bmap_nr(sb,val) set_le16 (sb, s_v1.sb_bmap_nr, val) + +#define get_sb_version(sb) get_le16 (sb, s_v1.sb_version) +#define set_sb_version(sb,val) set_le16 (sb, s_v1.sb_version, val) + +#define get_sb_reserved_for_journal(sb) get_le16 (sb, s_v1.sb_reserved_for_journal) +#define set_sb_reserved_for_journal(sb,val) set_le16 (sb, s_v1.sb_reserved_for_journal, val) + +#define get_sb_v2_inode_generation(sb) get_le32 (sb, sb_inode_generation) +#define set_sb_v2_inode_generation(sb,val) set_le32 (sb, sb_inode_generation, val) + +#define get_sb_v2_mnt_count(sb) get_le16 (sb, s_mnt_count) +#define set_sb_v2_mnt_count(sb,val) set_le16 (sb, s_mnt_count, val) + +#define get_sb_v2_max_mnt_count(sb) \ + get_le16 (sb, s_max_mnt_count) +#define set_sb_v2_max_mnt_count(sb,val) \ + set_le16 (sb, s_max_mnt_count, val) + +#define get_sb_v2_lastcheck(sb) get_le32 (sb, s_lastcheck) +#define set_sb_v2_lastcheck(sb,val) set_le32 (sb, s_lastcheck, val) + +#define get_sb_v2_check_interval(sb) \ + get_le32 (sb, s_check_interval) +#define set_sb_v2_check_interval(sb,val) \ + set_le32 (sb, s_check_interval, val) + +#define get_sb_v2_flags(sb) get_le32 (sb, s_flags) +#define set_sb_v2_flags(sb, val) set_le32 (sb, s_flags, val) + +#define get_sb_v2_flag(sb, flag) (get_le32 (sb, s_flags) & flag) +#define set_sb_v2_flag(sb, flag) set_le32 (sb, s_flags, get_le32 (sb, s_flags) | flag) +#define clear_sb_v2_flag(sb, flag) set_le32 (sb, s_flags, get_le32 (sb, s_flags) & ~(flag)) + +/* +#define journal_is_relocated(sb) get_jp_journal_dev(sb_jp (sb)) +*/ + +#define DEFAULT_MAX_MNT_COUNT 30 /* 30 mounts */ +#define DEFAULT_CHECK_INTERVAL (180 * 60 * 60 * 24) /* 180 days */ + +/* these are possible values for sb_fs_state */ +#define FS_CONSISTENT 0x0 /* this is set by mkreiserfs and by reiserfsck */ +#define FS_ERROR 0x1 /* this is set by the kernel when fsck is wanted. */ +#define FS_FATAL 0x2 /* this is set by fsck when fatal corruption is found */ +#define IO_ERROR 0x4 /* this is set by kernel when io error occures */ +#define PASS_0_DONE 0xfa02 /* set by fsck when pass-by-pass (-d), + FS_FATAL flag included */ +#define PASS_1_DONE 0xfb02 /* set by fsck when pass-by-pass (-d), + FS_FATAL flag included */ +#define TREE_IS_BUILT 0xfc02 /* set by fsck when pass-by-pass (-d), + FS_FATAL flag included */ +#define SEMANTIC_DONE 0xfd02 /* set by fsck when pass-by-pass (-d), + FS_FATAL flag included */ +#define LOST_FOUND_DONE 0xfe02 /* set by fsck when pass-by-pass (-d), + FS_FATAL flag included */ + +/* struct stat_data* access macros */ +/* v1 */ +#define sd_v1_mode(sd) (le16_to_cpu((sd)->sd_mode)) +#define set_sd_v1_mode(sd,n) ((sd)->sd_mode = cpu_to_le16((n))) +#define sd_v1_nlink(sd) (le16_to_cpu((sd)->sd_nlink)) +#define set_sd_v1_nlink(sd,n) ((sd)->sd_nlink = cpu_to_le16((n))) +#define sd_v1_uid(sd) (le16_to_cpu((sd)->sd_uid)) +#define set_sd_v1_uid(sd,n) ((sd)->sd_uid = cpu_to_le16((n))) +#define sd_v1_gid(sd) (le16_to_cpu((sd)->sd_gid)) +#define set_sd_v1_gid(sd,n) ((sd)->sd_gid = cpu_to_le16((n))) +#define sd_v1_size(sd) (le32_to_cpu((sd)->sd_size)) +#define set_sd_v1_size(sd,n) ((sd)->sd_size = cpu_to_le32((n))) +#define sd_v1_atime(sd) (le32_to_cpu((sd)->sd_atime)) +#define set_sd_v1_atime(sd,n) ((sd)->sd_atime = cpu_to_le32((n))) +#define sd_v1_mtime(sd) (le32_to_cpu((sd)->sd_mtime)) +#define set_sd_v1_mtime(sd,n) ((sd)->sd_mtime = cpu_to_le32((n))) +#define sd_v1_ctime(sd) (le32_to_cpu((sd)->sd_ctime)) +#define set_sd_v1_ctime(sd,n) ((sd)->sd_ctime = cpu_to_le32((n))) +#define sd_v1_blocks(sd) (le32_to_cpu((sd)->u.sd_blocks)) +#define set_sd_v1_blocks(sd,n) ((sd)->u.sd_blocks = cpu_to_le32((n))) +#define sd_v1_rdev(sd) (le32_to_cpu((sd)->u.sd_rdev)) +#define set_sd_v1_rdev(sd,n) ((sd)->u.sd_rdev = cpu_to_le32((n))) +#define sd_v1_first_direct_byte(sd) (le32_to_cpu((sd)->sd_first_direct_byte)) +#define set_sd_v1_first_direct_byte(sd,n) \ + ((sd)->sd_first_direct_byte = cpu_to_le32((n))) +/* v2 */ +#define sd_v2_mode(sd) (le16_to_cpu((sd)->sd_mode)) +#define set_sd_v2_mode(sd,n) ((sd)->sd_mode = cpu_to_le16((n))) +#define sd_v2_sd_attrs(sd) (le16_to_cpu((sd)->sd_attrs)) +#define set_sd_v2_sd_attrs(sd,n) ((sd)->sd_attrs = cpu_to_le16((n))) +#define sd_v2_nlink(sd) (le32_to_cpu((sd)->sd_nlink)) +#define set_sd_v2_nlink(sd,n) ((sd)->sd_nlink = cpu_to_le32((n))) +#define sd_v2_size(sd) (le64_to_cpu((sd)->sd_size)) +#define set_sd_v2_size(sd,n) ((sd)->sd_size = cpu_to_le64((n))) +#define sd_v2_uid(sd) (le32_to_cpu((sd)->sd_uid)) +#define set_sd_v2_uid(sd,n) ((sd)->sd_uid = cpu_to_le32((n))) +#define sd_v2_gid(sd) (le32_to_cpu((sd)->sd_gid)) +#define set_sd_v2_gid(sd,n) ((sd)->sd_gid = cpu_to_le32((n))) +#define sd_v2_atime(sd) (le32_to_cpu((sd)->sd_atime)) +#define set_sd_v2_atime(sd,n) ((sd)->sd_atime = cpu_to_le32((n))) +#define sd_v2_mtime(sd) (le32_to_cpu((sd)->sd_mtime)) +#define set_sd_v2_mtime(sd,n) ((sd)->sd_mtime = cpu_to_le32((n))) +#define sd_v2_ctime(sd) (le32_to_cpu((sd)->sd_ctime)) +#define set_sd_v2_ctime(sd,n) ((sd)->sd_ctime = cpu_to_le32((n))) +#define sd_v2_blocks(sd) (le32_to_cpu((sd)->sd_blocks)) +#define set_sd_v2_blocks(sd,n) ((sd)->sd_blocks = cpu_to_le32((n))) +#define sd_v2_rdev(sd) (le32_to_cpu((sd)->u.sd_rdev)) +#define set_sd_v2_rdev(sd,n) ((sd)->u.sd_rdev = cpu_to_le32((n))) + +/* ReiserFS leaves the first 64k unused, so that partition labels have enough + space. If someone wants to write a fancy bootloader that needs more than + 64k, let us know, and this will be increased in size. This number must be + larger than than the largest block size on any platform, or code will + break. -Hans */ +#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024) + +/*#define MD_RAID_SUPERBLOCKS_IN_BYTES (128 * 1024)*/ + +/* the spot for the super in versions 3.5 - 3.5.11 (inclusive) */ +#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024) + +/* prejournalled reiserfs had signature in the other place in super block */ +#define REISERFS_SUPER_MAGIC_STRING_OFFSET_NJ 20 + +/* f_type of struct statfs will be set at this value by statfs(2) */ +#define REISERFS_SUPER_MAGIC 0x52654973 + +/* various reiserfs signatures. We have 3 so far. ReIsErFs for 3.5 format with + standard journal, ReIsEr2Fs for 3.6 (or converted 3.5) and ReIsEr3Fs for + filesystem with non-standard journal (formats are distinguished by + sb_version in that case). Those signatures should be looked for at the + 64-th and at the 8-th 1k block of the device */ +#define REISERFS_3_5_SUPER_MAGIC_STRING "ReIsErFs" +#define REISERFS_3_6_SUPER_MAGIC_STRING "ReIsEr2Fs" +#define REISERFS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs" /* JR stands for Journal + Relocation */ + +#define get_reiserfs_ondisk_offset(block_of_super_block, block_size) \ + (block_of_super_block * block_size) + +#define is_new_sb_location(block_of_super_block, block_size) \ + ((get_reiserfs_ondisk_offset(block_of_super_block, block_size) == REISERFS_DISK_OFFSET_IN_BYTES) \ + ? 1 : 0) + +/*only 4k blocks for old location*/ +#define is_old_sb_location(block_of_super_block, block_size) \ + ((get_reiserfs_ondisk_offset(block_of_super_block, 4096) == REISERFS_OLD_DISK_OFFSET_IN_BYTES) \ + ? 1 : 0) + +/***************************************************************************/ +/* JOURNAL */ +/***************************************************************************/ + +#define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick. magic string to find desc + blocks in the journal */ + +/* journal.c see journal.c for all the comments here */ + +//#define JOURNAL_TRANS_HALF 1018 /* must be correct to keep the desc and commit structs at 4k */ + +/* first block written in a commit. BUG, not 64bit safe */ +struct reiserfs_journal_desc { + __le32 j2_trans_id; /* id of commit */ + __le32 j2_len; /* length of commit. len +1 is the commit block */ + __le32 j2_mount_id; /* mount id of this trans */ + __le32 j2_realblock[1]; /* real locations for each block */ +}; + +#define get_jd_magic(bh) (bh->b_data + bh->b_size - 12) + +#define journal_trans_half(blocksize) \ +((blocksize - sizeof (struct reiserfs_journal_desc) + sizeof (__le32) - 12) / sizeof (__le32)) + +#define jdesc_header(bh) ((struct reiserfs_journal_desc *)bh->b_data) + +#define get_desc_trans_id(bh) get_le32 (jdesc_header (bh), j2_trans_id) +#define set_desc_trans_id(bh,val) set_le32 (jdesc_header (bh), j2_trans_id, val) + +#define get_desc_trans_len(bh) get_le32 (jdesc_header (bh), j2_len) +#define set_desc_trans_len(bh,val) set_le32 (jdesc_header (bh), j2_len, val) + +#define get_desc_mount_id(bh) get_le32 (jdesc_header (bh), j2_mount_id) +#define set_desc_mount_id(bh,val) set_le32 (jdesc_header (bh), j2_mount_id, val) + +/* last block written in a commit BUG, not 64bit safe */ +struct reiserfs_journal_commit { + __le32 j3_trans_id; /* must match j_trans_id from the desc block */ + __le32 j3_len; /* ditto */ + __le32 j3_realblock[1]; /* real locations for each block */ +}; + +#define jcommit_header(bh) ((struct reiserfs_journal_commit *)bh->b_data) + +#define get_commit_trans_id(bh) get_le32 (jcommit_header(bh), j3_trans_id) +#define set_commit_trans_id(bh,val) set_le32 (jcommit_header(bh), j3_trans_id, val) + +#define get_commit_trans_len(bh) get_le32 (jcommit_header(bh), j3_len) +#define set_comm_trans_len(bh,val) set_le32 (jcommit_header(bh), j3_len, val) + +/* this header block gets written whenever a transaction is considered fully +** flushed, and is more recent than the last fully flushed transaction. fully +** flushed means all the log blocks and all the real blocks are on disk, and +** this transaction does not need to be replayed. */ +struct reiserfs_journal_header { + __le32 jh_last_flush_trans_id; /* id of last fully flushed transaction */ + __le32 jh_first_unflushed_offset; /* offset in the log of where to start replay after a crash */ + __le32 jh_mount_id; + + struct journal_params jh_journal; + + __le32 jh_last_check_mount_id; /* the mount id of the fs during the last reiserfsck --check. */ +}; + +/* set/get fields of journal header with these defines */ +#define get_jh_mount_id(jh) get_le32 (jh, jh_mount_id) +#define set_jh_mount_id(jh,val) set_le32 (jh, jh_mount_id, val) + +#define get_jh_last_flushed(jh) get_le32 (jh, jh_last_flush_trans_id) +#define set_jh_last_flushed(jh,val) set_le32 (jh, jh_last_flush_trans_id, val) + +#define get_jh_replay_start_offset(jh) get_le32 (jh, jh_first_unflushed_offset) +#define set_jh_replay_start_offset(jh,val) set_le32 (jh, jh_first_unflushed_offset, val) + +/* journal default settings */ + +#define JOURNAL_MIN_SIZE 512 +#define JOURNAL_TRANS_MAX 1024 /* biggest possible single transaction, don't + change for now (8/3/99) */ +#define JOURNAL_TRANS_MIN 256 /* need to check whether it works */ +#define JOURNAL_DEFAULT_RATIO 8 /* default journal size / max trans length */ +#define JOURNAL_MIN_RATIO 2 +#define JOURNAL_MAX_BATCH 900 /* max blocks to batch into one transaction, + don't make this any bigger than 900 */ +#define JOURNAL_MAX_COMMIT_AGE 30 +#define JOURNAL_MAX_TRANS_AGE 30 + +/* journal max size is a maximum number of blocks pointed by first bitmap - + REISERFS_DISK_OFFSET - superblock - first bitmap - journal herader */ +#define journal_max_size(block_of_super_block,blocksize) \ + blocksize * 8 - (block_of_super_block + 1 + 1 + 1) + +#define journal_default_size(block_of_super_block,blocksize) \ + (unsigned long long)((8192 > journal_max_size (block_of_super_block,blocksize)) ? \ + journal_max_size (block_of_super_block,blocksize) : 8192) + +int reiserfs_replay_journal(reiserfs_filsys_t fs); + +//#define JOURNAL_DEFAULT_SIZE 8192 number of blocks in the journal +//#define JOURNAL_DEFAULT_SIZE_FOR_BS_1024 8125 number of blocks in the journal for block size 1KB + +#define bh_desc(bh) ((struct reiserfs_journal_desc *)((bh)->b_data)) +#define bh_commit(bh) ((struct reiserfs_journal_commit *)((bh)->b_data)) + +/***************************************************************************/ +/* KEY & ITEM HEAD */ +/***************************************************************************/ + +struct offset_v1 { + __le32 k_offset; + __le32 k_uniqueness; +} __attribute__ ((__packed__)); + +/* + * little endian structure: + * bits 0-59 [60]: offset + * bits 60-63 [4]: type + */ +struct offset_v2 { + __le64 v; +} __attribute__ ((__packed__)); + +/* Key of the object determines object's location in the tree, composed of 4 components */ +struct reiserfs_key { + __le32 k2_dir_id; /* packing locality: by default parent directory object id */ + __le32 k2_objectid; /* object identifier */ + union { + struct offset_v1 k2_offset_v1; + struct offset_v2 k2_offset_v2; + } __attribute__ ((__packed__)) u; +} __attribute__ ((__packed__)); + +extern const struct reiserfs_key MIN_KEY, MAX_KEY; + +/* set/get fields of keys on disk with these defines */ +#define get_key_dirid(k) get_le32 (k, k2_dir_id) +#define set_key_dirid(k,val) set_le32 (k, k2_dir_id, val) + +#define get_key_objectid(k) get_le32 (k, k2_objectid) +#define set_key_objectid(k,val) set_le32 (k, k2_objectid, val) + +#define get_key_offset_v1(k) get_le32 (k, u.k2_offset_v1.k_offset) +#define set_key_offset_v1(k,val) set_le32 (k, u.k2_offset_v1.k_offset, val) + +#define get_key_uniqueness(k) get_le32 (k, u.k2_offset_v1.k_uniqueness) +#define set_key_uniqueness(k,val) set_le32 (k, u.k2_offset_v1.k_uniqueness, val) + +/* +#define get_key_offset_v2(k) get_le64 (k, u.k2_offset_v2.k_offset) +#define set_key_offset_v2(k,val) set_le64 (k, u.k2_offset_v2.k_offset, val) +*/ +/* ??? */ +/* +#define get_key_type(k) get_le16 (k, u.k2_offset_v2.k_type) +#define set_key_type(k,val) set_le16 (k, u.k2_offset_v2.k_type, val) +*/ +/* +#define key_dir_id(key) (le32_to_cpu((key)->k_dir_id)) +#define set_key_dir_id(key,n) ((key)->k_dir_id = cpu_to_le32((n))) +#define key_objectid(key) (le32_to_cpu((key)->k_objectid)) +#define set_key_objectid(key,n) ((key)->k_objectid = cpu_to_le32((n))) +*/ + +#define KEY_SIZE (sizeof(struct reiserfs_key)) +#define SHORT_KEY_SIZE 8 + +// values for k_uniqueness field of the struct reiserfs_key +#define V1_SD_UNIQUENESS 0 +#define V1_DIRENTRY_UNIQUENESS 500 +#define DIRENTRY_UNIQUENESS 500 +#define V1_DIRECT_UNIQUENESS 0xffffffff +#define V1_INDIRECT_UNIQUENESS 0xfffffffe +#define V1_UNKNOWN_UNIQUENESS 555 + +// values for k_type field of the struct reiserfs_key +#define TYPE_STAT_DATA 0 +#define TYPE_INDIRECT 1 +#define TYPE_DIRECT 2 +#define TYPE_DIRENTRY 3 +#define TYPE_MAXTYPE 4 + +#define TYPE_UNKNOWN 15 + +/* special type for symlink not conflicting to any of item types. */ +#define TYPE_SYMLINK 4 + +#define KEY_FORMAT_1 0 +#define KEY_FORMAT_2 1 +#define KEY_FORMAT_UNDEFINED 15 + + /* Our function for comparing keys can compare keys of different lengths. It + takes as a parameter the length of the keys it is to compare. These + defines are used in determining what is to be passed to it as that + parameter. */ +#define REISERFS_FULL_KEY_LEN 4 + +#define REISERFS_SHORT_KEY_LEN 2 + +/* Everything in the filesystem is stored as a set of items. The item head + contains the key of the item, its free space (for indirect items) and + specifies the location of the item itself within the block. */ + +struct item_head { + struct reiserfs_key ih_key; /* Everything in the tree is found by searching for it + based on its key. */ + + union { + __le16 ih2_free_space; /* The free space in the last unformatted node + of an indirect item if this is an indirect + item. This equals 0xFFFF iff this is a direct + item or stat data item. Note that the key, not + this field, is used to determine the item + type, and thus which field this union + contains. */ + __le16 ih2_entry_count; /* Iff this is a directory item, this field + equals the number of directory entries in + the directory item. */ + } __attribute__ ((__packed__)) u; + __le16 ih2_item_len; /* total size of the item body */ + __le16 ih2_item_location; /* an offset to the item body within the + block */ + + __le16 ih_format; /* key format is stored in bits 0-11 of this item + flags are stored in bits 12-15 */ +#if 0 + struct { + __le16 key_format:12; /* KEY_FORMAT_1 or KEY_FORMAT_2. This is not + necessary, but we have space, let use it */ + __le16 flags:4; /* fsck set here its flag (reachable/unreachable) */ + } __attribute__ ((__packed__)) ih2_format; +#endif +} __attribute__ ((__packed__)); + +/* size of item header */ +#define IH_SIZE (sizeof(struct item_head)) + +/* set/get fields of item head on disk with these defines */ +#define get_ih_entry_count(ih) get_le16 (ih, u.ih2_entry_count) +#define set_ih_entry_count(ih,val) set_le16 (ih, u.ih2_entry_count, val) + +#define get_ih_free_space(ih) get_le16 (ih, u.ih2_free_space) +#define set_ih_free_space(ih,val) set_le16 (ih, u.ih2_free_space, 0) + +#define get_ih_item_len(ih) get_le16 (ih, ih2_item_len) +#define set_ih_item_len(ih,val) set_le16 (ih, ih2_item_len, val) + +#define get_ih_location(ih) get_le16 (ih, ih2_item_location) +#define set_ih_location(ih,val) set_le16 (ih, ih2_item_location, val) + +__u16 get_ih_flags(const struct item_head *ih); +__u16 get_ih_key_format(const struct item_head *ih); +void set_ih_flags(struct item_head *ih, __u16 val); +void set_ih_key_format(struct item_head *ih, __u16 val); + +/* +#define get_ih_key_format(ih) get_le16 (ih, ih2_format.key_format) +#define set_ih_key_format(ih,val) set_le16 (ih, ih2_format.key_format, val) + +#define get_ih_flags(ih) get_le16 (ih, ih2_format.flags) +#define set_ih_flags(ih,val) set_le16 (ih, ih2_format.flags, val) +*/ + +#define I_K_KEY_IN_ITEM(p_s_ih, p_s_key, n_blocksize) \ + ( ! not_of_one_file(p_s_ih, p_s_key) && \ + I_OFF_BYTE_IN_ITEM(p_s_ih, get_offset (p_s_key), n_blocksize) ) + +#define IH_Unreachable 0 +#define IH_Was_Tail 1 +#define IH_Checked 2 +#define IH_Writable 3 + +/* Unreachable bit is set on tree rebuilding and is cleared in semantic pass */ +#define clean_ih_flags(ih) set_ih_flags (ih, 0) + +#define ih_reachable(ih) (!(get_ih_flags (ih) & (1 << IH_Unreachable))) +#define mark_ih_reachable(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Unreachable)) +#define mark_ih_unreachable(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Unreachable)) + +#define ih_was_tail(ih) (get_ih_flags (ih) & (1 << IH_Was_Tail)) +#define mark_ih_was_tail(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Was_Tail)) +#define mark_ih_become_tail(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Was_Tail)) + +#define ih_checked(ih) (get_ih_flags (ih) & (1 << IH_Checked)) +#define mark_ih_checked(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Checked)) +#define clear_ih_checked(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Checked)) + +#define ih_writable(ih) (get_ih_flags (ih) & (1 << IH_Writable)) +#define mark_ih_writable(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Writable)) +#define clear_ih_writable(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Writable)) + +/* maximal length of item */ +#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE) +#define MIN_ITEM_LEN 1 + +/* object identifier for root dir */ +#define REISERFS_ROOT_OBJECTID 2 +#define REISERFS_ROOT_PARENT_OBJECTID 1 + +/* + * Picture represents a leaf of internal tree + * ______________________________________________________ + * | | Array of | | | + * |Block | Object-Item | F r e e | Objects- | + * | head | Headers | S p a c e | Items | + * |______|_______________|___________________|___________| + */ + +/* Header of a disk block. More precisely, header of a formatted leaf + or internal node, and not the header of an unformatted node. */ +struct block_head { + __le16 blk2_level; /* Level of a block in the tree. */ + __le16 blk2_nr_item; /* Number of keys/items in a block. */ + __le16 blk2_free_space; /* Block free space in bytes. */ + __le16 blk_reserved; + __le32 reserved[4]; +}; + +#define BLKH_SIZE (sizeof(struct block_head)) + +/* set/get fields of block head on disk with these defines */ +#define get_blkh_level(blkh) get_le16 (blkh, blk2_level) +#define set_blkh_level(blkh,val) set_le16 (blkh, blk2_level, val) + +#define get_blkh_nr_items(blkh) get_le16 (blkh, blk2_nr_item) +#define set_blkh_nr_items(blkh,val) set_le16 (blkh, blk2_nr_item, val) + +#define get_blkh_free_space(blkh) get_le16 (blkh, blk2_free_space) +#define set_blkh_free_space(blkh,val) set_le16 (blkh, blk2_free_space, val) + +/* + * values for blk_type field + */ + +#define FREE_LEVEL 0 /* Node of this level is out of the tree. */ +#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */ + +#define is_leaf_block_head(buf) (get_blkh_level ((struct block_head *)(buf)) == DISK_LEAF_NODE_LEVEL) +#define is_internal_block_head(buf) \ +((get_blkh_level (((struct block_head *)(buf))) > DISK_LEAF_NODE_LEVEL) &&\ + (get_blkh_level (((struct block_head *)(buf))) <= MAX_HEIGHT)) + +/* Given the buffer head of a formatted node, resolve to the block head of that node. */ +#define B_BLK_HEAD(p_s_bh) ((struct block_head *)((p_s_bh)->b_data)) + +#define B_NR_ITEMS(bh) get_blkh_nr_items (B_BLK_HEAD(bh)) +#define B_LEVEL(bh) get_blkh_level (B_BLK_HEAD(bh)) +#define B_FREE_SPACE(bh) get_blkh_free_space (B_BLK_HEAD(bh)) + +#define is_leaf_node(bh) is_leaf_block_head ((bh)->b_data) +#define is_internal_node(bh) is_internal_block_head ((bh)->b_data) + +/***************************************************************************/ +/* STAT DATA */ +/***************************************************************************/ + +/* Stat Data on disk (reiserfs version of UFS disk inode minus the address blocks) */ + +/* The sense of adding union to stat data is to keep a value of real number of + blocks used by file. The necessity of adding such information is caused by + existing of files with holes. Reiserfs should keep number of used blocks + for file, but not calculate it from file size (that is not correct for + holed files). Thus we have to add additional information to stat data. + When we have a device special file, there is no need to get number of used + blocks for them, and, accordingly, we doesn't need to keep major and minor + numbers for regular files, which might have holes. So this field is being + overloaded. */ + +struct stat_data_v1 { + __le16 sd_mode; /* file type, permissions */ + __le16 sd_nlink; /* number of hard links */ + __le16 sd_uid; /* owner */ + __le16 sd_gid; /* group */ + __le32 sd_size; /* file size */ + __le32 sd_atime; /* time of last access */ + __le32 sd_mtime; /* time file was last modified */ + __le32 sd_ctime; /* time inode (stat data) was last changed (except + changes to sd_atime and sd_mtime) */ + union { + __le32 sd_rdev; + __le32 sd_blocks; /* number of blocks file uses */ + } __attribute__ ((__packed__)) u; + __le32 sd_first_direct_byte; /* first byte of file which is stored + in a direct item: except that if it + equals 1 it is a symlink and if it + equals MAX_KEY_OFFSET there is no + direct item. The existence of this + field really grates on me. Let's + replace it with a macro based on + sd_size and our tail suppression + policy. Someday. -Hans */ +} __attribute__ ((__packed__)); +#define SD_V1_SIZE (sizeof(struct stat_data_v1)) + +/* this is used to check sd_size of stat data v1 */ +#define MAX_FILE_SIZE_V1 0x7fffffff + +// sd_first_direct_byte is set to this when there are no direct items in a +// file +#define NO_BYTES_IN_DIRECT_ITEM 0xffffffff + +/* Stat Data on disk (reiserfs version of UFS disk inode minus the + address blocks) */ +struct stat_data { + __le16 sd_mode; /* file type, permissions */ + __le16 sd_attrs; + __le32 sd_nlink; /* 32 bit nlink! */ + __le64 sd_size; /* 64 bit size! */ + __le32 sd_uid; /* 32 bit uid! */ + __le32 sd_gid; /* 32 bit gid! */ + __le32 sd_atime; /* time of last access */ + __le32 sd_mtime; /* time file was last modified */ + __le32 sd_ctime; /* time inode (stat data) was last changed (except + changes to sd_atime and sd_mtime) */ + __le32 sd_blocks; + union { + __le32 sd_rdev; + __le32 sd_generation; + //__le32 sd_first_direct_byte; + /* first byte of file which is stored in a direct item: except that if + it equals 1 it is a symlink and if it equals ~(__le32)0 there is no + direct item. The existence of this field really grates on me. Let's + replace it with a macro based on sd_size and our tail suppression + policy? */ + } __attribute__ ((__packed__)) u; +} __attribute__ ((__packed__)); +// +// this is 44 bytes long +// +#define SD_SIZE (sizeof(struct stat_data)) + +// there are two ways: to check length of item or ih_format field +// (for old stat data it is set to 0 (KEY_FORMAT_1)) +#define stat_data_v1(ih) (get_ih_key_format (ih) == KEY_FORMAT_1) + +/* this is used to check sd_size of stat data v2: max offset which can + be reached with a key of format 2 is 60 bits */ +#define MAX_FILE_SIZE_V2 0xfffffffffffffffLL + +/***************************************************************************/ +/* DIRECTORY STRUCTURE */ +/***************************************************************************/ +/* + Picture represents the structure of directory items + ________________________________________________ + | Array of | | | | | | + | directory |N-1| N-2 | .... | 1st |0th| + | entry headers | | | | | | + |_______________|___|_____|________|_______|___| + <---- directory entries ------> + + First directory item has k_offset component 1. We store "." and ".." + in one item, always, we never split "." and ".." into differing + items. This makes, among other things, the code for removing + directories simpler. */ +#define SD_OFFSET 0 +#define DOT_OFFSET 1 +#define DOT_DOT_OFFSET 2 + +/* Each directory entry has its header. This header has deh_dir_id and + deh_objectid fields, those are key of object, entry points to */ + +/* NOT IMPLEMENTED: + Directory will someday contain stat data of object */ +struct reiserfs_de_head { + __le32 deh2_offset; /* third component of the directory entry key */ + __le32 deh2_dir_id; /* objectid of the parent directory of the object, + that is referenced by directory entry */ + __le32 deh2_objectid; /* objectid of the object, that is referenced by + directory entry */ + __le16 deh2_location; /* offset of name in the whole item */ + __le16 deh2_state; /* whether 1) entry contains stat data (for future), + and 2) whether entry is hidden (unlinked) */ +} __attribute__ ((__packed__)); + +#define DEH_SIZE sizeof(struct reiserfs_de_head) + +/* set/get fields of dir entry head these defines */ +#define get_deh_offset(deh) get_le32 (deh, deh2_offset) +#define set_deh_offset(deh,val) set_le32 (deh, deh2_offset, val) + +#define get_deh_dirid(deh) get_le32 (deh, deh2_dir_id) +#define set_deh_dirid(deh,val) set_le32 (deh, deh2_dir_id, val) + +#define get_deh_objectid(deh) get_le32 (deh, deh2_objectid) +#define set_deh_objectid(deh,val) set_le32 (deh, deh2_objectid, val) + +#define get_deh_location(deh) get_le16 (deh, deh2_location) +#define set_deh_location(deh,val) set_le16 (deh, deh2_location, val) + +#define get_deh_state(deh) get_le16 (deh, deh2_state) +#define set_deh_state(deh,val) set_le16 (deh, deh2_state, val) + +#define deh_offset(deh) (le32_to_cpu ((deh)->deh_offset)) +#define deh_dir_id(deh) (le32_to_cpu ((deh)->deh_dir_id)) +#define deh_objectid(deh) (le32_to_cpu ((deh)->deh_objectid)) +#define deh_location(deh) (le16_to_cpu ((deh)->deh_location)) +#define deh_state(deh) (le16_to_cpu ((deh)->deh_state)) + +/* empty directory contains two entries "." and ".." and their headers */ +#define EMPTY_DIR_SIZE \ +(DEH_SIZE * 2 + ROUND_UP (strlen (".")) + ROUND_UP (strlen (".."))) + +/* old format directories have this size when empty */ +#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3) + +#define DEH_Statdata 0 /* not used now */ +#define DEH_Visible2 2 + +#define DEH_Bad_offset 4 /* fsck marks entries to be deleted with this flag */ +#define DEH_Bad_location 5 + +#define test_deh_state_le_bit(deh,bit) (get_deh_state (deh) & (1 << bit)) + +#define set_deh_state_le_bit(deh,bit) \ +{\ + __u16 state;\ + state = get_deh_state (deh);\ + state |= (1 << bit);\ + set_deh_state(deh, state);\ +} + +#define clear_deh_state_le_bit(deh,bit) \ +{\ + __u16 state;\ + state = get_deh_state (deh);\ + state &= ~(1 << bit);\ + set_deh_state(deh, state);\ +} + +#define mark_de_without_sd(deh) clear_deh_state_le_bit (deh, DEH_Statdata) +#define mark_de_visible(deh) set_deh_state_le_bit (deh, DEH_Visible2) +#define mark_de_hidden(deh) clear_deh_state_le_bit (deh, DEH_Visible) + +#define de_with_sd(deh) test_deh_state_le_bit (deh, DEH_Statdata) +#define de_visible(deh) test_deh_state_le_bit (deh, DEH_Visible2) +#define de_hidden(deh) !test_deh_state_le_bit (deh, DEH_Visible2) + +/* Bad means "hashed unproperly or/and invalid location" */ +#define de_bad_location(deh) test_deh_state_le_bit (deh, DEH_Bad_location) +#define mark_de_bad_location(deh) set_deh_state_le_bit (deh, DEH_Bad_location) +#define mark_de_good_location(deh) clear_deh_state_le_bit (deh, DEH_Bad_location) + +#define de_bad_offset(deh) test_deh_state_le_bit (deh, DEH_Bad_offset) +#define mark_de_bad_offset(deh) set_deh_state_le_bit (deh, DEH_Bad_offset) + +#define de_bad(deh) (de_bad_location(deh) || de_bad_offset(deh)) + +/* for directories st_blocks is number of 512 byte units which fit into dir + size round up to blocksize */ +#define dir_size2st_blocks(size) ((size + 511) / 512) + +/* array of the entry headers */ +#define B_I_DEH(bh,ih) ((struct reiserfs_de_head *)(ih_item_body(bh,ih))) + +#define REISERFS_MAX_NAME_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE - DEH_SIZE) + /* -SD_SIZE when entry will contain stat data */ + +/* hash value occupies 24 bits starting from 7 up to 30 */ +#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80) +/* generation number occupies 7 bits starting from 0 up to 6 */ +#define GET_GENERATION_NUMBER(offset) ((offset) & 0x0000007f) + +/* + * Picture represents an internal node of the reiserfs tree + * ______________________________________________________ + * | | Array of | Array of | Free | + * |block | keys | pointers | space | + * | head | N | N+1 | | + * |______|_______________|___________________|___________| + */ + +/***************************************************************************/ +/* DISK CHILD */ +/***************************************************************************/ +/* Disk child pointer: The pointer from an internal node of the tree + to a node that is on disk. */ +struct disk_child { + __le32 dc2_block_number; /* Disk child's block number. */ + __le16 dc2_size; /* Disk child's used space. */ + __le16 dc2_reserved; +} __attribute__ ((__packed__)); + +#define DC_SIZE (sizeof(struct disk_child)) + +/* set/get fields of disk_child with these defines */ +#define get_dc_child_blocknr(dc) get_le32 (dc, dc2_block_number) +#define set_dc_child_blocknr(dc,val) set_le32 (dc, dc2_block_number, val) + +#define get_dc_child_size(dc) get_le16 (dc, dc2_size) +#define set_dc_child_size(dc,val) set_le16 (dc, dc2_size, val) + +#define set_dc(dc, size, blocknr) \ +({ \ + set_dc_child_blocknr(dc, blocknr); \ + set_dc_child_size(dc, size); \ + set_le16(dc, dc2_reserved, 0); \ +}) + +/* Get disk child by buffer header and position in the tree node. */ +#define B_N_CHILD(p_s_bh,n_pos) ((struct disk_child *)\ + ((p_s_bh)->b_data + BLKH_SIZE + B_NR_ITEMS(p_s_bh) \ + * KEY_SIZE + DC_SIZE * (n_pos))) + + /* maximal value of field child_size in structure disk_child */ + /* child size is the combined size of all items and their headers */ +#define MAX_CHILD_SIZE(blocksize) ((blocksize) - BLKH_SIZE) +#define MAX_FREE_SPACE(blocksize) MAX_CHILD_SIZE(blocksize) + +/* amount of used space in buffer (not including block head) */ +#define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur->b_size)-(B_FREE_SPACE(cur))) + +/* max and min number of keys in internal node */ +#define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh->b_size)-DC_SIZE)/(KEY_SIZE+DC_SIZE) ) +#define MIN_NR_KEY(bh) (MAX_NR_KEY(bh)/2) + +/***************************************************************************/ +/* PATH STRUCTURES AND DEFINES */ +/***************************************************************************/ + +/* Search_by_key fills up the path from the root to the leaf as it + descends the tree looking for the key. It uses reiserfs_bread to + try to find buffers in the cache given their block number. If it + does not find them in the cache it reads them from disk. For each + node search_by_key finds using reiserfs_bread it then uses + bin_search to look through that node. bin_search will find the + position of the block_number of the next node if it is looking + through an internal node. If it is looking through a leaf node + bin_search will find the position of the item which has key either + equal to given key, or which is the maximal key less than the given + key. */ + +struct reiserfs_path_element { + struct buffer_head *pe_buffer; /* Pointer to the buffer at the path in + the tree. */ + unsigned int pe_position; /* Position in the tree node which is placed + in the buffer above. */ +}; + +#define MAX_HEIGHT 6 +#define FIRST_PATH_ELEMENT_OFFSET 2 +#define EXTENDED_MAX_HEIGHT (MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET) + +#define ILLEGAL_PATH_ELEMENT_OFFSET 1 +#define MAX_FEB_SIZE (MAX_HEIGHT + 1) + +/* We need to keep track of who the ancestors of nodes are. When we + perform a search we record which nodes were visited while + descending the tree looking for the node we searched for. This list + of nodes is called the path. This information is used while + performing balancing. Note that this path information may become + invalid, and this means we must check it when using it to see if it + is still valid. You'll need to read search_by_key and the comments + in it, especially about decrement_counters_in_path(), to understand + this structure. */ +struct reiserfs_path { + unsigned int path_length; /* Length of the array above. */ + struct reiserfs_path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */ + unsigned int pos_in_item; +}; + +#define INITIALIZE_REISERFS_PATH(var) \ +struct reiserfs_path var = {ILLEGAL_PATH_ELEMENT_OFFSET, } + +/* Get path element by path and path position. */ +#define PATH_OFFSET_PELEMENT(p_s_path,n_offset) ((p_s_path)->path_elements +(n_offset)) + +/* Get buffer header at the path by path and path position. */ +#define PATH_OFFSET_PBUFFER(p_s_path,n_offset) (PATH_OFFSET_PELEMENT(p_s_path,n_offset)->pe_buffer) + +/* Get position in the element at the path by path and path position. */ +#define PATH_OFFSET_POSITION(p_s_path,n_offset) (PATH_OFFSET_PELEMENT(p_s_path,n_offset)->pe_position) + +#define PATH_PLAST_BUFFER(p_s_path) (PATH_OFFSET_PBUFFER((p_s_path), (p_s_path)->path_length)) +#define PATH_LAST_POSITION(p_s_path) (PATH_OFFSET_POSITION((p_s_path), (p_s_path)->path_length)) + +#define tp_item_head(p_s_path) item_head(PATH_PLAST_BUFFER(p_s_path),PATH_LAST_POSITION(p_s_path)) + +/* in do_balance leaf has h == 0 in contrast with path structure, + where root has level == 0. That is why we need these defines */ +#define PATH_H_PBUFFER(p_s_path, h) PATH_OFFSET_PBUFFER (p_s_path, p_s_path->path_length - (h)) /* tb->S[h] */ +#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1) /* tb->F[h] or tb->S[0]->b_parent */ +#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h)) +#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) /* tb->S[h]->b_item_order */ + +#define PATH_H_PATH_OFFSET(p_s_path, n_h) ((p_s_path)->path_length - (n_h)) + +#define get_bh(path) PATH_PLAST_BUFFER(path) +#define get_item_pos(path) PATH_LAST_POSITION(path) +#define tp_item_body(path) ((void *)item_body(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION (path))) +#define item_moved(ih,path) comp_items(ih, path) +#define path_changed(ih,path) comp_items (ih, path) + +/***************************************************************************/ +/* MISC */ +/***************************************************************************/ + +/* n must be power of 2 */ +#define _ROUND_UP(x,n) (((x)+(n)-1u) & ~((n)-1u)) + +// to be ok for alpha and others we have to align structures to 8 byte +// boundary. +// FIXME: do not change 4 by anything else: there is code which relies on that +#define ROUND_UP(x) _ROUND_UP(x,8LL) + +// search_by_key (and clones) and fix_nodes error code +#define CARRY_ON 0 + +#define NO_DISK_SPACE 3 +/* #define IO_ERROR 0x4 - defined above as 0x4 */ +#define NO_BALANCING_NEEDED 5 +#define ITEM_FOUND 6 +#define ITEM_NOT_FOUND 7 +#define GOTO_PREVIOUS_ITEM 10 +#define POSITION_FOUND_INVISIBLE 11 +#define FILE_NOT_FOUND 12 + +// used by fsck +#define DIRECTORY_NOT_FOUND 13 +#define REGULAR_FILE_FOUND 14 +#define DIRECTORY_FOUND 15 + +/* Size of pointer to the unformatted node. */ +#define UNFM_P_SIZE (sizeof(__le32)) + +#define MAX_KEY1_OFFSET 0xffffffff +#define MAX_KEY2_OFFSET 0xfffffffffffffffLL + +/* this is aggressive tail suppression policy taken from the kernel */ +/* It should be MAX_DIRECT_ITEM_LEN used here, but sometimes it is not enough, + * and items got deleted. */ +#define STORE_TAIL_IN_UNFM(n_file_size,n_tail_size,n_block_size) \ +(\ + (!(n_tail_size)) || \ + (((n_tail_size) > MAX_ITEM_LEN(n_block_size)) || \ + ( (n_file_size) >= (n_block_size) * 4 ) || \ + ( ( (n_file_size) >= (n_block_size) * 3 ) && \ + ( (n_tail_size) >= (MAX_ITEM_LEN(n_block_size))/4) ) || \ + ( ( (n_file_size) >= (n_block_size) * 2 ) && \ + ( (n_tail_size) >= (MAX_ITEM_LEN(n_block_size))/2) ) || \ + ( ( (n_file_size) >= (n_block_size) ) && \ + ( (n_tail_size) >= (MAX_ITEM_LEN(n_block_size) * 3)/4) ) ) \ +) + +/***************************************************************************/ +/* FIXATE NODES */ +/***************************************************************************/ + +#define VI_TYPE_STAT_DATA 1 +#define VI_TYPE_DIRECT 2 +#define VI_TYPE_INDIRECT 4 +#define VI_TYPE_DIRECTORY 8 +#define VI_TYPE_FIRST_DIRECTORY_ITEM 16 +#define VI_TYPE_INSERTED_DIRECTORY_ITEM 32 + +#define VI_TYPE_LEFT_MERGEABLE 64 +#define VI_TYPE_RIGHT_MERGEABLE 128 + +/* To make any changes in the tree we always first find node, that contains + item to be changed/deleted or place to insert a new item. We call this node + S. To do balancing we need to decide what we will shift to left/right + neighbor, or to a new node, where new item will be etc. To make this + analysis simpler we build virtual node. Virtual node is an array of items, + that will replace items of node S. (For instance if we are going to delete + an item, virtual node does not contain it). Virtual node keeps information + about item sizes and types, mergeability of first and last items, sizes of + all entries in directory item. We use this array of items when calculating + what we can shift to neighbors and how many nodes we have to have if we do + not any shiftings, if we shift to left/right neighbor or to both. */ +struct virtual_item { + unsigned short vi_type; /* item type, mergeability */ + unsigned short vi_item_len; /* length of item that it will have after balancing */ + __u64 vi_item_offset; /* offset of item that it have before balancing */ + + short vi_entry_count; /* number of entries in directory item + (including the new one if any, or excluding + entry if it must be cut) */ + unsigned short *vi_entry_sizes; /* array of entry lengths for directory item */ +}; + +struct virtual_node { + char *vn_free_ptr; /* this is a pointer to the free space in the buffer */ + unsigned short vn_nr_item; /* number of items in virtual node */ + short vn_size; /* size of node , that node would have if it has unlimited + size and no balancing is performed */ + short vn_mode; /* mode of balancing (paste, insert, delete, cut) */ + short vn_affected_item_num; + short vn_pos_in_item; + struct item_head *vn_ins_ih; /* item header of inserted item, 0 for other modes */ + struct virtual_item *vn_vi; /* array of items (including a new one, excluding item to be deleted) */ +}; + +/***************************************************************************/ +/* TREE BALANCE */ +/***************************************************************************/ + +/* This temporary structure is used in tree balance algorithms, and + constructed as we go to the extent that its various parts are needed. It + contains arrays of nodes that can potentially be involved in the balancing + of node S, and parameters that define how each of the nodes must be + balanced. Note that in these algorithms for balancing the worst case is to + need to balance the current node S and the left and right neighbors and all + of their parents plus create a new node. We implement S1 balancing for the + leaf nodes and S0 balancing for the internal nodes (S1 and S0 are defined + in our papers.)*/ + +#define MAX_FREE_BLOCK 7 /* size of the array of buffers to free at end of do_balance */ + +/* maximum number of FEB blocknrs on a single level */ +#define MAX_AMOUNT_NEEDED 2 + +/* someday somebody will prefix every field in this struct with tb_ */ +struct tree_balance { + struct reiserfs_transaction_handle *transaction_handle; + reiserfs_filsys_t tb_fs; + struct reiserfs_path *tb_path; + struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */ + struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */ + struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */ + struct buffer_head *FR[MAX_HEIGHT]; /* array of fathers of the right neighbors */ + struct buffer_head *CFL[MAX_HEIGHT]; /* array of common parents of center node and its left neighbor */ + struct buffer_head *CFR[MAX_HEIGHT]; /* array of common parents of center node and its right neighbor */ + + /* array of blocknr's that are free and are the nearest to the left node that are usable + for writing dirty formatted leaves, using the write_next_to algorithm. */ + /*unsigned long free_and_near[MAX_DIRTIABLE]; */ + + struct buffer_head *FEB[MAX_FEB_SIZE]; /* array of empty buffers. Number of buffers in array equals + cur_blknum. */ + struct buffer_head *used[MAX_FEB_SIZE]; + short int lnum[MAX_HEIGHT]; /* array of number of items which must be shifted to the left in + order to balance the current node; for leaves includes item + that will be partially shifted; for internal nodes, it is + the number of child pointers rather than items. It includes + the new item being created. For preserve_shifted() purposes + the code sometimes subtracts one from this number to get the + number of currently existing items being shifted, and even + more often for leaves it subtracts one to get the number of + wholly shifted items for other purposes. */ + short int rnum[MAX_HEIGHT]; /* substitute right for left in comment above */ + short int lkey[MAX_HEIGHT]; /* array indexed by height h mapping the key delimiting L[h] and + S[h] to its item number within the node CFL[h] */ + short int rkey[MAX_HEIGHT]; /* substitute r for l in comment above */ + short int insert_size[MAX_HEIGHT]; /* the number of bytes by we are trying to add or remove from + S[h]. A negative value means removing. */ + short int blknum[MAX_HEIGHT]; /* number of nodes that will replace node S[h] after + balancing on the level h of the tree. If 0 then S is + being deleted, if 1 then S is remaining and no new nodes + are being created, if 2 or 3 then 1 or 2 new nodes is + being created */ + + /* fields that are used only for balancing leaves of the tree */ + short int cur_blknum; /* number of empty blocks having been already allocated */ + short int s0num; /* number of items that fall into left most node when S[0] splits */ + short int s1num; /* number of items that fall into first new node when S[0] splits */ + short int s2num; /* number of items that fall into second new node when S[0] splits */ + short int lbytes; /* number of bytes which can flow to the left neighbor from the left */ + /* most liquid item that cannot be shifted from S[0] entirely */ + /* if -1 then nothing will be partially shifted */ + short int rbytes; /* number of bytes which will flow to the right neighbor from the right */ + /* most liquid item that cannot be shifted from S[0] entirely */ + /* if -1 then nothing will be partially shifted */ + short int s1bytes; /* number of bytes which flow to the first new node when S[0] splits */ + /* note: if S[0] splits into 3 nodes, then items do not need to be cut */ + short int s2bytes; + struct buffer_head *buf_to_free[MAX_FREE_BLOCK]; /* buffers which are to be freed after do_balance finishes by unfix_nodes */ + char *vn_buf; /* kmalloced memory. Used to create + virtual node and keep map of + dirtied bitmap blocks */ + int vn_buf_size; /* size of the vn_buf */ + struct virtual_node *tb_vn; /* VN starts after bitmap of bitmap blocks */ +}; + +/* These are modes of balancing */ + +/* When inserting an item. */ +#define M_INSERT 'i' +/* When inserting into (directories only) or appending onto an already + existant item. */ +#define M_PASTE 'p' +/* When deleting an item. */ +#define M_DELETE 'd' +/* When truncating an item or removing an entry from a (directory) item. */ +#define M_CUT 'c' + +/* used when balancing on leaf level skipped (in reiserfsck) */ +#define M_INTERNAL 'n' + +/* When further balancing is not needed, then do_balance does not need + to be called. */ +#define M_SKIP_BALANCING 's' +#define M_CONVERT 'v' + +/* modes of leaf_move_items */ +#define LEAF_FROM_S_TO_L 0 +#define LEAF_FROM_S_TO_R 1 +#define LEAF_FROM_R_TO_L 2 +#define LEAF_FROM_L_TO_R 3 +#define LEAF_FROM_S_TO_SNEW 4 + +#define FIRST_TO_LAST 0 +#define LAST_TO_FIRST 1 + +/* used in do_balance for passing parent of node information that has been + gotten from tb struct */ +struct buffer_info { + reiserfs_filsys_t bi_fs; + struct buffer_head * bi_bh; + struct buffer_head * bi_parent; + int bi_position; +}; + +/* there are 4 types of items: stat data, directory item, indirect, direct. + FIXME: This table does not describe new key format ++-------------------+------------+--------------+------------+ +| | k_offset | k_uniqueness | mergeable? | ++-------------------+------------+--------------+------------+ +| stat data | 0 | 0 | no | ++-------------------+------------+--------------+------------+ +| 1st directory item| DOT_OFFSET |DIRENTRY_UNIQUENESS| no | +| non 1st directory | hash value | | yes | +| item | | | | ++-------------------+------------+--------------+------------+ +| indirect item | offset + 1 |TYPE_INDIRECT | if this is not the first indirect item of the object ++-------------------+------------+--------------+------------+ +| direct item | offset + 1 |TYPE_DIRECT | if not this is not the first direct item of the object ++-------------------+------------+--------------+------------+ +*/ + + + +#define KEY_IS_STAT_DATA_KEY(p_s_key) ( get_type (p_s_key) == TYPE_STAT_DATA ) +#define KEY_IS_DIRECTORY_KEY(p_s_key) ( get_type (p_s_key) == TYPE_DIRENTRY ) +#define KEY_IS_DIRECT_KEY(p_s_key) ( get_type (p_s_key) == TYPE_DIRECT ) +#define KEY_IS_INDIRECT_KEY(p_s_key) ( get_type (p_s_key) == TYPE_INDIRECT ) + +#define I_IS_STAT_DATA_ITEM(p_s_ih) KEY_IS_STAT_DATA_KEY(&((p_s_ih)->ih_key)) +#define I_IS_DIRECTORY_ITEM(p_s_ih) KEY_IS_DIRECTORY_KEY(&((p_s_ih)->ih_key)) +#define I_IS_DIRECT_ITEM(p_s_ih) KEY_IS_DIRECT_KEY(&((p_s_ih)->ih_key)) +#define I_IS_INDIRECT_ITEM(p_s_ih) KEY_IS_INDIRECT_KEY(&((p_s_ih)->ih_key)) + +#define is_indirect_ih(ih) I_IS_INDIRECT_ITEM(ih) +#define is_direct_ih(ih) I_IS_DIRECT_ITEM(ih) +#define is_direntry_ih(ih) I_IS_DIRECTORY_ITEM(ih) +#define is_stat_data_ih(ih) I_IS_STAT_DATA_ITEM(ih) + +#define is_indirect_key(key) KEY_IS_INDIRECT_KEY(key) +#define is_direct_key(key) KEY_IS_DIRECT_KEY(key) +#define is_direntry_key(key) KEY_IS_DIRECTORY_KEY(key) +#define is_stat_data_key(key) KEY_IS_STAT_DATA_KEY(key) + +#define COMP_KEYS comp_keys + +//#define COMP_SHORT_KEYS comp_short_keys +#define not_of_one_file comp_short_keys + +/* number of blocks pointed to by the indirect item */ +#define I_UNFM_NUM(p_s_ih) ( get_ih_item_len(p_s_ih) / UNFM_P_SIZE ) + +/* the used space within the unformatted node corresponding to pos within the item pointed to by ih */ +#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space (ih) : (size)) + +/* check whether byte number 'offset' is in this item */ +#define I_OFF_BYTE_IN_ITEM(p_s_ih, n_offset, n_blocksize) \ + ( get_offset(&(p_s_ih)->ih_key) <= (n_offset) && \ + get_offset(&(p_s_ih)->ih_key) + get_bytes_number(p_s_ih,n_blocksize) > (n_offset) ) + +/* these operate on indirect items, where you've got an array of ints +** at a possibly unaligned location. These are a noop on ia32 +** +** p is the array of __u32, i is the index into the array, v is the value +** to store there. +*/ +#define d32_get(p, i) le32_to_cpu(get_unaligned((p) + (i))) +#define d32_put(p, i, v) put_unaligned(cpu_to_le32(v), (p) + (i)) + + +/* get the item header */ +#define item_head(bh,item_num) ( (struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num) ) + +/* get key */ +#define internal_key(bh,item_num) ( (struct reiserfs_key *)((bh)->b_data + BLKH_SIZE) + (item_num) ) + +/* get the key */ +#define leaf_key(bh,item_num) ( &(item_head(bh,item_num)->ih_key) ) + +/* get item body */ +#define item_body(bh,item_num) ( (bh)->b_data + get_ih_location (item_head((bh),(item_num)))) + +/* get the stat data by the buffer header and the item order */ +#define B_N_STAT_DATA(bh,nr) \ +( (struct stat_data *)((bh)->b_data+get_ih_location(item_head((bh),(nr))) ) ) + + /* following defines use reiserfs buffer header and item header */ + /* get item body */ +#define ih_item_body(bh,ih) ( (bh)->b_data + get_ih_location(ih)) + +/* get stat-data */ +#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )ih_item_body(bh,ih) ) + +#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE) +#define MAX_INDIRECT_ITEM_LEN(size) MAX_ITEM_LEN(size) + +/* Extended attributes */ +/* Magic value in header */ +#define REISERFS_XATTR_MAGIC 0x52465841 /* "RFXA" */ + +struct reiserfs_xattr_header { + __le32 h_magic; + __le32 h_hash; +}; + +/* ACLs */ +#define REISERFS_ACL_VERSION 0x0001 +struct reiserfs_acl_entry { + __le16 e_tag; + __le16 e_perm; + __le32 e_id; +}; + +struct reiserfs_acl_entry_short { + __le16 e_tag; + __le16 e_perm; +}; + +struct reiserfs_acl_header { + __le32 a_version; +}; + +/***************************************************************************/ +/* FUNCTION DECLARATIONS */ +/***************************************************************************/ + + + +/* stree.c */ +void padd_item (char * item, int total_length, int length); +int B_IS_IN_TREE(const struct buffer_head *); +const struct reiserfs_key *get_rkey(const struct reiserfs_path *p_s_chk_path, + const reiserfs_filsys_t ); +int bin_search (const void * p_v_key, const void * p_v_base, int p_n_num, int p_n_width, unsigned int * p_n_pos); +int search_by_key (reiserfs_filsys_t , const struct reiserfs_key *, struct reiserfs_path *, int); +int search_by_entry_key (reiserfs_filsys_t , struct reiserfs_key *, struct reiserfs_path *); +int search_for_position_by_key (reiserfs_filsys_t , struct reiserfs_key *, struct reiserfs_path *); +int search_by_objectid (reiserfs_filsys_t , struct reiserfs_key *, struct reiserfs_path *, int *); +void decrement_counters_in_path (struct reiserfs_path *p_s_search_path); +void pathrelse (struct reiserfs_path *p_s_search_path); + + +int is_left_mergeable (reiserfs_filsys_t s, struct reiserfs_path *path); +int is_right_mergeable (reiserfs_filsys_t s, struct reiserfs_path *path); +int are_items_mergeable (struct item_head * left, struct item_head * right, int bsize); + + +/* fix_nodes.c */ +int fix_nodes (/*struct reiserfs_transaction_handle *th,*/ int n_op_mode, struct tree_balance * p_s_tb, + /*int n_pos_in_item,*/ struct item_head * p_s_ins_ih); +void unfix_nodes (/*struct reiserfs_transaction_handle *th,*/ struct tree_balance *); +void free_buffers_in_tb (struct tree_balance * p_s_tb); +void init_path (struct reiserfs_path *); + +/* prints.c */ +/* options */ +#define PRINT_TREE_DETAILS 0x1 /* print all items from internal tree */ +#define PRINT_DETAILS 0x2 /* print all items from bitmap */ +#define PRINT_ITEM_DETAILS 0x4 /* print contents of directory items and stat + data items and indirect items */ +#define PRINT_DIRECT_ITEMS 0x8 /* print contents of direct items */ + +void print_tb (int mode, int item_pos, int pos_in_item, struct tree_balance * tb, const char * mes); + + +void print_bmap (FILE * fp, reiserfs_filsys_t fs, int silent); +void print_objectid_map (FILE * fp, reiserfs_filsys_t fs); + + + +/* lbalance.c */ +int leaf_move_items (int shift_mode, struct tree_balance * tb, + int mov_num, int mov_bytes, struct buffer_head * Snew); +int leaf_shift_left (struct tree_balance * tb, int shift_num, int shift_bytes); +int leaf_shift_right (struct tree_balance * tb, int shift_num, int shift_bytes); +void leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first, + int del_num, int del_bytes); +void leaf_insert_into_buf(struct buffer_info *bi, int before, + struct item_head * inserted_item_ih, + const char * inserted_item_body, int zeros_number); +void leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num, + int pos_in_item, int paste_size, const char * body, + int zeros_number); +void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num, + int pos_in_item, int cut_size); +void leaf_paste_entries (struct buffer_head * bh, int item_num, int before, int new_entry_count, + struct reiserfs_de_head * new_dehs, const char * records, + int paste_size); +void delete_item (reiserfs_filsys_t , struct buffer_head * bh, int item_num); +void cut_entry (reiserfs_filsys_t , struct buffer_head * bh, + int item_num, int entry_num, int del_count); + + +/* ibalance.c */ +int balance_internal (struct tree_balance * , int, int, struct item_head * , + struct buffer_head **); + +/* do_balance.c */ +void do_balance (struct tree_balance * tb, + struct item_head * ih, const char * body, int flag, int zeros_num); +void reiserfs_invalidate_buffer (struct tree_balance * tb, struct buffer_head * bh); +int get_left_neighbor_position (const struct tree_balance * tb, int h); +int get_right_neighbor_position (const struct tree_balance * tb, int h); +void replace_key (reiserfs_filsys_t , struct buffer_head *, int, struct buffer_head *, int); +void replace_lkey (struct tree_balance *, int, struct item_head *); +void replace_rkey (struct tree_balance *, int, struct item_head *); +void make_empty_node (struct buffer_info *); +void make_empty_leaf (struct buffer_head *); +struct buffer_head * get_FEB (struct tree_balance *); + + +__u32 get_bytes_number (struct item_head * ih, int blocksize); + + + + +/* hashes.c */ +__u32 keyed_hash (const char *msg, int len); +__u32 yura_hash (const char *msg, int len); +__u32 r5_hash (const char *msg, int len); + + + +/* node_format.c */ +extern unsigned int get_journal_old_start_must (reiserfs_filsys_t fs); +extern unsigned int get_journal_new_start_must (reiserfs_filsys_t fs); +extern unsigned int get_journal_start_must (reiserfs_filsys_t fs); +/*extern hashf_t hashes [];*/ + +static inline void buffer_info_init_left(const struct tree_balance *tb, + struct buffer_info *bi, int h) +{ + bi->bi_fs = tb->tb_fs; + bi->bi_bh = tb->L[h]; + bi->bi_parent = tb->FL[h]; + bi->bi_position = get_left_neighbor_position(tb, h); +} + +static inline void buffer_info_init_right(const struct tree_balance *tb, + struct buffer_info *bi, int h) +{ + bi->bi_fs = tb->tb_fs; + bi->bi_bh = tb->R[h]; + bi->bi_parent = tb->FR[h]; + bi->bi_position = get_right_neighbor_position(tb, h); +} + +static inline void buffer_info_init_last(const struct tree_balance *tb, + struct buffer_info *bi) +{ + bi->bi_fs = tb->tb_fs; + bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path); + bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0); + bi->bi_position = PATH_H_B_ITEM_ORDER(tb->tb_path, 0); +} + +static inline void buffer_info_init_tbSh(const struct tree_balance *tb, + struct buffer_info *bi, int h) +{ + bi->bi_fs = tb->tb_fs; + bi->bi_bh = PATH_H_PBUFFER(tb->tb_path, h); + bi->bi_parent = PATH_H_PPARENT(tb->tb_path, h); + bi->bi_position = PATH_H_POSITION(tb->tb_path, h + 1); +} + +static inline void buffer_info_init_tbS0(const struct tree_balance *tb, + struct buffer_info *bi) +{ + buffer_info_init_tbSh(tb, bi, 0); +} + +static inline void buffer_info_init_bh(const struct tree_balance *tb, + struct buffer_info *bi, + struct buffer_head *bh) +{ + bi->bi_fs = tb ? tb->tb_fs : NULL; + bi->bi_bh = bh; + bi->bi_parent = NULL; + bi->bi_position = 0; +} + +static inline __u64 get_key_offset_v2(const struct reiserfs_key *key) +{ + const struct offset_v2 *v2 = &key->u.k2_offset_v2; + return le64_to_cpu(v2->v) & (~0ULL >> 4); +} + +static inline __u32 get_key_type_v2(const struct reiserfs_key *key) +{ + const struct offset_v2 *v2 = &key->u.k2_offset_v2; + char type = le64_to_cpu(v2->v) >> 60; + return (type <= TYPE_MAXTYPE) ? type : TYPE_UNKNOWN; +} + +static inline void set_key_offset_v2(struct reiserfs_key *key, __u64 offset) +{ + struct offset_v2 *v2 = &key->u.k2_offset_v2; + offset &= (~0ULL >> 4); + v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset); +} + +static inline void set_key_type_v2(struct reiserfs_key *key, __u32 type) +{ + struct offset_v2 *v2 = &key->u.k2_offset_v2; + __u64 type64 = type; + v2->v = (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64(type64 << 60); +} +#endif + +/* + * Local variables: + * c-indentation-style: "bsd" + * c-basic-offset: 4 + * tab-width: 8 + * fill-column: 78 + * End: + */ diff --git a/test/files/reiserfs/reiserfs_lib.h b/test/files/reiserfs/reiserfs_lib.h new file mode 100644 index 000000000..215638069 --- /dev/null +++ b/test/files/reiserfs/reiserfs_lib.h @@ -0,0 +1,440 @@ +/* + * Copyright 2000-2004 by Hans Reiser, licensing governed by + * reiserfsprogs/README + */ + +#ifndef REISERFSPROGS_LIB_H +#define REISERFSPROGS_LIB_H + +#define BADBLOCK_DIRID 1 +#define BADBLOCK_OBJID (__u32)-1 + +typedef struct reiserfs_filsys * reiserfs_filsys_t; + +#include +#include "reiserfs_fs.h" + +struct _bitmap { + unsigned long bm_byte_size; + unsigned long bm_bit_size; + char *bm_map; + unsigned long bm_set_bits; + int bm_dirty; /* used for fetched bitmap */ +}; + +typedef struct _bitmap reiserfs_bitmap_t; + +typedef __u32(*hashf_t) (const char *, int); + +struct reiserfs_filsys { + unsigned int fs_blocksize; + int fs_format; /* on-disk format version */ + hashf_t fs_hash_function; /* pointer to function which is used to sort + names in directory. It is set by + reiserfs_open if it is set in the super + block, otherwise it is set by first + is_properly_hashed */ + + char *fs_file_name; /* file name of underlying device */ + int fs_dev; /* descriptor of opened block device file */ + struct buffer_head *fs_super_bh; /* buffer containing super block */ + struct reiserfs_super_block *fs_ondisk_sb; /* pointer to its b_data */ + + reiserfs_bitmap_t *fs_bitmap2; /* ondisk bitmap after + reiserfs_open_ondisk_bitmap */ + + /* opened journal fields */ + char *fs_j_file_name; /* file name of relocated journal device */ + int fs_journal_dev; /* descriptor of opened journal device */ + struct buffer_head *fs_jh_bh; /* buffer containing journal header */ + + /* badblocks */ + reiserfs_bitmap_t *fs_badblocks_bm; + + int fs_dirt; + int fs_flags; + void *fs_vp; + int (*block_allocator) (reiserfs_filsys_t fs, + unsigned long *free_blocknrs, + unsigned long start, int amount_needed); + int (*block_deallocator) (reiserfs_filsys_t fs, unsigned long block); +}; + +struct _transaction { + unsigned long mount_id; + unsigned long trans_id; + unsigned long desc_blocknr; + unsigned long trans_len; + unsigned long commit_blocknr; + unsigned long next_trans_offset; +}; + +typedef struct _transaction reiserfs_trans_t; + +/* reiserfslib.c */ + +void init_tb_struct(struct tree_balance *tb, reiserfs_filsys_t , + struct reiserfs_path *path, int size); + +reiserfs_filsys_t reiserfs_open(const char *filename, int flags, long *error, + void *vp, int skip_check); +reiserfs_filsys_t reiserfs_create(const char *filename, int version, + unsigned long block_count, int block_size, + int default_journal, int new_format, + long *error); +void reiserfs_flush(reiserfs_filsys_t ); +void reiserfs_free(reiserfs_filsys_t ); +void reiserfs_close(reiserfs_filsys_t ); +void reiserfs_reopen(reiserfs_filsys_t , int flags); +int is_opened_rw(reiserfs_filsys_t fs); + +/* +void reiserfs_read_bitmap_blocks (reiserfs_filsys_t ); +void reiserfs_free_bitmap_blocks (reiserfs_filsys_t ); +*/ +int no_reiserfs_found(reiserfs_filsys_t ); +int is_block_count_correct(unsigned long block_of_super_block, + unsigned int block_size, unsigned long block_count, + unsigned long journal_size); +//unsigned long min_block_amount (int block_size, unsigned long journal_size); +unsigned long get_size_of_journal_or_reserved_area(struct reiserfs_super_block + *sb); + +int reiserfs_new_blocknrs(reiserfs_filsys_t , + unsigned long *free_blocknrs, unsigned long start, + int amount_needed); +int reiserfs_free_block(reiserfs_filsys_t , unsigned long block); +int spread_bitmaps(reiserfs_filsys_t ); +int filesystem_dirty(reiserfs_filsys_t ); +void mark_filesystem_dirty(reiserfs_filsys_t ); + +void reiserfs_paste_into_item(reiserfs_filsys_t , struct reiserfs_path *path, + const void *body, int size); +void reiserfs_insert_item(reiserfs_filsys_t , struct reiserfs_path *path, + struct item_head *ih, const void *body); + +int reiserfs_locate_entry(reiserfs_filsys_t , struct reiserfs_key *dir, + const char *name, struct reiserfs_path *path); +int reiserfs_find_entry(reiserfs_filsys_t , const struct reiserfs_key *dir, + const char *name, unsigned int *min_gen_counter, + struct reiserfs_key *key); +int reiserfs_add_entry(reiserfs_filsys_t , const struct reiserfs_key *dir, + const char *name, int name_len, + const struct reiserfs_key *key, __u16 fsck_need); + +struct reiserfs_key *uget_lkey(const struct reiserfs_path *path); +struct reiserfs_key *uget_rkey(const struct reiserfs_path *path); +int reiserfs_search_by_key_3(reiserfs_filsys_t , const struct reiserfs_key *key, + struct reiserfs_path *path); +int reiserfs_search_by_key_4(reiserfs_filsys_t , const struct reiserfs_key *key, + struct reiserfs_path *path); +int reiserfs_search_by_entry_key(reiserfs_filsys_t, + const struct reiserfs_key *key, + struct reiserfs_path *path); +int reiserfs_search_by_position(reiserfs_filsys_t , struct reiserfs_key *key, + int version, struct reiserfs_path *path); +struct reiserfs_key *reiserfs_next_key(const struct reiserfs_path *path); +void copy_key(void *to, const void *from); +void copy_short_key(void *to, const void *from); +int comp_keys(const void *k1, const void *k2); +int comp_keys_3(const void *k1, const void *k2); +int comp_short_keys(const void *p_s_key1, const void *p_s_key2); +int comp_items(struct item_head *p_s_ih, struct reiserfs_path *p_s_path); + +__u32 hash_value(hashf_t func, const char *name, int namelen); + +int create_dir_sd(reiserfs_filsys_t fs, + struct reiserfs_path *path, const struct reiserfs_key *key, + void (*modify_item) (struct item_head *, void *)); +void make_sure_root_dir_exists(reiserfs_filsys_t fs, + void (*modyfy_item) (struct item_head *, void *), + int ih_flags); + +typedef void (*badblock_func_t) (reiserfs_filsys_t fs, + struct reiserfs_path *badblock_path, + void *data); + +void mark_badblock(reiserfs_filsys_t fs, struct reiserfs_path *badblock_path, + void *data); +int create_badblock_bitmap(reiserfs_filsys_t fs, const char *badblocks_file); +void add_badblock_list(reiserfs_filsys_t fs, int no_badblock_in_tree_yet); +void badblock_list(reiserfs_filsys_t fs, badblock_func_t action, void *data); +#define reiserfs_fs_bmap_nr(fs) reiserfs_bmap_nr(get_sb_block_count(fs->fs_ondisk_sb), fs->fs_blocksize) +#define reiserfs_bmap_nr(count, blk_size) ((count - 1) / (blk_size * 8) + 1) +#define reiserfs_bmap_over(nr) (nr > ((1LL << 16) - 1)) + +typedef int (*reiserfs_file_iterate_indirect_fn)(reiserfs_filsys_t fs, + __u64 position, __u64 size, + int num_blocks, __u32 *blocks, + void *data); +typedef int (*reiserfs_file_iterate_direct_fn)(reiserfs_filsys_t fs, + __u64 position, __u64 size, + const char *body, size_t len, + void *data); +int reiserfs_iterate_file_data(reiserfs_filsys_t fs, + const struct reiserfs_key const *short_key, + reiserfs_file_iterate_indirect_fn indirect_fn, + reiserfs_file_iterate_direct_fn direct_fn, + void *data); + +typedef int (*reiserfs_iterate_dir_fn)(reiserfs_filsys_t fs, + const struct reiserfs_key const *dir_short_key, + const char *name, size_t len, + __u32 deh_dirid, __u32 deh_objectid, void *data); +int reiserfs_iterate_dir(reiserfs_filsys_t fs, + const struct reiserfs_key const *dir_short_key, + const reiserfs_iterate_dir_fn callback, void *data); + + +extern struct reiserfs_key root_dir_key; +extern struct reiserfs_key parent_root_dir_key; +extern struct reiserfs_key lost_found_dir_key; +extern __u16 root_dir_format; +extern __u16 lost_found_dir_format; + +/* bitmap.c */ +int reiserfs_open_ondisk_bitmap(reiserfs_filsys_t ); +int reiserfs_create_ondisk_bitmap(reiserfs_filsys_t ); +void reiserfs_free_ondisk_bitmap(reiserfs_filsys_t ); +void reiserfs_close_ondisk_bitmap(reiserfs_filsys_t ); +int reiserfs_flush_to_ondisk_bitmap(reiserfs_bitmap_t *bm, + reiserfs_filsys_t fs); +unsigned int reiserfs_calc_bmap_nr(reiserfs_filsys_t fs, unsigned int blocks); + +reiserfs_bitmap_t *reiserfs_create_bitmap(unsigned int bit_count); +int reiserfs_expand_bitmap(reiserfs_bitmap_t *bm, unsigned int bit_count); +void reiserfs_shrink_bitmap(reiserfs_bitmap_t *bm, unsigned int bit_count); +void reiserfs_delete_bitmap(reiserfs_bitmap_t *bm); +void reiserfs_bitmap_copy(reiserfs_bitmap_t *to, reiserfs_bitmap_t *from); +int reiserfs_bitmap_compare(reiserfs_bitmap_t *bm1, reiserfs_bitmap_t *bm2); +void reiserfs_bitmap_disjunction(reiserfs_bitmap_t *disk, + reiserfs_bitmap_t *cont); +void reiserfs_bitmap_delta(reiserfs_bitmap_t *base, + reiserfs_bitmap_t *exclude); +void reiserfs_bitmap_set_bit(reiserfs_bitmap_t *bm, unsigned int bit_number); +void reiserfs_bitmap_clear_bit(reiserfs_bitmap_t *bm, unsigned int bit_number); + +int reiserfs_bitmap_test_bit(reiserfs_bitmap_t *bm, unsigned int bit_number); +int reiserfs_bitmap_find_zero_bit(reiserfs_bitmap_t *bm, unsigned long *start); +/*int reiserfs_fetch_ondisk_bitmap (reiserfs_bitmap_t *bm, reiserfs_filsys_t );*/ +/*int reiserfs_flush_bitmap (reiserfs_bitmap_t *bm, reiserfs_filsys_t );*/ +void reiserfs_bitmap_zero(reiserfs_bitmap_t *bm); +void reiserfs_bitmap_fill(reiserfs_bitmap_t *bm); +unsigned int reiserfs_bitmap_ones(reiserfs_bitmap_t *bm); +unsigned int reiserfs_bitmap_zeros(reiserfs_bitmap_t *bm); + +FILE *open_file(const char *filename, char *option); +void close_file(FILE * fp); +void reiserfs_bitmap_save(FILE * fp, reiserfs_bitmap_t *bm); + +/* this probably should be in fsck */ +void reiserfs_begin_stage_info_save(FILE * file, unsigned long stage); +void reiserfs_end_stage_info_save(FILE * file); +int is_stage_magic_correct(FILE * fp); +//void reiserfs_stage_info_save(struct fsck_data *, FILE * file); + +reiserfs_bitmap_t *reiserfs_bitmap_load(FILE * fp); +void reiserfs_bitmap_invert(reiserfs_bitmap_t *bm); + +int reiserfs_remove_entry(reiserfs_filsys_t, const struct reiserfs_key *key); + +/* node_formats.c */ + +#define THE_LEAF 1 +#define THE_INTERNAL 2 +#define THE_SUPER 3 +#define THE_JDESC 4 +#define HAS_IH_ARRAY 5 +#define THE_UNKNOWN 6 + +int is_blocksize_correct(unsigned int blocksize); +int is_reiserfs_3_5_magic_string(struct reiserfs_super_block *rs); +int is_reiserfs_3_6_magic_string(struct reiserfs_super_block *rs); +int is_reiserfs_jr_magic_string(struct reiserfs_super_block *rs); +int does_look_like_super_block(struct reiserfs_super_block *rs); +int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs); +int get_reiserfs_format(struct reiserfs_super_block *sb); +int reiserfs_super_block_size(struct reiserfs_super_block *rs); +/*int magic_2_version (struct reiserfs_super_block * rs);*/ +int is_prejournaled_reiserfs(struct reiserfs_super_block *rs); +int who_is_this(const char *buf, int blocksize); + +int leaf_count_ih(const char *buf, int blocksize); +int leaf_free_space_estimate(const char *buf, int blocksize); +int is_a_leaf(const char *buf, int blocksize); +int leaf_item_number_estimate(const struct buffer_head *bh); + +char *which_block(int code); +int get_journal_size(reiserfs_filsys_t ); +int not_data_block(reiserfs_filsys_t , unsigned long block); +int not_journalable(reiserfs_filsys_t , unsigned long block); +int block_of_bitmap(reiserfs_filsys_t , unsigned long block); +int block_of_journal(reiserfs_filsys_t , unsigned long block); +int is_tree_node(struct buffer_head *bh, int level); +int is_properly_hashed(reiserfs_filsys_t , + const char *name, int namelen, __u32 offset); +int dir_entry_bad_location(struct reiserfs_de_head *deh, + struct item_head *ih, int first); +void make_dir_stat_data(int blocksize, int key_format, + __u32 dirid, __u32 objectid, + struct item_head *ih, void *sd); +void make_empty_dir_item_v1(char *body, __u32 dirid, __u32 objid, + __u32 par_dirid, __u32 par_objid); +void make_empty_dir_item(char *body, __u32 dirid, __u32 objid, + __u32 par_dirid, __u32 par_objid); +int reiserfs_is_fs_consistent(reiserfs_filsys_t fs); + +typedef void (*item_action_t) (struct buffer_head * bh, struct item_head * ih); +typedef void (*item_head_action_t) (struct item_head * ih); + +void for_every_item(struct buffer_head *bh, item_head_action_t action, + item_action_t *actions); +int key_format(const struct reiserfs_key *key); +unsigned long long get_offset(const struct reiserfs_key *key); +int uniqueness2type(__u32 uniqueness); +__u32 type2uniqueness(int type); +int get_type(const struct reiserfs_key *key); +char *key_of_what(const struct reiserfs_key *key); +int type_unknown(const struct reiserfs_key *key); +void set_type(int format, struct reiserfs_key *key, int type); +void set_offset(int format, struct reiserfs_key *key, loff_t offset); +void set_type_and_offset(int format, struct reiserfs_key *key, loff_t offset, + int type); + +typedef int (*check_unfm_func_t) (reiserfs_filsys_t , __u32); +int is_it_bad_item(reiserfs_filsys_t , struct item_head *, const char *, + check_unfm_func_t, int bad_dir); + +#define hash_func_is_unknown(fs) ((fs)->fs_hash_function == NULL) +#define reiserfs_hash(fs) ((fs)->fs_hash_function) + +int known_hashes(void); +char *code2name(unsigned int code); +int func2code(hashf_t func); +hashf_t code2func(unsigned int code); +hashf_t name2func(const char *hash); +int find_hash_in_use(const char *name, int namelen, __u32 deh_offset, + unsigned int code_to_try_first); + +int entry_length(const struct item_head *ih, const struct reiserfs_de_head *deh, + int pos_in_item); +char *name_in_entry(const struct reiserfs_de_head *deh, int pos_in_item); +int name_in_entry_length(const struct item_head *ih, + const struct reiserfs_de_head *deh, int pos_in_item); +int name_length(const char *name, int key_format); + +/* access to stat data fields */ +void get_set_sd_field(int field, struct item_head *ih, void *sd, + void *value, int set); +#define GET_SD_MODE 0 +#define GET_SD_SIZE 1 +#define GET_SD_NLINK 2 +#define GET_SD_BLOCKS 3 +#define GET_SD_FIRST_DIRECT_BYTE 4 + +#define get_sd_mode(ih,sd,pmode) get_set_sd_field (GET_SD_MODE, ih, sd, pmode, 0/*get*/) +#define set_sd_mode(ih,sd,pmode) get_set_sd_field (GET_SD_MODE, ih, sd, pmode, 1/*set*/) + +#define get_sd_size(ih,sd,psize) get_set_sd_field (GET_SD_SIZE, ih, sd, psize, 0/*get*/) +#define set_sd_size(ih,sd,psize) get_set_sd_field (GET_SD_SIZE, ih, sd, psize, 1/*set*/) + +#define get_sd_blocks(ih,sd,pblocks) get_set_sd_field (GET_SD_BLOCKS, ih, sd, pblocks, 0/*get*/) +#define set_sd_blocks(ih,sd,pblocks) get_set_sd_field (GET_SD_BLOCKS, ih, sd, pblocks, 1/*set*/) + +//#define get_sd_rdev(ih,sd,pblocks) get_set_sd_field (GET_SD_RDEV, ih, sd, pblocks, 0/*get*/) +//#define set_sd_rdev(ih,sd,pblocks) get_set_sd_field (GET_SD_RDEV, ih, sd, pblocks, 1/*set*/) + +//#define get_sd_generation(ih,sd,pblocks) get_set_sd_field (GET_SD_GENER, ih, sd, pblocks, 0/*get*/) +//#define set_sd_generation(ih,sd,pblocks) get_set_sd_field (GET_SD_GENER, ih, sd, pblocks, 1/*set*/) + +#define get_sd_nlink(ih,sd,pnlink) get_set_sd_field (GET_SD_NLINK, ih, sd, pnlink, 0/*get*/) +#define set_sd_nlink(ih,sd,pnlink) get_set_sd_field (GET_SD_NLINK, ih, sd, pnlink, 1/*set*/) + +#define get_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 0/*get*/) +#define set_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 1/*set*/) + +int is_objectid_used(reiserfs_filsys_t fs, __u32 objectid); +void mark_objectid_used(reiserfs_filsys_t fs, __u32 objectid); + +/* journal.c */ +int get_boundary_transactions(reiserfs_filsys_t , reiserfs_trans_t *, + reiserfs_trans_t *); +int next_transaction(reiserfs_filsys_t , reiserfs_trans_t *, reiserfs_trans_t); + +int replay_one_transaction(reiserfs_filsys_t , reiserfs_trans_t *); + +typedef void (*action_on_trans_t) (reiserfs_filsys_t , reiserfs_trans_t *); +void for_each_transaction(reiserfs_filsys_t , action_on_trans_t); + +typedef void (*action_on_block_t) (reiserfs_filsys_t , reiserfs_trans_t *, + unsigned int index, + unsigned long in_journal, + unsigned long in_place); +void for_each_block(reiserfs_filsys_t fs, reiserfs_trans_t *trans, + action_on_block_t action); + +int reiserfs_open_journal(reiserfs_filsys_t , const char *, int flags); +int reiserfs_journal_params_check(reiserfs_filsys_t fs); +int reiserfs_create_journal(reiserfs_filsys_t fs, const char *j_filename, + unsigned long offset, unsigned long len, + int transaction_max_size, int force); +int reiserfs_journal_opened(reiserfs_filsys_t ); +void reiserfs_flush_journal(reiserfs_filsys_t fs); +void reiserfs_free_journal(reiserfs_filsys_t fs); +void reiserfs_close_journal(reiserfs_filsys_t ); +void reiserfs_reopen_journal(reiserfs_filsys_t fs, int flag); +__u32 advise_journal_max_trans_age(void); +__u32 advise_journal_max_commit_age(void); +__u32 advise_journal_max_batch(unsigned long journal_trans_max); +__u32 advise_journal_max_trans_len(__u32 desired, __u32 journal_size, + int blocksize, int verbose); + +/* prints.c */ +void print_indirect_item(FILE * fp, struct buffer_head *bh, int item_num); +void print_block(FILE * fp, reiserfs_filsys_t , struct buffer_head *bh, ...); //int print_mode, int first, int last); +int print_super_block(FILE * fp, reiserfs_filsys_t , const char *file_name, + struct buffer_head *bh, int short_print); +void print_journal(reiserfs_filsys_t ); +void print_journal_header(reiserfs_filsys_t fs); +void reiserfs_warning(FILE * fp, const char *fmt, ...); +char ftypelet(mode_t mode); +void reiserfs_print_item(FILE * fp, struct buffer_head *bh, + struct item_head *ih); +void print_filesystem_state(FILE * fp, reiserfs_filsys_t fs); +void print_one_transaction(reiserfs_filsys_t fs, reiserfs_trans_t *trans); +void print_journal_params(FILE * fp, struct journal_params *jp); +char *get_reiserfs_version(__u16 version); +int can_we_format_it(const char *device_name, int force); + +#define reiserfs_panic(fmt, list...) \ +{\ + fflush (stdout);\ + fprintf (stderr, "%s %d %s\n", __FILE__, __LINE__, __FUNCTION__);\ + reiserfs_warning (stderr, (const char *)fmt, ## list);\ + reiserfs_warning (stderr, "\n" );\ + abort ();\ +} +#define reiserfs_exit(val, fmt, list...) \ +{\ + fflush (stdout);\ + reiserfs_warning (stderr, (const char *)fmt, ## list);\ + reiserfs_warning (stderr, "\n" );\ + exit (val);\ +} + +#define check_forcing_ask_confirmation(force) \ + if (force < 1) {\ + /* avoid formatting it without being forced */\ + reiserfs_warning (stderr, "Use -f to force over\n");\ + return 0;\ + }\ + if (force < 2) {\ + if (!user_confirmed (stderr, "Continue (y/n):", "y\n"))\ + return 0;\ + }\ + +/* xattr.c */ +__u32 reiserfs_xattr_hash(const char *msg, int len); +int reiserfs_check_xattr(const void *body, int len); +int reiserfs_acl_count(size_t size); +#endif /* REISERFSPROGS_LIB_H */ diff --git a/test/files/reiserfs/reiserfscore.pc b/test/files/reiserfs/reiserfscore.pc new file mode 100644 index 000000000..1225c9640 --- /dev/null +++ b/test/files/reiserfs/reiserfscore.pc @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=/ +libdir=/usr/lib64 +includedir=/usr/include + +Name: reiserfscore +Description: ReiserFS Core Library +Version: 3.6.27 +Cflags: -I${includedir}/reiserfs -I${includedir} +Libs: -L${libdir} -lreiserfscore diff --git a/test/files/reiserfs/swab.h b/test/files/reiserfs/swab.h new file mode 100644 index 000000000..fef3c5596 --- /dev/null +++ b/test/files/reiserfs/swab.h @@ -0,0 +1,93 @@ +/* + * Copyright 2002-2004 by Hans Reiser, licensing governed by + * reiserfsprogs/README + */ + +#ifndef REISERFSPROGS_SWAB_H +#define REISERFSPROGS_SWAB_H + +#include +#include + +#define __constant_swab16(x) ((__u16)( \ + (((__u16)(x) & (__u16)0x00ffU) << 8) | \ + (((__u16)(x) & (__u16)0xff00U) >> 8) )) + +#define __swab16(x) \ +({ \ + __u16 __x = (x); \ + __constant_swab16(__x); \ +}) + +#define __constant_swab32(x) ((__u32)( \ + (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \ + (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \ + (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \ + (((__u32)(x) & (__u32)0xff000000UL) >> 24))) + +#define __swab32(x) \ +({ \ + __u32 __x = (x); \ + __constant_swab32(__x); \ +}) + +#define __constant_swab64(x) ((__u64)( \ + (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \ + (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \ + (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \ + (((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \ + (((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \ + (((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \ + (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \ + (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56))) + + +#define __swab64(x) \ +({ \ + __u64 __x = (x); \ + __constant_swab64(__x); \ +}) + +#ifndef le32_to_cpu +#ifdef __CHECKER__ +#define __force __attribute__((force)) +#else +#define __force +#endif + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define cpu_to_le64(x) ((__force __le64)(__u64)(x)) +#define le64_to_cpu(x) ((__force __u64)(__le64)(x)) +#define cpu_to_le32(x) ((__force __le32)(__u32)(x)) +#define le32_to_cpu(x) ((__force __u32)(__le32)(x)) +#define cpu_to_le16(x) ((__force __le16)(__u16)(x)) +#define le16_to_cpu(x) ((__force __u16)(__le16)(x)) + +#define constant_cpu_to_le64(x) ((__force __le64)(__u64)(x)) +#define constant_le64_to_cpu(x) ((__force __u64)(__le64)(x)) +#define constant_cpu_to_le32(x) ((__force __le32)(__u32)(x)) +#define constant_le32_to_cpu(x) ((__force __u32)(__le32)(x)) +#define constant_cpu_to_le16(x) ((__force __le16)(__u16)(x)) +#define constant_le16_to_cpu(x) ((__force __u16)(__le16)(x)) + +#elif __BYTE_ORDER == __BIG_ENDIAN +#define cpu_to_le64(x) ((__force __le64)__swab64((x))) +#define le64_to_cpu(x) __swab64((__force __u64)(__le64)(x)) +#define cpu_to_le32(x) ((__force __le32)__swab32((x))) +#define le32_to_cpu(x) __swab32((__force __u32)(__le32)(x)) +#define cpu_to_le16(x) ((__force __le16)__swab16((x))) +#define le16_to_cpu(x) __swab16((__force __u16)(__le16)(x)) + +#define constant_cpu_to_le64(x) ((__force __le64)__constant_swab64((x))) +#define constant_le64_to_cpu(x) __constant_swab64((__force __u64)(__le64)(x)) +#define constant_cpu_to_le32(x) ((__force __le32)__constant_swab32((x))) +#define constant_le32_to_cpu(x) __constant_swab32((__force __u32)(__le32)(x)) +#define constant_cpu_to_le16(x) ((__force __le16)__constant_swab16((x))) +#define constant_le16_to_cpu(x) __constant_swab16((__force __u16)(__le16)(x)) + +#else +# error "nuxi/pdp-endian archs are not supported" +#endif +#endif + +#endif /* REISERFS_SWAB_H */ diff --git a/test/files/rpmlint-test-good.desktop b/test/files/rpmlint-test-good.desktop new file mode 100644 index 000000000..b972d1df5 --- /dev/null +++ b/test/files/rpmlint-test-good.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Name=rpmlint-test +Name[de]=rpmlint-test umlaut äöü +Name[x-test]=xxrpmlint-testxx +MimeType=application/x-rpm; +Exec=rpmlint-test file.file +Icon=chameleon_v_balíku +Type=Application +InitialPreference=5 +NoDisplay=false +GenericName=rpmlint testcase +GenericName[x-test]=xxrpmlint testcasexx +Categories=System;PackageManager; +Keywords=software;package; +Keywords[x-test]=xxsoftwarexx;xxpackagexx; diff --git a/test/files/systemd/org.freedesktop.NetworkManager.conf b/test/files/systemd/org.freedesktop.NetworkManager.conf new file mode 100644 index 000000000..b27b4d9f5 --- /dev/null +++ b/test/files/systemd/org.freedesktop.NetworkManager.conf @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1024 + 2048 + + diff --git a/test/files/systemd/org.freedesktop.NetworkManager2.conf b/test/files/systemd/org.freedesktop.NetworkManager2.conf new file mode 100644 index 000000000..98fef3182 --- /dev/null +++ b/test/files/systemd/org.freedesktop.NetworkManager2.conf @@ -0,0 +1,10 @@ + + + + + 1024 + 2048 + + diff --git a/test/files/x.typelib b/test/files/x.typelib deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/mockdata/mock_FHS.py b/test/mockdata/mock_FHS.py index 8b54281bb..2d360c52f 100644 --- a/test/mockdata/mock_FHS.py +++ b/test/mockdata/mock_FHS.py @@ -1,7 +1,7 @@ from Testing import get_tested_mock_package -FHS = get_tested_mock_package( -files={ -'/usr/dummy': {'content': ''}, -'/var/dummy': {'content': ''}, -'/var/local': {'content': ''}}) + +NoFHSPackage = get_tested_mock_package( + lazyload=True, + files=['/usr/dummy', '/var/dummy', '/var/local'], +) diff --git a/test/mockdata/mock_LSB.py b/test/mockdata/mock_LSB.py index 442c8bd36..46fad9924 100644 --- a/test/mockdata/mock_LSB.py +++ b/test/mockdata/mock_LSB.py @@ -1,17 +1,20 @@ from Testing import get_tested_mock_package -LSB = get_tested_mock_package( -files={ -'/usr/sbin/fping', -'/usr/share/doc/packages/fPing', -'/usr/share/doc/packages/fPing/CHANGELOG.md', -'/usr/share/licenses/fPing', -'/usr/share/licenses/fPing/COPYING', -'/usr/share/man/man8/fping.8.gz', -}, -header={ -'name': 'fPing@1', -'version': '1.0_beta', -'release': '1.0-beta' -}) +NonLSBCompliancePackage = get_tested_mock_package( + lazyload=True, + name='fPing@1', + files={ + '/usr/sbin/fping', + '/usr/share/doc/packages/fPing', + '/usr/share/doc/packages/fPing/CHANGELOG.md', + '/usr/share/licenses/fPing', + '/usr/share/licenses/fPing/COPYING', + '/usr/share/man/man8/fping.8.gz', + }, + header={ + 'name': 'fPing@1', + 'version': '1.0_beta', + 'release': '1.0-beta' + }, +) diff --git a/test/mockdata/mock_appdata.py b/test/mockdata/mock_appdata.py index 06c01467f..109008ce7 100644 --- a/test/mockdata/mock_appdata.py +++ b/test/mockdata/mock_appdata.py @@ -1,18 +1,16 @@ from Testing import get_tested_mock_package -APPDATA = get_tested_mock_package( -files={ -'/usr/share/appdata/broken.appdata.xml': { - 'content-path': 'files/broken.appdata.xml', - 'create_dirs': True}, -'/usr/share/appdata/broken-xml.metainfo.xml': { - 'content-path': 'files/broken-xml.metainfo.xml', - 'create_dirs': True} -}) -APPDATA2 = get_tested_mock_package( -files={ -'/usr/share/appdata/broken-xml.metainfo.xml': { - 'content-path': 'files/broken-xml.metainfo.xml', - 'create_dirs': True} -}) +AppDataPackage = get_tested_mock_package( + lazyload=True, + files={ + '/usr/share/appdata/broken.appdata.xml': { + 'content-path': 'files/broken.appdata.xml', + 'create_dirs': True, + }, + '/usr/share/appdata/broken-xml.metainfo.xml': { + 'content-path': 'files/broken-xml.metainfo.xml', + 'create_dirs': True, + }, + } +) diff --git a/test/mockdata/mock_bashisms.py b/test/mockdata/mock_bashisms.py index 9c95a5b83..7825095bd 100644 --- a/test/mockdata/mock_bashisms.py +++ b/test/mockdata/mock_bashisms.py @@ -1,11 +1,18 @@ from Testing import get_tested_mock_package -BASHISMS = get_tested_mock_package( - files={ - '/bin/script1': {'content': """#!/bin/sh + +SCRIPT1 = """#!/bin/sh xz $tmp/1 &> /dev/null -"""}, - '/bin/script2': {'content': """#!/bin/sh +""" + +SCRIPT2 = """#!/bin/sh do -"""} - }) +""" + + +BashismsPackage = get_tested_mock_package( + files={ + '/bin/script1': {'content': SCRIPT1}, + '/bin/script2': {'content': SCRIPT2}, + }, +) diff --git a/test/mockdata/mock_build_date.py b/test/mockdata/mock_build_date.py index 609210582..837550380 100644 --- a/test/mockdata/mock_build_date.py +++ b/test/mockdata/mock_build_date.py @@ -1,15 +1,10 @@ from Testing import get_tested_mock_package -BUILDDATE = get_tested_mock_package( - files={ - '/bin/with-date': {'content': """Jan 1 2019"""}, - '/bin/with-datetime': {'content': """Jan 1 2019 12:15:11"""} - } -) -BUILDDATE2 = get_tested_mock_package( +BuildDatePackage = get_tested_mock_package( + lazyload=True, files={ - '/bin/script1', - '/bin/script2' - } + '/bin/with-date': {'content': 'Jan 1 2019'}, + '/bin/with-datetime': {'content': 'Jan 1 2019 12:15:11'}, + }, ) diff --git a/test/mockdata/mock_build_root.py b/test/mockdata/mock_build_root.py index a20681bd6..b66d452b4 100644 --- a/test/mockdata/mock_build_root.py +++ b/test/mockdata/mock_build_root.py @@ -1,6 +1,9 @@ from Testing import get_tested_mock_package -BUILDROOT = get_tested_mock_package( -files={ -'/bin/trace': {'content': '/home/marxin/rpmbuild/BUILDROOT/buildroot-0-0.x86_64'} -}) + +BuildrootPackage = get_tested_mock_package( + lazyload=True, + files={ + '/bin/trace': {'content': '/home/marxin/rpmbuild/BUILDROOT/buildroot-0-0.x86_64'}, + }, +) diff --git a/test/mockdata/mock_config_files.py b/test/mockdata/mock_config_files.py index db79780a7..cdc4c4281 100644 --- a/test/mockdata/mock_config_files.py +++ b/test/mockdata/mock_config_files.py @@ -3,7 +3,8 @@ from Testing import get_tested_mock_package -CONFIGFILES = get_tested_mock_package( +ConfigFilesBrokenPackage = get_tested_mock_package( + lazyload=True, files={ '/etc/conffile1': {'metadata': {'flags': RPMFILE_CONFIG}}, '/var/conffile2': {'metadata': {'flags': RPMFILE_CONFIG}}, @@ -11,17 +12,9 @@ } ) -CONFIGFILES2 = get_tested_mock_package( - files=[ - 'tmp/foo/my.log', - 'tmp/foo2/my.log', - 'etc/logrotate.d/logrotate2.conf', - 'etc/logrotate.d/logrotate.conf', - ] -) - -CONFIGFILES3 = get_tested_mock_package( +ConfigFilesOkPackage = get_tested_mock_package( + lazyload=True, files={ '/etc/conffile1': {'metadata': {'flags': RPMFILE_CONFIG & RPMFILE_NOREPLACE}}, '/var/conffile2': {'metadata': {'flags': RPMFILE_CONFIG & RPMFILE_NOREPLACE}}, diff --git a/test/mockdata/mock_dbus_policy.py b/test/mockdata/mock_dbus_policy.py index d7f1e65f5..230f24939 100644 --- a/test/mockdata/mock_dbus_policy.py +++ b/test/mockdata/mock_dbus_policy.py @@ -1,29 +1,15 @@ from Testing import get_tested_mock_package -DBUSPOLICY = get_tested_mock_package( -files={ -'/etc/dbus-1/system.d/noxml.conf': { -'content': '', -}, -'/etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf': { -'content': """ - - - - - - - - - -""", -}, -'/etc/dbus-1/system.d/org.freedesktop.NetworkManager2.conf': { -'content': """ - - - - - -""", -}}) + +DbusRulePackage = get_tested_mock_package( + lazyload=True, + files={ + '/etc/dbus-1/system.d/noxml.conf': {}, + '/etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf': { + 'content-path': 'files/systemd/org.freedesktop.NetworkManager.conf', + }, + '/etc/dbus-1/system.d/org.freedesktop.NetworkManager2.conf': { + 'content-path': 'files/systemd/org.freedesktop.NetworkManager2.conf', + }, + }, +) diff --git a/test/mockdata/mock_doc.py b/test/mockdata/mock_doc.py new file mode 100644 index 000000000..11ed3ee0e --- /dev/null +++ b/test/mockdata/mock_doc.py @@ -0,0 +1,89 @@ +import stat + +import rpm + +from Testing import get_tested_mock_package + + +MyDocPackage = get_tested_mock_package( + lazyload=True, + files={ + '/usr/share/doc/packages/mydoc/README': { + 'metadata': { + 'mode': 0o755 | stat.S_IFREG, + 'flags': rpm.RPMFILE_DOC, + }, + }, + '/usr/share/doc/packages/mydoc/doc.html': { + 'metadata': { + 'mode': 0o755 | stat.S_IFREG, + 'flags': rpm.RPMFILE_DOC, + }, + }, + '/usr/share/doc/packages/mydoc/strace.txt': { + 'metadata': { + 'mode': 0o644 | stat.S_IFREG, + 'flags': rpm.RPMFILE_DOC, + 'size': 268 * 1024, + }, + }, + }, + header={ + 'requires': [ + 'python-leftover', + 'python-no-leftover', + ], + }, +) + + +DocFileDependencyPackage = get_tested_mock_package( + lazyload=True, + name='doc-file-dependency', + files={ + '/usr/bin/example': { + 'metadata': {'mode': stat.S_IFREG | 0o755, 'flags': rpm.RPMFILE_DOC}, + }, + '/usr/lib/python3.7/site-packages/__pycache__/example.cpython-37.pyc': { + 'metadata': { + 'mode': stat.S_IFREG | 0o644, + 'flags': rpm.RPMFILE_DOC, + 'requires': ['python(abi) = 3.7'], + }, + }, + '/usr/lib/python3.7/site-packages/example-1.0.0-py3.7.egg-info/PKG-INFO': { + 'metadata': {'mode': stat.S_IFREG | 0o644, 'flags': rpm.RPMFILE_DOC}, + }, + '/usr/lib/python3.7/site-packages/example-1.0.0-py3.7.egg-info/SOURCES.txt': { + 'metadata': {'mode': stat.S_IFREG | 0o644, 'flags': rpm.RPMFILE_DOC}, + }, + '/usr/lib/python3.7/site-packages/example-1.0.0-py3.7.egg-info/dependency_links.txt': { + 'metadata': {'mode': stat.S_IFREG | 0o644, 'flags': rpm.RPMFILE_DOC}, + }, + '/usr/lib/python3.7/site-packages/example-1.0.0-py3.7.egg-info/entry_points.txt': { + 'metadata': {'mode': stat.S_IFREG | 0o644, 'flags': rpm.RPMFILE_DOC}, + }, + '/usr/lib/python3.7/site-packages/example-1.0.0-py3.7.egg-info/top_level.txt': { + 'metadata': {'mode': stat.S_IFREG | 0o644, 'flags': rpm.RPMFILE_DOC}, + }, + '/usr/lib/python3.7/site-packages/example.py': { + 'metadata': { + 'mode': stat.S_IFREG | 0o644, + 'flags': rpm.RPMFILE_DOC, + 'requires': ['python(abi) = 3.7'], + }, + }, + }, + header={'provides': [], 'requires': []}, +) + +InstallFileInDocPackage = get_tested_mock_package( + lazyload=True, + name='install-file-in-docs', + files={ + '/usr/share/doc/packages/install-file-in-docs/INSTALL': { + 'metadata': {'mode': stat.S_IFREG | 0o644, 'flags': rpm.RPMFILE_DOC}, + }, + }, + header={'provides': [], 'requires': []}, +) diff --git a/test/mockdata/mock_erlang.py b/test/mockdata/mock_erlang.py index 8b6044c6b..f44f94e29 100644 --- a/test/mockdata/mock_erlang.py +++ b/test/mockdata/mock_erlang.py @@ -1,6 +1,7 @@ from Testing import get_tested_mock_package -ERLANG = get_tested_mock_package( +ErlangPackage = get_tested_mock_package( + lazyload=True, files={ '/usr/lib/erlang/m-no-CInf.beam': { 'content-path': 'files/m-no-CInf.beam', @@ -16,6 +17,7 @@ 'rpmlib(CompressedFileNames) <= 3.0.4-1', 'rpmlib(FileDigests) <= 4.6.0-1', 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsZstd) <= 5.4.18-1'], + 'rpmlib(PayloadIsZstd) <= 5.4.18-1', + ], }, ) diff --git a/test/mockdata/mock_files.py b/test/mockdata/mock_files.py index de63f29b3..4c40a4d68 100644 --- a/test/mockdata/mock_files.py +++ b/test/mockdata/mock_files.py @@ -4,97 +4,108 @@ from Testing import get_tested_mock_package -FILES = get_tested_mock_package( + +UnexpandedMacroFilesPackage = get_tested_mock_package( + lazyload=True, files={ '/%{unexpanded}/test': {}, '/usr/bin/unexpanded-macro-files': {'is_dir': True}, '/usr/share/licenses/unexpanded-macro-files': {'is_dir': True}, - '/usr/share/licenses/unexpanded-macro-files/LICENSE': {} + '/usr/share/licenses/unexpanded-macro-files/LICENSE': {}, }, - header={ - 'requires': [""" - /bin/bash - bash - rpmlib(CompressedFileNames) <= 3.0.4-1 - rpmlib(FileDigests) <= 4.6.0-1 - rpmlib(PayloadFilesHavePrefix) <= 4.0-1 - rpmlib(PayloadIsZstd) <= 5.4.18-1 - """]} + header={'requires': []}, ) -FILES2 = get_tested_mock_package( + +Python3PowerPackage = get_tested_mock_package( name='python3-power', + lazyload=True, + header={'requires': ['python(abi) = 3.3']}, files={ - '/usr/lib/python3.3/site-packages/power/__init__.py': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 0 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/darwin.cpython-33.pyc': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/darwin.cpython-33.pyo': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/common.py': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 0 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/darwin.py': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 0 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/linux.py': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 0 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/tests.py': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 0 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/win32.py': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 0 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/darwin/IOPSKeys_h/index.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/darwin/IOPSKeys_h/toc.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/darwin/IOPowerSources_h/index.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/darwin/IOPowerSources_h/toc.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/linux/power_supply.h': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/linux/power_supply_class.txt': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/win32/CallNtPowerInformation.htm': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/win32/GetSystemPowerStatus .htm': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/win32/Power Setting GUIDs.htm': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/win32/PowerSettingRegisterNotification.htm': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/win32/PowerSettingUnregisterNotification.htm': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/win32/SYSTEM_BATTERY_STATE.htm': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/python3-power-1.1/win32/SYSTEM_POWER_STATUS.htm': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/__init__.cpython-33.pyc': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/__init__.cpython-33.pyo': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/common.cpython-33.pyc': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/common.cpython-33.pyo': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/linux.cpython-33.pyc': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/linux.cpython-33.pyo': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/tests.cpython-33.pyc': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/tests.cpython-33.pyo': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/win32.cpython-33.pyc': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/lib/python3.3/site-packages/power/__pycache__/win32.cpython-33.pyo': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}} + '/usr/lib/python3.3/site-packages/power/__init__.py': { + 'content-path': 'files/python3-power/__init__.py', + 'metadata': {'mtime': 1_363_887_182}, + }, + '/usr/lib/python3.3/site-packages/power/common.py': { + 'content-path': 'files/python3-power/common.py', + 'metadata': {'mtime': 1_363_887_182}, + }, + '/usr/lib/python3.3/site-packages/power/__pycache__/__init__.cpython-33.pyc': { + 'content-path': 'files/python3-power/__init__.cpython-33.pyc', + }, + '/usr/lib/python3.3/site-packages/power/__pycache__/__init__.cpython-33.pyo': { + 'content-path': 'files/python3-power/__init__.cpython-33.pyo', + }, + '/usr/lib/python3.3/site-packages/power/__pycache__/common.cpython-33.pyc': { + 'content-path': 'files/python3-power/common.cpython-33.pyc', + }, + '/usr/lib/python3.3/site-packages/power/__pycache__/common.cpython-33.pyo': { + 'content-path': 'files/python3-power/common.cpython-33.pyo', + }, + '/usr/share/doc/python3-power-1.1/index.html': { + 'metadata': {'flags': rpm.RPMFILE_DOC, 'size': 100}, + }, + }, +) + + +Python3PowerBrokenPackage = Python3PowerPackage.clone( + files={ + '/usr/lib/python3.3/site-packages/power/__init__.py': { + 'content-path': 'files/python3-power/__init__.py', + 'metadata': {'mtime': 1_363_887_182}, + }, + '/usr/lib/python3.3/site-packages/power/__pycache__/__init__.cpython-33.pyc': { + 'content': 'BROKEN-MAGIC-PYC', + }, + '/usr/share/doc/python3-power-1.1/index.html': { + 'metadata': {'flags': rpm.RPMFILE_DOC, 'size': 100}, + }, }, - header={ - 'requires': [ - 'python(abi) = 3.3', - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PartialHardlinkSets) <= 4.0.4-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1' - ] - } ) -FILES3 = get_tested_mock_package( + +TestDocumentationPackage = get_tested_mock_package( name='testdocumentation', + lazyload=True, files={ - 'usr/share/doc/packages/testdocumentation': {'is_dir': True, 'metadata': {'mode': 0o755 | stat.S_IFDIR, 'user': 'root', 'group': 'root', 'flags': 0}}, - '/usr/share/doc/packages/testdocumentation/README1.gz': {'content-path': 'files/README1.gz', 'create_dirs': True, 'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 2 | rpm.RPMFILE_DOC}}, - '/usr/share/doc/packages/testdocumentation/README2.bz2': {'content-path': 'files/README2.bz2', 'create_dirs': True, 'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 2 | rpm.RPMFILE_DOC}}, - '/usr/share/doc/packages/testdocumentation/README3.xz': {'content-path': 'files/README3.xz', 'create_dirs': True, 'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 2 | rpm.RPMFILE_DOC}}, + 'usr/share/doc/packages/testdocumentation': {'is_dir': True}, + '/usr/share/doc/packages/testdocumentation/README1.gz': { + 'content-path': 'files/README1.gz', + 'metadata': {'flags': rpm.RPMFILE_DOC}, + }, + '/usr/share/doc/packages/testdocumentation/README2.bz2': { + 'content-path': 'files/README2.bz2', + 'metadata': {'flags': rpm.RPMFILE_DOC}, + }, + '/usr/share/doc/packages/testdocumentation/README3.xz': { + 'content-path': 'files/README3.xz', + 'metadata': {'flags': rpm.RPMFILE_DOC}, + }, }, - header={ - 'requires': { - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1' - } - } + header={'requires': {}}, ) -FILES4 = get_tested_mock_package( + +NetmaskDebugsourcePackage = get_tested_mock_package( + lazyload=True, name='netmask-debugsource', files={ - '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/errors.c': {'content-path': 'files/netmask/errors.c', 'metadata': {'mode': 0o644 | stat.S_IFREG}}, - '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/errors.h': {'content-path': 'files/netmask/errors.h', 'metadata': {'mode': 0o644 | stat.S_IFREG}}, - '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/main.c': {'content-path': 'files/netmask/main.c', 'metadata': {'mode': 0o644 | stat.S_IFREG}}, - '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/netmask.c': {'content-path': 'files/netmask/netmask.c', 'metadata': {'mode': 0o644 | stat.S_IFREG}}, - '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/netmask.h': {'content-path': 'files/netmask/netmask.h', 'metadata': {'mode': 0o644 | stat.S_IFREG}}, + '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/errors.c': { + 'content-path': 'files/netmask/errors.c', + }, + '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/errors.h': { + 'content-path': 'files/netmask/errors.h', + }, + '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/main.c': { + 'content-path': 'files/netmask/main.c', + }, + '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/netmask.c': { + 'content-path': 'files/netmask/netmask.c', + }, + '/usr/src/debug/netmask-2.4.3-5.fc27.x86_64/netmask.h': { + 'content-path': 'files/netmask/netmask.h', + }, }, header={ 'version': '2.4.3', @@ -108,7 +119,8 @@ } ) -FILES5 = get_tested_mock_package( +MakefileJunkPackage = get_tested_mock_package( + lazyload=True, files={ '/usr/share/CMakeLists.txt': {}, '/usr/share/Makefile.am': {'metadata': {'flags': rpm.RPMFILE_DOC}}, @@ -118,268 +130,150 @@ '/usr/src/foo': {'is_dir': True}, '/usr/src/foo/Makefile': {} }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsZstd) <= 5.4.18-1' - ] - } + header={'requires': []}, ) -FILES6 = get_tested_mock_package( +SphinxInvPackage = get_tested_mock_package( + lazyload=True, files={ - '/usr/lib64/python3.7/site-packages/greenlet-0.4.15-py3.7.egg-info': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 0 | stat.S_IFREG}}, - '/usr/lib64/python3.7/site-packages/greenlet.cpython-37m-x86_64-linux-gnu.so': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o755, 'flags': 0 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/AUTHORS': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/NEWS': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/README.rst': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_sources/greenlet.txt': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_sources/index.txt': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/basic.css': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/classic.css': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/default.css': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/doctools.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/documentation_options.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/file.png': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/jquery-3.2.1.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/jquery.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/language_data.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/minus.png': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/plus.png': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/pygments.css': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/searchtools.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/sidebar.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/underscore-1.3.1.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/_static/underscore.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/genindex.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/greenlet.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/index.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/objects.inv': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/search.html': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/doc/packages/python3-greenlet/html/searchindex.js': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 2 | stat.S_IFREG}}, - '/usr/share/licenses/python3-greenlet/LICENSE': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 128 | stat.S_IFREG}}, - '/usr/share/licenses/python3-greenlet/LICENSE.PSF': {'metadata': {'user': 'root', 'group': 'root', 'mode': 0o644, 'flags': 128 | stat.S_IFREG}}, + '/usr/share/doc/packages/python3-greenlet/html/objects.inv': { + 'metadata': {'flags': rpm.RPMFILE_DOC}, + 'content': '# Sphinx inventory version 2', + }, }, - header={ - 'requires': [ - 'libc.so.6()(64bit)', - 'libc.so.6(GLIBC_2.14)(64bit)', - 'libc.so.6(GLIBC_2.2.5)(64bit)', - 'libc.so.6(GLIBC_2.4)(64bit)', - 'libpython3.7m.so.1.0()(64bit)', - 'python(abi) = 3.7', - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - ] - } + header={'requires': []}, ) -FILES7 = get_tested_mock_package( - files={ - '/.gitignore': {}, - '/.htaccess': {}, - '/bin/foo/bar': {}, - '/etc/systemd/system/foo': {}, - '/etc/tmpfiles.d/foo': {}, - '/etc/udev/rules.d/foo': {}, - '/run/foo': {}, - '/site_perl/foo': {}, - '/usr/info/dir': {}, - '/usr/share/doc/perl-foo/MANIFEST': {}, - '/~backup.rej': {} - }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - ] - } + +FileChecksPackage = get_tested_mock_package( + lazyload=True, + files=[ + '/run/foo', + '/etc/systemd/system/foo', + '/etc/udev/rules.d/foo', + '/etc/tmpfiles.d/foo', + '/bin/foo/bar', + '/site_perl/foo', + '/~backup.rej', + '/.gitignore', + '/.htaccess', + '/usr/share/doc/perl-foo/MANIFEST', + '/usr/info/dir', + ], + header={'requires': []}, ) -FILES8 = get_tested_mock_package( - files={ - '/usr/lib64/tcl/pkgIndex.tcl': {} - }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - ] - } + +TclPackage = get_tested_mock_package( + lazyload=True, + files=['/usr/lib64/tcl/pkgIndex.tcl'], + header={'requires': []}, ) -FILES9 = get_tested_mock_package( + +RustFilesPackage = get_tested_mock_package( + lazyload=True, files={ - '/etc/bar.rs': {'content': '#![allow(box_pointers)]', 'metadata': {'mode': 0o755}}, + '/etc/bar.rs': { + 'content': '#![allow(box_pointers)]', + 'metadata': {'mode': 0o644 | stat.S_IFREG}, + }, '/etc/foo.rs': { 'content': '#![allow(box_pointers)]', - 'metadata': {'mode': 0o755 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': rpm.RPMFILE_DOC} + 'metadata': {'mode': 0o755 | stat.S_IFREG}, }, }, - header={ - 'requires': [ - 'insserv', - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - 'xinetd', - ] - } + header={'requires': []}, ) -FILES10 = get_tested_mock_package( + +ManPagesPackage = get_tested_mock_package( + lazyload=True, files={ - '/etc/ngircd.conf': {}, - '/etc/pam.d/ngircd': {}, - '/usr/lib/systemd/system/ngircd.service': {}, - '/usr/sbin/ngircd': {}, - '/usr/share/doc/ngircd': {'is_dir': True}, - '/usr/share/doc/ngircd/AUTHORS': {}, - '/usr/share/doc/ngircd/Bopm.txt': {}, - '/usr/share/doc/ngircd/COPYING': {}, - '/usr/share/doc/ngircd/Capabilities.txt': {}, - '/usr/share/doc/ngircd/ChangeLog': {}, - '/usr/share/doc/ngircd/Commands.txt': {}, - '/usr/share/doc/ngircd/Contributing.txt': {}, - '/usr/share/doc/ngircd/FAQ.txt': {}, - '/usr/share/doc/ngircd/GIT.txt': {}, - '/usr/share/doc/ngircd/HowToRelease.txt': {}, - '/usr/share/doc/ngircd/Modes.txt': {}, - '/usr/share/doc/ngircd/NEWS': {}, - '/usr/share/doc/ngircd/PAM.txt': {}, - '/usr/share/doc/ngircd/Platforms.txt': {}, - '/usr/share/doc/ngircd/Protocol.txt': {}, - '/usr/share/doc/ngircd/README': {}, - '/usr/share/doc/ngircd/README-AUX.txt': {}, - '/usr/share/doc/ngircd/README-BeOS.txt': {}, - '/usr/share/doc/ngircd/README-Interix.txt': {}, - '/usr/share/doc/ngircd/RFC.txt': {}, - '/usr/share/doc/ngircd/SSL.txt': {}, - '/usr/share/doc/ngircd/Services.txt': {}, - '/usr/share/doc/ngircd/sample-ngircd.conf': {}, - '/usr/share/doc/ngircd/sample-ngircd.conf.tmpl': {}, - '/usr/share/man/man5/ngircd.conf.5.gz': {}, - '/usr/share/man/man8/ngircd.8.gz': {}, - '/var/run/ngircd': {} + '/etc/ngircd.conf': {'content': 'conf'}, + '/usr/sbin/ngircd': {'content': 'XXXX', 'metadata': {'mode': 0o755 | stat.S_IFREG}}, + '/usr/share/man/man5/ngircd.conf.5.gz': {'content': 'gz'}, + '/usr/share/man/man8/ngircd.8.gz': {'content': 'gz', 'metadata': {'flags': rpm.RPMFILE_DOC}}, }, - header={ - 'requires': [""" - /bin/sh - /bin/sh - /bin/sh - /bin/sh - config(ngircd) = 22-2.fc22 - libc.so.6()(64bit) - libc.so.6(GLIBC_2.14)(64bit) - libc.so.6(GLIBC_2.15)(64bit) - libc.so.6(GLIBC_2.2.5)(64bit) - libc.so.6(GLIBC_2.3)(64bit) - libc.so.6(GLIBC_2.3.2)(64bit) - libc.so.6(GLIBC_2.3.4)(64bit) - libc.so.6(GLIBC_2.4)(64bit) - libgnutls.so.28()(64bit) - libgnutls.so.28(GNUTLS_1_4)(64bit) - libident.so.0()(64bit) - libpam.so.0()(64bit) - libpam.so.0(LIBPAM_1.0)(64bit) - libwrap.so.0()(64bit) - libz.so.1()(64bit) - rpmlib(CompressedFileNames) <= 3.0.4-1 - rpmlib(FileDigests) <= 4.6.0-1 - rpmlib(PayloadFilesHavePrefix) <= 4.0-1 - rpmlib(PayloadIsXz) <= 5.2-1 - rtld(GNU_HASH) - shadow-utils - systemd - systemd - systemd"""] - } + header={'requires': []}, ) -FILES11 = get_tested_mock_package( + +DevelopmentPackage = get_tested_mock_package( + lazyload=True, name='my-package-devel', files={ - '/usr/x.typelib': {'content-path': 'files/x.typelib', 'metadata': {'mode': 0o644 | stat.S_IFREG, 'size': 100, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}} + '/usr/x.typelib': {'metadata': {'size': 100}}, }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1' - ] - } + header={'requires': []}, ) -FILES12 = get_tested_mock_package( + +Shlib1Package = get_tested_mock_package( name='shlib1', + lazyload=True, files={ - '/usr/lib/libfoo-2.so': {'content-path': 'files/shlib2/libfoo-2.so', 'metadata': {'mode': 0o755 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}}, - '/usr/lib/libfoo-2.so.foo': {'content-path': 'files/shlib2/libfoo-2.so.foo', 'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}}, - '/usr/lib/libfoo.so': {'content-path': 'files/shlib2/libfoo.so', 'metadata': {'mode': 0o777 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}, 'linkto': 'libfoo.so.1'}, - '/usr/lib/libfoo.so.1': {'content-path': 'files/shlib2/libfoo.so.1', 'metadata': {'mode': 0o755 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}} + '/usr/lib/libfoo-2.so': { + 'content-path': 'files/shlib2/libfoo-2.so', + 'metadata': {'mode': 0o755 | stat.S_IFREG}, + }, + '/usr/lib/libfoo-2.so.foo': { + 'content-path': 'files/shlib2/libfoo-2.so.foo', + 'metadata': {'mode': 0o644 | stat.S_IFREG}, + }, + '/usr/lib/libfoo.so': { + 'linkto': 'libfoo.so.1', + 'metadata': {'mode': 0o777 | stat.S_IFREG}, + }, + '/usr/lib/libfoo.so.1': { + 'content-path': 'files/shlib2/libfoo.so.1', + 'metadata': {'mode': 0o755 | stat.S_IFREG}, + }, }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1' - ] - } + header={'requires': []}, ) +Shlib2DevelPackage = Shlib1Package.clone(name='shlib2-devel') -FILES13 = get_tested_mock_package( - name='shlib2-devel', - files={ - '/usr/lib/libfoo-2.so': {'content-path': 'files/shlib2/libfoo-2.so', 'metadata': {'mode': 0o755 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}}, - '/usr/lib/libfoo-2.so.foo': {'content-path': 'files/shlib2/libfoo-2.so.foo', 'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}}, - '/usr/lib/libfoo.so': {'content-path': 'files/shlib2/libfoo.so', 'metadata': {'mode': 0o777 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}, 'linkto': 'libfoo.so.1'}, - '/usr/lib/libfoo.so.1': {'content-path': 'files/shlib2/libfoo.so.1', 'metadata': {'mode': 0o755 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0 | rpm.RPMFILE_DOC}} - }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1' - ]} -) -FILES14 = get_tested_mock_package( +FileZeroLengthPackage = get_tested_mock_package( + lazyload=True, files={ - '/etc/security/console.apps': {'is_dir': True, 'metadata': {'mode': 0o755, 'flags': 0 | rpm.RPMFILE_GHOST | stat.S_IFDIR, 'user': 'root', 'group': 'root', 'size': 4096}}, - '/etc/security/console.apps/myapp': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'size': 100, 'flags': 1}}, - '/usr/lib/.nosearch': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'flags': 0}}, - '/usr/lib/emptyfile': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'size': 0, 'flags': 0}}, # Tamaño 0 para activar la verificación - '/usr/lib/nonemptyfile': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'size': 100, 'flags': 0}}, # Tamaño no 0 - '/usr/lib/python': {'is_dir': True, 'metadata': {'flags': rpm.RPMFILE_GHOST | stat.S_IFDIR | 0, 'size': 4096, 'mode': 0o755 | stat.S_IFDIR, 'user': 'root', 'group': 'root'}}, - '/usr/lib/python/__init__.py': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'size': 0, 'flags': 0}}, # Tamaño 0 pero será ignorado por normal_zero_length_regex - '/usr/lib/python/py.typed': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'size': 0, 'flags': 0}}, # Tamaño 0 pero será ignorado por normal_zero_length_regex - '/usr/lib/python/pypackagefromwheel-0.0.0.dist-info/REQUESTED': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'size': 0, 'flags': 0}}, # Tamaño 0 pero será ignorado - '/usr/lib/ruby/gem.build_complete': {'metadata': {'mode': 0o644 | stat.S_IFREG, 'user': 'root', 'group': 'root', 'size': 0, 'flags': 0}}, # Tamaño 0 pero será ignorado + '/usr/lib/python': {'is_dir': True}, + # Ok files + '/etc/security/console.apps/myapp': { + 'create_dirs': True, + 'metadata': { + 'mode': 0o644 | stat.S_IFREG, + 'size': 100, + 'flags': rpm.RPMFILE_CONFIG, + }, + }, + '/etc/share/doc/packages/file-zero-length/dummydoc': { + 'create_dirs': True, + 'metadata': { + 'mode': 0o644 | stat.S_IFREG, + 'size': 100, + 'flags': rpm.RPMFILE_DOC, + }, + }, + '/usr/lib/nonemptyfile': { + 'metadata': {'mode': 0o644 | stat.S_IFREG, 'size': 100}, + }, + # Not Ok file + '/usr/lib/emptyfile': {'metadata': {'mode': 0o644 | stat.S_IFREG}}, + # Ignored by normal_zero_length_regex + '/usr/lib/.nosearch': {'metadata': {'mode': 0o644 | stat.S_IFREG}}, + '/usr/lib/python/__init__.py': {'metadata': {'mode': 0o644 | stat.S_IFREG}}, + '/usr/lib/python/py.typed': {'metadata': {'mode': 0o644 | stat.S_IFREG}}, + '/usr/lib/python/pypackagefromwheel-0.0.0.dist-info/REQUESTED': {'metadata': {'mode': 0o644 | stat.S_IFREG}}, + '/usr/lib/ruby/gem.build_complete': {'metadata': {'mode': 0o644 | stat.S_IFREG}}, }, - header={ - 'requires': [ - 'config(file-zero-length) = 1.1-0', - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsZstd) <= 5.4.18-1' - ] - } + header={'requires': []}, ) -FILES15 = get_tested_mock_package( + +ManualPagesPackage = get_tested_mock_package( + lazyload=True, files={ '/usr/share/man/man0p': {'is_dir': True}, '/usr/share/man/man0p/foo.3.gz': {}, @@ -391,17 +285,12 @@ '/usr/share/man/man3/foo/bar/baz.3.gz': {}, '/usr/share/man/man3/some.3pm.gz': {} }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsZstd) <= 5.4.18-1' - ] - } + header={'requires': []}, ) -FILES16 = get_tested_mock_package( + +PythonShebangLinkPackage = get_tested_mock_package( + lazyload=True, files={ '/usr/share/package/bin.py': { 'content': '#!/usr/bin/python3\nprint("python required")', @@ -413,23 +302,13 @@ }, header={}, ) - -FILES17 = get_tested_mock_package( - files={ - '/usr/share/package/bin.py': { - 'content': '#!/usr/bin/python3\nprint("python required")', - 'metadata': {'mode': 0o755 | stat.S_IFREG}, - }, - '/usr/bin/testlink': { - 'linkto': '../share/package/bin.py', - }, - }, - header={ - 'requires': ['/usr/bin/python3'], - }, +PythonShebangLinkOkPackage = PythonShebangLinkPackage.clone( + header={'requires': ['/usr/bin/python3']}, ) -FILES18 = get_tested_mock_package( + +DirectoryWithoutXPermPackage = get_tested_mock_package( + lazyload=True, header={'requires': []}, files={ '/etc/raddb/mods-config/sql/moonshot-targeted-ids/mysql': { @@ -447,67 +326,26 @@ }, ) -FILES19 = get_tested_mock_package( + +DirectoryWithoutXPerm2Package = get_tested_mock_package( + lazyload=True, header={'requires': []}, files={ - '/etc/raddb': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/etc/raddb/certs': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/etc/raddb/mods-available': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/etc/raddb/mods-config': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/etc/raddb/policy.d': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/etc/raddb/sites-available': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/etc/raddb/sites-enabled': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/usr/lib64/freeradius': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - '/usr/share/freeradius': { - 'is_dir': True, - 'metadata': { - 'mode': 0o640 | stat.S_IFDIR - }, - }, - } + '/etc/raddb': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/etc/raddb/certs': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/etc/raddb/mods-available': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/etc/raddb/mods-config': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/etc/raddb/policy.d': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/etc/raddb/sites-available': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/etc/raddb/sites-enabled': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/usr/lib64/freeradius': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + '/usr/share/freeradius': {'is_dir': True, 'metadata': {'mode': 0o640 | stat.S_IFDIR}}, + }, ) -FILES20 = get_tested_mock_package( + +FilesWithoutPermsPackage = get_tested_mock_package( + lazyload=True, header={'requires': []}, files={ '/var/lib/pipewire': {'is_dir': True, 'metadata': {'mode': 0o000 | stat.S_IFDIR}}, @@ -519,7 +357,9 @@ }, ) -FILES21 = get_tested_mock_package( + +FilesWithoutPermsTmpfilesPackage = get_tested_mock_package( + lazyload=True, header={'requires': []}, files={ '/run/netconfig/resolv.conf': {'metadata': {'mode': 0o000, 'flags': rpm.RPMFILE_GHOST}}, @@ -534,3 +374,19 @@ }, }, ) + + +# Package with just a ghost file that doesn't exists in rpmroot during build so +# it has no permissions +NonReadableGhostPackage = get_tested_mock_package( + lazyload=True, + header={'requires': []}, + files={ + '/boohoo': { + 'metadata': { + 'mode': 0o000 | stat.S_IFREG, + 'flags': rpm.RPMFILE_GHOST, + }, + }, + }, +) diff --git a/test/mockdata/mock_i18n.py b/test/mockdata/mock_i18n.py index 9b62791b9..09a9a9218 100644 --- a/test/mockdata/mock_i18n.py +++ b/test/mockdata/mock_i18n.py @@ -1,10 +1,23 @@ from Testing import get_tested_mock_package -I18N = get_tested_mock_package(files=['/usr/share/locale/xx_ES/LC_MESSAGES/goodvibes.mo']) -I18N2 = get_tested_mock_package(files=['/usr/share/locale/es_XX/LC_MESSAGES/goodvibes.mo']) -I18N3 = get_tested_mock_package(files=['/usr/share/locale/xx/LC_MESSAGES/goodvibes.mo']) -I18N4 = get_tested_mock_package(files=['/usr/share/locale/zh/LC_MESSAGES/goodvibes.mo']) -I18N5 = get_tested_mock_package(files=['/usr/share/locale/zh_Hant/LC_MESSAGES/goodvibes.mo']) -I18N6 = get_tested_mock_package(files=['/usr/share/locale/es_ES/LC_MESSAGES/goodvibes.mo']) -I18N7 = get_tested_mock_package(files=['/usr/share/locale/zh_TW/LC_MESSAGES/goodvibes.mo']) -I18N8 = get_tested_mock_package(files=['/usr/share/locale/pt_BR/LC_MESSAGES/goodvibes.mo']) + +I18NPackage = get_tested_mock_package( + lazyload=True, + files=[ + '/usr/share/locale/zh/LC_MESSAGES/goodvibes.mo', + '/usr/share/locale/zh_Hant/LC_MESSAGES/goodvibes.mo', + '/usr/share/locale/es_ES/LC_MESSAGES/goodvibes.mo', + '/usr/share/locale/zh_TW/LC_MESSAGES/goodvibes.mo', + '/usr/share/locale/pt_BR/LC_MESSAGES/goodvibes.mo', + ], +) + + +InvalidI18NPackage = get_tested_mock_package( + lazyload=True, + files=[ + '/usr/share/locale/xx_ES/LC_MESSAGES/goodvibes.mo', + '/usr/share/locale/es_XX/LC_MESSAGES/goodvibes.mo', + '/usr/share/locale/xx/LC_MESSAGES/goodvibes.mo', + ], +) diff --git a/test/mockdata/mock_icon_sizes.py b/test/mockdata/mock_icon_sizes.py index 31c37ff15..c67f860ec 100644 --- a/test/mockdata/mock_icon_sizes.py +++ b/test/mockdata/mock_icon_sizes.py @@ -1,11 +1,10 @@ from Testing import get_tested_mock_package -ICONSIZES = get_tested_mock_package( + +WrongIconSizePackage = get_tested_mock_package( files={ '/usr/share/tasque/icons/hicolor/16x16/status/tasque-note.png': { - 'metadata': { - 'magic': '22 x 22' - } + 'metadata': {'magic': '22 x 22'} } } ) diff --git a/test/mockdata/mock_lib_dependency.py b/test/mockdata/mock_lib_dependency.py deleted file mode 100644 index 0bbd59ad8..000000000 --- a/test/mockdata/mock_lib_dependency.py +++ /dev/null @@ -1,113 +0,0 @@ -from Testing import get_tested_mock_package - -LIBDEPENDENCY = get_tested_mock_package( -name='shlib2-devel', - files={ - '/usr/lib/libfoo.so': {'linkto': 'libfoo.so.1'}, - }, - header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - ], - }, -) - -LIBDEPENDENCY2 = get_tested_mock_package( -files={ -'/usr/bin/xrootd-config', -'/usr/include/xrootd', -'/usr/include/xrootd/XProtocol', -'/usr/include/xrootd/XProtocol/XProtocol.hh', -'/usr/include/xrootd/XProtocol/XPtypes.hh', -'/usr/include/xrootd/Xrd', -'/usr/include/xrootd/Xrd/XrdBuffer.hh', -'/usr/include/xrootd/Xrd/XrdJob.hh', -'/usr/include/xrootd/Xrd/XrdLink.hh', -'/usr/include/xrootd/Xrd/XrdLinkMatch.hh', -'/usr/include/xrootd/Xrd/XrdProtocol.hh', -'/usr/include/xrootd/Xrd/XrdScheduler.hh', -'/usr/include/xrootd/Xrd/XrdTcpMonPin.hh', -'/usr/include/xrootd/XrdCks', -'/usr/include/xrootd/XrdCks/XrdCks.hh', -'/usr/include/xrootd/XrdCks/XrdCksAssist.hh', -'/usr/include/xrootd/XrdCks/XrdCksCalc.hh', -'/usr/include/xrootd/XrdCks/XrdCksData.hh', -'/usr/include/xrootd/XrdCks/XrdCksManager.hh', -'/usr/include/xrootd/XrdCks/XrdCksWrapper.hh', -'/usr/include/xrootd/XrdNet', -'/usr/include/xrootd/XrdNet/XrdNet.hh', -'/usr/include/xrootd/XrdNet/XrdNetAddr.hh', -'/usr/include/xrootd/XrdNet/XrdNetAddrInfo.hh', -'/usr/include/xrootd/XrdNet/XrdNetCmsNotify.hh', -'/usr/include/xrootd/XrdNet/XrdNetConnect.hh', -'/usr/include/xrootd/XrdNet/XrdNetOpts.hh', -'/usr/include/xrootd/XrdNet/XrdNetSockAddr.hh', -'/usr/include/xrootd/XrdNet/XrdNetSocket.hh', -'/usr/include/xrootd/XrdNet/XrdNetUtils.hh', -'/usr/include/xrootd/XrdOuc', -'/usr/include/xrootd/XrdOuc/XrdOucBuffer.hh', -'/usr/include/xrootd/XrdOuc/XrdOucCRC.hh', -'/usr/include/xrootd/XrdOuc/XrdOucCacheCM.hh', -'/usr/include/xrootd/XrdOuc/XrdOucCacheStats.hh', -'/usr/include/xrootd/XrdOuc/XrdOucCallBack.hh', -'/usr/include/xrootd/XrdOuc/XrdOucChain.hh', -'/usr/include/xrootd/XrdOuc/XrdOucCompiler.hh', -'/usr/include/xrootd/XrdOuc/XrdOucDLlist.hh', -'/usr/include/xrootd/XrdOuc/XrdOucEnum.hh', -'/usr/include/xrootd/XrdOuc/XrdOucEnv.hh', -'/usr/include/xrootd/XrdOuc/XrdOucErrInfo.hh', -'/usr/include/xrootd/XrdOuc/XrdOucGMap.hh', -'/usr/include/xrootd/XrdOuc/XrdOucHash.hh', -'/usr/include/xrootd/XrdOuc/XrdOucHash.icc', -'/usr/include/xrootd/XrdOuc/XrdOucIOVec.hh', -'/usr/include/xrootd/XrdOuc/XrdOucLock.hh', -'/usr/include/xrootd/XrdOuc/XrdOucName2Name.hh', -'/usr/include/xrootd/XrdOuc/XrdOucPinObject.hh', -'/usr/include/xrootd/XrdOuc/XrdOucPinPath.hh', -'/usr/include/xrootd/XrdOuc/XrdOucRash.hh', -'/usr/include/xrootd/XrdOuc/XrdOucRash.icc', -'/usr/include/xrootd/XrdOuc/XrdOucSFVec.hh', -'/usr/include/xrootd/XrdOuc/XrdOucStream.hh', -'/usr/include/xrootd/XrdOuc/XrdOucString.hh', -'/usr/include/xrootd/XrdOuc/XrdOucTList.hh', -'/usr/include/xrootd/XrdOuc/XrdOucTable.hh', -'/usr/include/xrootd/XrdOuc/XrdOucTokenizer.hh', -'/usr/include/xrootd/XrdOuc/XrdOucTrace.hh', -'/usr/include/xrootd/XrdOuc/XrdOucUtils.hh', -'/usr/include/xrootd/XrdOuc/XrdOuca2x.hh', -'/usr/include/xrootd/XrdSec', -'/usr/include/xrootd/XrdSec/XrdSecAttr.hh', -'/usr/include/xrootd/XrdSec/XrdSecEntity.hh', -'/usr/include/xrootd/XrdSec/XrdSecEntityAttr.hh', -'/usr/include/xrootd/XrdSec/XrdSecEntityPin.hh', -'/usr/include/xrootd/XrdSec/XrdSecInterface.hh', -'/usr/include/xrootd/XrdSys', -'/usr/include/xrootd/XrdSys/XrdSysAtomics.hh', -'/usr/include/xrootd/XrdSys/XrdSysError.hh', -'/usr/include/xrootd/XrdSys/XrdSysFD.hh', -'/usr/include/xrootd/XrdSys/XrdSysHeaders.hh', -'/usr/include/xrootd/XrdSys/XrdSysLogPI.hh', -'/usr/include/xrootd/XrdSys/XrdSysLogger.hh', -'/usr/include/xrootd/XrdSys/XrdSysPageSize.hh', -'/usr/include/xrootd/XrdSys/XrdSysPlatform.hh', -'/usr/include/xrootd/XrdSys/XrdSysPlugin.hh', -'/usr/include/xrootd/XrdSys/XrdSysPthread.hh', -'/usr/include/xrootd/XrdSys/XrdSysSemWait.hh', -'/usr/include/xrootd/XrdSys/XrdSysTimer.hh', -'/usr/include/xrootd/XrdSys/XrdSysXAttr.hh', -'/usr/include/xrootd/XrdSys/XrdSysXSLock.hh', -'/usr/include/xrootd/XrdVersion.hh', -'/usr/include/xrootd/XrdXml', -'/usr/include/xrootd/XrdXml/XrdXmlReader.hh', -'/usr/lib64/libXrdAppUtils.so', -'/usr/lib64/libXrdCrypto.so', -'/usr/lib64/libXrdCryptoLite.so', -'/usr/lib64/libXrdUtils.so', -'/usr/lib64/libXrdXml.so', -'/usr/share/xrootd', -'/usr/share/xrootd/cmake', -'/usr/share/xrootd/cmake/XRootDConfig.cmake', -}) diff --git a/test/mockdata/mock_logrotate.py b/test/mockdata/mock_logrotate.py new file mode 100644 index 000000000..d4ac94bb1 --- /dev/null +++ b/test/mockdata/mock_logrotate.py @@ -0,0 +1,50 @@ +import stat + +from Testing import get_tested_mock_package + + +LogrotatePackage = get_tested_mock_package( + lazyload=True, + files={ + '/tmp/foo': { + 'create_dirs': True, + 'is_dir': True, + 'metadata': { + 'mode': stat.S_IFDIR | 0o755, + 'user': 'marxin', + 'group': 'users', + }, + }, + '/tmp/foo2': { + 'create_dirs': True, + 'is_dir': True, + 'metadata': { + 'mode': stat.S_IFREG | stat.S_ISUID | 0o777, + 'user': 'root', + 'group': 'users2', + }, + }, + '/tmp/foo/my.log': { + 'metadata': { + 'mode': 0o644 | stat.S_IFREG, + 'user': 'root', + 'group': 'users2', + }, + }, + '/tmp/foo2/my.log': { + 'metadata': { + 'mode': stat.S_IFREG | stat.S_ISUID | 0o777, + 'user': 'root', + 'group': 'users2', + }, + }, + '/etc/logrotate.d/logrotate.conf': { + 'create_dirs': True, + 'content-path': 'files/logrotate/logrotate.conf', + }, + '/etc/logrotate.d/logrotate2.conf': { + 'create_dirs': True, + 'content-path': 'files/logrotate/logrotate2.conf', + }, + } +) diff --git a/test/mockdata/mock_menuxdg.py b/test/mockdata/mock_menuxdg.py index 4a1c59649..5896a9208 100644 --- a/test/mockdata/mock_menuxdg.py +++ b/test/mockdata/mock_menuxdg.py @@ -1,17 +1,13 @@ from Testing import get_tested_mock_package -MENUXDG = get_tested_mock_package( -files={ -'/usr/share/applications/somefile.desktop': {'content': """ + +BROKEN = """ [DEFAULT] something = true [else -"""} -}) +""" -MENUXDG1 = get_tested_mock_package( -files={ -'/usr/share/applications/rpmlint-test.desktop': {'content': """ +BADBIN = """ [Desktop Entry] Name=rpmlint-test Exec=rpmlint-test file.file @@ -19,12 +15,10 @@ Type=Application GenericName=rpmlint testcase Categories=Game;Amusement; -"""} -}) +""" + -MENUXDG2 = get_tested_mock_package( -files={ -'/usr/share/applications/rpmlint-test.desktop': {'content': """ +BADDUP = """ [Desktop Entry] [Desktop Entry] Name=rpmlint-test @@ -34,36 +28,61 @@ Type=Application GenericName=rpmlint testcase Categories=Game;Amusement; -"""} -}) +""" -MENUXDG3 = get_tested_mock_package( -files={ -'/usr/share/applications/rpmlint-test.desktop': {'content': """ + +BADSEC = """ Name=rpmlint-test [Bad Section] Name[x-test]=xxrpmlint-testxx Exec=rpmlint-test file.file Icon=rpmlint-test Type=Application -GenericName=rpmlint testcase"""} -}) - -MENUXDG4 = get_tested_mock_package( -files={ -'/usr/share/applications/rpmlint-test.desktop': { - 'content-path': 'files/rpmlint-test.desktop', - 'create_dirs': True, -} -}) - -MENUXDG5 = get_tested_mock_package( -files={ -'/usr/bin/rpmlint-test', -'/usr/share/applications', -'/usr/share/applications/rpmlint-test.desktop', -'/usr/share/icons/hicolor', -'/usr/share/icons/hicolor/scalable', -'/usr/share/icons/hicolor/scalable/apps', -'/usr/share/icons/hicolor/scalable/apps/chameleon_v_balíku.png' -}) +GenericName=rpmlint testcase +""" + + +MenuXDGInvalidPackage = get_tested_mock_package( + lazyload=True, + files={'/usr/share/applications/somefile.desktop': {'content': BROKEN}}, +) + + +MenuXDGBadBinPackage = get_tested_mock_package( + lazyload=True, + files={'/usr/share/applications/rpmlint-test.desktop': {'content': BADBIN}}, +) + + +MenuXDGBadDupPackage = get_tested_mock_package( + lazyload=True, + files={'/usr/share/applications/rpmlint-test.desktop': {'content': BADDUP}}, +) + + +MenuXDGBadSecPackage = get_tested_mock_package( + lazyload=True, + files={'/usr/share/applications/rpmlint-test.desktop': {'content': BADSEC}}, +) + + +MenuXDGBadUTF8Package = get_tested_mock_package( + lazyload=True, + files={ + '/usr/share/applications/rpmlint-test.desktop': { + 'content-path': 'files/rpmlint-test.desktop', + 'create_dirs': True, + }, + }, +) + +MenuXDGPackage = get_tested_mock_package( + lazyload=True, + files={ + '/usr/bin/rpmlint-test': {}, + '/usr/share/applications/rpmlint-test.desktop': { + 'content-path': 'files/rpmlint-test-good.desktop', + 'create_dirs': True, + }, + }, +) diff --git a/test/mockdata/mock_mixed_ownership.py b/test/mockdata/mock_mixed_ownership.py index 7d5db448d..eeac6c964 100644 --- a/test/mockdata/mock_mixed_ownership.py +++ b/test/mockdata/mock_mixed_ownership.py @@ -1,15 +1,21 @@ from Testing import get_tested_mock_package -MixedOwnership = get_tested_mock_package( -files={ -'/usr/bin/noproblem': {}, - '/var/lib/badfolder': { - 'metadata': {'user': 'nobody'}, - 'is_dir': True}, - '/var/lib/badfolder/broken1': { - 'metadata': {'user': 'root'}}, - '/var/lib/badfolder/correctperms': { - 'metadata': {'user': 'root'}, - 'is_dir': True}, - '/var/lib/badfolder/correctperms/broken2': {}, -}) + +MixedOwnershipPackage = get_tested_mock_package( + lazyload=True, + files={ + '/usr/bin/noproblem': {}, + '/var/lib/badfolder': { + 'metadata': {'user': 'nobody'}, + 'is_dir': True + }, + '/var/lib/badfolder/broken1': { + 'metadata': {'user': 'root'} + }, + '/var/lib/badfolder/correctperms': { + 'metadata': {'user': 'root'}, + 'is_dir': True, + }, + '/var/lib/badfolder/correctperms/broken2': {}, + }, +) diff --git a/test/mockdata/mock_pam_modules.py b/test/mockdata/mock_pam_modules.py index 6bd7f9c52..082d154e4 100644 --- a/test/mockdata/mock_pam_modules.py +++ b/test/mockdata/mock_pam_modules.py @@ -1,7 +1,7 @@ from Testing import get_tested_mock_package -PAMMODULES = get_tested_mock_package( -files={ -'/usr/lib64/security/pam-module.so': {'content': ''} -} + +PAMModulePackage = get_tested_mock_package( + lazyload=True, + files=['/usr/lib64/security/pam-module.so'], ) diff --git a/test/mockdata/mock_pkgconfig.py b/test/mockdata/mock_pkgconfig.py index 7ea5457c7..44bea77b4 100644 --- a/test/mockdata/mock_pkgconfig.py +++ b/test/mockdata/mock_pkgconfig.py @@ -1,9 +1,7 @@ from Testing import get_tested_mock_package -PKGCONFIG = get_tested_mock_package( -files={ -'/tmp/pkgconfig/xcb.pc': {'content': """ +XCB_PC = """ prefix=/usr exec_prefix=/usr libdir=/var/tmp/usr/lib64 @@ -14,25 +12,67 @@ Version: 1.13 Requires.private: xcb Libs: -L/usr/lib -Cflags: -I${includedir}"""} -}, -header={ - 'arch': 'x86_64' -}) +Cflags: -I${includedir} +""" -PKGCONFIG2 = get_tested_mock_package( -files={ -'/usr/include/reiserfs', -'/usr/include/reiserfs/io.h', -'/usr/include/reiserfs/misc.h', -'/usr/include/reiserfs/reiserfs_err.h', -'/usr/include/reiserfs/reiserfs_fs.h', -'/usr/include/reiserfs/reiserfs_lib.h', -'/usr/include/reiserfs/swab.h', -'/usr/lib64/libreiserfscore.a', -'/usr/lib64/libreiserfscore.la', -'/usr/lib64/libreiserfscore.so', -'/usr/lib64/libreiserfscore.so.0', -'/usr/lib64/pkgconfig/reiserfscore.pc'} +PCPackage = get_tested_mock_package( + lazyload=True, + files={ + '/tmp/pkgconfig/xcb.pc': {'content': XCB_PC}, + }, + header={'arch': 'x86_64'}, +) + + +LibReiserFSCoreDevelPackage = get_tested_mock_package( + name='libreiserfscore-devel', + lazyload=True, + files={ + '/usr/include/reiserfs/io.h': { + 'content-path': 'files/reiserfs/io.h', + }, + '/usr/include/reiserfs/misc.h': { + 'content-path': 'files/reiserfs/misc.h', + }, + '/usr/include/reiserfs/reiserfs_err.h': { + 'content-path': 'files/reiserfs/reiserfs_err.h', + }, + '/usr/include/reiserfs/reiserfs_fs.h': { + 'content-path': 'files/reiserfs/reiserfs_fs.h', + }, + '/usr/include/reiserfs/reiserfs_lib.h': { + 'content-path': 'files/reiserfs/reiserfs_lib.h', + }, + '/usr/include/reiserfs/swab.h': { + 'content-path': 'files/reiserfs/swab.h', + }, + '/usr/lib64/libreiserfscore.a': { + 'content-path': 'files/reiserfs/libreiserfscore.a', + }, + '/usr/lib64/libreiserfscore.la': { + 'content-path': 'files/reiserfs/libreiserfscore.la', + }, + '/usr/lib64/libreiserfscore.so': { + 'link-to': 'libreiserfscore.so.0.0.0', + }, + '/usr/lib64/libreiserfscore.so.0': { + 'link-to': 'libreiserfscore.so.0.0.0', + }, + '/usr/lib64/pkgconfig/reiserfscore.pc': { + 'content-path': 'files/reiserfs/reiserfscore.pc', + }, + }, + header={ + 'requires': [ + '/usr/bin/pkg-config', + 'libcom_err-devel', + 'libreiserfscore0 = 3.6.27', + 'libuuid-devel', + 'rpmlib(CompressedFileNames) <= 3.0.4-1', + 'rpmlib(FileDigests) <= 4.6.0-1', + 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', + 'rpmlib(PayloadIsXz) <= 5.2-1', + ], + }, ) diff --git a/test/mockdata/mock_shlib_policy.py b/test/mockdata/mock_shlib_policy.py index 3d88a3bc4..a277748d2 100644 --- a/test/mockdata/mock_shlib_policy.py +++ b/test/mockdata/mock_shlib_policy.py @@ -1,24 +1,27 @@ from Testing import get_tested_mock_package -SHLIBPOLICY = get_tested_mock_package( + +Libtest1Package = get_tested_mock_package( + lazyload=True, name='libtest1', files={ - '/usr/lib64/libtest.so.1.5.0': {'content-path': 'files/shlib_policy/libtest.so.1.5.0'} + '/usr/lib64/libtest.so.1.5.0': { + # SONAME: libtest.so.1x + 'content-path': 'files/shlib_policy/libtest.so.1.5.0', + } }, header={ 'requires': [ '/sbin/ldconfig', 'libc.so.6()(64bit)', 'libc.so.6(GLIBC_2.2.5)(64bit)', - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', ] } ) -SHLIBPOLICY2 = get_tested_mock_package( + +LibslpMissingSuffixPackage = get_tested_mock_package( + lazyload=True, name='libslp-missing-suffix', files={ '/usr/lib64/hello': {'is_dir': True}, @@ -30,16 +33,15 @@ 'requires': [ 'libc.so.6()(64bit)', 'libc.so.6(GLIBC_2.2.5)(64bit)', + # Excessive dependency 'libsparta.so.2', - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsZstd) <= 5.4.18-1' ] } ) -SHLIBPOLICY3 = get_tested_mock_package( + +Libslp1234Package = get_tested_mock_package( + lazyload=True, name='libslp1234', files={ '/usr/lib64/hello': {'is_dir': True}, @@ -51,11 +53,8 @@ 'requires': [ 'libc.so.6()(64bit)', 'libc.so.6(GLIBC_2.2.5)(64bit)', + # Fixed shlib dependency 'libsparta.so.2 = 1.23', - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsZstd) <= 5.4.18-1' ] } ) diff --git a/test/mockdata/mock_sysvinitonsystemd.py b/test/mockdata/mock_sysvinitonsystemd.py index 5f7a3ebff..7dcc9233f 100644 --- a/test/mockdata/mock_sysvinitonsystemd.py +++ b/test/mockdata/mock_sysvinitonsystemd.py @@ -1,19 +1,7 @@ from Testing import get_tested_mock_package -SYSVINITONSYSTEMD = get_tested_mock_package( -files={ -'/etc/init.d/boot.script': {'content': ''}, -'/etc/init.d/weekly.script': {'content': ''} -}, -header={ -'requires': ['insserv'] -}) - - -SYSVINITONSYSTEMD2 = get_tested_mock_package( -files={ -'/etc/init.d/bar': {'content': """ +BAR_INITRD = """ #! /bin/bash ### BEGIN INIT INFO @@ -44,8 +32,25 @@ esac exit 0 -"""}, -'/usr/lib/systemd/system/bar.service': {}, -'/usr/lib/systemd/system/foo.service': {}}, -header={ -'requires': ['insserv']}) +""" + + +InitPackage = get_tested_mock_package( + lazyload=True, + files={ + '/etc/init.d/boot.script': {'content': ''}, + '/etc/init.d/weekly.script': {'content': ''}, + }, + header={'requires': ['insserv']}, +) + + +RcLinksPackage = get_tested_mock_package( + lazyload=True, + files={ + '/etc/init.d/bar': {'content': BAR_INITRD}, + '/usr/lib/systemd/system/bar.service': {}, + '/usr/lib/systemd/system/foo.service': {}, + }, + header={'requires': ['insserv']}, +) diff --git a/test/mockdata/mock_tags.py b/test/mockdata/mock_tags.py new file mode 100644 index 000000000..4544d03c5 --- /dev/null +++ b/test/mockdata/mock_tags.py @@ -0,0 +1,145 @@ +import rpm + +from Testing import get_tested_mock_package + + +UnexpandedMacroPackage = get_tested_mock_package( + lazyload=True, + name='unexpanded1', + header={ + 'requires': [], + 'provides': ['/%notreally', 'unexpanded1 = 0-0'], + 'suggests': ['/%asdf'], + 'conflicts': ['something:%unexpanded_conflicts'], + 'enhances': ['/%else'], + 'obsoletes': ['something:%unexpanded'], + 'recommends': ['/%unxpanded_recommends'], + 'supplements': ['/%something'], + 'arch': 'noarch', + 'name': 'unexpanded1', + 'version': '0', + 'release': '0', + }, +) + + +SelfPackage = get_tested_mock_package( + lazyload=True, + name='self', + header={ + 'requires': [ + 'insserv', + 'rpmlib(CompressedFileNames) <= 3.0.4-1', + 'rpmlib(FileDigests) <= 4.6.0-1', + 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', + 'rpmlib(PayloadIsXz) <= 5.2-1', + 'xinetd', + ], + 'provides': [ + 'self', + 'self = 0-0', + 'self(x86-64) = 0-0', + ], + 'arch': 'x86_64', + 'name': 'self', + 'version': '0', + 'release': '0', + }, +) + + +FuseCommonPackage = get_tested_mock_package( + lazyload=True, + name='fuse-common', + files={ + 'etc/fuse.conf': { + 'content': '# mount_max = 1000\nuser_allow_other\n', + 'flags': rpm.RPMFILE_NOREPLACE | rpm.RPMFILE_CONFIG, + }, + }, + header={ + 'requires': [ + 'config(fuse-common) = 3.10.2-5.el8', + 'rpmlib(CompressedFileNames) <= 3.0.4-1', + 'rpmlib(FileDigests) <= 4.6.0-1', + 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', + 'rpmlib(PayloadIsXz) <= 5.2-1', + ], + 'provides': [ + 'config(fuse-common) = 3.10.2-5.el8', + 'fuse-common = 3.10.2-5.el8', + 'fuse-common = 3.2.1', + 'fuse-common = 3.3.0', + 'fuse-common(x86-64) = 3.10.2-5.el8', + ], + 'arch': 'x86_64', + 'name': 'fuse-common', + 'version': '3.10.2', + 'release': '5.el8', + }, +) + + +FooDevelPackage = get_tested_mock_package( + lazyload=True, + name='foo-devel', + header={ + 'requires': [], + 'provides': [], + 'arch': 'x86_64', + 'name': 'foo-devel', + 'version': '0', + 'release': '0', + 'group': 'Games', + 'license': 'GPL-2.0+', + 'url': 'http://www.opensuse.org/', + 'buildhost': 'marxinbox.suse.cz', + 'summary': 'Lorem ipsum', + 'description': """Lorem ipsum dolor sit amet, consectetur adipisici elit, sed +eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim +ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut +aliquid ex ea commodi consequat. Quis aute iure reprehenderit in +voluptate velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui +officia deserunt mollit anim id est laborum. +""", + 'changelogname': ['daniel.garcia@suse.com'], + 'changelogtime': [1303128000], + 'changelogtext': ['dummy'], + }, +) + + +MissingProvidesPackage = get_tested_mock_package( + lazyload=True, + name='missingprovides-devel', + files=['/usr/lib64/pkgconfig/libparted.pc'], + header={ + 'requires': [], + 'provides': [], + 'arch': 'x86_64', + 'name': 'missingprovides-devel', + 'version': '0', + 'release': '0', + }, +) + + +InvalidExceptionPackage = MissingProvidesPackage.clone( + extend=True, + name='invalid-exception', + header={ + 'name': 'invalid-exception', + 'license': 'GPL-2.0+ WITH sparta', + }, +) + + +ValidExceptionPackage = InvalidExceptionPackage.clone( + extend=True, + name='valid-exception', + header={ + 'name': 'valid-exception', + 'license': 'GPL-2.0+ WITH 389-exception', + }, +) diff --git a/test/mockdata/mock_tmp_files.py b/test/mockdata/mock_tmp_files.py index a30cb7323..f64f58734 100644 --- a/test/mockdata/mock_tmp_files.py +++ b/test/mockdata/mock_tmp_files.py @@ -1,8 +1,7 @@ from Testing import get_tested_mock_package -TMPFILES = get_tested_mock_package( - files={ - '/usr/lib/tmpfiles.d/krb5.conf': {'content': """ + +KRB5_CONF = """ d /var/lib/kerberos 0755 root root - d /var/lib/kerberos/krb5 0755 root root - d /var/lib/kerberos/krb5/user 0755 root root - @@ -10,30 +9,50 @@ C /var/lib/kerberos/krb5kdc/kdc.conf 0600 root root - /usr/share/kerberos/krb5kdc/kdc.conf C /var/lib/kerberos/krb5kdc/kadm5.acl 0600 root root - /usr/share/kerberos/krb5kdc/kadm5.acl C /var/lib/kerberos/krb5kdc/kadm5.dict 0600 root root - /usr/share/kerberos/krb5kdc/kadm5.dict -"""}, +""" + + +SYSTEMD_TMPFILES_CONF = """ +# create a directory with permissions 0770 owned by user foo and group bar +d /run/my_new_directory 0770 foo bar +""" + + +PREIN = """ +[ -z "${TRANSACTIONAL_UPDATE}" -a -x /usr/bin/systemd-tmpfiles ] && + /usr/bin/systemd-tmpfiles --create /usr/lib/tmpfiles.d/systemd-tmpfiles.conf || : +""" + +POSTIN = """ +[ -z "${TRANSACTIONAL_UPDATE}" -a -x /usr/bin/systemd-tmpfiles ] && + /usr/bin/systemd-tmpfiles --create /usr/lib/tmpfiles.d/systemd-tmpfiles_correct.conf || : +""" + + +TempfiledPackage = get_tested_mock_package( + lazyload=True, + files={ + '/usr/lib/tmpfiles.d/krb5.conf': {'content': KRB5_CONF}, '/usr/lib/tmpfiles.d/symlink.conf': {'linkto': '/usr/lib/tmpfiles.d/krb5.conf'} }, header={}, ) -TMPFILES2 = get_tested_mock_package( +SystemdTempfilesPackage = get_tested_mock_package( + lazyload=True, files={ - '/usr/lib/tmpfiles.d/systemd-tmpfiles.conf': {'content': """ -# create a directory with permissions 0770 owned by user foo and group bar -d /run/my_new_directory 0770 foo bar -"""}, }, - header={ - 'PREIN': """[ -z "${TRANSACTIONAL_UPDATE}" -a -x /usr/bin/systemd-tmpfiles ] && /usr/bin/systemd-tmpfiles --create /usr/lib/tmpfiles.d/systemd-tmpfiles.conf || : -"""}, + '/usr/lib/tmpfiles.d/systemd-tmpfiles.conf': {'content': SYSTEMD_TMPFILES_CONF}, + }, + header={'PREIN': PREIN}, ) -TMPFILES3 = get_tested_mock_package( +SystemdTempfilesOkPackage = get_tested_mock_package( + lazyload=True, files={ - '/run/my_new_directory' - '/usr/lib/tmpfiles.d/systemd-tmpfiles_correct.conf': {'content': """ -# create a directory with permissions 0770 owned by user foo and group bar -d /run/my_new_directory 0770 foo bar -"""}, }, - header={}, ) + '/run/my_new_directory': {}, + '/usr/lib/tmpfiles.d/systemd-tmpfiles_correct.conf': {'content': SYSTEMD_TMPFILES_CONF}, + }, + header={'POSTIN': POSTIN}, +) diff --git a/test/mockdata/mock_xinetd.py b/test/mockdata/mock_xinetd.py index bc5bcbbfd..f493832b6 100644 --- a/test/mockdata/mock_xinetd.py +++ b/test/mockdata/mock_xinetd.py @@ -2,13 +2,10 @@ RequireXinetd = get_tested_mock_package( + lazyload=True, header={ 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - 'xinetd' - ] + 'xinetd', + ], }, ) diff --git a/test/mockdata/mock_zypp_syntax.py b/test/mockdata/mock_zypp_syntax.py index c2b1c7f0c..a40f044a7 100644 --- a/test/mockdata/mock_zypp_syntax.py +++ b/test/mockdata/mock_zypp_syntax.py @@ -1,14 +1,10 @@ from Testing import get_tested_mock_package -ZYPPSYNTAX = get_tested_mock_package( + +SyntaxPackageandPackage = get_tested_mock_package( + lazyload=True, header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - 'rpmlib(RichDependencies) <= 4.12.0-1', - ], + 'requires': [], 'supplements': ['packageand(c:d)'], 'recommends': ['packageand(a:b)'], 'suggests': ['(a and b)'], @@ -19,15 +15,11 @@ }, ) -ZYPPSYNTAX2 = get_tested_mock_package( + +SyntaxAndPackage = get_tested_mock_package( + lazyload=True, header={ - 'requires': [ - 'rpmlib(CompressedFileNames) <= 3.0.4-1', - 'rpmlib(FileDigests) <= 4.6.0-1', - 'rpmlib(PayloadFilesHavePrefix) <= 4.0-1', - 'rpmlib(PayloadIsXz) <= 5.2-1', - 'rpmlib(RichDependencies) <= 4.12.0-1', - ], + 'requires': [], 'supplements': ['(c and d)'], 'recommends': ['b'], 'suggests': ['(a and b)'], diff --git a/test/spec/yast2-installation.spec b/test/spec/yast2-installation.spec new file mode 100644 index 000000000..e77ac6607 --- /dev/null +++ b/test/spec/yast2-installation.spec @@ -0,0 +1,221 @@ +# +# spec file for package yast2-installation +# +# Copyright (c) 2024 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +Name: yast2-installation +Version: 5.0.15 +Release: 0 +Summary: YaST2 - Installation Parts +License: GPL-2.0-only +Group: System/YaST +URL: https://github.com/yast/yast-installation +Source0: %{name}-%{version}.tar.bz2 +Source1: YaST2-Second-Stage.service +Source2: YaST2-Firstboot.service + +BuildRequires: update-desktop-files +# Kernel: Use is_zvm from Yast::Arch +BuildRequires: yast2 >= 5.0.5 +# systemd-boot kernel parameters +BuildRequires: yast2-bootloader >= 5.0.9 +# storage-ng based version +BuildRequires: yast2-country >= 3.3.1 +BuildRequires: yast2-devtools >= 3.1.10 +# For firewall widgets +BuildRequires: yast2-firewall +# Y2Network::ProposalSettings #modify_defaults and #apply_defaults (forwarding configurable) +BuildRequires: yast2-network >= 4.4.12 +# ProductSpec API +BuildRequires: yast2-packager >= 4.4.13 +# yast/rspec/helpers.rb +BuildRequires: yast2-ruby-bindings >= 4.4.7 +# Support for SecurityPolicies +BuildRequires: yast2-security >= 4.5.3 +# using /usr/bin/udevadm +BuildRequires: yast2-storage-ng >= 4.2.71 +# Y2Users +BuildRequires: yast2-users >= 4.4.2 +# needed for xml agent reading about products +BuildRequires: yast2-xml +BuildRequires: rubygem(%{rb_default_ruby_abi}:rspec) +BuildRequires: rubygem(%{rb_default_ruby_abi}:yast-rake) +# Augeas lenses +Requires: augeas-lenses +Requires: coreutils +Requires: gzip +# use in startup scripts +Requires: initviocons +# bsc#1214277; require awk, not gawk, to allow for lighterweight alternatives like busybox +Requires: awk +# Needed call /sbin/ip in vnc.sh/network.sh +Requires: iproute2 +# for the first/second stage of installation +# currently not used +# bugzilla #208307 +#Requires: /usr/bin/jpegtopnm +#Requires: /usr/bin/pnmtopng +# BNC 446533, /sbin/lspci called but not installed +Requires: pciutils +# tar-gzip some system files and untar-ungzip them after the installation (FATE #300421, #120103) +Requires: tar +# /usr/lib/YaST2/bin/xftdpi, install only when the GUI is installed +Requires: (yast2-x11 >= 4.5.1 if libyui-qt) +# Y2Packager::Repository.refresh +Requires: yast2 >= 5.0.3 +Requires: yast2-bootloader >= 5.0.9 +Requires: yast2-country >= 3.3.1 +# Language::GetLanguageItems and other API +# Language::Set (handles downloading the translation extensions) +Requires: yast2-country-data >= 2.16.11 +# Y2Network::ProposalSettings #modify_defaults and #apply_defaults (forwarding configurable) +Requires: yast2-network >= 4.4.12 +# ProductSpec API +Requires: yast2-packager >= 4.4.13 +# Pkg::ProvidePackage +Requires: yast2-pkg-bindings >= 3.1.33 +# Proxy settings for 2nd stage (bnc#764951) +Requires: yast2-proxy >= 4.4.1 +# for AbortException and handle direct abort +Requires: yast2-ruby-bindings >= 4.0.6 +# Systemd default target and services. This version supports +# writing settings in the first installation stage. +Requires: yast2-services-manager >= 3.2.1 +# Only in inst-sys +Requires: yast2-storage-ng >= 4.0.175 +# Y2Users +Requires: yast2-users >= 4.4.2 +# Support for SecurityPolicies +Requires: yast2-security >= 4.5.3 +PreReq: %fillup_prereq +Recommends: yast2-add-on +Recommends: yast2-firewall +Recommends: yast2-online-update +Supplements: autoyast(deploy_image:ssh_import) +# new autoinst_files_finish call +Conflicts: autoyast2 < 4.3.26 +# SingleItemSelector not enforcing an initial selection +Conflicts: libyui < 3.8.2 +# InstError +Conflicts: yast2 < 2.18.6 +# storage-ng based version +Conflicts: yast2-bootloader < 3.3.1 +# Added new function WFM::ClientExists +Conflicts: yast2-core < 2.17.10 +# Mouse-related scripts moved to yast2-mouse +Conflicts: yast2-mouse < 2.18.0 +# Pkg::SourceProvideSignedFile Pkg::SourceProvideDigestedFile +# pkg-bindings are not directly required +Conflicts: yast2-pkg-bindings < 2.17.25 +# Registration#get_updates_list does not handle exceptions +Conflicts: yast2-registration < 3.2.3 +# Top bar with logo +Conflicts: yast2-ycp-ui-bindings < 3.1.7 +Obsoletes: yast2-installation-devel-doc +# we provide here only client that is used in microos from caasp package +# and those clients conflicts on file level +Conflicts: yast2-caasp <= 5.0.0 +BuildArch: noarch +%if 0%{?suse_version} >= 1210 +%{systemd_requires} +%endif + +%description +System installation code as present on installation media. + +%prep +%setup -q + +%check +%yast_check + +%build + +%install +%yast_install +%yast_metainfo + +for f in `find %{buildroot}%{_datadir}/autoinstall/modules -name "*.desktop"`; do + %suse_update_desktop_file $f +done + +mkdir -p %{buildroot}%{yast_vardir}/hooks/installation +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/preFirstCall +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/preSecondCall +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/postFirstCall +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/postSecondCall +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/preFirstStage +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/preSecondStage +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/postFirstStage +mkdir -p %{buildroot}%{yast_ystartupdir}/startup/hooks/postSecondStage + +mkdir -p %{buildroot}%{_unitdir} +install -m 644 %{SOURCE1} %{buildroot}%{_unitdir} +install -m 644 %{SOURCE2} %{buildroot}%{_unitdir} + +%post +%{fillup_only -ns security checksig} + +%service_add_post YaST2-Second-Stage.service YaST2-Firstboot.service + +# bsc#924278 Always enable these services by default, they are already listed +# in systemd-presets-branding package, but that works for new installations +# only, it does not work for upgrades from SLE 11 where scripts had different +# name and were not handled by systemd. +# When we upgrade/update from systemd-based system, scripts are always enabled +# by the service_add_post macro. +systemctl enable YaST2-Second-Stage.service +systemctl enable YaST2-Firstboot.service + +%pre +%service_add_pre YaST2-Second-Stage.service YaST2-Firstboot.service + +%preun +%service_del_preun YaST2-Second-Stage.service YaST2-Firstboot.service + +%postun +%service_del_postun_without_restart YaST2-Second-Stage.service YaST2-Firstboot.service + +%files +%license COPYING +%doc %{yast_docdir} +# systemd service files +%{_unitdir}/YaST2-Firstboot.service +%{_unitdir}/YaST2-Second-Stage.service +%{_bindir}/memsample +%{_bindir}/memsample-archive-to-csv +%{_bindir}/memsample-csv-plot +# yupdate script +%{_bindir}/yupdate +%{yast_clientdir} +%{yast_moduledir} +%{yast_desktopdir} +%{_datadir}/autoinstall/ +%{yast_schemadir} +%{yast_yncludedir} +%{yast_libdir} +# agents +%{yast_scrconfdir} +# fillup +%{_fillupdir}/sysconfig.security-checksig +# programs and scripts +%{yast_ystartupdir}/startup +# installation hooks +%{yast_vardir} +%{_datadir}/metainfo/org.*yast.*xml +%{_datadir}/icons/hicolor/*/apps/yast-* + +%changelog diff --git a/test/test_FHS.py b/test/test_FHS.py index 3d0357cf5..35a462fc5 100644 --- a/test/test_FHS.py +++ b/test/test_FHS.py @@ -1,4 +1,4 @@ -from mockdata.mock_FHS import FHS +from mockdata.mock_FHS import NoFHSPackage import pytest from rpmlint.checks.FHSCheck import FHSCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def fhscheck(): return output, test -@pytest.mark.parametrize('package', [FHS]) +@pytest.mark.parametrize('package', [NoFHSPackage]) def test_FHS_compliance(package, fhscheck): """ Check that the directories are not FHS compliant. diff --git a/test/test_LSB.py b/test/test_LSB.py index 96bab0ce6..4bb70136d 100644 --- a/test/test_LSB.py +++ b/test/test_LSB.py @@ -1,4 +1,4 @@ -from mockdata.mock_LSB import LSB +from mockdata.mock_LSB import NonLSBCompliancePackage import pytest from rpmlint.checks.LSBCheck import LSBCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def lsbcheck(): return output, test -@pytest.mark.parametrize('package', [LSB]) +@pytest.mark.parametrize('package', [NonLSBCompliancePackage]) def test_LSB_compliance(package, lsbcheck): """ Check that the package name, version and release number are LSB compliant. diff --git a/test/test_appdata.py b/test/test_appdata.py index b6ec132ce..58d1bca41 100644 --- a/test/test_appdata.py +++ b/test/test_appdata.py @@ -1,6 +1,6 @@ from unittest.mock import patch -from mockdata.mock_appdata import APPDATA, APPDATA2 +from mockdata.mock_appdata import AppDataPackage import pytest from rpmlint.checks.AppDataCheck import AppDataCheck from rpmlint.filter import Filter @@ -17,7 +17,7 @@ def appdatacheck(): @pytest.mark.skipif(not HAS_APPSTREAM_GLIB, reason='Optional dependency appstream-glib not installed') -@pytest.mark.parametrize('package', [APPDATA]) +@pytest.mark.parametrize('package', [AppDataPackage]) def test_appdata_fail(package, appdatacheck): output, test = appdatacheck test.check(package) @@ -27,7 +27,7 @@ def test_appdata_fail(package, appdatacheck): assert 'invalid-appdata-file' in out -@pytest.mark.parametrize('package', [APPDATA2]) +@pytest.mark.parametrize('package', [AppDataPackage]) @patch('rpmlint.checks.AppDataCheck.AppDataCheck.cmd', 'command-really-not-found') def test_appdata_fail_no_checker(package, appdatacheck): output, test = appdatacheck diff --git a/test/test_bashisms.py b/test/test_bashisms.py index 34ec4848b..5d72f21a9 100644 --- a/test/test_bashisms.py +++ b/test/test_bashisms.py @@ -1,4 +1,4 @@ -from mockdata.mock_bashisms import BASHISMS +from mockdata.mock_bashisms import BashismsPackage import pytest from rpmlint.checks.BashismsCheck import BashismsCheck from rpmlint.filter import Filter @@ -16,7 +16,7 @@ def bashismscheck(): @pytest.mark.skipif(not HAS_CHECKBASHISMS, reason='Optional dependency checkbashisms not installed') @pytest.mark.skipif(not HAS_DASH, reason='Optional dependency dash not installed') -@pytest.mark.parametrize('package', [BASHISMS]) +@pytest.mark.parametrize('package', [BashismsPackage]) def test_bashisms(package, bashismscheck): output, test = bashismscheck test.check(package) @@ -27,7 +27,7 @@ def test_bashisms(package, bashismscheck): @pytest.mark.skipif(not HAS_CHECKBASHISMS, reason='Optional dependency checkbashisms not installed') @pytest.mark.skipif(not HAS_DASH, reason='Optional dependency dash not installed') -@pytest.mark.parametrize('package', [BASHISMS]) +@pytest.mark.parametrize('package', [BashismsPackage]) def test_bashisms_error(package, bashismscheck): output, test = bashismscheck package.dirname = 'I-do-not-exist-for-sure' diff --git a/test/test_binaries.py b/test/test_binaries.py index a8a9c63ab..466d52a49 100644 --- a/test/test_binaries.py +++ b/test/test_binaries.py @@ -1,3 +1,4 @@ +from mockdata.mock_pkgconfig import LibReiserFSCoreDevelPackage import pytest from rpmlint.checks.BinariesCheck import BinariesCheck from rpmlint.filter import Filter @@ -31,10 +32,10 @@ def test_waived_forbidden_c_calls(tmp_path, package, binariescheck): assert 'crypto-policy-non-compliance' not in out -@pytest.mark.parametrize('package', ['binary/libreiserfscore-devel']) -def test_lto_bytecode(tmp_path, package, binariescheck): +@pytest.mark.parametrize('package', [LibReiserFSCoreDevelPackage]) +def test_lto_bytecode(package, binariescheck): output, test = binariescheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'lto-bytecode' in out diff --git a/test/test_build_date.py b/test/test_build_date.py index 107a92ebf..c31e4f551 100644 --- a/test/test_build_date.py +++ b/test/test_build_date.py @@ -1,6 +1,7 @@ import re -from mockdata.mock_build_date import BUILDDATE, BUILDDATE2 +from mockdata.mock_bashisms import BashismsPackage +from mockdata.mock_build_date import BuildDatePackage import pytest from rpmlint.checks.BuildRootAndDateCheck import BuildRootAndDateCheck from rpmlint.filter import Filter @@ -16,7 +17,7 @@ def builddatecheck(): return output, test -@pytest.mark.parametrize('package', [BUILDDATE]) +@pytest.mark.parametrize('package', [BuildDatePackage]) def test_build_date_time(package, builddatecheck): output, test = builddatecheck test.istoday = re.compile('Jan 1 2019') @@ -26,7 +27,7 @@ def test_build_date_time(package, builddatecheck): assert 'E: file-contains-current-date /bin/with-date' in out -@pytest.mark.parametrize('package', [BUILDDATE2]) +@pytest.mark.parametrize('package', [BashismsPackage]) def test_build_date_time_correct(package, builddatecheck): output, test = builddatecheck test.istoday = re.compile('Jan 1 2019') diff --git a/test/test_build_root.py b/test/test_build_root.py index 54fc640b4..857a176fb 100644 --- a/test/test_build_root.py +++ b/test/test_build_root.py @@ -1,4 +1,4 @@ -from mockdata.mock_build_root import BUILDROOT +from mockdata.mock_build_root import BuildrootPackage import pytest from rpmlint.checks.BuildRootAndDateCheck import BuildRootAndDateCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def buildrootcheck(): return output, test -@pytest.mark.parametrize('package', [BUILDROOT]) +@pytest.mark.parametrize('package', [BuildrootPackage]) def test_build_root(package, buildrootcheck): output, test = buildrootcheck test.prepare_regex('/home/marxin/rpmbuild/BUILDROOT/%{NAME}-%{VERSION}-%{RELEASE}.x86_64') diff --git a/test/test_config_files.py b/test/test_config_files.py index 8a7f2a335..f1eb06e28 100644 --- a/test/test_config_files.py +++ b/test/test_config_files.py @@ -1,4 +1,8 @@ -from mockdata.mock_config_files import (CONFIGFILES, CONFIGFILES2, CONFIGFILES3) +from mockdata.mock_config_files import ( + ConfigFilesBrokenPackage, + ConfigFilesOkPackage, +) +from mockdata.mock_logrotate import LogrotatePackage import pytest from rpmlint.checks.ConfigFilesCheck import ConfigFilesCheck from rpmlint.filter import Filter @@ -14,7 +18,7 @@ def configfilescheck(): return output, test -@pytest.mark.parametrize('package', [CONFIGFILES]) +@pytest.mark.parametrize('package', [ConfigFilesBrokenPackage]) def test_config_files1(package, configfilescheck): output, test = configfilescheck test.check(package) @@ -25,7 +29,7 @@ def test_config_files1(package, configfilescheck): assert 'conffile-without-noreplace-flag /usr/share/conffile3' in out -@pytest.mark.parametrize('package', [CONFIGFILES2, CONFIGFILES3]) +@pytest.mark.parametrize('package', [LogrotatePackage, ConfigFilesOkPackage]) def test_config_files_correct1(package, configfilescheck): output, test = configfilescheck test.check(package) diff --git a/test/test_dbus_policy.py b/test/test_dbus_policy.py index 63cad4706..270c78cd1 100644 --- a/test/test_dbus_policy.py +++ b/test/test_dbus_policy.py @@ -1,4 +1,4 @@ -from mockdata.mock_dbus_policy import DBUSPOLICY +from mockdata.mock_dbus_policy import DbusRulePackage import pytest from rpmlint.checks.DBusPolicyCheck import DBusPolicyCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def dbuspolicycheck(): return output, test -@pytest.mark.parametrize('package', [DBUSPOLICY]) +@pytest.mark.parametrize('package', [DbusRulePackage]) def test_dbus_policy(package, dbuspolicycheck): output, test = dbuspolicycheck test.check(package) diff --git a/test/test_doc.py b/test/test_doc.py index 79bf700b1..88475ea9d 100644 --- a/test/test_doc.py +++ b/test/test_doc.py @@ -1,8 +1,13 @@ +from mockdata.mock_doc import ( + DocFileDependencyPackage, + InstallFileInDocPackage, + MyDocPackage, +) import pytest from rpmlint.checks.DocCheck import DocCheck from rpmlint.filter import Filter -from Testing import CONFIG, get_tested_package +from Testing import CONFIG @pytest.fixture(scope='function', autouse=True) @@ -13,29 +18,29 @@ def doccheck(): return output, test -@pytest.mark.parametrize('package', ['binary/mydoc']) -def test_doccheck(tmp_path, package, doccheck): +@pytest.mark.parametrize('package', [MyDocPackage]) +def test_doccheck(package, doccheck): output, test = doccheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'E: executable-docs /usr/share/doc/packages/mydoc/doc.html' in out assert 'E: executable-docs /usr/share/doc/packages/mydoc/README' in out assert 'W: package-with-huge-docs 100%' in out -@pytest.mark.parametrize('package', ['binary/doc-file-dependency']) -def test_doc_file_dep(tmp_path, package, doccheck): +@pytest.mark.parametrize('package', [DocFileDependencyPackage]) +def test_doc_file_dep(package, doccheck): output, test = doccheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'W: doc-file-dependency' in out assert 'W: install-file-in-docs' not in out -@pytest.mark.parametrize('package', ['binary/install-file-in-docs']) -def test_install_file_in_docs(tmp_path, package, doccheck): +@pytest.mark.parametrize('package', [InstallFileInDocPackage]) +def test_install_file_in_docs(package, doccheck): output, test = doccheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'W: install-file-in-docs' in out assert 'E: executable-docs' not in out diff --git a/test/test_erlang.py b/test/test_erlang.py index ed6a7aef6..07fcdf57f 100644 --- a/test/test_erlang.py +++ b/test/test_erlang.py @@ -1,6 +1,6 @@ from importlib.metadata import distribution -from mockdata.mock_erlang import ERLANG +from mockdata.mock_erlang import ErlangPackage from packaging.version import parse import pytest from rpmlint.checks.ErlangCheck import ErlangCheck @@ -18,7 +18,7 @@ def erlangcheck(): @pytest.mark.skipif(parse(distribution('pybeam').version) < parse('0.7'), reason='pybeam >= 0.7 required') -@pytest.mark.parametrize('package', [ERLANG]) +@pytest.mark.parametrize('package', [ErlangPackage]) def test_erlang(package, erlangcheck): output, test = erlangcheck test.check(package) diff --git a/test/test_files.py b/test/test_files.py index 28513b887..2ae17332c 100644 --- a/test/test_files.py +++ b/test/test_files.py @@ -1,27 +1,29 @@ import re from mockdata.mock_files import ( - FILES, - FILES10, - FILES11, - FILES12, - FILES13, - FILES14, - FILES15, - FILES16, - FILES17, - FILES18, - FILES19, - FILES2, - FILES20, - FILES21, - FILES3, - FILES4, - FILES5, - FILES6, - FILES7, - FILES8, - FILES9 + DevelopmentPackage, + DirectoryWithoutXPerm2Package, + DirectoryWithoutXPermPackage, + FileChecksPackage, + FilesWithoutPermsPackage, + FilesWithoutPermsTmpfilesPackage, + FileZeroLengthPackage, + MakefileJunkPackage, + ManPagesPackage, + ManualPagesPackage, + NetmaskDebugsourcePackage, + NonReadableGhostPackage, + Python3PowerBrokenPackage, + Python3PowerPackage, + PythonShebangLinkOkPackage, + PythonShebangLinkPackage, + RustFilesPackage, + Shlib1Package, + Shlib2DevelPackage, + SphinxInvPackage, + TclPackage, + TestDocumentationPackage, + UnexpandedMacroFilesPackage, ) import pytest from rpmlint.checks.FilesCheck import FilesCheck @@ -76,7 +78,7 @@ def chunk_from_pyc(version, size=16): return f.read(size) -@pytest.mark.parametrize('package', [FILES]) +@pytest.mark.parametrize('package', [UnexpandedMacroFilesPackage]) def test_unexpanded_macros(package, filescheck): output, test = filescheck test.check(package) @@ -84,16 +86,18 @@ def test_unexpanded_macros(package, filescheck): assert 'unexpanded-macro' in out -@pytest.mark.parametrize('package', [FILES2]) -def test_python_bytecode_magic(package, filescheck): +@pytest.mark.parametrize('package,result', [ + (Python3PowerPackage, False), + (Python3PowerBrokenPackage, True), +]) +def test_python_bytecode_magic(package, result, filescheck): output, test = filescheck test.check(package) - assert not output.results out = output.print_results(output.results) - assert 'python-bytecode-wrong-magic-value' not in out + assert ('python-bytecode-wrong-magic-value' in out) == result -@pytest.mark.parametrize('package', [FILES3]) +@pytest.mark.parametrize('package', [TestDocumentationPackage]) def test_file_not_utf8_for_compression_algorithms(package, filescheck): output, test = filescheck test.check(package) @@ -115,7 +119,7 @@ def test_pyc_mtime_from_chunk(version, mtime): assert pyc_mtime_from_chunk(chunk) == mtime -@pytest.mark.parametrize('package', [FILES4]) +@pytest.mark.parametrize('package', [NetmaskDebugsourcePackage]) def test_devel_files(package, filescheck): output, test = filescheck test.check(package) @@ -126,7 +130,7 @@ def test_devel_files(package, filescheck): assert 'no-documentation' in out -@pytest.mark.parametrize('package', [FILES5]) +@pytest.mark.parametrize('package', [MakefileJunkPackage]) def test_makefile_junk(package, filescheck): output, test = filescheck test.check(package) @@ -135,14 +139,14 @@ def test_makefile_junk(package, filescheck): assert out.count('W: makefile-junk') == 1 -@pytest.mark.parametrize('package', [FILES6]) +@pytest.mark.parametrize('package', [SphinxInvPackage]) def test_sphinx_inv_files(package, filescheck): output, test = filescheck test.check(package) assert not len(output.results) -@pytest.mark.parametrize('package', [FILES7]) +@pytest.mark.parametrize('package', [FileChecksPackage]) def test_invalid_package(package, filescheck): output, test = filescheck test.check(package) @@ -160,7 +164,7 @@ def test_invalid_package(package, filescheck): assert 'E: info-dir-file /usr/info/dir' in out -@pytest.mark.parametrize('package', [FILES8]) +@pytest.mark.parametrize('package', [TclPackage]) def test_tcl_package(package, filescheck): output, test = filescheck test.check(package) @@ -205,7 +209,7 @@ def test_lib_regex(): '/usr/lib64/rsocket/binary',)) -@pytest.mark.parametrize('package', [FILES9]) +@pytest.mark.parametrize('package', [RustFilesPackage]) def test_rust_files(package, filescheck): output, test = filescheck test.check(package) @@ -214,8 +218,8 @@ def test_rust_files(package, filescheck): assert 'E: wrong-script-interpreter /etc/bar.rs' not in out -@pytest.mark.parametrize('package', [FILES10]) -def test_distribution_tags(package, filescheck): +@pytest.mark.parametrize('package', [ManPagesPackage]) +def test_manpages(package, filescheck): output, test = filescheck test.check(package) out = output.print_results(output.results) @@ -224,7 +228,7 @@ def test_distribution_tags(package, filescheck): assert 'This manual page is not compressed with the bz2 compression' in out -@pytest.mark.parametrize('package', [FILES11]) +@pytest.mark.parametrize('package', [DevelopmentPackage]) def test_provides_devel(package, filescheck): output, test = filescheck test.check(package) @@ -232,47 +236,46 @@ def test_provides_devel(package, filescheck): assert 'E: non-devel-file-in-devel-package /usr/x.typelib' in out -@pytest.mark.parametrize('package', [FILES12]) -def test_shlib1(package, filescheck): +@pytest.mark.parametrize('package,is_devel', [ + (Shlib1Package, False), + (Shlib2DevelPackage, True), +]) +def test_shlib(package, is_devel, filescheck): output, test = filescheck test.check(package) out = output.print_results(output.results) assert 'library-without-ldconfig-postin' in out assert 'library-without-ldconfig-postun' in out - assert 'devel-file-in-non-devel-package' in out - - -@pytest.mark.parametrize('package', [FILES13]) -def test_shlib2_devel(package, filescheck): + if is_devel: + assert ('non-devel-file-in-devel-package' in out) + else: + assert ('devel-file-in-non-devel-package' in out) + + +@pytest.mark.parametrize('package, files', [ + (FileZeroLengthPackage, [ + ('/usr/lib/emptyfile', True), + ('/usr/lib/nonemptyfile', False), + ('/etc/security/console.apps', False), + ('/etc/security/console.apps/myapp', False), + ('/usr/lib/.nosearch', False), + ('/etc/share/doc/packages/file-zero-length/dummydoc', False), + ('/usr/lib/python/__init__.py', False), + ('/usr/lib/python/py.typed', False), + ('/usr/lib/python/pypackagefromwheel-0.0.0.dist-info/REQUESTED', False), + ('/usr/lib/ruby/gem.build_complete', False), + ]), +]) +def test_zero_length_ignore(package, files, filescheck): output, test = filescheck test.check(package) out = output.print_results(output.results) - assert 'library-without-ldconfig-postin' in out - assert 'library-without-ldconfig-postun' in out - assert 'non-devel-file-in-devel-package' in out - - -@pytest.mark.parametrize('package', [FILES14]) -@pytest.mark.parametrize( - 'filename, show', - [('/usr/lib/emptyfile', True), - ('/usr/lib/nonemptyfile', False), - ('/etc/security/console.apps', False), - ('/usr/lib/.nosearch', False), - ('/usr/lib/python/__init__.py', False), - ('/usr/lib/python/py.typed', False), - ('/usr/lib/python/pypackagefromwheel-0.0.0.dist-info/REQUESTED', False), - ('/usr/lib/ruby/gem.build_complete', False)]) -def test_zero_length_ignore(package, filescheck, filename, show): - output, test = filescheck - pkg = package - test.check(pkg) - out = output.print_results(output.results) - assert filename in pkg.files - assert (f'zero-length {filename}' in out) == show + for filename, show in files: + assert filename in package.files + assert (f'zero-length {filename}' in out) == show -@pytest.mark.parametrize('package', [FILES15]) +@pytest.mark.parametrize('package', [ManualPagesPackage]) def test_manual_pages(package, filescheck): output, test = filescheck test.check(package) @@ -280,39 +283,30 @@ def test_manual_pages(package, filescheck): assert 'E: manual-page-in-subfolder /usr/share/man/man3/foo/bar/baz.3.gz' in out assert 'W: manpage-not-compressed bz2 /usr/share/man/man1/test.1.zst' in out assert 'E: bad-manual-page-folder /usr/share/man/man0p/foo.3.gz expected folder: man3' in out - assert 'bad-manual-page-folder /usr/share/man/man3/some.3pm.gz' not in out - - -@pytest.mark.parametrize('package', [FILES16]) -def test_shebang(package, output, test): - test.check(package) - out = output.print_results(output.results) - assert 'W: symlink-to-binary-with-shebang /usr/bin/testlink' in out + assert 'E: bad-manual-page-folder /usr/share/man/man3/some.3pm.gz' not in out -@pytest.mark.parametrize('package', [FILES17]) -def test_shebang_ok(package, output, test): +@pytest.mark.parametrize('package,is_ok', [ + (PythonShebangLinkPackage, False), + (PythonShebangLinkOkPackage, True), +]) +def test_shebang(package, is_ok, output, test): test.check(package) out = output.print_results(output.results) - assert 'W: symlink-to-binary-with-shebang /usr/bin/testlink' not in out + assert ('W: symlink-to-binary-with-shebang /usr/bin/testlink' not in out) == is_ok -@pytest.mark.parametrize('package', [FILES18]) -def test_directory_without_x_permission(package, output, test): +@pytest.mark.parametrize('package, is_ok', [ + (DirectoryWithoutXPermPackage, False), + (DirectoryWithoutXPerm2Package, False), +]) +def test_directory_without_x_permission(package, is_ok, output, test): test.check(package) out = output.print_results(output.results) - assert 'E: non-standard-dir-perm' in out + assert ('E: non-standard-dir-perm' not in out) == is_ok -@pytest.mark.parametrize('package', [FILES19]) -def test_directory_without_x_permission2(package, filescheck): - output, test = filescheck - test.check(package) - out = output.print_results(output.results) - assert 'E: non-standard-dir-perm' in out - - -@pytest.mark.parametrize('package', [FILES20]) +@pytest.mark.parametrize('package', [FilesWithoutPermsPackage]) def test_files_without_perms(package, output, test): test.check(package) out = output.print_results(output.results) @@ -324,10 +318,18 @@ def test_files_without_perms(package, output, test): assert not re.findall('W: zero-perms-ghost .*ghost_file_read', out) -@pytest.mark.parametrize('package', [FILES21]) +@pytest.mark.parametrize('package', [FilesWithoutPermsTmpfilesPackage]) def test_files_without_perms_tmpfiles(package, output, test): test.check(package) out = output.print_results(output.results) assert re.findall(r'W: zero-perms-ghost .*"%ghost %attr\(0644,root,root\) .*resolv.conf"', out) assert re.findall(r'W: zero-perms-ghost .*"%ghost %attr\(0755,root,group\) /run/netconfig"', out) assert not re.findall('W: zero-perms.*yp.conf ', out) + + +# https://github.com/rpm-software-management/rpmlint/issues/1287 +@pytest.mark.parametrize('package', [NonReadableGhostPackage]) +def test_non_readable_ghost_files(package, output, test): + test.check(package) + out = output.print_results(output.results) + assert 'E: non-readable /boohoo 0' not in out diff --git a/test/test_i18n.py b/test/test_i18n.py index 55409a9d2..d86b4f435 100644 --- a/test/test_i18n.py +++ b/test/test_i18n.py @@ -1,4 +1,4 @@ -from mockdata.mock_i18n import I18N, I18N2, I18N3, I18N4, I18N5, I18N6, I18N7, I18N8 +from mockdata.mock_i18n import I18NPackage, InvalidI18NPackage import pytest from rpmlint.checks.I18NCheck import I18NCheck from rpmlint.filter import Filter @@ -26,14 +26,16 @@ def test(i18ncheck): yield test -@pytest.mark.parametrize('package', [I18N, I18N2, I18N3]) +@pytest.mark.parametrize('package', [InvalidI18NPackage]) def test_i18n_invalid_lang(package, output, test): test.check(package) out = output.print_results(output.results) - assert 'E: invalid-lc-messages-dir' in out + assert 'E: invalid-lc-messages-dir /usr/share/locale/xx_ES/LC_MESSAGES/goodvibes.mo' in out + assert 'E: invalid-lc-messages-dir /usr/share/locale/es_XX/LC_MESSAGES/goodvibes.mo' in out + assert 'E: invalid-lc-messages-dir /usr/share/locale/xx/LC_MESSAGES/goodvibes.mo' in out -@pytest.mark.parametrize('package', [I18N4, I18N5, I18N6, I18N7, I18N8]) +@pytest.mark.parametrize('package', [I18NPackage]) def test_i18n_valid_lang(package, output, test): test.check(package) out = output.print_results(output.results) diff --git a/test/test_icon_sizes.py b/test/test_icon_sizes.py index 7a0498300..4f632e7e2 100644 --- a/test/test_icon_sizes.py +++ b/test/test_icon_sizes.py @@ -1,4 +1,4 @@ -from mockdata.mock_icon_sizes import ICONSIZES +from mockdata.mock_icon_sizes import WrongIconSizePackage import pytest from rpmlint.checks.IconSizesCheck import IconSizesCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def iconsizescheck(): return output, test -@pytest.mark.parametrize('package', [ICONSIZES]) +@pytest.mark.parametrize('package', [WrongIconSizePackage]) def test_icon_sizes(package, iconsizescheck): output, test = iconsizescheck test.check(package) diff --git a/test/test_lib_dependency.py b/test/test_lib_dependency.py index 69ef29fb9..5a21944aa 100644 --- a/test/test_lib_dependency.py +++ b/test/test_lib_dependency.py @@ -1,4 +1,4 @@ -from mockdata.mock_lib_dependency import LIBDEPENDENCY, LIBDEPENDENCY2 +from mockdata.mock_files import Shlib2DevelPackage import pytest from rpmlint.checks.LibraryDependencyCheck import LibraryDependencyCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def libdependencycheck(): return output, test -@pytest.mark.parametrize('package', [LIBDEPENDENCY]) +@pytest.mark.parametrize('package', [Shlib2DevelPackage]) def test_shlib2_devel(package, libdependencycheck): output, test = libdependencycheck test.check(package) @@ -22,13 +22,3 @@ def test_shlib2_devel(package, libdependencycheck): out = output.print_results(output.results) print(out) assert 'E: no-library-dependency-for /usr/lib/libfoo.so.1' in out - - -# TODO: Check out this test. It seems to do nothing -@pytest.mark.parametrize('package', [LIBDEPENDENCY2]) -def test_missing_depency_on(package, libdependencycheck): - output, test = libdependencycheck - test.check(package) - test.after_checks() - out = output.print_results(output.results) - assert 'W: missing-dependency-on' not in out diff --git a/test/test_logrotate.py b/test/test_logrotate.py index 7d4759c6f..55976c406 100644 --- a/test/test_logrotate.py +++ b/test/test_logrotate.py @@ -1,8 +1,9 @@ +from mockdata.mock_logrotate import LogrotatePackage import pytest from rpmlint.checks.LogrotateCheck import LogrotateCheck from rpmlint.filter import Filter -from Testing import CONFIG, get_tested_package +from Testing import CONFIG @pytest.fixture(scope='function', autouse=True) @@ -13,10 +14,10 @@ def logrotatecheck(): return output, test -@pytest.mark.parametrize('package', ['binary/logrotate']) -def test_logrotate(tmp_path, package, logrotatecheck): +@pytest.mark.parametrize('package', [LogrotatePackage]) +def test_logrotate(package, logrotatecheck): output, test = logrotatecheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'E: logrotate-log-dir-not-packaged /var/log/myapp' in out assert 'E: logrotate-duplicate /var/log/myapp' in out diff --git a/test/test_menuxdg.py b/test/test_menuxdg.py index f2bd8b2a0..95f3aa7a8 100644 --- a/test/test_menuxdg.py +++ b/test/test_menuxdg.py @@ -1,4 +1,11 @@ -from mockdata.mock_menuxdg import MENUXDG, MENUXDG1, MENUXDG2, MENUXDG3, MENUXDG4, MENUXDG5 +from mockdata.mock_menuxdg import ( + MenuXDGBadBinPackage, + MenuXDGBadDupPackage, + MenuXDGBadSecPackage, + MenuXDGBadUTF8Package, + MenuXDGInvalidPackage, + MenuXDGPackage, +) import pytest from rpmlint.checks.MenuXDGCheck import MenuXDGCheck from rpmlint.filter import Filter @@ -15,7 +22,7 @@ def menuxdgcheck(): @pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed') -@pytest.mark.parametrize('package', [MENUXDG]) +@pytest.mark.parametrize('package', [MenuXDGInvalidPackage]) def test_raises_parse_error(package, menuxdgcheck): output, test = menuxdgcheck test.check(package) @@ -27,7 +34,7 @@ def test_raises_parse_error(package, menuxdgcheck): @pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed') -@pytest.mark.parametrize('package', [MENUXDG1]) +@pytest.mark.parametrize('package', [MenuXDGBadBinPackage]) def test_without_binary(package, menuxdgcheck): output, test = menuxdgcheck test.check(package) @@ -36,7 +43,7 @@ def test_without_binary(package, menuxdgcheck): @pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed') -@pytest.mark.parametrize('package', [MENUXDG2]) +@pytest.mark.parametrize('package', [MenuXDGBadDupPackage]) def test_duplicate(package, menuxdgcheck): output, test = menuxdgcheck test.check(package) @@ -46,7 +53,7 @@ def test_duplicate(package, menuxdgcheck): @pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed') -@pytest.mark.parametrize('package', [MENUXDG3]) +@pytest.mark.parametrize('package', [MenuXDGBadSecPackage]) def test_missing_header(package, menuxdgcheck): output, test = menuxdgcheck test.check(package) @@ -56,7 +63,7 @@ def test_missing_header(package, menuxdgcheck): @pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed') -@pytest.mark.parametrize('package', [MENUXDG4]) +@pytest.mark.parametrize('package', [MenuXDGBadUTF8Package]) def test_bad_unicode(package, menuxdgcheck): output, test = menuxdgcheck test.check(package) @@ -65,7 +72,7 @@ def test_bad_unicode(package, menuxdgcheck): @pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed') -@pytest.mark.parametrize('package', [MENUXDG5]) +@pytest.mark.parametrize('package', [MenuXDGPackage]) def test_good(package, menuxdgcheck): output, test = menuxdgcheck test.check(package) diff --git a/test/test_mixed_ownership.py b/test/test_mixed_ownership.py index 5f2074478..090b08cc1 100644 --- a/test/test_mixed_ownership.py +++ b/test/test_mixed_ownership.py @@ -1,4 +1,4 @@ -from mockdata.mock_mixed_ownership import MixedOwnership +from mockdata.mock_mixed_ownership import MixedOwnershipPackage import pytest from rpmlint.checks.MixedOwnershipCheck import MixedOwnershipCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def mixedownershipcheck(): return output, test -@pytest.mark.parametrize('package', [MixedOwnership]) +@pytest.mark.parametrize('package', [MixedOwnershipPackage]) def test_mixed_ownership(package, mixedownershipcheck): output, test = mixedownershipcheck test.check(package) diff --git a/test/test_pam_modules.py b/test/test_pam_modules.py index ff510a371..065e93339 100644 --- a/test/test_pam_modules.py +++ b/test/test_pam_modules.py @@ -1,4 +1,4 @@ -from mockdata.mock_pam_modules import PAMMODULES +from mockdata.mock_pam_modules import PAMModulePackage import pytest from rpmlint.checks.PAMModulesCheck import PAMModulesCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def pammodulecheck(): return output, test -@pytest.mark.parametrize('package', [PAMMODULES]) +@pytest.mark.parametrize('package', [PAMModulePackage]) def test_pam_modules(package, pammodulecheck): output, test = pammodulecheck test.check(package) diff --git a/test/test_pkg.py b/test/test_pkg.py index 415c80b39..312741d20 100644 --- a/test/test_pkg.py +++ b/test/test_pkg.py @@ -29,16 +29,13 @@ def test_range_compare(): @pytest.mark.parametrize('package', ['binary/python311-pytest-xprocess']) +@pytest.mark.skipif(os.getuid() == 0, reason='Root has full permission') def test_extract_fail(package, tmp_path): """ Check that rpm2cpio fails to extract this package because it has no permissions to some files. """ - # Root can extract the package, so nothing to check - if os.getuid() == 0: - return - with mock.patch('shutil.which') as mock_which: mock_which.return_value = None # the package cannot be extracted using rpm2cpio because it contains a directory without 'x' permission diff --git a/test/test_pkgconfig.py b/test/test_pkgconfig.py index 415ced171..b801d5ccd 100644 --- a/test/test_pkgconfig.py +++ b/test/test_pkgconfig.py @@ -1,4 +1,4 @@ -from mockdata.mock_pkgconfig import PKGCONFIG, PKGCONFIG2 +from mockdata.mock_pkgconfig import LibReiserFSCoreDevelPackage, PCPackage import pytest from rpmlint.checks.PkgConfigCheck import PkgConfigCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def pkgconfigcheck(): return output, test -@pytest.mark.parametrize('package', [PKGCONFIG]) +@pytest.mark.parametrize('package', [PCPackage]) def test_pkg_config(package, pkgconfigcheck): output, test = pkgconfigcheck test.check(package) @@ -24,7 +24,7 @@ def test_pkg_config(package, pkgconfigcheck): assert 'E: double-slash-in-pkgconfig-path /tmp/pkgconfig/xcb.pc includedir=/usr/include//xyz' in out -@pytest.mark.parametrize('package', [PKGCONFIG2]) +@pytest.mark.parametrize('package', [LibReiserFSCoreDevelPackage]) def test_pkg_config_correct(package, pkgconfigcheck): output, test = pkgconfigcheck test.check(package) diff --git a/test/test_shlib_policy.py b/test/test_shlib_policy.py index e4f806dc2..45560928d 100644 --- a/test/test_shlib_policy.py +++ b/test/test_shlib_policy.py @@ -1,4 +1,8 @@ -from mockdata.mock_shlib_policy import SHLIBPOLICY, SHLIBPOLICY2, SHLIBPOLICY3 +from mockdata.mock_shlib_policy import ( + Libslp1234Package, + LibslpMissingSuffixPackage, + Libtest1Package, +) import pytest from rpmlint.checks.SharedLibraryPolicyCheck import SharedLibraryPolicyCheck from rpmlint.filter import Filter @@ -14,7 +18,7 @@ def slpcheck(): return output, test -@pytest.mark.parametrize('package', [SHLIBPOLICY]) +@pytest.mark.parametrize('package', [Libtest1Package]) def test_shlib_policy_wrong_name(package, slpcheck): output, test = slpcheck test.check(package) @@ -22,7 +26,7 @@ def test_shlib_policy_wrong_name(package, slpcheck): assert 'W: shlib-unversioned-lib libtest.so.1x' in out -@pytest.mark.parametrize('package', [SHLIBPOLICY2]) +@pytest.mark.parametrize('package', [LibslpMissingSuffixPackage]) def test_shlib_policy_missing_suffix(package, slpcheck): output, test = slpcheck test.check(package) @@ -30,7 +34,7 @@ def test_shlib_policy_missing_suffix(package, slpcheck): assert 'E: shlib-policy-excessive-dependency libsparta.so.2' in out -@pytest.mark.parametrize('package', [SHLIBPOLICY3]) +@pytest.mark.parametrize('package', [Libslp1234Package]) def test_shlib_policy_errors(package, slpcheck): output, test = slpcheck test.check(package) diff --git a/test/test_speccheck.py b/test/test_speccheck.py index c352fb13a..33b531f51 100644 --- a/test/test_speccheck.py +++ b/test/test_speccheck.py @@ -1241,6 +1241,7 @@ def test_special_comments(package, output, test): ('spec/libcanberra', True), ('spec/MacroInComment', False), ('spec/ghc', False), + ('spec/yast2-installation', False), ]) def test_deprecated_suse_update_desktop_files(spec, expected, output, test): package = get_tested_spec_package(spec) diff --git a/test/test_sysvinitonsystemd.py b/test/test_sysvinitonsystemd.py index b1b33a9d1..8468cfeb9 100644 --- a/test/test_sysvinitonsystemd.py +++ b/test/test_sysvinitonsystemd.py @@ -1,4 +1,4 @@ -from mockdata.mock_sysvinitonsystemd import SYSVINITONSYSTEMD, SYSVINITONSYSTEMD2 +from mockdata.mock_sysvinitonsystemd import InitPackage, RcLinksPackage import pytest from rpmlint.checks.SysVInitOnSystemdCheck import SysVInitOnSystemdCheck from rpmlint.filter import Filter @@ -14,7 +14,7 @@ def sysvcheck(): return output, test -@pytest.mark.parametrize('package', [SYSVINITONSYSTEMD]) +@pytest.mark.parametrize('package', [InitPackage]) def test_sysv_init_on_systemd_check(package, sysvcheck): output, test = sysvcheck test.check(package) @@ -24,7 +24,7 @@ def test_sysv_init_on_systemd_check(package, sysvcheck): assert 'E: deprecated-boot-script boot.script' in out -@pytest.mark.parametrize('package', [SYSVINITONSYSTEMD2]) +@pytest.mark.parametrize('package', [RcLinksPackage]) def test_overshadowing_of_initscript(package, sysvcheck): output, test = sysvcheck test.check(package) diff --git a/test/test_tags.py b/test/test_tags.py index 6cba8c7e9..8515abaeb 100644 --- a/test/test_tags.py +++ b/test/test_tags.py @@ -1,3 +1,12 @@ +from mockdata.mock_tags import ( + FooDevelPackage, + FuseCommonPackage, + InvalidExceptionPackage, + MissingProvidesPackage, + SelfPackage, + UnexpandedMacroPackage, + ValidExceptionPackage, +) import pytest from rpmlint.checks.TagsCheck import TagsCheck from rpmlint.filter import Filter @@ -28,10 +37,10 @@ def test(tagscheck): yield test -@pytest.mark.parametrize('package', ['binary/unexpanded1']) -def test_unexpanded_macros(tmp_path, package, tagscheck): +@pytest.mark.parametrize('package', [UnexpandedMacroPackage]) +def test_unexpanded_macros(package, tagscheck): output, test = tagscheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'unexpanded-macro Recommends' in out assert 'unexpanded-macro Provides' in out @@ -41,53 +50,53 @@ def test_unexpanded_macros(tmp_path, package, tagscheck): assert 'unexpanded-macro Enhances' in out -@pytest.mark.parametrize('package', ['binary/self']) -def test_self_provides(tmp_path, package, tagscheck): +@pytest.mark.parametrize('package', [SelfPackage]) +def test_self_provides(package, tagscheck): output, test = tagscheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'E: useless-provides self' in out -@pytest.mark.parametrize('package', ['binary/fuse-common']) -def test_useless_provides_only_versions(tmp_path, package, tagscheck): +@pytest.mark.parametrize('package', [FuseCommonPackage]) +def test_useless_provides_only_versions(package, tagscheck): output, test = tagscheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) - assert 'E: useless-provides self' not in out + assert 'E: useless-provides fuse-common' not in out -@pytest.mark.parametrize('package', ['binary/foo-devel']) -def test_development_package(tmp_path, package, tagscheck): +@pytest.mark.parametrize('package', [FooDevelPackage]) +def test_development_package(package, tagscheck): output, test = tagscheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'W: devel-package-with-non-devel-group Games' in out -@pytest.mark.parametrize('package', ['binary/missingprovides']) -def test_missing_provides(tmp_path, package, tagscheck): +@pytest.mark.parametrize('package', [MissingProvidesPackage]) +def test_missing_provides(package, tagscheck): output, test = tagscheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'E: no-pkg-config-provides' in out -@pytest.mark.parametrize('package', ['binary/invalid-exception']) -def test_invalid_license_exception(tmp_path, package, tagscheck): +@pytest.mark.parametrize('package', [InvalidExceptionPackage]) +def test_invalid_license_exception(package, tagscheck): output, test = tagscheck - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'W: invalid-license-exception sparta' in out -@pytest.mark.parametrize('package', ['binary/valid-exception']) +@pytest.mark.parametrize('package', [ValidExceptionPackage]) def test_valid_license_exception(tmp_path, package, tagscheck): CONFIG.info = True CONFIG.configuration['ValidLicenseExceptions'] = ['389-exception'] output = Filter(CONFIG) test = TagsCheck(CONFIG, output) - test.check(get_tested_package(package, tmp_path)) + test.check(package) out = output.print_results(output.results) assert 'W: invalid-license-exception' not in out diff --git a/test/test_tmp_files.py b/test/test_tmp_files.py index 8734f7bbc..efc417a2f 100644 --- a/test/test_tmp_files.py +++ b/test/test_tmp_files.py @@ -1,4 +1,8 @@ -from mockdata.mock_tmp_files import (TMPFILES, TMPFILES2, TMPFILES3) +from mockdata.mock_tmp_files import ( + SystemdTempfilesOkPackage, + SystemdTempfilesPackage, + TempfiledPackage, +) import pytest from rpmlint.checks.TmpFilesCheck import TmpFilesCheck from rpmlint.filter import Filter @@ -14,7 +18,7 @@ def tmpfilescheck(): return output, test -@pytest.mark.parametrize('package', [TMPFILES]) +@pytest.mark.parametrize('package', [TempfiledPackage]) def test_tmpfiles(package, tmpfilescheck): output, test = tmpfilescheck test.check(package) @@ -26,7 +30,7 @@ def test_tmpfiles(package, tmpfilescheck): assert 'W: tmpfile-not-regular-file /usr/lib/tmpfiles.d/symlink.conf' in out -@pytest.mark.parametrize('package', [TMPFILES2]) +@pytest.mark.parametrize('package', [SystemdTempfilesPackage]) def test_tmpfiles2(package, tmpfilescheck): output, test = tmpfilescheck test.check(package) @@ -38,7 +42,7 @@ def test_tmpfiles2(package, tmpfilescheck): assert 'W: tmpfile-not-regular-file' not in out -@pytest.mark.parametrize('package', [TMPFILES3]) +@pytest.mark.parametrize('package', [SystemdTempfilesOkPackage]) def test_tmpfiles_correct(package, tmpfilescheck): output, test = tmpfilescheck test.check(package) diff --git a/test/test_zypp_syntax.py b/test/test_zypp_syntax.py index 4f63bde87..ab7afab9b 100644 --- a/test/test_zypp_syntax.py +++ b/test/test_zypp_syntax.py @@ -1,4 +1,7 @@ -from mockdata.mock_zypp_syntax import (ZYPPSYNTAX, ZYPPSYNTAX2) +from mockdata.mock_zypp_syntax import ( + SyntaxAndPackage, + SyntaxPackageandPackage, +) import pytest from rpmlint.checks.ZyppSyntaxCheck import ZyppSyntaxCheck from rpmlint.filter import Filter @@ -26,7 +29,7 @@ def test(zyppsyntaxcheck): yield test -@pytest.mark.parametrize('package', [ZYPPSYNTAX]) +@pytest.mark.parametrize('package', [SyntaxPackageandPackage]) def test_packageand(package, test, output): test.check(package) out = output.print_results(output.results) @@ -37,7 +40,7 @@ def test_packageand(package, test, output): assert 'suse-zypp-otherproviders otherproviders(yast2_theme)' in out -@pytest.mark.parametrize('package', [ZYPPSYNTAX2]) +@pytest.mark.parametrize('package', [SyntaxAndPackage]) def test_packageand_ok(package, test, output): test.check(package) out = output.print_results(output.results)