diff --git a/filesystem/ext4/ext4.go b/filesystem/ext4/ext4.go index 41872315..0e7d64ed 100644 --- a/filesystem/ext4/ext4.go +++ b/filesystem/ext4/ext4.go @@ -684,6 +684,9 @@ func Read(file util.File, size, start, sectorsize int64) (*FileSystem, error) { }, nil } +// interface guard +var _ filesystem.FileSystem = (*FileSystem)(nil) + // Type returns the type code for the filesystem. Always returns filesystem.TypeExt4 func (fs *FileSystem) Type() filesystem.Type { return filesystem.TypeExt4 @@ -699,6 +702,22 @@ func (fs *FileSystem) Mkdir(p string) error { return err } +// creates a filesystem node (file, device special file, or named pipe) named pathname, +// with attributes specified by mode and dev +func (fs *FileSystem) Mknod(path string, mode uint32, dev int) error { + return filesystem.ErrNotImplemented +} + +// creates a new link (also known as a hard link) to an existing file. +func (fs *FileSystem) Link(oldpath string, newpath string) error { + return filesystem.ErrNotImplemented +} + +// creates a symbolic link named linkpath which contains the string target. +func (fs *FileSystem) Symlink(oldpath string, newpath string) error { + return filesystem.ErrNotImplemented +} + // ReadDir return the contents of a given directory in a given filesystem. // // Returns a slice of os.FileInfo with all of the entries in the directory. @@ -808,12 +827,17 @@ func (fs *FileSystem) Label() string { return fs.superblock.volumeLabel } -// Rm remove file or directory at path. +// FIXME: API backwards compatibility +func (fs *FileSystem) Rm(p string) error { + return fs.Remove(p) +} + +// Removes file or directory at path. // If path is directory, it only will remove if it is empty. // If path is a file, it will remove the file. // Will not remove any parents. // Error if the file does not exist or is not an empty directory -func (fs *FileSystem) Rm(p string) error { +func (fs *FileSystem) Remove(p string) error { parentDir, entry, err := fs.getEntryAndParent(p) if err != nil { return err diff --git a/filesystem/fat32/fat32.go b/filesystem/fat32/fat32.go index 240b6632..d871f541 100644 --- a/filesystem/fat32/fat32.go +++ b/filesystem/fat32/fat32.go @@ -470,6 +470,9 @@ func (fs *FileSystem) writeFat() error { return nil } +// interface guard +var _ filesystem.FileSystem = (*FileSystem)(nil) + // Type returns the type code for the filesystem. Always returns filesystem.TypeFat32 func (fs *FileSystem) Type() filesystem.Type { return filesystem.TypeFat32 @@ -485,6 +488,22 @@ func (fs *FileSystem) Mkdir(p string) error { return err } +// creates a filesystem node (file, device special file, or named pipe) named pathname, +// with attributes specified by mode and dev +func (fs *FileSystem) Mknod(path string, mode uint32, dev int) error { + return filesystem.ErrNotSupported +} + +// creates a new link (also known as a hard link) to an existing file. +func (fs *FileSystem) Link(oldpath string, newpath string) error { + return filesystem.ErrNotSupported +} + +// creates a symbolic link named linkpath which contains the string target. +func (fs *FileSystem) Symlink(oldpath string, newpath string) error { + return filesystem.ErrNotSupported +} + // ReadDir return the contents of a given directory in a given filesystem. // // Returns a slice of os.FileInfo with all of the entries in the directory. @@ -606,6 +625,10 @@ func (fs *FileSystem) OpenFile(p string, flag int) (filesystem.File, error) { }, nil } +func (fs *FileSystem) Remove(p string) error { + return filesystem.ErrNotImplemented +} + // Label get the label of the filesystem from the secial file in the root directory. // The label stored in the boot sector is ignored to mimic Windows behavior which // only stores and reads the label from the special file in the root directory. diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index 2c1acfa6..b7816ffd 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -3,25 +3,40 @@ package filesystem import ( + "errors" "os" ) +var ( + ErrNotSupported = errors.New("method not supported by this filesystem") + ErrNotImplemented = errors.New("method not implemented (patches are welcome)") +) + // FileSystem is a reference to a single filesystem on a disk type FileSystem interface { // Type return the type of filesystem Type() Type // Mkdir make a directory - Mkdir(string) error + Mkdir(path string) error + // creates a filesystem node (file, device special file, or named pipe) named pathname, + // with attributes specified by mode and dev + Mknod(path string, mode uint32, dev int) error + // creates a new link (also known as a hard link) to an existing file. + Link(oldpath string, newpath string) error + // creates a symbolic link named linkpath which contains the string target. + Symlink(oldpath string, newpath string) error // ReadDir read the contents of a directory - ReadDir(string) ([]os.FileInfo, error) + ReadDir(path string) ([]os.FileInfo, error) // OpenFile open a handle to read or write to a file - OpenFile(string, int) (File, error) + OpenFile(path string, flag int) (File, error) + // removes the named file or (empty) directory. + Remove(path string) error // Label get the label for the filesystem, or "" if none. Be careful to trim it, as it may contain // leading or following whitespace. The label is passed as-is and not cleaned up at all. Label() string // SetLabel changes the label on the writable filesystem. Different file system may hav different // length constraints. - SetLabel(string) error + SetLabel(label string) error } // Type represents the type of disk this is diff --git a/filesystem/iso9660/iso9660.go b/filesystem/iso9660/iso9660.go index 64b28ed2..72e893c2 100644 --- a/filesystem/iso9660/iso9660.go +++ b/filesystem/iso9660/iso9660.go @@ -282,6 +282,9 @@ func Read(file util.File, size, start, blocksize int64) (*FileSystem, error) { return fs, nil } +// interface guard +var _ filesystem.FileSystem = (*FileSystem)(nil) + // Type returns the type code for the filesystem. Always returns filesystem.TypeFat32 func (fsm *FileSystem) Type() filesystem.Type { return filesystem.TypeISO9660 @@ -305,6 +308,22 @@ func (fsm *FileSystem) Mkdir(p string) error { return err } +// creates a filesystem node (file, device special file, or named pipe) named pathname, +// with attributes specified by mode and dev +func (fs *FileSystem) Mknod(path string, mode uint32, dev int) error { + return filesystem.ErrNotSupported +} + +// creates a new link (also known as a hard link) to an existing file. +func (fs *FileSystem) Link(oldpath string, newpath string) error { + return filesystem.ErrNotSupported +} + +// creates a symbolic link named linkpath which contains the string target. +func (fs *FileSystem) Symlink(oldpath string, newpath string) error { + return filesystem.ErrNotSupported +} + // ReadDir return the contents of a given directory in a given filesystem. // // Returns a slice of os.FileInfo with all of the entries in the directory. @@ -414,6 +433,13 @@ func (fsm *FileSystem) OpenFile(p string, flag int) (filesystem.File, error) { return f, nil } +func (fsm *FileSystem) Remove(p string) error { + if fsm.workspace == "" { + return filesystem.ErrNotSupported + } + return os.Remove(path.Join(fsm.workspace, p)) +} + // readDirectory - read directory entry on iso only (not workspace) func (fsm *FileSystem) readDirectory(p string) ([]*directoryEntry, error) { var ( diff --git a/filesystem/squashfs/squashfs.go b/filesystem/squashfs/squashfs.go index bdd8d5a7..1d5e699b 100644 --- a/filesystem/squashfs/squashfs.go +++ b/filesystem/squashfs/squashfs.go @@ -229,6 +229,9 @@ func Read(file util.File, size, start, blocksize int64) (*FileSystem, error) { return fs, nil } +// interface guard +var _ filesystem.FileSystem = (*FileSystem)(nil) + // Type returns the type code for the filesystem. Always returns filesystem.TypeFat32 func (fs *FileSystem) Type() filesystem.Type { return filesystem.TypeSquashfs @@ -276,6 +279,22 @@ func (fs *FileSystem) Mkdir(p string) error { return err } +// creates a filesystem node (file, device special file, or named pipe) named pathname, +// with attributes specified by mode and dev +func (fs *FileSystem) Mknod(path string, mode uint32, dev int) error { + return filesystem.ErrNotSupported +} + +// creates a new link (also known as a hard link) to an existing file. +func (fs *FileSystem) Link(oldpath string, newpath string) error { + return filesystem.ErrNotSupported +} + +// creates a symbolic link named linkpath which contains the string target. +func (fs *FileSystem) Symlink(oldpath string, newpath string) error { + return filesystem.ErrNotSupported +} + // ReadDir return the contents of a given directory in a given filesystem. // // Returns a slice of os.FileInfo with all of the entries in the directory. @@ -379,6 +398,13 @@ func (fs *FileSystem) OpenFile(p string, flag int) (filesystem.File, error) { return f, nil } +func (fs *FileSystem) Remove(p string) error { + if fs.workspace == "" { + return filesystem.ErrNotSupported + } + return os.Remove(path.Join(fs.workspace, p)) +} + // readDirectory - read directory entry on squashfs only (not workspace) func (fs *FileSystem) readDirectory(p string) ([]*directoryEntry, error) { // use the root inode to find the location of the root direectory in the table