You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4KB

  1. extern crate sunk;
  2. type Song = sunk::song::Song;
  3. trait SubFSFile {
  4. type File;
  5. fn get_ino_from_id(id: usize) -> u64;
  6. fn get_id_from_ino(ino: u64) -> usize;
  7. fn new_from_id(client: & sunk::Client, id: usize) -> Self::File;
  8. fn new_from_ino(client: & sunk::Client, ino: u64) -> Self::File;
  9. fn get_ino(&self) -> u64;
  10. fn get_attr(&self) -> FileAttr;
  11. }
  12. impl SubFSFile for Song {
  13. type File = Song;
  14. fn get_ino_from_id(id: usize) -> u64 {
  15. id as u64 | SONG_ID
  16. }
  17. fn get_id_from_ino(ino: u64) -> usize {
  18. ino as usize & !SONG_ID as usize
  19. }
  20. fn new_from_id(client: & sunk::Client, id: usize) -> Song {
  21. Song::get(&client, id as u64).unwrap()
  22. }
  23. fn new_from_ino(client: & sunk::Client, ino: u64) -> Song {
  24. let id = Song::get_id_from_ino(ino);
  25. Song::new_from_id(&client, id)
  26. }
  27. fn get_ino(&self) -> u64 {
  28. Song::get_ino_from_id(self.id as usize)
  29. }
  30. fn get_attr(&self) -> FileAttr {
  31. FileAttr {
  32. ino: self.get_ino(),
  33. size: self.size,
  34. blocks: 0,
  35. atime: CREATE_TIME,
  36. mtime: CREATE_TIME,
  37. ctime: CREATE_TIME,
  38. crtime: CREATE_TIME,
  39. kind: FileType::RegularFile,
  40. perm: 0o755,
  41. nlink: 2,
  42. uid: 501,
  43. gid: 20,
  44. rdev: 0,
  45. flags: 0,
  46. }
  47. }
  48. }